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

fix(ngcc): switch ngcc over to use the TraitCompiler #34889

Closed
wants to merge 3 commits into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented Jan 21, 2020

fix(ngcc): do not attempt compilation when analysis fails

In #34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata—due to errors in earlier phases—to be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's TraitCompiler,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own AnalyzedFile and
AnalyzedClass types, together with all of the logic to drive the
DecoratorHandlers. All of this is now handled in the TraitCompiler,
benefiting from its explicit state transitions of Traits so that the
ngcc crash is a thing of the past.

Fixes #34500
Resolves FW-1788

@JoostK JoostK added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer severity3: broken target: patch This PR is targeted for the next patch release risk: medium labels Jan 21, 2020
@ngbot ngbot bot added this to the needsTriage milestone Jan 21, 2020
@JoostK
Copy link
Member Author

JoostK commented Jan 21, 2020

This PR is a replacement for #34652, with a different approach. Instead of making use of the Trait types from within ngcc, this change goes one step further to drive the compilation using the TraitCompiler. The benefit of this is that the protocol around the calling of DecoratorHandlers isn't duplicated between ngtsc and ngcc, with the drawback of introducing a larger diff with more risk involved.

@JoostK JoostK marked this pull request as ready for review January 23, 2020 06:26
@JoostK JoostK requested review from a team as code owners January 23, 2020 06:26
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Nice refactoring! It is great to see so much code removed from ngcc.
Can you add the NgccTraitCompiler spec and simplify the DefaultMigrationHost spec as mentioned below.
Otherwise LGTM!

import {createComponentDecorator} from '../../src/migrations/utils';
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
import {MockLogger} from '../helpers/mock_logger';
import {makeTestEntryPointBundle} from '../helpers/utils';

runInEachFileSystem(() => {
describe('DefaultMigrationHost', () => {
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me that most of this spec file is actually testing the NgccTraitCompiler. The DefaultMigrationHost mostly just delegates to that.

How about simplifying this spec just to check that the delegation occurs as expected, and then create a spec for NgccTraitCompiler that exercises the tests here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm really not fond of testing just delegation behaviour, as doing so starts to be testing an implementation rather than some desired behaviour. I do see however where you're coming from here, and have moved most of the injectSyntheticDecorator and getAllDecorators tests to an NgccTraitCompiler spec file, while retaining some in the DefaultMigrationHost specs to test the logic in the context of the migration host.

This syntax is invalid in these source files and does result in
compilation errors as the constructor parameters could not be resolved.
This hasn't been an issue until now as those errors were ignored in the
tests, but future work to introduce the Trait system of ngtsc into
ngcc will cause these errors to prevent compilation, resulting in broken
tests.
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata—due to errors in earlier phases—to be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes angular#34500
Resolves FW-1788
JoostK added a commit to JoostK/ngcc-validation that referenced this pull request Jan 23, 2020
JoostK added a commit to JoostK/ngcc-validation that referenced this pull request Jan 23, 2020
JoostK added a commit to JoostK/ngcc-validation that referenced this pull request Jan 23, 2020
@JoostK
Copy link
Member Author

JoostK commented Jan 23, 2020

This is green on CI: angular/ngcc-validation#792

@petebacondarwin PTAL

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Grand!

@JoostK JoostK added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 23, 2020
@JoostK JoostK added the action: presubmit The PR is in need of a google3 presubmit label Jan 23, 2020
@JoostK
Copy link
Member Author

JoostK commented Jan 23, 2020

merge-assistence: Alex has approved on behalf of fw-compiler when it was still draft.

@AndrewKushnir
Copy link
Contributor

Presubmit

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Jan 23, 2020
AndrewKushnir pushed a commit that referenced this pull request Jan 23, 2020
In #34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata—due to errors in earlier phases—to be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes #34500
Resolves FW-1788

PR Close #34889
AndrewKushnir pushed a commit that referenced this pull request Jan 23, 2020
…34889)

This syntax is invalid in these source files and does result in
compilation errors as the constructor parameters could not be resolved.
This hasn't been an issue until now as those errors were ignored in the
tests, but future work to introduce the Trait system of ngtsc into
ngcc will cause these errors to prevent compilation, resulting in broken
tests.

PR Close #34889
AndrewKushnir pushed a commit that referenced this pull request Jan 23, 2020
In #34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata—due to errors in earlier phases—to be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes #34500
Resolves FW-1788

PR Close #34889
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
…ngular#34889)

This syntax is invalid in these source files and does result in
compilation errors as the constructor parameters could not be resolved.
This hasn't been an issue until now as those errors were ignored in the
tests, but future work to introduce the Trait system of ngtsc into
ngcc will cause these errors to prevent compilation, resulting in broken
tests.

PR Close angular#34889
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
)

In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata—due to errors in earlier phases—to be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes angular#34500
Resolves FW-1788

PR Close angular#34889
@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 Feb 23, 2020
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 cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: medium target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngcc: packages that fail with errors causes a crash
5 participants