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): constant object literals shared across element and component instances #33705

Closed

Conversation

@crisbeto
Copy link
Member

crisbeto commented Nov 9, 2019

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the consts array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the consts.

These changes also:

  • Fix an issue that meant that the pureFunction0 instruction could only be run during creation mode.
  • Make the getConstant utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.
@googlebot googlebot added the cla: yes label Nov 9, 2019
@crisbeto crisbeto marked this pull request as ready for review Nov 9, 2019
@crisbeto crisbeto requested review from angular/fw-compiler as code owners Nov 9, 2019
@ngbot ngbot bot modified the milestone: needsTriage Nov 9, 2019
@mhevery

This comment has been minimized.

Copy link
Member

mhevery commented Nov 12, 2019

@kara
kara approved these changes Nov 13, 2019
Copy link
Contributor

kara left a comment

LGTM once comments are updated

packages/compiler/src/render3/view/template.ts Outdated Show resolved Hide resolved
packages/compiler/src/render3/view/template.ts Outdated Show resolved Hide resolved
…t instances

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

```
<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>
```

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the `consts` array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the `consts`.

These changes also:
* Fix an issue that meant that the `pureFunction0` instruction could only be run during creation mode.
* Make the `getConstant` utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.
@crisbeto crisbeto force-pushed the crisbeto:FW-1633/shared-object-literals branch from 2a5ad2e to 221bdf5 Nov 13, 2019
@crisbeto

This comment has been minimized.

Copy link
Member Author

crisbeto commented Nov 13, 2019

Rebased and updated the comments.

@kara kara closed this in fcdada5 Nov 13, 2019
kara added a commit that referenced this pull request Nov 13, 2019
…t instances (#33705)

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

```
<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>
```

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the `consts` array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the `consts`.

These changes also:
* Fix an issue that meant that the `pureFunction0` instruction could only be run during creation mode.
* Make the `getConstant` utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.

PR Close #33705
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.