mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Update Place.type based on value inference
This commit is contained in:
@@ -402,4 +402,6 @@ export function makeInstructionId(id: number): InstructionId {
|
||||
|
||||
export enum Type {
|
||||
Any,
|
||||
Primitive,
|
||||
Object,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import invariant from "invariant";
|
||||
import DisjointSet from "./DisjointSet";
|
||||
import { HIRFunction, Identifier, Instruction, LValue, Place } from "./HIR";
|
||||
import {
|
||||
HIRFunction,
|
||||
Identifier,
|
||||
Instruction,
|
||||
LValue,
|
||||
Place,
|
||||
Type,
|
||||
} from "./HIR";
|
||||
import { printInstructionValue } from "./PrintHIR";
|
||||
|
||||
type AbstractValue = AbstractObject | AbstractPrimitive;
|
||||
@@ -13,6 +20,17 @@ type AbstractPrimitive = {
|
||||
value: number | boolean | string | null | undefined;
|
||||
};
|
||||
|
||||
function typeOf(value: AbstractValue) {
|
||||
switch (value.kind) {
|
||||
case "Primitive":
|
||||
return Type.Primitive;
|
||||
case "Object":
|
||||
return Type.Object;
|
||||
default:
|
||||
return Type.Any;
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractState {
|
||||
#values = new Map<Identifier, AbstractValue>();
|
||||
|
||||
@@ -96,6 +114,7 @@ class AbstractState {
|
||||
// Simple lvalue:
|
||||
// lvalue = alias;
|
||||
// lvalue = alias.memberPath;
|
||||
lvalue.place.type = typeOf(value);
|
||||
this.#values.set(lvalue.place.identifier, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user