Skip to content

fix(ivy): reuse compilation scope for incremental template changes. - #31932

Closed
petebacondarwin wants to merge 1 commit into
angular:masterfrom
petebacondarwin:ngtsc-incremental-resource-fix-issue-15122-a
Closed

petebacondarwin wants to merge 1 commit into
angular:masterfrom
petebacondarwin:ngtsc-incremental-resource-fix-issue-15122-a

Conversation

@petebacondarwin

Copy link
Copy Markdown
Contributor

Previously if only a component template changed then we would know to
rebuild its component source file. But the compilation was incorrect if the
component was part of an NgModule, since we were not capturing the
compilation scope information that had a been acquired from the NgModule
and was not being regenerated since we were not needing to recompile
the NgModule.

Now we register compilation scope information for each component, via the
ComponentScopeRegistry interface, so that it is available for incremental
compilation.

The ComponentDecoratorHandler now reads the compilation scope from a
ComponentScopeReader interface which is implemented as a compound
reader composed of the original LocalModuleScopeRegistry and the
IncrementalState.

Fixes #31654

@petebacondarwin petebacondarwin added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer effort1: hours severity2: inconvenient target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Jul 31, 2019
@petebacondarwin
petebacondarwin requested a review from a team July 31, 2019 16:12
@ngbot ngbot Bot added this to the needsTriage milestone Jul 31, 2019
@petebacondarwin
petebacondarwin force-pushed the ngtsc-incremental-resource-fix-issue-15122-a branch from 277e9d6 to 96062e9 Compare July 31, 2019 19:13
@petebacondarwin
petebacondarwin requested a review from a team July 31, 2019 19:13

@gkalpak gkalpak left a comment

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.

LGTM for fw-ngcc.

@petebacondarwin
petebacondarwin force-pushed the ngtsc-incremental-resource-fix-issue-15122-a branch from 96062e9 to 2dc3172 Compare July 31, 2019 21:02

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.

Use .has for map key presence and not || null

@petebacondarwin petebacondarwin Aug 6, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I think that this results in more verbose, ugly and less clear code:

  getScopeForComponent(clazz: ClassDeclaration): LocalModuleScope|null {
    const metadata = this.metadata.has(clazz.getSourceFile()) ?
        this.metadata.get(clazz.getSourceFile()) ! :
        null;
    return metadata && metadata.componentScope.has(clazz) ? metadata.componentScope.get(clazz) ! :
                                                            null;
  }

Notice the repetition and the need to use the ! operator.

I think it is fair to use has() when the type of the stored object could be falsy. But where a falsy return from get() can only mean the value was not there, then I think it is better to avoid the extra call to has().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Slightly cleaner version, which I can accept:

  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) !;
  }

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 live for the day .has() will narrow the type of a subsequent .get() 😁

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.

OOC wouldn't doing just a get be more performant anyway if you need the value? I see has for the use case of just testing whether or not a key exists without needing the actual value.

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.

Can you file a JIRA and add a TODO here...

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously if only a component template changed then we would know to
rebuild its component source file. But the compilation was incorrect if the
component was part of an NgModule, since we were not capturing the
compilation scope information that had a been acquired from the NgModule
and was not being regenerated since we were not needing to recompile
the NgModule.

Now we register compilation scope information for each component, via the
`ComponentScopeRegistry` interface, so that it is available for incremental
compilation.

The `ComponentDecoratorHandler` now reads the compilation scope from a
`ComponentScopeReader` interface which is implemented as a compound
reader composed of the original `LocalModuleScopeRegistry` and the
`IncrementalState`.

Fixes angular#31654
@petebacondarwin
petebacondarwin force-pushed the ngtsc-incremental-resource-fix-issue-15122-a branch from 55ae1cf to d643043 Compare August 6, 2019 14:03
@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 8, 2019
@AndrewKushnir

Copy link
Copy Markdown
Contributor

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Aug 9, 2019
@kara kara closed this in eb5412d Aug 9, 2019
@petebacondarwin
petebacondarwin deleted the ngtsc-incremental-resource-fix-issue-15122-a branch August 11, 2019 16:56
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
…ngular#31932)

Previously if only a component template changed then we would know to
rebuild its component source file. But the compilation was incorrect if the
component was part of an NgModule, since we were not capturing the
compilation scope information that had a been acquired from the NgModule
and was not being regenerated since we were not needing to recompile
the NgModule.

Now we register compilation scope information for each component, via the
`ComponentScopeRegistry` interface, so that it is available for incremental
compilation.

The `ComponentDecoratorHandler` now reads the compilation scope from a
`ComponentScopeReader` interface which is implemented as a compound
reader composed of the original `LocalModuleScopeRegistry` and the
`IncrementalState`.

Fixes angular#31654

PR Close angular#31932
@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 Sep 15, 2019
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 cla: yes effort1: hours target: major This PR is targeted for the next major release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng serve in Ivy mode is dropping directives list when editing a template

6 participants