From f54d121d7171debcabe0cb60b55750a808ae3a32 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 JsxExpression.props 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 9ed27aab02..28f0a2002d 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -860,7 +860,7 @@ function lowerExpression( const children = expr .get("children") .map((child) => lowerJsxElement(builder, child)); - const props: { [prop: string]: Place } = {}; + const props: Map = new Map(); opening.get("attributes").forEach((attribute) => { todoInvariant(attribute.isJSXAttribute(), "handle spread attributes"); const name = attribute.get("name"); @@ -882,7 +882,7 @@ function lowerExpression( value = lowerExpressionToPlace(builder, expression); } const prop: string = name.node.name; - props[prop] = value; + props.set(prop, value); }); return { kind: "JsxExpression", diff --git a/compiler/forget/src/HIR/Codegen.ts b/compiler/forget/src/HIR/Codegen.ts index 12091f7592..27145f62c7 100644 --- a/compiler/forget/src/HIR/Codegen.ts +++ b/compiler/forget/src/HIR/Codegen.ts @@ -215,7 +215,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array) { } case "JsxExpression": { const attributes: Array = []; - for (const [prop, value] of Object.entries(instrValue.props)) { + for (const [prop, value] of instrValue.props) { attributes.push( t.jsxAttribute( t.jsxIdentifier(prop), diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index e1c409beb2..331b9d74e8 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -185,7 +185,7 @@ export type InstructionData = | { kind: "JsxExpression"; tag: Place; - props: { [prop: string]: Place }; + props: Map; children: Array | null; // null === no children } | { diff --git a/compiler/forget/src/HIR/InferReferenceEffects.ts b/compiler/forget/src/HIR/InferReferenceEffects.ts index 8c235db025..3602d2dc64 100644 --- a/compiler/forget/src/HIR/InferReferenceEffects.ts +++ b/compiler/forget/src/HIR/InferReferenceEffects.ts @@ -546,7 +546,7 @@ function inferBlock(env: Environment, block: BasicBlock) { case "JsxExpression": { valueKind = ValueKind.Frozen; env.reference(instrValue.tag, Effect.Freeze); - for (const [_prop, value] of Object.entries(instrValue.props)) { + for (const [_prop, value] of instrValue.props) { env.reference(value, Effect.Freeze); } if (instrValue.children !== null) { diff --git a/compiler/forget/src/HIR/PrintHIR.ts b/compiler/forget/src/HIR/PrintHIR.ts index 679eda65d0..111a615e28 100644 --- a/compiler/forget/src/HIR/PrintHIR.ts +++ b/compiler/forget/src/HIR/PrintHIR.ts @@ -191,7 +191,7 @@ function printInstructionValue(instrValue: InstructionValue): string { } case "JsxExpression": { const propItems = []; - for (const [prop, value] of Object.entries(instrValue.props)) { + for (const [prop, value] of instrValue.props) { propItems.push(`${prop}={${printPlace(value)}}`); } const props = propItems.length !== 0 ? " " + propItems.join(" ") : "";