Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
mofeiZ committed Sep 26, 2024
2 parents e1832c6 + 5095141 commit 92c6cde
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ class Tree {
}

function pushPropertyLoadNode(
node: PropertyLoadNode,
loadSource: Identifier,
loadSourceNode: PropertyLoadNode,
instrId: InstructionId,
knownImmutableIdentifiers: Set<IdentifierId>,
result: Set<PropertyLoadNode>,
): void {
const object = node.fullPath.identifier;
/**
* Since this runs *after* buildReactiveScopeTerminals, identifier mutable ranges
* are not valid with respect to current instruction id numbering.
Expand All @@ -187,14 +187,14 @@ function pushPropertyLoadNode(
* See comment at top of function for why we track known immutable identifiers.
*/
const isMutableAtInstr =
object.mutableRange.end > object.mutableRange.start + 1 &&
object.scope != null &&
inRange({id: instrId}, object.scope.range);
loadSource.mutableRange.end > loadSource.mutableRange.start + 1 &&
loadSource.scope != null &&
inRange({id: instrId}, loadSource.scope.range);
if (
!isMutableAtInstr ||
knownImmutableIdentifiers.has(node.fullPath.identifier.id)
knownImmutableIdentifiers.has(loadSourceNode.fullPath.identifier.id)
) {
let curr: PropertyLoadNode | null = node;
let curr: PropertyLoadNode | null = loadSourceNode;
while (curr != null) {
result.add(curr);
curr = curr.parent;
Expand Down Expand Up @@ -248,9 +248,9 @@ function collectNonNullsInBlocks(
identifier: instr.value.object.identifier,
path: [],
};
const propertyNode = tree.getPropertyLoadNode(source);
pushPropertyLoadNode(
propertyNode,
instr.value.object.identifier,
tree.getPropertyLoadNode(source),
instr.id,
knownImmutableIdentifiers,
assumedNonNullObjects,
Expand All @@ -263,6 +263,7 @@ function collectNonNullsInBlocks(
const sourceNode = temporaries.get(source);
if (sourceNode != null) {
pushPropertyLoadNode(
instr.value.value.identifier,
tree.getPropertyLoadNode(sourceNode),
instr.id,
knownImmutableIdentifiers,
Expand All @@ -277,6 +278,7 @@ function collectNonNullsInBlocks(
const sourceNode = temporaries.get(source);
if (sourceNode != null) {
pushPropertyLoadNode(
instr.value.object.identifier,
tree.getPropertyLoadNode(sourceNode),
instr.id,
knownImmutableIdentifiers,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

## Input

```javascript
// @enablePropagateDepsInHIR
const {throwInput} = require('shared-runtime');

function Component(props) {
let x;
try {
const y = [];
y.push(props.y);
throwInput(y);
} catch (e) {
e.push(props.e);
x = e;
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{y: 'foo', e: 'bar'}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
const { throwInput } = require("shared-runtime");

function Component(props) {
const $ = _c(2);
let x;
if ($[0] !== props) {
try {
const y = [];
y.push(props.y);
throwInput(y);
} catch (t0) {
const e = t0;
e.push(props.e);
x = e;
}
$[0] = props;
$[1] = x;
} else {
x = $[1];
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ y: "foo", e: "bar" }],
};

```
### Eval output
(kind: ok) ["foo","bar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @enablePropagateDepsInHIR
const {throwInput} = require('shared-runtime');

function Component(props) {
let x;
try {
const y = [];
y.push(props.y);
throwInput(y);
} catch (e) {
e.push(props.e);
x = e;
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{y: 'foo', e: 'bar'}],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

## Input

```javascript
// @enablePropagateDepsInHIR
const {throwInput} = require('shared-runtime');

function Component(props) {
try {
const y = [];
y.push(props.y);
throwInput(y);
} catch (e) {
e.push(props.e);
return e;
}
return null;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{y: 'foo', e: 'bar'}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
const { throwInput } = require("shared-runtime");

function Component(props) {
const $ = _c(2);
let t0;
if ($[0] !== props) {
t0 = Symbol.for("react.early_return_sentinel");
bb0: {
try {
const y = [];
y.push(props.y);
throwInput(y);
} catch (t1) {
const e = t1;
e.push(props.e);
t0 = e;
break bb0;
}
}
$[0] = props;
$[1] = t0;
} else {
t0 = $[1];
}
if (t0 !== Symbol.for("react.early_return_sentinel")) {
return t0;
}
return null;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ y: "foo", e: "bar" }],
};

```
### Eval output
(kind: ok) ["foo","bar"]
Loading

0 comments on commit 92c6cde

Please sign in to comment.