-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
[compiler][hir-rewrite] Check mutability of base identifier when hoisting #31032
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
28aa315
Update (base update)
mofeiZ 15336c5
Update
mofeiZ bc2aa2b
Update (base update)
mofeiZ 2d5f234
Update
mofeiZ e001896
Update (base update)
mofeiZ 5633275
Update
mofeiZ 5db4684
Update (base update)
mofeiZ dfb45e2
Update
mofeiZ 3c847f6
Update (base update)
mofeiZ 90f7b5e
Update
mofeiZ 6dfd20a
Update (base update)
mofeiZ d9c0dc6
Update
mofeiZ ee44b6a
Update (base update)
mofeiZ 0735db9
Update
mofeiZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...r/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject: {value: {inner: number}} | null) { | ||
const y = []; | ||
try { | ||
y.push(identity(maybeNullObject.value.inner)); | ||
} catch { | ||
y.push('null'); | ||
} | ||
|
||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {value: 2}, {value: 3}, null], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { identity } from "shared-runtime"; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject) { | ||
const $ = _c(2); | ||
let y; | ||
if ($[0] !== maybeNullObject.value.inner) { | ||
y = []; | ||
try { | ||
y.push(identity(maybeNullObject.value.inner)); | ||
} catch { | ||
y.push("null"); | ||
} | ||
$[0] = maybeNullObject.value.inner; | ||
$[1] = y; | ||
} else { | ||
y = $[1]; | ||
} | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, { value: 2 }, { value: 3 }, null], | ||
}; | ||
|
||
``` | ||
|
22 changes: 22 additions & 0 deletions
22
...gin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject: {value: {inner: number}} | null) { | ||
const y = []; | ||
try { | ||
y.push(identity(maybeNullObject.value.inner)); | ||
} catch { | ||
y.push('null'); | ||
} | ||
|
||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {value: 2}, {value: 3}, null], | ||
}; |
79 changes: 79 additions & 0 deletions
79
...ompiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enablePropagateDepsInHIR | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject: {value: {inner: number}} | null) { | ||
const y = []; | ||
try { | ||
y.push(identity(maybeNullObject.value.inner)); | ||
} catch { | ||
y.push('null'); | ||
} | ||
|
||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {value: 2}, {value: 3}, null], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
import { identity } from "shared-runtime"; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject) { | ||
const $ = _c(4); | ||
let y; | ||
if ($[0] !== maybeNullObject) { | ||
y = []; | ||
try { | ||
let t0; | ||
if ($[2] !== maybeNullObject.value.inner) { | ||
t0 = identity(maybeNullObject.value.inner); | ||
$[2] = maybeNullObject.value.inner; | ||
$[3] = t0; | ||
} else { | ||
t0 = $[3]; | ||
} | ||
y.push(t0); | ||
} catch { | ||
y.push("null"); | ||
} | ||
$[0] = maybeNullObject; | ||
$[1] = y; | ||
} else { | ||
y = $[1]; | ||
} | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, { value: 2 }, { value: 3 }, null], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) ["null"] | ||
[null] | ||
[null] | ||
["null"] |
23 changes: 23 additions & 0 deletions
23
...ests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @enablePropagateDepsInHIR | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Not safe to hoist read of maybeNullObject.value.inner outside of the | ||
* try-catch block, as that might throw | ||
*/ | ||
function useFoo(maybeNullObject: {value: {inner: number}} | null) { | ||
const y = []; | ||
try { | ||
y.push(identity(maybeNullObject.value.inner)); | ||
} catch { | ||
y.push('null'); | ||
} | ||
|
||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [null], | ||
sequentialRenders: [null, {value: 2}, {value: 3}, null], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,9 @@ import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | |
const { throwInput } = require("shared-runtime"); | ||
|
||
function Component(props) { | ||
const $ = _c(2); | ||
const $ = _c(3); | ||
let x; | ||
if ($[0] !== props) { | ||
if ($[0] !== props.y || $[1] !== props.e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that we're now inferring |
||
try { | ||
const y = []; | ||
y.push(props.y); | ||
|
@@ -44,10 +44,11 @@ function Component(props) { | |
e.push(props.e); | ||
x = e; | ||
} | ||
$[0] = props; | ||
$[1] = x; | ||
$[0] = props.y; | ||
$[1] = props.e; | ||
$[2] = x; | ||
} else { | ||
x = $[1]; | ||
x = $[2]; | ||
} | ||
return x; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug repro is unrelated to this fix