Skip to content

refactor(compiler): integrate let declarations into the template pipeline - #56299

Closed
crisbeto wants to merge 7 commits into
angular:mainfrom
crisbeto:let-pipeline
Closed

crisbeto wants to merge 7 commits into
angular:mainfrom
crisbeto:let-pipeline

Conversation

@crisbeto

@crisbeto crisbeto commented Jun 6, 2024

Copy link
Copy Markdown
Member

These changes integrate let declarations into the template pipeline. This involves a few operations:

  • Producing a declareLet instruction call at creation time to initialize the declaration.
  • Producing a storeLet instruction call in the place of the let declaration, including the necessary advance calls beforehand.
  • For let declarations used within their declaration view, moving the const to be placed right after the storeLet call to ensure the their value has been computed.
  • For let declarations that are only used in their declaration view, removing the storeLet call and inlining the expression into the constant statement.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Jun 6, 2024
@ngbot ngbot Bot added this to the Backlog milestone Jun 6, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel great about adding a parameter like this, but I couldn't find another way to distinguish between listener and non-listener scopes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why we need to? Naively, I'd expect that we should generate the same variables inside listener functions. Or am I missing something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because, while in the current setup of the pipeline listeners have the same scope as their declaration view, they're technically child views, hence why we resolve @let declarations in them using ɵɵreadContextLet and why they currently generate nextContext calls.

@crisbeto
crisbeto requested a review from dylhunn June 6, 2024 08:11
@crisbeto
crisbeto marked this pull request as ready for review June 6, 2024 08:11
@alxhub alxhub self-assigned this Jun 7, 2024
@alxhub
alxhub self-requested a review June 7, 2024 21:49
@crisbeto
crisbeto force-pushed the let-pipeline branch 2 times, most recently from 116fa9f to 9817db7 Compare June 12, 2024 17:11

@dylhunn dylhunn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per VC -- my only suggested structural change is that optimization for let should probably be its own phase, since it has let-specific knowledge (e.g. extracting initializers from storeLet).

Thanks for the nice work!

@dylhunn
dylhunn self-requested a review June 12, 2024 20:33

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the reads are optimized out, can we do the same for the declaration and therefore the reserved binding slots?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why we need to? Naively, I'd expect that we should generate the same variables inside listener functions. Or am I missing something?

@crisbeto
crisbeto force-pushed the let-pipeline branch 2 times, most recently from ca1c36d to 3a92693 Compare June 18, 2024 12:04
crisbeto added 6 commits June 18, 2024 22:14
…line

These changes integrate let declarations into the template pipeline. This involves a few operations:
* Producing a `declareLet` instruction call at creation time to initialize the declaration.
* Producing a `storeLet` instruction call in the place of the let declaration, including the necessary `advance` calls beforehand.
* For let declarations used within their declaration view, moving the `const` to be placed right after the `storeLet` call to ensure the their value has been computed.
* For let declarations that are _only_ used in their declaration view, removing the `storeLet` call and inlining the expression into the constant statement.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 18, 2024
@AndrewKushnir

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 64990a5.

The changes were merged into the following branches: main, 18.0.x

AndrewKushnir pushed a commit that referenced this pull request Jun 20, 2024
…line (#56299)

These changes integrate let declarations into the template pipeline. This involves a few operations:
* Producing a `declareLet` instruction call at creation time to initialize the declaration.
* Producing a `storeLet` instruction call in the place of the let declaration, including the necessary `advance` calls beforehand.
* For let declarations used within their declaration view, moving the `const` to be placed right after the `storeLet` call to ensure the their value has been computed.
* For let declarations that are _only_ used in their declaration view, removing the `storeLet` call and inlining the expression into the constant statement.

PR Close #56299
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants