@samitouri / QOS-React / commits / d0f1a98144

[typer] Introduce a Hook type

Sathya Gunasekaran committed Feb 14, 2023 at 23:07 UTC d0f1a9814429278143e906425dad212440517b1e
1 file changed +10
compiler/forget/src/HIR/HIR.ts
+10
@@ -627,6 +627,7 @@ export function makeInstructionId(id: number): InstructionId {
627
628 export type Type =
629 | PrimitiveType
630 + | HookType
631 | FunctionType
632 | ObjectType
633 | PhiType
@@ -636,6 +637,10 @@ export type PrimitiveType = { kind: "Primitive" };
637 export type FunctionType = {
638 kind: "Function";
639 };
640 +export type HookType = {
641 + kind: "Hook";
642 + name: string;
643 +};
644 export type ObjectType = { kind: "Object" };
645 export type TypeVar = {
646 kind: "Type";
@@ -677,6 +682,7 @@ export function typeEquals(tA: Type, tB: Type): boolean {
682 return (
683 typeVarEquals(tA, tB) ||
684 funcTypeEquals(tA, tB) ||
685 + hookTypeEquals(tA, tB) ||
686 objectTypeEquals(tA, tB) ||
687 primitiveTypeEquals(tA, tB) ||
688 polyTypeEquals(tA, tB) ||
@@ -711,6 +717,10 @@ function funcTypeEquals(tA: Type, tB: Type): boolean {
717 return typeKindCheck(tA, tB, "Function");
718 }
719
720 +function hookTypeEquals(tA: Type, tB: Type): boolean {
721 + return tA.kind === "Hook" && tB.kind === "Hook" && tA.name === tB.name;
722 +}
723 +
724 function phiTypeEquals(tA: Type, tB: Type): boolean {
725 if (tA.kind === "Phi" && tB.kind === "Phi") {
726 if (tA.operands.length !== tB.operands.length) {