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(ivy): avoid remote scoping if it's not actually required #29404

Closed
wants to merge 1 commit into from

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Mar 19, 2019

Currently, ngtsc decides to use remote scoping if the compilation of a
component may create a cyclic import. This happens if there are two
components in a scope (say, A and B) and A directly uses B. During
compilation of B ngtsc will then note that if B were to use A, a cycle would
be generated, and so it will opt to use remote scoping for B.

ngtsc already uses the R3TargetBinder to correctly track the imports that
are actually required, for future cycle tracking. This commit expands that
usage to not trigger remote scoping unless B actually does consume A in its
template.

@alxhub alxhub requested a review from a team as a code owner March 19, 2019 20:37
@@ -3934,6 +3967,57 @@ export const Foo = Foo__PRE_R3__;
expect(jsContents).toContain('styles: ["h1[_ngcontent-%COMP%] {font-size: larger}"]');
});
});

xit('should not suck', () => {
Copy link
Member

Choose a reason for hiding this comment

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

ROFL 🤣

Copy link
Member Author

Choose a reason for hiding this comment

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

Hahaha. That's my usual test description for reproducing bugs within the compiler's test suite.

@alxhub alxhub force-pushed the ngtsc-remote-scope branch 3 times, most recently from 2cac81f to 15d606b Compare March 19, 2019 20:51

// The BoundTarget knows which directives and pipes matched the template.
const usedDirectives = bound.getUsedDirectives();
const usedPipes = bound.getUsedPipes().map(name => pipes.get(name) !);
Copy link
Member

@JoostK JoostK Mar 19, 2019

Choose a reason for hiding this comment

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

This non-null assertion operator is actually a problem, I think. T3TargetBinder, or more specifically TemplateBinder:

visitPipe(ast: BindingPipe, context: any): any {
this.usedPipes.add(ast.name);
return super.visitPipe(ast, context);
}

tracks pipes just by name regardless of their definition. So, a missing pipe results in a miss here.

edit: aha, existing code. Still, looks error-prone to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're absolutely right. I'll file an issue to clean that up.

@mhevery mhevery added the area: core Issues related to the framework runtime label Mar 19, 2019
@ngbot ngbot bot added this to the needsTriage milestone Mar 19, 2019
// any import which needs to be generated for the directive would create a cycle.
const cycleDetected = directives.some(dir => this._isCyclicImport(dir.expression, context)) ||
Array.from(pipes.values()).some(pipe => this._isCyclicImport(pipe, context));
// Next, the component template AST is bound using the R3TargetBinder. This produces an
Copy link
Member

Choose a reason for hiding this comment

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

an --> a ✌️

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release and removed action: merge The PR is ready for merge by the caretaker labels Mar 21, 2019
Currently, ngtsc decides to use remote scoping if the compilation of a
component may create a cyclic import. This happens if there are two
components in a scope (say, A and B) and A directly uses B. During
compilation of B ngtsc will then note that if B were to use A, a cycle would
be generated, and so it will opt to use remote scoping for B.

ngtsc already uses the R3TargetBinder to correctly track the imports that
are actually required, for future cycle tracking. This commit expands that
usage to not trigger remote scoping unless B actually does consume A in its
template.
@alxhub alxhub 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 labels Apr 1, 2019
@alxhub
Copy link
Member Author

alxhub commented Apr 1, 2019

I am the approver for compiler-cli.

@jasonaden jasonaden closed this in 3e56976 Apr 1, 2019
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…#29404)

Currently, ngtsc decides to use remote scoping if the compilation of a
component may create a cyclic import. This happens if there are two
components in a scope (say, A and B) and A directly uses B. During
compilation of B ngtsc will then note that if B were to use A, a cycle would
be generated, and so it will opt to use remote scoping for B.

ngtsc already uses the R3TargetBinder to correctly track the imports that
are actually required, for future cycle tracking. This commit expands that
usage to not trigger remote scoping unless B actually does consume A in its
template.

PR Close angular#29404
@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 Sep 14, 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: core Issues related to the framework runtime cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note 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

5 participants