From bb91cbbf62a148379c0c96ea3cd6b378d8b486e9 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Mon, 24 Oct 2022 16:04:18 +0100 Subject: [PATCH] [hir][be] Use a Map to store ObjectExpression.properties Semantically this seems like a better fit as we're using Map like methods to iterate and update values anyway. --- compiler/forget/src/HIR/BuildHIR.ts | 4 ++-- compiler/forget/src/HIR/Codegen.ts | 2 +- compiler/forget/src/HIR/HIR.ts | 2 +- compiler/forget/src/HIR/InferReferenceEffects.ts | 2 +- compiler/forget/src/HIR/PrintHIR.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index 28f0a2002d..4c72f7e8e8 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -682,7 +682,7 @@ function lowerExpression( case "ObjectExpression": { const expr = exprPath as NodePath; const propertyPaths = expr.get("properties"); - const properties: { [name: string]: Place } = {}; + const properties: Map = new Map(); for (const propertyPath of propertyPaths) { todoInvariant( propertyPath.isObjectProperty(), @@ -696,7 +696,7 @@ function lowerExpression( "Handle non-expression object values" ); const value = lowerExpressionToPlace(builder, valuePath); - properties[key.name] = value; + properties.set(key.name, value); } return { kind: "ObjectExpression", diff --git a/compiler/forget/src/HIR/Codegen.ts b/compiler/forget/src/HIR/Codegen.ts index 27145f62c7..d1a4592681 100644 --- a/compiler/forget/src/HIR/Codegen.ts +++ b/compiler/forget/src/HIR/Codegen.ts @@ -200,7 +200,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array) { case "ObjectExpression": { const properties = []; if (instrValue.properties !== null) { - for (const [property, value] of Object.entries(instrValue.properties)) { + for (const [property, value] of instrValue.properties) { properties.push( t.objectProperty(t.stringLiteral(property), codegenPlace(cx, value)) ); diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index 331b9d74e8..400385d100 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -190,7 +190,7 @@ export type InstructionData = } | { kind: "ObjectExpression"; - properties: { [property: string]: Place } | null; // null === empty object + properties: Map | null; // null === empty object } | { kind: "ArrayExpression"; elements: Array } diff --git a/compiler/forget/src/HIR/InferReferenceEffects.ts b/compiler/forget/src/HIR/InferReferenceEffects.ts index 3602d2dc64..f9c0e37dae 100644 --- a/compiler/forget/src/HIR/InferReferenceEffects.ts +++ b/compiler/forget/src/HIR/InferReferenceEffects.ts @@ -526,7 +526,7 @@ function inferBlock(env: Environment, block: BasicBlock) { valueKind = ValueKind.Mutable; // Object construction captures but does not modify the key/property values if (instrValue.properties !== null) { - for (const [_key, value] of Object.entries(instrValue.properties)) { + for (const [_key, value] of instrValue.properties) { env.reference(value, Effect.Read); } } diff --git a/compiler/forget/src/HIR/PrintHIR.ts b/compiler/forget/src/HIR/PrintHIR.ts index 111a615e28..86394c7a93 100644 --- a/compiler/forget/src/HIR/PrintHIR.ts +++ b/compiler/forget/src/HIR/PrintHIR.ts @@ -161,7 +161,7 @@ function printInstructionValue(instrValue: InstructionValue): string { case "ObjectExpression": { const properties = []; if (instrValue.properties !== null) { - for (const [key, value] of Object.entries(instrValue.properties)) { + for (const [key, value] of instrValue.properties) { properties.push(`${key}: ${printPlace(value)}`); } }