[effects] Track return ValueKind for function signatures

This commit is contained in:
Mofei Zhang
2023-05-22 19:37:50 -04:00
parent d456e4a78c
commit 19cf39f50b
3 changed files with 21 additions and 2 deletions
+12
View File
@@ -85,6 +85,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: null,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
// https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.from
@@ -104,6 +105,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Object", shapeId: BuiltInArrayId },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]),
@@ -122,6 +124,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
]),
@@ -138,6 +141,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -147,6 +151,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -156,6 +161,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -165,6 +171,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -174,6 +181,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -183,6 +191,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
]),
@@ -194,6 +203,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -203,6 +213,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
[
@@ -212,6 +223,7 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
restParam: Effect.Read,
returnType: { kind: "Primitive" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
// TODO: rest of Global objects
+6 -1
View File
@@ -6,7 +6,7 @@
*/
import invariant from "invariant";
import { Effect } from "./HIR";
import { Effect, ValueKind } from "./HIR";
import {
BuiltInType,
FunctionType,
@@ -100,6 +100,7 @@ export type FunctionSignature = {
positionalParams: Array<Effect>;
restParam: Effect | null;
returnType: BuiltInType | PolyType;
returnValueKind: ValueKind;
calleeEffect: Effect;
};
@@ -138,6 +139,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
restParam: null,
returnType: { kind: "Poly" },
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
[
@@ -150,6 +152,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
shapeId: BuiltInArrayId,
},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
["length", PRIMITIVE_TYPE],
@@ -160,6 +163,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
restParam: Effect.Capture,
returnType: PRIMITIVE_TYPE,
calleeEffect: Effect.Store,
returnValueKind: ValueKind.Immutable,
}),
],
// TODO: rest of Array properties
@@ -174,6 +178,7 @@ addObject(BUILTIN_SHAPES, BuiltInObjectId, [
restParam: null,
returnType: PRIMITIVE_TYPE,
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Immutable,
}),
],
// TODO:
@@ -729,6 +729,8 @@ function inferBlock(
const effects =
signature !== null ? getFunctionEffects(instrValue, signature) : null;
const returnValueKind =
signature !== null ? signature.returnValueKind : ValueKind.Mutable;
for (let i = 0; i < instrValue.args.length; i++) {
const arg = instrValue.args[i];
const place = arg.kind === "Identifier" ? arg : arg.place;
@@ -749,7 +751,7 @@ function inferBlock(
state.reference(instrValue.callee, Effect.Mutate);
}
state.initialize(instrValue, ValueKind.Mutable);
state.initialize(instrValue, returnValueKind);
state.define(instr.lvalue, instrValue);
instr.lvalue.effect = Effect.Mutate;
continue;