| author | |
| committer | |
| log | 5f7d9c58458b8c6a675f747f811c54ab4e4f60c2 |
| tree | 94f2705efb79ed9d5670acb48b66bc97d7886bc6 |
| parent | a7ddcabb5034f4fef90d266263611f6cfbe04f41 |
| signature | Commit is signed but in an unrecognized format. |
7 files changed, 77 insertions(+), 42 deletions(-)
src/all_types.hpp+6| ... | @@ -1262,6 +1262,10 @@ enum OnePossibleValue { | ... | @@ -1262,6 +1262,10 @@ enum OnePossibleValue { |
| 1262 | OnePossibleValueYes, | 1262 | OnePossibleValueYes, |
| 1263 | }; | 1263 | }; |
| 1264 | 1264 | ||
| 1265 | struct ZigTypeOpaque { | ||
| 1266 | Buf *bare_name; | ||
| 1267 | }; | ||
| 1268 | |||
| 1265 | struct ZigType { | 1269 | struct ZigType { |
| 1266 | ZigTypeId id; | 1270 | ZigTypeId id; |
| 1267 | Buf name; | 1271 | Buf name; |
| ... | @@ -1284,6 +1288,7 @@ struct ZigType { | ... | @@ -1284,6 +1288,7 @@ struct ZigType { |
| 1284 | ZigTypeBoundFn bound_fn; | 1288 | ZigTypeBoundFn bound_fn; |
| 1285 | ZigTypePromise promise; | 1289 | ZigTypePromise promise; |
| 1286 | ZigTypeVector vector; | 1290 | ZigTypeVector vector; |
| 1291 | ZigTypeOpaque opaque; | ||
| 1287 | } data; | 1292 | } data; |
| 1288 | 1293 | ||
| 1289 | // use these fields to make sure we don't duplicate type table entries for the same type | 1294 | // use these fields to make sure we don't duplicate type table entries for the same type |
| ... | @@ -1941,6 +1946,7 @@ struct ScopeDecls { | ... | @@ -1941,6 +1946,7 @@ struct ScopeDecls { |
| 1941 | ZigType *import; | 1946 | ZigType *import; |
| 1942 | // If this is a scope from a container, this is the type entry, otherwise null | 1947 | // If this is a scope from a container, this is the type entry, otherwise null |
| 1943 | ZigType *container_type; | 1948 | ZigType *container_type; |
| 1949 | Buf *bare_name; | ||
| 1944 | 1950 | ||
| 1945 | bool safety_off; | 1951 | bool safety_off; |
| 1946 | bool fast_math_on; | 1952 | bool fast_math_on; |
src/analyze.cpp+28-17| ... | @@ -120,13 +120,16 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope | ... | @@ -120,13 +120,16 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope |
| 120 | dest->parent = parent; | 120 | dest->parent = parent; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import) { | 123 | static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, |
| 124 | ZigType *import, Buf *bare_name) | ||
| 125 | { | ||
| 124 | assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr); | 126 | assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr); |
| 125 | ScopeDecls *scope = allocate<ScopeDecls>(1); | 127 | ScopeDecls *scope = allocate<ScopeDecls>(1); |
| 126 | init_scope(g, &scope->base, ScopeIdDecls, node, parent); | 128 | init_scope(g, &scope->base, ScopeIdDecls, node, parent); |
| 127 | scope->decl_table.init(4); | 129 | scope->decl_table.init(4); |
| 128 | scope->container_type = container_type; | 130 | scope->container_type = container_type; |
| 129 | scope->import = import; | 131 | scope->import = import; |
| 132 | scope->bare_name = bare_name; | ||
| 130 | return scope; | 133 | return scope; |
| 131 | } | 134 | } |
| 132 | 135 | ||
| ... | @@ -225,9 +228,12 @@ ZigType *get_scope_import(Scope *scope) { | ... | @@ -225,9 +228,12 @@ ZigType *get_scope_import(Scope *scope) { |
| 225 | zig_unreachable(); | 228 | zig_unreachable(); |
| 226 | } | 229 | } |
| 227 | 230 | ||
| 228 | static ZigType *new_container_type_entry(CodeGen *g, ZigTypeId id, AstNode *source_node, Scope *parent_scope) { | 231 | static ZigType *new_container_type_entry(CodeGen *g, ZigTypeId id, AstNode *source_node, Scope *parent_scope, |
| 232 | Buf *bare_name) | ||
| 233 | { | ||
| 229 | ZigType *entry = new_type_table_entry(id); | 234 | ZigType *entry = new_type_table_entry(id); |
| 230 | *get_container_scope_ptr(entry) = create_decls_scope(g, source_node, parent_scope, entry, get_scope_import(parent_scope)); | 235 | *get_container_scope_ptr(entry) = create_decls_scope(g, source_node, parent_scope, entry, |
| 236 | get_scope_import(parent_scope), bare_name); | ||
| 231 | return entry; | 237 | return entry; |
| 232 | } | 238 | } |
| 233 | 239 | ||
| ... | @@ -1009,21 +1015,22 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { | ... | @@ -1009,21 +1015,22 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { |
| 1009 | return entry; | 1015 | return entry; |
| 1010 | } | 1016 | } |
| 1011 | 1017 | ||
| 1012 | ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) { | 1018 | ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name) { |
| 1013 | ZigType *entry = new_type_table_entry(ZigTypeIdOpaque); | 1019 | ZigType *entry = new_type_table_entry(ZigTypeIdOpaque); |
| 1014 | 1020 | ||
| 1015 | buf_init_from_str(&entry->name, name); | 1021 | buf_init_from_str(&entry->name, full_name); |
| 1016 | 1022 | ||
| 1017 | ZigType *import = scope ? get_scope_import(scope) : nullptr; | 1023 | ZigType *import = scope ? get_scope_import(scope) : nullptr; |
| 1018 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; | 1024 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; |
| 1019 | 1025 | ||
| 1020 | entry->type_ref = LLVMInt8Type(); | 1026 | entry->type_ref = LLVMInt8Type(); |
| 1021 | entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, | 1027 | entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, |
| 1022 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), | 1028 | ZigLLVMTag_DW_structure_type(), full_name, |
| 1023 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, | 1029 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, |
| 1024 | import ? import->data.structure.root_struct->di_file : nullptr, | 1030 | import ? import->data.structure.root_struct->di_file : nullptr, |
| 1025 | line); | 1031 | line); |
| 1026 | entry->zero_bits = false; | 1032 | entry->zero_bits = false; |
| 1033 | entry->data.opaque.bare_name = bare_name; | ||
| 1027 | 1034 | ||
| 1028 | return entry; | 1035 | return entry; |
| 1029 | } | 1036 | } |
| ... | @@ -1293,29 +1300,31 @@ static ZigTypeId container_to_type(ContainerKind kind) { | ... | @@ -1293,29 +1300,31 @@ static ZigTypeId container_to_type(ContainerKind kind) { |
| 1293 | } | 1300 | } |
| 1294 | 1301 | ||
| 1295 | // This is like get_partial_container_type except it's for the implicit root struct of files. | 1302 | // This is like get_partial_container_type except it's for the implicit root struct of files. |
| 1296 | ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct) { | 1303 | ZigType *get_root_container_type(CodeGen *g, const char *full_name, Buf *bare_name, |
| 1304 | RootStruct *root_struct) | ||
| 1305 | { | ||
| 1297 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); | 1306 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); |
| 1298 | entry->data.structure.decls_scope = create_decls_scope(g, nullptr, nullptr, entry, entry); | 1307 | entry->data.structure.decls_scope = create_decls_scope(g, nullptr, nullptr, entry, entry, bare_name); |
| 1299 | entry->data.structure.root_struct = root_struct; | 1308 | entry->data.structure.root_struct = root_struct; |
| 1300 | entry->data.structure.layout = ContainerLayoutAuto; | 1309 | entry->data.structure.layout = ContainerLayoutAuto; |
| 1301 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name); | 1310 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), full_name); |
| 1302 | 1311 | ||
| 1303 | size_t line = 0; // root therefore first line | 1312 | size_t line = 0; // root therefore first line |
| 1304 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); | 1313 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); |
| 1305 | 1314 | ||
| 1306 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, | 1315 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, |
| 1307 | dwarf_kind, name, | 1316 | dwarf_kind, full_name, |
| 1308 | ZigLLVMFileToScope(root_struct->di_file), root_struct->di_file, (unsigned)(line + 1)); | 1317 | ZigLLVMFileToScope(root_struct->di_file), root_struct->di_file, (unsigned)(line + 1)); |
| 1309 | 1318 | ||
| 1310 | buf_init_from_str(&entry->name, name); | 1319 | buf_init_from_str(&entry->name, full_name); |
| 1311 | return entry; | 1320 | return entry; |
| 1312 | } | 1321 | } |
| 1313 | 1322 | ||
| 1314 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, | 1323 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, |
| 1315 | AstNode *decl_node, const char *name, ContainerLayout layout) | 1324 | AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout) |
| 1316 | { | 1325 | { |
| 1317 | ZigTypeId type_id = container_to_type(kind); | 1326 | ZigTypeId type_id = container_to_type(kind); |
| 1318 | ZigType *entry = new_container_type_entry(g, type_id, decl_node, scope); | 1327 | ZigType *entry = new_container_type_entry(g, type_id, decl_node, scope, bare_name); |
| 1319 | 1328 | ||
| 1320 | switch (kind) { | 1329 | switch (kind) { |
| 1321 | case ContainerKindStruct: | 1330 | case ContainerKindStruct: |
| ... | @@ -1336,13 +1345,13 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind | ... | @@ -1336,13 +1345,13 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind |
| 1336 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); | 1345 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); |
| 1337 | 1346 | ||
| 1338 | ZigType *import = get_scope_import(scope); | 1347 | ZigType *import = get_scope_import(scope); |
| 1339 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name); | 1348 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), full_name); |
| 1340 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, | 1349 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, |
| 1341 | dwarf_kind, name, | 1350 | dwarf_kind, full_name, |
| 1342 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | 1351 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), |
| 1343 | import->data.structure.root_struct->di_file, (unsigned)(line + 1)); | 1352 | import->data.structure.root_struct->di_file, (unsigned)(line + 1)); |
| 1344 | 1353 | ||
| 1345 | buf_init_from_str(&entry->name, name); | 1354 | buf_init_from_str(&entry->name, full_name); |
| 1346 | 1355 | ||
| 1347 | return entry; | 1356 | return entry; |
| 1348 | } | 1357 | } |
| ... | @@ -4501,6 +4510,8 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu | ... | @@ -4501,6 +4510,8 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu |
| 4501 | buf_len(&noextname) - (buf_len(&resolved_root_src_dir) + 1)); | 4510 | buf_len(&noextname) - (buf_len(&resolved_root_src_dir) + 1)); |
| 4502 | buf_replace(&namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR); | 4511 | buf_replace(&namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR); |
| 4503 | } | 4512 | } |
| 4513 | Buf *bare_name = buf_alloc(); | ||
| 4514 | os_path_extname(src_basename, bare_name, nullptr); | ||
| 4504 | 4515 | ||
| 4505 | RootStruct *root_struct = allocate<RootStruct>(1); | 4516 | RootStruct *root_struct = allocate<RootStruct>(1); |
| 4506 | root_struct->package = package; | 4517 | root_struct->package = package; |
| ... | @@ -4508,7 +4519,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu | ... | @@ -4508,7 +4519,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu |
| 4508 | root_struct->line_offsets = tokenization.line_offsets; | 4519 | root_struct->line_offsets = tokenization.line_offsets; |
| 4509 | root_struct->path = resolved_path; | 4520 | root_struct->path = resolved_path; |
| 4510 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | 4521 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); |
| 4511 | ZigType *import_entry = get_root_container_type(g, buf_ptr(&namespace_name), root_struct); | 4522 | ZigType *import_entry = get_root_container_type(g, buf_ptr(&namespace_name), bare_name, root_struct); |
| 4512 | if (source_kind == SourceKindRoot) { | 4523 | if (source_kind == SourceKindRoot) { |
| 4513 | assert(g->root_import == nullptr); | 4524 | assert(g->root_import == nullptr); |
| 4514 | g->root_import = import_entry; | 4525 | g->root_import = import_entry; |
src/analyze.hpp+4-4| ... | @@ -30,12 +30,13 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type); | ... | @@ -30,12 +30,13 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type); |
| 30 | ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size); | 30 | ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size); |
| 31 | ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); | 31 | ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); |
| 32 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, | 32 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, |
| 33 | AstNode *decl_node, const char *name, ContainerLayout layout); | 33 | AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout); |
| 34 | ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct); | 34 | ZigType *get_root_container_type(CodeGen *g, const char *full_name, Buf *bare_name, |
| 35 | RootStruct *root_struct); | ||
| 35 | ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); | 36 | ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); |
| 36 | ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type); | 37 | ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type); |
| 37 | ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry); | 38 | ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry); |
| 38 | ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name); | 39 | ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name); |
| 39 | ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], | 40 | ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], |
| 40 | ZigType *field_types[], size_t field_count); | 41 | ZigType *field_types[], size_t field_count); |
| 41 | ZigType *get_promise_type(CodeGen *g, ZigType *result_type); | 42 | ZigType *get_promise_type(CodeGen *g, ZigType *result_type); |
| ... | @@ -117,7 +118,6 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent); | ... | @@ -117,7 +118,6 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 117 | ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent); | 118 | ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 118 | ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent); | 119 | ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 119 | ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry); | 120 | ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry); |
| 120 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import); | ||
| 121 | Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent); | 121 | Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 122 | Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent); | 122 | Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 123 | Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime); | 123 | Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime); |
src/codegen.cpp+7-7| ... | @@ -7123,7 +7123,8 @@ static void define_builtin_types(CodeGen *g) { | ... | @@ -7123,7 +7123,8 @@ static void define_builtin_types(CodeGen *g) { |
| 7123 | g->builtin_types.entry_i64 = get_int_type(g, true, 64); | 7123 | g->builtin_types.entry_i64 = get_int_type(g, true, 64); |
| 7124 | 7124 | ||
| 7125 | { | 7125 | { |
| 7126 | g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void"); | 7126 | g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void", |
| 7127 | buf_create_from_str("c_void")); | ||
| 7127 | g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void); | 7128 | g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void); |
| 7128 | } | 7129 | } |
| 7129 | 7130 | ||
| ... | @@ -7943,19 +7944,18 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { | ... | @@ -7943,19 +7944,18 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 7943 | Buf noextname = BUF_INIT; | 7944 | Buf noextname = BUF_INIT; |
| 7944 | os_path_extname(src_basename, &noextname, nullptr); | 7945 | os_path_extname(src_basename, &noextname, nullptr); |
| 7945 | 7946 | ||
| 7947 | detect_libc(g); | ||
| 7948 | |||
| 7949 | init(g); | ||
| 7950 | |||
| 7946 | RootStruct *root_struct = allocate<RootStruct>(1); | 7951 | RootStruct *root_struct = allocate<RootStruct>(1); |
| 7947 | root_struct->source_code = nullptr; | 7952 | root_struct->source_code = nullptr; |
| 7948 | root_struct->path = full_path; | 7953 | root_struct->path = full_path; |
| 7949 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | 7954 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); |
| 7950 | 7955 | ||
| 7951 | ZigType *import = get_root_container_type(g, buf_ptr(&noextname), root_struct); | 7956 | ZigType *import = get_root_container_type(g, buf_ptr(&noextname), &noextname, root_struct); |
| 7952 | g->root_import = import; | 7957 | g->root_import = import; |
| 7953 | 7958 | ||
| 7954 | detect_libc(g); | ||
| 7955 | |||
| 7956 | init(g); | ||
| 7957 | |||
| 7958 | |||
| 7959 | ZigList<ErrorMsg *> errors = {0}; | 7959 | ZigList<ErrorMsg *> errors = {0}; |
| 7960 | Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr); | 7960 | Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr); |
| 7961 | 7961 |
src/ir.cpp+25-10| ... | @@ -6609,13 +6609,14 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o | ... | @@ -6609,13 +6609,14 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o |
| 6609 | } | 6609 | } |
| 6610 | 6610 | ||
| 6611 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, | 6611 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 6612 | Scope *scope, AstNode *source_node) | 6612 | Scope *scope, AstNode *source_node, Buf *out_bare_name) |
| 6613 | { | 6613 | { |
| 6614 | if (exec->name) { | 6614 | if (exec->name) { |
| 6615 | ZigType *import = get_scope_import(scope); | 6615 | ZigType *import = get_scope_import(scope); |
| 6616 | Buf *namespace_name = buf_create_from_buf(&import->name); | 6616 | Buf *namespace_name = buf_create_from_buf(&import->name); |
| 6617 | if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR); | 6617 | if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR); |
| 6618 | buf_append_buf(namespace_name, exec->name); | 6618 | buf_append_buf(namespace_name, exec->name); |
| 6619 | buf_init_from_buf(out_bare_name, exec->name); | ||
| 6619 | return namespace_name; | 6620 | return namespace_name; |
| 6620 | } else if (exec->name_fn != nullptr) { | 6621 | } else if (exec->name_fn != nullptr) { |
| 6621 | Buf *name = buf_alloc(); | 6622 | Buf *name = buf_alloc(); |
| ... | @@ -6623,6 +6624,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char | ... | @@ -6623,6 +6624,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 6623 | buf_appendf(name, "("); | 6624 | buf_appendf(name, "("); |
| 6624 | render_instance_name_recursive(codegen, name, &exec->name_fn->fndef_scope->base, exec->begin_scope); | 6625 | render_instance_name_recursive(codegen, name, &exec->name_fn->fndef_scope->base, exec->begin_scope); |
| 6625 | buf_appendf(name, ")"); | 6626 | buf_appendf(name, ")"); |
| 6627 | buf_init_from_buf(out_bare_name, name); | ||
| 6626 | return name; | 6628 | return name; |
| 6627 | } else { | 6629 | } else { |
| 6628 | ZigType *import = get_scope_import(scope); | 6630 | ZigType *import = get_scope_import(scope); |
| ... | @@ -6630,6 +6632,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char | ... | @@ -6630,6 +6632,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 6630 | if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR); | 6632 | if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR); |
| 6631 | buf_appendf(namespace_name, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, kind_name, | 6633 | buf_appendf(namespace_name, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, kind_name, |
| 6632 | source_node->line + 1, source_node->column + 1); | 6634 | source_node->line + 1, source_node->column + 1); |
| 6635 | buf_init_from_buf(out_bare_name, namespace_name); | ||
| 6633 | return namespace_name; | 6636 | return namespace_name; |
| 6634 | } | 6637 | } |
| 6635 | } | 6638 | } |
| ... | @@ -6655,11 +6658,12 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, | ... | @@ -6655,11 +6658,12 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, |
| 6655 | assert(node->type == NodeTypeContainerDecl); | 6658 | assert(node->type == NodeTypeContainerDecl); |
| 6656 | 6659 | ||
| 6657 | ContainerKind kind = node->data.container_decl.kind; | 6660 | ContainerKind kind = node->data.container_decl.kind; |
| 6658 | Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), parent_scope, node); | 6661 | Buf *bare_name = buf_alloc(); |
| 6662 | Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), parent_scope, node, bare_name); | ||
| 6659 | 6663 | ||
| 6660 | ContainerLayout layout = node->data.container_decl.layout; | 6664 | ContainerLayout layout = node->data.container_decl.layout; |
| 6661 | ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope, | 6665 | ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope, |
| 6662 | kind, node, buf_ptr(name), layout); | 6666 | kind, node, buf_ptr(name), bare_name, layout); |
| 6663 | ScopeDecls *child_scope = get_container_scope(container_type); | 6667 | ScopeDecls *child_scope = get_container_scope(container_type); |
| 6664 | 6668 | ||
| 6665 | for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) { | 6669 | for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) { |
| ... | @@ -6668,7 +6672,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, | ... | @@ -6668,7 +6672,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, |
| 6668 | } | 6672 | } |
| 6669 | 6673 | ||
| 6670 | TldContainer *tld_container = allocate<TldContainer>(1); | 6674 | TldContainer *tld_container = allocate<TldContainer>(1); |
| 6671 | init_tld(&tld_container->base, TldIdContainer, name, VisibModPub, node, parent_scope); | 6675 | init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope); |
| 6672 | tld_container->type_entry = container_type; | 6676 | tld_container->type_entry = container_type; |
| 6673 | tld_container->decls_scope = child_scope; | 6677 | tld_container->decls_scope = child_scope; |
| 6674 | irb->codegen->resolve_queue.append(&tld_container->base); | 6678 | irb->codegen->resolve_queue.append(&tld_container->base); |
| ... | @@ -6755,7 +6759,8 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A | ... | @@ -6755,7 +6759,8 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 6755 | 6759 | ||
| 6756 | uint32_t err_count = node->data.err_set_decl.decls.length; | 6760 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| 6757 | 6761 | ||
| 6758 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", parent_scope, node); | 6762 | Buf bare_name = BUF_INIT; |
| 6763 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", parent_scope, node, &bare_name); | ||
| 6759 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); | 6764 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6760 | buf_init_from_buf(&err_set_type->name, type_name); | 6765 | buf_init_from_buf(&err_set_type->name, type_name); |
| 6761 | err_set_type->data.error_set.err_count = err_count; | 6766 | err_set_type->data.error_set.err_count = err_count; |
| ... | @@ -18680,7 +18685,15 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc | ... | @@ -18680,7 +18685,15 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc |
| 18680 | return ira->codegen->invalid_instruction; | 18685 | return ira->codegen->invalid_instruction; |
| 18681 | 18686 | ||
| 18682 | if (!type_entry->cached_const_name_val) { | 18687 | if (!type_entry->cached_const_name_val) { |
| 18683 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, &type_entry->name); | 18688 | Buf *name; |
| 18689 | if (is_container(type_entry)) { | ||
| 18690 | name = get_container_scope(type_entry)->bare_name; | ||
| 18691 | } else if (type_entry->id == ZigTypeIdOpaque) { | ||
| 18692 | name = type_entry->data.opaque.bare_name; | ||
| 18693 | } else { | ||
| 18694 | name = &type_entry->name; | ||
| 18695 | } | ||
| 18696 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, name); | ||
| 18684 | } | 18697 | } |
| 18685 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); | 18698 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 18686 | copy_const_val(&result->value, type_entry->cached_const_name_val, true); | 18699 | copy_const_val(&result->value, type_entry->cached_const_name_val, true); |
| ... | @@ -18715,7 +18728,8 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct | ... | @@ -18715,7 +18728,8 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 18715 | // for this DIFile | 18728 | // for this DIFile |
| 18716 | root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder, | 18729 | root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder, |
| 18717 | buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str("."))); | 18730 | buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str("."))); |
| 18718 | ZigType *child_import = get_root_container_type(ira->codegen, buf_ptr(namespace_name), root_struct); | 18731 | ZigType *child_import = get_root_container_type(ira->codegen, buf_ptr(namespace_name), |
| 18732 | namespace_name, root_struct); | ||
| 18719 | 18733 | ||
| 18720 | ZigList<ErrorMsg *> errors = {0}; | 18734 | ZigList<ErrorMsg *> errors = {0}; |
| 18721 | 18735 | ||
| ... | @@ -21668,10 +21682,11 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru | ... | @@ -21668,10 +21682,11 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 21668 | } | 21682 | } |
| 21669 | 21683 | ||
| 21670 | static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { | 21684 | static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 21671 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", | 21685 | Buf *bare_name = buf_alloc(); |
| 21672 | instruction->base.scope, instruction->base.source_node); | 21686 | Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", |
| 21687 | instruction->base.scope, instruction->base.source_node, bare_name); | ||
| 21673 | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, | 21688 | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 21674 | buf_ptr(name)); | 21689 | buf_ptr(full_name), bare_name); |
| 21675 | return ir_const_type(ira, &instruction->base, result_type); | 21690 | return ir_const_type(ira, &instruction->base, result_type); |
| 21676 | } | 21691 | } |
| 21677 | 21692 |
test/compile_errors.zig+4-4| ... | @@ -1231,10 +1231,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1231,10 +1231,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1231 | \\ | 1231 | \\ |
| 1232 | \\fn bar(x: *b.Foo) void {} | 1232 | \\fn bar(x: *b.Foo) void {} |
| 1233 | , | 1233 | , |
| 1234 | "tmp.zig:6:10: error: expected type '*Foo', found '*Foo'", | 1234 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 1235 | "tmp.zig:6:10: note: pointer type child 'Foo' cannot cast into pointer type child 'Foo'", | 1235 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 1236 | "a.zig:1:17: note: Foo declared here", | 1236 | "a.zig:1:17: note: a.Foo declared here", |
| 1237 | "b.zig:1:17: note: Foo declared here", | 1237 | "b.zig:1:17: note: b.Foo declared here", |
| 1238 | ); | 1238 | ); |
| 1239 | 1239 | ||
| 1240 | tc.addSourceFile("a.zig", | 1240 | tc.addSourceFile("a.zig", |
test/tests.zig+3| ... | @@ -980,15 +980,18 @@ pub const TranslateCContext = struct { | ... | @@ -980,15 +980,18 @@ pub const TranslateCContext = struct { |
| 980 | Term.Exited => |code| { | 980 | Term.Exited => |code| { |
| 981 | if (code != 0) { | 981 | if (code != 0) { |
| 982 | warn("Compilation failed with exit code {}\n", code); | 982 | warn("Compilation failed with exit code {}\n", code); |
| 983 | printInvocation(zig_args.toSliceConst()); | ||
| 983 | return error.TestFailed; | 984 | return error.TestFailed; |
| 984 | } | 985 | } |
| 985 | }, | 986 | }, |
| 986 | Term.Signal => |code| { | 987 | Term.Signal => |code| { |
| 987 | warn("Compilation failed with signal {}\n", code); | 988 | warn("Compilation failed with signal {}\n", code); |
| 989 | printInvocation(zig_args.toSliceConst()); | ||
| 988 | return error.TestFailed; | 990 | return error.TestFailed; |
| 989 | }, | 991 | }, |
| 990 | else => { | 992 | else => { |
| 991 | warn("Compilation terminated unexpectedly\n"); | 993 | warn("Compilation terminated unexpectedly\n"); |
| 994 | printInvocation(zig_args.toSliceConst()); | ||
| 992 | return error.TestFailed; | 995 | return error.TestFailed; |
| 993 | }, | 996 | }, |
| 994 | } | 997 | } |