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): Forward refs now supported #27439

Closed
wants to merge 1 commit into from

Conversation

benlesh
Copy link
Contributor

@benlesh benlesh commented Dec 3, 2018

Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#

@benlesh benlesh requested a review from alxhub December 3, 2018 21:59
@ngbot ngbot bot added this to the needsTriage milestone Dec 3, 2018
@mary-poppins
Copy link

You can preview c572156 at https://pr27439-c572156.ngbuilds.io/.

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

This should probably be a feat(ivy) not fix(ivy) since forwardRefs were unsupported before.

Also, check if this fixes any more tests besides just this one.

for (let i = moduleQueue.length - 1; i--;) {
const {moduleType, ngModule} = moduleQueue[i];

if (ngModule.declarations && ngModule.declarations.every(isResolvedDeclaration)) {
Copy link
Member

Choose a reason for hiding this comment

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

ngModule.declarations could be nested, e.g: [[[forwardRef(() => Cmp)]]].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

@@ -19,14 +20,46 @@ import {reflectDependencies} from './util';

const EMPTY_ARRAY: Type<any>[] = [];

const moduleQueue: Array<{moduleType: Type<any>, ngModule: NgModule}> = [];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make a named type for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -51,6 +51,9 @@ export function compileComponent(type: Type<any>, metadata: Component): void {
error.push(`Did you run and wait for 'resolveComponentResources()'?`);
throw new Error(error.join('\n'));
}

flushModuleScopingQueueAsMuchAsPossible();
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment here explaining what's happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

I think this must be moved below the assignment of the compilation result of ngComponent below.

The flushModuleScopingQueueAsMuchAsPossible may find that the component can be patched. It sees that ngComponentDef is present and therefore reads it to patch its scope, which will re-enter here again. We should probably not do that, as it results in repeated compilation.

}
}

/** Returns truthy if a declaration (fron an ngModule.declarations) is resolved. */
Copy link
Member

Choose a reason for hiding this comment

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

Coerce this to boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/**
* Compiles a module in JIT mode.
*
* This function automatically gets called when a class has a `@NgModule` decorator.
*/
export function compileNgModule(moduleType: Type<any>, ngModule: NgModule = {}): void {
compileNgModuleDefs(moduleType, ngModule);
setScopeOnDeclaredComponents(moduleType, ngModule);
enqueueModuleForDelayedScoping(moduleType, ngModule);
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment here explaining what's happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@benlesh
Copy link
Contributor Author

benlesh commented Dec 3, 2018

  • Requested changes made
  • Haven't addressed CI failures yet
  • Haven't changed commit message yet (mostly to not lose comment history), will do that after approval.

@mary-poppins
Copy link

You can preview 8bc38ba at https://pr27439-8bc38ba.ngbuilds.io/.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Dec 4, 2018
@benlesh
Copy link
Contributor Author

benlesh commented Dec 4, 2018

Squashed and updated the commit message as requested... Will review CI failures once they're done running.

@mary-poppins
Copy link

You can preview 099157a at https://pr27439-099157a.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 3aded9b at https://pr27439-3aded9b.ngbuilds.io/.

@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release type: bug/fix labels Dec 4, 2018
@mary-poppins
Copy link

You can preview 11a259d at https://pr27439-11a259d.ngbuilds.io/.

@mary-poppins
Copy link

You can preview d645daf at https://pr27439-d645daf.ngbuilds.io/.

moduleQueue.slice(i, 1);
setScopeOnDeclaredComponents(moduleType, ngModule);
if (!flushingModuleQueue) {
flushingModuleQueue = true;
Copy link
Member

Choose a reason for hiding this comment

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

This dance could probably be avoided if we move flushModuleScopingQueueAsMuchAsPossible to after the completion of the ngComponentDef compilation (see #27439 (comment)). This hack is now required because ngComponentDef is not re-entrant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right about the flush needing to be moved... However, I'm going to leave this defensive check in this flush, because flushing should be idempotent.

@mary-poppins
Copy link

You can preview cf143cc at https://pr27439-cf143cc.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 3e51daf at https://pr27439-3e51daf.ngbuilds.io/.

@mary-poppins
Copy link

You can preview a2d42c1 at https://pr27439-a2d42c1.ngbuilds.io/.

@benlesh benlesh 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 Dec 5, 2018
@ngbot
Copy link

ngbot bot commented Dec 5, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "ci/circleci: test_aio_preview" is failing
    failure status "continuous-integration/travis-ci/pr" is failing
    pending forbidden labels detected: PR action: review
    pending status "code-review/pullapprove" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#
@IgorMinar
Copy link
Contributor

I've rebased and force-pushed this PR

@mary-poppins
Copy link

You can preview a39e019 at https://pr27439-a39e019.ngbuilds.io/.

@IgorMinar IgorMinar closed this in cd85832 Dec 5, 2018
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#

PR Close angular#27439
ngfelixl pushed a commit to ngfelixl/angular that referenced this pull request Jan 28, 2019
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#

PR Close angular#27439
@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 action: review The PR is still awaiting reviews from at least one requested reviewer 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 type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants