Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/compiler/src/backend/llvm/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ export function arrNewCall(
elem.kind === "promise" || // promise entries (Promise.all inputs): full REF story
elem.kind === "child" || // spawned child handles: scr_child_* adapters, no trace
elem.kind === "netServer" ||
elem.kind === "stats" || // fs.Stats snapshots: scr_stats_* adapters, no trace
elem.kind === "dyn" || // native collection seeds/drains: traced REF
elem.kind === "regex" || // RegExp values: scr_regex_* adapters, no trace (no refs inside)
(elem.kind === "array" && traceAdapter(host, elem) !== null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,14 @@ export function lowerArrayLiteral(
// A same-family array whose ELEMENT lifts (string[] into a
// (string | symbol)[] literal — per-element wrap/width copy):
// the interned width helper reshapes before the spread copies.
if (src.type.kind === "array" && !typeEquals(src.type, type)) {
// A fixed TUPLE (`[...FILES]` with FILES typed `[string, string,
// string]`) spreads its positions in order: the width helper copies
// the tuple's fields into an array of the literal's element type.
if (
(src.type.kind === "array" ||
(src.type.kind === "record" && lowerer.shapes.get(src.type.shapeId)?.tuple === true)) &&
!typeEquals(src.type, type)
) {
const w = lowerer.widthCoerce(src, type);
if (w) src = w;
}
Expand Down
55 changes: 54 additions & 1 deletion packages/compiler/src/frontend/lowering/lower-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,57 @@ function lowerStringMethodCallWithOptionalArgs(
return changed ? { ...lowered, args } : lowered;
}

/** `.then(String)` / `.then(Number)` / `.then(Boolean)` over a promise of
* a number, string or boolean: the ambient constructor converts its first
* argument (the settled value), so the handler is an interned closure over
* the settled type applying that conversion. The constructors' own value
* form takes a string, which a number or boolean settled value is not.
* Null for every other handler. */
function primitiveConversionHandler(
lowerer: Lowerer,
node: ts.Expression,
inner: IrType,
): IrExpr | null {
if (!ts.isIdentifier(node)) return null;
const name = node.text;
if (name !== "String" && name !== "Number" && name !== "Boolean") return null;
// A string settled value already fits the constructors' value form.
if (inner.kind !== "f64" && inner.kind !== "bool") return null;
if (!lowerer.isStdlibSymbol(lowerer.resolveValueSymbol(node) ?? undefined)) return null;
const loc = locOf(node);
const ret: IrType = name === "String" ? STRING : name === "Number" ? F64 : BOOL;
const fnT = funcOf([inner], ret);
const key = `then.${name}:${typeKey(inner)}`;
let fnName = lowerer.arrHofHelpers.get(key);
if (fnName === undefined) {
fnName = `%then.${name}.${lowerer.arrHofHelpers.size}`;
lowerer.arrHofHelpers.set(key, fnName);
const value = varRef("v.0", inner, loc);
let body: IrExpr;
if (name === "Boolean") body = { kind: "toBool", operand: value, type: BOOL, loc };
else if (name === "String") body = { kind: "toString", operand: value, type: STRING, loc };
else if (inner.kind === "f64") body = value;
else
body = {
kind: "ternary",
cond: value,
then: { kind: "numLit", value: 1, type: F64, loc },
else_: { kind: "numLit", value: 0, type: F64, loc },
type: F64,
loc,
};
lowerer.liftedFns.push({
name: fnName,
params: [{ localId: "v.0", name: "v", type: inner }],
returnType: ret,
locals: [{ id: "v.0", name: "v", type: inner, mutable: false }],
body: [{ kind: "return", value: body, loc }],
loc,
});
}
return { kind: "closure", fnName, captures: [], type: fnT, loc };
}

function lowerNumberConstructorValue(
lowerer: Lowerer,
argNode: ts.Expression,
Expand Down Expand Up @@ -5697,7 +5748,9 @@ export function lowerPromiseMethodCall(

if (inner.kind === "moduleNs")
markModuleNsHandlerParams(lowerer, call.arguments.nodes[0]!, inner);
let cb = lowerer.lowerExpr(call.arguments.nodes[0]!);
let cb =
primitiveConversionHandler(lowerer, call.arguments.nodes[0]!, inner) ??
lowerer.lowerExpr(call.arguments.nodes[0]!);
// A TYPED handler on a DYN-settling promise (the tracePromise
// result's `.then((value) => ...)` — the checker's generic
// instantiation typed the parameter, but the settled value is a
Expand Down
Loading
Loading