-
Notifications
You must be signed in to change notification settings - Fork 425
Eliminate child-parent read-write conflict errors #2542
Conversation
I'm not comfortable with this. I think it is fine to use the value of an outer scope variable, as it is at the time __optimize is being called, but any attempt to modify the variable after that should produce a warning. |
src/serializer/functions.js
Outdated
invariant(effects); | ||
if (effects.parentAdditionalFunction) return isParentOf(fun1, effects.parentAdditionalFunction); | ||
if (effects.parentAdditionalFunction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!== undefined
src/serializer/functions.js
Outdated
if (effects.parentAdditionalFunction) return isParentOf(fun1, effects.parentAdditionalFunction); | ||
if (effects.parentAdditionalFunction) { | ||
if (effects.parentAdditionalFunction === possibleParent) return true; | ||
return isParentOf(fun, effects.parentAdditionalFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be possibleParent instead of fun. Please add a test case that will fail with the code as it is now.
@NTillmann This doesn't change the behavior of Prepack -- it's consistent with how we deal with captured global variables, but I want to make sure that this is the behavior you want for nested functions. With this PR, we would allow:
as well as the example at the top of the page. This could produce incorrect code in the case that A more conservative assumption would be to say that we emit a Recoverable error if |
I think the combination of leaking and optimized functions is generally not working quite right (there are a few open issues related to that), so I don't expect this PR that aims at addressing #2351 to fix all that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cblappert is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Release Notes: None
This PR makes it so we no longer report conflicts for child optimized functions reading from values that their parents have written.
Couple of things for discussion:
AdditionalFunctionEffects.parentAdditionalFunction
which goes off of syntactic nesting of functions instead of nesting of__optimize
calls as in the issue. I believe basing the nesting off of__optimize
calls could lead to somewhat unintuitive results (especially considering we storeparentAdditionalFunction
inAdditionalFunctionEffects
to be the syntactic parent).I am not sure if it is needed by Instant Render @NTillmann? If it is, we may want to consider changing
AdditionalFunctionEffects.parentAdditionalFunction
to be based off of__optimize
call nesting as well for consistency.As an example a slight modification on the example above:
With this PR, we report an error. Based off of
__optimize
nesting, we would optimizeg
toreturn 46;
. I would expect to seereturn 42;
return 45;
orreturn obj.p;
in this case.Resolves #2351