Repository navigation
fix(ivy): reuse compilation scope for incremental template changes. #31932
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,14 @@ import {Reference} from '../../imports'; | |
| import {DirectiveMeta, MetadataReader, MetadataRegistry, NgModuleMeta, PipeMeta} from '../../metadata'; | ||
| import {DependencyTracker} from '../../partial_evaluator'; | ||
| import {ClassDeclaration} from '../../reflection'; | ||
| import {ComponentScopeReader, ComponentScopeRegistry, LocalModuleScope} from '../../scope'; | ||
| import {ResourceDependencyRecorder} from '../../util/src/resource_recorder'; | ||
|
|
||
| /** | ||
| * Accumulates state between compilations. | ||
| */ | ||
| export class IncrementalState implements DependencyTracker, MetadataReader, MetadataRegistry, | ||
| ResourceDependencyRecorder { | ||
| ResourceDependencyRecorder, ComponentScopeRegistry, ComponentScopeReader { | ||
| private constructor( | ||
| private unchangedFiles: Set<ts.SourceFile>, | ||
| private metadata: Map<ts.SourceFile, FileMetadata>, | ||
|
|
@@ -69,32 +70,56 @@ export class IncrementalState implements DependencyTracker, MetadataReader, Meta | |
| } | ||
|
|
||
| getFileDependencies(file: ts.SourceFile): ts.SourceFile[] { | ||
| const meta = this.metadata.get(file); | ||
| return meta ? Array.from(meta.fileDependencies) : []; | ||
| if (!this.metadata.has(file)) { | ||
| return []; | ||
| } | ||
| const meta = this.metadata.get(file) !; | ||
| return Array.from(meta.fileDependencies); | ||
| } | ||
|
|
||
| getNgModuleMetadata(ref: Reference<ClassDeclaration>): NgModuleMeta|null { | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) || null; | ||
| return metadata && metadata.ngModuleMeta.get(ref.node) || null; | ||
| if (!this.metadata.has(ref.node.getSourceFile())) { | ||
| return null; | ||
| } | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) !; | ||
| if (!metadata.ngModuleMeta.has(ref.node)) { | ||
| return null; | ||
| } | ||
| return metadata.ngModuleMeta.get(ref.node) !; | ||
| } | ||
|
|
||
| registerNgModuleMetadata(meta: NgModuleMeta): void { | ||
| const metadata = this.ensureMetadata(meta.ref.node.getSourceFile()); | ||
| metadata.ngModuleMeta.set(meta.ref.node, meta); | ||
| } | ||
|
|
||
| getDirectiveMetadata(ref: Reference<ClassDeclaration>): DirectiveMeta|null { | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) || null; | ||
| return metadata && metadata.directiveMeta.get(ref.node) || null; | ||
| if (!this.metadata.has(ref.node.getSourceFile())) { | ||
| return null; | ||
| } | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) !; | ||
| if (!metadata.directiveMeta.has(ref.node)) { | ||
| return null; | ||
| } | ||
| return metadata.directiveMeta.get(ref.node) !; | ||
| } | ||
|
|
||
| registerDirectiveMetadata(meta: DirectiveMeta): void { | ||
| const metadata = this.ensureMetadata(meta.ref.node.getSourceFile()); | ||
| metadata.directiveMeta.set(meta.ref.node, meta); | ||
| } | ||
|
|
||
| getPipeMetadata(ref: Reference<ClassDeclaration>): PipeMeta|null { | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) || null; | ||
| return metadata && metadata.pipeMeta.get(ref.node) || null; | ||
| if (!this.metadata.has(ref.node.getSourceFile())) { | ||
| return null; | ||
| } | ||
| const metadata = this.metadata.get(ref.node.getSourceFile()) !; | ||
| if (!metadata.pipeMeta.has(ref.node)) { | ||
| return null; | ||
| } | ||
| return metadata.pipeMeta.get(ref.node) !; | ||
| } | ||
|
|
||
| registerPipeMetadata(meta: PipeMeta): void { | ||
| const metadata = this.ensureMetadata(meta.ref.node.getSourceFile()); | ||
| metadata.pipeMeta.set(meta.ref.node, meta); | ||
|
|
@@ -105,6 +130,40 @@ export class IncrementalState implements DependencyTracker, MetadataReader, Meta | |
| metadata.resourcePaths.add(resourcePath); | ||
| } | ||
|
|
||
| registerComponentScope(clazz: ClassDeclaration, scope: LocalModuleScope): void { | ||
| const metadata = this.ensureMetadata(clazz.getSourceFile()); | ||
| metadata.componentScope.set(clazz, scope); | ||
| } | ||
|
|
||
| getScopeForComponent(clazz: ClassDeclaration): LocalModuleScope|null { | ||
| if (!this.metadata.has(clazz.getSourceFile())) { | ||
| return null; | ||
| } | ||
| const metadata = this.metadata.get(clazz.getSourceFile()) !; | ||
| if (!metadata.componentScope.has(clazz)) { | ||
| return null; | ||
| } | ||
| return metadata.componentScope.get(clazz) !; | ||
| } | ||
|
|
||
| setComponentAsRequiringRemoteScoping(clazz: ClassDeclaration): void { | ||
| const metadata = this.ensureMetadata(clazz.getSourceFile()); | ||
| metadata.remoteScoping.add(clazz); | ||
| } | ||
|
|
||
| getRequiresRemoteScope(clazz: ClassDeclaration): boolean|null { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you file a JIRA and add a Remote scoping is gonna be tricky. If a component requires remote scoping, it means that the component's template changing requires the module to be re-emitted. Also, we need to make sure the cycle detector works well across rebuilds. Incremental compilation is ugly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // TODO: https://angular-team.atlassian.net/browse/FW-1501 | ||
| // Handle the incremental build case where a component requires remote scoping. | ||
| // This means that if the the component's template changes, it requires the module to be | ||
| // re-emitted. | ||
| // Also, we need to make sure the cycle detector works well across rebuilds. | ||
| if (!this.metadata.has(clazz.getSourceFile())) { | ||
| return null; | ||
| } | ||
| const metadata = this.metadata.get(clazz.getSourceFile()) !; | ||
| return metadata.remoteScoping.has(clazz); | ||
| } | ||
|
|
||
| private ensureMetadata(sf: ts.SourceFile): FileMetadata { | ||
| const metadata = this.metadata.get(sf) || new FileMetadata(); | ||
| this.metadata.set(sf, metadata); | ||
|
|
@@ -131,4 +190,6 @@ class FileMetadata { | |
| directiveMeta = new Map<ClassDeclaration, DirectiveMeta>(); | ||
| ngModuleMeta = new Map<ClassDeclaration, NgModuleMeta>(); | ||
| pipeMeta = new Map<ClassDeclaration, PipeMeta>(); | ||
| componentScope = new Map<ClassDeclaration, LocalModuleScope>(); | ||
| remoteScoping = new Set<ClassDeclaration>(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google Inc. All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
| import {ClassDeclaration} from '../../reflection'; | ||
| import {LocalModuleScope} from './local'; | ||
|
|
||
| /** | ||
| * Register information about the compilation scope of components. | ||
| */ | ||
| export interface ComponentScopeRegistry { | ||
| registerComponentScope(clazz: ClassDeclaration, scope: LocalModuleScope): void; | ||
| setComponentAsRequiringRemoteScoping(clazz: ClassDeclaration): void; | ||
| } | ||
|
|
||
| /** | ||
| * Read information about the compilation scope of components. | ||
| */ | ||
| export interface ComponentScopeReader { | ||
| getScopeForComponent(clazz: ClassDeclaration): LocalModuleScope|null; | ||
| getRequiresRemoteScope(clazz: ClassDeclaration): boolean|null; | ||
| } | ||
|
|
||
| /** | ||
| * A noop registry that doesn't do anything. | ||
| * | ||
| * This can be used in tests and cases where we don't care about the compilation scopes | ||
| * being registered. | ||
| */ | ||
| export class NoopComponentScopeRegistry implements ComponentScopeRegistry { | ||
| registerComponentScope(clazz: ClassDeclaration, scope: LocalModuleScope): void {} | ||
| setComponentAsRequiringRemoteScoping(clazz: ClassDeclaration): void {} | ||
| } | ||
|
|
||
| /** | ||
| * A `ComponentScopeReader` that reads from an ordered set of child readers until it obtains the | ||
| * requested scope. | ||
| * | ||
| * This is used to combine `ComponentScopeReader`s that read from different sources (e.g. from a | ||
| * registry and from the incremental state). | ||
| */ | ||
| export class CompoundComponentScopeReader implements ComponentScopeReader { | ||
| constructor(private readers: ComponentScopeReader[]) {} | ||
|
|
||
| getScopeForComponent(clazz: ClassDeclaration): LocalModuleScope|null { | ||
| for (const reader of this.readers) { | ||
| const meta = reader.getScopeForComponent(clazz); | ||
| if (meta !== null) { | ||
| return meta; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| getRequiresRemoteScope(clazz: ClassDeclaration): boolean|null { | ||
| for (const reader of this.readers) { | ||
| const requiredScoping = reader.getRequiresRemoteScope(clazz); | ||
| if (requiredScoping !== null) { | ||
| return requiredScoping; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.