Give one application one type across modules; keep C names off the runtime's
Build check / check (push) Canceled after 0s

A pointer to Vec(Db.Match) could not reach a procedure of Db that takes
*Vec(Match), nor Vec(*Db.Frag) one that takes *Vec(*Frag): the two
spellings got different instance names, and same_type_application also
required the expanded bodies to match as text (*Match against *Db.Match).
Instance names now hash a qualified argument type the way its own module
spells it whenever the bare name means the same type here
(type_application_identity), so both spellings name one type for the
checker, C, Go and ZX alike. same_type_application compares the template
and the resolved arguments under pointer, slice and array shapes instead
of the body text. The checker accepts two spellings of one application
only when they share that name, because only then do the backends emit
one type; a module whose own Match hides Db.Match is still rejected.

A constant becomes an object-like C macro, so String :: 2 rewrote the
runtime's String typedef, length :: 3 every .length member, and a
file-private constant in one module a parameter of the same name in
another. Constants spelled like a runtime header name, a runtime member,
a record field, or a parameter or local anywhere in the program now take
the mangled zir_d_ name; globals and types spelled like a runtime header
or libc name are renamed the same way.

The "::" inside a multi-line file-scope string was already fixed by
c2ef7933; colon_text now also uses a typed table and the "x ::1 y" text
the TaijiOS port reported. tests/tool_diagnostics_cases.zi adds
runtime_names and module_vec, a case with a second module. Seeds for
c_emit, check_link, check_value, frontend_ir and zir_lower.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
waoziandClaude Opus 5.5 committed 2026-11-23 02:55:21 -03:00
1 parent a007a9cb73
commit 0fe03609a9
12 files changed
+930 -330

No files matched your search

