From 74599a92a28e0a5ea7db02afc44911cd2b1aae35 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Tue, 13 Dec 2022 09:17:19 +0000 Subject: [PATCH] [hir] Update Place.type based on value inference --- compiler/forget/src/HIR/HIR.ts | 2 ++ compiler/forget/src/HIR/InferTypes.ts | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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); } }