✓
Passing This code compiles and runs correctly.
Code
// PINS post-transform weld + dead_strip for transform-appended imports.
// A transform appends `fixture/rt/alpha` and rewrites boot → fixture.rt.alpha:init.
// dead_strip must keep init_event (reachable) and strip tick_event (not invoked).
~import fixture/hub
~fixture/hub:boot() |> check-emit
~tor check-emit {}
~proc check-emit|zig {
const std = @import("std");
const alpha = koru_fixture.koru_rt.koru_alpha;
if (!@hasDecl(alpha, "init_event")) {
@panic("dead_strip removed init_event from welded runtime");
}
if (@hasDecl(alpha, "tick_event")) {
@panic("dead_strip kept tick_event though only init is invoked");
}
std.debug.print("PASS: post-weld dead_strip keeps init, strips tick\n", .{});
}
Supporting Files
// Transform hub — appends the runtime import and rewrites boot → alpha:init.
~import std/compiler
const std = @import("std");
var runtime_imported: bool = false;
~[comptime|transform]pub tor boot {
invocation: *const Invocation,
item: *const std/compiler:Item,
allocator: std.mem.Allocator,
} -> SiteResult
~proc boot|zig {
const ast = @import("ast");
const ast_functional = @import("ast_functional");
if (item.* != .flow) return .{};
const flow = &item.flow;
var segs = allocator.alloc([]const u8, 1) catch unreachable;
segs[0] = allocator.dupe(u8, "init") catch unreachable;
const runtime_path = ast.DottedPath{
.module_qualifier = allocator.dupe(u8, "fixture.rt.alpha") catch unreachable,
.segments = segs,
};
var call_inv = ast_functional.cloneInvocation(allocator, invocation) catch unreachable;
call_inv.path = runtime_path;
call_inv.args = &.{};
const conts = allocator.alloc(ast.Continuation, flow.body.continuations.len) catch unreachable;
for (flow.body.continuations, 0..) |*c, i| {
conts[i] = ast_functional.cloneContinuation(allocator, c) catch unreachable;
}
var appended: []const ast.Item = &.{};
if (!runtime_imported) {
runtime_imported = true;
const items = allocator.alloc(ast.Item, 1) catch unreachable;
items[0] = ast.Item{ .import_decl = ast.ImportDecl{
.path = allocator.dupe(u8, "fixture/rt/alpha") catch unreachable,
.local_name = null,
.location = flow.location,
.module = allocator.dupe(u8, flow.module) catch unreachable,
} };
appended = items;
}
return .{
.replacement = ast.Item{ .flow = ast.Flow{
.body = ast.rootSite(call_inv, conts, flow.location),
.pre_label = null,
.impl_of = flow.impl_of,
.super_shape = null,
.inline_body = null,
.preamble_code = null,
.is_pure = false,
.is_transitively_pure = false,
.location = flow.location,
.module = allocator.dupe(u8, flow.module) catch unreachable,
} },
.appended = appended,
};
}
// Welded runtime — init is invoked; tick must be dead-stripped.
~pub tor init {}
~proc init|zig {}
~pub tor tick {}
~proc tick|zig {}
Actual
PASS: post-weld dead_strip keeps init, strips tick
Expected output
PASS: post-weld dead_strip keeps init, strips tick
Flows
flow ~boot click a branch to expand · @labels scroll to their anchor
boot
Test Configuration
MUST_RUN
koru.json:
{
"name": "post-weld-dead-strip",
"version": "0.1.0",
"paths": {
"std": "../../../../../koru_std",
"app": "{{ ENTRY }}",
"fixture": "{{ ENTRY }}/fixture"
}
}