-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Tree-Shakeable Tokens #22005
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
Tree-Shakeable Tokens #22005
Conversation
You can preview a87b87b at https://pr22005-a87b87b.ngbuilds.io/. |
1a952ae
to
c9bf452
Compare
You can preview 1a952ae at https://pr22005-1a952ae.ngbuilds.io/. |
You can preview c9bf452 at https://pr22005-c9bf452.ngbuilds.io/. |
c9bf452
to
16fdc6d
Compare
You can preview 16fdc6d at https://pr22005-16fdc6d.ngbuilds.io/. |
16fdc6d
to
440b225
Compare
You can preview 440b225 at https://pr22005-440b225.ngbuilds.io/. |
440b225
to
49c7e69
Compare
You can preview 49c7e69 at https://pr22005-49c7e69.ngbuilds.io/. |
...injectables.map( | ||
ref => ({ | ||
summary: this._metadataResolver.getInjectableSummary(ref.symbol) !, | ||
metadata: this._metadataResolver.getInjectableSummary(ref.symbol) !.type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was here before, but do we really need to make this call twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be tricky to unify these two, and for symmetry with the calls above I'm okay with the duplication. getInjectableSummary
has a cache.
packages/core/src/di/injector.ts
Outdated
if (_currentInjector === null) { | ||
throw new Error(`inject() must be called from an injection context`); | ||
} | ||
return _currentInjector !.get(token, notFoundValue, flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_currentInjector
should have been inferred non-null here, so the !
seems redundant.
packages/core/src/view/ng_module.ts
Outdated
data._providers[index] = UNDEFINED_VALUE; | ||
data._providers[index] = | ||
_createProviderInstance(data, data._def.providersByKey[depDef.tokenKey]); | ||
return data._providers[index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well return the above assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
49c7e69
to
2e39934
Compare
You can preview 2e39934 at https://pr22005-2e39934.ngbuilds.io/. |
2e39934
to
41f5007
Compare
You can preview 41f5007 at https://pr22005-41f5007.ngbuilds.io/. |
41f5007
to
1fa4a6a
Compare
You can preview 1fa4a6a at https://pr22005-1fa4a6a.ngbuilds.io/. |
1fa4a6a
to
eecb54b
Compare
You can preview eecb54b at https://pr22005-eecb54b.ngbuilds.io/. |
You can preview 101c73e at https://pr22005-101c73e.ngbuilds.io/. |
You can preview a3597d8 at https://pr22005-a3597d8.ngbuilds.io/. |
a3597d8
to
04a920c
Compare
You can preview 04a920c at https://pr22005-04a920c.ngbuilds.io/. |
04a920c
to
e0341d9
Compare
You can preview e0341d9 at https://pr22005-e0341d9.ngbuilds.io/. |
e0341d9
to
aa7cfbf
Compare
You can preview aa7cfbf at https://pr22005-aa7cfbf.ngbuilds.io/. |
aa7cfbf
to
6310ba1
Compare
You can preview 24a1d4c at https://pr22005-24a1d4c.ngbuilds.io/. |
24a1d4c
to
dae8341
Compare
You can preview dae8341 at https://pr22005-dae8341.ngbuilds.io/. |
This commit bundles 3 important changes, with the goal of enabling tree-shaking of services which are never injected. Ordinarily, this tree-shaking is prevented by the existence of a hard dependency on the service by the module in which it is declared. Firstly, @Injectable() is modified to accept a 'scope' parameter, which points to an @NgModule(). This reverses the dependency edge, permitting the module to not depend on the service which it "provides". Secondly, the runtime is modified to understand the new relationship created above. When a module receives a request to inject a token, and cannot find that token in its list of providers, it will then look at the token for a special ngInjectableDef field which indicates which module the token is scoped to. If that module happens to be in the injector, it will behave as if the token itself was in the injector to begin with. Thirdly, the compiler is modified to read the @Injectable() metadata and to generate the special ngInjectableDef field as part of TS compilation, using the PartialModules system. Additionally, this commit adds several unit and integration tests of various flavors to test this change.
dae8341
to
7700d3c
Compare
You can preview 7700d3c at https://pr22005-7700d3c.ngbuilds.io/. |
This is needed so the rules produce metadata.json files, which is essential for building compiler/integration tests with Bazel. PR Close #22005
…at runtime (#22005) All of the providers in a module get compiled into a module definition in the factory file. Some of these providers are for the actual module types, as those are available for injection in Angular. For tree-shakeable tokens, the runtime needs to be able to distinguish which modules are present in an injector. This change adds a NodeFlag which tags those module providers for later identification. PR Close #22005
This commit bundles 3 important changes, with the goal of enabling tree-shaking of services which are never injected. Ordinarily, this tree-shaking is prevented by the existence of a hard dependency on the service by the module in which it is declared. Firstly, @Injectable() is modified to accept a 'scope' parameter, which points to an @NgModule(). This reverses the dependency edge, permitting the module to not depend on the service which it "provides". Secondly, the runtime is modified to understand the new relationship created above. When a module receives a request to inject a token, and cannot find that token in its list of providers, it will then look at the token for a special ngInjectableDef field which indicates which module the token is scoped to. If that module happens to be in the injector, it will behave as if the token itself was in the injector to begin with. Thirdly, the compiler is modified to read the @Injectable() metadata and to generate the special ngInjectableDef field as part of TS compilation, using the PartialModules system. Additionally, this commit adds several unit and integration tests of various flavors to test this change. PR Close #22005
@@ -3,15 +3,15 @@ | |||
"master": { | |||
"uncompressed": { | |||
"inline": 1447, | |||
"main": 154185, | |||
"main": 159944, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change (while awesome!) increased cli hello world by 5.8kb and closure hello world by 4kb. Do we understand why? Is this size increase justified? @alxhub can you please comment?
This is needed so the rules produce metadata.json files, which is essential for building compiler/integration tests with Bazel. PR Close angular#22005
…at runtime (angular#22005) All of the providers in a module get compiled into a module definition in the factory file. Some of these providers are for the actual module types, as those are available for injection in Angular. For tree-shakeable tokens, the runtime needs to be able to distinguish which modules are present in an injector. This change adds a NodeFlag which tags those module providers for later identification. PR Close angular#22005
…22005) This commit bundles 3 important changes, with the goal of enabling tree-shaking of services which are never injected. Ordinarily, this tree-shaking is prevented by the existence of a hard dependency on the service by the module in which it is declared. Firstly, @Injectable() is modified to accept a 'scope' parameter, which points to an @NgModule(). This reverses the dependency edge, permitting the module to not depend on the service which it "provides". Secondly, the runtime is modified to understand the new relationship created above. When a module receives a request to inject a token, and cannot find that token in its list of providers, it will then look at the token for a special ngInjectableDef field which indicates which module the token is scoped to. If that module happens to be in the injector, it will behave as if the token itself was in the injector to begin with. Thirdly, the compiler is modified to read the @Injectable() metadata and to generate the special ngInjectableDef field as part of TS compilation, using the PartialModules system. Additionally, this commit adds several unit and integration tests of various flavors to test this change. PR Close angular#22005
This is needed so the rules produce metadata.json files, which is essential for building compiler/integration tests with Bazel. PR Close angular#22005
…at runtime (angular#22005) All of the providers in a module get compiled into a module definition in the factory file. Some of these providers are for the actual module types, as those are available for injection in Angular. For tree-shakeable tokens, the runtime needs to be able to distinguish which modules are present in an injector. This change adds a NodeFlag which tags those module providers for later identification. PR Close angular#22005
…22005) This commit bundles 3 important changes, with the goal of enabling tree-shaking of services which are never injected. Ordinarily, this tree-shaking is prevented by the existence of a hard dependency on the service by the module in which it is declared. Firstly, @Injectable() is modified to accept a 'scope' parameter, which points to an @NgModule(). This reverses the dependency edge, permitting the module to not depend on the service which it "provides". Secondly, the runtime is modified to understand the new relationship created above. When a module receives a request to inject a token, and cannot find that token in its list of providers, it will then look at the token for a special ngInjectableDef field which indicates which module the token is scoped to. If that module happens to be in the injector, it will behave as if the token itself was in the injector to begin with. Thirdly, the compiler is modified to read the @Injectable() metadata and to generate the special ngInjectableDef field as part of TS compilation, using the PartialModules system. Additionally, this commit adds several unit and integration tests of various flavors to test this change. PR Close angular#22005
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. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information