+292 -53
View File
@@ -675,6 +675,7 @@ static bool compiler_c_emit_IsCMacroName(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsCppKeyword(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsGoKeyword(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsCRuntimeName(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsCRuntimeHeaderName(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsGoRuntimeName(String name) ZIRAN_MAYBE_UNUSED;
static bool compiler_c_emit_IsCReservedName(ZirTarget target, uint8_t* name) ZIRAN_MAYBE_UNUSED;
static void compiler_c_emit_TargetTopName(ZirModule* module, ZirTarget target, uint8_t* name, bool is_global, uint8_t* out, size_t size) ZIRAN_MAYBE_UNUSED;
@@ -685,6 +686,7 @@ static void compiler_c_emit_NativeNamesMark(NativeValueNames* names, uint8_t* na
static void compiler_c_emit_NativeNamesFree(NativeValueNames* names) ZIRAN_MAYBE_UNUSED;
static void compiler_c_emit_NativeNamesMarkShared(NativeValueNames* names) ZIRAN_MAYBE_UNUSED;
static void compiler_c_emit_NativeNamesMarkTypeValues(NativeValueNames* names) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_c_emit_MarkNativeMacroCollisions(ZirProgram** programs, int32_t count) ZIRAN_MAYBE_UNUSED;
static uint64_t compiler_c_emit_NativeTopHash(ZirModule* module, ZirSourceSpan span, uint8_t* name) ZIRAN_MAYBE_UNUSED;
static void compiler_c_emit_ReadableModuleName(uint8_t* name, uint8_t* out, size_t size, bool upper) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_c_emit_ModuleNeedsStartupWalk(ZirModule* module, ModuleVisits* visits) ZIRAN_MAYBE_UNUSED;
@@ -1554,6 +1556,19 @@ compiler_c_emit_IsCRuntimeName(String name)
return false;
}
static bool
compiler_c_emit_IsCRuntimeHeaderName(String name)
{
String words[18] = {StringLiteral("String"), StringLiteral("Source_Code_Location"), StringLiteral("StringView"), StringLiteral("StringLiteral"), StringLiteral("StringRange"), StringLiteral("StringRangeAt"), StringLiteral("StringEqual"), StringLiteral("print_float"), StringLiteral("Slice"), StringLiteral("SliceIndex"), StringLiteral("SliceRange"), StringLiteral("SliceRangeAt"), StringLiteral("BoundsCheck"), StringLiteral("EmptyArrayIndex"), StringLiteral("ZirVecGrow"), StringLiteral("ZirVecIndex"), StringLiteral("ZirVecReserve"), StringLiteral("ZirVecReserveBounded")};
for (int64_t it_index = 0LL; it_index < 18; it_index++) {
String w = (words)[it_index];
if (StringEqual(name, w)) {
return true;
}
}
return false;
}
static bool
compiler_c_emit_IsGoRuntimeName(String name)
{
@@ -1985,6 +2000,219 @@ compiler_c_emit_NativeNamesMarkTypeValues(NativeValueNames* names)
}
}
static int32_t
compiler_c_emit_MarkNativeMacroCollisions(ZirProgram** programs, int32_t count)
{
NativeValueNames defines = {0};
int32_t total = 0;
{
int32_t range_first_2 = 0;
int32_t range_last_2 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_2;
if (p <= range_last_2) for (;;) {
{
int32_t range_first_3 = 0;
int32_t range_last_3 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_3;
if (m <= range_last_3) for (;;) {
total = (int32_t)((uint32_t)total + (uint32_t)((((programs[p])->modules)[m]).define_count));
if (m == range_last_3) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
if (p == range_last_2) {
break;
}
p = (int32_t)((uint32_t)p + 1u);
}
}
if (total == 0) {
return 1;
}
int32_t* value_0 = &(defines.bucket_count);
(*value_0) = (int32_t)(((uint32_t)total * 2u) + 1u);
int32_t** value_1 = &(defines.buckets);
void* value_2 = zir_f_88c96d1f737973e0_malloc((size_t)(defines.bucket_count) * sizeof(int32_t));
(*value_1) = (int32_t*)(value_2);
if (defines.buckets == ((void *)0)) {
return 0;
}
zir_f_88c96d1f737973e0_memset((void*)(defines.buckets), 255, (size_t)(defines.bucket_count) * sizeof(int32_t));
int32_t ok = 1;
{
int32_t range_first_17 = 0;
int32_t range_last_17 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_17;
if (p <= range_last_17) for (;;) {
{
int32_t range_first_18 = 0;
int32_t range_last_18 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_18;
if (m <= range_last_18) for (;;) {
ZirModule* module = &(((programs[p])->modules)[m]);
{
int32_t range_first_20 = 0;
int32_t range_last_20 = (int32_t)((uint32_t)(module->define_count) - 1u);
int32_t d = range_first_20;
if (d <= range_last_20) for (;;) {
if (ok == 0) {
break;
}
uint8_t native[256] = {0};
compiler_c_emit_TargetTopName(module, (ZirTarget)(0), &(((module->defines[d]).name)[0]), false, &(native[0]), 128 * 2);
ok = compiler_c_emit_NativeNamesAdd(&(defines), &(native[0]), &((module->defines[d]).native_name_collision), 0);
if (d == range_last_20) {
break;
}
d = (int32_t)((uint32_t)d + 1u);
}
}
if (m == range_last_18) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
if (p == range_last_17) {
break;
}
p = (int32_t)((uint32_t)p + 1u);
}
}
if (ok != 0) {
String members[4] = {StringLiteral("data"), StringLiteral("length"), StringLiteral("fully_pathed_filename"), StringLiteral("line_number")};
for (int64_t it_index = 0LL; it_index < 4; it_index++) {
String member = (members)[it_index];
uint8_t* value_3 = (void *)0;
{
String s = member;
value_3 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
}
compiler_c_emit_NativeNamesMark(&(defines), value_3);
}
{
int32_t range_first_35 = 0;
int32_t range_last_35 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_35;
if (p <= range_last_35) for (;;) {
{
int32_t range_first_36 = 0;
int32_t range_last_36 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_36;
if (m <= range_last_36) for (;;) {
ZirModule* module = &(((programs[p])->modules)[m]);
{
int32_t range_first_38 = 0;
int32_t range_last_38 = (int32_t)((uint32_t)(module->type_count) - 1u);
int32_t t = range_first_38;
if (t <= range_last_38) for (;;) {
ZirType* type = &(module->types[t]);
if (type->is_record_template != 0 || type->is_enum != 0) {
if (t == range_last_38) {
break;
}
t = (int32_t)((uint32_t)t + 1u);
continue;
}
size_t offset = 0;
ZirTypeField field = {0};
while (zir_f_88c96d1f737973e0_CTypeNextField(type, &(offset), &(field)) == 1) {
compiler_c_emit_NativeNamesMark(&(defines), &(field.name[0]));
}
if (t == range_last_38) {
break;
}
t = (int32_t)((uint32_t)t + 1u);
}
}
{
int32_t range_first_49 = 0;
int32_t range_last_49 = (int32_t)((uint32_t)(module->function_count) - 1u);
int32_t f = range_first_49;
if (f <= range_last_49) for (;;) {
ZirFunction* function = &(module->functions[f]);
if (function->is_template != 0) {
if (f == range_last_49) {
break;
}
f = (int32_t)((uint32_t)f + 1u);
continue;
}
uint8_t* value_5 = (void *)0;
{
ZirFunction* fn = function;
if (fn != ((void *)0) && ((uint8_t*)fn->args_text) != ((void *)0)) {
value_5 = (uint8_t*)fn->args_text;
goto value_6;
}
String value_7 = StringLiteral("");
uint8_t* value_8 = (void *)0;
{
String s = value_7;
value_8 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
}
value_5 = value_8;
value_6: ;
}
uint8_t* args = value_5;
if (args[0] != 0) {
CParameters* parameters = zir_f_88c96d1f737973e0_ParametersOf(args);
CParameter* items = (CParameter*)(&(parameters->items[0]));
{
int32_t range_first_58 = 0;
int32_t range_last_58 = (int32_t)((uint32_t)(parameters->count) - 1u);
int32_t i = range_first_58;
if (i <= range_last_58) for (;;) {
if ((items[i]).name != ((void *)0)) {
compiler_c_emit_NativeNamesMark(&(defines), (items[i]).name);
}
if (i == range_last_58) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
}
{
int32_t range_first_64 = 0;
int32_t range_last_64 = (int32_t)((uint32_t)(function->stmt_count) - 1u);
int32_t s = range_first_64;
if (s <= range_last_64) for (;;) {
ZirStmt* st = &(function->stmts[s]);
if (((ZirStmtKind)(st->kind)) == ((ZirStmtKind)(3)) && ((uint8_t*)st->names.name) != ((void *)0) && st->names.name[0] != 0) {
compiler_c_emit_NativeNamesMark(&(defines), (uint8_t*)st->names.name);
}
if (s == range_last_64) {
break;
}
s = (int32_t)((uint32_t)s + 1u);
}
}
if (f == range_last_49) {
break;
}
f = (int32_t)((uint32_t)f + 1u);
}
}
if (m == range_last_36) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
if (p == range_last_35) {
break;
}
p = (int32_t)((uint32_t)p + 1u);
}
}
}
compiler_c_emit_NativeNamesFree(&(defines));
return ok;
}
int32_t
MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
{
@@ -2084,6 +2312,11 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
compiler_c_emit_TargetTopName(module, value_7, name, is_global, &(native[0]), 128 * 2);
ok = compiler_c_emit_NativeNamesAdd(&(names[t]), &(native[0]), collision, 0);
}
bool value_8 = compiler_c_emit_IsCRuntimeHeaderName(compiler_ir_CText(name));
if (value_8 || compiler_c_emit_IsCRuntimeName(compiler_ir_CText(name))) {
int32_t* value_9 = &((*(collision)));
(*value_9) = 1;
}
if (v == range_last_29) {
break;
}
@@ -2107,33 +2340,33 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
compiler_c_emit_NativeNamesMarkShared(&(names[1]));
}
{
int32_t range_first_51 = 0;
int32_t range_last_51 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_51;
if (p <= range_last_51) for (;;) {
int32_t range_first_54 = 0;
int32_t range_last_54 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_54;
if (p <= range_last_54) for (;;) {
if (ok == 0) {
break;
}
{
int32_t range_first_55 = 0;
int32_t range_last_55 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_55;
if (m <= range_last_55) for (;;) {
int32_t range_first_58 = 0;
int32_t range_last_58 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_58;
if (m <= range_last_58) for (;;) {
if (ok == 0) {
break;
}
ZirModule* module = &(((programs[p])->modules)[m]);
{
int32_t range_first_60 = 0;
int32_t range_last_60 = (int32_t)((uint32_t)(module->type_count) - 1u);
int32_t t = range_first_60;
if (t <= range_last_60) for (;;) {
int32_t range_first_63 = 0;
int32_t range_last_63 = (int32_t)((uint32_t)(module->type_count) - 1u);
int32_t t = range_first_63;
if (t <= range_last_63) for (;;) {
if (ok == 0) {
break;
}
ZirType* type = &(module->types[t]);
if (type->is_record_template != 0 || (type->is_extern != 0 && (type->foreign_target)[0] == 0)) {
if (t == range_last_60) {
if (t == range_last_63) {
break;
}
t = (int32_t)((uint32_t)t + 1u);
@@ -2142,19 +2375,24 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
uint8_t native[256] = {0};
NativeTypeName(module, type, &(native[0]), 128 * 2);
ok = compiler_c_emit_NativeNamesAdd(&(names[0]), &(native[0]), &(type->native_name_mangled), 1);
if (t == range_last_60) {
bool value_10 = type->is_extern == 0;
if (value_10 && compiler_c_emit_IsCRuntimeHeaderName(compiler_ir_CText(&(native[0])))) {
int32_t* value_11 = &(type->native_name_mangled);
(*value_11) = 1;
}
if (t == range_last_63) {
break;
}
t = (int32_t)((uint32_t)t + 1u);
}
}
if (m == range_last_55) {
if (m == range_last_58) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
if (p == range_last_51) {
if (p == range_last_54) {
break;
}
p = (int32_t)((uint32_t)p + 1u);
@@ -2162,24 +2400,24 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
}
if (ok != 0) {
{
int32_t range_first_75 = 0;
int32_t range_last_75 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_75;
if (p <= range_last_75) for (;;) {
int32_t range_first_81 = 0;
int32_t range_last_81 = (int32_t)((uint32_t)count - 1u);
int32_t p = range_first_81;
if (p <= range_last_81) for (;;) {
{
int32_t range_first_76 = 0;
int32_t range_last_76 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_76;
if (m <= range_last_76) for (;;) {
int32_t range_first_82 = 0;
int32_t range_last_82 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
int32_t m = range_first_82;
if (m <= range_last_82) for (;;) {
ZirModule* module = &(((programs[p])->modules)[m]);
{
int32_t range_first_78 = 0;
int32_t range_last_78 = (int32_t)((uint32_t)(module->function_count) - 1u);
int32_t f = range_first_78;
if (f <= range_last_78) for (;;) {
int32_t range_first_84 = 0;
int32_t range_last_84 = (int32_t)((uint32_t)(module->function_count) - 1u);
int32_t f = range_first_84;
if (f <= range_last_84) for (;;) {
ZirFunction* function = &(module->functions[f]);
if (function->is_template != 0) {
if (f == range_last_78) {
if (f == range_last_84) {
break;
}
f = (int32_t)((uint32_t)f + 1u);
@@ -2189,45 +2427,45 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
NativeCFunctionName(module, function, &(native[0]), 128 * 2);
compiler_c_emit_NativeNamesMark(&(names[0]), &(native[0]));
if (NativeProgramMain(module, function) != 0) {
String value_8 = StringLiteral("main");
uint8_t* value_9 = (void *)0;
String value_12 = StringLiteral("main");
uint8_t* value_13 = (void *)0;
{
String s = value_8;
value_9 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
String s = value_12;
value_13 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
}
compiler_c_emit_NativeNamesMark(&(names[0]), value_9);
compiler_c_emit_NativeNamesMark(&(names[0]), value_13);
}
NativeGoFunctionName(programs, count, module, function, &(native[0]), 128 * 2);
compiler_c_emit_NativeNamesMark(&(names[1]), &(native[0]));
if ((function->export_symbol)[0] != 0) {
compiler_c_emit_NativeNamesMark(&(names[1]), &(function->export_symbol[0]));
}
if (f == range_last_78) {
if (f == range_last_84) {
break;
}
f = (int32_t)((uint32_t)f + 1u);
}
}
{
int32_t range_first_95 = 0;
int32_t range_last_95 = (int32_t)((uint32_t)(module->import_count) - 1u);
int32_t i = range_first_95;
if (i <= range_last_95) for (;;) {
int32_t range_first_101 = 0;
int32_t range_last_101 = (int32_t)((uint32_t)(module->import_count) - 1u);
int32_t i = range_first_101;
if (i <= range_last_101) for (;;) {
ZirImport* foreign = &(module->imports[i]);
bool value_11 = ((ZirImportKind)(foreign->kind)) != ((ZirImportKind)(3));
bool value_12 = value_11;
if (!value_12) {
String value_13 = StringLiteral("c.");
uint8_t* value_14 = (void *)0;
bool value_15 = ((ZirImportKind)(foreign->kind)) != ((ZirImportKind)(3));
bool value_16 = value_15;
if (!value_16) {
String value_17 = StringLiteral("c.");
uint8_t* value_18 = (void *)0;
{
String s = value_13;
value_14 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
String s = value_17;
value_18 = ((zir_9d57101922f2e428_StaticText*)(&(s)))->data;
}
bool value_16 = zir_f_88c96d1f737973e0_strncmp(&(foreign->target[0]), value_14, 2) != 0;
value_12 = value_16;
bool value_20 = zir_f_88c96d1f737973e0_strncmp(&(foreign->target[0]), value_18, 2) != 0;
value_16 = value_20;
}
if (value_12) {
if (i == range_last_95) {
if (value_16) {
if (i == range_last_101) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
@@ -2237,25 +2475,26 @@ MarkNativeNameCollisions(ZirProgram** programs, int32_t count)
NativeCForeignName(module, foreign, &(native[0]), 128 * 2);
compiler_c_emit_NativeNamesMark(&(names[0]), &(native[0]));
compiler_c_emit_NativeNamesMark(&(names[0]), &(foreign->target[2]));
if (i == range_last_95) {
if (i == range_last_101) {
break;
}
i = (int32_t)((uint32_t)i + 1u);
}
}
if (m == range_last_76) {
if (m == range_last_82) {
break;
}
m = (int32_t)((uint32_t)m + 1u);
}
}
if (p == range_last_75) {
if (p == range_last_81) {
break;
}
p = (int32_t)((uint32_t)p + 1u);
}
}
compiler_c_emit_NativeNamesMarkTypeValues(&(names[0]));
ok = compiler_c_emit_MarkNativeMacroCollisions(programs, count);
}
compiler_c_emit_NativeNamesFree(&(names[0]));
compiler_c_emit_NativeNamesFree(&(names[1]));
@@ -744,6 +744,92 @@ private_check_canonical_type_arguments(uint8_t* source, uint8_t* output, size_t
return 1;
}
int32_t
private_check_type_application_identity(ZirModule* module, uint8_t* canonical, uint8_t* output, size_t capacity)
{
size_t used = 0;
size_t at = 0;
uint8_t quote = 0;
while (canonical[at] != 0) {
uint8_t byte = canonical[at];
bool value_0 = quote == 0;
bool value_1 = value_0;
if (value_1) {
bool value_2 = zir_f_4dd49c3deb4b30c4_isalpha((int32_t)(byte)) != 0;
value_1 = (value_2 || byte == 95);
}
if (value_1) {
size_t start = at;
bool dotted = false;
while (true) {
bool value_3 = zir_f_4dd49c3deb4b30c4_isalnum((int32_t)(canonical[at])) != 0;
bool value_4 = value_3 || canonical[at] == 95;
bool value_5 = value_4;
if (!value_5) {
bool value_6 = canonical[at] == 46;
bool value_7 = value_6;
if (value_7) {
bool value_8 = zir_f_4dd49c3deb4b30c4_isalpha((int32_t)(canonical[(at + 1)])) != 0;
value_7 = (value_8 || canonical[(at + 1)] == 95);
}
value_5 = value_7;
}
if (!value_5) { break; }
if (canonical[at] == 46) {
dotted = true;
}
at = at + 1;
}
uint8_t* token = (uint8_t*)(((size_t)(canonical) + start));
size_t length = at - start;
if (dotted && length < 256) {
uint8_t path[256] = {0};
zir_f_4dd49c3deb4b30c4_memcpy((void*)(&(path[0])), (void*)(token), length);
uint8_t* value_9 = &(path[length]);
(*value_9) = 0;
ZirModule* owner = (void *)0;
ZirType* type = zir_f_4dd49c3deb4b30c4_FindType(module, &(path[0]), &(owner));
if (type != ((void *)0) && owner != ((void *)0) && owner != module) {
ZirType* local = zir_f_4dd49c3deb4b30c4_FindType(module, &(type->name[0]), (void *)0);
if (local == ((void *)0) || local == type) {
token = &(type->name[0]);
length = zir_f_4dd49c3deb4b30c4_strlen(token);
}
}
}
if (used + length >= capacity) {
return 0;
}
zir_f_4dd49c3deb4b30c4_memcpy((void*)(((size_t)(output) + used)), (void*)(token), length);
used = used + length;
continue;
}
if (used + 1 >= capacity) {
return 0;
}
uint8_t* value_10 = &(output[used]);
(*value_10) = byte;
used = used + 1;
if (quote != 0 && byte == 92 && canonical[(at + 1)] != 0) {
at = at + 1;
if (used + 1 >= capacity) {
return 0;
}
uint8_t* value_11 = &(output[used]);
(*value_11) = canonical[at];
used = used + 1;
} else if (quote != 0 && byte == quote) {
quote = 0;
} else if (quote == 0 && (byte == 34 || byte == 39)) {
quote = byte;
}
at = at + 1;
}
uint8_t* value_12 = &(output[used]);
(*value_12) = 0;
return 1;
}
void
TypeApplicationScope(ZirModule* module, uint8_t* arguments, int32_t template_public, int32_t template_file_private, ZirType* instance)
{
@@ -963,6 +1049,18 @@ compiler_check_link_rewrite_type_applications_with_buffers(ZirModule* module, ui
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_2;
}
void* value_34 = zir_f_4dd49c3deb4b30c4_AllocateOrExit(sizeof(S12Array4096_u8));
S12Array4096_u8* identity_storage = (S12Array4096_u8*)(value_34);
bool value_35 = private_check_type_application_identity(module, (uint8_t*)(&(buffers->canonical.items)), (uint8_t*)(&((identity_storage[0]).items)), (size_t)((uint64_t)(sizeof(S12Array4096_u8)))) != 0;
if (!value_35) {
ZirSourceSpan value_36 = span;
uint8_t* value_37 = compiler_check_types_CheckCString(StringLiteral("check.type_application"));
zir_f_4dd49c3deb4b30c4_Diagnostic(value_36, value_37, compiler_check_types_CheckCString(StringLiteral("type application arguments are too long: %s")), (uint8_t*)(&((base_storage_0[0]).items)));
int32_t cleanup_return_3 = 0;
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(identity_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_3;
}
uint64_t hash = 14695981039346656037ULL;
{
uint8_t* p = (uint8_t*)((uint8_t*)(&(generic->name)));
@@ -977,7 +1075,7 @@ compiler_check_link_rewrite_type_applications_with_buffers(ZirModule* module, ui
}
hash = (uint64_t)(((uint64_t)hash ^ UINT64_C(40)) * UINT64_C(1099511628211));
{
uint8_t* p = (uint8_t*)((uint8_t*)(&(buffers->canonical.items)));
uint8_t* p = (uint8_t*)((uint8_t*)(&((identity_storage[0]).items)));
while (true) {
bool check_loop_153 = p[0] != 0;
if (!check_loop_153) {
@@ -987,11 +1085,11 @@ compiler_check_link_rewrite_type_applications_with_buffers(ZirModule* module, ui
compiler_check_s12_types_S12Post1(&(p));
}
}
void* value_34 = zir_f_4dd49c3deb4b30c4_AllocateOrExit(sizeof(S12Array128_u8));
S12Array128_u8* name_storage_1 = (S12Array128_u8*)(value_34);
void* value_38 = zir_f_4dd49c3deb4b30c4_AllocateOrExit(sizeof(S12Array128_u8));
S12Array128_u8* name_storage_1 = (S12Array128_u8*)(value_38);
zir_f_4dd49c3deb4b30c4_memset((void*)(name_storage_1), 0, sizeof(S12Array128_u8));
uint8_t* value_35 = compiler_check_types_CheckCString(StringLiteral("__type_%016llx"));
zir_f_4dd49c3deb4b30c4_snprintf((uint8_t*)(&((name_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(S12Array128_u8))), value_35, hash);
uint8_t* value_39 = compiler_check_types_CheckCString(StringLiteral("__type_%016llx"));
zir_f_4dd49c3deb4b30c4_snprintf((uint8_t*)(&((name_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(S12Array128_u8))), value_39, hash);
ZirType* instance = (void *)0;
{
int32_t t = 0;
@@ -1011,70 +1109,85 @@ compiler_check_link_rewrite_type_applications_with_buffers(ZirModule* module, ui
}
zir_loop_break_7: ;
}
bool value_36 = instance != (ZirType*)(((void *)0));
bool value_37 = value_36;
if (value_37) {
bool value_38 = !(instance->is_synthetic_application != 0);
bool value_39 = value_38;
if (!value_39) {
bool value_40 = instance->is_type_instance != 0;
bool value_41 = value_40;
if (value_41) {
ZirType* value_42 = zir_f_4dd49c3deb4b30c4_FindType(module, (uint8_t*)(&(instance->template_name)), (void *)0);
bool value_43 = value_42 != generic;
bool value_44 = value_43 || zir_f_4dd49c3deb4b30c4_strcmp((uint8_t*)(&(instance->template_args)), (uint8_t*)(&(buffers->canonical.items))) != 0;
value_41 = value_44;
}
value_39 = value_41;
}
value_37 = value_39;
void* value_40 = zir_f_4dd49c3deb4b30c4_AllocateOrExit(sizeof(S12Array4096_u8));
S12Array4096_u8* existing_storage = (S12Array4096_u8*)(value_40);
bool value_41 = instance != ((void *)0);
if (value_41 && private_check_type_application_identity(module, (uint8_t*)(&(instance->template_args)), (uint8_t*)(&((existing_storage[0]).items)), (size_t)((uint64_t)(sizeof(S12Array4096_u8)))) == 0) {
uint8_t* value_42 = &(((existing_storage[0]).items)[0]);
(*value_42) = 0;
}
if (value_37) {
ZirSourceSpan value_45 = span;
uint8_t* value_46 = compiler_check_types_CheckCString(StringLiteral("check.type_application"));
zir_f_4dd49c3deb4b30c4_Diagnostic(value_45, value_46, compiler_check_types_CheckCString(StringLiteral("type application name collision: %s")), (uint8_t*)(&((base_storage_0[0]).items)));
int32_t cleanup_return_3 = 0;
bool value_43 = instance != (ZirType*)(((void *)0));
bool value_44 = value_43;
if (value_44) {
bool value_45 = !(instance->is_synthetic_application != 0);
bool value_46 = value_45;
if (!value_46) {
bool value_47 = instance->is_type_instance != 0;
bool value_48 = value_47;
if (value_48) {
ZirType* value_49 = zir_f_4dd49c3deb4b30c4_FindType(module, (uint8_t*)(&(instance->template_name)), (void *)0);
bool value_50 = value_49 != generic;
bool value_51 = value_50 || zir_f_4dd49c3deb4b30c4_strcmp((uint8_t*)(&((existing_storage[0]).items)), (uint8_t*)(&((identity_storage[0]).items))) != 0;
value_48 = value_51;
}
value_46 = value_48;
}
value_44 = value_46;
}
if (value_44) {
ZirSourceSpan value_52 = span;
uint8_t* value_53 = compiler_check_types_CheckCString(StringLiteral("check.type_application"));
zir_f_4dd49c3deb4b30c4_Diagnostic(value_52, value_53, compiler_check_types_CheckCString(StringLiteral("type application name collision: %s")), (uint8_t*)(&((base_storage_0[0]).items)));
int32_t cleanup_return_4 = 0;
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(existing_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(name_storage_1));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(identity_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_3;
return cleanup_return_4;
}
if (instance == (ZirType*)(((void *)0))) {
int32_t generic_public = generic->is_public;
int32_t generic_file_private = generic->is_file_private;
instance = zir_f_4dd49c3deb4b30c4_ModuleAddType(module, (uint8_t*)(&((name_storage_1[0]).items)), span);
if (instance == (ZirType*)(((void *)0))) {
int32_t cleanup_return_4 = 0;
int32_t cleanup_return_5 = 0;
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(existing_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(name_storage_1));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(identity_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_4;
return cleanup_return_5;
}
TypeApplicationScope(module, (uint8_t*)(&(buffers->canonical.items)), generic_public, generic_file_private, instance);
int32_t* value_47 = &(instance->is_type_instance);
(*value_47) = 1;
int32_t* value_48 = &(instance->is_synthetic_application);
(*value_48) = 1;
int32_t* value_54 = &(instance->is_type_instance);
(*value_54) = 1;
int32_t* value_55 = &(instance->is_synthetic_application);
(*value_55) = 1;
zir_f_4dd49c3deb4b30c4_copy_text((uint8_t*)(&(instance->template_name)), (size_t)((uint64_t)(sizeof(S12Array128_u8))), (uint8_t*)(&((base_storage_0[0]).items)));
zir_f_4dd49c3deb4b30c4_copy_text((uint8_t*)(&(instance->template_args)), (size_t)((uint64_t)(sizeof(S12Array4096_u8))), (uint8_t*)(&(buffers->canonical.items)));
}
size_t value_49 = zir_f_4dd49c3deb4b30c4_strlen((uint8_t*)(&((name_storage_1[0]).items)));
size_t name_length = (size_t)((uint64_t)(value_49));
size_t value_56 = zir_f_4dd49c3deb4b30c4_strlen((uint8_t*)(&((name_storage_1[0]).items)));
size_t name_length = (size_t)((uint64_t)(value_56));
if (used + name_length >= capacity) {
int32_t cleanup_return_5 = 0;
int32_t cleanup_return_6 = 0;
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(existing_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(name_storage_1));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(identity_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_5;
return cleanup_return_6;
}
zir_f_4dd49c3deb4b30c4_memcpy((void*)((uint8_t*)(((size_t)(output) + ((size_t)(used) * sizeof(uint8_t))))), (void*)((uint8_t*)(&((name_storage_1[0]).items))), name_length);
used = used + name_length;
cursor = (uint8_t*)(((size_t)(closing) + ((size_t)(1LL) * sizeof(uint8_t))));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(existing_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(name_storage_1));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(identity_storage));
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
goto zir_loop_continue_1;
}
if (used + length >= capacity) {
int32_t cleanup_return_6 = 0;
int32_t cleanup_return_7 = 0;
zir_f_4dd49c3deb4b30c4_CompilerFree((void*)(base_storage_0));
return cleanup_return_6;
return cleanup_return_7;
}
zir_f_4dd49c3deb4b30c4_memcpy((void*)((uint8_t*)(((size_t)(output) + ((size_t)(used) * sizeof(uint8_t))))), (void*)(start), length);
used = used + length;
@@ -1084,17 +1197,17 @@ compiler_check_link_rewrite_type_applications_with_buffers(ZirModule* module, ui
if (used + (size_t)(1LL) >= capacity) {
return 0;
}
size_t value_50 = compiler_check_s12_types_S12Post5(&(used));
uint8_t* value_51 = &(output[value_50]);
uint8_t* value_52 = compiler_check_s12_types_S12Post1(&(cursor));
(*value_51) = value_52[0];
size_t value_57 = compiler_check_s12_types_S12Post5(&(used));
uint8_t* value_58 = &(output[value_57]);
uint8_t* value_59 = compiler_check_s12_types_S12Post1(&(cursor));
(*value_58) = value_59[0];
}
zir_loop_continue_1: ;
}
zir_loop_break_1: ;
}
uint8_t* value_53 = &(output[used]);
(*value_53) = 0;
uint8_t* value_60 = &(output[used]);
(*value_60) = 0;
return 1;
}
@@ -13,6 +13,7 @@ extern "C" {
#endif
int32_t private_check_check_foreign_slice_returns(ZirProgram** programs, int32_t count);
int32_t private_check_canonical_type_arguments(uint8_t* source, uint8_t* output, size_t capacity);
int32_t private_check_type_application_identity(ZirModule* module, uint8_t* canonical, uint8_t* output, size_t capacity);
void TypeApplicationScope(ZirModule* module, uint8_t* arguments, int32_t template_public, int32_t template_file_private, ZirType* instance);
int32_t private_check_rewrite_type_applications(ZirModule* module, uint8_t* source, uint8_t* output, size_t capacity, ZirSourceSpan span, int32_t recursion);
int32_t private_check_normalize_type_applications(ZirModule* module);
@@ -412,6 +412,19 @@ zir_f_6d0830be4da0a0ed_canonical_type_arguments(uint8_t* source, uint8_t* output
return zir_foreign_zir_f_6d0830be4da0a0ed_canonical_type_arguments(source, output, capacity);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_6d0830be4da0a0ed_type_application_identity_54da762a
#define ZIR_FOREIGN_zir_f_6d0830be4da0a0ed_type_application_identity_54da762a
#ifdef __APPLE__
int32_t zir_foreign_zir_f_6d0830be4da0a0ed_type_application_identity(ZirModule* module, uint8_t* canonical, uint8_t* output, size_t capacity) __asm__("_private_check_type_application_identity");
#else
int32_t zir_foreign_zir_f_6d0830be4da0a0ed_type_application_identity(ZirModule* module, uint8_t* canonical, uint8_t* output, size_t capacity) __asm__("private_check_type_application_identity");
#endif
static int32_t
zir_f_6d0830be4da0a0ed_type_application_identity(ZirModule* module, uint8_t* canonical, uint8_t* output, size_t capacity)
{
return zir_foreign_zir_f_6d0830be4da0a0ed_type_application_identity(module, canonical, output, capacity);
}
#endif
#ifndef ZIR_FOREIGN_zir_f_6d0830be4da0a0ed_contains_vec_05fb2d6d
#define ZIR_FOREIGN_zir_f_6d0830be4da0a0ed_contains_vec_05fb2d6d
#ifdef __APPLE__
@@ -3264,54 +3277,56 @@ private_check_same_declared_type(ZirModule* module, uint8_t* to, uint8_t* from,
return 1;
}
bool value_6 = target != (ZirType*)(((void *)0)) && source != (ZirType*)(((void *)0));
bool value_7 = value_6;
if (value_7) {
ZirModule* value_8 = (void *)0;
bool value_7 = value_6 && zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(target->name)), (uint8_t*)(&(source->name))) == 0;
bool value_8 = value_7;
bool value_9 = value_8;
if (value_9) {
ZirModule* value_10 = (void *)0;
if (target_owner != ((void *)0)) {
value_8 = target_owner;
value_10 = target_owner;
} else {
value_8 = module;
value_10 = module;
}
ZirModule* value_9 = (void *)0;
ZirModule* value_11 = (void *)0;
if (source_owner != ((void *)0)) {
value_9 = source_owner;
value_11 = source_owner;
} else {
value_9 = module;
value_11 = module;
}
bool value_10 = zir_f_6d0830be4da0a0ed_same_type_application(value_8, target, value_9, source) != 0;
value_7 = value_10;
bool value_12 = zir_f_6d0830be4da0a0ed_same_type_application(value_10, target, value_11, source) != 0;
value_9 = value_12;
}
if (value_7) {
if (value_9) {
return 1;
}
void* value_11 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* to_element_storage_0 = (CheckArray128_u8*)(value_11);
void* value_13 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* to_element_storage_0 = (CheckArray128_u8*)(value_13);
zir_f_6d0830be4da0a0ed_memset((void*)(to_element_storage_0), 0, sizeof(CheckArray128_u8));
void* value_12 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* from_element_storage_1 = (CheckArray128_u8*)(value_12);
void* value_14 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* from_element_storage_1 = (CheckArray128_u8*)(value_14);
zir_f_6d0830be4da0a0ed_memset((void*)(from_element_storage_1), 0, sizeof(CheckArray128_u8));
int32_t to_capacity = 0;
int32_t from_capacity = 0;
bool value_13 = zir_f_6d0830be4da0a0ed_ArrayElementType(to, (uint8_t*)(&((to_element_storage_0[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), &(to_capacity)) != 0;
bool value_14 = value_13 && zir_f_6d0830be4da0a0ed_ArrayElementType(from, (uint8_t*)(&((from_element_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), &(from_capacity)) != 0;
if (value_14 && to_capacity >= 0 && to_capacity == from_capacity) {
bool value_15 = zir_f_6d0830be4da0a0ed_ArrayElementType(to, (uint8_t*)(&((to_element_storage_0[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), &(to_capacity)) != 0;
bool value_16 = value_15 && zir_f_6d0830be4da0a0ed_ArrayElementType(from, (uint8_t*)(&((from_element_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), &(from_capacity)) != 0;
if (value_16 && to_capacity >= 0 && to_capacity == from_capacity) {
int32_t cleanup_return_0 = private_check_same_declared_type(module, (uint8_t*)(&((to_element_storage_0[0]).items)), (uint8_t*)(&((from_element_storage_1[0]).items)), (int32_t)((uint32_t)depth + 1u));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(from_element_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(to_element_storage_0));
return cleanup_return_0;
}
bool value_15 = zir_f_6d0830be4da0a0ed_SliceElementType(to, (uint8_t*)(&((to_element_storage_0[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8)))) != 0;
if (value_15 && zir_f_6d0830be4da0a0ed_SliceElementType(from, (uint8_t*)(&((from_element_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8)))) != 0) {
bool value_17 = zir_f_6d0830be4da0a0ed_SliceElementType(to, (uint8_t*)(&((to_element_storage_0[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8)))) != 0;
if (value_17 && zir_f_6d0830be4da0a0ed_SliceElementType(from, (uint8_t*)(&((from_element_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8)))) != 0) {
int32_t cleanup_return_1 = private_check_same_declared_type(module, (uint8_t*)(&((to_element_storage_0[0]).items)), (uint8_t*)(&((from_element_storage_1[0]).items)), (int32_t)((uint32_t)depth + 1u));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(from_element_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(to_element_storage_0));
return cleanup_return_1;
}
if ((int32_t)((int8_t)(to[0])) == 42 && (int32_t)((int8_t)(from[0])) == 42) {
ZirModule* value_16 = module;
uint8_t* value_17 = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(((size_t)(to) + ((size_t)(1LL) * sizeof(uint8_t)))));
uint8_t* value_18 = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(((size_t)(from) + ((size_t)(1LL) * sizeof(uint8_t)))));
int32_t cleanup_return_2 = private_check_same_declared_type(value_16, value_17, value_18, (int32_t)((uint32_t)depth + 1u));
ZirModule* value_18 = module;
uint8_t* value_19 = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(((size_t)(to) + ((size_t)(1LL) * sizeof(uint8_t)))));
uint8_t* value_20 = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(((size_t)(from) + ((size_t)(1LL) * sizeof(uint8_t)))));
int32_t cleanup_return_2 = private_check_same_declared_type(value_18, value_19, value_20, (int32_t)((uint32_t)depth + 1u));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(from_element_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(to_element_storage_0));
return cleanup_return_2;
@@ -4014,8 +4029,22 @@ private_check_vec_option_result_type(Checker* c, uint8_t* element, ZirSourceSpan
}
}
hash = (uint64_t)(((uint64_t)hash ^ UINT64_C(40)) * UINT64_C(1099511628211));
void* value_7 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray4096_u8));
CheckArray4096_u8* identity_storage = (CheckArray4096_u8*)(value_7);
bool value_8 = zir_f_6d0830be4da0a0ed_type_application_identity(c->module, (uint8_t*)(&((canonical_storage_0[0]).items)), (uint8_t*)(&((identity_storage[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray4096_u8)))) != 0;
if (!value_8) {
Checker* value_9 = c;
ZirSourceSpan value_10 = span;
uint8_t* value_11 = compiler_check_types_CheckCString(StringLiteral("Vec result element type is too long"));
zir_f_6d0830be4da0a0ed_error(value_9, value_10, value_11, element);
int32_t cleanup_return_1 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_1;
}
{
uint8_t* p = (uint8_t*)((uint8_t*)(&((canonical_storage_0[0]).items)));
uint8_t* p = (uint8_t*)((uint8_t*)(&((identity_storage[0]).items)));
while (true) {
bool check_loop_104 = p[0] != 0;
if (!check_loop_104) {
@@ -4025,8 +4054,8 @@ private_check_vec_option_result_type(Checker* c, uint8_t* element, ZirSourceSpan
compiler_check_types_CheckPost6(&(p));
}
}
uint8_t* value_7 = compiler_check_types_CheckCString(StringLiteral("__type_%016llx"));
zir_f_6d0830be4da0a0ed_snprintf((uint8_t*)(&((name_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), value_7, hash);
uint8_t* value_12 = compiler_check_types_CheckCString(StringLiteral("__type_%016llx"));
zir_f_6d0830be4da0a0ed_snprintf((uint8_t*)(&((name_storage_1[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), value_12, hash);
{
int32_t t = 0;
while (true) {
@@ -4036,103 +4065,107 @@ private_check_vec_option_result_type(Checker* c, uint8_t* element, ZirSourceSpan
}
if (zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&((c->module->types[t]).name)), (uint8_t*)(&((name_storage_1[0]).items))) == 0) {
zir_f_6d0830be4da0a0ed_copy_text(out, size, (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_1 = 1;
int32_t cleanup_return_2 = 1;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_1;
return cleanup_return_2;
}
compiler_check_types_CheckPost0(&(t));
}
}
ZirModule* value_8 = c->module;
uint8_t* value_9 = compiler_check_types_CheckCString(StringLiteral("Option"));
ZirType* generic = zir_f_6d0830be4da0a0ed_FindType(value_8, value_9, (void *)0);
void* value_10 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* parameter_storage_2 = (CheckArray128_u8*)(value_10);
ZirModule* value_13 = c->module;
uint8_t* value_14 = compiler_check_types_CheckCString(StringLiteral("Option"));
ZirType* generic = zir_f_6d0830be4da0a0ed_FindType(value_13, value_14, (void *)0);
void* value_15 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray128_u8));
CheckArray128_u8* parameter_storage_2 = (CheckArray128_u8*)(value_15);
zir_f_6d0830be4da0a0ed_memset((void*)(parameter_storage_2), 0, sizeof(CheckArray128_u8));
uint8_t* value_11 = (uint8_t*)(parameter_storage_2);
zir_f_6d0830be4da0a0ed_copy_text(value_11, sizeof(CheckArray128_u8), compiler_check_types_CheckCString(StringLiteral("")));
uint8_t* value_16 = (uint8_t*)(parameter_storage_2);
zir_f_6d0830be4da0a0ed_copy_text(value_16, sizeof(CheckArray128_u8), compiler_check_types_CheckCString(StringLiteral("")));
uint8_t* cursor = (void *)0;
uint8_t* dollar = (void *)0;
size_t length = (size_t)(0LL);
size_t offset = (size_t)(0LL);
ZirTypeField field = {0};
if (generic == (ZirType*)(((void *)0)) || !(generic->is_record_template != 0)) {
Checker* value_12 = c;
ZirSourceSpan value_13 = span;
uint8_t* value_14 = compiler_check_types_CheckCString(StringLiteral("Vec result requires the Option record; import option"));
zir_f_6d0830be4da0a0ed_error(value_12, value_13, value_14, element);
int32_t cleanup_return_2 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_2;
}
cursor = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(&(generic->template_params)));
uint8_t* value_15 = (void *)0;
if ((int32_t)((int8_t)(cursor[0])) == 36) {
value_15 = (uint8_t*)(((size_t)(cursor) + ((size_t)(1LL) * sizeof(uint8_t))));
} else {
value_15 = cursor;
}
dollar = value_15;
while (true) {
bool value_16 = zir_f_6d0830be4da0a0ed_isalnum((int32_t)(dollar[length])) != 0;
bool value_17 = value_16 || (int32_t)((int8_t)(dollar[length])) == 95;
if (value_17) {
uint64_t value_18 = (uint64_t)((length + (size_t)(1LL)));
uint64_t value_19 = (uint64_t)(sizeof(CheckArray128_u8));
value_17 = (value_18 < value_19);
}
bool check_loop_106 = value_17;
if (!check_loop_106) {
break;
}
uint8_t* value_20 = &(((parameter_storage_2[0]).items)[length]);
(*value_20) = dollar[length];
compiler_check_types_CheckPost5(&(length));
}
uint8_t* value_21 = &(((parameter_storage_2[0]).items)[length]);
(*value_21) = 0;
bool value_22 = zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 1;
bool value_23 = value_22 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.name)), compiler_check_types_CheckCString(StringLiteral("has_value"))) != 0;
bool value_24 = value_23 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.type)), compiler_check_types_CheckCString(StringLiteral("bool"))) != 0;
bool value_25 = value_24 || zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 1;
bool value_26 = value_25 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.name)), compiler_check_types_CheckCString(StringLiteral("value"))) != 0;
bool value_27 = value_26 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.type)), (uint8_t*)(&((parameter_storage_2[0]).items))) != 0;
if (value_27 || zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 0) {
Checker* value_28 = c;
ZirSourceSpan value_29 = span;
zir_f_6d0830be4da0a0ed_error(value_28, value_29, compiler_check_types_CheckCString(StringLiteral("Vec result requires Option fields has_value and value")), (uint8_t*)(&(generic->name)));
Checker* value_17 = c;
ZirSourceSpan value_18 = span;
uint8_t* value_19 = compiler_check_types_CheckCString(StringLiteral("Vec result requires the Option record; import option"));
zir_f_6d0830be4da0a0ed_error(value_17, value_18, value_19, element);
int32_t cleanup_return_3 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_3;
}
cursor = zir_f_6d0830be4da0a0ed_skip_ws((uint8_t*)(&(generic->template_params)));
uint8_t* value_20 = (void *)0;
if ((int32_t)((int8_t)(cursor[0])) == 36) {
value_20 = (uint8_t*)(((size_t)(cursor) + ((size_t)(1LL) * sizeof(uint8_t))));
} else {
value_20 = cursor;
}
dollar = value_20;
while (true) {
bool value_21 = zir_f_6d0830be4da0a0ed_isalnum((int32_t)(dollar[length])) != 0;
bool value_22 = value_21 || (int32_t)((int8_t)(dollar[length])) == 95;
if (value_22) {
uint64_t value_23 = (uint64_t)((length + (size_t)(1LL)));
uint64_t value_24 = (uint64_t)(sizeof(CheckArray128_u8));
value_22 = (value_23 < value_24);
}
bool check_loop_106 = value_22;
if (!check_loop_106) {
break;
}
uint8_t* value_25 = &(((parameter_storage_2[0]).items)[length]);
(*value_25) = dollar[length];
compiler_check_types_CheckPost5(&(length));
}
uint8_t* value_26 = &(((parameter_storage_2[0]).items)[length]);
(*value_26) = 0;
bool value_27 = zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 1;
bool value_28 = value_27 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.name)), compiler_check_types_CheckCString(StringLiteral("has_value"))) != 0;
bool value_29 = value_28 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.type)), compiler_check_types_CheckCString(StringLiteral("bool"))) != 0;
bool value_30 = value_29 || zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 1;
bool value_31 = value_30 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.name)), compiler_check_types_CheckCString(StringLiteral("value"))) != 0;
bool value_32 = value_31 || zir_f_6d0830be4da0a0ed_strcmp((uint8_t*)(&(field.type)), (uint8_t*)(&((parameter_storage_2[0]).items))) != 0;
if (value_32 || zir_f_6d0830be4da0a0ed_TypeNextField(generic, &(offset), &(field)) != 0) {
Checker* value_33 = c;
ZirSourceSpan value_34 = span;
zir_f_6d0830be4da0a0ed_error(value_33, value_34, compiler_check_types_CheckCString(StringLiteral("Vec result requires Option fields has_value and value")), (uint8_t*)(&(generic->name)));
int32_t cleanup_return_4 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_4;
}
int32_t generic_public = generic->is_public;
int32_t generic_file_private = generic->is_file_private;
ZirType* instance = zir_f_6d0830be4da0a0ed_ModuleAddType(c->module, (uint8_t*)(&((name_storage_1[0]).items)), span);
if (instance == (ZirType*)(((void *)0))) {
Checker* value_30 = c;
ZirSourceSpan value_31 = span;
zir_f_6d0830be4da0a0ed_error(value_30, value_31, compiler_check_types_CheckCString(StringLiteral("cannot register Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_4 = 0;
Checker* value_35 = c;
ZirSourceSpan value_36 = span;
zir_f_6d0830be4da0a0ed_error(value_35, value_36, compiler_check_types_CheckCString(StringLiteral("cannot register Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_5 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_4;
return cleanup_return_5;
}
zir_f_6d0830be4da0a0ed_TypeApplicationScope(c->module, (uint8_t*)(&((canonical_storage_0[0]).items)), generic_public, generic_file_private, instance);
int32_t* value_32 = &(instance->is_type_instance);
(*value_32) = 1;
int32_t* value_33 = &(instance->is_synthetic_application);
(*value_33) = 1;
int32_t* value_37 = &(instance->is_type_instance);
(*value_37) = 1;
int32_t* value_38 = &(instance->is_synthetic_application);
(*value_38) = 1;
zir_f_6d0830be4da0a0ed_copy_text((uint8_t*)(&(instance->template_name)), (size_t)((uint64_t)(sizeof(CheckArray128_u8))), compiler_check_types_CheckCString(StringLiteral("Option")));
zir_f_6d0830be4da0a0ed_copy_text((uint8_t*)(&(instance->template_args)), (size_t)((uint64_t)(sizeof(CheckArray4096_u8))), (uint8_t*)(&((canonical_storage_0[0]).items)));
ZirModule* value_34 = c->module;
uint8_t* value_35 = compiler_check_types_CheckCString(StringLiteral("Option"));
generic = zir_f_6d0830be4da0a0ed_FindType(value_34, value_35, (void *)0);
ZirModule* value_39 = c->module;
uint8_t* value_40 = compiler_check_types_CheckCString(StringLiteral("Option"));
generic = zir_f_6d0830be4da0a0ed_FindType(value_39, value_40, (void *)0);
instance = (void *)0;
{
int32_t t = 0;
@@ -4152,21 +4185,22 @@ private_check_vec_option_result_type(Checker* c, uint8_t* element, ZirSourceSpan
}
zir_loop_break_5: ;
}
bool value_36 = instance == (ZirType*)(((void *)0)) || generic == (ZirType*)(((void *)0));
bool value_37 = value_36;
if (!value_37) {
bool value_38 = zir_f_6d0830be4da0a0ed_InstantiateGenericRecord(instance, generic) != 0;
value_37 = !value_38;
bool value_41 = instance == (ZirType*)(((void *)0)) || generic == (ZirType*)(((void *)0));
bool value_42 = value_41;
if (!value_42) {
bool value_43 = zir_f_6d0830be4da0a0ed_InstantiateGenericRecord(instance, generic) != 0;
value_42 = !value_43;
}
if (value_37) {
Checker* value_39 = c;
ZirSourceSpan value_40 = span;
zir_f_6d0830be4da0a0ed_error(value_39, value_40, compiler_check_types_CheckCString(StringLiteral("cannot instantiate Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_5 = 0;
if (value_42) {
Checker* value_44 = c;
ZirSourceSpan value_45 = span;
zir_f_6d0830be4da0a0ed_error(value_44, value_45, compiler_check_types_CheckCString(StringLiteral("cannot instantiate Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_6 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_5;
return cleanup_return_6;
}
instance = (void *)0;
{
@@ -4188,30 +4222,32 @@ private_check_vec_option_result_type(Checker* c, uint8_t* element, ZirSourceSpan
zir_loop_break_6: ;
}
if (instance != (ZirType*)(((void *)0)) && (instance->body)[0] != 0) {
void* value_41 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray8192_u8));
CheckArray8192_u8* expanded_storage_3 = (CheckArray8192_u8*)(value_41);
void* value_46 = zir_f_6d0830be4da0a0ed_AllocateOrExit(sizeof(CheckArray8192_u8));
CheckArray8192_u8* expanded_storage_3 = (CheckArray8192_u8*)(value_46);
zir_f_6d0830be4da0a0ed_memset((void*)(expanded_storage_3), 0, sizeof(CheckArray8192_u8));
bool value_42 = zir_f_6d0830be4da0a0ed_rewrite_type_applications(c->module, (uint8_t*)(&(instance->body)), (uint8_t*)(&((expanded_storage_3[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray8192_u8))), span, 0) != 0;
if (!value_42) {
Checker* value_43 = c;
ZirSourceSpan value_44 = span;
zir_f_6d0830be4da0a0ed_error(value_43, value_44, compiler_check_types_CheckCString(StringLiteral("cannot expand Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_6 = 0;
bool value_47 = zir_f_6d0830be4da0a0ed_rewrite_type_applications(c->module, (uint8_t*)(&(instance->body)), (uint8_t*)(&((expanded_storage_3[0]).items)), (size_t)((uint64_t)(sizeof(CheckArray8192_u8))), span, 0) != 0;
if (!value_47) {
Checker* value_48 = c;
ZirSourceSpan value_49 = span;
zir_f_6d0830be4da0a0ed_error(value_48, value_49, compiler_check_types_CheckCString(StringLiteral("cannot expand Vec result record")), (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_7 = 0;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(expanded_storage_3));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_6;
return cleanup_return_7;
}
zir_f_6d0830be4da0a0ed_copy_text((uint8_t*)(&(instance->body)), (size_t)((uint64_t)(sizeof(CheckArray8192_u8))), (uint8_t*)(&((expanded_storage_3[0]).items)));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(expanded_storage_3));
}
zir_f_6d0830be4da0a0ed_copy_text(out, size, (uint8_t*)(&((name_storage_1[0]).items)));
int32_t cleanup_return_7 = 1;
int32_t cleanup_return_8 = 1;
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(parameter_storage_2));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(identity_storage));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(name_storage_1));
zir_f_6d0830be4da0a0ed_CompilerFree((void*)(canonical_storage_0));
return cleanup_return_7;
return cleanup_return_8;
}
int32_t
@@ -824,6 +824,7 @@ static GeneratedOutputs* compiler_frontend_ir_context_outputs(void) ZIRAN_MAYBE_
static uint8_t* compiler_frontend_ir_path_base_name(uint8_t* path) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_frontend_ir_same_file_bytes_with_buffers(uint8_t* left, uint8_t* right, SameFileBytesBuffers* buffers) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_frontend_ir_starts_with_marker(uint8_t* path, uint8_t* marker) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_frontend_ir_same_type_argument(ZirModule* target_owner, uint8_t* target, ZirModule* source_owner, uint8_t* source, int32_t depth) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_frontend_ir_same_type_application_at_depth(ZirModule* target_owner, ZirType* target, ZirModule* source_owner, ZirType* source, int32_t depth) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_frontend_ir_copy_part(uint8_t* output, size_t capacity, String part) ZIRAN_MAYBE_UNUSED;
static FieldSnapshots* compiler_frontend_ir_context_fields(CompilerThread* thread) ZIRAN_MAYBE_UNUSED;
@@ -7008,6 +7009,58 @@ GeneratedOutputPrune(uint8_t* out_dir, uint8_t* marker)
return compiler_frontend_ir_prune_generated(out_dir, marker, 0);
}
static int32_t
compiler_frontend_ir_same_type_argument(ZirModule* target_owner, uint8_t* target, ZirModule* source_owner, uint8_t* source, int32_t depth)
{
while (zir_f_c9f352eed87788d1_isspace((int32_t)(target[0])) != 0) {
target = (uint8_t*)(((size_t)(target) + 1));
}
while (zir_f_c9f352eed87788d1_isspace((int32_t)(source[0])) != 0) {
source = (uint8_t*)(((size_t)(source) + 1));
}
if (target[0] == 42 || source[0] == 42) {
if (target[0] != source[0]) {
return 0;
}
return compiler_frontend_ir_same_type_argument(target_owner, (uint8_t*)(((size_t)(target) + 1)), source_owner, (uint8_t*)(((size_t)(source) + 1)), depth);
}
if (target[0] == 91 || source[0] == 91) {
uint8_t* target_close = zir_f_c9f352eed87788d1_strchr(target, 93);
uint8_t* source_close = zir_f_c9f352eed87788d1_strchr(source, 93);
if (target_close == ((void *)0) || source_close == ((void *)0)) {
return 0;
}
size_t length = (size_t)(target_close) - (size_t)(target);
if (length != (size_t)(source_close) - (size_t)(source) || zir_f_c9f352eed87788d1_strncmp(target, source, length) != 0) {
return 0;
}
return compiler_frontend_ir_same_type_argument(target_owner, (uint8_t*)(((size_t)(target_close) + 1)), source_owner, (uint8_t*)(((size_t)(source_close) + 1)), depth);
}
uint8_t* target_scalar = zir_f_c9f352eed87788d1_ScalarType(target);
uint8_t* source_scalar = zir_f_c9f352eed87788d1_ScalarType(source);
if (target_scalar[0] != 0 || source_scalar[0] != 0) {
bool value_0 = zir_f_c9f352eed87788d1_strcmp(target_scalar, source_scalar) == 0;
int32_t value_1 = 0;
if (value_0) {
value_1 = 1;
}
return value_1;
}
ZirModule* a_owner = (void *)0;
ZirModule* b_owner = (void *)0;
ZirType* a = FindType(target_owner, target, &(a_owner));
ZirType* b = FindType(source_owner, source, &(b_owner));
if (a == ((void *)0) || b == ((void *)0)) {
return 0;
}
bool value_2 = a == b || compiler_frontend_ir_same_type_application_at_depth(a_owner, a, b_owner, b, (int32_t)((uint32_t)depth + 1u)) != 0;
int32_t value_3 = 0;
if (value_2) {
value_3 = 1;
}
return value_3;
}
static int32_t
compiler_frontend_ir_same_type_application_at_depth(ZirModule* target_owner, ZirType* target, ZirModule* source_owner, ZirType* source, int32_t depth)
{
@@ -7015,9 +7068,7 @@ compiler_frontend_ir_same_type_application_at_depth(ZirModule* target_owner, Zir
return 0;
}
bool value_0 = target != (ZirType*)(((void *)0)) && source != (ZirType*)(((void *)0)) && target_owner != (ZirModule*)(((void *)0));
bool value_1 = value_0 && source_owner != (ZirModule*)(((void *)0)) && target->is_synthetic_application != 0 && source->is_synthetic_application != 0;
bool value_2 = value_1;
if (value_2 && zir_f_c9f352eed87788d1_strcmp((uint8_t*)(&(target->body)), (uint8_t*)(&(source->body))) == 0) {
if (value_0 && source_owner != (ZirModule*)(((void *)0)) && target->is_synthetic_application != 0 && source->is_synthetic_application != 0) {
ZirType* target_template = FindType(target_owner, (uint8_t*)(&(target->template_name)), (void *)0);
ZirType* source_template = FindType(source_owner, (uint8_t*)(&(source->template_name)), (void *)0);
if (target_template != (ZirType*)(((void *)0)) && target_template == source_template) {
@@ -7025,11 +7076,11 @@ compiler_frontend_ir_same_type_application_at_depth(ZirModule* target_owner, Zir
CoreArray16_CoreArray128_u8 source_args = {0};
int32_t target_count = zir_f_c9f352eed87788d1_split_top_level((uint8_t*)(&(target->template_args)), (uint8_t*)(&(((target_args.items[0]).items)[0])), 16, (size_t)(128LL));
int32_t source_count = zir_f_c9f352eed87788d1_split_top_level((uint8_t*)(&(source->template_args)), (uint8_t*)(&(((source_args.items[0]).items)[0])), 16, (size_t)(128LL));
int32_t value_3 = 0;
int32_t value_1 = 0;
if (target_count > 0 && target_count < 16 && target_count == source_count) {
value_3 = 1;
value_1 = 1;
}
int32_t same = value_3;
int32_t same = value_1;
{
int32_t i = 0;
while (true) {
@@ -7037,43 +7088,17 @@ compiler_frontend_ir_same_type_application_at_depth(ZirModule* target_owner, Zir
if (!check_loop_68) {
break;
}
uint8_t* target_scalar = zir_f_c9f352eed87788d1_ScalarType((uint8_t*)(&(((target_args.items[i]).items)[0])));
uint8_t* source_scalar = zir_f_c9f352eed87788d1_ScalarType((uint8_t*)(&(((source_args.items[i]).items)[0])));
if (target_scalar[0] != 0 || source_scalar[0] != 0) {
bool value_4 = zir_f_c9f352eed87788d1_strcmp(target_scalar, source_scalar) == 0;
int32_t value_5 = 0;
if (value_4) {
value_5 = 1;
}
same = value_5;
} else {
ZirModule* a_owner = (void *)0;
ZirModule* b_owner = (void *)0;
ZirType* a = FindType(target_owner, (uint8_t*)(&(((target_args.items[i]).items)[0])), &(a_owner));
ZirType* b = FindType(source_owner, (uint8_t*)(&(((source_args.items[i]).items)[0])), &(b_owner));
bool value_6 = a != (ZirType*)(((void *)0)) && b != (ZirType*)(((void *)0));
bool value_7 = value_6;
if (value_7) {
bool value_8 = a == b;
bool value_9 = value_8 || compiler_frontend_ir_same_type_application_at_depth(a_owner, a, b_owner, b, (int32_t)((uint32_t)depth + 1u)) != 0;
value_7 = value_9;
}
int32_t value_10 = 0;
if (value_7) {
value_10 = 1;
}
same = value_10;
}
int32_t* value_11 = &(i);
int32_t value_12 = 0;
same = compiler_frontend_ir_same_type_argument(target_owner, (uint8_t*)(&(((target_args.items[i]).items)[0])), source_owner, (uint8_t*)(&(((source_args.items[i]).items)[0])), depth);
int32_t* value_2 = &(i);
int32_t value_3 = 0;
{
int32_t* p = value_11;
int32_t* p = value_2;
int32_t old = p[0];
int32_t* value_14 = &(p[0]);
(*value_14) = (int32_t)((uint32_t)(p[0]) + 1u);
value_12 = old;
int32_t* value_5 = &(p[0]);
(*value_5) = (int32_t)((uint32_t)(p[0]) + 1u);
value_3 = old;
}
(void)value_12;
(void)value_3;
}
}
if (same != 0) {
@@ -626,15 +626,15 @@ static void* compiler_zir_lower_Allocate(AssemblyProgram* program, size_t count,
static bool compiler_zir_lower_Push(AssemblyProgram* program, RawVector* vector, size_t width, void* value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushS32(AssemblyProgram* program, __type_0c8c2c2a7dfdc73a* vector, int32_t value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushString(AssemblyProgram* program, __type_5a6f11963c9bea0f* vector, String value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirType(AssemblyProgram* program, __type_54c6b18f653132c8* vector, LirType value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirConstant(AssemblyProgram* program, __type_02b39c93b9b3b114* vector, LirConstant value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirOrigin(AssemblyProgram* program, __type_fd7fa0ce6aa22182* vector, LirOrigin value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirType(AssemblyProgram* program, __type_ddeffb4af1d2a905* vector, LirType value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirConstant(AssemblyProgram* program, __type_df30cb38159eb83d* vector, LirConstant value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushLirOrigin(AssemblyProgram* program, __type_37ce17372029b897* vector, LirOrigin value) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_1(__type_a179548355995a8b vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_2(__type_0c8c2c2a7dfdc73a vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_3(__type_5a6f11963c9bea0f vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_4(__type_54c6b18f653132c8 vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_5(__type_02b39c93b9b3b114 vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_6(__type_fd7fa0ce6aa22182 vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_4(__type_ddeffb4af1d2a905 vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_5(__type_df30cb38159eb83d vector) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_SliceOf__overload_6(__type_37ce17372029b897 vector) ZIRAN_MAYBE_UNUSED;
static uint8_t* compiler_zir_lower_Text(AssemblyProgram* program, uint8_t* text) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_zir_lower_Name(AssemblyProgram* program, __type_5a6f11963c9bea0f* names, uint8_t* name) ZIRAN_MAYBE_UNUSED;
static int32_t compiler_zir_lower_Origin(AssemblyProgram* program, ZirSourceSpan span) ZIRAN_MAYBE_UNUSED;
@@ -645,8 +645,8 @@ static bool compiler_zir_lower_PushFunctionPtr(AssemblyProgram* program, __type_
static bool compiler_zir_lower_PushBlock(AssemblyProgram* program, __type_67ee5567ed548753* vector, AssemblyBlock value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushBinding(AssemblyProgram* program, __type_dd536e055506338b* vector, AssemblyBinding value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushZeroSlot(AssemblyProgram* program, __type_745e0b4796abfa08* vector, AssemblyZeroSlot value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushProbe(AssemblyProgram* program, __type_9059301564cb61cc* vector, ZirFunction* value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushInstruction(AssemblyProgram* program, __type_ace813280a8878e0* vector, LirInstruction value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushProbe(AssemblyProgram* program, __type_f12db627436ed32d* vector, ZirFunction* value) ZIRAN_MAYBE_UNUSED;
static bool compiler_zir_lower_PushInstruction(AssemblyProgram* program, __type_64f69ff50dc44167* vector, LirInstruction value) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_LirEdgeItems(LirEdge* data, int64_t count) ZIRAN_MAYBE_UNUSED;
static Slice compiler_zir_lower_LirInstructionItems(LirInstruction* data, int64_t count) ZIRAN_MAYBE_UNUSED;
static LirType* compiler_zir_lower_TypeAt(AssemblyProgram* program, int32_t identity) ZIRAN_MAYBE_UNUSED;
@@ -1300,19 +1300,19 @@ compiler_zir_lower_PushString(AssemblyProgram* program, __type_5a6f11963c9bea0f*
}
static bool
compiler_zir_lower_PushLirType(AssemblyProgram* program, __type_54c6b18f653132c8* vector, LirType value)
compiler_zir_lower_PushLirType(AssemblyProgram* program, __type_ddeffb4af1d2a905* vector, LirType value)
{
return compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(LirType), (void*)(&(value)));
}
static bool
compiler_zir_lower_PushLirConstant(AssemblyProgram* program, __type_02b39c93b9b3b114* vector, LirConstant value)
compiler_zir_lower_PushLirConstant(AssemblyProgram* program, __type_df30cb38159eb83d* vector, LirConstant value)
{
return compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(LirConstant), (void*)(&(value)));
}
static bool
compiler_zir_lower_PushLirOrigin(AssemblyProgram* program, __type_fd7fa0ce6aa22182* vector, LirOrigin value)
compiler_zir_lower_PushLirOrigin(AssemblyProgram* program, __type_37ce17372029b897* vector, LirOrigin value)
{
return compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(LirOrigin), (void*)(&(value)));
}
@@ -1336,19 +1336,19 @@ compiler_zir_lower_SliceOf__overload_3(__type_5a6f11963c9bea0f vector)
}
static Slice
compiler_zir_lower_SliceOf__overload_4(__type_54c6b18f653132c8 vector)
compiler_zir_lower_SliceOf__overload_4(__type_ddeffb4af1d2a905 vector)
{
return compiler_zir_lower_LirTypeItems(vector.data, (int64_t)(vector.count));
}
static Slice
compiler_zir_lower_SliceOf__overload_5(__type_02b39c93b9b3b114 vector)
compiler_zir_lower_SliceOf__overload_5(__type_df30cb38159eb83d vector)
{
return compiler_zir_lower_LirConstantItems(vector.data, (int64_t)(vector.count));
}
static Slice
compiler_zir_lower_SliceOf__overload_6(__type_fd7fa0ce6aa22182 vector)
compiler_zir_lower_SliceOf__overload_6(__type_37ce17372029b897 vector)
{
return compiler_zir_lower_LirOriginItems(vector.data, (int64_t)(vector.count));
}
@@ -1445,11 +1445,11 @@ compiler_zir_lower_Origin(AssemblyProgram* program, ZirSourceSpan span)
}
int32_t index = program->origins.count;
AssemblyProgram* value_5 = program;
__type_fd7fa0ce6aa22182* value_6 = &(program->origins);
__type_37ce17372029b897* value_6 = &(program->origins);
bool value_7 = false;
{
AssemblyProgram* program = value_5;
__type_fd7fa0ce6aa22182* vector = value_6;
__type_37ce17372029b897* vector = value_6;
LirOrigin value = origin;
value_7 = compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(LirOrigin), (void*)(&(value)));
}
@@ -1525,13 +1525,13 @@ compiler_zir_lower_PushZeroSlot(AssemblyProgram* program, __type_745e0b4796abfa0
}
static bool
compiler_zir_lower_PushProbe(AssemblyProgram* program, __type_9059301564cb61cc* vector, ZirFunction* value)
compiler_zir_lower_PushProbe(AssemblyProgram* program, __type_f12db627436ed32d* vector, ZirFunction* value)
{
return compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(void *), (void*)(&(value)));
}
static bool
compiler_zir_lower_PushInstruction(AssemblyProgram* program, __type_ace813280a8878e0* vector, LirInstruction value)
compiler_zir_lower_PushInstruction(AssemblyProgram* program, __type_64f69ff50dc44167* vector, LirInstruction value)
{
return compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(LirInstruction), (void*)(&(value)));
}
@@ -3023,11 +3023,11 @@ compiler_zir_lower_ConstantInitializer(AssemblyProgram* program, ZirModule* owne
}
int32_t root = zir_f_0fe5ce4064831140_ParseExprTyped(probe, owner, (void*)(((uint8_t*)source->init)), source->span, (void*)(&(source->type[0])));
AssemblyProgram* value_2 = program;
__type_9059301564cb61cc* value_3 = &(program->probes);
__type_f12db627436ed32d* value_3 = &(program->probes);
bool value_4 = false;
{
AssemblyProgram* program = value_2;
__type_9059301564cb61cc* vector = value_3;
__type_f12db627436ed32d* vector = value_3;
ZirFunction* value = probe;
value_4 = compiler_zir_lower_Push(program, (RawVector*)(vector), sizeof(void *), (void*)(&(value)));
}
@@ -309,9 +309,9 @@ typedef struct AssemblyGlobal AssemblyGlobal;
#define ZIRAN_CONCRETE_FORWARD___type_0c8c2c2a7dfdc73a
typedef struct __type_0c8c2c2a7dfdc73a __type_0c8c2c2a7dfdc73a;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_ace813280a8878e0
#define ZIRAN_CONCRETE_FORWARD___type_ace813280a8878e0
typedef struct __type_ace813280a8878e0 __type_ace813280a8878e0;
#ifndef ZIRAN_CONCRETE_FORWARD___type_64f69ff50dc44167
#define ZIRAN_CONCRETE_FORWARD___type_64f69ff50dc44167
typedef struct __type_64f69ff50dc44167 __type_64f69ff50dc44167;
#endif
typedef struct AssemblyBlock AssemblyBlock;
typedef struct AssemblyZeroSlot AssemblyZeroSlot;
@@ -334,29 +334,29 @@ typedef struct AssemblyExportRoot AssemblyExportRoot;
#define ZIRAN_CONCRETE_FORWARD___type_5a6f11963c9bea0f
typedef struct __type_5a6f11963c9bea0f __type_5a6f11963c9bea0f;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_02b39c93b9b3b114
#define ZIRAN_CONCRETE_FORWARD___type_02b39c93b9b3b114
typedef struct __type_02b39c93b9b3b114 __type_02b39c93b9b3b114;
#ifndef ZIRAN_CONCRETE_FORWARD___type_df30cb38159eb83d
#define ZIRAN_CONCRETE_FORWARD___type_df30cb38159eb83d
typedef struct __type_df30cb38159eb83d __type_df30cb38159eb83d;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_01190c4c4b9b9bf1
#define ZIRAN_CONCRETE_FORWARD___type_01190c4c4b9b9bf1
typedef struct __type_01190c4c4b9b9bf1 __type_01190c4c4b9b9bf1;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_fd7fa0ce6aa22182
#define ZIRAN_CONCRETE_FORWARD___type_fd7fa0ce6aa22182
typedef struct __type_fd7fa0ce6aa22182 __type_fd7fa0ce6aa22182;
#ifndef ZIRAN_CONCRETE_FORWARD___type_37ce17372029b897
#define ZIRAN_CONCRETE_FORWARD___type_37ce17372029b897
typedef struct __type_37ce17372029b897 __type_37ce17372029b897;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_4903477303ada8c0
#define ZIRAN_CONCRETE_FORWARD___type_4903477303ada8c0
typedef struct __type_4903477303ada8c0 __type_4903477303ada8c0;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_9059301564cb61cc
#define ZIRAN_CONCRETE_FORWARD___type_9059301564cb61cc
typedef struct __type_9059301564cb61cc __type_9059301564cb61cc;
#ifndef ZIRAN_CONCRETE_FORWARD___type_f12db627436ed32d
#define ZIRAN_CONCRETE_FORWARD___type_f12db627436ed32d
typedef struct __type_f12db627436ed32d __type_f12db627436ed32d;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_54c6b18f653132c8
#define ZIRAN_CONCRETE_FORWARD___type_54c6b18f653132c8
typedef struct __type_54c6b18f653132c8 __type_54c6b18f653132c8;
#ifndef ZIRAN_CONCRETE_FORWARD___type_ddeffb4af1d2a905
#define ZIRAN_CONCRETE_FORWARD___type_ddeffb4af1d2a905
typedef struct __type_ddeffb4af1d2a905 __type_ddeffb4af1d2a905;
#endif
#ifndef ZIRAN_CONCRETE_FORWARD___type_ebdb196ca6e54c46
#define ZIRAN_CONCRETE_FORWARD___type_ebdb196ca6e54c46
@@ -559,10 +559,10 @@ struct __type_0c8c2c2a7dfdc73a {
int32_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_ace813280a8878e0
#define ZIRAN_CONCRETE___type_ace813280a8878e0
#ifndef ZIRAN_CONCRETE___type_64f69ff50dc44167
#define ZIRAN_CONCRETE___type_64f69ff50dc44167
struct __type_ace813280a8878e0 {
struct __type_64f69ff50dc44167 {
LirInstruction* data;
int32_t count;
int32_t capacity;
@@ -571,7 +571,7 @@ struct __type_ace813280a8878e0 {
struct AssemblyBlock {
__type_0c8c2c2a7dfdc73a parameters;
__type_ace813280a8878e0 instructions;
__type_64f69ff50dc44167 instructions;
int32_t effect;
};
@@ -649,10 +649,10 @@ struct __type_5a6f11963c9bea0f {
int32_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_02b39c93b9b3b114
#define ZIRAN_CONCRETE___type_02b39c93b9b3b114
#ifndef ZIRAN_CONCRETE___type_df30cb38159eb83d
#define ZIRAN_CONCRETE___type_df30cb38159eb83d
struct __type_02b39c93b9b3b114 {
struct __type_df30cb38159eb83d {
LirConstant* data;
int32_t count;
int32_t capacity;
@@ -667,10 +667,10 @@ struct __type_01190c4c4b9b9bf1 {
int32_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_fd7fa0ce6aa22182
#define ZIRAN_CONCRETE___type_fd7fa0ce6aa22182
#ifndef ZIRAN_CONCRETE___type_37ce17372029b897
#define ZIRAN_CONCRETE___type_37ce17372029b897
struct __type_fd7fa0ce6aa22182 {
struct __type_37ce17372029b897 {
LirOrigin* data;
int32_t count;
int32_t capacity;
@@ -685,19 +685,19 @@ struct __type_4903477303ada8c0 {
int32_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_9059301564cb61cc
#define ZIRAN_CONCRETE___type_9059301564cb61cc
#ifndef ZIRAN_CONCRETE___type_f12db627436ed32d
#define ZIRAN_CONCRETE___type_f12db627436ed32d
struct __type_9059301564cb61cc {
struct __type_f12db627436ed32d {
ZirFunction** data;
int32_t count;
int32_t capacity;
};
#endif
#ifndef ZIRAN_CONCRETE___type_54c6b18f653132c8
#define ZIRAN_CONCRETE___type_54c6b18f653132c8
#ifndef ZIRAN_CONCRETE___type_ddeffb4af1d2a905
#define ZIRAN_CONCRETE___type_ddeffb4af1d2a905
struct __type_54c6b18f653132c8 {
struct __type_ddeffb4af1d2a905 {
LirType* data;
int32_t count;
int32_t capacity;
@@ -719,14 +719,14 @@ struct AssemblyProgram {
Allocation* allocations;
__type_5a6f11963c9bea0f modules;
__type_5a6f11963c9bea0f sources;
__type_02b39c93b9b3b114 constants;
__type_df30cb38159eb83d constants;
__type_01190c4c4b9b9bf1 globals;
__type_fd7fa0ce6aa22182 origins;
__type_37ce17372029b897 origins;
__type_4903477303ada8c0 functions;
__type_0c8c2c2a7dfdc73a initializers;
__type_0c8c2c2a7dfdc73a constant_initializers;
__type_9059301564cb61cc probes;
__type_54c6b18f653132c8 types;
__type_f12db627436ed32d probes;
__type_ddeffb4af1d2a905 types;
__type_ebdb196ca6e54c46 type_names;
size_t bytes;
int64_t work;
+78
View File
@@ -481,6 +481,18 @@ IsCRuntimeName :: (name: string) -> bool {
return false
}
// File-scope names of the runtime headers the generated C includes
// (zir_string_types.h, zir_string.h, zir_slice.h, zir_bounds.h, zir_vec.h).
// A top-level constant, global or type with one of these names is renamed.
IsCRuntimeHeaderName :: (name: string) -> bool {
words := string.["String", "Source_Code_Location", "StringView", "StringLiteral",
"StringRange", "StringRangeAt", "StringEqual", "print_float", "Slice", "SliceIndex",
"SliceRange", "SliceRangeAt", "BoundsCheck", "EmptyArrayIndex", "ZirVecGrow",
"ZirVecIndex", "ZirVecReserve", "ZirVecReserveBounded"]
for w: words { if name == w { return true } }
return false
}
IsGoRuntimeName :: (name: string) -> bool {
words: [41]string = .{
"any", "append", "bool", "byte", "cap", "clear", "close", "complex",
@@ -684,6 +696,69 @@ NativeNamesMarkTypeValues :: (names: *NativeValueNames) {
}
}
// A constant is an object-like C macro, which rewrites its spelling in all
// C that follows: the runtime's String and Slice members and any record
// field, parameter or local of another module. A constant spelled like one
// of them takes a mangled name.
MarkNativeMacroCollisions :: (programs: **IR.ZirProgram, count: s32) -> s32 {
defines: NativeValueNames
total: s32 = 0
for p: cast(s32)0..count - 1 {
for m: cast(s32)0..programs[p].module_count - 1 { total += programs[p].modules[m].define_count }
}
if total == 0 { return 1 }
defines.bucket_count = total * 2 + 1
defines.buckets = cast(*s32)malloc(cast(usize)defines.bucket_count * size_of(s32))
if defines.buckets == null { return 0 }
memset(cast(*void)defines.buckets, 0xff, cast(usize)defines.bucket_count * size_of(s32))
ok: s32 = 1
for p: cast(s32)0..count - 1 {
for m: cast(s32)0..programs[p].module_count - 1 {
module := *programs[p].modules[m]
for d: cast(s32)0..module.define_count - 1 {
if ok == 0 { break }
native: [IR.ZIR_NAME_MAX * 2]u8
TargetTopName(module, .ZIR_C, *module.defines[d].name[0], false, *native[0], IR.ZIR_NAME_MAX * 2)
ok = NativeNamesAdd(*defines, *native[0], *module.defines[d].native_name_collision, 0)
}
}
}
if ok != 0 {
members := string.["data", "length", "fully_pathed_filename", "line_number"]
for member: members { NativeNamesMark(*defines, CStr(member)) }
for p: cast(s32)0..count - 1 {
for m: cast(s32)0..programs[p].module_count - 1 {
module := *programs[p].modules[m]
for t: cast(s32)0..module.type_count - 1 {
type := *module.types[t]
if type.is_record_template != 0 || type.is_enum != 0 { continue }
offset: usize = 0
field: IR.ZirTypeField
while CTypeNextField(type, *offset, *field) == 1 { NativeNamesMark(*defines, *field.name[0]) }
}
for f: cast(s32)0..module.function_count - 1 {
function := *module.functions[f]
if function.is_template != 0 { continue }
args := FunctionArgs(function)
if args[0] != 0 {
parameters := ParametersOf(args)
items := cast(*CParameter)(*parameters.items[0])
for i: cast(s32)0..parameters.count - 1 {
if items[i].name != null { NativeNamesMark(*defines, items[i].name) }
}
}
for s: cast(s32)0..function.stmt_count - 1 {
st := *function.stmts[s]
if st.kind == .DECL && st.name != null && st.name[0] != 0 { NativeNamesMark(*defines, st.name) }
}
}
}
}
}
NativeNamesFree(*defines)
return ok
}
#scope_export
#program_export
@@ -721,6 +796,7 @@ MarkNativeNameCollisions :: (programs: **IR.ZirProgram, count: s32) -> s32 {
name, is_global, *native[0], IR.ZIR_NAME_MAX * 2)
ok = NativeNamesAdd(*names[t], *native[0], collision, 0)
}
if IsCRuntimeHeaderName(IR.CText(name)) || IsCRuntimeName(IR.CText(name)) { <<collision = 1 }
}
}
}
@@ -740,6 +816,7 @@ MarkNativeNameCollisions :: (programs: **IR.ZirProgram, count: s32) -> s32 {
native: [IR.ZIR_NAME_MAX * 2]u8
NativeTypeName(module, type, *native[0], IR.ZIR_NAME_MAX * 2)
ok = NativeNamesAdd(*names[0], *native[0], *type.native_name_mangled, 1)
if type.is_extern == 0 && IsCRuntimeHeaderName(IR.CText(*native[0])) { type.native_name_mangled = 1 }
}
}
}
@@ -773,6 +850,7 @@ MarkNativeNameCollisions :: (programs: **IR.ZirProgram, count: s32) -> s32 {
}
}
NativeNamesMarkTypeValues(*names[0])
ok = MarkNativeMacroCollisions(programs, count)
}
NativeNamesFree(*names[0])
NativeNamesFree(*names[1])
+74 -2
View File
@@ -141,6 +141,67 @@ canonical_type_arguments :: (source: *u8, output: *u8, capacity: usize) -> s32 {
return 1
}
// The spelling that names a type application: canonical arguments with each
// qualified type, such as Db.Match, spelled as its own module declares it
// (Match). An application then has one name in every module that spells it,
// and so one type. A qualified type keeps its spelling when the bare name
// means another type here.
#scope_export
#program_export "private_check_type_application_identity"
type_application_identity :: (module: *IR.ZirModule, canonical: *u8, output: *u8, capacity: usize) -> s32 {
used: usize = 0
at: usize = 0
quote: u8 = 0
while canonical[at] != 0 {
byte := canonical[at]
if quote == 0 && (isalpha(cast(s32)byte) != 0 || byte == #char "_") {
start := at
dotted := false
while isalnum(cast(s32)canonical[at]) != 0 || canonical[at] == #char "_" ||
(canonical[at] == #char "." && (isalpha(cast(s32)canonical[at + 1]) != 0 || canonical[at + 1] == #char "_")) {
if canonical[at] == #char "." { dotted = true }
at += 1
}
token := cast(*u8)(cast(usize)canonical + start)
length := at - start
if dotted && length < 256 {
path: [256]u8
memcpy(cast(*void)*path[0], cast(*void)token, length)
path[length] = 0
owner: *IR.ZirModule = null
type := FindType(module, *path[0], *owner)
if type != null && owner != null && owner != module {
local := FindType(module, *type.name[0], null)
if local == null || local == type {
token = *type.name[0]
length = strlen(token)
}
}
}
if used + length >= capacity { return 0 }
memcpy(cast(*void)(cast(usize)output + used), cast(*void)token, length)
used += length
continue
}
if used + 1 >= capacity { return 0 }
output[used] = byte
used += 1
if quote != 0 && byte == #char "\\" && canonical[at + 1] != 0 {
at += 1
if used + 1 >= capacity { return 0 }
output[used] = canonical[at]
used += 1
} else if quote != 0 && byte == quote {
quote = 0
} else if quote == 0 && (byte == #char "\"" || byte == #char "'") {
quote = byte
}
at += 1
}
output[used] = 0
return 1
}
#scope_export
#program_export "TypeApplicationScope"
TypeApplicationScope :: (module: *IR.ZirModule, arguments: *u8, template_public: s32, template_file_private: s32, instance: *IR.ZirType) {
@@ -258,6 +319,12 @@ rewrite_type_applications_with_buffers :: (module: *IR.ZirModule, source: *u8, o
Diagnostic(span, CheckCString("check.type_application"), CheckCString("type application arguments are too long: %s"), cast(*u8)(*((base_storage_0[0]).items)))
return 0
}
identity_storage := cast(*S12Array4096_u8)AllocateOrExit(size_of(S12Array4096_u8))
defer CompilerFree(cast(*void)identity_storage)
if !(type_application_identity(module, cast(*u8)(*(((buffers).canonical).items)), cast(*u8)(*((identity_storage[0]).items)), cast(usize)(cast(u64)size_of(S12Array4096_u8))) != 0) {
Diagnostic(span, CheckCString("check.type_application"), CheckCString("type application arguments are too long: %s"), cast(*u8)(*((base_storage_0[0]).items)))
return 0
}
hash: u64 = 14695981039346656037
{
p: *u8 = cast(*u8)(cast(*u8)(*((generic).name)))
@@ -268,7 +335,7 @@ rewrite_type_applications_with_buffers :: (module: *IR.ZirModule, source: *u8, o
}
hash = (((hash ^ cast(u64)(40))) * 1099511628211)
{
p: *u8 = cast(*u8)(cast(*u8)(*(((buffers).canonical).items)))
p: *u8 = cast(*u8)(cast(*u8)(*((identity_storage[0]).items)))
while check_loop_153 := ((p)[0] != 0) {
hash = (((hash ^ cast(u64)((p)[0]))) * 1099511628211)
S12Post1(*(p))
@@ -289,7 +356,12 @@ rewrite_type_applications_with_buffers :: (module: *IR.ZirModule, source: *u8, o
S12Post2(*(t))
}
}
if ((instance != cast(*IR.ZirType)((null))) && (!((instance).is_synthetic_application != 0) || (((instance).is_type_instance != 0) && ((FindType(module, cast(*u8)(*((instance).template_name)), null) != generic) || (strcmp(cast(*u8)(*((instance).template_args)), cast(*u8)(*(((buffers).canonical).items))) != 0))))) {
existing_storage := cast(*S12Array4096_u8)AllocateOrExit(size_of(S12Array4096_u8))
defer CompilerFree(cast(*void)existing_storage)
if instance != null && type_application_identity(module, cast(*u8)(*((instance).template_args)), cast(*u8)(*((existing_storage[0]).items)), cast(usize)(cast(u64)size_of(S12Array4096_u8))) == 0 {
(existing_storage[0]).items[0] = 0
}
if ((instance != cast(*IR.ZirType)((null))) && (!((instance).is_synthetic_application != 0) || (((instance).is_type_instance != 0) && ((FindType(module, cast(*u8)(*((instance).template_name)), null) != generic) || (strcmp(cast(*u8)(*((existing_storage[0]).items)), cast(*u8)(*((identity_storage[0]).items))) != 0))))) {
Diagnostic(span, CheckCString("check.type_application"), CheckCString("type application name collision: %s"), cast(*u8)(*((base_storage_0[0]).items)))
return 0
}
+11 -2
View File
@@ -35,6 +35,7 @@ TypeNextField :: (record: *IR.ZirType, offset: *usize, field: *IR.ZirTypeField)
VecElementType :: (module: *IR.ZirModule, type: *u8, element: *u8, element_size: usize) -> s32 #foreign compiler "VecElementType";
ZirIntegerLiteral :: (text: *u8, value: *u64) -> s32 #foreign compiler "ZirIntegerLiteral";
canonical_type_arguments :: (source: *u8, output: *u8, capacity: usize) -> s32 #foreign compiler "private_check_canonical_type_arguments";
type_application_identity :: (module: *IR.ZirModule, canonical: *u8, output: *u8, capacity: usize) -> s32 #foreign compiler "private_check_type_application_identity";
contains_vec :: (module: *IR.ZirModule, type: *u8, depth: s32) -> s32 #foreign compiler "private_check_contains_vec";
copy_text :: (dst: *u8, dst_size: usize, src: *u8) #foreign compiler "copy_text";
error :: (c: *Checker, span: IR.ZirSourceSpan, message: *u8, detail: *u8) #foreign compiler "private_check_error";
@@ -1451,7 +1452,9 @@ same_declared_type :: (module: *IR.ZirModule, to: *u8, from: *u8, depth: s32) ->
if (SameMapType((ifx (target_owner != null) then target_owner else module), target, (ifx (source_owner != null) then source_owner else module), source) != 0) {
return 1
}
if (((target != cast(*IR.ZirType)((null))) && (source != cast(*IR.ZirType)((null)))) && (same_type_application((ifx (target_owner != null) then target_owner else module), target, (ifx (source_owner != null) then source_owner else module), source) != 0)) {
// One application under one name is one native type; type_application_identity
// gives Vec(Db.Match) and Db's Vec(Match) that name.
if (((target != cast(*IR.ZirType)((null))) && (source != cast(*IR.ZirType)((null)))) && (strcmp(cast(*u8)(*((target).name)), cast(*u8)(*((source).name))) == 0) && (same_type_application((ifx (target_owner != null) then target_owner else module), target, (ifx (source_owner != null) then source_owner else module), source) != 0)) {
return 1
}
to_element_storage_0 := cast(*CheckArray128_u8)AllocateOrExit(size_of(CheckArray128_u8))
@@ -1813,8 +1816,14 @@ vec_option_result_type :: (c: *Checker, element: *u8, span: IR.ZirSourceSpan, ou
}
}
hash = (((hash ^ cast(u64)(40))) * 1099511628211)
identity_storage := cast(*CheckArray4096_u8)AllocateOrExit(size_of(CheckArray4096_u8))
defer CompilerFree(cast(*void)identity_storage)
if !(type_application_identity((c).module, cast(*u8)(*((canonical_storage_0[0]).items)), cast(*u8)(*((identity_storage[0]).items)), cast(usize)(cast(u64)size_of(CheckArray4096_u8))) != 0) {
error(c, span, CheckCString("Vec result element type is too long"), element)
return 0
}
{
p: *u8 = cast(*u8)(cast(*u8)(*((canonical_storage_0[0]).items)))
p: *u8 = cast(*u8)(cast(*u8)(*((identity_storage[0]).items)))
while check_loop_104 := ((p)[0] != 0) {
hash = (((hash ^ cast(u64)((p)[0]))) * 1099511628211)
CheckPost6(*(p))
+32 -12
View File
@@ -2868,11 +2868,41 @@ GeneratedOutputPrune :: (out_dir: *u8, marker: *u8) -> s32 {
#scope_file
// Two argument texts of a type application name one type: the same scalar,
// declared type or application under the same pointer, slice and array
// shapes. Each text resolves in its own module, so Db.Match in one module
// and Match in Db are one argument.
same_type_argument :: (target_owner: *IR.ZirModule, target: *u8, source_owner: *IR.ZirModule, source: *u8, depth: s32) -> s32 {
while isspace(cast(s32)target[0]) != 0 { target = cast(*u8)(cast(usize)target + 1) }
while isspace(cast(s32)source[0]) != 0 { source = cast(*u8)(cast(usize)source + 1) }
if target[0] == #char "*" || source[0] == #char "*" {
if target[0] != source[0] { return 0 }
return same_type_argument(target_owner, cast(*u8)(cast(usize)target + 1), source_owner, cast(*u8)(cast(usize)source + 1), depth)
}
if target[0] == #char "[" || source[0] == #char "[" {
target_close := strchr(target, #char "]")
source_close := strchr(source, #char "]")
if target_close == null || source_close == null { return 0 }
length := cast(usize)target_close - cast(usize)target
if length != cast(usize)source_close - cast(usize)source || strncmp(target, source, length) != 0 { return 0 }
return same_type_argument(target_owner, cast(*u8)(cast(usize)target_close + 1), source_owner, cast(*u8)(cast(usize)source_close + 1), depth)
}
target_scalar := ScalarType(target)
source_scalar := ScalarType(source)
if target_scalar[0] != 0 || source_scalar[0] != 0 { return cast(s32)(strcmp(target_scalar, source_scalar) == 0) }
a_owner: *IR.ZirModule = null
b_owner: *IR.ZirModule = null
a := FindType(target_owner, target, *a_owner)
b := FindType(source_owner, source, *b_owner)
if a == null || b == null { return 0 }
return cast(s32)(a == b || same_type_application_at_depth(a_owner, a, b_owner, b, depth + 1) != 0)
}
same_type_application_at_depth :: (target_owner: *IR.ZirModule, target: *IR.ZirType, source_owner: *IR.ZirModule, source: *IR.ZirType, depth: s32) -> s32 {
if (depth > 16) {
return 0
}
if (((((((target != cast(*IR.ZirType)((null))) && (source != cast(*IR.ZirType)((null)))) && (target_owner != cast(*IR.ZirModule)((null)))) && (source_owner != cast(*IR.ZirModule)((null)))) && ((target).is_synthetic_application != 0)) && ((source).is_synthetic_application != 0)) && (strcmp(cast(*u8)(*((target).body)), cast(*u8)(*((source).body))) == 0)) {
if ((((((target != cast(*IR.ZirType)((null))) && (source != cast(*IR.ZirType)((null)))) && (target_owner != cast(*IR.ZirModule)((null)))) && (source_owner != cast(*IR.ZirModule)((null)))) && ((target).is_synthetic_application != 0)) && ((source).is_synthetic_application != 0)) {
target_template: *IR.ZirType = FindType(target_owner, cast(*u8)(*((target).template_name)), null)
source_template: *IR.ZirType = FindType(source_owner, cast(*u8)(*((source).template_name)), null)
if ((target_template != cast(*IR.ZirType)((null))) && (target_template == source_template)) {
@@ -2884,17 +2914,7 @@ same_type_application_at_depth :: (target_owner: *IR.ZirModule, target: *IR.ZirT
{
i: s32 = 0
while check_loop_68 := ((i < target_count) && (same != 0)) {
target_scalar: *u8 = ScalarType(cast(*u8)(*((target_args).items[i]).items[0]))
source_scalar: *u8 = ScalarType(cast(*u8)(*((source_args).items[i]).items[0]))
if (((target_scalar)[0] != 0) || ((source_scalar)[0] != 0)) {
same = cast(s32)(strcmp(target_scalar, source_scalar) == 0)
} else {
a_owner: *IR.ZirModule = null
b_owner: *IR.ZirModule = null
a: *IR.ZirType = FindType(target_owner, cast(*u8)(*((target_args).items[i]).items[0]), *(a_owner))
b: *IR.ZirType = FindType(source_owner, cast(*u8)(*((source_args).items[i]).items[0]), *(b_owner))
same = cast(s32)(((a != cast(*IR.ZirType)((null))) && (b != cast(*IR.ZirType)((null)))) && ((a == b) || (same_type_application_at_depth(a_owner, a, b_owner, b, (depth + 1)) != 0)))
}
same = same_type_argument(target_owner, cast(*u8)(*((target_args).items[i]).items[0]), source_owner, cast(*u8)(*((source_args).items[i]).items[0]), depth)
ParserPost2(*(i))
}
}
+11 -4
View File
@@ -149,9 +149,11 @@ ToolSourceExcerpts :: (test: *NativeTest) -> bool {
}
// A program that passes ziran check also builds as strict ISO C and runs:
// empty literals, named constant array lengths, and fields or locals named
// like C keywords or predefined macros.
BuildCase :: struct { name: string; source: string; code: s32; }
// empty literals, named constant array lengths, fields or locals named like
// C keywords, predefined macros or the runtime's own names, and Vecs of
// another module's records passed to that module. A case with a module
// writes it as NAME_db.zi.
BuildCase :: struct { name: string; source: string; code: s32; module: string; }
ToolCheckBuildAgree :: (test: *NativeTest) -> bool {
cases := BuildCase.[
@@ -160,12 +162,17 @@ ToolCheckBuildAgree :: (test: *NativeTest) -> bool {
.{"for_call", "#import \"std/text_tools\"\nmain :: () -> s32 {\n total: s64 = 0\n for line: TextLines(\"ab\\ncde\") { total += line.count }\n for < TextSplit(\"x,yz\", \",\") { total += it.count + it_index }\n return cast(s32)total\n}\n", 9},
.{"cast_constant", "LIMIT :: cast(s64)9223372036854775807;\nSMALL :: cast(u8)200;\nmain :: () -> s32 {\n big: s64 = LIMIT\n small: u8 = SMALL\n return ifx big > 0 then cast(s32)small - 190 else 1\n}\n", 10},
.{"owned_view", "Name :: () -> Text { return TextCopy(\"ada\") }\nmain :: () -> s32 {\n name := Name()\n view := TextView(name)\n return cast(s32)view.count\n}\n", 3},
.{"colon_text", "Pair :: struct { name: string; text: string; }\npairs: [2]Pair = .[\n .{name = \"a\", text = \"NAME :: value;\"},\n .{name = \"bc\", text = \"x\"},\n];\nmain :: () -> s32 { return cast(s32)(pairs[0].text.count + pairs[1].name.count) }\n", 16},
.{"colon_text", "Pair :: struct { name: string; text: string; }\npairs: [2]Pair = Pair.[\n .{name = \"a\", text = \"NAME :: value;\"},\n .{name = \"bc\", text = \"x ::1 y\"},\n];\nmain :: () -> s32 { return cast(s32)(pairs[0].text.count + pairs[1].name.count) }\n", 16},
.{"c_names", "Flags :: struct { bool: s32; signed: s32; unsigned: s32; true: s32; }\nmain :: () -> s32 {\n f: Flags\n f.bool = 1\n f.unsigned = 2\n linux := 3\n unix := 4\n return f.bool + f.signed + f.unsigned + cast(s32)(linux + unix)\n}\n", 10},
.{"runtime_names", "String :: 2;\nlength :: 3;\nSlice :: struct { a: s64; }\nPair :: struct { length: s64; }\nmain :: () -> s32 {\n text := \"ab\"\n pair: Pair\n pair.length = length\n view: Slice\n view.a = String\n values: [2]s64\n part := values[:]\n return cast(s32)(text.count + pair.length + view.a + part.count)\n}\n", 9},
.{name = "module_vec", code = 10,
source = "using Vectors :: #import \"std/vec\"\nusing Db :: #import \"module_vec_db\"\nScale :: (width: s64) -> s64 { return width * 2 }\nmain :: () -> s32 {\n matches: Vec(Db.Match)\n Db.Find(*matches, 1)\n frag: Db.Frag = .{line = 3}\n frags: Vec(*Db.Frag)\n Db.Keep(*frags, *frag)\n total := matches[0].line + frags[0].line + Scale(1)\n VecFree(matches)\n VecFree(frags)\n return cast(s32)total\n}\n",
module = "using Vectors :: #import \"std/vec\"\n#scope_file\nwidth :: 5;\n#scope_export\nMatch :: struct { name: string; line: s64; }\nFrag :: struct { line: s64; }\nFind :: (matches: *Vec(Match), line: s64) { VecPush(<<matches, .{name = \"m\", line = line * width}) }\nKeep :: (frags: *Vec(*Frag), frag: *Frag) { VecPush(<<frags, frag) }\n"},
]
for build: cases {
source := CheckPath(test.work, CheckConcat(build.name, ".zi"))
output := CheckPath(test.work, CheckConcat(build.name, "-c"))
if build.module.count != 0 && !NativeWrite(test, CheckPath(test.work, CheckConcat(build.name, "_db.zi")), build.module) { return false }
if !NativeWrite(test, source, build.source) { return false }
check := string.[test.ziran, "check", "--root", test.work, source]
unused NativeRun(test, check[:])