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

Back patch spec #22235

Closed
wants to merge 2 commits into from
Closed

Back patch spec #22235

wants to merge 2 commits into from

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Feb 15, 2018

This PR is a WIP which provides an example how Ivy and non-Ivy code can interoperate through back patching.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[X] Other... Please describe: Compiler canonical design spec

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

@mhevery mhevery added this to Sprint Backlog in Framework via automation Feb 15, 2018
export class LibAModule {}
// END FILE: node_modules/libA/module.ts
// BEGIN FILE: node_modules/libA/module.metadata.json
// Abridged version of metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

A bridged (space between)?

Another case below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:-) Actually abridged is a word

const node_modules_libA_module_metadata = {
'LibAModule': {
refs: ["LibAComponent"],
constructorDes: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Des? Deps?

Several other cases below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// END FILE: src/main.ts

// BEGIN FILE: src/app.ngfactory.ts
function ngBackPatch_node_modules_libB_module() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it return true? The returned value is used in logical and below.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should update the code not to rely on the result of this function.

It is important that it be easy to remove everything from this function so what it be empty after the build optimizer is finished with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added : void

moduleType: AppModule,
patchedDeps: false,
create(parentInjector: Injector | null): NgModuleRef<AppModule> {
this.patchedDeps && ngBackPatch_node_modules_libB_module() && (this.patchedDeps = true);
Copy link
Contributor

Choose a reason for hiding this comment

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

!this.patchedDeps && ... rather than this.patchedDeps && ...?

Copy link
Contributor

@chuckjaz chuckjaz Feb 22, 2018

Choose a reason for hiding this comment

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

We should generate this more simply as,

if (!this.patchDeps) {
  this.patchedDeps = true;
  ngBackPatch_node_modules_libB_module();
}

which will be rewritten by uglify into something like:

!this.patchedDeps && (this.patchedDeps = true, b())

In other words, lets leave the ugly code production to uglify.

As it shouldn't matter, it is slightly safer to set this.pachedDeps = true before calling the back-patch function which would an indirect recursive loop if one exists, so I moved the set of patchedDeps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

class CompiledWithIvy {
// NORMATIVE
static ngInjectableDef = pending_pull_22005.defineInjectable(
{factory: function CompileWithIvy_Factory() { return new CompiledWithIvy(); }});
Copy link
Contributor

Choose a reason for hiding this comment

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

CompileWithIvy_Factory -> CompiledWithIvy_Factory according to the class name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

function ngPatch_node_modules_some_library_path_public_CompileWithIvy() {
/** @__BUILD_OPTIMIZER_COLOCATE__ */
(ThirdPartyClass as any).ngInjectableDef = pending_pull_22005.defineInjectable(
{factory: function CompileWithIvy_Factory() { return new ThirdPartyClass(); }});
Copy link
Contributor

Choose a reason for hiding this comment

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

CompileWithIvy_Factory -> ThirdPartyClass_Factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@vicb vicb added the area: core Issues related to the framework runtime label Feb 15, 2018
@mhevery mhevery moved this from Sprint Backlog to In progress in Framework Feb 16, 2018
@ngbot
Copy link

ngbot bot commented Feb 21, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

moduleType: AppModule,
patchedDeps: false,
create(parentInjector: Injector | null): NgModuleRef<AppModule> {
this.patchedDeps && ngBackPatch_node_modules_libB_module() && (this.patchedDeps = true);
Copy link
Contributor

@chuckjaz chuckjaz Feb 22, 2018

Choose a reason for hiding this comment

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

We should generate this more simply as,

if (!this.patchDeps) {
  this.patchedDeps = true;
  ngBackPatch_node_modules_libB_module();
}

which will be rewritten by uglify into something like:

!this.patchedDeps && (this.patchedDeps = true, b())

In other words, lets leave the ugly code production to uglify.

As it shouldn't matter, it is slightly safer to set this.pachedDeps = true before calling the back-patch function which would an indirect recursive loop if one exists, so I moved the set of patchedDeps.

}

export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = {
moduleType: AppModule,
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: This is generated in a separate module from AppModule so we import this using i0.AppModule syntax so the normative section should reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = {
moduleType: AppModule,
patchedDeps: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't actually need this as the default value of patchDeps is undefined. We should consider changing the declaration to ... & {patchedDeps?: true} and remove this explicit set to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, Done.

export const AppModuleFactory: NgModuleFactory<AppModule>&{patchedDeps: boolean} = {
moduleType: AppModule,
patchedDeps: false,
create(parentInjector: Injector | null): NgModuleRef<AppModule> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This syntax is hard for me to create. Consider changing this to a function expression create: function AppModuleFactory_Create { ... }

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

@mhevery mhevery moved this from In progress to in review in Framework Feb 28, 2018
@mhevery mhevery moved this from in review to In progress in Framework Feb 28, 2018
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Feb 28, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
@mhevery mhevery added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 1, 2018

// Simulate Imports
const i0 = {
AppModule: MyAppModule,
Copy link
Contributor

Choose a reason for hiding this comment

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

MyAppModule: MyAppModule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

ngBackPatch_node_modules_libB_module_packageAComponent();
ngBackPatch_node_modules_libB_module_packageAModule();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

// NORMATIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

function ngBackPatch_node_modules_libB_module_packageAModule(): void {
(NpmModule as any).ngInjectorDef = pending_pull_22458.defineInjector(details_elided);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

// /NORMATIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

const i0 = {
AppModule: MyAppModule,
};

Copy link
Contributor

Choose a reason for hiding this comment

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

// NORMATIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

this.patchedDeps = true;
ngBackPatch_node_modules_libB_module();
}
return details_elided;
Copy link
Contributor

Choose a reason for hiding this comment

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

// /NORMATIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

// Simulate Imports
const i0 = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change i0 to $i0$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


export const AppModuleFactory: NgModuleFactory<MyAppModule>&{patchedDeps?: true} = {
moduleType: i0.AppModule,
create: function AppModuleFactory_Create(parentInjector: Injector | null):
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be easier if you created:

type $ParentInjector$ = Injector | null;

and used that here. This allows me to cut/paste this directly instead of having to fix up the types.

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

import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef} from '../../../src/core';
import * as r3 from '../../../src/render3/index';

import {pending_pull_22458} from './small_app_spec';
Copy link
Contributor

Choose a reason for hiding this comment

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

import {pending_pull_22458 as $pending_pull_22458$} from './small_app_spec';

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

import {NgModuleFactory, NgModuleRef} from 'core';

import {Component, ContentChild, Directive, Injectable, Injector, Input, NgModule, OnDestroy, Optional, Pipe, PipeTransform, QueryList, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef} from '../../../src/core';
import * as r3 from '../../../src/render3/index';
Copy link
Contributor

Choose a reason for hiding this comment

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

import * as $r3$ from '../../src/core_rener3_private_export'; and then use the ɵ versions.

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

@mhevery mhevery changed the title WIP: Back patch Back patch spec Mar 1, 2018
@mhevery mhevery force-pushed the back_patch branch 2 times, most recently from 1aa4500 to b437bbc Compare March 1, 2018 17:08
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 1, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 1, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 1, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 1, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
@mhevery mhevery added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 2, 2018
@ngbot
Copy link

ngbot bot commented Mar 2, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure missing required label: "PR target: *"
    pending status "google3" is pending
    pending status "ci/circleci: lint" 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.

@mhevery
Copy link
Contributor Author

mhevery commented Mar 3, 2018

@mhevery mhevery added the target: major This PR is targeted for the next major release label Mar 3, 2018
@alexeagle alexeagle closed this in 363dfa5 Mar 6, 2018
Framework automation moved this from In progress to Done / Merged Mar 6, 2018
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 8, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
chuckjaz added a commit to chuckjaz/angular that referenced this pull request Mar 8, 2018
Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.
kara pushed a commit that referenced this pull request Mar 9, 2018
Produces back-patch as described in the #22235 and referenced in #22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in #22480 will be in a follow on
change.

PR Close #22506
@mhevery mhevery removed this from Done / Merged in Framework Mar 13, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
)

Produces back-patch as described in the angular#22235 and referenced in angular#22480.

This just contains the compiler implementations and the corresponding unit
tests. Connecting the dots as described in angular#22480 will be in a follow on
change.

PR Close angular#22506
@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 13, 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 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