Change function parameters to type Place

So that we can infer a Capability of Freeze for components
This commit is contained in:
Sathya Gunasekaran
2022-10-13 11:29:58 +01:00
parent 5149ce0fbb
commit b01fbfa7fb
5 changed files with 15 additions and 8 deletions
+10 -3
View File
@@ -12,7 +12,6 @@ import { invariant } from "../CompilerError";
import {
Capability,
HIRFunction,
Identifier,
IfTerminal,
InstructionKind,
InstructionValue,
@@ -55,10 +54,18 @@ export function lower(func: NodePath<t.Function>): HIRFunction {
? builder.resolveIdentifier(func.node.id)
: null;
const params: Array<Identifier> = [];
const params: Array<Place> = [];
func.node.params.forEach((param) => {
todoInvariant(t.isIdentifier(param), "todo: support non-identifier params");
params.push(builder.resolveIdentifier(param));
const identifier = builder.resolveIdentifier(param);
const place: Place = {
kind: "Identifier",
value: identifier,
memberPath: null,
capability: Capability.Unknown,
path: null as any,
};
params.push(place);
});
const body = func.get("body");
+1 -1
View File
@@ -50,7 +50,7 @@ export default function codegen(fn: HIRFunction): t.Function {
t.isFunctionDeclaration(node),
"todo: handle other than function declaration"
);
const params = fn.params.map((param) => convertIdentifier(param));
const params = fn.params.map((param) => convertIdentifier(param.value));
return t.functionDeclaration(
fn.id !== null ? convertIdentifier(fn.id) : null,
params,
+2 -2
View File
@@ -39,7 +39,7 @@ import { invariant } from "../CompilerError";
export type ReactFunction = {
path: NodePath<t.Function>;
id: Identifier | null;
params: Array<Identifier>;
params: Array<Place>;
returnScope: ScopeId;
scopes: Map<ScopeId, ReactiveScope>;
};
@@ -61,7 +61,7 @@ export type ReactiveScope = {
export type HIRFunction = {
path: NodePath<t.Function>;
id: Identifier | null;
params: Array<Identifier>;
params: Array<Place>;
body: HIR;
};
@@ -86,7 +86,7 @@ export default function inferReferenceCapability(fn: HIRFunction) {
const place: Place = {
kind: "Identifier",
memberPath: null,
value: param,
value: param.value,
path: null as any, // TODO
capability: Capability.Freeze,
};
+1 -1
View File
@@ -64,7 +64,7 @@ export default function analyzeScopes(fn: HIRFunction): ReactFunction {
inputs: new Set(
fn.params.map((param) => ({
kind: "Identifier",
value: param,
value: param.value,
memberPath: null,
capability: Capability.Freeze,
path: null as any,