ngcc: implement ivy switch rendering#25534
Conversation
b858548 to
5038aa1
Compare
mhevery
left a comment
There was a problem hiding this comment.
There seems to be other unrelated changes in this PR, but the __PRE_NGCC__ rewrite to __POST_NGCC__ looks good to me.
There was a problem hiding this comment.
As of right now this switch is in @angular/core only. Should we short circuit this for perf reasons? Is there an argument to be made to enable such switch for others?
There was a problem hiding this comment.
I need to test this but I suspect that the bottleneck for performance is creating the TS compilation, which is necessary for the rest of the work. So I believe that parsing for these markers will make little performance difference.
There was a problem hiding this comment.
I suggest that we have a period of performance tuning once the functionality is in place. I think that there is potentially a lot of duplication of work, especially in the ngtsc resolver and the reflection hosts right now that would benefit from some caching strategies.
|
The other changes were to simplify the rendering tests, without which the changes to the tests would have got yet more complicated. |
gkalpak
left a comment
There was a problem hiding this comment.
Some minor comments. LGTM otherwise 👍
There was a problem hiding this comment.
Why not make this a method on the ReflectionHost. Having both standalone functions and Class methods gets confusing (imo).
There was a problem hiding this comment.
We have lots of type constraint functions in the ngcc and ngtsc code. They are all standalone.
There was a problem hiding this comment.
This sounds more like a visitor than a worker 😁
There was a problem hiding this comment.
I wouldn't mind a test with __PRE_NGCC__ at the beginning of the identifier 😁
There was a problem hiding this comment.
I wouldn't mind a test with __PRE_NGCC__ at the beginning of the identifier 😁
There was a problem hiding this comment.
Using a helper function to strip indentation makes the code look (and get folded) much better. I usually have:
const stripIndentation = (input: string): string => {
const lines = input.replace(/^ *\n/, '').replace(/\n *$/, '').split('\n');
const minIndentation = Math.min(...lines.
filter(l => !/^ *$/.test(l)).
map(l => /^ */.exec(l)![0].length));
const re = new RegExp(`^ {0,${minIndentation}}`);
return lines.map(l => l.replace(re, '')).join('\n');
};There was a problem hiding this comment.
Fair enough. This has been a worry for me for a while. I'll give this a go.
There was a problem hiding this comment.
why the two replaces? Blank lines get stripped in the filter right?
There was a problem hiding this comment.
I think we should add that helper in a separate PR (since it would hit a lot of the tests).
There was a problem hiding this comment.
SGTM.
why the two replaces? Blank lines get stripped in the filter right?
The two replace remove leading/trailing empty/whitespace-only lines from the output. The filter is only used to ignore whitespace-only lines for computing the min indentation.
|
Can a Googler run the presubmit please? |
6d7e15a to
059a9e1
Compare
|
Rebased on master. Hoping @alxhub can get this through G3 etc. |
|
You can preview 059a9e1 at https://pr25534-059a9e1.ngbuilds.io/. |
059a9e1 to
ae1b36f
Compare
|
You can preview ae1b36f at https://pr25534-ae1b36f.ngbuilds.io/. |
There was a problem hiding this comment.
I'm becoming less of a fan of this approach of testing. It's really hard to look at this test and figure out whether it's correct.
Can we start thinking of a way to make this more straightforward? It doesn't have to happen in this PR.
There was a problem hiding this comment.
We should implement a performance optimization where we check module.getText() for PRE_NGCC_MARER via regex or .indexOf. Only if the test is positive should we walk the AST to actually find them.
This method will be used to find all the places where the "ivy switch" will occur. See angular#25238
This supports the "ngcc ivy switch" specified in angular#25238.
Also incorporates a refactoring of the tests to make them less fragile.
Only parse the AST for ngcc ivy switch constants if the marker is not found in the module text.
ae1b36f to
29457cc
Compare
|
You can preview 29457cc at https://pr25534-29457cc.ngbuilds.io/. |
|
@alxhub can you help get the G3 presubmit green so that we can merge this? |
Also incorporates a refactoring of the tests to make them less fragile. PR Close #25534
Only parse the AST for ngcc ivy switch constants if the marker is not found in the module text. PR Close #25534
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This is related to #25238