Use defining modules for portable host type identity
Resolve record and enum names through their defining module when writing the host interface, including container element names. Match package-qualified module names against plain host module names without accepting other modules. Update native host assertions and the generated bootstrap lowerer. Local tests: host records, slices, arrays, capability, VM payloads and browser lifecycle passed; check-bootstrap passed. Full check initially 275/281; the two wire-name assertion failures now pass. Remaining failures were unrelated placement/debug output and a stale generated site page. Reported-by: Breeze task codex-breeze-breeze-crash-recovery-ui
This commit is contained in:
1 parent
900ed8f716
commit
96c23c7de6
9 files changed
+143
-23
No files matched your search
@@ -778,6 +778,7 @@ static void compiler_zir_lower_InterfacePut(InterfaceText* text, uint8_t* part)
|
||||
static void compiler_zir_lower_InterfaceField(InterfaceText* text, uint8_t* part) ZIRAN_MAYBE_UNUSED;
|
||||
static void compiler_zir_lower_InterfaceReject(InterfaceText* text, uint8_t* spelling) ZIRAN_MAYBE_UNUSED;
|
||||
static uint8_t* compiler_zir_lower_ClassText(int32_t class_id) ZIRAN_MAYBE_UNUSED;
|
||||
static uint8_t* compiler_zir_lower_InterfaceTypeName(AssemblyProgram* program, ZirModule* module, uint8_t* spelling, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
||||
static int32_t compiler_zir_lower_DescribeNode(AssemblyProgram* program, InterfaceText* text, __type_5edaf1f9ada62dbd* nodes, ZirModule* module, uint8_t* spelling, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
||||
static void compiler_zir_lower_PrintString(void* output, String value) ZIRAN_MAYBE_UNUSED;
|
||||
static int32_t compiler_zir_lower_HexDigit(int32_t digit) ZIRAN_MAYBE_UNUSED;
|
||||
@@ -35167,6 +35168,63 @@ compiler_zir_lower_ClassText(int32_t class_id)
|
||||
return compiler_services_Keep(StringLiteral("scalar"));
|
||||
}
|
||||
|
||||
static uint8_t*
|
||||
compiler_zir_lower_InterfaceTypeName(AssemblyProgram* program, ZirModule* module, uint8_t* spelling, int32_t depth)
|
||||
{
|
||||
if (depth > 64) {
|
||||
return spelling;
|
||||
}
|
||||
String spelled = compiler_ir_CText(spelling);
|
||||
uint8_t element[128] = {0};
|
||||
int32_t count = 0;
|
||||
uint8_t* prefix = (void *)0;
|
||||
bool value_0 = zir_f_0fe5ce4064831140_CArrayElementType(spelling, &(element[0]), (size_t)(128LL), &(count)) == 1;
|
||||
if (value_0 || zir_f_0fe5ce4064831140_CSliceElementType(spelling, &(element[0]), (size_t)(128LL)) == 1) {
|
||||
size_t close = 0;
|
||||
while (spelling[close] != 0 && spelling[close] != 93) {
|
||||
close = close + 1;
|
||||
}
|
||||
void* value_1 = compiler_zir_lower_Allocate(program, close + 2, 1);
|
||||
prefix = (uint8_t*)(value_1);
|
||||
if (prefix == ((void *)0)) {
|
||||
return spelling;
|
||||
}
|
||||
zir_f_0fe5ce4064831140_memcpy((void*)(prefix), (void*)(spelling), close + 1);
|
||||
uint8_t* value_2 = &(prefix[(close + 1)]);
|
||||
(*value_2) = 0;
|
||||
} else if ((int64_t)(spelled).length > 0LL && (uint8_t)spelled.data[0] == 42) {
|
||||
prefix = compiler_services_Keep(StringLiteral("*"));
|
||||
size_t length = zir_f_0fe5ce4064831140_strlen(spelling);
|
||||
if (length >= (size_t)(128LL)) {
|
||||
return spelling;
|
||||
}
|
||||
zir_f_0fe5ce4064831140_memcpy((void*)(&(element[0])), (void*)(((size_t)(spelling) + 1)), length);
|
||||
}
|
||||
InterfaceText text = {0};
|
||||
if (prefix != ((void *)0)) {
|
||||
compiler_zir_lower_InterfacePut(&(text), prefix);
|
||||
compiler_zir_lower_InterfacePut(&(text), compiler_zir_lower_InterfaceTypeName(program, module, &(element[0]), (int32_t)((uint32_t)depth + 1u)));
|
||||
} else {
|
||||
ZirModule* owner = module;
|
||||
ZirType* record = zir_f_0fe5ce4064831140_CFindType(module, spelling, &(owner));
|
||||
if (record == ((void *)0)) {
|
||||
return spelling;
|
||||
}
|
||||
compiler_zir_lower_InterfacePut(&(text), &(owner->name[0]));
|
||||
compiler_zir_lower_InterfacePut(&(text), compiler_services_Keep(StringLiteral(".")));
|
||||
compiler_zir_lower_InterfacePut(&(text), &(record->name[0]));
|
||||
}
|
||||
if (text.failed != 0) {
|
||||
int32_t* value_3 = &(program->failed);
|
||||
(*value_3) = 1;
|
||||
zir_f_0fe5ce4064831140_free((void*)(text.data));
|
||||
return spelling;
|
||||
}
|
||||
uint8_t* result = compiler_zir_lower_Text(program, text.data);
|
||||
zir_f_0fe5ce4064831140_free((void*)(text.data));
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
compiler_zir_lower_DescribeNode(AssemblyProgram* program, InterfaceText* text, __type_5edaf1f9ada62dbd* nodes, ZirModule* module, uint8_t* spelling, int32_t depth)
|
||||
{
|
||||
@@ -35354,7 +35412,7 @@ compiler_zir_lower_DescribeNode(AssemblyProgram* program, InterfaceText* text, _
|
||||
}
|
||||
compiler_zir_lower_InterfacePut(&(line), value_18);
|
||||
compiler_zir_lower_PutTab(&(line));
|
||||
compiler_zir_lower_InterfacePut(&(line), spelling);
|
||||
compiler_zir_lower_InterfacePut(&(line), compiler_zir_lower_InterfaceTypeName(program, module, spelling, 0));
|
||||
if (child >= 0) {
|
||||
compiler_zir_lower_PutTab(&(line));
|
||||
compiler_zir_lower_InterfacePut(&(line), compiler_zir_lower_NumberBytes(&(number[0]), (int64_t)(child)));
|
||||
|
||||
@@ -7276,6 +7276,52 @@ ClassText :: (class_id: s32) -> *u8 {
|
||||
return SVC.Keep("scalar")
|
||||
}
|
||||
|
||||
// Host values identify nominal types by their defining module, independent
|
||||
// of the import alias used by the foreign declaration. Containers retain
|
||||
// their shape and apply the same identity to their element type.
|
||||
InterfaceTypeName :: (program: *AssemblyProgram, module: *IR.ZirModule,
|
||||
spelling: *u8, depth: s32) -> *u8 {
|
||||
if depth > 64 { return spelling }
|
||||
spelled := IR.CText(spelling)
|
||||
element: [IR.ZIR_NAME_MAX]u8
|
||||
count: s32 = 0
|
||||
prefix: *u8 = null
|
||||
if CArrayElementType(spelling, *element[0], cast(usize)IR.ZIR_NAME_MAX, *count) == 1 ||
|
||||
CSliceElementType(spelling, *element[0], cast(usize)IR.ZIR_NAME_MAX) == 1 {
|
||||
close: usize = 0
|
||||
while spelling[close] != 0 && spelling[close] != 93 { close += 1 }
|
||||
prefix = cast(*u8)Allocate(program, close + 2, 1)
|
||||
if prefix == null { return spelling }
|
||||
memcpy(cast(*void)prefix, cast(*void)spelling, close + 1)
|
||||
prefix[close + 1] = 0
|
||||
} else if spelled.count > 0 && spelled[0] == cast(u8)42 {
|
||||
prefix = SVC.Keep("*")
|
||||
length := strlen(spelling)
|
||||
if length >= cast(usize)IR.ZIR_NAME_MAX { return spelling }
|
||||
memcpy(cast(*void)*element[0], cast(*void)(cast(usize)spelling + 1), length)
|
||||
}
|
||||
text: InterfaceText
|
||||
if prefix != null {
|
||||
InterfacePut(*text, prefix)
|
||||
InterfacePut(*text, InterfaceTypeName(program, module, *element[0], depth + 1))
|
||||
} else {
|
||||
owner := module
|
||||
record := CFindType(module, spelling, *owner)
|
||||
if record == null { return spelling }
|
||||
InterfacePut(*text, *owner.name[0])
|
||||
InterfacePut(*text, SVC.Keep("."))
|
||||
InterfacePut(*text, *record.name[0])
|
||||
}
|
||||
if text.failed != 0 {
|
||||
program.failed = 1
|
||||
free(cast(*void)text.data)
|
||||
return spelling
|
||||
}
|
||||
result := Text(program, text.data)
|
||||
free(cast(*void)text.data)
|
||||
return result
|
||||
}
|
||||
|
||||
// interface_node: one host-interface node, deduplicated by module and
|
||||
// spelling. The id is taken before children are described, so a type that
|
||||
// reaches itself finds its own node.
|
||||
@@ -7364,7 +7410,7 @@ DescribeNode :: (program: *AssemblyProgram, text: *InterfaceText,
|
||||
PutTab(*line)
|
||||
InterfacePut(*line, ClassText(class_id))
|
||||
PutTab(*line)
|
||||
InterfacePut(*line, spelling)
|
||||
InterfacePut(*line, InterfaceTypeName(program, module, spelling, 0))
|
||||
if child >= 0 {
|
||||
PutTab(*line)
|
||||
InterfacePut(*line, NumberBytes(*number[0], cast(s64)child))
|
||||
|
||||
+17
-1
@@ -1077,7 +1077,23 @@ exec_type_matches(const char *expected, const char *actual, int depth)
|
||||
const char *actual_dot = strrchr(actual, '.');
|
||||
const char *expected_leaf = expected_dot != NULL ? expected_dot + 1 : expected;
|
||||
const char *actual_leaf = actual_dot != NULL ? actual_dot + 1 : actual;
|
||||
if(expected_dot != NULL && actual_dot != NULL) return 0;
|
||||
if(expected_dot != NULL && actual_dot != NULL) {
|
||||
if(strcmp(expected_leaf, actual_leaf) != 0) return 0;
|
||||
size_t expected_module = (size_t)(expected_dot - expected);
|
||||
size_t actual_module = (size_t)(actual_dot - actual);
|
||||
const char *packaged = expected;
|
||||
const char *plain = actual;
|
||||
size_t packaged_length = expected_module, plain_length = actual_module;
|
||||
if(actual_module > expected_module) {
|
||||
packaged = actual; plain = expected;
|
||||
packaged_length = actual_module; plain_length = expected_module;
|
||||
}
|
||||
if(packaged_length != plain_length + 18 || packaged[0] != 'p' || packaged[17] != '_') return 0;
|
||||
for(size_t i = 1; i < 17; i++)
|
||||
if(!((packaged[i] >= '0' && packaged[i] <= '9') ||
|
||||
(packaged[i] >= 'a' && packaged[i] <= 'f'))) return 0;
|
||||
return memcmp(packaged + 18, plain, plain_length) == 0;
|
||||
}
|
||||
if(strcmp(expected_leaf, actual_leaf) == 0) return 1;
|
||||
if(expected_dot != NULL) return exec_flat_type_matches(expected, actual);
|
||||
if(actual_dot != NULL) return exec_flat_type_matches(actual, expected);
|
||||
|
||||
@@ -64,12 +64,12 @@ host_call(void *context, const char *module, const char *function,
|
||||
return 1;
|
||||
}
|
||||
assert(strcmp(function, "EchoBoxes") == 0);
|
||||
assert(strcmp(args[0].type, "[2]Box") == 0);
|
||||
assert(strcmp(args[0].type, "[2]arrays.Box") == 0);
|
||||
assert(args[0].length == 2 && args[0].elements != NULL);
|
||||
for(int i = 0; i < 2; i++) {
|
||||
const HostValue *box = &args[0].elements[i];
|
||||
assert(box->kind == HOST_RECORD);
|
||||
assert(strcmp(box->type, "Box") == 0);
|
||||
assert(strcmp(box->type, "arrays.Box") == 0);
|
||||
assert(box->field_count == 2);
|
||||
assert(strcmp(box->fields[0].name, "empty") == 0);
|
||||
assert(box->fields[0].value.kind == HOST_ARRAY);
|
||||
@@ -82,7 +82,7 @@ host_call(void *context, const char *module, const char *function,
|
||||
.kind = HOST_ARRAY, .type = "[0]s32"}};
|
||||
fields[i][1] = (HostField){"value", {
|
||||
.kind = HOST_INTEGER, .type = "s32", .integer = i == 0 ? 40 : 2}};
|
||||
boxes[i] = (HostValue){.kind = HOST_RECORD, .type = "Box",
|
||||
boxes[i] = (HostValue){.kind = HOST_RECORD, .type = "arrays.Box",
|
||||
.fields = fields[i], .field_count = 2};
|
||||
}
|
||||
if(malformed == 2)
|
||||
|
||||
@@ -27,7 +27,7 @@ read_file(const char *path, size_t *size)
|
||||
static long long
|
||||
tree_sum(const HostValue *node)
|
||||
{
|
||||
assert(node->kind == HOST_RECORD && strcmp(node->type, "Node") == 0 && node->field_count == 2);
|
||||
assert(node->kind == HOST_RECORD && strcmp(node->type, "tree.Node") == 0 && node->field_count == 2);
|
||||
const HostValue *children = &node->fields[1].value;
|
||||
assert(strcmp(node->fields[1].name, "children") == 0 && children->kind == HOST_SLICE);
|
||||
long long sum = node->fields[0].value.integer;
|
||||
|
||||
@@ -90,10 +90,10 @@ record_slice(void *context, const char *module, const char *function,
|
||||
assert(strcmp(module, "record_slices") == 0);
|
||||
if(strcmp(function, "Mutate") == 0) {
|
||||
assert(arg_count == 1 && args[0].kind == HOST_SLICE);
|
||||
assert(strcmp(args[0].type, "[]Point") == 0);
|
||||
assert(strcmp(args[0].type, "[]record_slices.Point") == 0);
|
||||
assert(args[0].length == 2 && args[0].elements != NULL);
|
||||
assert(args[0].elements[0].kind == HOST_RECORD);
|
||||
assert(strcmp(args[0].elements[0].type, "Point") == 0);
|
||||
assert(strcmp(args[0].elements[0].type, "record_slices.Point") == 0);
|
||||
assert(args[0].elements[0].field_count == 2);
|
||||
HostField *fields = (HostField *)args[0].elements[0].fields;
|
||||
assert(strcmp(fields[0].name, "x") == 0);
|
||||
@@ -117,14 +117,14 @@ record_slice(void *context, const char *module, const char *function,
|
||||
i == 1 && j == 1 ? 2 : 0;
|
||||
}
|
||||
elements[i].kind = HOST_RECORD;
|
||||
elements[i].type = "Point";
|
||||
elements[i].type = "record_slices.Point";
|
||||
elements[i].fields = fields[i];
|
||||
elements[i].field_count = 2;
|
||||
}
|
||||
if(bad_return)
|
||||
fields[1][1].name = "wrong";
|
||||
result->kind = HOST_SLICE;
|
||||
result->type = "[]Point";
|
||||
result->type = "[]record_slices.Point";
|
||||
result->elements = elements;
|
||||
result->length = 2;
|
||||
return 1;
|
||||
@@ -143,10 +143,10 @@ named_records(void *context, const char *module, const char *function,
|
||||
assert(args[0].kind == (strcmp(function, "SliceHost") == 0 ?
|
||||
HOST_SLICE : HOST_ARRAY));
|
||||
assert(strcmp(args[0].type, strcmp(function, "SliceHost") == 0 ?
|
||||
"[]Types.Point" : "[2]Types.Point") == 0);
|
||||
"[]types.Point" : "[2]types.Point") == 0);
|
||||
for(size_t i = 0; i < args[0].length; i++) {
|
||||
assert(args[0].elements[i].kind == HOST_RECORD);
|
||||
assert(strcmp(args[0].elements[i].type, "Types.Point") == 0);
|
||||
assert(strcmp(args[0].elements[i].type, "types.Point") == 0);
|
||||
}
|
||||
HostField *first = (HostField *)args[0].elements[0].fields;
|
||||
HostField *second = (HostField *)args[0].elements[1].fields;
|
||||
|
||||
@@ -18,12 +18,12 @@ sum_slice(void *context, const char *module, const char *function,
|
||||
assert(strcmp(function, "SumSliceHost") == 0);
|
||||
assert(arg_count == 1);
|
||||
assert(args[0].kind == HOST_SLICE);
|
||||
assert(strcmp(args[0].type, "[]Point") == 0);
|
||||
assert(strcmp(args[0].type, "[]shapes.Point") == 0);
|
||||
assert(args[0].length == 2);
|
||||
for(size_t i = 0; i < args[0].length; i++) {
|
||||
const HostValue *point = &args[0].elements[i];
|
||||
assert(point->kind == HOST_RECORD);
|
||||
assert(strcmp(point->type, "Point") == 0);
|
||||
assert(strcmp(point->type, "shapes.Point") == 0);
|
||||
assert(point->field_count == 2);
|
||||
assert(strcmp(point->fields[0].name, "x") == 0);
|
||||
total += point->fields[0].value.integer +
|
||||
@@ -47,7 +47,7 @@ host_call(void *context, const char *module, const char *function,
|
||||
if(strcmp(function, "ObserveHost") == 0) {
|
||||
assert(strcmp(module, "record_host") == 0);
|
||||
assert(arg_count == 2 && args[0].kind == HOST_RECORD);
|
||||
assert(strcmp(args[0].type, "State") == 0 && args[0].field_count == 1);
|
||||
assert(strcmp(args[0].type, "shapes.State") == 0 && args[0].field_count == 1);
|
||||
const HostValue *values = &args[0].fields[0].value;
|
||||
assert(values->kind == HOST_ARRAY && values->length == 2);
|
||||
assert(values->elements[0].integer == 10 && args[1].integer == 1);
|
||||
@@ -61,11 +61,11 @@ host_call(void *context, const char *module, const char *function,
|
||||
assert(strcmp(function, "TransformHost") == 0);
|
||||
assert(arg_count == 1);
|
||||
assert(args[0].kind == HOST_RECORD);
|
||||
assert(strcmp(args[0].type, "Packet") == 0);
|
||||
assert(strcmp(args[0].type, "shapes.Packet") == 0);
|
||||
assert(args[0].field_count == 3);
|
||||
assert(strcmp(args[0].fields[0].name, "point") == 0);
|
||||
assert(args[0].fields[0].value.kind == HOST_RECORD);
|
||||
assert(strcmp(args[0].fields[0].value.type, "Point") == 0);
|
||||
assert(strcmp(args[0].fields[0].value.type, "shapes.Point") == 0);
|
||||
assert(args[0].fields[0].value.field_count == 2);
|
||||
assert(args[0].fields[0].value.fields[0].value.integer == 40);
|
||||
assert(args[0].fields[0].value.fields[1].value.integer == 1);
|
||||
@@ -74,7 +74,7 @@ host_call(void *context, const char *module, const char *function,
|
||||
assert(args[0].fields[1].value.length == 2);
|
||||
assert(memcmp(args[0].fields[1].value.data, "in", 2) == 0);
|
||||
assert(strcmp(args[0].fields[2].name, "tone") == 0);
|
||||
assert(strcmp(args[0].fields[2].value.type, "Tone") == 0);
|
||||
assert(strcmp(args[0].fields[2].value.type, "shapes.Tone") == 0);
|
||||
assert(args[0].fields[2].value.integer == 0);
|
||||
calls++;
|
||||
|
||||
@@ -85,13 +85,13 @@ host_call(void *context, const char *module, const char *function,
|
||||
if(malformed == 2)
|
||||
point_fields[0].value.type = "u32";
|
||||
packet_fields[0] = (HostField){malformed == 1 ? "wrong" : "point",
|
||||
{.kind = HOST_RECORD, .type = "Point", .fields = point_fields,
|
||||
{.kind = HOST_RECORD, .type = "shapes.Point", .fields = point_fields,
|
||||
.field_count = 2}};
|
||||
packet_fields[1] = (HostField){"label",
|
||||
{.kind = HOST_STRING, .type = "string",
|
||||
.data = (const unsigned char *)"ok", .length = 2}};
|
||||
packet_fields[2] = (HostField){"tone",
|
||||
{.kind = HOST_INTEGER, .type = "Tone", .integer = 1}};
|
||||
{.kind = HOST_INTEGER, .type = "shapes.Tone", .integer = 1}};
|
||||
if(malformed == 3)
|
||||
packet_fields[2].value.kind = HOST_REAL;
|
||||
result->kind = HOST_RECORD;
|
||||
|
||||
@@ -6,7 +6,7 @@ static int handle;
|
||||
static int calls, records;
|
||||
static HostField returned[2][6];
|
||||
static const char *names[] = {"number", "wide", "real", "text", "tone", "handle"};
|
||||
static const char *types[] = {"s64", "u64", "float64", "string", "Tone", "*void"};
|
||||
static const char *types[] = {"s64", "u64", "float64", "string", "vm_value_payloads_test.Tone", "*void"};
|
||||
|
||||
/* The public host ABI keeps independent fields. A compact VM payload must
|
||||
* not expose the bits of a float/string as an unrelated number or pointer. */
|
||||
|
||||
@@ -175,7 +175,7 @@ static int migrate_instance(BundleInstance *old, const Bundle *replacement,
|
||||
HostValue *first, *title;
|
||||
ok = ok && BundleStateFind(new_state, "component", "state", &index) &&
|
||||
BundleStateValueAt(new_state, index, &value) &&
|
||||
strcmp(value.type, "State") == 0 &&
|
||||
strcmp(value.type, "component.State") == 0 &&
|
||||
(first = state_field(&value, "first")) != NULL &&
|
||||
(title = record_field(first, "title")) != NULL &&
|
||||
strcmp(title->type, "string") == 0 && title->length == 3 &&
|
||||
|
||||
Reference in new issue
Block a user