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 b8b9de0 + d2a7be0 commit 5f8e81e
Show file tree
Hide file tree
Showing 30 changed files with 312 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,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 @@ -229,14 +229,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 @@ -299,9 +299,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 @@ -314,6 +314,7 @@ function collectNonNullsInBlocks(
const sourceNode = temporaries.get(source);
if (sourceNode != null) {
addNonNullPropertyPath(
instr.value.value.identifier,
registry.getOrCreateProperty(sourceNode),
instr.id,
knownImmutableIdentifiers,
Expand All @@ -328,6 +329,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.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
```javascript
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function Foo({a, shouldReadA}) {
return <Stringify fn={() => {
if (shouldReadA) return a.b.c;
return null;
}} shouldInvokeFns={true} />
return (
<Stringify
fn={() => {
if (shouldReadA) return a.b.c;
return null;
}}
shouldInvokeFns={true}
/>
);
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function Foo({a, shouldReadA}) {
return <Stringify fn={() => {
if (shouldReadA) return a.b.c;
return null;
}} shouldInvokeFns={true} />
return (
<Stringify
fn={() => {
if (shouldReadA) return a.b.c;
return null;
}}
shouldInvokeFns={true}
/>
);
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```javascript
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function useFoo(a) {
return <Stringify fn={() => a.b.c} shouldInvokeFns={true} />;
Expand All @@ -28,9 +28,9 @@ import { Stringify } from "shared-runtime";
function useFoo(a) {
const $ = _c(2);
let t0;
if ($[0] !== a.b.c) {
if ($[0] !== a) {
t0 = <Stringify fn={() => a.b.c} shouldInvokeFns={true} />;
$[0] = a.b.c;
$[0] = a;
$[1] = t0;
} else {
t0 = $[1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function useFoo(a) {
return <Stringify fn={() => a.b.c} shouldInvokeFns={true} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```javascript
// @enablePropagateDepsInHIR

import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';

function Foo({a, cond}) {
// Assume fn will be uncond evaluated, so we can safely evaluate {a.<any>,
Expand All @@ -21,7 +21,11 @@ function Foo({a, cond}) {
export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{a: null, cond: true}],
sequentialRenders: [{a: null, cond: true}, {a: {b: {c: 4}}, cond: true}, {a: {b: {c: 4}}, cond: true}],
sequentialRenders: [
{a: null, cond: true},
{a: {b: {c: 4}}, cond: true},
{a: {b: {c: 4}}, cond: true},
],
};

```
Expand All @@ -47,13 +51,13 @@ function Foo(t0) {
const fn = t1;
useIdentity(null);
let x;
if ($[2] !== cond || $[3] !== a.b.c) {
if ($[2] !== cond || $[3] !== a) {
x = makeArray();
if (cond) {
x.push(identity(a.b.c));
}
$[2] = cond;
$[3] = a.b.c;
$[3] = a;
$[4] = x;
} else {
x = $[4];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @enablePropagateDepsInHIR

import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';

function Foo({a, cond}) {
// Assume fn will be uncond evaluated, so we can safely evaluate {a.<any>,
Expand All @@ -17,5 +17,9 @@ function Foo({a, cond}) {
export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{a: null, cond: true}],
sequentialRenders: [{a: null, cond: true}, {a: {b: {c: 4}}, cond: true}, {a: {b: {c: 4}}, cond: true}],
sequentialRenders: [
{a: null, cond: true},
{a: {b: {c: 4}}, cond: true},
{a: {b: {c: 4}}, cond: true},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```javascript
// @enablePropagateDepsInHIR

import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';

function Foo({a, cond}) {
// Assume fn can be uncond evaluated, so we can safely evaluate a.b?.c.<any>
Expand All @@ -20,7 +20,11 @@ function Foo({a, cond}) {
export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{a: null, cond: true}],
sequentialRenders: [{a: null, cond: true}, {a: {b: {c: {d: 5}}}, cond: true}, {a: {b: null}, cond: false}],
sequentialRenders: [
{a: null, cond: true},
{a: {b: {c: {d: 5}}}, cond: true},
{a: {b: null}, cond: false},
],
};

```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @enablePropagateDepsInHIR

import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';

function Foo({a, cond}) {
// Assume fn can be uncond evaluated, so we can safely evaluate a.b?.c.<any>
Expand All @@ -16,5 +16,9 @@ function Foo({a, cond}) {
export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{a: null, cond: true}],
sequentialRenders: [{a: null, cond: true}, {a: {b: {c: {d: 5}}}, cond: true}, {a: {b: null}, cond: false}],
sequentialRenders: [
{a: null, cond: true},
{a: {b: {c: {d: 5}}}, cond: true},
{a: {b: null}, cond: false},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```javascript
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function useFoo(a) {
return <Stringify fn={() => a.b?.c.d?.e} shouldInvokeFns={true} />;
Expand All @@ -13,7 +13,13 @@ function useFoo(a) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: {b: null}}, {a: {b: {c: {d: null}}}}, , {a: {b: {c: {d: {e: 4}}}}}],
sequentialRenders: [
{a: null},
{a: {b: null}},
{a: {b: {c: {d: null}}}},
,
{a: {b: {c: {d: {e: 4}}}}},
],
};

```
Expand Down Expand Up @@ -45,6 +51,7 @@ export const FIXTURE_ENTRYPOINT = {
{ a: null },
{ a: { b: null } },
{ a: { b: { c: { d: null } } } },

,
{ a: { b: { c: { d: { e: 4 } } } } },
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @enablePropagateDepsInHIR

import { Stringify } from "shared-runtime";
import {Stringify} from 'shared-runtime';

function useFoo(a) {
return <Stringify fn={() => a.b?.c.d?.e} shouldInvokeFns={true} />;
Expand All @@ -9,5 +9,11 @@ function useFoo(a) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: {b: null}}, {a: {b: {c: {d: null}}}}, , {a: {b: {c: {d: {e: 4}}}}}],
sequentialRenders: [
{a: null},
{a: {b: null}},
{a: {b: {c: {d: null}}}},
,
{a: {b: {c: {d: {e: 4}}}}},
],
};
Loading

0 comments on commit 5f8e81e

Please sign in to comment.