[be] Hook type inference should only happen at LoadGlobal
--- #1254 added inference for hooks loaded from globals. This is the only time we need to generate a type equation assigning `lval` to a resolved`Hook` type. @gsathya Would love to get your feedback here on the change. From my understanding, this change is technically incorrect, since the type equation we generate should be dependent on the `callee` type (i.e. `Hook` if callee is a hook, `Function` if callee is a function). Would the next step be to consolidate `Hook` and `Function` types? ```js type Function { ... isHook: boolean, // set by inference } type FunctionSignature { isHook: boolean, // set when adding to ShapeRegistry } ```
Mofei Zhang committed
Mar 30, 2023 at 15:03 UTC
8e37df6dab0d44ac8f1ea452afc70708b7851387
1 file changed
+8
-11
compiler/forget/src/TypeInference/InferTypes.ts
+8
-11
@@ -144,17 +144,14 @@ function* generateInstructionTypes(
144
}
145
146
case "CallExpression": {
147
- const hook =
148
- value.callee.identifier.name !== null
149
- ? env.getHookDeclaration(value.callee.identifier.name)
150
- : null;
151
- let type: Type;
152
- if (hook !== null) {
153
- type = { kind: "Hook", definition: hook };
154
- } else {
155
- type = { kind: "Function", shapeId: null, return: left };
156
- }
157
- yield equation(value.callee.identifier.type, type);
147
+ // TODO: callee could be a hook or a function, so this type equation isn't correct.
148
+ // We should change Hook to a subtype of Function or change unifier logic.
149
+ // (see https://github.com/facebook/react-forget/pull/1427)
150
+ yield equation(value.callee.identifier.type, {
151
+ kind: "Function",
152
+ shapeId: null,
153
+ return: left,
154
+ });
155
break;
156
}
157