| author | |
| committer | |
| log | 5424b4320def194b205dcfe8e937035d2d80ae09 |
| tree | 033c9534190356feefa34ac7649f729202beac89 |
| parent | d093f51f16ab9fe4f119a47c80c59d99a90a590f |
| signature |
closes #104718 files changed, 329 insertions(+), 411 deletions(-)
doc/langref.html.in+14-11| ... | ... | @@ -6785,7 +6785,6 @@ pub const TypeId = enum { |
| 6785 | 6785 | Enum, |
| 6786 | 6786 | Union, |
| 6787 | 6787 | Fn, |
| 6788 | Namespace, | |
| 6789 | 6788 | Block, |
| 6790 | 6789 | BoundFn, |
| 6791 | 6790 | ArgTuple, |
| ... | ... | @@ -6820,7 +6819,6 @@ pub const TypeInfo = union(TypeId) { |
| 6820 | 6819 | Enum: Enum, |
| 6821 | 6820 | Union: Union, |
| 6822 | 6821 | Fn: Fn, |
| 6823 | Namespace: void, | |
| 6824 | 6822 | BoundFn: Fn, |
| 6825 | 6823 | ArgTuple: void, |
| 6826 | 6824 | Opaque: void, |
| ... | ... | @@ -8167,17 +8165,18 @@ coding style. |
| 8167 | 8165 | </p> |
| 8168 | 8166 | <ul> |
| 8169 | 8167 | <li> |
| 8170 | If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} (or an alias of a {#syntax#}struct{#endsyntax#}), | |
| 8171 | then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}. | |
| 8168 | If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#} | |
| 8169 | then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}, unless it | |
| 8170 | is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated, | |
| 8171 | in which case it is considered to be a "namespace" and uses {#syntax#}snake_case{#end_syntax#}. | |
| 8172 | 8172 | </li> |
| 8173 | 8173 | <li> |
| 8174 | If {#syntax#}x{#endsyntax#} otherwise identifies a type, {#syntax#}x{#endsyntax#} should have {#syntax#}snake_case{#endsyntax#}. | |
| 8174 | If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is | |
| 8175 | {#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}. | |
| 8175 | 8176 | </li> |
| 8176 | 8177 | <li> |
| 8177 | If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is {#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}. | |
| 8178 | </li> | |
| 8179 | <li> | |
| 8180 | If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should be {#syntax#}camelCase{#endsyntax#}. | |
| 8178 | If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should | |
| 8179 | be {#syntax#}camelCase{#endsyntax#}. | |
| 8181 | 8180 | </li> |
| 8182 | 8181 | <li> |
| 8183 | 8182 | Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}. |
| ... | ... | @@ -8203,7 +8202,9 @@ const const_name = 42; |
| 8203 | 8202 | const primitive_type_alias = f32; |
| 8204 | 8203 | const string_alias = []u8; |
| 8205 | 8204 | |
| 8206 | const StructName = struct {}; | |
| 8205 | const StructName = struct { | |
| 8206 | field: i32, | |
| 8207 | }; | |
| 8207 | 8208 | const StructAlias = StructName; |
| 8208 | 8209 | |
| 8209 | 8210 | fn functionName(param_name: TypeName) void { |
| ... | ... | @@ -8231,7 +8232,9 @@ const xml_document = |
| 8231 | 8232 | \\<document> |
| 8232 | 8233 | \\</document> |
| 8233 | 8234 | ; |
| 8234 | const XmlParser = struct {}; | |
| 8235 | const XmlParser = struct { | |
| 8236 | field: i32, | |
| 8237 | }; | |
| 8235 | 8238 | |
| 8236 | 8239 | // The initials BE (Big Endian) are just another word in Zig identifier names. |
| 8237 | 8240 | fn readU32Be() u32 {} |
src-self-hosted/type.zig-12| ... | ... | @@ -39,7 +39,6 @@ pub const Type = struct { |
| 39 | 39 | Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp), |
| 40 | 40 | Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp), |
| 41 | 41 | Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp), |
| 42 | Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp), | |
| 43 | 42 | Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp), |
| 44 | 43 | Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp), |
| 45 | 44 | Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp), |
| ... | ... | @@ -73,7 +72,6 @@ pub const Type = struct { |
| 73 | 72 | Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context), |
| 74 | 73 | Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context), |
| 75 | 74 | Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context), |
| 76 | Id.Namespace => unreachable, | |
| 77 | 75 | Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context), |
| 78 | 76 | Id.ArgTuple => unreachable, |
| 79 | 77 | Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context), |
| ... | ... | @@ -89,7 +87,6 @@ pub const Type = struct { |
| 89 | 87 | Id.ComptimeInt, |
| 90 | 88 | Id.Undefined, |
| 91 | 89 | Id.Null, |
| 92 | Id.Namespace, | |
| 93 | 90 | Id.BoundFn, |
| 94 | 91 | Id.ArgTuple, |
| 95 | 92 | Id.Opaque, |
| ... | ... | @@ -123,7 +120,6 @@ pub const Type = struct { |
| 123 | 120 | Id.ComptimeInt, |
| 124 | 121 | Id.Undefined, |
| 125 | 122 | Id.Null, |
| 126 | Id.Namespace, | |
| 127 | 123 | Id.BoundFn, |
| 128 | 124 | Id.ArgTuple, |
| 129 | 125 | Id.Opaque, |
| ... | ... | @@ -1020,14 +1016,6 @@ pub const Type = struct { |
| 1020 | 1016 | } |
| 1021 | 1017 | }; |
| 1022 | 1018 | |
| 1023 | pub const Namespace = struct { | |
| 1024 | base: Type, | |
| 1025 | ||
| 1026 | pub fn destroy(self: *Namespace, comp: *Compilation) void { | |
| 1027 | comp.gpa().destroy(self); | |
| 1028 | } | |
| 1029 | }; | |
| 1030 | ||
| 1031 | 1019 | pub const BoundFn = struct { |
| 1032 | 1020 | base: Type, |
| 1033 | 1021 |
src/all_types.hpp+40-44| ... | ... | @@ -21,7 +21,6 @@ |
| 21 | 21 | #include "libc_installation.hpp" |
| 22 | 22 | |
| 23 | 23 | struct AstNode; |
| 24 | struct ImportTableEntry; | |
| 25 | 24 | struct ZigFn; |
| 26 | 25 | struct Scope; |
| 27 | 26 | struct ScopeBlock; |
| ... | ... | @@ -317,7 +316,6 @@ struct ConstExprValue { |
| 317 | 316 | ConstUnionValue x_union; |
| 318 | 317 | ConstArrayValue x_array; |
| 319 | 318 | ConstPtrValue x_ptr; |
| 320 | ImportTableEntry *x_import; | |
| 321 | 319 | ConstArgTuple x_arg_tuple; |
| 322 | 320 | |
| 323 | 321 | // populated if special == ConstValSpecialRuntime |
| ... | ... | @@ -369,7 +367,7 @@ struct Tld { |
| 369 | 367 | VisibMod visib_mod; |
| 370 | 368 | AstNode *source_node; |
| 371 | 369 | |
| 372 | ImportTableEntry *import; | |
| 370 | ZigType *import; | |
| 373 | 371 | Scope *parent_scope; |
| 374 | 372 | // set this flag temporarily to detect infinite loops |
| 375 | 373 | bool dep_loop_flag; |
| ... | ... | @@ -937,7 +935,7 @@ struct AstNode { |
| 937 | 935 | enum NodeType type; |
| 938 | 936 | size_t line; |
| 939 | 937 | size_t column; |
| 940 | ImportTableEntry *owner; | |
| 938 | ZigType *owner; | |
| 941 | 939 | union { |
| 942 | 940 | AstNodeFnDef fn_def; |
| 943 | 941 | AstNodeFnProto fn_proto; |
| ... | ... | @@ -1075,12 +1073,32 @@ enum ResolveStatus { |
| 1075 | 1073 | ResolveStatusSizeKnown, |
| 1076 | 1074 | }; |
| 1077 | 1075 | |
| 1076 | struct ZigPackage { | |
| 1077 | Buf root_src_dir; | |
| 1078 | Buf root_src_path; // relative to root_src_dir | |
| 1079 | ||
| 1080 | // reminder: hash tables must be initialized before use | |
| 1081 | HashMap<Buf *, ZigPackage *, buf_hash, buf_eql_buf> package_table; | |
| 1082 | }; | |
| 1083 | ||
| 1084 | // Stuff that only applies to a struct which is the implicit root struct of a file | |
| 1085 | struct RootStruct { | |
| 1086 | ZigPackage *package; | |
| 1087 | Buf *path; // relative to root_package->root_src_dir | |
| 1088 | ZigList<size_t> *line_offsets; | |
| 1089 | Buf *source_code; | |
| 1090 | AstNode *c_import_node; | |
| 1091 | ZigLLVMDIFile *di_file; | |
| 1092 | bool scanned; | |
| 1093 | }; | |
| 1094 | ||
| 1078 | 1095 | struct ZigTypeStruct { |
| 1079 | 1096 | AstNode *decl_node; |
| 1080 | 1097 | TypeStructField *fields; |
| 1081 | 1098 | ScopeDecls *decls_scope; |
| 1082 | 1099 | uint64_t size_bytes; |
| 1083 | 1100 | HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name; |
| 1101 | RootStruct *root_struct; | |
| 1084 | 1102 | |
| 1085 | 1103 | uint32_t src_field_count; |
| 1086 | 1104 | uint32_t gen_field_count; |
| ... | ... | @@ -1232,7 +1250,6 @@ enum ZigTypeId { |
| 1232 | 1250 | ZigTypeIdEnum, |
| 1233 | 1251 | ZigTypeIdUnion, |
| 1234 | 1252 | ZigTypeIdFn, |
| 1235 | ZigTypeIdNamespace, | |
| 1236 | 1253 | ZigTypeIdBoundFn, |
| 1237 | 1254 | ZigTypeIdArgTuple, |
| 1238 | 1255 | ZigTypeIdOpaque, |
| ... | ... | @@ -1285,29 +1302,6 @@ struct ZigType { |
| 1285 | 1302 | bool gen_h_loop_flag; |
| 1286 | 1303 | }; |
| 1287 | 1304 | |
| 1288 | struct PackageTableEntry { | |
| 1289 | Buf root_src_dir; | |
| 1290 | Buf root_src_path; // relative to root_src_dir | |
| 1291 | ||
| 1292 | // reminder: hash tables must be initialized before use | |
| 1293 | HashMap<Buf *, PackageTableEntry *, buf_hash, buf_eql_buf> package_table; | |
| 1294 | }; | |
| 1295 | ||
| 1296 | struct ImportTableEntry { | |
| 1297 | AstNode *root; | |
| 1298 | Buf *path; // relative to root_package->root_src_dir | |
| 1299 | PackageTableEntry *package; | |
| 1300 | ZigLLVMDIFile *di_file; | |
| 1301 | Buf *source_code; | |
| 1302 | ZigList<size_t> *line_offsets; | |
| 1303 | ScopeDecls *decls_scope; | |
| 1304 | AstNode *c_import_node; | |
| 1305 | bool any_imports_failed; | |
| 1306 | bool scanned; | |
| 1307 | ||
| 1308 | ZigList<AstNode *> use_decls; | |
| 1309 | }; | |
| 1310 | ||
| 1311 | 1305 | enum FnAnalState { |
| 1312 | 1306 | FnAnalStateReady, |
| 1313 | 1307 | FnAnalStateProbing, |
| ... | ... | @@ -1670,7 +1664,7 @@ struct CodeGen { |
| 1670 | 1664 | LLVMValueRef return_err_fn; |
| 1671 | 1665 | |
| 1672 | 1666 | // reminder: hash tables must be initialized before use |
| 1673 | HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table; | |
| 1667 | HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> import_table; | |
| 1674 | 1668 | HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table; |
| 1675 | 1669 | HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table; |
| 1676 | 1670 | HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table; |
| ... | ... | @@ -1684,7 +1678,7 @@ struct CodeGen { |
| 1684 | 1678 | HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table; |
| 1685 | 1679 | HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache; |
| 1686 | 1680 | |
| 1687 | ZigList<ImportTableEntry *> import_queue; | |
| 1681 | ZigList<ZigType *> import_queue; | |
| 1688 | 1682 | size_t import_queue_index; |
| 1689 | 1683 | ZigList<Tld *> resolve_queue; |
| 1690 | 1684 | size_t resolve_queue_index; |
| ... | ... | @@ -1699,14 +1693,14 @@ struct CodeGen { |
| 1699 | 1693 | ZigList<ErrorTableEntry *> errors_by_index; |
| 1700 | 1694 | size_t largest_err_name_len; |
| 1701 | 1695 | |
| 1702 | PackageTableEntry *std_package; | |
| 1703 | PackageTableEntry *panic_package; | |
| 1704 | PackageTableEntry *test_runner_package; | |
| 1705 | PackageTableEntry *compile_var_package; | |
| 1706 | ImportTableEntry *compile_var_import; | |
| 1707 | ImportTableEntry *root_import; | |
| 1708 | ImportTableEntry *bootstrap_import; | |
| 1709 | ImportTableEntry *test_runner_import; | |
| 1696 | ZigPackage *std_package; | |
| 1697 | ZigPackage *panic_package; | |
| 1698 | ZigPackage *test_runner_package; | |
| 1699 | ZigPackage *compile_var_package; | |
| 1700 | ZigType *compile_var_import; | |
| 1701 | ZigType *root_import; | |
| 1702 | ZigType *bootstrap_import; | |
| 1703 | ZigType *test_runner_import; | |
| 1710 | 1704 | |
| 1711 | 1705 | struct { |
| 1712 | 1706 | ZigType *entry_bool; |
| ... | ... | @@ -1731,7 +1725,6 @@ struct CodeGen { |
| 1731 | 1725 | ZigType *entry_unreachable; |
| 1732 | 1726 | ZigType *entry_type; |
| 1733 | 1727 | ZigType *entry_invalid; |
| 1734 | ZigType *entry_namespace; | |
| 1735 | 1728 | ZigType *entry_block; |
| 1736 | 1729 | ZigType *entry_num_lit_int; |
| 1737 | 1730 | ZigType *entry_num_lit_float; |
| ... | ... | @@ -1851,7 +1844,7 @@ struct CodeGen { |
| 1851 | 1844 | Buf *root_out_name; |
| 1852 | 1845 | Buf *test_filter; |
| 1853 | 1846 | Buf *test_name_prefix; |
| 1854 | PackageTableEntry *root_package; | |
| 1847 | ZigPackage *root_package; | |
| 1855 | 1848 | Buf *zig_lib_dir; |
| 1856 | 1849 | Buf *zig_std_dir; |
| 1857 | 1850 | |
| ... | ... | @@ -1945,13 +1938,16 @@ struct ScopeDecls { |
| 1945 | 1938 | Scope base; |
| 1946 | 1939 | |
| 1947 | 1940 | HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table; |
| 1948 | bool safety_off; | |
| 1941 | ZigList<AstNode *> use_decls; | |
| 1949 | 1942 | AstNode *safety_set_node; |
| 1950 | bool fast_math_on; | |
| 1951 | 1943 | AstNode *fast_math_set_node; |
| 1952 | ImportTableEntry *import; | |
| 1944 | ZigType *import; | |
| 1953 | 1945 | // If this is a scope from a container, this is the type entry, otherwise null |
| 1954 | 1946 | ZigType *container_type; |
| 1947 | ||
| 1948 | bool safety_off; | |
| 1949 | bool fast_math_on; | |
| 1950 | bool any_imports_failed; | |
| 1955 | 1951 | }; |
| 1956 | 1952 | |
| 1957 | 1953 | // This scope comes from a block expression in user code. |
| ... | ... | @@ -3507,7 +3503,7 @@ struct FnWalkTypes { |
| 3507 | 3503 | }; |
| 3508 | 3504 | |
| 3509 | 3505 | struct FnWalkVars { |
| 3510 | ImportTableEntry *import; | |
| 3506 | ZigType *import; | |
| 3511 | 3507 | LLVMValueRef llvm_fn; |
| 3512 | 3508 | ZigFn *fn; |
| 3513 | 3509 | ZigVar *var; |
src/analyze.cpp+133-145| ... | ... | @@ -28,10 +28,14 @@ static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum |
| 28 | 28 | static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type); |
| 29 | 29 | static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry); |
| 30 | 30 | |
| 31 | static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTableEntry *owner, Token *token, | |
| 32 | Buf *msg) | |
| 33 | { | |
| 34 | if (owner->c_import_node != nullptr) { | |
| 31 | static bool is_top_level_struct(ZigType *import) { | |
| 32 | return import->id == ZigTypeIdStruct && import->data.structure.root_struct != nullptr; | |
| 33 | } | |
| 34 | ||
| 35 | static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ZigType *owner, Token *token, Buf *msg) { | |
| 36 | assert(is_top_level_struct(owner)); | |
| 37 | RootStruct *root_struct = owner->data.structure.root_struct; | |
| 38 | if (root_struct->c_import_node != nullptr) { | |
| 35 | 39 | // if this happens, then translate_c generated code that |
| 36 | 40 | // failed semantic analysis, which isn't supposed to happen |
| 37 | 41 | |
| ... | ... | @@ -46,18 +50,20 @@ static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTa |
| 46 | 50 | return note; |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column, | |
| 50 | owner->source_code, owner->line_offsets, msg); | |
| 53 | ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column, | |
| 54 | root_struct->source_code, root_struct->line_offsets, msg); | |
| 51 | 55 | |
| 52 | 56 | err_msg_add_note(parent_msg, err); |
| 53 | 57 | return err; |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg) { | |
| 57 | if (owner->c_import_node != nullptr) { | |
| 60 | ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) { | |
| 61 | assert(is_top_level_struct(owner)); | |
| 62 | RootStruct *root_struct = owner->data.structure.root_struct; | |
| 63 | if (root_struct->c_import_node != nullptr) { | |
| 58 | 64 | // if this happens, then translate_c generated code that |
| 59 | 65 | // failed semantic analysis, which isn't supposed to happen |
| 60 | ErrorMsg *err = add_node_error(g, owner->c_import_node, | |
| 66 | ErrorMsg *err = add_node_error(g, root_struct->c_import_node, | |
| 61 | 67 | buf_sprintf("compiler bug: @cImport generated invalid zig code")); |
| 62 | 68 | |
| 63 | 69 | add_error_note_token(g, err, owner, token, msg); |
| ... | ... | @@ -65,8 +71,8 @@ ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf |
| 65 | 71 | g->errors.append(err); |
| 66 | 72 | return err; |
| 67 | 73 | } |
| 68 | ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column, | |
| 69 | owner->source_code, owner->line_offsets, msg); | |
| 74 | ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column, | |
| 75 | root_struct->source_code, root_struct->line_offsets, msg); | |
| 70 | 76 | |
| 71 | 77 | g->errors.append(err); |
| 72 | 78 | return err; |
| ... | ... | @@ -114,7 +120,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope |
| 114 | 120 | dest->parent = parent; |
| 115 | 121 | } |
| 116 | 122 | |
| 117 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) { | |
| 123 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import) { | |
| 118 | 124 | assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr); |
| 119 | 125 | ScopeDecls *scope = allocate<ScopeDecls>(1); |
| 120 | 126 | init_scope(g, &scope->base, ScopeIdDecls, node, parent); |
| ... | ... | @@ -207,11 +213,11 @@ Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent) { |
| 207 | 213 | return &scope->base; |
| 208 | 214 | } |
| 209 | 215 | |
| 210 | ImportTableEntry *get_scope_import(Scope *scope) { | |
| 216 | ZigType *get_scope_import(Scope *scope) { | |
| 211 | 217 | while (scope) { |
| 212 | 218 | if (scope->id == ScopeIdDecls) { |
| 213 | 219 | ScopeDecls *decls_scope = (ScopeDecls *)scope; |
| 214 | assert(decls_scope->import); | |
| 220 | assert(is_top_level_struct(decls_scope->import)); | |
| 215 | 221 | return decls_scope->import; |
| 216 | 222 | } |
| 217 | 223 | scope = scope->parent; |
| ... | ... | @@ -261,7 +267,6 @@ AstNode *type_decl_node(ZigType *type_entry) { |
| 261 | 267 | case ZigTypeIdErrorUnion: |
| 262 | 268 | case ZigTypeIdErrorSet: |
| 263 | 269 | case ZigTypeIdFn: |
| 264 | case ZigTypeIdNamespace: | |
| 265 | 270 | case ZigTypeIdBoundFn: |
| 266 | 271 | case ZigTypeIdArgTuple: |
| 267 | 272 | case ZigTypeIdPromise: |
| ... | ... | @@ -323,7 +328,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { |
| 323 | 328 | case ZigTypeIdErrorUnion: |
| 324 | 329 | case ZigTypeIdErrorSet: |
| 325 | 330 | case ZigTypeIdFn: |
| 326 | case ZigTypeIdNamespace: | |
| 327 | 331 | case ZigTypeIdBoundFn: |
| 328 | 332 | case ZigTypeIdArgTuple: |
| 329 | 333 | case ZigTypeIdPromise: |
| ... | ... | @@ -1010,14 +1014,14 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c |
| 1010 | 1014 | |
| 1011 | 1015 | buf_init_from_str(&entry->name, name); |
| 1012 | 1016 | |
| 1013 | ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr; | |
| 1017 | ZigType *import = scope ? get_scope_import(scope) : nullptr; | |
| 1014 | 1018 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; |
| 1015 | 1019 | |
| 1016 | 1020 | entry->type_ref = LLVMInt8Type(); |
| 1017 | 1021 | entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, |
| 1018 | 1022 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), |
| 1019 | import ? ZigLLVMFileToScope(import->di_file) : nullptr, | |
| 1020 | import ? import->di_file : nullptr, | |
| 1023 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, | |
| 1024 | import ? import->data.structure.root_struct->di_file : nullptr, | |
| 1021 | 1025 | line); |
| 1022 | 1026 | entry->zero_bits = false; |
| 1023 | 1027 | |
| ... | ... | @@ -1288,6 +1292,25 @@ static ZigTypeId container_to_type(ContainerKind kind) { |
| 1288 | 1292 | zig_unreachable(); |
| 1289 | 1293 | } |
| 1290 | 1294 | |
| 1295 | // 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) { | |
| 1297 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); | |
| 1298 | entry->data.structure.decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, entry); | |
| 1299 | entry->data.structure.root_struct = root_struct; | |
| 1300 | entry->data.structure.layout = ContainerLayoutAuto; | |
| 1301 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name); | |
| 1302 | ||
| 1303 | size_t line = 0; // root therefore first line | |
| 1304 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); | |
| 1305 | ||
| 1306 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, | |
| 1307 | dwarf_kind, name, | |
| 1308 | ZigLLVMFileToScope(root_struct->di_file), root_struct->di_file, (unsigned)(line + 1)); | |
| 1309 | ||
| 1310 | buf_init_from_str(&entry->name, name); | |
| 1311 | return entry; | |
| 1312 | } | |
| 1313 | ||
| 1291 | 1314 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, |
| 1292 | 1315 | AstNode *decl_node, const char *name, ContainerLayout layout) |
| 1293 | 1316 | { |
| ... | ... | @@ -1312,11 +1335,12 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind |
| 1312 | 1335 | size_t line = decl_node ? decl_node->line : 0; |
| 1313 | 1336 | unsigned dwarf_kind = ZigLLVMTag_DW_structure_type(); |
| 1314 | 1337 | |
| 1315 | ImportTableEntry *import = get_scope_import(scope); | |
| 1338 | ZigType *import = get_scope_import(scope); | |
| 1316 | 1339 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name); |
| 1317 | 1340 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, |
| 1318 | 1341 | dwarf_kind, name, |
| 1319 | ZigLLVMFileToScope(import->di_file), import->di_file, (unsigned)(line + 1)); | |
| 1342 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 1343 | import->data.structure.root_struct->di_file, (unsigned)(line + 1)); | |
| 1320 | 1344 | |
| 1321 | 1345 | buf_init_from_str(&entry->name, name); |
| 1322 | 1346 | |
| ... | ... | @@ -1459,7 +1483,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType |
| 1459 | 1483 | case ZigTypeIdNull: |
| 1460 | 1484 | case ZigTypeIdErrorUnion: |
| 1461 | 1485 | case ZigTypeIdErrorSet: |
| 1462 | case ZigTypeIdNamespace: | |
| 1463 | 1486 | case ZigTypeIdBoundFn: |
| 1464 | 1487 | case ZigTypeIdArgTuple: |
| 1465 | 1488 | case ZigTypeIdOpaque: |
| ... | ... | @@ -1547,7 +1570,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { |
| 1547 | 1570 | case ZigTypeIdNull: |
| 1548 | 1571 | case ZigTypeIdErrorUnion: |
| 1549 | 1572 | case ZigTypeIdErrorSet: |
| 1550 | case ZigTypeIdNamespace: | |
| 1551 | 1573 | case ZigTypeIdBoundFn: |
| 1552 | 1574 | case ZigTypeIdArgTuple: |
| 1553 | 1575 | case ZigTypeIdPromise: |
| ... | ... | @@ -1706,7 +1728,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1706 | 1728 | return g->builtin_types.entry_invalid; |
| 1707 | 1729 | case ZigTypeIdComptimeFloat: |
| 1708 | 1730 | case ZigTypeIdComptimeInt: |
| 1709 | case ZigTypeIdNamespace: | |
| 1710 | 1731 | case ZigTypeIdBoundFn: |
| 1711 | 1732 | case ZigTypeIdMetaType: |
| 1712 | 1733 | case ZigTypeIdVoid: |
| ... | ... | @@ -1801,7 +1822,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1801 | 1822 | |
| 1802 | 1823 | case ZigTypeIdComptimeFloat: |
| 1803 | 1824 | case ZigTypeIdComptimeInt: |
| 1804 | case ZigTypeIdNamespace: | |
| 1805 | 1825 | case ZigTypeIdBoundFn: |
| 1806 | 1826 | case ZigTypeIdMetaType: |
| 1807 | 1827 | case ZigTypeIdUnreachable: |
| ... | ... | @@ -1895,7 +1915,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { |
| 1895 | 1915 | ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count); |
| 1896 | 1916 | |
| 1897 | 1917 | Scope *scope = &enum_type->data.enumeration.decls_scope->base; |
| 1898 | ImportTableEntry *import = get_scope_import(scope); | |
| 1918 | ZigType *import = get_scope_import(scope); | |
| 1899 | 1919 | |
| 1900 | 1920 | // set temporary flag |
| 1901 | 1921 | enum_type->data.enumeration.embedded_in_current = true; |
| ... | ... | @@ -1924,9 +1944,9 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { |
| 1924 | 1944 | ZigLLVMDIType **di_root_members = nullptr; |
| 1925 | 1945 | size_t debug_member_count = 0; |
| 1926 | 1946 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| 1927 | ZigLLVMFileToScope(import->di_file), | |
| 1947 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 1928 | 1948 | buf_ptr(&enum_type->name), |
| 1929 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 1949 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 1930 | 1950 | debug_size_in_bits, |
| 1931 | 1951 | debug_align_in_bits, |
| 1932 | 1952 | 0, nullptr, di_root_members, (int)debug_member_count, 0, nullptr, ""); |
| ... | ... | @@ -1942,8 +1962,8 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { |
| 1942 | 1962 | uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref); |
| 1943 | 1963 | uint64_t tag_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref); |
| 1944 | 1964 | ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder, |
| 1945 | ZigLLVMFileToScope(import->di_file), buf_ptr(&enum_type->name), | |
| 1946 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 1965 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&enum_type->name), | |
| 1966 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 1947 | 1967 | tag_debug_size_in_bits, |
| 1948 | 1968 | tag_debug_align_in_bits, |
| 1949 | 1969 | di_enumerators, field_count, |
| ... | ... | @@ -2159,15 +2179,15 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2159 | 2179 | if (struct_type->zero_bits) { |
| 2160 | 2180 | struct_type->type_ref = LLVMVoidType(); |
| 2161 | 2181 | |
| 2162 | ImportTableEntry *import = get_scope_import(scope); | |
| 2182 | ZigType *import = get_scope_import(scope); | |
| 2163 | 2183 | uint64_t debug_size_in_bits = 0; |
| 2164 | 2184 | uint64_t debug_align_in_bits = 0; |
| 2165 | 2185 | ZigLLVMDIType **di_element_types = nullptr; |
| 2166 | 2186 | size_t debug_field_count = 0; |
| 2167 | 2187 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| 2168 | ZigLLVMFileToScope(import->di_file), | |
| 2188 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 2169 | 2189 | buf_ptr(&struct_type->name), |
| 2170 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2190 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2171 | 2191 | debug_size_in_bits, |
| 2172 | 2192 | debug_align_in_bits, |
| 2173 | 2193 | 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, ""); |
| ... | ... | @@ -2191,7 +2211,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2191 | 2211 | |
| 2192 | 2212 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count); |
| 2193 | 2213 | |
| 2194 | ImportTableEntry *import = get_scope_import(scope); | |
| 2214 | ZigType *import = get_scope_import(scope); | |
| 2195 | 2215 | size_t debug_field_index = 0; |
| 2196 | 2216 | for (size_t i = 0; i < field_count; i += 1) { |
| 2197 | 2217 | AstNode *field_node = decl_node->data.container_decl.fields.at(i); |
| ... | ... | @@ -2234,7 +2254,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2234 | 2254 | } |
| 2235 | 2255 | di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 2236 | 2256 | ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name), |
| 2237 | import->di_file, (unsigned)(field_node->line + 1), | |
| 2257 | import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1), | |
| 2238 | 2258 | debug_size_in_bits, |
| 2239 | 2259 | debug_align_in_bits, |
| 2240 | 2260 | debug_offset_in_bits, |
| ... | ... | @@ -2247,9 +2267,9 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2247 | 2267 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref); |
| 2248 | 2268 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, struct_type->type_ref); |
| 2249 | 2269 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| 2250 | ZigLLVMFileToScope(import->di_file), | |
| 2270 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 2251 | 2271 | buf_ptr(&struct_type->name), |
| 2252 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2272 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2253 | 2273 | debug_size_in_bits, |
| 2254 | 2274 | debug_align_in_bits, |
| 2255 | 2275 | 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, ""); |
| ... | ... | @@ -2298,7 +2318,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2298 | 2318 | uint64_t biggest_size_in_bits = 0; |
| 2299 | 2319 | |
| 2300 | 2320 | Scope *scope = &union_type->data.unionation.decls_scope->base; |
| 2301 | ImportTableEntry *import = get_scope_import(scope); | |
| 2321 | ZigType *import = get_scope_import(scope); | |
| 2302 | 2322 | |
| 2303 | 2323 | // set temporary flag |
| 2304 | 2324 | union_type->data.unionation.embedded_in_current = true; |
| ... | ... | @@ -2325,7 +2345,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2325 | 2345 | |
| 2326 | 2346 | union_inner_di_types[union_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 2327 | 2347 | ZigLLVMTypeToScope(union_type->di_type), buf_ptr(union_field->enum_field->name), |
| 2328 | import->di_file, (unsigned)(field_node->line + 1), | |
| 2348 | import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1), | |
| 2329 | 2349 | store_size_in_bits, |
| 2330 | 2350 | abi_align_in_bits, |
| 2331 | 2351 | 0, |
| ... | ... | @@ -2358,9 +2378,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2358 | 2378 | ZigLLVMDIType **di_root_members = nullptr; |
| 2359 | 2379 | size_t debug_member_count = 0; |
| 2360 | 2380 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder, |
| 2361 | ZigLLVMFileToScope(import->di_file), | |
| 2381 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 2362 | 2382 | buf_ptr(&union_type->name), |
| 2363 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2383 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2364 | 2384 | debug_size_in_bits, |
| 2365 | 2385 | debug_align_in_bits, |
| 2366 | 2386 | 0, di_root_members, (int)debug_member_count, 0, ""); |
| ... | ... | @@ -2396,8 +2416,8 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2396 | 2416 | |
| 2397 | 2417 | // create debug type for union |
| 2398 | 2418 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder, |
| 2399 | ZigLLVMFileToScope(import->di_file), buf_ptr(&union_type->name), | |
| 2400 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2419 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&union_type->name), | |
| 2420 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2401 | 2421 | biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types, |
| 2402 | 2422 | gen_field_count, 0, ""); |
| 2403 | 2423 | |
| ... | ... | @@ -2452,7 +2472,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2452 | 2472 | // create debug type for union |
| 2453 | 2473 | ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder, |
| 2454 | 2474 | ZigLLVMTypeToScope(union_type->di_type), "AnonUnion", |
| 2455 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2475 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2456 | 2476 | biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types, |
| 2457 | 2477 | gen_field_count, 0, ""); |
| 2458 | 2478 | |
| ... | ... | @@ -2463,7 +2483,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2463 | 2483 | |
| 2464 | 2484 | ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 2465 | 2485 | ZigLLVMTypeToScope(union_type->di_type), "payload", |
| 2466 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2486 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2467 | 2487 | biggest_size_in_bits, |
| 2468 | 2488 | biggest_align_in_bits, |
| 2469 | 2489 | union_offset_in_bits, |
| ... | ... | @@ -2474,7 +2494,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2474 | 2494 | |
| 2475 | 2495 | ZigLLVMDIType *tag_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 2476 | 2496 | ZigLLVMTypeToScope(union_type->di_type), "tag", |
| 2477 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2497 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2478 | 2498 | tag_debug_size_in_bits, |
| 2479 | 2499 | tag_debug_align_in_bits, |
| 2480 | 2500 | tag_offset_in_bits, |
| ... | ... | @@ -2487,9 +2507,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2487 | 2507 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, union_type->type_ref); |
| 2488 | 2508 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, union_type->type_ref); |
| 2489 | 2509 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| 2490 | ZigLLVMFileToScope(import->di_file), | |
| 2510 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), | |
| 2491 | 2511 | buf_ptr(&union_type->name), |
| 2492 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 2512 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 2493 | 2513 | debug_size_in_bits, |
| 2494 | 2514 | debug_align_in_bits, |
| 2495 | 2515 | 0, nullptr, di_root_members, 2, 0, nullptr, ""); |
| ... | ... | @@ -3185,15 +3205,15 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3185 | 3205 | } |
| 3186 | 3206 | |
| 3187 | 3207 | if (create_enum_type) { |
| 3188 | ImportTableEntry *import = get_scope_import(scope); | |
| 3208 | ZigType *import = get_scope_import(scope); | |
| 3189 | 3209 | uint64_t tag_debug_size_in_bits = tag_type->zero_bits ? 0 : |
| 3190 | 3210 | 8*LLVMStoreSizeOfType(g->target_data_ref, tag_type->type_ref); |
| 3191 | 3211 | uint64_t tag_debug_align_in_bits = tag_type->zero_bits ? 0 : |
| 3192 | 3212 | 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_type->type_ref); |
| 3193 | 3213 | // TODO get a more accurate debug scope |
| 3194 | 3214 | ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder, |
| 3195 | ZigLLVMFileToScope(import->di_file), buf_ptr(&tag_type->name), | |
| 3196 | import->di_file, (unsigned)(decl_node->line + 1), | |
| 3215 | ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&tag_type->name), | |
| 3216 | import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1), | |
| 3197 | 3217 | tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count, |
| 3198 | 3218 | tag_type->di_type, ""); |
| 3199 | 3219 | tag_type->di_type = tag_di_type; |
| ... | ... | @@ -3265,7 +3285,8 @@ static bool scope_is_root_decls(Scope *scope) { |
| 3265 | 3285 | while (scope) { |
| 3266 | 3286 | if (scope->id == ScopeIdDecls) { |
| 3267 | 3287 | ScopeDecls *scope_decls = (ScopeDecls *)scope; |
| 3268 | return (scope_decls->container_type == nullptr); | |
| 3288 | return scope_decls->container_type == nullptr || | |
| 3289 | is_top_level_struct(scope_decls->container_type); | |
| 3269 | 3290 | } |
| 3270 | 3291 | scope = scope->parent; |
| 3271 | 3292 | } |
| ... | ... | @@ -3326,7 +3347,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi |
| 3326 | 3347 | } |
| 3327 | 3348 | |
| 3328 | 3349 | static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3329 | ImportTableEntry *import = tld_fn->base.import; | |
| 3350 | ZigType *import = tld_fn->base.import; | |
| 3330 | 3351 | AstNode *source_node = tld_fn->base.source_node; |
| 3331 | 3352 | if (source_node->type == NodeTypeFnProto) { |
| 3332 | 3353 | AstNodeFnProto *fn_proto = &source_node->data.fn_proto; |
| ... | ... | @@ -3382,11 +3403,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3382 | 3403 | } |
| 3383 | 3404 | |
| 3384 | 3405 | if (scope_is_root_decls(tld_fn->base.parent_scope) && |
| 3385 | (import == g->root_import || import->package == g->panic_package)) | |
| 3406 | (import == g->root_import || import->data.structure.root_struct->package == g->panic_package)) | |
| 3386 | 3407 | { |
| 3387 | 3408 | if (g->have_pub_main && buf_eql_str(&fn_table_entry->symbol_name, "main")) { |
| 3388 | 3409 | g->main_fn = fn_table_entry; |
| 3389 | } else if ((import->package == g->panic_package || g->have_pub_panic) && | |
| 3410 | } else if ((import->data.structure.root_struct->package == g->panic_package || g->have_pub_panic) && | |
| 3390 | 3411 | buf_eql_str(&fn_table_entry->symbol_name, "panic")) |
| 3391 | 3412 | { |
| 3392 | 3413 | g->panic_fn = fn_table_entry; |
| ... | ... | @@ -3473,8 +3494,8 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope |
| 3473 | 3494 | if (!g->is_test_build) |
| 3474 | 3495 | return; |
| 3475 | 3496 | |
| 3476 | ImportTableEntry *import = get_scope_import(&decls_scope->base); | |
| 3477 | if (import->package != g->root_package) | |
| 3497 | ZigType *import = get_scope_import(&decls_scope->base); | |
| 3498 | if (import->data.structure.root_struct->package != g->root_package) | |
| 3478 | 3499 | return; |
| 3479 | 3500 | |
| 3480 | 3501 | Buf *decl_name_buf = node->data.test_decl.name; |
| ... | ... | @@ -3511,8 +3532,8 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source |
| 3511 | 3532 | } |
| 3512 | 3533 | |
| 3513 | 3534 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) { |
| 3514 | Tld *tld = g->compile_var_import->decls_scope->decl_table.get(name); | |
| 3515 | resolve_top_level_decl(g, tld, false, tld->source_node); | |
| 3535 | Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name); | |
| 3536 | resolve_top_level_decl(g, tld, tld->source_node); | |
| 3516 | 3537 | assert(tld->id == TldIdVar); |
| 3517 | 3538 | TldVar *tld_var = (TldVar *)tld; |
| 3518 | 3539 | tld_var->var->const_value = value; |
| ... | ... | @@ -3561,8 +3582,8 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 3561 | 3582 | case NodeTypeUse: |
| 3562 | 3583 | { |
| 3563 | 3584 | g->use_queue.append(node); |
| 3564 | ImportTableEntry *import = get_scope_import(&decls_scope->base); | |
| 3565 | import->use_decls.append(node); | |
| 3585 | ZigType *import = get_scope_import(&decls_scope->base); | |
| 3586 | get_container_scope(import)->use_decls.append(node); | |
| 3566 | 3587 | break; |
| 3567 | 3588 | } |
| 3568 | 3589 | case NodeTypeTestDecl: |
| ... | ... | @@ -3654,7 +3675,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry |
| 3654 | 3675 | return g->builtin_types.entry_invalid; |
| 3655 | 3676 | case ZigTypeIdComptimeFloat: |
| 3656 | 3677 | case ZigTypeIdComptimeInt: |
| 3657 | case ZigTypeIdNamespace: | |
| 3658 | 3678 | case ZigTypeIdMetaType: |
| 3659 | 3679 | case ZigTypeIdVoid: |
| 3660 | 3680 | case ZigTypeIdBool: |
| ... | ... | @@ -3847,16 +3867,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { |
| 3847 | 3867 | g->global_vars.append(tld_var); |
| 3848 | 3868 | } |
| 3849 | 3869 | |
| 3850 | void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node) { | |
| 3870 | void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) { | |
| 3851 | 3871 | if (tld->resolution != TldResolutionUnresolved) |
| 3852 | 3872 | return; |
| 3853 | 3873 | |
| 3854 | if (tld->dep_loop_flag) { | |
| 3855 | add_node_error(g, tld->source_node, buf_sprintf("'%s' depends on itself", buf_ptr(tld->name))); | |
| 3856 | tld->resolution = TldResolutionInvalid; | |
| 3857 | return; | |
| 3858 | } | |
| 3859 | ||
| 3860 | 3874 | tld->dep_loop_flag = true; |
| 3861 | 3875 | g->tld_ref_source_node_stack.append(source_node); |
| 3862 | 3876 | |
| ... | ... | @@ -3894,9 +3908,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so |
| 3894 | 3908 | |
| 3895 | 3909 | Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) { |
| 3896 | 3910 | // we must resolve all the use decls |
| 3897 | ImportTableEntry *import = get_scope_import(scope); | |
| 3898 | for (size_t i = 0; i < import->use_decls.length; i += 1) { | |
| 3899 | AstNode *use_decl_node = import->use_decls.at(i); | |
| 3911 | ZigType *import = get_scope_import(scope); | |
| 3912 | for (size_t i = 0; i < get_container_scope(import)->use_decls.length; i += 1) { | |
| 3913 | AstNode *use_decl_node = get_container_scope(import)->use_decls.at(i); | |
| 3900 | 3914 | if (use_decl_node->data.use.resolution == TldResolutionUnresolved) { |
| 3901 | 3915 | preview_use_decl(g, use_decl_node); |
| 3902 | 3916 | resolve_use_decl(g, use_decl_node); |
| ... | ... | @@ -4039,7 +4053,6 @@ static bool is_container(ZigType *type_entry) { |
| 4039 | 4053 | case ZigTypeIdErrorUnion: |
| 4040 | 4054 | case ZigTypeIdErrorSet: |
| 4041 | 4055 | case ZigTypeIdFn: |
| 4042 | case ZigTypeIdNamespace: | |
| 4043 | 4056 | case ZigTypeIdBoundFn: |
| 4044 | 4057 | case ZigTypeIdArgTuple: |
| 4045 | 4058 | case ZigTypeIdOpaque: |
| ... | ... | @@ -4098,7 +4111,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) { |
| 4098 | 4111 | case ZigTypeIdErrorUnion: |
| 4099 | 4112 | case ZigTypeIdErrorSet: |
| 4100 | 4113 | case ZigTypeIdFn: |
| 4101 | case ZigTypeIdNamespace: | |
| 4102 | 4114 | case ZigTypeIdBoundFn: |
| 4103 | 4115 | case ZigTypeIdInvalid: |
| 4104 | 4116 | case ZigTypeIdArgTuple: |
| ... | ... | @@ -4344,7 +4356,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 4344 | 4356 | |
| 4345 | 4357 | ConstExprValue *use_target_value = src_use_node->data.use.value; |
| 4346 | 4358 | if (type_is_invalid(use_target_value->type)) { |
| 4347 | dst_use_node->owner->any_imports_failed = true; | |
| 4359 | get_container_scope(dst_use_node->owner)->any_imports_failed = true; | |
| 4348 | 4360 | return; |
| 4349 | 4361 | } |
| 4350 | 4362 | |
| ... | ... | @@ -4352,14 +4364,15 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 4352 | 4364 | |
| 4353 | 4365 | assert(use_target_value->special != ConstValSpecialRuntime); |
| 4354 | 4366 | |
| 4355 | ImportTableEntry *target_import = use_target_value->data.x_import; | |
| 4367 | ZigType *target_import = use_target_value->data.x_type; | |
| 4356 | 4368 | assert(target_import); |
| 4369 | assert(target_import->id == ZigTypeIdStruct); | |
| 4357 | 4370 | |
| 4358 | if (target_import->any_imports_failed) { | |
| 4359 | dst_use_node->owner->any_imports_failed = true; | |
| 4371 | if (get_container_scope(target_import)->any_imports_failed) { | |
| 4372 | get_container_scope(dst_use_node->owner)->any_imports_failed = true; | |
| 4360 | 4373 | } |
| 4361 | 4374 | |
| 4362 | auto it = target_import->decls_scope->decl_table.entry_iterator(); | |
| 4375 | auto it = get_container_scope(target_import)->decl_table.entry_iterator(); | |
| 4363 | 4376 | for (;;) { |
| 4364 | 4377 | auto *entry = it.next(); |
| 4365 | 4378 | if (!entry) |
| ... | ... | @@ -4374,7 +4387,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 4374 | 4387 | |
| 4375 | 4388 | Buf *target_tld_name = entry->key; |
| 4376 | 4389 | |
| 4377 | auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld); | |
| 4390 | auto existing_entry = get_container_scope(dst_use_node->owner)->decl_table.put_unique(target_tld_name, target_tld); | |
| 4378 | 4391 | if (existing_entry) { |
| 4379 | 4392 | Tld *existing_decl = existing_entry->value; |
| 4380 | 4393 | if (existing_decl != target_tld) { |
| ... | ... | @@ -4387,8 +4400,8 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * |
| 4387 | 4400 | } |
| 4388 | 4401 | } |
| 4389 | 4402 | |
| 4390 | for (size_t i = 0; i < target_import->use_decls.length; i += 1) { | |
| 4391 | AstNode *use_decl_node = target_import->use_decls.at(i); | |
| 4403 | for (size_t i = 0; i < get_container_scope(target_import)->use_decls.length; i += 1) { | |
| 4404 | AstNode *use_decl_node = get_container_scope(target_import)->use_decls.at(i); | |
| 4392 | 4405 | if (use_decl_node->data.use.visib_mod != VisibModPrivate) |
| 4393 | 4406 | add_symbols_from_import(g, use_decl_node, dst_use_node); |
| 4394 | 4407 | } |
| ... | ... | @@ -4415,16 +4428,16 @@ void preview_use_decl(CodeGen *g, AstNode *node) { |
| 4415 | 4428 | } |
| 4416 | 4429 | |
| 4417 | 4430 | node->data.use.resolution = TldResolutionResolving; |
| 4418 | ConstExprValue *result = analyze_const_value(g, &node->owner->decls_scope->base, | |
| 4419 | node->data.use.expr, g->builtin_types.entry_namespace, nullptr); | |
| 4431 | ConstExprValue *result = analyze_const_value(g, &get_container_scope(node->owner)->base, | |
| 4432 | node->data.use.expr, g->builtin_types.entry_type, nullptr); | |
| 4420 | 4433 | |
| 4421 | 4434 | if (type_is_invalid(result->type)) |
| 4422 | node->owner->any_imports_failed = true; | |
| 4435 | get_container_scope(node->owner)->any_imports_failed = true; | |
| 4423 | 4436 | |
| 4424 | 4437 | node->data.use.value = result; |
| 4425 | 4438 | } |
| 4426 | 4439 | |
| 4427 | ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) { | |
| 4440 | ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Buf *source_code) { | |
| 4428 | 4441 | if (g->verbose_tokenize) { |
| 4429 | 4442 | fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path)); |
| 4430 | 4443 | fprintf(stderr, "----------------\n"); |
| ... | ... | @@ -4452,32 +4465,34 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r |
| 4452 | 4465 | fprintf(stderr, "------\n"); |
| 4453 | 4466 | } |
| 4454 | 4467 | |
| 4455 | ImportTableEntry *import_entry = allocate<ImportTableEntry>(1); | |
| 4456 | import_entry->package = package; | |
| 4457 | import_entry->source_code = source_code; | |
| 4458 | import_entry->line_offsets = tokenization.line_offsets; | |
| 4459 | import_entry->path = resolved_path; | |
| 4460 | ||
| 4461 | import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color); | |
| 4462 | assert(import_entry->root); | |
| 4463 | if (g->verbose_ast) { | |
| 4464 | ast_print(stderr, import_entry->root, 0); | |
| 4465 | } | |
| 4466 | ||
| 4467 | 4468 | Buf *src_dirname = buf_alloc(); |
| 4468 | 4469 | Buf *src_basename = buf_alloc(); |
| 4469 | 4470 | os_path_split(resolved_path, src_dirname, src_basename); |
| 4470 | 4471 | |
| 4471 | import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | |
| 4472 | Buf noextname = BUF_INIT; | |
| 4473 | os_path_extname(src_basename, &noextname, nullptr); | |
| 4474 | RootStruct *root_struct = allocate<RootStruct>(1); | |
| 4475 | root_struct->package = package; | |
| 4476 | root_struct->source_code = source_code; | |
| 4477 | root_struct->line_offsets = tokenization.line_offsets; | |
| 4478 | root_struct->path = resolved_path; | |
| 4479 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | |
| 4480 | ZigType *import_entry = get_root_container_type(g, buf_ptr(&noextname), root_struct); | |
| 4481 | ||
| 4482 | AstNode *root_node = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color); | |
| 4483 | assert(root_node != nullptr); | |
| 4484 | assert(root_node->type == NodeTypeContainerDecl); | |
| 4485 | import_entry->data.structure.decl_node = root_node; | |
| 4486 | import_entry->data.structure.decls_scope->base.source_node = root_node; | |
| 4487 | if (g->verbose_ast) { | |
| 4488 | ast_print(stderr, root_node, 0); | |
| 4489 | } | |
| 4490 | ||
| 4472 | 4491 | g->import_table.put(resolved_path, import_entry); |
| 4473 | 4492 | g->import_queue.append(import_entry); |
| 4474 | 4493 | |
| 4475 | import_entry->decls_scope = create_decls_scope(g, import_entry->root, nullptr, nullptr, import_entry); | |
| 4476 | ||
| 4477 | ||
| 4478 | assert(import_entry->root->type == NodeTypeContainerDecl); | |
| 4479 | for (size_t decl_i = 0; decl_i < import_entry->root->data.container_decl.decls.length; decl_i += 1) { | |
| 4480 | AstNode *top_level_decl = import_entry->root->data.container_decl.decls.at(decl_i); | |
| 4494 | for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) { | |
| 4495 | AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i); | |
| 4481 | 4496 | |
| 4482 | 4497 | if (top_level_decl->type == NodeTypeFnDef) { |
| 4483 | 4498 | AstNode *proto_node = top_level_decl->data.fn_def.fn_proto; |
| ... | ... | @@ -4502,16 +4517,16 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r |
| 4502 | 4517 | return import_entry; |
| 4503 | 4518 | } |
| 4504 | 4519 | |
| 4505 | void scan_import(CodeGen *g, ImportTableEntry *import) { | |
| 4506 | if (!import->scanned) { | |
| 4507 | import->scanned = true; | |
| 4508 | scan_decls(g, import->decls_scope, import->root); | |
| 4520 | void scan_import(CodeGen *g, ZigType *import) { | |
| 4521 | if (!import->data.structure.root_struct->scanned) { | |
| 4522 | import->data.structure.root_struct->scanned = true; | |
| 4523 | scan_decls(g, import->data.structure.decls_scope, import->data.structure.decl_node); | |
| 4509 | 4524 | } |
| 4510 | 4525 | } |
| 4511 | 4526 | |
| 4512 | 4527 | void semantic_analyze(CodeGen *g) { |
| 4513 | 4528 | for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) { |
| 4514 | ImportTableEntry *import = g->import_queue.at(g->import_queue_index); | |
| 4529 | ZigType *import = g->import_queue.at(g->import_queue_index); | |
| 4515 | 4530 | scan_import(g, import); |
| 4516 | 4531 | } |
| 4517 | 4532 | |
| ... | ... | @@ -4530,9 +4545,8 @@ void semantic_analyze(CodeGen *g) { |
| 4530 | 4545 | { |
| 4531 | 4546 | for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) { |
| 4532 | 4547 | Tld *tld = g->resolve_queue.at(g->resolve_queue_index); |
| 4533 | bool pointer_only = false; | |
| 4534 | 4548 | AstNode *source_node = nullptr; |
| 4535 | resolve_top_level_decl(g, tld, pointer_only, source_node); | |
| 4549 | resolve_top_level_decl(g, tld, source_node); | |
| 4536 | 4550 | } |
| 4537 | 4551 | |
| 4538 | 4552 | for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { |
| ... | ... | @@ -4613,7 +4627,6 @@ bool handle_is_ptr(ZigType *type_entry) { |
| 4613 | 4627 | case ZigTypeIdComptimeInt: |
| 4614 | 4628 | case ZigTypeIdUndefined: |
| 4615 | 4629 | case ZigTypeIdNull: |
| 4616 | case ZigTypeIdNamespace: | |
| 4617 | 4630 | case ZigTypeIdBoundFn: |
| 4618 | 4631 | case ZigTypeIdArgTuple: |
| 4619 | 4632 | case ZigTypeIdOpaque: |
| ... | ... | @@ -4880,8 +4893,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 4880 | 4893 | return 3415065496; |
| 4881 | 4894 | case ZigTypeIdErrorSet: |
| 4882 | 4895 | return hash_const_val_error_set(const_val); |
| 4883 | case ZigTypeIdNamespace: | |
| 4884 | return hash_ptr(const_val->data.x_import); | |
| 4885 | 4896 | case ZigTypeIdVector: |
| 4886 | 4897 | // TODO better hashing algorithm |
| 4887 | 4898 | return 3647867726; |
| ... | ... | @@ -4943,7 +4954,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) { |
| 4943 | 4954 | case ZigTypeIdComptimeInt: |
| 4944 | 4955 | case ZigTypeIdUndefined: |
| 4945 | 4956 | case ZigTypeIdNull: |
| 4946 | case ZigTypeIdNamespace: | |
| 4947 | 4957 | case ZigTypeIdBoundFn: |
| 4948 | 4958 | case ZigTypeIdFn: |
| 4949 | 4959 | case ZigTypeIdOpaque: |
| ... | ... | @@ -5013,7 +5023,6 @@ static bool return_type_is_cacheable(ZigType *return_type) { |
| 5013 | 5023 | case ZigTypeIdComptimeInt: |
| 5014 | 5024 | case ZigTypeIdUndefined: |
| 5015 | 5025 | case ZigTypeIdNull: |
| 5016 | case ZigTypeIdNamespace: | |
| 5017 | 5026 | case ZigTypeIdBoundFn: |
| 5018 | 5027 | case ZigTypeIdFn: |
| 5019 | 5028 | case ZigTypeIdOpaque: |
| ... | ... | @@ -5143,7 +5152,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 5143 | 5152 | case ZigTypeIdComptimeFloat: |
| 5144 | 5153 | case ZigTypeIdComptimeInt: |
| 5145 | 5154 | case ZigTypeIdMetaType: |
| 5146 | case ZigTypeIdNamespace: | |
| 5147 | 5155 | case ZigTypeIdBoundFn: |
| 5148 | 5156 | case ZigTypeIdArgTuple: |
| 5149 | 5157 | case ZigTypeIdOptional: |
| ... | ... | @@ -5209,7 +5217,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) { |
| 5209 | 5217 | case ZigTypeIdUndefined: |
| 5210 | 5218 | case ZigTypeIdNull: |
| 5211 | 5219 | case ZigTypeIdMetaType: |
| 5212 | case ZigTypeIdNamespace: | |
| 5213 | 5220 | case ZigTypeIdBoundFn: |
| 5214 | 5221 | case ZigTypeIdArgTuple: |
| 5215 | 5222 | return ReqCompTimeYes; |
| ... | ... | @@ -5797,8 +5804,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) { |
| 5797 | 5804 | } |
| 5798 | 5805 | case ZigTypeIdErrorUnion: |
| 5799 | 5806 | zig_panic("TODO"); |
| 5800 | case ZigTypeIdNamespace: | |
| 5801 | return a->data.x_import == b->data.x_import; | |
| 5802 | 5807 | case ZigTypeIdArgTuple: |
| 5803 | 5808 | return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index && |
| 5804 | 5809 | a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index; |
| ... | ... | @@ -6072,16 +6077,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 6072 | 6077 | } |
| 6073 | 6078 | return; |
| 6074 | 6079 | } |
| 6075 | case ZigTypeIdNamespace: | |
| 6076 | { | |
| 6077 | ImportTableEntry *import = const_val->data.x_import; | |
| 6078 | if (import->c_import_node) { | |
| 6079 | buf_appendf(buf, "(namespace from C import)"); | |
| 6080 | } else { | |
| 6081 | buf_appendf(buf, "(namespace: %s)", buf_ptr(import->path)); | |
| 6082 | } | |
| 6083 | return; | |
| 6084 | } | |
| 6085 | 6080 | case ZigTypeIdBoundFn: |
| 6086 | 6081 | { |
| 6087 | 6082 | ZigFn *fn_entry = const_val->data.x_bound_fn.fn; |
| ... | ... | @@ -6203,7 +6198,6 @@ uint32_t type_id_hash(TypeId x) { |
| 6203 | 6198 | case ZigTypeIdEnum: |
| 6204 | 6199 | case ZigTypeIdUnion: |
| 6205 | 6200 | case ZigTypeIdFn: |
| 6206 | case ZigTypeIdNamespace: | |
| 6207 | 6201 | case ZigTypeIdBoundFn: |
| 6208 | 6202 | case ZigTypeIdArgTuple: |
| 6209 | 6203 | case ZigTypeIdPromise: |
| ... | ... | @@ -6252,7 +6246,6 @@ bool type_id_eql(TypeId a, TypeId b) { |
| 6252 | 6246 | case ZigTypeIdEnum: |
| 6253 | 6247 | case ZigTypeIdUnion: |
| 6254 | 6248 | case ZigTypeIdFn: |
| 6255 | case ZigTypeIdNamespace: | |
| 6256 | 6249 | case ZigTypeIdBoundFn: |
| 6257 | 6250 | case ZigTypeIdArgTuple: |
| 6258 | 6251 | case ZigTypeIdOpaque: |
| ... | ... | @@ -6419,7 +6412,6 @@ static const ZigTypeId all_type_ids[] = { |
| 6419 | 6412 | ZigTypeIdEnum, |
| 6420 | 6413 | ZigTypeIdUnion, |
| 6421 | 6414 | ZigTypeIdFn, |
| 6422 | ZigTypeIdNamespace, | |
| 6423 | 6415 | ZigTypeIdBoundFn, |
| 6424 | 6416 | ZigTypeIdArgTuple, |
| 6425 | 6417 | ZigTypeIdOpaque, |
| ... | ... | @@ -6480,18 +6472,16 @@ size_t type_id_index(ZigType *entry) { |
| 6480 | 6472 | return 17; |
| 6481 | 6473 | case ZigTypeIdFn: |
| 6482 | 6474 | return 18; |
| 6483 | case ZigTypeIdNamespace: | |
| 6484 | return 19; | |
| 6485 | 6475 | case ZigTypeIdBoundFn: |
| 6486 | return 20; | |
| 6476 | return 19; | |
| 6487 | 6477 | case ZigTypeIdArgTuple: |
| 6488 | return 21; | |
| 6478 | return 20; | |
| 6489 | 6479 | case ZigTypeIdOpaque: |
| 6490 | return 22; | |
| 6480 | return 21; | |
| 6491 | 6481 | case ZigTypeIdPromise: |
| 6492 | return 23; | |
| 6482 | return 22; | |
| 6493 | 6483 | case ZigTypeIdVector: |
| 6494 | return 24; | |
| 6484 | return 23; | |
| 6495 | 6485 | } |
| 6496 | 6486 | zig_unreachable(); |
| 6497 | 6487 | } |
| ... | ... | @@ -6538,8 +6528,6 @@ const char *type_id_name(ZigTypeId id) { |
| 6538 | 6528 | return "Union"; |
| 6539 | 6529 | case ZigTypeIdFn: |
| 6540 | 6530 | return "Fn"; |
| 6541 | case ZigTypeIdNamespace: | |
| 6542 | return "Namespace"; | |
| 6543 | 6531 | case ZigTypeIdBoundFn: |
| 6544 | 6532 | return "BoundFn"; |
| 6545 | 6533 | case ZigTypeIdArgTuple: |
| ... | ... | @@ -6619,8 +6607,8 @@ bool type_ptr_eql(const ZigType *a, const ZigType *b) { |
| 6619 | 6607 | } |
| 6620 | 6608 | |
| 6621 | 6609 | ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { |
| 6622 | Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name)); | |
| 6623 | resolve_top_level_decl(codegen, tld, false, nullptr); | |
| 6610 | Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name)); | |
| 6611 | resolve_top_level_decl(codegen, tld, nullptr); | |
| 6624 | 6612 | assert(tld->id == TldIdVar); |
| 6625 | 6613 | TldVar *tld_var = (TldVar *)tld; |
| 6626 | 6614 | ConstExprValue *var_value = tld_var->var->const_value; |
src/analyze.hpp+8-7| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | |
| 13 | 13 | void semantic_analyze(CodeGen *g); |
| 14 | 14 | ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg); |
| 15 | ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg); | |
| 15 | ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg); | |
| 16 | 16 | ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg); |
| 17 | 17 | ZigType *new_type_table_entry(ZigTypeId id); |
| 18 | 18 | ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const); |
| ... | ... | @@ -30,6 +30,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size); |
| 30 | 30 | ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); |
| 31 | 31 | ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, |
| 32 | 32 | AstNode *decl_node, const char *name, ContainerLayout layout); |
| 33 | ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct); | |
| 33 | 34 | ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); |
| 34 | 35 | ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type); |
| 35 | 36 | ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry); |
| ... | ... | @@ -46,12 +47,12 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry); |
| 46 | 47 | bool ptr_allows_addr_zero(ZigType *ptr_type); |
| 47 | 48 | bool type_is_nonnull_ptr(ZigType *type); |
| 48 | 49 | |
| 49 | ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code); | |
| 50 | ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Buf *source_code); | |
| 50 | 51 | |
| 51 | 52 | |
| 52 | 53 | ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope); |
| 53 | 54 | Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); |
| 54 | void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node); | |
| 55 | void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node); | |
| 55 | 56 | bool type_is_codegen_pointer(ZigType *type); |
| 56 | 57 | |
| 57 | 58 | ZigType *get_src_ptr_type(ZigType *type); |
| ... | ... | @@ -77,11 +78,11 @@ bool is_array_ref(ZigType *type_entry); |
| 77 | 78 | bool is_container_ref(ZigType *type_entry); |
| 78 | 79 | bool is_valid_vector_elem_type(ZigType *elem_type); |
| 79 | 80 | void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node); |
| 80 | void scan_import(CodeGen *g, ImportTableEntry *import); | |
| 81 | void scan_import(CodeGen *g, ZigType *import); | |
| 81 | 82 | void preview_use_decl(CodeGen *g, AstNode *node); |
| 82 | 83 | void resolve_use_decl(CodeGen *g, AstNode *node); |
| 83 | 84 | ZigFn *scope_fn_entry(Scope *scope); |
| 84 | ImportTableEntry *get_scope_import(Scope *scope); | |
| 85 | ZigType *get_scope_import(Scope *scope); | |
| 85 | 86 | void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope); |
| 86 | 87 | ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, |
| 87 | 88 | bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type); |
| ... | ... | @@ -109,7 +110,7 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 109 | 110 | ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 110 | 111 | ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 111 | 112 | ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry); |
| 112 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import); | |
| 113 | ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import); | |
| 113 | 114 | Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 114 | 115 | Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent); |
| 115 | 116 | Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime); |
| ... | ... | @@ -186,7 +187,7 @@ LinkLib *add_link_lib(CodeGen *codegen, Buf *lib); |
| 186 | 187 | |
| 187 | 188 | uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry); |
| 188 | 189 | ZigType *get_align_amt_type(CodeGen *g); |
| 189 | PackageTableEntry *new_anonymous_package(void); | |
| 190 | ZigPackage *new_anonymous_package(void); | |
| 190 | 191 | |
| 191 | 192 | Buf *const_value_to_buffer(ConstExprValue *const_val); |
| 192 | 193 | void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc); |
src/codegen.cpp+33-41| ... | ... | @@ -48,15 +48,15 @@ static void init_darwin_native(CodeGen *g) { |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) { | |
| 52 | PackageTableEntry *entry = allocate<PackageTableEntry>(1); | |
| 51 | static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path) { | |
| 52 | ZigPackage *entry = allocate<ZigPackage>(1); | |
| 53 | 53 | entry->package_table.init(4); |
| 54 | 54 | buf_init_from_str(&entry->root_src_dir, root_src_dir); |
| 55 | 55 | buf_init_from_str(&entry->root_src_path, root_src_path); |
| 56 | 56 | return entry; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | PackageTableEntry *new_anonymous_package(void) { | |
| 59 | ZigPackage *new_anonymous_package(void) { | |
| 60 | 60 | return new_package("", ""); |
| 61 | 61 | } |
| 62 | 62 | |
| ... | ... | @@ -621,7 +621,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { |
| 621 | 621 | if (scope->di_scope) |
| 622 | 622 | return scope->di_scope; |
| 623 | 623 | |
| 624 | ImportTableEntry *import = get_scope_import(scope); | |
| 624 | ZigType *import = get_scope_import(scope); | |
| 625 | 625 | switch (scope->id) { |
| 626 | 626 | case ScopeIdCImport: |
| 627 | 627 | zig_unreachable(); |
| ... | ... | @@ -644,7 +644,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { |
| 644 | 644 | assert(fn_di_scope != nullptr); |
| 645 | 645 | ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder, |
| 646 | 646 | fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "", |
| 647 | import->di_file, line_number, | |
| 647 | import->data.structure.root_struct->di_file, line_number, | |
| 648 | 648 | fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage, |
| 649 | 649 | is_definition, scope_line, flags, is_optimized, nullptr); |
| 650 | 650 | |
| ... | ... | @@ -658,7 +658,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { |
| 658 | 658 | assert(decls_scope->container_type); |
| 659 | 659 | scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type); |
| 660 | 660 | } else { |
| 661 | scope->di_scope = ZigLLVMFileToScope(import->di_file); | |
| 661 | scope->di_scope = ZigLLVMFileToScope(import->data.structure.root_struct->di_file); | |
| 662 | 662 | } |
| 663 | 663 | return scope->di_scope; |
| 664 | 664 | case ScopeIdBlock: |
| ... | ... | @@ -668,7 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { |
| 668 | 668 | assert(scope->parent); |
| 669 | 669 | ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder, |
| 670 | 670 | get_di_scope(g, scope->parent), |
| 671 | import->di_file, | |
| 671 | import->data.structure.root_struct->di_file, | |
| 672 | 672 | (unsigned)scope->source_node->line + 1, |
| 673 | 673 | (unsigned)scope->source_node->column + 1); |
| 674 | 674 | scope->di_scope = ZigLLVMLexicalBlockToScope(di_block); |
| ... | ... | @@ -2196,7 +2196,7 @@ var_ok: |
| 2196 | 2196 | if (dest_ty != nullptr && var->decl_node) { |
| 2197 | 2197 | // arg index + 1 because the 0 index is return value |
| 2198 | 2198 | var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), |
| 2199 | buf_ptr(&var->name), fn_walk->data.vars.import->di_file, | |
| 2199 | buf_ptr(&var->name), fn_walk->data.vars.import->data.structure.root_struct->di_file, | |
| 2200 | 2200 | (unsigned)(var->decl_node->line + 1), |
| 2201 | 2201 | dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1); |
| 2202 | 2202 | } |
| ... | ... | @@ -5800,7 +5800,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 5800 | 5800 | case ZigTypeIdNull: |
| 5801 | 5801 | case ZigTypeIdErrorUnion: |
| 5802 | 5802 | case ZigTypeIdErrorSet: |
| 5803 | case ZigTypeIdNamespace: | |
| 5804 | 5803 | case ZigTypeIdBoundFn: |
| 5805 | 5804 | case ZigTypeIdArgTuple: |
| 5806 | 5805 | case ZigTypeIdVoid: |
| ... | ... | @@ -6400,7 +6399,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c |
| 6400 | 6399 | case ZigTypeIdComptimeInt: |
| 6401 | 6400 | case ZigTypeIdUndefined: |
| 6402 | 6401 | case ZigTypeIdNull: |
| 6403 | case ZigTypeIdNamespace: | |
| 6404 | 6402 | case ZigTypeIdBoundFn: |
| 6405 | 6403 | case ZigTypeIdArgTuple: |
| 6406 | 6404 | case ZigTypeIdOpaque: |
| ... | ... | @@ -6506,12 +6504,12 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val, |
| 6506 | 6504 | assert(var->gen_is_const); |
| 6507 | 6505 | assert(type_entry); |
| 6508 | 6506 | |
| 6509 | ImportTableEntry *import = get_scope_import(var->parent_scope); | |
| 6507 | ZigType *import = get_scope_import(var->parent_scope); | |
| 6510 | 6508 | assert(import); |
| 6511 | 6509 | |
| 6512 | 6510 | bool is_local_to_unit = true; |
| 6513 | 6511 | ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name), |
| 6514 | buf_ptr(&var->name), import->di_file, | |
| 6512 | buf_ptr(&var->name), import->data.structure.root_struct->di_file, | |
| 6515 | 6513 | (unsigned)(var->decl_node->line + 1), |
| 6516 | 6514 | type_entry->di_type, is_local_to_unit); |
| 6517 | 6515 | |
| ... | ... | @@ -6767,7 +6765,7 @@ static void do_code_gen(CodeGen *g) { |
| 6767 | 6765 | *slot = build_alloca(g, slot_type, "", alignment_bytes); |
| 6768 | 6766 | } |
| 6769 | 6767 | |
| 6770 | ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base); | |
| 6768 | ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base); | |
| 6771 | 6769 | |
| 6772 | 6770 | unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0; |
| 6773 | 6771 | |
| ... | ... | @@ -6799,7 +6797,7 @@ static void do_code_gen(CodeGen *g) { |
| 6799 | 6797 | var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes); |
| 6800 | 6798 | |
| 6801 | 6799 | var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope), |
| 6802 | buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1), | |
| 6800 | buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1), | |
| 6803 | 6801 | var->var_type->di_type, !g->strip_debug_symbols, 0); |
| 6804 | 6802 | |
| 6805 | 6803 | } else if (is_c_abi) { |
| ... | ... | @@ -6823,7 +6821,7 @@ static void do_code_gen(CodeGen *g) { |
| 6823 | 6821 | } |
| 6824 | 6822 | if (var->decl_node) { |
| 6825 | 6823 | var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), |
| 6826 | buf_ptr(&var->name), import->di_file, | |
| 6824 | buf_ptr(&var->name), import->data.structure.root_struct->di_file, | |
| 6827 | 6825 | (unsigned)(var->decl_node->line + 1), |
| 6828 | 6826 | gen_type->di_type, !g->strip_debug_symbols, 0, (unsigned)(var->gen_arg_index + 1)); |
| 6829 | 6827 | } |
| ... | ... | @@ -6971,12 +6969,6 @@ static void define_builtin_types(CodeGen *g) { |
| 6971 | 6969 | entry->zero_bits = true; |
| 6972 | 6970 | g->builtin_types.entry_invalid = entry; |
| 6973 | 6971 | } |
| 6974 | { | |
| 6975 | ZigType *entry = new_type_table_entry(ZigTypeIdNamespace); | |
| 6976 | buf_init_from_str(&entry->name, "(namespace)"); | |
| 6977 | entry->zero_bits = true; | |
| 6978 | g->builtin_types.entry_namespace = entry; | |
| 6979 | } | |
| 6980 | 6972 | { |
| 6981 | 6973 | ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat); |
| 6982 | 6974 | buf_init_from_str(&entry->name, "comptime_float"); |
| ... | ... | @@ -7470,7 +7462,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { |
| 7470 | 7462 | " Enum: Enum,\n" |
| 7471 | 7463 | " Union: Union,\n" |
| 7472 | 7464 | " Fn: Fn,\n" |
| 7473 | " Namespace: void,\n" | |
| 7474 | 7465 | " BoundFn: Fn,\n" |
| 7475 | 7466 | " ArgTuple: void,\n" |
| 7476 | 7467 | " Opaque: void,\n" |
| ... | ... | @@ -7948,17 +7939,21 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 7948 | 7939 | Buf *src_dirname = buf_alloc(); |
| 7949 | 7940 | os_path_split(full_path, src_dirname, src_basename); |
| 7950 | 7941 | |
| 7951 | ImportTableEntry *import = allocate<ImportTableEntry>(1); | |
| 7952 | import->source_code = nullptr; | |
| 7953 | import->path = full_path; | |
| 7942 | Buf noextname = BUF_INIT; | |
| 7943 | os_path_extname(src_basename, &noextname, nullptr); | |
| 7944 | ||
| 7945 | RootStruct *root_struct = allocate<RootStruct>(1); | |
| 7946 | root_struct->source_code = nullptr; | |
| 7947 | root_struct->path = full_path; | |
| 7948 | root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | |
| 7949 | ||
| 7950 | ZigType *import = get_root_container_type(g, buf_ptr(&noextname), root_struct); | |
| 7954 | 7951 | g->root_import = import; |
| 7955 | import->decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, import); | |
| 7956 | 7952 | |
| 7957 | 7953 | detect_libc(g); |
| 7958 | 7954 | |
| 7959 | 7955 | init(g); |
| 7960 | 7956 | |
| 7961 | import->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); | |
| 7962 | 7957 | |
| 7963 | 7958 | ZigList<ErrorMsg *> errors = {0}; |
| 7964 | 7959 | Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr); |
| ... | ... | @@ -7977,7 +7972,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 7977 | 7972 | } |
| 7978 | 7973 | } |
| 7979 | 7974 | |
| 7980 | static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) { | |
| 7975 | static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *basename) { | |
| 7981 | 7976 | Buf *code_basename = buf_create_from_str(basename); |
| 7982 | 7977 | Buf path_to_code_src = BUF_INIT; |
| 7983 | 7978 | os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src); |
| ... | ... | @@ -7994,17 +7989,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package |
| 7994 | 7989 | return add_source_file(g, package, resolved_path, import_code); |
| 7995 | 7990 | } |
| 7996 | 7991 | |
| 7997 | static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) { | |
| 7998 | PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig"); | |
| 7992 | static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) { | |
| 7993 | ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig"); | |
| 7999 | 7994 | package->package_table.put(buf_create_from_str("@root"), pkg_with_main); |
| 8000 | 7995 | return package; |
| 8001 | 7996 | } |
| 8002 | 7997 | |
| 8003 | static PackageTableEntry *create_test_runner_pkg(CodeGen *g) { | |
| 7998 | static ZigPackage *create_test_runner_pkg(CodeGen *g) { | |
| 8004 | 7999 | return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig"); |
| 8005 | 8000 | } |
| 8006 | 8001 | |
| 8007 | static PackageTableEntry *create_panic_pkg(CodeGen *g) { | |
| 8002 | static ZigPackage *create_panic_pkg(CodeGen *g) { | |
| 8008 | 8003 | return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig"); |
| 8009 | 8004 | } |
| 8010 | 8005 | |
| ... | ... | @@ -8096,7 +8091,7 @@ static void gen_root_source(CodeGen *g) { |
| 8096 | 8091 | |
| 8097 | 8092 | { |
| 8098 | 8093 | // Zig has lazy top level definitions. Here we semantically analyze the panic function. |
| 8099 | ImportTableEntry *import_with_panic; | |
| 8094 | ZigType *import_with_panic; | |
| 8100 | 8095 | if (g->have_pub_panic) { |
| 8101 | 8096 | import_with_panic = g->root_import; |
| 8102 | 8097 | } else { |
| ... | ... | @@ -8104,9 +8099,9 @@ static void gen_root_source(CodeGen *g) { |
| 8104 | 8099 | import_with_panic = add_special_code(g, g->panic_package, "panic.zig"); |
| 8105 | 8100 | } |
| 8106 | 8101 | scan_import(g, import_with_panic); |
| 8107 | Tld *panic_tld = find_decl(g, &import_with_panic->decls_scope->base, buf_create_from_str("panic")); | |
| 8102 | Tld *panic_tld = find_decl(g, &get_container_scope(import_with_panic)->base, buf_create_from_str("panic")); | |
| 8108 | 8103 | assert(panic_tld != nullptr); |
| 8109 | resolve_top_level_decl(g, panic_tld, false, nullptr); | |
| 8104 | resolve_top_level_decl(g, panic_tld, nullptr); | |
| 8110 | 8105 | } |
| 8111 | 8106 | |
| 8112 | 8107 | |
| ... | ... | @@ -8341,7 +8336,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e |
| 8341 | 8336 | case ZigTypeIdComptimeInt: |
| 8342 | 8337 | case ZigTypeIdUndefined: |
| 8343 | 8338 | case ZigTypeIdNull: |
| 8344 | case ZigTypeIdNamespace: | |
| 8345 | 8339 | case ZigTypeIdBoundFn: |
| 8346 | 8340 | case ZigTypeIdArgTuple: |
| 8347 | 8341 | case ZigTypeIdErrorUnion: |
| ... | ... | @@ -8524,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu |
| 8524 | 8518 | case ZigTypeIdInvalid: |
| 8525 | 8519 | case ZigTypeIdMetaType: |
| 8526 | 8520 | case ZigTypeIdBoundFn: |
| 8527 | case ZigTypeIdNamespace: | |
| 8528 | 8521 | case ZigTypeIdComptimeFloat: |
| 8529 | 8522 | case ZigTypeIdComptimeInt: |
| 8530 | 8523 | case ZigTypeIdUndefined: |
| ... | ... | @@ -8676,7 +8669,6 @@ static void gen_h_file(CodeGen *g) { |
| 8676 | 8669 | case ZigTypeIdNull: |
| 8677 | 8670 | case ZigTypeIdErrorUnion: |
| 8678 | 8671 | case ZigTypeIdErrorSet: |
| 8679 | case ZigTypeIdNamespace: | |
| 8680 | 8672 | case ZigTypeIdBoundFn: |
| 8681 | 8673 | case ZigTypeIdArgTuple: |
| 8682 | 8674 | case ZigTypeIdOptional: |
| ... | ... | @@ -8775,7 +8767,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) { |
| 8775 | 8767 | g->timing_events.append({os_get_time(), name}); |
| 8776 | 8768 | } |
| 8777 | 8769 | |
| 8778 | static void add_cache_pkg(CodeGen *g, CacheHash *ch, PackageTableEntry *pkg) { | |
| 8770 | static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) { | |
| 8779 | 8771 | if (buf_len(&pkg->root_src_path) == 0) |
| 8780 | 8772 | return; |
| 8781 | 8773 | |
| ... | ... | @@ -9029,9 +9021,9 @@ void codegen_build_and_link(CodeGen *g) { |
| 9029 | 9021 | codegen_add_time_event(g, "Done"); |
| 9030 | 9022 | } |
| 9031 | 9023 | |
| 9032 | PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) { | |
| 9024 | ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) { | |
| 9033 | 9025 | init(g); |
| 9034 | PackageTableEntry *pkg = new_package(root_src_dir, root_src_path); | |
| 9026 | ZigPackage *pkg = new_package(root_src_dir, root_src_path); | |
| 9035 | 9027 | if (g->std_package != nullptr) { |
| 9036 | 9028 | assert(g->compile_var_package != nullptr); |
| 9037 | 9029 | pkg->package_table.put(buf_create_from_str("std"), g->std_package); |
src/codegen.hpp+1-1| ... | ... | @@ -48,7 +48,7 @@ void codegen_print_timing_report(CodeGen *g, FILE *f); |
| 48 | 48 | void codegen_link(CodeGen *g); |
| 49 | 49 | void codegen_build_and_link(CodeGen *g); |
| 50 | 50 | |
| 51 | PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path); | |
| 51 | ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path); | |
| 52 | 52 | void codegen_add_assembly(CodeGen *g, Buf *path); |
| 53 | 53 | void codegen_add_object(CodeGen *g, Buf *object_path); |
| 54 | 54 |
src/ir.cpp+34-84| ... | ... | @@ -258,7 +258,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) { |
| 258 | 258 | case ZigTypeIdPointer: |
| 259 | 259 | case ZigTypeIdUndefined: |
| 260 | 260 | case ZigTypeIdNull: |
| 261 | case ZigTypeIdNamespace: | |
| 262 | 261 | case ZigTypeIdBoundFn: |
| 263 | 262 | case ZigTypeIdErrorSet: |
| 264 | 263 | case ZigTypeIdOpaque: |
| ... | ... | @@ -1123,11 +1122,11 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * |
| 1123 | 1122 | return &const_instruction->base; |
| 1124 | 1123 | } |
| 1125 | 1124 | |
| 1126 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) { | |
| 1125 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) { | |
| 1127 | 1126 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1128 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace; | |
| 1127 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; | |
| 1129 | 1128 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1130 | const_instruction->base.value.data.x_import = import; | |
| 1129 | const_instruction->base.value.data.x_type = import; | |
| 1131 | 1130 | return &const_instruction->base; |
| 1132 | 1131 | } |
| 1133 | 1132 | |
| ... | ... | @@ -3824,7 +3823,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3824 | 3823 | if (tld) |
| 3825 | 3824 | return ir_build_decl_ref(irb, scope, node, tld, lval); |
| 3826 | 3825 | |
| 3827 | if (node->owner->any_imports_failed) { | |
| 3826 | if (get_container_scope(node->owner)->any_imports_failed) { | |
| 3828 | 3827 | // skip the error message since we had a failing import in this file |
| 3829 | 3828 | // if an import breaks we don't need redundant undeclared identifier errors |
| 3830 | 3829 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -6620,9 +6619,12 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 6620 | 6619 | buf_appendf(name, ")"); |
| 6621 | 6620 | return name; |
| 6622 | 6621 | } else { |
| 6623 | //Note: C-imports do not have valid location information | |
| 6622 | // Note: C-imports do not have valid location information | |
| 6623 | // TODO this will get fixed by https://github.com/ziglang/zig/issues/2015 | |
| 6624 | 6624 | return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name, |
| 6625 | (source_node->owner->path != nullptr) ? buf_ptr(source_node->owner->path) : "(null)", source_node->line + 1, source_node->column + 1); | |
| 6625 | (source_node->owner->data.structure.root_struct->path != nullptr) ? | |
| 6626 | buf_ptr(source_node->owner->data.structure.root_struct->path) : | |
| 6627 | "(null)", source_node->line + 1, source_node->column + 1); | |
| 6626 | 6628 | } |
| 6627 | 6629 | } |
| 6628 | 6630 | |
| ... | ... | @@ -12065,7 +12067,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 12065 | 12067 | case ZigTypeIdErrorSet: |
| 12066 | 12068 | case ZigTypeIdFn: |
| 12067 | 12069 | case ZigTypeIdOpaque: |
| 12068 | case ZigTypeIdNamespace: | |
| 12069 | 12070 | case ZigTypeIdBoundFn: |
| 12070 | 12071 | case ZigTypeIdArgTuple: |
| 12071 | 12072 | case ZigTypeIdPromise: |
| ... | ... | @@ -13407,7 +13408,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 13407 | 13408 | case ZigTypeIdOptional: |
| 13408 | 13409 | case ZigTypeIdErrorUnion: |
| 13409 | 13410 | case ZigTypeIdErrorSet: |
| 13410 | case ZigTypeIdNamespace: | |
| 13411 | 13411 | case ZigTypeIdBoundFn: |
| 13412 | 13412 | case ZigTypeIdArgTuple: |
| 13413 | 13413 | case ZigTypeIdOpaque: |
| ... | ... | @@ -13432,7 +13432,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 13432 | 13432 | case ZigTypeIdErrorSet: |
| 13433 | 13433 | case ZigTypeIdVector: |
| 13434 | 13434 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); |
| 13435 | case ZigTypeIdNamespace: | |
| 13436 | 13435 | case ZigTypeIdBoundFn: |
| 13437 | 13436 | case ZigTypeIdArgTuple: |
| 13438 | 13437 | case ZigTypeIdOpaque: |
| ... | ... | @@ -14616,7 +14615,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_ |
| 14616 | 14615 | case ZigTypeIdEnum: |
| 14617 | 14616 | case ZigTypeIdUnion: |
| 14618 | 14617 | case ZigTypeIdFn: |
| 14619 | case ZigTypeIdNamespace: | |
| 14620 | 14618 | case ZigTypeIdBoundFn: |
| 14621 | 14619 | case ZigTypeIdArgTuple: |
| 14622 | 14620 | case ZigTypeIdPromise: |
| ... | ... | @@ -15368,7 +15366,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 15368 | 15366 | auto entry = container_scope->decl_table.maybe_get(field_name); |
| 15369 | 15367 | Tld *tld = entry ? entry->value : nullptr; |
| 15370 | 15368 | if (tld && tld->id == TldIdFn) { |
| 15371 | resolve_top_level_decl(ira->codegen, tld, false, source_instr->source_node); | |
| 15369 | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node); | |
| 15372 | 15370 | if (tld->resolution == TldResolutionInvalid) |
| 15373 | 15371 | return ira->codegen->invalid_instruction; |
| 15374 | 15372 | TldFn *tld_fn = (TldFn *)tld; |
| ... | ... | @@ -15557,8 +15555,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 15557 | 15555 | |
| 15558 | 15556 | |
| 15559 | 15557 | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 15560 | bool pointer_only = false; | |
| 15561 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); | |
| 15558 | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node); | |
| 15562 | 15559 | if (tld->resolution == TldResolutionInvalid) |
| 15563 | 15560 | return ira->codegen->invalid_instruction; |
| 15564 | 15561 | |
| ... | ... | @@ -15971,37 +15968,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 15971 | 15968 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 15972 | 15969 | return ira->codegen->invalid_instruction; |
| 15973 | 15970 | } |
| 15974 | } else if (container_type->id == ZigTypeIdNamespace) { | |
| 15975 | assert(container_ptr->value.type->id == ZigTypeIdPointer); | |
| 15976 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); | |
| 15977 | if (!container_ptr_val) | |
| 15978 | return ira->codegen->invalid_instruction; | |
| 15979 | ||
| 15980 | ConstExprValue *namespace_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, | |
| 15981 | field_ptr_instruction->base.source_node); | |
| 15982 | if (namespace_val == nullptr) | |
| 15983 | return ira->codegen->invalid_instruction; | |
| 15984 | assert(namespace_val->special == ConstValSpecialStatic); | |
| 15985 | ||
| 15986 | ImportTableEntry *namespace_import = namespace_val->data.x_import; | |
| 15987 | ||
| 15988 | Tld *tld = find_decl(ira->codegen, &namespace_import->decls_scope->base, field_name); | |
| 15989 | if (tld) { | |
| 15990 | if (tld->visib_mod == VisibModPrivate && | |
| 15991 | tld->import != source_node->owner) | |
| 15992 | { | |
| 15993 | ErrorMsg *msg = ir_add_error_node(ira, source_node, | |
| 15994 | buf_sprintf("'%s' is private", buf_ptr(field_name))); | |
| 15995 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); | |
| 15996 | return ira->codegen->invalid_instruction; | |
| 15997 | } | |
| 15998 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); | |
| 15999 | } else { | |
| 16000 | const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)"; | |
| 16001 | ir_add_error_node(ira, source_node, | |
| 16002 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name)); | |
| 16003 | return ira->codegen->invalid_instruction; | |
| 16004 | } | |
| 16005 | 15971 | } else { |
| 16006 | 15972 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 16007 | 15973 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| ... | ... | @@ -16281,7 +16247,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 16281 | 16247 | case ZigTypeIdEnum: |
| 16282 | 16248 | case ZigTypeIdUnion: |
| 16283 | 16249 | case ZigTypeIdFn: |
| 16284 | case ZigTypeIdNamespace: | |
| 16285 | 16250 | case ZigTypeIdBoundFn: |
| 16286 | 16251 | case ZigTypeIdPromise: |
| 16287 | 16252 | case ZigTypeIdVector: |
| ... | ... | @@ -16402,7 +16367,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 16402 | 16367 | case ZigTypeIdEnum: |
| 16403 | 16368 | case ZigTypeIdUnion: |
| 16404 | 16369 | case ZigTypeIdFn: |
| 16405 | case ZigTypeIdNamespace: | |
| 16406 | 16370 | case ZigTypeIdBoundFn: |
| 16407 | 16371 | case ZigTypeIdPromise: |
| 16408 | 16372 | case ZigTypeIdVector: |
| ... | ... | @@ -16452,7 +16416,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 16452 | 16416 | case ZigTypeIdComptimeInt: |
| 16453 | 16417 | case ZigTypeIdBoundFn: |
| 16454 | 16418 | case ZigTypeIdMetaType: |
| 16455 | case ZigTypeIdNamespace: | |
| 16456 | 16419 | case ZigTypeIdArgTuple: |
| 16457 | 16420 | case ZigTypeIdOpaque: |
| 16458 | 16421 | ir_add_error_node(ira, size_of_instruction->base.source_node, |
| ... | ... | @@ -16860,7 +16823,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16860 | 16823 | case ZigTypeIdPointer: |
| 16861 | 16824 | case ZigTypeIdPromise: |
| 16862 | 16825 | case ZigTypeIdFn: |
| 16863 | case ZigTypeIdNamespace: | |
| 16864 | 16826 | case ZigTypeIdErrorSet: { |
| 16865 | 16827 | if (pointee_val) { |
| 16866 | 16828 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| ... | ... | @@ -17009,25 +16971,25 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 17009 | 16971 | return ira->codegen->invalid_instruction; |
| 17010 | 16972 | |
| 17011 | 16973 | AstNode *source_node = import_instruction->base.source_node; |
| 17012 | ImportTableEntry *import = source_node->owner; | |
| 16974 | ZigType *import = source_node->owner; | |
| 17013 | 16975 | |
| 17014 | 16976 | Buf *import_target_path; |
| 17015 | 16977 | Buf *search_dir; |
| 17016 | assert(import->package); | |
| 17017 | PackageTableEntry *target_package; | |
| 17018 | auto package_entry = import->package->package_table.maybe_get(import_target_str); | |
| 16978 | assert(import->data.structure.root_struct->package); | |
| 16979 | ZigPackage *target_package; | |
| 16980 | auto package_entry = import->data.structure.root_struct->package->package_table.maybe_get(import_target_str); | |
| 17019 | 16981 | if (package_entry) { |
| 17020 | 16982 | target_package = package_entry->value; |
| 17021 | 16983 | import_target_path = &target_package->root_src_path; |
| 17022 | 16984 | search_dir = &target_package->root_src_dir; |
| 17023 | 16985 | } else { |
| 17024 | 16986 | // try it as a filename |
| 17025 | target_package = import->package; | |
| 16987 | target_package = import->data.structure.root_struct->package; | |
| 17026 | 16988 | import_target_path = import_target_str; |
| 17027 | 16989 | |
| 17028 | 16990 | // search relative to importing file |
| 17029 | 16991 | search_dir = buf_alloc(); |
| 17030 | os_path_dirname(import->path, search_dir); | |
| 16992 | os_path_dirname(import->data.structure.root_struct->path, search_dir); | |
| 17031 | 16993 | } |
| 17032 | 16994 | |
| 17033 | 16995 | Buf full_path = BUF_INIT; |
| ... | ... | @@ -17041,10 +17003,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 17041 | 17003 | |
| 17042 | 17004 | auto import_entry = ira->codegen->import_table.maybe_get(resolved_path); |
| 17043 | 17005 | if (import_entry) { |
| 17044 | IrInstruction *result = ir_const(ira, &import_instruction->base, | |
| 17045 | ira->codegen->builtin_types.entry_namespace); | |
| 17046 | result->value.data.x_import = import_entry->value; | |
| 17047 | return result; | |
| 17006 | return ir_const_type(ira, &import_instruction->base, import_entry->value); | |
| 17048 | 17007 | } |
| 17049 | 17008 | |
| 17050 | 17009 | if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { |
| ... | ... | @@ -17059,13 +17018,11 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 17059 | 17018 | } |
| 17060 | 17019 | } |
| 17061 | 17020 | |
| 17062 | ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code); | |
| 17021 | ZigType *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code); | |
| 17063 | 17022 | |
| 17064 | 17023 | scan_import(ira->codegen, target_import); |
| 17065 | 17024 | |
| 17066 | IrInstruction *result = ir_const(ira, &import_instruction->base, ira->codegen->builtin_types.entry_namespace); | |
| 17067 | result->value.data.x_import = target_import; | |
| 17068 | return result; | |
| 17025 | return ir_const_type(ira, &import_instruction->base, target_import); | |
| 17069 | 17026 | } |
| 17070 | 17027 | |
| 17071 | 17028 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| ... | ... | @@ -17741,7 +17698,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17741 | 17698 | while ((curr_entry = decl_it.next()) != nullptr) { |
| 17742 | 17699 | // If the definition is unresolved, force it to be resolved again. |
| 17743 | 17700 | if (curr_entry->value->resolution == TldResolutionUnresolved) { |
| 17744 | resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node); | |
| 17701 | resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node); | |
| 17745 | 17702 | if (curr_entry->value->resolution != TldResolutionOk) { |
| 17746 | 17703 | return ErrorSemanticAnalyzeFail; |
| 17747 | 17704 | } |
| ... | ... | @@ -18056,7 +18013,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy |
| 18056 | 18013 | case ZigTypeIdComptimeInt: |
| 18057 | 18014 | case ZigTypeIdUndefined: |
| 18058 | 18015 | case ZigTypeIdNull: |
| 18059 | case ZigTypeIdNamespace: | |
| 18060 | 18016 | case ZigTypeIdArgTuple: |
| 18061 | 18017 | case ZigTypeIdOpaque: |
| 18062 | 18018 | *out = nullptr; |
| ... | ... | @@ -18702,14 +18658,14 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 18702 | 18658 | if (type_is_invalid(cimport_result->type)) |
| 18703 | 18659 | return ira->codegen->invalid_instruction; |
| 18704 | 18660 | |
| 18705 | ImportTableEntry *child_import = allocate<ImportTableEntry>(1); | |
| 18706 | child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import); | |
| 18707 | child_import->c_import_node = node; | |
| 18708 | child_import->package = new_anonymous_package(); | |
| 18709 | child_import->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package); | |
| 18710 | child_import->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package); | |
| 18711 | child_import->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder, | |
| 18661 | RootStruct *root_struct = allocate<RootStruct>(1); | |
| 18662 | root_struct->package = new_anonymous_package(); | |
| 18663 | root_struct->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package); | |
| 18664 | root_struct->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package); | |
| 18665 | root_struct->c_import_node = node; | |
| 18666 | root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder, | |
| 18712 | 18667 | buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str("."))); |
| 18668 | ZigType *child_import = get_root_container_type(ira->codegen, "cimport", root_struct); | |
| 18713 | 18669 | |
| 18714 | 18670 | ZigList<ErrorMsg *> errors = {0}; |
| 18715 | 18671 | |
| ... | ... | @@ -18738,14 +18694,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 18738 | 18694 | if (ira->codegen->verbose_cimport) { |
| 18739 | 18695 | fprintf(stderr, "\nC imports:\n"); |
| 18740 | 18696 | fprintf(stderr, "-----------\n"); |
| 18741 | ast_render(ira->codegen, stderr, child_import->root, 4); | |
| 18697 | ast_render(ira->codegen, stderr, child_import->data.structure.decl_node, 4); | |
| 18742 | 18698 | } |
| 18743 | 18699 | |
| 18744 | scan_decls(ira->codegen, child_import->decls_scope, child_import->root); | |
| 18700 | scan_decls(ira->codegen, get_container_scope(child_import), child_import->data.structure.decl_node); | |
| 18745 | 18701 | |
| 18746 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_namespace); | |
| 18747 | result->value.data.x_import = child_import; | |
| 18748 | return result; | |
| 18702 | return ir_const_type(ira, &instruction->base, child_import); | |
| 18749 | 18703 | } |
| 18750 | 18704 | |
| 18751 | 18705 | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| ... | ... | @@ -18819,10 +18773,10 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 18819 | 18773 | if (!rel_file_path) |
| 18820 | 18774 | return ira->codegen->invalid_instruction; |
| 18821 | 18775 | |
| 18822 | ImportTableEntry *import = get_scope_import(instruction->base.scope); | |
| 18776 | ZigType *import = get_scope_import(instruction->base.scope); | |
| 18823 | 18777 | // figure out absolute path to resource |
| 18824 | 18778 | Buf source_dir_path = BUF_INIT; |
| 18825 | os_path_dirname(import->path, &source_dir_path); | |
| 18779 | os_path_dirname(import->data.structure.root_struct->path, &source_dir_path); | |
| 18826 | 18780 | |
| 18827 | 18781 | Buf *resolve_paths[] = { |
| 18828 | 18782 | &source_dir_path, |
| ... | ... | @@ -20179,7 +20133,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 20179 | 20133 | case ZigTypeIdComptimeInt: |
| 20180 | 20134 | case ZigTypeIdUndefined: |
| 20181 | 20135 | case ZigTypeIdNull: |
| 20182 | case ZigTypeIdNamespace: | |
| 20183 | 20136 | case ZigTypeIdBoundFn: |
| 20184 | 20137 | case ZigTypeIdArgTuple: |
| 20185 | 20138 | case ZigTypeIdVoid: |
| ... | ... | @@ -21025,7 +20978,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 21025 | 20978 | case ZigTypeIdOpaque: |
| 21026 | 20979 | case ZigTypeIdBoundFn: |
| 21027 | 20980 | case ZigTypeIdArgTuple: |
| 21028 | case ZigTypeIdNamespace: | |
| 21029 | 20981 | case ZigTypeIdUnreachable: |
| 21030 | 20982 | case ZigTypeIdComptimeFloat: |
| 21031 | 20983 | case ZigTypeIdComptimeInt: |
| ... | ... | @@ -21185,7 +21137,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 21185 | 21137 | case ZigTypeIdOpaque: |
| 21186 | 21138 | case ZigTypeIdBoundFn: |
| 21187 | 21139 | case ZigTypeIdArgTuple: |
| 21188 | case ZigTypeIdNamespace: | |
| 21189 | 21140 | case ZigTypeIdUnreachable: |
| 21190 | 21141 | case ZigTypeIdComptimeFloat: |
| 21191 | 21142 | case ZigTypeIdComptimeInt: |
| ... | ... | @@ -21343,7 +21294,6 @@ static bool type_can_bit_cast(ZigType *t) { |
| 21343 | 21294 | case ZigTypeIdOpaque: |
| 21344 | 21295 | case ZigTypeIdBoundFn: |
| 21345 | 21296 | case ZigTypeIdArgTuple: |
| 21346 | case ZigTypeIdNamespace: | |
| 21347 | 21297 | case ZigTypeIdUnreachable: |
| 21348 | 21298 | case ZigTypeIdComptimeFloat: |
| 21349 | 21299 | case ZigTypeIdComptimeInt: |
| ... | ... | @@ -21516,7 +21466,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 21516 | 21466 | Tld *tld = instruction->tld; |
| 21517 | 21467 | LVal lval = instruction->lval; |
| 21518 | 21468 | |
| 21519 | resolve_top_level_decl(ira->codegen, tld, lval == LValPtr, instruction->base.source_node); | |
| 21469 | resolve_top_level_decl(ira->codegen, tld, instruction->base.source_node); | |
| 21520 | 21470 | if (tld->resolution == TldResolutionInvalid) |
| 21521 | 21471 | return ira->codegen->invalid_instruction; |
| 21522 | 21472 |
src/main.cpp+5-5| ... | ... | @@ -215,7 +215,7 @@ struct CliPkg { |
| 215 | 215 | CliPkg *parent; |
| 216 | 216 | }; |
| 217 | 217 | |
| 218 | static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { | |
| 218 | static void add_package(CodeGen *g, CliPkg *cli_pkg, ZigPackage *pkg) { | |
| 219 | 219 | for (size_t i = 0; i < cli_pkg->children.length; i += 1) { |
| 220 | 220 | CliPkg *child_cli_pkg = cli_pkg->children.at(i); |
| 221 | 221 | |
| ... | ... | @@ -223,10 +223,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { |
| 223 | 223 | Buf *basename = buf_alloc(); |
| 224 | 224 | os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename); |
| 225 | 225 | |
| 226 | PackageTableEntry *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename)); | |
| 226 | ZigPackage *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename)); | |
| 227 | 227 | auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg); |
| 228 | 228 | if (entry) { |
| 229 | PackageTableEntry *existing_pkg = entry->value; | |
| 229 | ZigPackage *existing_pkg = entry->value; | |
| 230 | 230 | Buf *full_path = buf_alloc(); |
| 231 | 231 | os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path); |
| 232 | 232 | fprintf(stderr, "Unable to add package '%s'->'%s': already exists as '%s'\n", |
| ... | ... | @@ -543,7 +543,7 @@ int main(int argc, char **argv) { |
| 543 | 543 | return EXIT_FAILURE; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname), | |
| 546 | ZigPackage *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname), | |
| 547 | 547 | buf_ptr(&build_file_basename)); |
| 548 | 548 | g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg); |
| 549 | 549 | g->enable_cache = get_cache_opt(enable_cache, true); |
| ... | ... | @@ -1145,7 +1145,7 @@ int main(int argc, char **argv) { |
| 1145 | 1145 | } |
| 1146 | 1146 | } else if (cmd == CmdTranslateC) { |
| 1147 | 1147 | codegen_translate_c(g, in_file_buf); |
| 1148 | ast_render(g, stdout, g->root_import->root, 4); | |
| 1148 | ast_render(g, stdout, g->root_import->data.structure.decl_node, 4); | |
| 1149 | 1149 | if (timing_info) |
| 1150 | 1150 | codegen_print_timing_report(g, stdout); |
| 1151 | 1151 | return EXIT_SUCCESS; |
src/parser.cpp+10-8| ... | ... | @@ -18,7 +18,7 @@ struct ParseContext { |
| 18 | 18 | Buf *buf; |
| 19 | 19 | size_t current_token; |
| 20 | 20 | ZigList<Token> *tokens; |
| 21 | ImportTableEntry *owner; | |
| 21 | ZigType *owner; | |
| 22 | 22 | ErrColor err_color; |
| 23 | 23 | }; |
| 24 | 24 | |
| ... | ... | @@ -130,8 +130,10 @@ static void ast_error(ParseContext *pc, Token *token, const char *format, ...) { |
| 130 | 130 | va_end(ap); |
| 131 | 131 | |
| 132 | 132 | |
| 133 | ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column, | |
| 134 | pc->owner->source_code, pc->owner->line_offsets, msg); | |
| 133 | ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path, | |
| 134 | token->start_line, token->start_column, | |
| 135 | pc->owner->data.structure.root_struct->source_code, | |
| 136 | pc->owner->data.structure.root_struct->line_offsets, msg); | |
| 135 | 137 | err->line_start = token->start_line; |
| 136 | 138 | err->column_start = token->start_column; |
| 137 | 139 | |
| ... | ... | @@ -148,8 +150,10 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const |
| 148 | 150 | Buf *msg = buf_vprintf(format, ap); |
| 149 | 151 | va_end(ap); |
| 150 | 152 | |
| 151 | ErrorMsg *err = err_msg_create_with_line(pc->owner->path, node->line, node->column, | |
| 152 | pc->owner->source_code, pc->owner->line_offsets, msg); | |
| 153 | ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path, | |
| 154 | node->line, node->column, | |
| 155 | pc->owner->data.structure.root_struct->source_code, | |
| 156 | pc->owner->data.structure.root_struct->line_offsets, msg); | |
| 153 | 157 | |
| 154 | 158 | print_err_msg(err, pc->err_color); |
| 155 | 159 | exit(EXIT_FAILURE); |
| ... | ... | @@ -570,9 +574,7 @@ static void ast_parse_asm_template(ParseContext *pc, AstNode *node) { |
| 570 | 574 | } |
| 571 | 575 | } |
| 572 | 576 | |
| 573 | AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, | |
| 574 | ErrColor err_color) | |
| 575 | { | |
| 577 | AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color) { | |
| 576 | 578 | ParseContext pc = {}; |
| 577 | 579 | pc.err_color = err_color; |
| 578 | 580 | pc.owner = owner; |
src/parser.hpp+1-1| ... | ... | @@ -16,7 +16,7 @@ ATTRIBUTE_PRINTF(2, 3) |
| 16 | 16 | void ast_token_error(Token *token, const char *format, ...); |
| 17 | 17 | |
| 18 | 18 | |
| 19 | AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color); | |
| 19 | AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color); | |
| 20 | 20 | |
| 21 | 21 | void ast_print(AstNode *node, int indent); |
| 22 | 22 |
src/translate_c.cpp+5-4| ... | ... | @@ -76,7 +76,7 @@ struct TransScopeWhile { |
| 76 | 76 | }; |
| 77 | 77 | |
| 78 | 78 | struct Context { |
| 79 | ImportTableEntry *import; | |
| 79 | ZigType *import; | |
| 80 | 80 | ZigList<ErrorMsg *> *errors; |
| 81 | 81 | VisibMod visib_mod; |
| 82 | 82 | bool want_export; |
| ... | ... | @@ -4732,7 +4732,7 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) { |
| 4732 | 4732 | } |
| 4733 | 4733 | } |
| 4734 | 4734 | |
| 4735 | Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 4735 | Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 4736 | 4736 | CodeGen *codegen, AstNode *source_node) |
| 4737 | 4737 | { |
| 4738 | 4738 | Error err; |
| ... | ... | @@ -4748,7 +4748,7 @@ Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *so |
| 4748 | 4748 | return err; |
| 4749 | 4749 | } |
| 4750 | 4750 | |
| 4751 | Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 4751 | Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 4752 | 4752 | CodeGen *codegen, AstNode *source_node) |
| 4753 | 4753 | { |
| 4754 | 4754 | Context context = {0}; |
| ... | ... | @@ -4958,7 +4958,8 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const |
| 4958 | 4958 | render_macros(c); |
| 4959 | 4959 | render_aliases(c); |
| 4960 | 4960 | |
| 4961 | import->root = c->root; | |
| 4961 | import->data.structure.decl_node = c->root; | |
| 4962 | import->data.structure.decls_scope->base.source_node = c->root; | |
| 4962 | 4963 | |
| 4963 | 4964 | return ErrorNone; |
| 4964 | 4965 | } |
src/translate_c.hpp+2-2| ... | ... | @@ -11,10 +11,10 @@ |
| 11 | 11 | |
| 12 | 12 | #include "all_types.hpp" |
| 13 | 13 | |
| 14 | Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 14 | Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 15 | 15 | CodeGen *codegen, AstNode *source_node); |
| 16 | 16 | |
| 17 | Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 17 | Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 18 | 18 | CodeGen *codegen, AstNode *source_node); |
| 19 | 19 | |
| 20 | 20 | #endif |
std/hash_map.zig-2| ... | ... | @@ -486,7 +486,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type |
| 486 | 486 | builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng), |
| 487 | 487 | builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng), |
| 488 | 488 | |
| 489 | builtin.TypeId.Namespace, | |
| 490 | 489 | builtin.TypeId.BoundFn, |
| 491 | 490 | builtin.TypeId.ComptimeFloat, |
| 492 | 491 | builtin.TypeId.ComptimeInt, |
| ... | ... | @@ -532,7 +531,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool { |
| 532 | 531 | builtin.TypeId.Float, |
| 533 | 532 | builtin.TypeId.ComptimeFloat, |
| 534 | 533 | builtin.TypeId.ComptimeInt, |
| 535 | builtin.TypeId.Namespace, | |
| 536 | 534 | builtin.TypeId.Promise, |
| 537 | 535 | builtin.TypeId.Enum, |
| 538 | 536 | builtin.TypeId.BoundFn, |
std/testing.zig-1| ... | ... | @@ -44,7 +44,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 44 | 44 | TypeId.ComptimeFloat, |
| 45 | 45 | TypeId.ComptimeInt, |
| 46 | 46 | TypeId.Enum, |
| 47 | TypeId.Namespace, | |
| 48 | 47 | TypeId.Fn, |
| 49 | 48 | TypeId.Promise, |
| 50 | 49 | TypeId.Vector, |
test/compile_errors.zig+41-41| ... | ... | @@ -2,6 +2,47 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | |
| 6 | "@typeInfo causing depend on itself compile error", | |
| 7 | \\const start = struct { | |
| 8 | \\ fn crash() bug() { | |
| 9 | \\ return bug; | |
| 10 | \\ } | |
| 11 | \\}; | |
| 12 | \\fn bug() void { | |
| 13 | \\ _ = @typeInfo(start).Struct; | |
| 14 | \\} | |
| 15 | \\export fn entry() void { | |
| 16 | \\ var boom = start.crash(); | |
| 17 | \\} | |
| 18 | , | |
| 19 | ".tmp_source.zig:2:5: error: 'crash' depends on itself", | |
| 20 | ); | |
| 21 | ||
| 22 | cases.add( | |
| 23 | "enum field value references enum", | |
| 24 | \\pub const Foo = extern enum { | |
| 25 | \\ A = Foo.B, | |
| 26 | \\ C = D, | |
| 27 | \\}; | |
| 28 | \\export fn entry() void { | |
| 29 | \\ var s: Foo = Foo.E; | |
| 30 | \\} | |
| 31 | , | |
| 32 | ".tmp_source.zig:1:17: error: 'Foo' depends on itself", | |
| 33 | ); | |
| 34 | ||
| 35 | cases.add( | |
| 36 | "top level decl dependency loop", | |
| 37 | \\const a : @typeOf(b) = 0; | |
| 38 | \\const b : @typeOf(a) = 0; | |
| 39 | \\export fn entry() void { | |
| 40 | \\ const c = a + b; | |
| 41 | \\} | |
| 42 | , | |
| 43 | ".tmp_source.zig:1:1: error: 'a' depends on itself", | |
| 44 | ); | |
| 45 | ||
| 5 | 46 | cases.addTest( |
| 6 | 47 | "not an enum type", |
| 7 | 48 | \\export fn entry() void { |
| ... | ... | @@ -917,23 +958,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 917 | 958 | ".tmp_source.zig:1:1: error: non-extern function has no body", |
| 918 | 959 | ); |
| 919 | 960 | |
| 920 | cases.add( | |
| 921 | "@typeInfo causing depend on itself compile error", | |
| 922 | \\const start = struct { | |
| 923 | \\ fn crash() bug() { | |
| 924 | \\ return bug; | |
| 925 | \\ } | |
| 926 | \\}; | |
| 927 | \\fn bug() void { | |
| 928 | \\ _ = @typeInfo(start).Struct; | |
| 929 | \\} | |
| 930 | \\export fn entry() void { | |
| 931 | \\ var boom = start.crash(); | |
| 932 | \\} | |
| 933 | , | |
| 934 | ".tmp_source.zig:2:5: error: 'crash' depends on itself", | |
| 935 | ); | |
| 936 | ||
| 937 | 961 | cases.add( |
| 938 | 962 | "@handle() called outside of function definition", |
| 939 | 963 | \\var handle_undef: promise = undefined; |
| ... | ... | @@ -1182,19 +1206,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1182 | 1206 | break :x tc; |
| 1183 | 1207 | }); |
| 1184 | 1208 | |
| 1185 | cases.add( | |
| 1186 | "enum field value references enum", | |
| 1187 | \\pub const Foo = extern enum { | |
| 1188 | \\ A = Foo.B, | |
| 1189 | \\ C = D, | |
| 1190 | \\}; | |
| 1191 | \\export fn entry() void { | |
| 1192 | \\ var s: Foo = Foo.E; | |
| 1193 | \\} | |
| 1194 | , | |
| 1195 | ".tmp_source.zig:1:17: error: 'Foo' depends on itself", | |
| 1196 | ); | |
| 1197 | ||
| 1198 | 1209 | cases.add( |
| 1199 | 1210 | "@floatToInt comptime safety", |
| 1200 | 1211 | \\comptime { |
| ... | ... | @@ -2622,17 +2633,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2622 | 2633 | ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'", |
| 2623 | 2634 | ); |
| 2624 | 2635 | |
| 2625 | cases.add( | |
| 2626 | "top level decl dependency loop", | |
| 2627 | \\const a : @typeOf(b) = 0; | |
| 2628 | \\const b : @typeOf(a) = 0; | |
| 2629 | \\export fn entry() void { | |
| 2630 | \\ const c = a + b; | |
| 2631 | \\} | |
| 2632 | , | |
| 2633 | ".tmp_source.zig:1:1: error: 'a' depends on itself", | |
| 2634 | ); | |
| 2635 | ||
| 2636 | 2636 | cases.add( |
| 2637 | 2637 | "noalias on non pointer param", |
| 2638 | 2638 | \\fn f(noalias x: i32) void {} |
test/stage1/behavior/misc.zig+1-1| ... | ... | @@ -469,7 +469,7 @@ test "@typeId" { |
| 469 | 469 | expect(@typeId(AUnionEnum) == Tid.Union); |
| 470 | 470 | expect(@typeId(AUnion) == Tid.Union); |
| 471 | 471 | expect(@typeId(fn () void) == Tid.Fn); |
| 472 | expect(@typeId(@typeOf(builtin)) == Tid.Namespace); | |
| 472 | expect(@typeId(@typeOf(builtin)) == Tid.Type); | |
| 473 | 473 | // TODO bound fn |
| 474 | 474 | // TODO arg tuple |
| 475 | 475 | // TODO opaque |
test/stage1/behavior/type_info.zig+1-1| ... | ... | @@ -186,7 +186,7 @@ fn testUnion() void { |
| 186 | 186 | expect(TypeId(typeinfo_info) == TypeId.Union); |
| 187 | 187 | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 188 | 188 | expect(typeinfo_info.Union.tag_type.? == TypeId); |
| 189 | expect(typeinfo_info.Union.fields.len == 25); | |
| 189 | expect(typeinfo_info.Union.fields.len == 24); | |
| 190 | 190 | expect(typeinfo_info.Union.fields[4].enum_field != null); |
| 191 | 191 | expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); |
| 192 | 192 | expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); |