Update on "[compiler] Bail out and log calls that likely have side effects"

[ghstack-poisoned]
This commit is contained in:
Mike Vitousek
2024-08-01 14:05:37 -07:00
parent 3affe0339f
commit 2e114b0b2e
3 changed files with 18 additions and 18 deletions
@@ -36,6 +36,9 @@ class Visitor extends ReactiveFunctionVisitor<LValues> {
instruction: ReactiveInstruction,
state: LValues,
): void {
if (instruction.value.kind === 'FunctionExpression') {
this.visitHirFunction(instruction.value.loweredFunc.func, state)
}
this.traverseInstruction(instruction, state);
if (
instruction.lvalue !== null &&
@@ -18,7 +18,7 @@ import {
getHookKind,
isSetStateType,
} from '../HIR/HIR';
import { eachInstructionValueLValue } from '../HIR/visitors';
import { eachInstructionLValue, eachInstructionValueLValue } from '../HIR/visitors';
import {
ReactiveFunctionVisitor,
eachReactiveValueOperand,
@@ -115,6 +115,8 @@ class Visitor extends ReactiveFunctionVisitor<CompilerError> {
break;
}
}
} else {
super.visitInstruction(instr, state);
}
let hookKind = null;
@@ -131,11 +133,11 @@ class Visitor extends ReactiveFunctionVisitor<CompilerError> {
hookKind = getHookKind(this.#env, callee.identifier);
}
if (hookKind !== 'useEffect' && hookKind !== 'useLayoutEffect' && hookKind !== 'useInsertionEffect' && instr.value.kind !== "JsxExpression") {
if (instr.value.kind !== 'JsxExpression') {
for (const operand of eachReactiveValueOperand(instr.value)) {
const errors = this.#functions.get(operand.identifier.id);
if (errors != null) {
for (const lval of eachInstructionValueLValue(instr.value)) {
for (const lval of eachInstructionLValue(instr)) {
const existing = this.#functions.get(lval.identifier.id) ?? new CompilerError();
errors.details.forEach(detail => existing.pushErrorDetail(detail));
this.#functions.set(lval.identifier.id, existing);
@@ -150,7 +152,9 @@ class Visitor extends ReactiveFunctionVisitor<CompilerError> {
isSetStateType(callee.identifier);
const name = this.getName(callee.identifier) ?? "(unknown)";
this.#functions.get(callee.identifier.id)?.details?.forEach(detail => state.pushErrorDetail(detail));
if (hookKind !== 'useEffect' && hookKind !== 'useLayoutEffect' && hookKind !== 'useInsertionEffect') {
[...eachReactiveValueOperand(instr.value)].forEach(operand => this.#functions.get(operand.identifier.id)?.details?.forEach(detail => state.pushErrorDetail(detail)));
}
if (instr.lvalue === null && !isException && !allowedNames.has(name)) {
let allReads = true;
@@ -1,19 +1,12 @@
import {useMemo} from 'react';
import {useEffect, useMemo} from 'react';
function Component(props) {
const outerHandlers = useMemo(() => {
let handlers = {value: props.value};
switch (props.test) {
case true: {
console.log(handlers.value);
break;
}
default: {
}
}
return handlers;
});
return outerHandlers;
function foo() {
mutate();
}
const h = [foo];
useEffect(() => { a(h) });
return lengh();
}
export const FIXTURE_ENTRYPOINT = {