[hir] Add Type to Place
Sathya Gunasekaran committed
Dec 12, 2022 at 21:10 UTC
b8cf85d77dd964e2f658ab53d02d5636fffc8a46
4 files changed
+22
-1
compiler/forget/src/HIR/BuildHIR.ts
+13
-1
@@ -21,8 +21,8 @@ import {
21
Place,
22
ReturnTerminal,
23
SourceLocation,
24
- Terminal,
24
ThrowTerminal,
25
+ Type,
26
} from "./HIR";
27
import HIRBuilder, { Environment } from "./HIRBuilder";
28
import todo, { todoInvariant } from "./todo";
@@ -83,6 +83,7 @@ export function lower(
83
memberPath: null,
84
effect: Effect.Unknown,
85
loc: param.loc ?? GeneratedSource,
86
+ type: Type.Any,
87
};
88
params.push(place);
89
});
@@ -890,6 +891,7 @@ function lowerExpression(
891
memberPath: null,
892
effect: Effect.Unknown,
893
loc: left.loc,
894
+ type: Type.Any,
895
};
896
builder.push({
897
id: makeInstructionId(0),
@@ -908,6 +910,7 @@ function lowerExpression(
910
memberPath: null,
911
effect: Effect.Unknown,
912
loc: left.loc,
913
+ type: Type.Any,
914
};
915
builder.push({
916
id: makeInstructionId(0),
@@ -1006,6 +1009,7 @@ function lowerExpression(
1009
memberPath: [...(object.memberPath ?? []), property.node.name],
1010
effect: Effect.Unknown,
1011
loc: exprLoc,
1012
+ type: Type.Any,
1013
};
1014
return place;
1015
}
@@ -1082,6 +1086,7 @@ function lowerConditional(
1086
memberPath: null,
1087
effect: Effect.Read,
1088
loc,
1089
+ type: Type.Any,
1090
};
1091
// Block for code following the if
1092
const continuationBlock = builder.reserve();
@@ -1153,6 +1158,7 @@ function lowerJsxElementName(
1158
memberPath: null,
1159
effect: Effect.Unknown,
1160
loc: exprLoc,
1161
+ type: Type.Any,
1162
};
1163
return place;
1164
} else {
@@ -1162,6 +1168,7 @@ function lowerJsxElementName(
1168
memberPath: null,
1169
effect: Effect.Unknown,
1170
loc: exprLoc,
1171
+ type: Type.Any,
1172
};
1173
builder.push({
1174
id: makeInstructionId(0),
@@ -1202,6 +1209,7 @@ function lowerJsxElement(
1209
memberPath: null,
1210
effect: Effect.Unknown,
1211
loc: exprLoc,
1212
+ type: Type.Any,
1213
};
1214
builder.push({
1215
id: makeInstructionId(0),
@@ -1225,6 +1233,7 @@ function lowerJsxElement(
1233
memberPath: null,
1234
effect: Effect.Unknown,
1235
loc: exprLoc,
1236
+ type: Type.Any,
1237
};
1238
builder.push({
1239
id: makeInstructionId(0),
@@ -1255,6 +1264,7 @@ function lowerExpressionToPlace(
1264
memberPath: null,
1265
effect: Effect.Unknown,
1266
loc: exprLoc,
1267
+ type: Type.Any,
1268
};
1269
builder.push({
1270
id: makeInstructionId(0),
@@ -1303,6 +1313,7 @@ function lowerLVal(builder: HIRBuilder, exprPath: NodePath<t.LVal>): Place {
1313
memberPath: null,
1314
effect: Effect.Unknown,
1315
loc: exprLoc,
1316
+ type: Type.Any,
1317
};
1318
return place;
1319
}
@@ -1322,6 +1333,7 @@ function lowerLVal(builder: HIRBuilder, exprPath: NodePath<t.LVal>): Place {
1333
memberPath: [...(object.memberPath ?? []), propertyPath.node.name],
1334
effect: Effect.Unknown,
1335
loc: exprLoc,
1336
+ type: Type.Any,
1337
};
1338
return place;
1339
}
compiler/forget/src/HIR/HIR.ts
+5
@@ -270,6 +270,7 @@ export type Place = {
270
memberPath: Array<string> | null;
271
effect: Effect;
272
loc: SourceLocation;
273
+ type: Type;
274
};
275
276
/**
@@ -398,3 +399,7 @@ export function makeInstructionId(id: number): InstructionId {
399
);
400
return id as InstructionId;
401
}
402
+
403
+export enum Type {
404
+ Any,
405
+}
compiler/forget/src/HIR/InferReferenceEffects.ts
+2
@@ -16,6 +16,7 @@ import {
16
InstructionValue,
17
Phi,
18
Place,
19
+ Type,
20
ValueKind,
21
} from "./HIR";
22
import { printMixedHIR, printPlace, printSourceLocation } from "./PrintHIR";
@@ -77,6 +78,7 @@ export default function inferReferenceEffects(fn: HIRFunction) {
78
identifier: fn.id as any,
79
loc: fn.loc,
80
effect: Effect.Freeze,
81
+ type: Type.Any,
82
};
83
const value: InstructionValue = {
84
kind: "Primitive",
compiler/forget/src/HIR/LeaveSSA.ts
+2
@@ -16,6 +16,7 @@ import {
16
makeInstructionId,
17
Phi,
18
Place,
19
+ Type,
20
} from "./HIR";
21
import { eachInstructionValueOperand, eachTerminalOperand } from "./visitors";
22
@@ -153,6 +154,7 @@ export function leaveSSA(fn: HIRFunction) {
154
identifier,
155
effect: Effect.Mutate,
156
loc: GeneratedSource,
157
+ type: Type.Any,
158
},
159
kind: InstructionKind.Let,
160
},