@samitouri / QOS-React-2 / commits / db3839e716

[typer] Cleanup lvalue null checking

Sathya Gunasekaran committed Jan 5, 2023 at 13:46 UTC db3839e716b397109f10d42e4d0a992c096cc9f8
1 file changed +6 -17
compiler/forget/src/TypeInference/InferTypes.ts
+6 -17
@@ -75,8 +75,7 @@ function generateTypeEquation(
75 ): Array<TypeEquation> {
76 const equations: Array<TypeEquation> = [];
77
78 - function add(left: Type | null, right: Type | null) {
79 - if (left === null || right === null) return;
78 + function add(left: Type, right: Type) {
79 equations.push({
80 left,
81 right,
@@ -84,7 +83,7 @@ function generateTypeEquation(
83 }
84
85 const { lvalue, value } = instr;
87 - const left = assignType(lvalue?.place);
86 + const left = lvalue.place.identifier.type;
87
88 switch (value.kind) {
89 case "JSXText":
@@ -94,21 +93,21 @@ function generateTypeEquation(
93 }
94
95 case "Identifier": {
97 - add(left, assignType(value));
96 + add(left, value.identifier.type);
97 break;
98 }
99
100 case "BinaryExpression": {
101 if (isPrimitiveBinaryOp(value.operator)) {
103 - add(assignType(value.left), { kind: "Primitive" });
104 - add(assignType(value.right), { kind: "Primitive" });
102 + add(value.left.identifier.type, { kind: "Primitive" });
103 + add(value.right.identifier.type, { kind: "Primitive" });
104 }
105 add(left, { kind: "Primitive" });
106 break;
107 }
108
109 case "CallExpression": {
111 - add(assignType(value.callee), { kind: "Function" });
110 + add(value.callee.identifier.type, { kind: "Function" });
111 break;
112 }
113
@@ -121,16 +120,6 @@ function generateTypeEquation(
120 return equations;
121 }
122
124 -function assignType(place: Place | undefined): Type | null {
125 - // We type only top level identifiers. Typing objects is not very useful
126 - // when we have to be so conservative.
127 - if (place === undefined) {
128 - return null;
129 - }
130 -
131 - return place.identifier.type;
132 -}
133 -
123 type Substitution = Map<TypeId, Type>;
124 class Unifier {
125 substitutions: Substitution = new Map();