Update (base update)

[ghstack-poisoned]
This commit is contained in:
Mofei Zhang
2024-10-02 12:53:57 -04:00
parent 3c847f64a4
commit 6dfd20a728
7 changed files with 74 additions and 26 deletions
@@ -279,16 +279,11 @@ function collectNonNullsInBlocks(
knownNonNullIdentifiers,
);
nodes.set(block.id, {
block,
assumedNonNullObjects,
});
const maybeOptionalChain = hoistableFromOptionals.get(block.id);
if (maybeOptionalChain != null) {
assumedNonNullObjects.add(
registry.getOrCreateProperty(maybeOptionalChain),
);
continue;
}
for (const instr of block.instructions) {
if (instr.value.kind === 'PropertyLoad') {
@@ -329,6 +324,11 @@ function collectNonNullsInBlocks(
}
}
}
nodes.set(block.id, {
block,
assumedNonNullObjects,
});
}
return nodes;
}
@@ -1,5 +1,4 @@
import {CompilerError} from '..';
import {arrayNonNulls} from '../Utils/utils';
import {assertNonNull} from './CollectHoistablePropertyLoads';
import {
BlockId,
@@ -15,6 +14,7 @@ import {
TBasicBlock,
OptionalTerminal,
HIRFunction,
DependencyPathEntry,
} from './HIR';
import {printIdentifier} from './PrintHIR';
@@ -237,20 +237,18 @@ function traverseOptionalBlock(
) {
return null;
}
const path = maybeTest.instructions.slice(1).map((entry, i) => {
const instrVal = entry.value;
const prevEntry = maybeTest.instructions[i];
const path: Array<DependencyPathEntry> = [];
for (let i = 1; i < maybeTest.instructions.length; i++) {
const instrVal = maybeTest.instructions[i].value;
const prevInstr = maybeTest.instructions[i - 1];
if (
instrVal.kind === 'PropertyLoad' &&
instrVal.object.identifier.id === prevEntry.lvalue.identifier.id
instrVal.object.identifier.id === prevInstr.lvalue.identifier.id
) {
return {property: instrVal.property, optional: false};
path.push({property: instrVal.property, optional: false});
} else {
return null;
}
});
if (!arrayNonNulls(path)) {
return null;
}
CompilerError.invariant(
maybeTest.terminal.test.identifier.id ===
@@ -139,12 +139,6 @@ export function nonNull<T extends NonNullable<U>, U>(
return value != null;
}
export function arrayNonNulls<T extends NonNullable<U>, U>(
arr: Array<T | null | undefined>,
): arr is Array<T> {
return arr.every(e => e != null);
}
export function Set_filter<T>(
source: ReadonlySet<T>,
fn: (arg: T) => boolean,
@@ -12,7 +12,15 @@ function useFoo({a}) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: null}, {a: {}}],
sequentialRenders: [
{a: null},
{a: null},
{a: {}},
{a: {b: {c: {d: {e: 42}}}}},
{a: {b: {c: {d: {e: 43}}}}},
{a: {b: {c: {d: {e: undefined}}}}},
{a: {b: undefined}},
],
};
```
@@ -40,7 +48,15 @@ function useFoo(t0) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ a: null }],
sequentialRenders: [{ a: null }, { a: null }, { a: {} }],
sequentialRenders: [
{ a: null },
{ a: null },
{ a: {} },
{ a: { b: { c: { d: { e: 42 } } } } },
{ a: { b: { c: { d: { e: 43 } } } } },
{ a: { b: { c: { d: { e: undefined } } } } },
{ a: { b: undefined } },
],
};
```
@@ -48,4 +64,8 @@ export const FIXTURE_ENTRYPOINT = {
### Eval output
(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
[42,42]
[43,43]
[null,null]
[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
@@ -8,5 +8,13 @@ function useFoo({a}) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: null}, {a: {}}],
sequentialRenders: [
{a: null},
{a: null},
{a: {}},
{a: {b: {c: {d: {e: 42}}}}},
{a: {b: {c: {d: {e: 43}}}}},
{a: {b: {c: {d: {e: undefined}}}}},
{a: {b: undefined}},
],
};
@@ -14,7 +14,15 @@ function useFoo({a}) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: null}, {a: {}}],
sequentialRenders: [
{a: null},
{a: null},
{a: {}},
{a: {b: {c: {d: {e: 42}}}}},
{a: {b: {c: {d: {e: 43}}}}},
{a: {b: {c: {d: {e: undefined}}}}},
{a: {b: undefined}},
],
};
```
@@ -43,7 +51,15 @@ function useFoo(t0) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ a: null }],
sequentialRenders: [{ a: null }, { a: null }, { a: {} }],
sequentialRenders: [
{ a: null },
{ a: null },
{ a: {} },
{ a: { b: { c: { d: { e: 42 } } } } },
{ a: { b: { c: { d: { e: 43 } } } } },
{ a: { b: { c: { d: { e: undefined } } } } },
{ a: { b: undefined } },
],
};
```
@@ -51,4 +67,8 @@ export const FIXTURE_ENTRYPOINT = {
### Eval output
(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
[42,42]
[43,43]
[null,null]
[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
@@ -10,5 +10,13 @@ function useFoo({a}) {
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: null}],
sequentialRenders: [{a: null}, {a: null}, {a: {}}],
sequentialRenders: [
{a: null},
{a: null},
{a: {}},
{a: {b: {c: {d: {e: 42}}}}},
{a: {b: {c: {d: {e: 43}}}}},
{a: {b: {c: {d: {e: undefined}}}}},
{a: {b: undefined}},
],
};