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

[hir][typer] infer polymorphic types from PropertyLoad and PropertyCall

--- Expand Hindley Milner type inference to infer dependent types. Say `t` is a typevar and `t'` is some type (a built-in type, phi node, or another typevar). Our type equations are as follows (please edit/correct notation 😅) - type substitution: `t = t'`, - ~~dependent~~ polymorphic property load: `t = t'.prop` - polymorphic function call `t = fnCall{returnType}` - ~~dependent property call: `t = t'.prop` (only if t'.prop is a function type)~~ - ~~dependent return type: `t = t'.[[returntype]]`~~

Mofei Zhang committed Mar 23, 2023 at 15:08 UTC ef83c02d3cbd9736132a420259103067da93283a
1 file changed +7 -14
compiler/forget/src/TypeInference/InferTypes.ts
+7 -14
@@ -172,26 +172,21 @@ function* generateInstructionTypes(
172 }
173
174 case "ObjectExpression": {
175 - invariant(left !== null, "invald object expression");
175 yield equation(left, { kind: "Object", shapeId: ObjectShapeId });
176 break;
177 }
178
179 case "ArrayExpression": {
181 - if (left) {
182 - yield equation(left, { kind: "Object", shapeId: ArrayShapeId });
183 - }
180 + yield equation(left, { kind: "Object", shapeId: ArrayShapeId });
181 break;
182 }
183
184 case "PropertyLoad": {
188 - if (left) {
189 - yield equation(left, {
190 - kind: "Property",
191 - object: value.object.identifier.type,
192 - propertyName: value.property,
193 - });
194 - }
185 + yield equation(left, {
186 + kind: "Property",
187 + object: value.object.identifier.type,
188 + propertyName: value.property,
189 + });
190 break;
191 }
192
@@ -201,9 +196,7 @@ function* generateInstructionTypes(
196 kind: "FunctionCall",
197 returnType,
198 });
204 - if (left) {
205 - yield equation(left, returnType);
206 - }
199 + yield equation(left, returnType);
200 }
201 }
202 }