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 e5e5d6b + 6bd365f commit b90b8b0
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 @@ -185,12 +185,12 @@ class PropertyPathRegistry {
}

function addNonNullPropertyPath(
node: PropertyPathNode,
source: Identifier,
sourceNode: PropertyPathNode,
instrId: InstructionId,
knownImmutableIdentifiers: Set<IdentifierId>,
result: Set<PropertyPathNode>,
): 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 @@ -202,14 +202,14 @@ function addNonNullPropertyPath(
* 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);
source.mutableRange.end > source.mutableRange.start + 1 &&
source.scope != null &&
inRange({id: instrId}, source.scope.range);
if (
!isMutableAtInstr ||
knownImmutableIdentifiers.has(node.fullPath.identifier.id)
knownImmutableIdentifiers.has(sourceNode.fullPath.identifier.id)
) {
result.add(node);
result.add(sourceNode);
}
}

Expand Down Expand Up @@ -259,9 +259,9 @@ function collectNonNullsInBlocks(
identifier: instr.value.object.identifier,
path: [],
};
const propertyNode = registry.getOrCreateProperty(source);
addNonNullPropertyPath(
propertyNode,
instr.value.object.identifier,
registry.getOrCreateProperty(source),
instr.id,
knownImmutableIdentifiers,
assumedNonNullObjects,
Expand All @@ -274,6 +274,7 @@ function collectNonNullsInBlocks(
const sourceNode = temporaries.get(source);
if (sourceNode != null) {
addNonNullPropertyPath(
instr.value.value.identifier,
registry.getOrCreateProperty(sourceNode),
instr.id,
knownImmutableIdentifiers,
Expand All @@ -288,6 +289,7 @@ function collectNonNullsInBlocks(
const sourceNode = temporaries.get(source);
if (sourceNode != null) {
addNonNullPropertyPath(
instr.value.object.identifier,
registry.getOrCreateProperty(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 b90b8b0

Please sign in to comment.