diff --git a/compiler/forget/src/HIR/Globals.ts b/compiler/forget/src/HIR/Globals.ts index f6d600772f..12e17b0f56 100644 --- a/compiler/forget/src/HIR/Globals.ts +++ b/compiler/forget/src/HIR/Globals.ts @@ -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 diff --git a/compiler/forget/src/HIR/ObjectShape.ts b/compiler/forget/src/HIR/ObjectShape.ts index 43459357f0..873140f75c 100644 --- a/compiler/forget/src/HIR/ObjectShape.ts +++ b/compiler/forget/src/HIR/ObjectShape.ts @@ -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; 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: diff --git a/compiler/forget/src/Inference/InferReferenceEffects.ts b/compiler/forget/src/Inference/InferReferenceEffects.ts index c58b8fe872..edfc37dbc9 100644 --- a/compiler/forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/forget/src/Inference/InferReferenceEffects.ts @@ -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;