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

Change function parameters to type Place

So that we can infer a Capability of Freeze for components

Sathya Gunasekaran committed Oct 13, 2022 at 11:29 UTC b01fbfa7fbfc7e5c3005febd8a2c6ca05f1519d9
5 files changed +15 -8
compiler/forget/src/HIR/BuildHIR.ts
+10 -3
@@ -12,7 +12,6 @@ import { invariant } from "../CompilerError";
12 import {
13 Capability,
14 HIRFunction,
15 - Identifier,
15 IfTerminal,
16 InstructionKind,
17 InstructionValue,
@@ -55,10 +54,18 @@ export function lower(func: NodePath<t.Function>): HIRFunction {
54 ? builder.resolveIdentifier(func.node.id)
55 : null;
56
58 - const params: Array<Identifier> = [];
57 + const params: Array<Place> = [];
58 func.node.params.forEach((param) => {
59 todoInvariant(t.isIdentifier(param), "todo: support non-identifier params");
61 - params.push(builder.resolveIdentifier(param));
60 + const identifier = builder.resolveIdentifier(param);
61 + const place: Place = {
62 + kind: "Identifier",
63 + value: identifier,
64 + memberPath: null,
65 + capability: Capability.Unknown,
66 + path: null as any,
67 + };
68 + params.push(place);
69 });
70
71 const body = func.get("body");
compiler/forget/src/HIR/Codegen.ts
+1 -1
@@ -50,7 +50,7 @@ export default function codegen(fn: HIRFunction): t.Function {
50 t.isFunctionDeclaration(node),
51 "todo: handle other than function declaration"
52 );
53 - const params = fn.params.map((param) => convertIdentifier(param));
53 + const params = fn.params.map((param) => convertIdentifier(param.value));
54 return t.functionDeclaration(
55 fn.id !== null ? convertIdentifier(fn.id) : null,
56 params,
compiler/forget/src/HIR/HIR.ts
+2 -2
@@ -39,7 +39,7 @@ import { invariant } from "../CompilerError";
39 export type ReactFunction = {
40 path: NodePath<t.Function>;
41 id: Identifier | null;
42 - params: Array<Identifier>;
42 + params: Array<Place>;
43 returnScope: ScopeId;
44 scopes: Map<ScopeId, ReactiveScope>;
45 };
@@ -61,7 +61,7 @@ export type ReactiveScope = {
61 export type HIRFunction = {
62 path: NodePath<t.Function>;
63 id: Identifier | null;
64 - params: Array<Identifier>;
64 + params: Array<Place>;
65 body: HIR;
66 };
67
compiler/forget/src/HIR/InferReferenceCapability.ts
+1 -1
@@ -86,7 +86,7 @@ export default function inferReferenceCapability(fn: HIRFunction) {
86 const place: Place = {
87 kind: "Identifier",
88 memberPath: null,
89 - value: param,
89 + value: param.value,
90 path: null as any, // TODO
91 capability: Capability.Freeze,
92 };
compiler/forget/src/HIR/ScopeAnalysis.ts
+1 -1
@@ -64,7 +64,7 @@ export default function analyzeScopes(fn: HIRFunction): ReactFunction {
64 inputs: new Set(
65 fn.params.map((param) => ({
66 kind: "Identifier",
67 - value: param,
67 + value: param.value,
68 memberPath: null,
69 capability: Capability.Freeze,
70 path: null as any,