Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deferred blocks in partial compilation #54908

Closed
wants to merge 5 commits into from

Conversation

crisbeto
Copy link
Member

Includes some changes that are necessary to support @defer blocks in partial compilation mode.

refactor(compiler): ensure defer blocks maintain the template order in the binder

Switches to tracking the deferred blocks in a flat array in the binder to ensure that their template order is maintained. This will be relevant in the next commits where we'll match deferred blocks by their index.

Note that the current map we have technically guarantees the insertion order in the spec, but the array is a bit more explicit.

refactor(compiler): widen type of resolver function

Updates the type of the resolver function to be any Expression since JIT may receive a function reference rather than a ArrowFunctionExpr.

refactor(compiler-cli): add method for extracting function parameters

Updates the linker's AST host to add the ability to extract a function's parameters. This will be required for the next commits.

refactor(core): introduce API for declaring asynchronous partial metadata

Adds the ɵɵngDeclareClassMetadataAsync function that will be produced during partial compilation for component classes that have deferred dependencies. At runtime the dependencies will be resolved before setting the metadata.

feat(compiler-cli): add partial compilation support for deferred blocks

Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made:

  • The metadata passed into ɵɵngDeclareComponent has an additional field called deferBlockDependencies which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the deferBlockDependencies array.
  • There's a new ɵɵngDeclareClassMetadataAsync function that is created for components that have deferred dependencies. It gets transpiled to setClassMetadataAsync and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code.
  • Deferred import statements are now stripped in partial compilation mode, similar to full compilation.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Mar 16, 2024
@ngbot ngbot bot added this to the Backlog milestone Mar 16, 2024
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Mar 16, 2024
@crisbeto crisbeto marked this pull request as ready for review March 16, 2024 11:20
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@crisbeto the change looks great 👍 Huge thanks for splitting the change into multiple commits, it made it much easier to review.

@AndrewKushnir
Copy link
Contributor

@alxhub could you please take a look at this change when you get a chance? Would love to get your feedback on the shape of partially compiled components. Thank you.

@crisbeto crisbeto modified the milestones: Backlog, v18-candidates Mar 19, 2024
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

LGTM with one comment

…n the binder

Switches to tracking the deferred blocks in a flat array in the binder to ensure that their template order is maintained. This will be relevant in the next commits where we'll match deferred blocks by their index.

Note that the current map we have technically guarantees the insertion order in the spec, but the array is a bit more explicit.
Updates the type of the resolver function to be any `Expression` since JIT may receive a function reference rather than a `ArrowFunctionExpr`.
Updates the linker's AST host to add the ability to extract a function's parameters. This will be required for the next commits.
…data

Adds the `ɵɵngDeclareClassMetadataAsync` function that will be produced during partial compilation for component classes that have deferred dependencies. At runtime the dependencies will be resolved before setting the metadata.
Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made:
* The metadata passed into `ɵɵngDeclareComponent` has an additional field called `deferBlockDependencies` which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the `deferBlockDependencies` array.
* There's a new `ɵɵngDeclareClassMetadataAsync` function that is created for components that have deferred dependencies. It gets transpiled to `setClassMetadataAsync` and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code.
* Deferred import statements are now stripped in partial compilation mode, similar to full compilation.
@crisbeto crisbeto removed the request for review from alxhub March 20, 2024 21:52
@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 Mar 20, 2024
@dylhunn
Copy link
Contributor

dylhunn commented Mar 22, 2024

This PR was merged into the repository by commit 5bd188a.

@dylhunn dylhunn closed this in 36de5c3 Mar 22, 2024
dylhunn pushed a commit that referenced this pull request Mar 22, 2024
Updates the type of the resolver function to be any `Expression` since JIT may receive a function reference rather than a `ArrowFunctionExpr`.

PR Close #54908
dylhunn pushed a commit that referenced this pull request Mar 22, 2024
…#54908)

Updates the linker's AST host to add the ability to extract a function's parameters. This will be required for the next commits.

PR Close #54908
dylhunn pushed a commit that referenced this pull request Mar 22, 2024
…data (#54908)

Adds the `ɵɵngDeclareClassMetadataAsync` function that will be produced during partial compilation for component classes that have deferred dependencies. At runtime the dependencies will be resolved before setting the metadata.

PR Close #54908
dylhunn pushed a commit that referenced this pull request Mar 22, 2024
…ks (#54908)

Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made:
* The metadata passed into `ɵɵngDeclareComponent` has an additional field called `deferBlockDependencies` which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the `deferBlockDependencies` array.
* There's a new `ɵɵngDeclareClassMetadataAsync` function that is created for components that have deferred dependencies. It gets transpiled to `setClassMetadataAsync` and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code.
* Deferred import statements are now stripped in partial compilation mode, similar to full compilation.

PR Close #54908
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…n the binder (angular#54908)

Switches to tracking the deferred blocks in a flat array in the binder to ensure that their template order is maintained. This will be relevant in the next commits where we'll match deferred blocks by their index.

Note that the current map we have technically guarantees the insertion order in the spec, but the array is a bit more explicit.

PR Close angular#54908
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
Updates the type of the resolver function to be any `Expression` since JIT may receive a function reference rather than a `ArrowFunctionExpr`.

PR Close angular#54908
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…angular#54908)

Updates the linker's AST host to add the ability to extract a function's parameters. This will be required for the next commits.

PR Close angular#54908
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…data (angular#54908)

Adds the `ɵɵngDeclareClassMetadataAsync` function that will be produced during partial compilation for component classes that have deferred dependencies. At runtime the dependencies will be resolved before setting the metadata.

PR Close angular#54908
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…ks (angular#54908)

Builds on top of the previous changes to add support for deferred blocks during partial compilation. To do this, the following changes had to be made:
* The metadata passed into `ɵɵngDeclareComponent` has an additional field called `deferBlockDependencies` which has an array of the dependency loading functions for each defer block in the template. During linking, the dependency functions are loaded by matching their template index to the index in the `deferBlockDependencies` array.
* There's a new `ɵɵngDeclareClassMetadataAsync` function that is created for components that have deferred dependencies. It gets transpiled to `setClassMetadataAsync` and works in the same way by capturing a dependency loading function and setting the metadata after the dependencies are resolved. It also has some extra fields for capturing the version which are standard in linker-generated code.
* Deferred import statements are now stripped in partial compilation mode, similar to full compilation.

PR Close angular#54908
@angular-automatic-lock-bot
Copy link

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 Apr 22, 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 detected: feature PR contains a feature commit target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants