Skip to content

Commit

Permalink
[be] Hook type inference should only happen at LoadGlobal
Browse files Browse the repository at this point in the history
--- 

#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 

} 

```
  • Loading branch information
mofeiZ committed Mar 30, 2023
1 parent e81063e commit 8e37df6
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions compiler/forget/src/TypeInference/InferTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,14 @@ function* generateInstructionTypes(
}

case "CallExpression": {
const hook =
value.callee.identifier.name !== null
? env.getHookDeclaration(value.callee.identifier.name)
: null;
let type: Type;
if (hook !== null) {
type = { kind: "Hook", definition: hook };
} else {
type = { kind: "Function", shapeId: null, return: left };
}
yield equation(value.callee.identifier.type, type);
// TODO: callee could be a hook or a function, so this type equation isn't correct.
// We should change Hook to a subtype of Function or change unifier logic.
// (see https://github.com/facebook/react-forget/pull/1427)
yield equation(value.callee.identifier.type, {
kind: "Function",
shapeId: null,
return: left,
});
break;
}

Expand Down

0 comments on commit 8e37df6

Please sign in to comment.