-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Lower JSXMemberExpression with LoadLocal
`JSXMemberExpression` is currently the only instruction (that I know of) that directly references identifier lvalues without a corresponding `LoadLocal`. This has some side effects: - deadcode elimination and constant propagation now reach JSXMemberExpressions - we can delete `LoweredFunction.dependencies` without dangling references (previously, the only reference to JSXMemberExpression objects in HIR was in function dependencies) - JSXMemberExpression now is consistent with all other instructions (e.g. has a rvalue-producing LoadLocal) '
- Loading branch information
Showing
14 changed files
with
299 additions
and
7 deletions.
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
75 changes: 75 additions & 0 deletions
75
...mpiler/src/__tests__/fixtures/compiler/invalid-jsx-lowercase-localvar.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,75 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {Throw} from 'shared-runtime'; | ||
|
||
/** | ||
* Note: this is disabled in the evaluator due to different devmode errors. | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: ['Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag'] | ||
* | ||
* Forget: | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: [ | ||
* 'Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag', | ||
* 'Warning: The tag <%s> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.%s','invalidTag', | ||
* ] | ||
*/ | ||
function useFoo() { | ||
const invalidTag = Throw; | ||
/** | ||
* Need to be careful to not parse `invalidTag` as a localVar (i.e. render | ||
* Throw). Note that the jsx transform turns this into a string tag: | ||
* `jsx("invalidTag"... | ||
*/ | ||
return <invalidTag val={{val: 2}} />; | ||
} | ||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { Throw } from "shared-runtime"; | ||
|
||
/** | ||
* Note: this is disabled in the evaluator due to different devmode errors. | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: ['Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag'] | ||
* | ||
* Forget: | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: [ | ||
* 'Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag', | ||
* 'Warning: The tag <%s> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.%s','invalidTag', | ||
* ] | ||
*/ | ||
function useFoo() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = <invalidTag val={{ val: 2 }} />; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
29 changes: 29 additions & 0 deletions
29
...-plugin-react-compiler/src/__tests__/fixtures/compiler/invalid-jsx-lowercase-localvar.jsx
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,29 @@ | ||
import {Throw} from 'shared-runtime'; | ||
|
||
/** | ||
* Note: this is disabled in the evaluator due to different devmode errors. | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: ['Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag'] | ||
* | ||
* Forget: | ||
* (kind: ok) <invalidtag val="[object Object]"></invalidtag> | ||
* logs: [ | ||
* 'Warning: <%s /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.%s','invalidTag', | ||
* 'Warning: The tag <%s> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.%s','invalidTag', | ||
* ] | ||
*/ | ||
function useFoo() { | ||
const invalidTag = Throw; | ||
/** | ||
* Need to be careful to not parse `invalidTag` as a localVar (i.e. render | ||
* Throw). Note that the jsx transform turns this into a string tag: | ||
* `jsx("invalidTag"... | ||
*/ | ||
return <invalidTag val={{val: 2}} />; | ||
} | ||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; |
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
59 changes: 59 additions & 0 deletions
59
...tests__/fixtures/compiler/jsx-lowercase-localvar-memberexpr-in-lambda.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,59 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import * as SharedRuntime from 'shared-runtime'; | ||
import {invoke} from 'shared-runtime'; | ||
function useComponentFactory({name}) { | ||
const localVar = SharedRuntime; | ||
const cb = () => <localVar.Stringify>hello world {name}</localVar.Stringify>; | ||
return invoke(cb); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useComponentFactory, | ||
params: [{name: 'sathya'}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import * as SharedRuntime from "shared-runtime"; | ||
import { invoke } from "shared-runtime"; | ||
function useComponentFactory(t0) { | ||
const $ = _c(4); | ||
const { name } = t0; | ||
let t1; | ||
if ($[0] !== name) { | ||
t1 = () => ( | ||
<SharedRuntime.Stringify>hello world {name}</SharedRuntime.Stringify> | ||
); | ||
$[0] = name; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
const cb = t1; | ||
let t2; | ||
if ($[2] !== cb) { | ||
t2 = invoke(cb); | ||
$[2] = cb; | ||
$[3] = t2; | ||
} else { | ||
t2 = $[3]; | ||
} | ||
return t2; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useComponentFactory, | ||
params: [{ name: "sathya" }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>{"children":["hello world ","sathya"]}</div> |
12 changes: 12 additions & 0 deletions
12
...-compiler/src/__tests__/fixtures/compiler/jsx-lowercase-localvar-memberexpr-in-lambda.jsx
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,12 @@ | ||
import * as SharedRuntime from 'shared-runtime'; | ||
import {invoke} from 'shared-runtime'; | ||
function useComponentFactory({name}) { | ||
const localVar = SharedRuntime; | ||
const cb = () => <localVar.Stringify>hello world {name}</localVar.Stringify>; | ||
return invoke(cb); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useComponentFactory, | ||
params: [{name: 'sathya'}], | ||
}; |
45 changes: 45 additions & 0 deletions
45
...ler/src/__tests__/fixtures/compiler/jsx-lowercase-localvar-memberexpr.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,45 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import * as SharedRuntime from 'shared-runtime'; | ||
function Component({name}) { | ||
const localVar = SharedRuntime; | ||
return <localVar.Stringify>hello world {name}</localVar.Stringify>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{name: 'sathya'}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import * as SharedRuntime from "shared-runtime"; | ||
function Component(t0) { | ||
const $ = _c(2); | ||
const { name } = t0; | ||
let t1; | ||
if ($[0] !== name) { | ||
t1 = <SharedRuntime.Stringify>hello world {name}</SharedRuntime.Stringify>; | ||
$[0] = name; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "sathya" }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>{"children":["hello world ","sathya"]}</div> |
10 changes: 10 additions & 0 deletions
10
...ugin-react-compiler/src/__tests__/fixtures/compiler/jsx-lowercase-localvar-memberexpr.jsx
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,10 @@ | ||
import * as SharedRuntime from 'shared-runtime'; | ||
function Component({name}) { | ||
const localVar = SharedRuntime; | ||
return <localVar.Stringify>hello world {name}</localVar.Stringify>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{name: 'sathya'}], | ||
}; |
44 changes: 44 additions & 0 deletions
44
...act-compiler/src/__tests__/fixtures/compiler/jsx-lowercase-memberexpr.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,44 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import * as SharedRuntime from 'shared-runtime'; | ||
function Component({name}) { | ||
return <SharedRuntime.Stringify>hello world {name}</SharedRuntime.Stringify>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{name: 'sathya'}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import * as SharedRuntime from "shared-runtime"; | ||
function Component(t0) { | ||
const $ = _c(2); | ||
const { name } = t0; | ||
let t1; | ||
if ($[0] !== name) { | ||
t1 = <SharedRuntime.Stringify>hello world {name}</SharedRuntime.Stringify>; | ||
$[0] = name; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "sathya" }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>{"children":["hello world ","sathya"]}</div> |
9 changes: 9 additions & 0 deletions
9
.../babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-lowercase-memberexpr.jsx
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,9 @@ | ||
import * as SharedRuntime from 'shared-runtime'; | ||
function Component({name}) { | ||
return <SharedRuntime.Stringify>hello world {name}</SharedRuntime.Stringify>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{name: 'sathya'}], | ||
}; |
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
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