diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index 4cb4bc2384..075e6db1bf 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -402,4 +402,6 @@ export function makeInstructionId(id: number): InstructionId { export enum Type { Any, + Primitive, + Object, } diff --git a/compiler/forget/src/HIR/InferTypes.ts b/compiler/forget/src/HIR/InferTypes.ts index 212a356f35..11ec27a442 100644 --- a/compiler/forget/src/HIR/InferTypes.ts +++ b/compiler/forget/src/HIR/InferTypes.ts @@ -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(); @@ -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); } }