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): incorrectly generating shared pure function between null and object literal #35481

Closed

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 16, 2020

In #33705 we made it so that we generate pure functions for object/array literals in order to avoid having them be shared across elements/views. The problem this introduced is that further down the line the ContantPool uses the generated literal in order to figure out whether to share an existing factory or to create a new one. ConstantPool determines whether to share a factory by creating a key from the AST node and using it to look it up in the factory cache, however the key generation function didn't handle function invocations and replaced them with null. This means that the key for {foo: pureFunction0(...)} and {foo: null} are the same.

These changes rework the logic so that instead of generating a null key for function invocations, we generate a variable called <unknown> which shouldn't be able to collide with anything.

Fixes #35298.

@crisbeto crisbeto force-pushed the 35298/pure-function-null-shared branch 3 times, most recently from 2e2cdd1 to 5c54e91 Compare February 16, 2020 11:49
@crisbeto crisbeto added comp: ivy action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release type: bug/fix labels Feb 16, 2020
@ngbot ngbot bot added this to the needsTriage milestone Feb 16, 2020
@crisbeto crisbeto marked this pull request as ready for review February 16, 2020 12:10
@pullapprove pullapprove bot requested a review from kara February 16, 2020 12:10
@Component({
template: `
<div [dir]="{foo: null}"></div>
<div [dir]="{foo: getFoo()}"></div>
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 think this one has been an issue even before #33705, but we just never hit it.

packages/compiler/src/constant_pool.ts Outdated Show resolved Hide resolved
@crisbeto crisbeto force-pushed the 35298/pure-function-null-shared branch from db86429 to f95ca65 Compare February 19, 2020 21:49
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.

Please update the commit message as well - it's now out of date since the changes we made yesterday :-)

packages/compiler/src/constant_pool.ts Outdated Show resolved Hide resolved
…d object literal

In angular#33705 we made it so that we generate pure functions for object/array literals in order to avoid having them be shared across elements/views. The problem this introduced is that further down the line the `ContantPool` uses the generated literal in order to figure out whether to share an existing factory or to create a new one. `ConstantPool` determines whether to share a factory by creating a key from the AST node and using it to look it up in the factory cache, however the key generation function didn't handle function invocations and replaced them with `null`. This means that the key for `{foo: pureFunction0(...)}` and `{foo: null}` are the same.

These changes rework the logic so that instead of generating a `null` key
for function invocations, we generate a variable called `<unknown>` which
shouldn't be able to collide with anything.

Fixes angular#35298.
@crisbeto crisbeto force-pushed the 35298/pure-function-null-shared branch from f95ca65 to b87b90f Compare February 20, 2020 17:26
@crisbeto crisbeto 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 Feb 20, 2020
@mhevery
Copy link
Contributor

mhevery commented Feb 20, 2020

presubmit

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the detailed commit message! :)

mhevery pushed a commit that referenced this pull request Feb 20, 2020
…d object literal (#35481)

In #33705 we made it so that we generate pure functions for object/array literals in order to avoid having them be shared across elements/views. The problem this introduced is that further down the line the `ContantPool` uses the generated literal in order to figure out whether to share an existing factory or to create a new one. `ConstantPool` determines whether to share a factory by creating a key from the AST node and using it to look it up in the factory cache, however the key generation function didn't handle function invocations and replaced them with `null`. This means that the key for `{foo: pureFunction0(...)}` and `{foo: null}` are the same.

These changes rework the logic so that instead of generating a `null` key
for function invocations, we generate a variable called `<unknown>` which
shouldn't be able to collide with anything.

Fixes #35298.

PR Close #35481
@mhevery mhevery closed this in 22786c8 Feb 20, 2020
@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 Mar 22, 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 action: presubmit The PR is in need of a google3 presubmit cla: yes 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.

Angular 9 confuses literal null with undefined when wrapped in object in input
5 participants