refactor: name recovery boundaries and compact IR strings

This commit is contained in:
2026-10-24 01:47:33 +02:00
parent 9932750e21
commit 021cbecac8
8 changed files with 68 additions and 36 deletions
+13 -4
View File
@@ -560,8 +560,17 @@ lower_string proc(state @mut State, id ast.NodeId) ir.ValueId ! (mem.AllocError
trap(state, try diagnostics.add(state.diagnostics, .invalid_escape, span), span)
return ir.no_value
}
# retain the complete allocation for freeing, but expose only decoded bytes.
try arraylist.append(&state.module.strings, owned)
if (state.module.strings.items.len > usize(maxval!(ir.StringId)))
return .out_of_memory
string_id :: ir.StringId(state.module.strings.items.len)
try arraylist.append(&state.module.strings, ir.StringStorage{
allocation = owned,
len = length,
})
transferred = true
return try constant(state, ir.Value{ type = .string, data = ir.ValueData{ string = owned[..length] } }, span)
}
return try constant(state, ir.Value{
type = .string,
data = ir.ValueData{ string = string_id },
}, span)
}
+14 -1
View File
@@ -91,7 +91,20 @@ owns_decoded_strings_after_source_and_frontend_are_freed test {
outcome :: try interpreter.run(mem.c_allocator, &module, &diagnostic_store)
try testing.expect(outcome.trap == null)
try testing.expect_equal(ir.Type.string, outcome.value.type)
try testing.expect(mem.eql(outcome.value.data.string, "a\\\"\n\r\t\x00Az"))
try testing.expect(mem.eql(ir.string_bytes(&module, outcome.value.data.string), "a\\\"\n\r\t\x00Az"))
}
resolves_module_local_string_ids_after_frontend_cleanup test {
diagnostic_store := diagnostics.init(mem.c_allocator)
defer diagnostics.deinit(&diagnostic_store)
module := try compile_owned(
"first :: \"not the result\"\nidentity proc(value string) string { return value }\nmain proc() string { return identity(\"second\\n\\x00\") }\n",
&diagnostic_store,
)
defer ir.deinit(&module)
outcome :: try interpreter.run(mem.c_allocator, &module, &diagnostic_store)
try testing.expect(outcome.trap == null)
try testing.expect_equal([]u8, "second\n\x00", ir.string_bytes(&module, outcome.value.data.string))
}
honors_float_context_and_float_division test {