Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] repro for dep merging edge case (non-hir) #31035

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

## Input

```javascript
import {identity} from 'shared-runtime';

/**
* Evaluator failure:
* Found differences in evaluator results
* Non-forget (expected):
* (kind: ok) {}
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
* Forget:
* (kind: ok) {}
* {}
*/
/**
* Very contrived text fixture showing that it's technically incorrect to merge
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
* unconditionally evaluated optional chain (`dep?.path`).
*
*
* when screen is non-null, useFoo returns { title: null } or "(not null)"
* when screen is null, useFoo throws
*/
function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
return screen?.title_text != null
? '(not null)'
: identity({title: screen.title_text});
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{screen: null}],
sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
import { identity } from "shared-runtime";

/**
* Evaluator failure:
* Found differences in evaluator results
* Non-forget (expected):
* (kind: ok) {}
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
* Forget:
* (kind: ok) {}
* {}
*/
/**
* Very contrived text fixture showing that it's technically incorrect to merge
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
* unconditionally evaluated optional chain (`dep?.path`).
*
*
* when screen is non-null, useFoo returns { title: null } or "(not null)"
* when screen is null, useFoo throws
*/
function useFoo(t0) {
const $ = _c(2);
const { screen } = t0;
let t1;
if ($[0] !== screen?.title_text) {
t1 =
screen?.title_text != null
? "(not null)"
: identity({ title: screen.title_text });
$[0] = screen?.title_text;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ screen: null }],
sequentialRenders: [{ screen: { title_bar: undefined } }, { screen: null }],
};

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {identity} from 'shared-runtime';

/**
* Evaluator failure:
* Found differences in evaluator results
* Non-forget (expected):
* (kind: ok) {}
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
* Forget:
* (kind: ok) {}
* {}
*/
/**
* Very contrived text fixture showing that it's technically incorrect to merge
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
* unconditionally evaluated optional chain (`dep?.path`).
*
*
* when screen is non-null, useFoo returns { title: null } or "(not null)"
* when screen is null, useFoo throws
*/
function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
return screen?.title_text != null
? '(not null)'
: identity({title: screen.title_text});
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{screen: null}],
sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
};
1 change: 1 addition & 0 deletions compiler/packages/snap/src/SproutTodoFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ const skipFilter = new Set([
'fbt/bug-fbt-plural-multiple-function-calls',
'fbt/bug-fbt-plural-multiple-mixed-call-tag',
'bug-invalid-hoisting-functionexpr',
'reduce-reactive-deps/bug-merge-uncond-optional-chain-and-cond',
'original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block',
'original-reactive-scopes-fork/bug-hoisted-declaration-with-scope',
'bug-codegen-inline-iife',
Expand Down