[typer] Move type inference to a separate folder
Sathya Gunasekaran committed
Jan 4, 2023 at 21:11 UTC
d187fff41450f95b6eb0b9c3dc512d794e3a6a1a
5 files changed
+13
-6
compiler/forget/src/CompilerPipeline.ts
+1
-1
@@ -11,7 +11,6 @@ import {
11
HIRFunction,
12
inferMutableRanges,
13
inferReferenceEffects,
14
- inferTypes,
14
lower,
15
} from "./HIR";
16
import { ReactiveFunction } from "./HIR/HIR";
@@ -28,6 +27,7 @@ import {
27
renameVariables,
28
} from "./ReactiveScopes";
29
import { eliminateRedundantPhi, enterSSA, leaveSSA } from "./SSA";
30
+import { inferTypes } from "./TypeInference";
31
import { logHIRFunction, logReactiveFunction } from "./Utils/logger";
32
33
export type CompilerResult = {
compiler/forget/src/HIR/index.ts
-1
@@ -10,5 +10,4 @@ export { HIRFunction } from "./HIR";
10
export { Environment } from "./HIRBuilder";
11
export { inferMutableRanges } from "./InferMutableRanges";
12
export { default as inferReferenceEffects } from "./InferReferenceEffects";
13
-export { inferTypes } from "./InferTypes";
13
export { printFunction } from "./PrintHIR";
compiler/forget/src/TypeInference/InferTypes.ts
renamed
+3
-3
@@ -8,8 +8,8 @@ import {
8
typeEquals,
9
TypeId,
10
TypeVar,
11
-} from "./HIR";
12
-import { eachInstructionOperand } from "./visitors";
11
+} from "../HIR/HIR";
12
+import { eachInstructionOperand } from "../HIR/visitors";
13
14
function isPrimitiveBinaryOp(op: t.BinaryExpression["operator"]) {
15
switch (op) {
@@ -36,7 +36,7 @@ function isPrimitiveBinaryOp(op: t.BinaryExpression["operator"]) {
36
}
37
}
38
39
-export function inferTypes(func: HIRFunction) {
39
+export default function (func: HIRFunction) {
40
const unifier = new Unifier();
41
for (const e of generate(func, unifier)) {
42
unifier.unify(e.left, e.right);
compiler/forget/src/TypeInference/index.ts
new
+8
@@ -0,0 +1,8 @@
1
+/**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+export { default as inferTypes } from "./InferTypes";
compiler/forget/src/index.ts
+1
-1
@@ -19,7 +19,7 @@ import codegen from "./HIR/Codegen";
19
import { Environment } from "./HIR/HIRBuilder";
20
import { inferMutableRanges } from "./HIR/InferMutableRanges";
21
import inferReferenceEffects from "./HIR/InferReferenceEffects";
22
-import { inferTypes } from "./HIR/InferTypes";
22
+import { inferTypes } from "./TypeInference";
23
import printHIR, { printFunction } from "./HIR/PrintHIR";
24
import { buildReactiveFunction } from "./ReactiveScopes/BuildReactiveFunction";
25
import { codegenReactiveFunction } from "./ReactiveScopes/CodegenReactiveFunction";