authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-28 10:11:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-28 10:11:32-05:00
log5424b4320def194b205dcfe8e937035d2d80ae09
tree033c9534190356feefa34ac7649f729202beac89
parentd093f51f16ab9fe4f119a47c80c59d99a90a590f
signaturelock-open Commit is signed but in an unrecognized format.

remove namespace type; files are empty structs

closes #1047

18 files changed, 329 insertions(+), 411 deletions(-)

doc/langref.html.in+14-11
...@@ -6785,7 +6785,6 @@ pub const TypeId = enum {...@@ -6785,7 +6785,6 @@ pub const TypeId = enum {
6785 Enum,6785 Enum,
6786 Union,6786 Union,
6787 Fn,6787 Fn,
6788 Namespace,
6789 Block,6788 Block,
6790 BoundFn,6789 BoundFn,
6791 ArgTuple,6790 ArgTuple,
...@@ -6820,7 +6819,6 @@ pub const TypeInfo = union(TypeId) {...@@ -6820,7 +6819,6 @@ pub const TypeInfo = union(TypeId) {
6820 Enum: Enum,6819 Enum: Enum,
6821 Union: Union,6820 Union: Union,
6822 Fn: Fn,6821 Fn: Fn,
6823 Namespace: void,
6824 BoundFn: Fn,6822 BoundFn: Fn,
6825 ArgTuple: void,6823 ArgTuple: void,
6826 Opaque: void,6824 Opaque: void,
...@@ -8167,17 +8165,18 @@ coding style....@@ -8167,17 +8165,18 @@ coding style.
8167 </p>8165 </p>
8168 <ul>8166 <ul>
8169 <li>8167 <li>
8170 If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} (or an alias of a {#syntax#}struct{#endsyntax#}),8168 If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#}
8171 then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#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 </li>8172 </li>
8173 <li>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 </li>8176 </li>
8176 <li>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 If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should
8178 </li>8179 be {#syntax#}camelCase{#endsyntax#}.
8179 <li>
8180 If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should be {#syntax#}camelCase{#endsyntax#}.
8181 </li>8180 </li>
8182 <li>8181 <li>
8183 Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}.8182 Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}.
...@@ -8203,7 +8202,9 @@ const const_name = 42;...@@ -8203,7 +8202,9 @@ const const_name = 42;
8203const primitive_type_alias = f32;8202const primitive_type_alias = f32;
8204const string_alias = []u8;8203const string_alias = []u8;
82058204
8206const StructName = struct {};8205const StructName = struct {
8206 field: i32,
8207};
8207const StructAlias = StructName;8208const StructAlias = StructName;
82088209
8209fn functionName(param_name: TypeName) void {8210fn functionName(param_name: TypeName) void {
...@@ -8231,7 +8232,9 @@ const xml_document =...@@ -8231,7 +8232,9 @@ const xml_document =
8231 \\<document>8232 \\<document>
8232 \\</document>8233 \\</document>
8233;8234;
8234const XmlParser = struct {};8235const XmlParser = struct {
8236 field: i32,
8237};
82358238
8236// The initials BE (Big Endian) are just another word in Zig identifier names.8239// The initials BE (Big Endian) are just another word in Zig identifier names.
8237fn readU32Be() u32 {}8240fn readU32Be() u32 {}
src-self-hosted/type.zig-12
...@@ -39,7 +39,6 @@ pub const Type = struct {...@@ -39,7 +39,6 @@ pub const Type = struct {
39 Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp),39 Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp),
40 Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),40 Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
41 Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp),41 Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp),
42 Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp),
43 Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),42 Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
44 Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),43 Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
45 Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),44 Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
...@@ -73,7 +72,6 @@ pub const Type = struct {...@@ -73,7 +72,6 @@ pub const Type = struct {
73 Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context),72 Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context),
74 Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),73 Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
75 Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),74 Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
76 Id.Namespace => unreachable,
77 Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),75 Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
78 Id.ArgTuple => unreachable,76 Id.ArgTuple => unreachable,
79 Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),77 Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
...@@ -89,7 +87,6 @@ pub const Type = struct {...@@ -89,7 +87,6 @@ pub const Type = struct {
89 Id.ComptimeInt,87 Id.ComptimeInt,
90 Id.Undefined,88 Id.Undefined,
91 Id.Null,89 Id.Null,
92 Id.Namespace,
93 Id.BoundFn,90 Id.BoundFn,
94 Id.ArgTuple,91 Id.ArgTuple,
95 Id.Opaque,92 Id.Opaque,
...@@ -123,7 +120,6 @@ pub const Type = struct {...@@ -123,7 +120,6 @@ pub const Type = struct {
123 Id.ComptimeInt,120 Id.ComptimeInt,
124 Id.Undefined,121 Id.Undefined,
125 Id.Null,122 Id.Null,
126 Id.Namespace,
127 Id.BoundFn,123 Id.BoundFn,
128 Id.ArgTuple,124 Id.ArgTuple,
129 Id.Opaque,125 Id.Opaque,
...@@ -1020,14 +1016,6 @@ pub const Type = struct {...@@ -1020,14 +1016,6 @@ pub const Type = struct {
1020 }1016 }
1021 };1017 };
10221018
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 pub const BoundFn = struct {1019 pub const BoundFn = struct {
1032 base: Type,1020 base: Type,
10331021
src/all_types.hpp+40-44
...@@ -21,7 +21,6 @@...@@ -21,7 +21,6 @@
21#include "libc_installation.hpp"21#include "libc_installation.hpp"
2222
23struct AstNode;23struct AstNode;
24struct ImportTableEntry;
25struct ZigFn;24struct ZigFn;
26struct Scope;25struct Scope;
27struct ScopeBlock;26struct ScopeBlock;
...@@ -317,7 +316,6 @@ struct ConstExprValue {...@@ -317,7 +316,6 @@ struct ConstExprValue {
317 ConstUnionValue x_union;316 ConstUnionValue x_union;
318 ConstArrayValue x_array;317 ConstArrayValue x_array;
319 ConstPtrValue x_ptr;318 ConstPtrValue x_ptr;
320 ImportTableEntry *x_import;
321 ConstArgTuple x_arg_tuple;319 ConstArgTuple x_arg_tuple;
322320
323 // populated if special == ConstValSpecialRuntime321 // populated if special == ConstValSpecialRuntime
...@@ -369,7 +367,7 @@ struct Tld {...@@ -369,7 +367,7 @@ struct Tld {
369 VisibMod visib_mod;367 VisibMod visib_mod;
370 AstNode *source_node;368 AstNode *source_node;
371369
372 ImportTableEntry *import;370 ZigType *import;
373 Scope *parent_scope;371 Scope *parent_scope;
374 // set this flag temporarily to detect infinite loops372 // set this flag temporarily to detect infinite loops
375 bool dep_loop_flag;373 bool dep_loop_flag;
...@@ -937,7 +935,7 @@ struct AstNode {...@@ -937,7 +935,7 @@ struct AstNode {
937 enum NodeType type;935 enum NodeType type;
938 size_t line;936 size_t line;
939 size_t column;937 size_t column;
940 ImportTableEntry *owner;938 ZigType *owner;
941 union {939 union {
942 AstNodeFnDef fn_def;940 AstNodeFnDef fn_def;
943 AstNodeFnProto fn_proto;941 AstNodeFnProto fn_proto;
...@@ -1075,12 +1073,32 @@ enum ResolveStatus {...@@ -1075,12 +1073,32 @@ enum ResolveStatus {
1075 ResolveStatusSizeKnown,1073 ResolveStatusSizeKnown,
1076};1074};
10771075
1076struct 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
1085struct 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
1078struct ZigTypeStruct {1095struct ZigTypeStruct {
1079 AstNode *decl_node;1096 AstNode *decl_node;
1080 TypeStructField *fields;1097 TypeStructField *fields;
1081 ScopeDecls *decls_scope;1098 ScopeDecls *decls_scope;
1082 uint64_t size_bytes;1099 uint64_t size_bytes;
1083 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;1100 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
1101 RootStruct *root_struct;
10841102
1085 uint32_t src_field_count;1103 uint32_t src_field_count;
1086 uint32_t gen_field_count;1104 uint32_t gen_field_count;
...@@ -1232,7 +1250,6 @@ enum ZigTypeId {...@@ -1232,7 +1250,6 @@ enum ZigTypeId {
1232 ZigTypeIdEnum,1250 ZigTypeIdEnum,
1233 ZigTypeIdUnion,1251 ZigTypeIdUnion,
1234 ZigTypeIdFn,1252 ZigTypeIdFn,
1235 ZigTypeIdNamespace,
1236 ZigTypeIdBoundFn,1253 ZigTypeIdBoundFn,
1237 ZigTypeIdArgTuple,1254 ZigTypeIdArgTuple,
1238 ZigTypeIdOpaque,1255 ZigTypeIdOpaque,
...@@ -1285,29 +1302,6 @@ struct ZigType {...@@ -1285,29 +1302,6 @@ struct ZigType {
1285 bool gen_h_loop_flag;1302 bool gen_h_loop_flag;
1286};1303};
12871304
1288struct 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
1296struct 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
1311enum FnAnalState {1305enum FnAnalState {
1312 FnAnalStateReady,1306 FnAnalStateReady,
1313 FnAnalStateProbing,1307 FnAnalStateProbing,
...@@ -1670,7 +1664,7 @@ struct CodeGen {...@@ -1670,7 +1664,7 @@ struct CodeGen {
1670 LLVMValueRef return_err_fn;1664 LLVMValueRef return_err_fn;
16711665
1672 // reminder: hash tables must be initialized before use1666 // 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 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;1668 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
1675 HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;1669 HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
1676 HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;1670 HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
...@@ -1684,7 +1678,7 @@ struct CodeGen {...@@ -1684,7 +1678,7 @@ struct CodeGen {
1684 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;1678 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
1685 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;1679 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
16861680
1687 ZigList<ImportTableEntry *> import_queue;1681 ZigList<ZigType *> import_queue;
1688 size_t import_queue_index;1682 size_t import_queue_index;
1689 ZigList<Tld *> resolve_queue;1683 ZigList<Tld *> resolve_queue;
1690 size_t resolve_queue_index;1684 size_t resolve_queue_index;
...@@ -1699,14 +1693,14 @@ struct CodeGen {...@@ -1699,14 +1693,14 @@ struct CodeGen {
1699 ZigList<ErrorTableEntry *> errors_by_index;1693 ZigList<ErrorTableEntry *> errors_by_index;
1700 size_t largest_err_name_len;1694 size_t largest_err_name_len;
17011695
1702 PackageTableEntry *std_package;1696 ZigPackage *std_package;
1703 PackageTableEntry *panic_package;1697 ZigPackage *panic_package;
1704 PackageTableEntry *test_runner_package;1698 ZigPackage *test_runner_package;
1705 PackageTableEntry *compile_var_package;1699 ZigPackage *compile_var_package;
1706 ImportTableEntry *compile_var_import;1700 ZigType *compile_var_import;
1707 ImportTableEntry *root_import;1701 ZigType *root_import;
1708 ImportTableEntry *bootstrap_import;1702 ZigType *bootstrap_import;
1709 ImportTableEntry *test_runner_import;1703 ZigType *test_runner_import;
17101704
1711 struct {1705 struct {
1712 ZigType *entry_bool;1706 ZigType *entry_bool;
...@@ -1731,7 +1725,6 @@ struct CodeGen {...@@ -1731,7 +1725,6 @@ struct CodeGen {
1731 ZigType *entry_unreachable;1725 ZigType *entry_unreachable;
1732 ZigType *entry_type;1726 ZigType *entry_type;
1733 ZigType *entry_invalid;1727 ZigType *entry_invalid;
1734 ZigType *entry_namespace;
1735 ZigType *entry_block;1728 ZigType *entry_block;
1736 ZigType *entry_num_lit_int;1729 ZigType *entry_num_lit_int;
1737 ZigType *entry_num_lit_float;1730 ZigType *entry_num_lit_float;
...@@ -1851,7 +1844,7 @@ struct CodeGen {...@@ -1851,7 +1844,7 @@ struct CodeGen {
1851 Buf *root_out_name;1844 Buf *root_out_name;
1852 Buf *test_filter;1845 Buf *test_filter;
1853 Buf *test_name_prefix;1846 Buf *test_name_prefix;
1854 PackageTableEntry *root_package;1847 ZigPackage *root_package;
1855 Buf *zig_lib_dir;1848 Buf *zig_lib_dir;
1856 Buf *zig_std_dir;1849 Buf *zig_std_dir;
18571850
...@@ -1945,13 +1938,16 @@ struct ScopeDecls {...@@ -1945,13 +1938,16 @@ struct ScopeDecls {
1945 Scope base;1938 Scope base;
19461939
1947 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table;1940 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table;
1948 bool safety_off;1941 ZigList<AstNode *> use_decls;
1949 AstNode *safety_set_node;1942 AstNode *safety_set_node;
1950 bool fast_math_on;
1951 AstNode *fast_math_set_node;1943 AstNode *fast_math_set_node;
1952 ImportTableEntry *import;1944 ZigType *import;
1953 // If this is a scope from a container, this is the type entry, otherwise null1945 // If this is a scope from a container, this is the type entry, otherwise null
1954 ZigType *container_type;1946 ZigType *container_type;
1947
1948 bool safety_off;
1949 bool fast_math_on;
1950 bool any_imports_failed;
1955};1951};
19561952
1957// This scope comes from a block expression in user code.1953// This scope comes from a block expression in user code.
...@@ -3507,7 +3503,7 @@ struct FnWalkTypes {...@@ -3507,7 +3503,7 @@ struct FnWalkTypes {
3507};3503};
35083504
3509struct FnWalkVars {3505struct FnWalkVars {
3510 ImportTableEntry *import;3506 ZigType *import;
3511 LLVMValueRef llvm_fn;3507 LLVMValueRef llvm_fn;
3512 ZigFn *fn;3508 ZigFn *fn;
3513 ZigVar *var;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,10 +28,14 @@ static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum
28static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type);28static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type);
29static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry);29static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry);
3030
31static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTableEntry *owner, Token *token,31static bool is_top_level_struct(ZigType *import) {
32 Buf *msg)32 return import->id == ZigTypeIdStruct && import->data.structure.root_struct != nullptr;
33{33}
34 if (owner->c_import_node != nullptr) {34
35static 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 // if this happens, then translate_c generated code that39 // if this happens, then translate_c generated code that
36 // failed semantic analysis, which isn't supposed to happen40 // failed semantic analysis, which isn't supposed to happen
3741
...@@ -46,18 +50,20 @@ static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTa...@@ -46,18 +50,20 @@ static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTa
46 return note;50 return note;
47 }51 }
4852
49 ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column,53 ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column,
50 owner->source_code, owner->line_offsets, msg);54 root_struct->source_code, root_struct->line_offsets, msg);
5155
52 err_msg_add_note(parent_msg, err);56 err_msg_add_note(parent_msg, err);
53 return err;57 return err;
54}58}
5559
56ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg) {60ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) {
57 if (owner->c_import_node != nullptr) {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 // if this happens, then translate_c generated code that64 // if this happens, then translate_c generated code that
59 // failed semantic analysis, which isn't supposed to happen65 // 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 buf_sprintf("compiler bug: @cImport generated invalid zig code"));67 buf_sprintf("compiler bug: @cImport generated invalid zig code"));
6268
63 add_error_note_token(g, err, owner, token, msg);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,8 +71,8 @@ ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf
65 g->errors.append(err);71 g->errors.append(err);
66 return err;72 return err;
67 }73 }
68 ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column,74 ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column,
69 owner->source_code, owner->line_offsets, msg);75 root_struct->source_code, root_struct->line_offsets, msg);
7076
71 g->errors.append(err);77 g->errors.append(err);
72 return err;78 return err;
...@@ -114,7 +120,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope...@@ -114,7 +120,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
114 dest->parent = parent;120 dest->parent = parent;
115}121}
116122
117ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) {123ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import) {
118 assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);124 assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
119 ScopeDecls *scope = allocate<ScopeDecls>(1);125 ScopeDecls *scope = allocate<ScopeDecls>(1);
120 init_scope(g, &scope->base, ScopeIdDecls, node, parent);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,11 +213,11 @@ Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent) {
207 return &scope->base;213 return &scope->base;
208}214}
209215
210ImportTableEntry *get_scope_import(Scope *scope) {216ZigType *get_scope_import(Scope *scope) {
211 while (scope) {217 while (scope) {
212 if (scope->id == ScopeIdDecls) {218 if (scope->id == ScopeIdDecls) {
213 ScopeDecls *decls_scope = (ScopeDecls *)scope;219 ScopeDecls *decls_scope = (ScopeDecls *)scope;
214 assert(decls_scope->import);220 assert(is_top_level_struct(decls_scope->import));
215 return decls_scope->import;221 return decls_scope->import;
216 }222 }
217 scope = scope->parent;223 scope = scope->parent;
...@@ -261,7 +267,6 @@ AstNode *type_decl_node(ZigType *type_entry) {...@@ -261,7 +267,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
261 case ZigTypeIdErrorUnion:267 case ZigTypeIdErrorUnion:
262 case ZigTypeIdErrorSet:268 case ZigTypeIdErrorSet:
263 case ZigTypeIdFn:269 case ZigTypeIdFn:
264 case ZigTypeIdNamespace:
265 case ZigTypeIdBoundFn:270 case ZigTypeIdBoundFn:
266 case ZigTypeIdArgTuple:271 case ZigTypeIdArgTuple:
267 case ZigTypeIdPromise:272 case ZigTypeIdPromise:
...@@ -323,7 +328,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {...@@ -323,7 +328,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
323 case ZigTypeIdErrorUnion:328 case ZigTypeIdErrorUnion:
324 case ZigTypeIdErrorSet:329 case ZigTypeIdErrorSet:
325 case ZigTypeIdFn:330 case ZigTypeIdFn:
326 case ZigTypeIdNamespace:
327 case ZigTypeIdBoundFn:331 case ZigTypeIdBoundFn:
328 case ZigTypeIdArgTuple:332 case ZigTypeIdArgTuple:
329 case ZigTypeIdPromise:333 case ZigTypeIdPromise:
...@@ -1010,14 +1014,14 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c...@@ -1010,14 +1014,14 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c
10101014
1011 buf_init_from_str(&entry->name, name);1015 buf_init_from_str(&entry->name, name);
10121016
1013 ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr;1017 ZigType *import = scope ? get_scope_import(scope) : nullptr;
1014 unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0;1018 unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0;
10151019
1016 entry->type_ref = LLVMInt8Type();1020 entry->type_ref = LLVMInt8Type();
1017 entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder,1021 entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder,
1018 ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name),1022 ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name),
1019 import ? ZigLLVMFileToScope(import->di_file) : nullptr,1023 import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr,
1020 import ? import->di_file : nullptr,1024 import ? import->data.structure.root_struct->di_file : nullptr,
1021 line);1025 line);
1022 entry->zero_bits = false;1026 entry->zero_bits = false;
10231027
...@@ -1288,6 +1292,25 @@ static ZigTypeId container_to_type(ContainerKind kind) {...@@ -1288,6 +1292,25 @@ static ZigTypeId container_to_type(ContainerKind kind) {
1288 zig_unreachable();1292 zig_unreachable();
1289}1293}
12901294
1295// This is like get_partial_container_type except it's for the implicit root struct of files.
1296ZigType *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
1291ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,1314ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
1292 AstNode *decl_node, const char *name, ContainerLayout layout)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,11 +1335,12 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
1312 size_t line = decl_node ? decl_node->line : 0;1335 size_t line = decl_node ? decl_node->line : 0;
1313 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();1336 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
13141337
1315 ImportTableEntry *import = get_scope_import(scope);1338 ZigType *import = get_scope_import(scope);
1316 entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name);1339 entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name);
1317 entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,1340 entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
1318 dwarf_kind, name,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));
13201344
1321 buf_init_from_str(&entry->name, name);1345 buf_init_from_str(&entry->name, name);
13221346
...@@ -1459,7 +1483,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType...@@ -1459,7 +1483,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType
1459 case ZigTypeIdNull:1483 case ZigTypeIdNull:
1460 case ZigTypeIdErrorUnion:1484 case ZigTypeIdErrorUnion:
1461 case ZigTypeIdErrorSet:1485 case ZigTypeIdErrorSet:
1462 case ZigTypeIdNamespace:
1463 case ZigTypeIdBoundFn:1486 case ZigTypeIdBoundFn:
1464 case ZigTypeIdArgTuple:1487 case ZigTypeIdArgTuple:
1465 case ZigTypeIdOpaque:1488 case ZigTypeIdOpaque:
...@@ -1547,7 +1570,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {...@@ -1547,7 +1570,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
1547 case ZigTypeIdNull:1570 case ZigTypeIdNull:
1548 case ZigTypeIdErrorUnion:1571 case ZigTypeIdErrorUnion:
1549 case ZigTypeIdErrorSet:1572 case ZigTypeIdErrorSet:
1550 case ZigTypeIdNamespace:
1551 case ZigTypeIdBoundFn:1573 case ZigTypeIdBoundFn:
1552 case ZigTypeIdArgTuple:1574 case ZigTypeIdArgTuple:
1553 case ZigTypeIdPromise:1575 case ZigTypeIdPromise:
...@@ -1706,7 +1728,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1706,7 +1728,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1706 return g->builtin_types.entry_invalid;1728 return g->builtin_types.entry_invalid;
1707 case ZigTypeIdComptimeFloat:1729 case ZigTypeIdComptimeFloat:
1708 case ZigTypeIdComptimeInt:1730 case ZigTypeIdComptimeInt:
1709 case ZigTypeIdNamespace:
1710 case ZigTypeIdBoundFn:1731 case ZigTypeIdBoundFn:
1711 case ZigTypeIdMetaType:1732 case ZigTypeIdMetaType:
1712 case ZigTypeIdVoid:1733 case ZigTypeIdVoid:
...@@ -1801,7 +1822,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1801,7 +1822,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
18011822
1802 case ZigTypeIdComptimeFloat:1823 case ZigTypeIdComptimeFloat:
1803 case ZigTypeIdComptimeInt:1824 case ZigTypeIdComptimeInt:
1804 case ZigTypeIdNamespace:
1805 case ZigTypeIdBoundFn:1825 case ZigTypeIdBoundFn:
1806 case ZigTypeIdMetaType:1826 case ZigTypeIdMetaType:
1807 case ZigTypeIdUnreachable:1827 case ZigTypeIdUnreachable:
...@@ -1895,7 +1915,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {...@@ -1895,7 +1915,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1895 ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);1915 ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
18961916
1897 Scope *scope = &enum_type->data.enumeration.decls_scope->base;1917 Scope *scope = &enum_type->data.enumeration.decls_scope->base;
1898 ImportTableEntry *import = get_scope_import(scope);1918 ZigType *import = get_scope_import(scope);
18991919
1900 // set temporary flag1920 // set temporary flag
1901 enum_type->data.enumeration.embedded_in_current = true;1921 enum_type->data.enumeration.embedded_in_current = true;
...@@ -1924,9 +1944,9 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {...@@ -1924,9 +1944,9 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1924 ZigLLVMDIType **di_root_members = nullptr;1944 ZigLLVMDIType **di_root_members = nullptr;
1925 size_t debug_member_count = 0;1945 size_t debug_member_count = 0;
1926 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,1946 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
1927 ZigLLVMFileToScope(import->di_file),1947 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
1928 buf_ptr(&enum_type->name),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 debug_size_in_bits,1950 debug_size_in_bits,
1931 debug_align_in_bits,1951 debug_align_in_bits,
1932 0, nullptr, di_root_members, (int)debug_member_count, 0, nullptr, "");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,8 +1962,8 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1942 uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);1962 uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);
1943 uint64_t tag_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);1963 uint64_t tag_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);
1944 ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,1964 ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
1945 ZigLLVMFileToScope(import->di_file), buf_ptr(&enum_type->name),1965 ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&enum_type->name),
1946 import->di_file, (unsigned)(decl_node->line + 1),1966 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
1947 tag_debug_size_in_bits,1967 tag_debug_size_in_bits,
1948 tag_debug_align_in_bits,1968 tag_debug_align_in_bits,
1949 di_enumerators, field_count,1969 di_enumerators, field_count,
...@@ -2159,15 +2179,15 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2159,15 +2179,15 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2159 if (struct_type->zero_bits) {2179 if (struct_type->zero_bits) {
2160 struct_type->type_ref = LLVMVoidType();2180 struct_type->type_ref = LLVMVoidType();
21612181
2162 ImportTableEntry *import = get_scope_import(scope);2182 ZigType *import = get_scope_import(scope);
2163 uint64_t debug_size_in_bits = 0;2183 uint64_t debug_size_in_bits = 0;
2164 uint64_t debug_align_in_bits = 0;2184 uint64_t debug_align_in_bits = 0;
2165 ZigLLVMDIType **di_element_types = nullptr;2185 ZigLLVMDIType **di_element_types = nullptr;
2166 size_t debug_field_count = 0;2186 size_t debug_field_count = 0;
2167 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,2187 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
2168 ZigLLVMFileToScope(import->di_file),2188 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
2169 buf_ptr(&struct_type->name),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 debug_size_in_bits,2191 debug_size_in_bits,
2172 debug_align_in_bits,2192 debug_align_in_bits,
2173 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");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,7 +2211,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
21912211
2192 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);2212 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
21932213
2194 ImportTableEntry *import = get_scope_import(scope);2214 ZigType *import = get_scope_import(scope);
2195 size_t debug_field_index = 0;2215 size_t debug_field_index = 0;
2196 for (size_t i = 0; i < field_count; i += 1) {2216 for (size_t i = 0; i < field_count; i += 1) {
2197 AstNode *field_node = decl_node->data.container_decl.fields.at(i);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,7 +2254,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2234 }2254 }
2235 di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,2255 di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
2236 ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name),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 debug_size_in_bits,2258 debug_size_in_bits,
2239 debug_align_in_bits,2259 debug_align_in_bits,
2240 debug_offset_in_bits,2260 debug_offset_in_bits,
...@@ -2247,9 +2267,9 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2247,9 +2267,9 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2247 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref);2267 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref);
2248 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, struct_type->type_ref);2268 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, struct_type->type_ref);
2249 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,2269 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
2250 ZigLLVMFileToScope(import->di_file),2270 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
2251 buf_ptr(&struct_type->name),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 debug_size_in_bits,2273 debug_size_in_bits,
2254 debug_align_in_bits,2274 debug_align_in_bits,
2255 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");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,7 +2318,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2298 uint64_t biggest_size_in_bits = 0;2318 uint64_t biggest_size_in_bits = 0;
22992319
2300 Scope *scope = &union_type->data.unionation.decls_scope->base;2320 Scope *scope = &union_type->data.unionation.decls_scope->base;
2301 ImportTableEntry *import = get_scope_import(scope);2321 ZigType *import = get_scope_import(scope);
23022322
2303 // set temporary flag2323 // set temporary flag
2304 union_type->data.unionation.embedded_in_current = true;2324 union_type->data.unionation.embedded_in_current = true;
...@@ -2325,7 +2345,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2325,7 +2345,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
23252345
2326 union_inner_di_types[union_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,2346 union_inner_di_types[union_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
2327 ZigLLVMTypeToScope(union_type->di_type), buf_ptr(union_field->enum_field->name),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 store_size_in_bits,2349 store_size_in_bits,
2330 abi_align_in_bits,2350 abi_align_in_bits,
2331 0,2351 0,
...@@ -2358,9 +2378,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2358,9 +2378,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2358 ZigLLVMDIType **di_root_members = nullptr;2378 ZigLLVMDIType **di_root_members = nullptr;
2359 size_t debug_member_count = 0;2379 size_t debug_member_count = 0;
2360 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,2380 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
2361 ZigLLVMFileToScope(import->di_file),2381 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
2362 buf_ptr(&union_type->name),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 debug_size_in_bits,2384 debug_size_in_bits,
2365 debug_align_in_bits,2385 debug_align_in_bits,
2366 0, di_root_members, (int)debug_member_count, 0, "");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,8 +2416,8 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
23962416
2397 // create debug type for union2417 // create debug type for union
2398 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,2418 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
2399 ZigLLVMFileToScope(import->di_file), buf_ptr(&union_type->name),2419 ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&union_type->name),
2400 import->di_file, (unsigned)(decl_node->line + 1),2420 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
2401 biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,2421 biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,
2402 gen_field_count, 0, "");2422 gen_field_count, 0, "");
24032423
...@@ -2452,7 +2472,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2452,7 +2472,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2452 // create debug type for union2472 // create debug type for union
2453 ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,2473 ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
2454 ZigLLVMTypeToScope(union_type->di_type), "AnonUnion",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 biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,2476 biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,
2457 gen_field_count, 0, "");2477 gen_field_count, 0, "");
24582478
...@@ -2463,7 +2483,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2463,7 +2483,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
24632483
2464 ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,2484 ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
2465 ZigLLVMTypeToScope(union_type->di_type), "payload",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 biggest_size_in_bits,2487 biggest_size_in_bits,
2468 biggest_align_in_bits,2488 biggest_align_in_bits,
2469 union_offset_in_bits,2489 union_offset_in_bits,
...@@ -2474,7 +2494,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2474,7 +2494,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
24742494
2475 ZigLLVMDIType *tag_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,2495 ZigLLVMDIType *tag_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
2476 ZigLLVMTypeToScope(union_type->di_type), "tag",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 tag_debug_size_in_bits,2498 tag_debug_size_in_bits,
2479 tag_debug_align_in_bits,2499 tag_debug_align_in_bits,
2480 tag_offset_in_bits,2500 tag_offset_in_bits,
...@@ -2487,9 +2507,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2487,9 +2507,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2487 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, union_type->type_ref);2507 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, union_type->type_ref);
2488 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, union_type->type_ref);2508 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, union_type->type_ref);
2489 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,2509 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
2490 ZigLLVMFileToScope(import->di_file),2510 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
2491 buf_ptr(&union_type->name),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 debug_size_in_bits,2513 debug_size_in_bits,
2494 debug_align_in_bits,2514 debug_align_in_bits,
2495 0, nullptr, di_root_members, 2, 0, nullptr, "");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,15 +3205,15 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3185 }3205 }
31863206
3187 if (create_enum_type) {3207 if (create_enum_type) {
3188 ImportTableEntry *import = get_scope_import(scope);3208 ZigType *import = get_scope_import(scope);
3189 uint64_t tag_debug_size_in_bits = tag_type->zero_bits ? 0 :3209 uint64_t tag_debug_size_in_bits = tag_type->zero_bits ? 0 :
3190 8*LLVMStoreSizeOfType(g->target_data_ref, tag_type->type_ref);3210 8*LLVMStoreSizeOfType(g->target_data_ref, tag_type->type_ref);
3191 uint64_t tag_debug_align_in_bits = tag_type->zero_bits ? 0 :3211 uint64_t tag_debug_align_in_bits = tag_type->zero_bits ? 0 :
3192 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_type->type_ref);3212 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_type->type_ref);
3193 // TODO get a more accurate debug scope3213 // TODO get a more accurate debug scope
3194 ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,3214 ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
3195 ZigLLVMFileToScope(import->di_file), buf_ptr(&tag_type->name),3215 ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&tag_type->name),
3196 import->di_file, (unsigned)(decl_node->line + 1),3216 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
3197 tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count,3217 tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count,
3198 tag_type->di_type, "");3218 tag_type->di_type, "");
3199 tag_type->di_type = tag_di_type;3219 tag_type->di_type = tag_di_type;
...@@ -3265,7 +3285,8 @@ static bool scope_is_root_decls(Scope *scope) {...@@ -3265,7 +3285,8 @@ static bool scope_is_root_decls(Scope *scope) {
3265 while (scope) {3285 while (scope) {
3266 if (scope->id == ScopeIdDecls) {3286 if (scope->id == ScopeIdDecls) {
3267 ScopeDecls *scope_decls = (ScopeDecls *)scope;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 scope = scope->parent;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,7 +3347,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
3326}3347}
33273348
3328static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {3349static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3329 ImportTableEntry *import = tld_fn->base.import;3350 ZigType *import = tld_fn->base.import;
3330 AstNode *source_node = tld_fn->base.source_node;3351 AstNode *source_node = tld_fn->base.source_node;
3331 if (source_node->type == NodeTypeFnProto) {3352 if (source_node->type == NodeTypeFnProto) {
3332 AstNodeFnProto *fn_proto = &source_node->data.fn_proto;3353 AstNodeFnProto *fn_proto = &source_node->data.fn_proto;
...@@ -3382,11 +3403,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3382,11 +3403,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3382 }3403 }
33833404
3384 if (scope_is_root_decls(tld_fn->base.parent_scope) &&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 if (g->have_pub_main && buf_eql_str(&fn_table_entry->symbol_name, "main")) {3408 if (g->have_pub_main && buf_eql_str(&fn_table_entry->symbol_name, "main")) {
3388 g->main_fn = fn_table_entry;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 buf_eql_str(&fn_table_entry->symbol_name, "panic"))3411 buf_eql_str(&fn_table_entry->symbol_name, "panic"))
3391 {3412 {
3392 g->panic_fn = fn_table_entry;3413 g->panic_fn = fn_table_entry;
...@@ -3473,8 +3494,8 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope...@@ -3473,8 +3494,8 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
3473 if (!g->is_test_build)3494 if (!g->is_test_build)
3474 return;3495 return;
34753496
3476 ImportTableEntry *import = get_scope_import(&decls_scope->base);3497 ZigType *import = get_scope_import(&decls_scope->base);
3477 if (import->package != g->root_package)3498 if (import->data.structure.root_struct->package != g->root_package)
3478 return;3499 return;
34793500
3480 Buf *decl_name_buf = node->data.test_decl.name;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,8 +3532,8 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source
3511}3532}
35123533
3513void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {3534void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {
3514 Tld *tld = g->compile_var_import->decls_scope->decl_table.get(name);3535 Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);
3515 resolve_top_level_decl(g, tld, false, tld->source_node);3536 resolve_top_level_decl(g, tld, tld->source_node);
3516 assert(tld->id == TldIdVar);3537 assert(tld->id == TldIdVar);
3517 TldVar *tld_var = (TldVar *)tld;3538 TldVar *tld_var = (TldVar *)tld;
3518 tld_var->var->const_value = value;3539 tld_var->var->const_value = value;
...@@ -3561,8 +3582,8 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3561,8 +3582,8 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3561 case NodeTypeUse:3582 case NodeTypeUse:
3562 {3583 {
3563 g->use_queue.append(node);3584 g->use_queue.append(node);
3564 ImportTableEntry *import = get_scope_import(&decls_scope->base);3585 ZigType *import = get_scope_import(&decls_scope->base);
3565 import->use_decls.append(node);3586 get_container_scope(import)->use_decls.append(node);
3566 break;3587 break;
3567 }3588 }
3568 case NodeTypeTestDecl:3589 case NodeTypeTestDecl:
...@@ -3654,7 +3675,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry...@@ -3654,7 +3675,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
3654 return g->builtin_types.entry_invalid;3675 return g->builtin_types.entry_invalid;
3655 case ZigTypeIdComptimeFloat:3676 case ZigTypeIdComptimeFloat:
3656 case ZigTypeIdComptimeInt:3677 case ZigTypeIdComptimeInt:
3657 case ZigTypeIdNamespace:
3658 case ZigTypeIdMetaType:3678 case ZigTypeIdMetaType:
3659 case ZigTypeIdVoid:3679 case ZigTypeIdVoid:
3660 case ZigTypeIdBool:3680 case ZigTypeIdBool:
...@@ -3847,16 +3867,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {...@@ -3847,16 +3867,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
3847 g->global_vars.append(tld_var);3867 g->global_vars.append(tld_var);
3848}3868}
38493869
3850void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node) {3870void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) {
3851 if (tld->resolution != TldResolutionUnresolved)3871 if (tld->resolution != TldResolutionUnresolved)
3852 return;3872 return;
38533873
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 tld->dep_loop_flag = true;3874 tld->dep_loop_flag = true;
3861 g->tld_ref_source_node_stack.append(source_node);3875 g->tld_ref_source_node_stack.append(source_node);
38623876
...@@ -3894,9 +3908,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so...@@ -3894,9 +3908,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so
38943908
3895Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {3909Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
3896 // we must resolve all the use decls3910 // we must resolve all the use decls
3897 ImportTableEntry *import = get_scope_import(scope);3911 ZigType *import = get_scope_import(scope);
3898 for (size_t i = 0; i < import->use_decls.length; i += 1) {3912 for (size_t i = 0; i < get_container_scope(import)->use_decls.length; i += 1) {
3899 AstNode *use_decl_node = import->use_decls.at(i);3913 AstNode *use_decl_node = get_container_scope(import)->use_decls.at(i);
3900 if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {3914 if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
3901 preview_use_decl(g, use_decl_node);3915 preview_use_decl(g, use_decl_node);
3902 resolve_use_decl(g, use_decl_node);3916 resolve_use_decl(g, use_decl_node);
...@@ -4039,7 +4053,6 @@ static bool is_container(ZigType *type_entry) {...@@ -4039,7 +4053,6 @@ static bool is_container(ZigType *type_entry) {
4039 case ZigTypeIdErrorUnion:4053 case ZigTypeIdErrorUnion:
4040 case ZigTypeIdErrorSet:4054 case ZigTypeIdErrorSet:
4041 case ZigTypeIdFn:4055 case ZigTypeIdFn:
4042 case ZigTypeIdNamespace:
4043 case ZigTypeIdBoundFn:4056 case ZigTypeIdBoundFn:
4044 case ZigTypeIdArgTuple:4057 case ZigTypeIdArgTuple:
4045 case ZigTypeIdOpaque:4058 case ZigTypeIdOpaque:
...@@ -4098,7 +4111,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) {...@@ -4098,7 +4111,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) {
4098 case ZigTypeIdErrorUnion:4111 case ZigTypeIdErrorUnion:
4099 case ZigTypeIdErrorSet:4112 case ZigTypeIdErrorSet:
4100 case ZigTypeIdFn:4113 case ZigTypeIdFn:
4101 case ZigTypeIdNamespace:
4102 case ZigTypeIdBoundFn:4114 case ZigTypeIdBoundFn:
4103 case ZigTypeIdInvalid:4115 case ZigTypeIdInvalid:
4104 case ZigTypeIdArgTuple:4116 case ZigTypeIdArgTuple:
...@@ -4344,7 +4356,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4344,7 +4356,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
43444356
4345 ConstExprValue *use_target_value = src_use_node->data.use.value;4357 ConstExprValue *use_target_value = src_use_node->data.use.value;
4346 if (type_is_invalid(use_target_value->type)) {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 return;4360 return;
4349 }4361 }
43504362
...@@ -4352,14 +4364,15 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4352,14 +4364,15 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
43524364
4353 assert(use_target_value->special != ConstValSpecialRuntime);4365 assert(use_target_value->special != ConstValSpecialRuntime);
43544366
4355 ImportTableEntry *target_import = use_target_value->data.x_import;4367 ZigType *target_import = use_target_value->data.x_type;
4356 assert(target_import);4368 assert(target_import);
4369 assert(target_import->id == ZigTypeIdStruct);
43574370
4358 if (target_import->any_imports_failed) {4371 if (get_container_scope(target_import)->any_imports_failed) {
4359 dst_use_node->owner->any_imports_failed = true;4372 get_container_scope(dst_use_node->owner)->any_imports_failed = true;
4360 }4373 }
43614374
4362 auto it = target_import->decls_scope->decl_table.entry_iterator();4375 auto it = get_container_scope(target_import)->decl_table.entry_iterator();
4363 for (;;) {4376 for (;;) {
4364 auto *entry = it.next();4377 auto *entry = it.next();
4365 if (!entry)4378 if (!entry)
...@@ -4374,7 +4387,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4374,7 +4387,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
43744387
4375 Buf *target_tld_name = entry->key;4388 Buf *target_tld_name = entry->key;
43764389
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 if (existing_entry) {4391 if (existing_entry) {
4379 Tld *existing_decl = existing_entry->value;4392 Tld *existing_decl = existing_entry->value;
4380 if (existing_decl != target_tld) {4393 if (existing_decl != target_tld) {
...@@ -4387,8 +4400,8 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4387,8 +4400,8 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
4387 }4400 }
4388 }4401 }
43894402
4390 for (size_t i = 0; i < target_import->use_decls.length; i += 1) {4403 for (size_t i = 0; i < get_container_scope(target_import)->use_decls.length; i += 1) {
4391 AstNode *use_decl_node = target_import->use_decls.at(i);4404 AstNode *use_decl_node = get_container_scope(target_import)->use_decls.at(i);
4392 if (use_decl_node->data.use.visib_mod != VisibModPrivate)4405 if (use_decl_node->data.use.visib_mod != VisibModPrivate)
4393 add_symbols_from_import(g, use_decl_node, dst_use_node);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,16 +4428,16 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
4415 }4428 }
44164429
4417 node->data.use.resolution = TldResolutionResolving;4430 node->data.use.resolution = TldResolutionResolving;
4418 ConstExprValue *result = analyze_const_value(g, &node->owner->decls_scope->base,4431 ConstExprValue *result = analyze_const_value(g, &get_container_scope(node->owner)->base,
4419 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);4432 node->data.use.expr, g->builtin_types.entry_type, nullptr);
44204433
4421 if (type_is_invalid(result->type))4434 if (type_is_invalid(result->type))
4422 node->owner->any_imports_failed = true;4435 get_container_scope(node->owner)->any_imports_failed = true;
44234436
4424 node->data.use.value = result;4437 node->data.use.value = result;
4425}4438}
44264439
4427ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) {4440ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Buf *source_code) {
4428 if (g->verbose_tokenize) {4441 if (g->verbose_tokenize) {
4429 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path));4442 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path));
4430 fprintf(stderr, "----------------\n");4443 fprintf(stderr, "----------------\n");
...@@ -4452,32 +4465,34 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r...@@ -4452,32 +4465,34 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
4452 fprintf(stderr, "------\n");4465 fprintf(stderr, "------\n");
4453 }4466 }
44544467
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 Buf *src_dirname = buf_alloc();4468 Buf *src_dirname = buf_alloc();
4468 Buf *src_basename = buf_alloc();4469 Buf *src_basename = buf_alloc();
4469 os_path_split(resolved_path, src_dirname, src_basename);4470 os_path_split(resolved_path, src_dirname, src_basename);
44704471
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 g->import_table.put(resolved_path, import_entry);4491 g->import_table.put(resolved_path, import_entry);
4473 g->import_queue.append(import_entry);4492 g->import_queue.append(import_entry);
44744493
4475 import_entry->decls_scope = create_decls_scope(g, import_entry->root, nullptr, nullptr, import_entry);4494 for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) {
44764495 AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i);
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);
44814496
4482 if (top_level_decl->type == NodeTypeFnDef) {4497 if (top_level_decl->type == NodeTypeFnDef) {
4483 AstNode *proto_node = top_level_decl->data.fn_def.fn_proto;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,16 +4517,16 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
4502 return import_entry;4517 return import_entry;
4503}4518}
45044519
4505void scan_import(CodeGen *g, ImportTableEntry *import) {4520void scan_import(CodeGen *g, ZigType *import) {
4506 if (!import->scanned) {4521 if (!import->data.structure.root_struct->scanned) {
4507 import->scanned = true;4522 import->data.structure.root_struct->scanned = true;
4508 scan_decls(g, import->decls_scope, import->root);4523 scan_decls(g, import->data.structure.decls_scope, import->data.structure.decl_node);
4509 }4524 }
4510}4525}
45114526
4512void semantic_analyze(CodeGen *g) {4527void semantic_analyze(CodeGen *g) {
4513 for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) {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 scan_import(g, import);4530 scan_import(g, import);
4516 }4531 }
45174532
...@@ -4530,9 +4545,8 @@ void semantic_analyze(CodeGen *g) {...@@ -4530,9 +4545,8 @@ void semantic_analyze(CodeGen *g) {
4530 {4545 {
4531 for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) {4546 for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) {
4532 Tld *tld = g->resolve_queue.at(g->resolve_queue_index);4547 Tld *tld = g->resolve_queue.at(g->resolve_queue_index);
4533 bool pointer_only = false;
4534 AstNode *source_node = nullptr;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 }
45374551
4538 for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {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,7 +4627,6 @@ bool handle_is_ptr(ZigType *type_entry) {
4613 case ZigTypeIdComptimeInt:4627 case ZigTypeIdComptimeInt:
4614 case ZigTypeIdUndefined:4628 case ZigTypeIdUndefined:
4615 case ZigTypeIdNull:4629 case ZigTypeIdNull:
4616 case ZigTypeIdNamespace:
4617 case ZigTypeIdBoundFn:4630 case ZigTypeIdBoundFn:
4618 case ZigTypeIdArgTuple:4631 case ZigTypeIdArgTuple:
4619 case ZigTypeIdOpaque:4632 case ZigTypeIdOpaque:
...@@ -4880,8 +4893,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4880,8 +4893,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4880 return 3415065496;4893 return 3415065496;
4881 case ZigTypeIdErrorSet:4894 case ZigTypeIdErrorSet:
4882 return hash_const_val_error_set(const_val);4895 return hash_const_val_error_set(const_val);
4883 case ZigTypeIdNamespace:
4884 return hash_ptr(const_val->data.x_import);
4885 case ZigTypeIdVector:4896 case ZigTypeIdVector:
4886 // TODO better hashing algorithm4897 // TODO better hashing algorithm
4887 return 3647867726;4898 return 3647867726;
...@@ -4943,7 +4954,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4943,7 +4954,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4943 case ZigTypeIdComptimeInt:4954 case ZigTypeIdComptimeInt:
4944 case ZigTypeIdUndefined:4955 case ZigTypeIdUndefined:
4945 case ZigTypeIdNull:4956 case ZigTypeIdNull:
4946 case ZigTypeIdNamespace:
4947 case ZigTypeIdBoundFn:4957 case ZigTypeIdBoundFn:
4948 case ZigTypeIdFn:4958 case ZigTypeIdFn:
4949 case ZigTypeIdOpaque:4959 case ZigTypeIdOpaque:
...@@ -5013,7 +5023,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {...@@ -5013,7 +5023,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
5013 case ZigTypeIdComptimeInt:5023 case ZigTypeIdComptimeInt:
5014 case ZigTypeIdUndefined:5024 case ZigTypeIdUndefined:
5015 case ZigTypeIdNull:5025 case ZigTypeIdNull:
5016 case ZigTypeIdNamespace:
5017 case ZigTypeIdBoundFn:5026 case ZigTypeIdBoundFn:
5018 case ZigTypeIdFn:5027 case ZigTypeIdFn:
5019 case ZigTypeIdOpaque:5028 case ZigTypeIdOpaque:
...@@ -5143,7 +5152,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5143,7 +5152,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5143 case ZigTypeIdComptimeFloat:5152 case ZigTypeIdComptimeFloat:
5144 case ZigTypeIdComptimeInt:5153 case ZigTypeIdComptimeInt:
5145 case ZigTypeIdMetaType:5154 case ZigTypeIdMetaType:
5146 case ZigTypeIdNamespace:
5147 case ZigTypeIdBoundFn:5155 case ZigTypeIdBoundFn:
5148 case ZigTypeIdArgTuple:5156 case ZigTypeIdArgTuple:
5149 case ZigTypeIdOptional:5157 case ZigTypeIdOptional:
...@@ -5209,7 +5217,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {...@@ -5209,7 +5217,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
5209 case ZigTypeIdUndefined:5217 case ZigTypeIdUndefined:
5210 case ZigTypeIdNull:5218 case ZigTypeIdNull:
5211 case ZigTypeIdMetaType:5219 case ZigTypeIdMetaType:
5212 case ZigTypeIdNamespace:
5213 case ZigTypeIdBoundFn:5220 case ZigTypeIdBoundFn:
5214 case ZigTypeIdArgTuple:5221 case ZigTypeIdArgTuple:
5215 return ReqCompTimeYes;5222 return ReqCompTimeYes;
...@@ -5797,8 +5804,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {...@@ -5797,8 +5804,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
5797 }5804 }
5798 case ZigTypeIdErrorUnion:5805 case ZigTypeIdErrorUnion:
5799 zig_panic("TODO");5806 zig_panic("TODO");
5800 case ZigTypeIdNamespace:
5801 return a->data.x_import == b->data.x_import;
5802 case ZigTypeIdArgTuple:5807 case ZigTypeIdArgTuple:
5803 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&5808 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
5804 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;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,16 +6077,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
6072 }6077 }
6073 return;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 case ZigTypeIdBoundFn:6080 case ZigTypeIdBoundFn:
6086 {6081 {
6087 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;6082 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
...@@ -6203,7 +6198,6 @@ uint32_t type_id_hash(TypeId x) {...@@ -6203,7 +6198,6 @@ uint32_t type_id_hash(TypeId x) {
6203 case ZigTypeIdEnum:6198 case ZigTypeIdEnum:
6204 case ZigTypeIdUnion:6199 case ZigTypeIdUnion:
6205 case ZigTypeIdFn:6200 case ZigTypeIdFn:
6206 case ZigTypeIdNamespace:
6207 case ZigTypeIdBoundFn:6201 case ZigTypeIdBoundFn:
6208 case ZigTypeIdArgTuple:6202 case ZigTypeIdArgTuple:
6209 case ZigTypeIdPromise:6203 case ZigTypeIdPromise:
...@@ -6252,7 +6246,6 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -6252,7 +6246,6 @@ bool type_id_eql(TypeId a, TypeId b) {
6252 case ZigTypeIdEnum:6246 case ZigTypeIdEnum:
6253 case ZigTypeIdUnion:6247 case ZigTypeIdUnion:
6254 case ZigTypeIdFn:6248 case ZigTypeIdFn:
6255 case ZigTypeIdNamespace:
6256 case ZigTypeIdBoundFn:6249 case ZigTypeIdBoundFn:
6257 case ZigTypeIdArgTuple:6250 case ZigTypeIdArgTuple:
6258 case ZigTypeIdOpaque:6251 case ZigTypeIdOpaque:
...@@ -6419,7 +6412,6 @@ static const ZigTypeId all_type_ids[] = {...@@ -6419,7 +6412,6 @@ static const ZigTypeId all_type_ids[] = {
6419 ZigTypeIdEnum,6412 ZigTypeIdEnum,
6420 ZigTypeIdUnion,6413 ZigTypeIdUnion,
6421 ZigTypeIdFn,6414 ZigTypeIdFn,
6422 ZigTypeIdNamespace,
6423 ZigTypeIdBoundFn,6415 ZigTypeIdBoundFn,
6424 ZigTypeIdArgTuple,6416 ZigTypeIdArgTuple,
6425 ZigTypeIdOpaque,6417 ZigTypeIdOpaque,
...@@ -6480,18 +6472,16 @@ size_t type_id_index(ZigType *entry) {...@@ -6480,18 +6472,16 @@ size_t type_id_index(ZigType *entry) {
6480 return 17;6472 return 17;
6481 case ZigTypeIdFn:6473 case ZigTypeIdFn:
6482 return 18;6474 return 18;
6483 case ZigTypeIdNamespace:
6484 return 19;
6485 case ZigTypeIdBoundFn:6475 case ZigTypeIdBoundFn:
6486 return 20;6476 return 19;
6487 case ZigTypeIdArgTuple:6477 case ZigTypeIdArgTuple:
6488 return 21;6478 return 20;
6489 case ZigTypeIdOpaque:6479 case ZigTypeIdOpaque:
6490 return 22;6480 return 21;
6491 case ZigTypeIdPromise:6481 case ZigTypeIdPromise:
6492 return 23;6482 return 22;
6493 case ZigTypeIdVector:6483 case ZigTypeIdVector:
6494 return 24;6484 return 23;
6495 }6485 }
6496 zig_unreachable();6486 zig_unreachable();
6497}6487}
...@@ -6538,8 +6528,6 @@ const char *type_id_name(ZigTypeId id) {...@@ -6538,8 +6528,6 @@ const char *type_id_name(ZigTypeId id) {
6538 return "Union";6528 return "Union";
6539 case ZigTypeIdFn:6529 case ZigTypeIdFn:
6540 return "Fn";6530 return "Fn";
6541 case ZigTypeIdNamespace:
6542 return "Namespace";
6543 case ZigTypeIdBoundFn:6531 case ZigTypeIdBoundFn:
6544 return "BoundFn";6532 return "BoundFn";
6545 case ZigTypeIdArgTuple:6533 case ZigTypeIdArgTuple:
...@@ -6619,8 +6607,8 @@ bool type_ptr_eql(const ZigType *a, const ZigType *b) {...@@ -6619,8 +6607,8 @@ bool type_ptr_eql(const ZigType *a, const ZigType *b) {
6619}6607}
66206608
6621ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {6609ConstExprValue *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));6610 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
6623 resolve_top_level_decl(codegen, tld, false, nullptr);6611 resolve_top_level_decl(codegen, tld, nullptr);
6624 assert(tld->id == TldIdVar);6612 assert(tld->id == TldIdVar);
6625 TldVar *tld_var = (TldVar *)tld;6613 TldVar *tld_var = (TldVar *)tld;
6626 ConstExprValue *var_value = tld_var->var->const_value;6614 ConstExprValue *var_value = tld_var->var->const_value;
src/analyze.hpp+8-7
...@@ -12,7 +12,7 @@...@@ -12,7 +12,7 @@
1212
13void semantic_analyze(CodeGen *g);13void semantic_analyze(CodeGen *g);
14ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);14ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
15ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg);15ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
17ZigType *new_type_table_entry(ZigTypeId id);17ZigType *new_type_table_entry(ZigTypeId id);
18ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);18ZigType *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,6 +30,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
30ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);30ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
31ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,31ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
32 AstNode *decl_node, const char *name, ContainerLayout layout);32 AstNode *decl_node, const char *name, ContainerLayout layout);
33ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct);
33ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);34ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
34ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);35ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
35ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);36ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
...@@ -46,12 +47,12 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry);...@@ -46,12 +47,12 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry);
46bool ptr_allows_addr_zero(ZigType *ptr_type);47bool ptr_allows_addr_zero(ZigType *ptr_type);
47bool type_is_nonnull_ptr(ZigType *type);48bool type_is_nonnull_ptr(ZigType *type);
4849
49ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);50ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Buf *source_code);
5051
5152
52ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);53ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
53Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);54Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
54void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);55void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
55bool type_is_codegen_pointer(ZigType *type);56bool type_is_codegen_pointer(ZigType *type);
5657
57ZigType *get_src_ptr_type(ZigType *type);58ZigType *get_src_ptr_type(ZigType *type);
...@@ -77,11 +78,11 @@ bool is_array_ref(ZigType *type_entry);...@@ -77,11 +78,11 @@ bool is_array_ref(ZigType *type_entry);
77bool is_container_ref(ZigType *type_entry);78bool is_container_ref(ZigType *type_entry);
78bool is_valid_vector_elem_type(ZigType *elem_type);79bool is_valid_vector_elem_type(ZigType *elem_type);
79void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);80void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
80void scan_import(CodeGen *g, ImportTableEntry *import);81void scan_import(CodeGen *g, ZigType *import);
81void preview_use_decl(CodeGen *g, AstNode *node);82void preview_use_decl(CodeGen *g, AstNode *node);
82void resolve_use_decl(CodeGen *g, AstNode *node);83void resolve_use_decl(CodeGen *g, AstNode *node);
83ZigFn *scope_fn_entry(Scope *scope);84ZigFn *scope_fn_entry(Scope *scope);
84ImportTableEntry *get_scope_import(Scope *scope);85ZigType *get_scope_import(Scope *scope);
85void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);86void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
86ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,87ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
87 bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type);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,7 +110,7 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent);
109ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);110ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
110ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);111ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
111ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);112ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
112ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);113ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import);
113Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);114Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
114Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);115Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);
115Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);116Scope *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,7 +187,7 @@ LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
186187
187uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);188uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
188ZigType *get_align_amt_type(CodeGen *g);189ZigType *get_align_amt_type(CodeGen *g);
189PackageTableEntry *new_anonymous_package(void);190ZigPackage *new_anonymous_package(void);
190191
191Buf *const_value_to_buffer(ConstExprValue *const_val);192Buf *const_value_to_buffer(ConstExprValue *const_val);
192void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);193void 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,15 +48,15 @@ static void init_darwin_native(CodeGen *g) {
48 }48 }
49}49}
5050
51static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) {51static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path) {
52 PackageTableEntry *entry = allocate<PackageTableEntry>(1);52 ZigPackage *entry = allocate<ZigPackage>(1);
53 entry->package_table.init(4);53 entry->package_table.init(4);
54 buf_init_from_str(&entry->root_src_dir, root_src_dir);54 buf_init_from_str(&entry->root_src_dir, root_src_dir);
55 buf_init_from_str(&entry->root_src_path, root_src_path);55 buf_init_from_str(&entry->root_src_path, root_src_path);
56 return entry;56 return entry;
57}57}
5858
59PackageTableEntry *new_anonymous_package(void) {59ZigPackage *new_anonymous_package(void) {
60 return new_package("", "");60 return new_package("", "");
61}61}
6262
...@@ -621,7 +621,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -621,7 +621,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
621 if (scope->di_scope)621 if (scope->di_scope)
622 return scope->di_scope;622 return scope->di_scope;
623623
624 ImportTableEntry *import = get_scope_import(scope);624 ZigType *import = get_scope_import(scope);
625 switch (scope->id) {625 switch (scope->id) {
626 case ScopeIdCImport:626 case ScopeIdCImport:
627 zig_unreachable();627 zig_unreachable();
...@@ -644,7 +644,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -644,7 +644,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
644 assert(fn_di_scope != nullptr);644 assert(fn_di_scope != nullptr);
645 ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,645 ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
646 fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "",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 fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage,648 fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage,
649 is_definition, scope_line, flags, is_optimized, nullptr);649 is_definition, scope_line, flags, is_optimized, nullptr);
650650
...@@ -658,7 +658,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -658,7 +658,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
658 assert(decls_scope->container_type);658 assert(decls_scope->container_type);
659 scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);659 scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);
660 } else {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 return scope->di_scope;663 return scope->di_scope;
664 case ScopeIdBlock:664 case ScopeIdBlock:
...@@ -668,7 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -668,7 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
668 assert(scope->parent);668 assert(scope->parent);
669 ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,669 ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
670 get_di_scope(g, scope->parent),670 get_di_scope(g, scope->parent),
671 import->di_file,671 import->data.structure.root_struct->di_file,
672 (unsigned)scope->source_node->line + 1,672 (unsigned)scope->source_node->line + 1,
673 (unsigned)scope->source_node->column + 1);673 (unsigned)scope->source_node->column + 1);
674 scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);674 scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
...@@ -2196,7 +2196,7 @@ var_ok:...@@ -2196,7 +2196,7 @@ var_ok:
2196 if (dest_ty != nullptr && var->decl_node) {2196 if (dest_ty != nullptr && var->decl_node) {
2197 // arg index + 1 because the 0 index is return value2197 // arg index + 1 because the 0 index is return value
2198 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),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 (unsigned)(var->decl_node->line + 1),2200 (unsigned)(var->decl_node->line + 1),
2201 dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1);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,7 +5800,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
5800 case ZigTypeIdNull:5800 case ZigTypeIdNull:
5801 case ZigTypeIdErrorUnion:5801 case ZigTypeIdErrorUnion:
5802 case ZigTypeIdErrorSet:5802 case ZigTypeIdErrorSet:
5803 case ZigTypeIdNamespace:
5804 case ZigTypeIdBoundFn:5803 case ZigTypeIdBoundFn:
5805 case ZigTypeIdArgTuple:5804 case ZigTypeIdArgTuple:
5806 case ZigTypeIdVoid:5805 case ZigTypeIdVoid:
...@@ -6400,7 +6399,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -6400,7 +6399,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
6400 case ZigTypeIdComptimeInt:6399 case ZigTypeIdComptimeInt:
6401 case ZigTypeIdUndefined:6400 case ZigTypeIdUndefined:
6402 case ZigTypeIdNull:6401 case ZigTypeIdNull:
6403 case ZigTypeIdNamespace:
6404 case ZigTypeIdBoundFn:6402 case ZigTypeIdBoundFn:
6405 case ZigTypeIdArgTuple:6403 case ZigTypeIdArgTuple:
6406 case ZigTypeIdOpaque:6404 case ZigTypeIdOpaque:
...@@ -6506,12 +6504,12 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,...@@ -6506,12 +6504,12 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
6506 assert(var->gen_is_const);6504 assert(var->gen_is_const);
6507 assert(type_entry);6505 assert(type_entry);
65086506
6509 ImportTableEntry *import = get_scope_import(var->parent_scope);6507 ZigType *import = get_scope_import(var->parent_scope);
6510 assert(import);6508 assert(import);
65116509
6512 bool is_local_to_unit = true;6510 bool is_local_to_unit = true;
6513 ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name),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 (unsigned)(var->decl_node->line + 1),6513 (unsigned)(var->decl_node->line + 1),
6516 type_entry->di_type, is_local_to_unit);6514 type_entry->di_type, is_local_to_unit);
65176515
...@@ -6767,7 +6765,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6767,7 +6765,7 @@ static void do_code_gen(CodeGen *g) {
6767 *slot = build_alloca(g, slot_type, "", alignment_bytes);6765 *slot = build_alloca(g, slot_type, "", alignment_bytes);
6768 }6766 }
67696767
6770 ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);6768 ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
67716769
6772 unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;6770 unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
67736771
...@@ -6799,7 +6797,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6799,7 +6797,7 @@ static void do_code_gen(CodeGen *g) {
6799 var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);6797 var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);
68006798
6801 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),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 var->var_type->di_type, !g->strip_debug_symbols, 0);6801 var->var_type->di_type, !g->strip_debug_symbols, 0);
68046802
6805 } else if (is_c_abi) {6803 } else if (is_c_abi) {
...@@ -6823,7 +6821,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6823,7 +6821,7 @@ static void do_code_gen(CodeGen *g) {
6823 }6821 }
6824 if (var->decl_node) {6822 if (var->decl_node) {
6825 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),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 (unsigned)(var->decl_node->line + 1),6825 (unsigned)(var->decl_node->line + 1),
6828 gen_type->di_type, !g->strip_debug_symbols, 0, (unsigned)(var->gen_arg_index + 1));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,12 +6969,6 @@ static void define_builtin_types(CodeGen *g) {
6971 entry->zero_bits = true;6969 entry->zero_bits = true;
6972 g->builtin_types.entry_invalid = entry;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 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);6973 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
6982 buf_init_from_str(&entry->name, "comptime_float");6974 buf_init_from_str(&entry->name, "comptime_float");
...@@ -7470,7 +7462,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7470,7 +7462,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7470 " Enum: Enum,\n"7462 " Enum: Enum,\n"
7471 " Union: Union,\n"7463 " Union: Union,\n"
7472 " Fn: Fn,\n"7464 " Fn: Fn,\n"
7473 " Namespace: void,\n"
7474 " BoundFn: Fn,\n"7465 " BoundFn: Fn,\n"
7475 " ArgTuple: void,\n"7466 " ArgTuple: void,\n"
7476 " Opaque: void,\n"7467 " Opaque: void,\n"
...@@ -7948,17 +7939,21 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {...@@ -7948,17 +7939,21 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
7948 Buf *src_dirname = buf_alloc();7939 Buf *src_dirname = buf_alloc();
7949 os_path_split(full_path, src_dirname, src_basename);7940 os_path_split(full_path, src_dirname, src_basename);
79507941
7951 ImportTableEntry *import = allocate<ImportTableEntry>(1);7942 Buf noextname = BUF_INIT;
7952 import->source_code = nullptr;7943 os_path_extname(src_basename, &noextname, nullptr);
7953 import->path = full_path;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 g->root_import = import;7951 g->root_import = import;
7955 import->decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, import);
79567952
7957 detect_libc(g);7953 detect_libc(g);
79587954
7959 init(g);7955 init(g);
79607956
7961 import->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
79627957
7963 ZigList<ErrorMsg *> errors = {0};7958 ZigList<ErrorMsg *> errors = {0};
7964 Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr);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,7 +7972,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
7977 }7972 }
7978}7973}
79797974
7980static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) {7975static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *basename) {
7981 Buf *code_basename = buf_create_from_str(basename);7976 Buf *code_basename = buf_create_from_str(basename);
7982 Buf path_to_code_src = BUF_INIT;7977 Buf path_to_code_src = BUF_INIT;
7983 os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);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,17 +7989,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
7994 return add_source_file(g, package, resolved_path, import_code);7989 return add_source_file(g, package, resolved_path, import_code);
7995}7990}
79967991
7997static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {7992static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {
7998 PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig");7993 ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig");
7999 package->package_table.put(buf_create_from_str("@root"), pkg_with_main);7994 package->package_table.put(buf_create_from_str("@root"), pkg_with_main);
8000 return package;7995 return package;
8001}7996}
80027997
8003static PackageTableEntry *create_test_runner_pkg(CodeGen *g) {7998static ZigPackage *create_test_runner_pkg(CodeGen *g) {
8004 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig");7999 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig");
8005}8000}
80068001
8007static PackageTableEntry *create_panic_pkg(CodeGen *g) {8002static ZigPackage *create_panic_pkg(CodeGen *g) {
8008 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig");8003 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig");
8009}8004}
80108005
...@@ -8096,7 +8091,7 @@ static void gen_root_source(CodeGen *g) {...@@ -8096,7 +8091,7 @@ static void gen_root_source(CodeGen *g) {
80968091
8097 {8092 {
8098 // Zig has lazy top level definitions. Here we semantically analyze the panic function.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 if (g->have_pub_panic) {8095 if (g->have_pub_panic) {
8101 import_with_panic = g->root_import;8096 import_with_panic = g->root_import;
8102 } else {8097 } else {
...@@ -8104,9 +8099,9 @@ static void gen_root_source(CodeGen *g) {...@@ -8104,9 +8099,9 @@ static void gen_root_source(CodeGen *g) {
8104 import_with_panic = add_special_code(g, g->panic_package, "panic.zig");8099 import_with_panic = add_special_code(g, g->panic_package, "panic.zig");
8105 }8100 }
8106 scan_import(g, import_with_panic);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 assert(panic_tld != nullptr);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 }
81118106
81128107
...@@ -8341,7 +8336,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e...@@ -8341,7 +8336,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
8341 case ZigTypeIdComptimeInt:8336 case ZigTypeIdComptimeInt:
8342 case ZigTypeIdUndefined:8337 case ZigTypeIdUndefined:
8343 case ZigTypeIdNull:8338 case ZigTypeIdNull:
8344 case ZigTypeIdNamespace:
8345 case ZigTypeIdBoundFn:8339 case ZigTypeIdBoundFn:
8346 case ZigTypeIdArgTuple:8340 case ZigTypeIdArgTuple:
8347 case ZigTypeIdErrorUnion:8341 case ZigTypeIdErrorUnion:
...@@ -8524,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -8524,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
8524 case ZigTypeIdInvalid:8518 case ZigTypeIdInvalid:
8525 case ZigTypeIdMetaType:8519 case ZigTypeIdMetaType:
8526 case ZigTypeIdBoundFn:8520 case ZigTypeIdBoundFn:
8527 case ZigTypeIdNamespace:
8528 case ZigTypeIdComptimeFloat:8521 case ZigTypeIdComptimeFloat:
8529 case ZigTypeIdComptimeInt:8522 case ZigTypeIdComptimeInt:
8530 case ZigTypeIdUndefined:8523 case ZigTypeIdUndefined:
...@@ -8676,7 +8669,6 @@ static void gen_h_file(CodeGen *g) {...@@ -8676,7 +8669,6 @@ static void gen_h_file(CodeGen *g) {
8676 case ZigTypeIdNull:8669 case ZigTypeIdNull:
8677 case ZigTypeIdErrorUnion:8670 case ZigTypeIdErrorUnion:
8678 case ZigTypeIdErrorSet:8671 case ZigTypeIdErrorSet:
8679 case ZigTypeIdNamespace:
8680 case ZigTypeIdBoundFn:8672 case ZigTypeIdBoundFn:
8681 case ZigTypeIdArgTuple:8673 case ZigTypeIdArgTuple:
8682 case ZigTypeIdOptional:8674 case ZigTypeIdOptional:
...@@ -8775,7 +8767,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {...@@ -8775,7 +8767,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
8775 g->timing_events.append({os_get_time(), name});8767 g->timing_events.append({os_get_time(), name});
8776}8768}
87778769
8778static void add_cache_pkg(CodeGen *g, CacheHash *ch, PackageTableEntry *pkg) {8770static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
8779 if (buf_len(&pkg->root_src_path) == 0)8771 if (buf_len(&pkg->root_src_path) == 0)
8780 return;8772 return;
87818773
...@@ -9029,9 +9021,9 @@ void codegen_build_and_link(CodeGen *g) {...@@ -9029,9 +9021,9 @@ void codegen_build_and_link(CodeGen *g) {
9029 codegen_add_time_event(g, "Done");9021 codegen_add_time_event(g, "Done");
9030}9022}
90319023
9032PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) {9024ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) {
9033 init(g);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 if (g->std_package != nullptr) {9027 if (g->std_package != nullptr) {
9036 assert(g->compile_var_package != nullptr);9028 assert(g->compile_var_package != nullptr);
9037 pkg->package_table.put(buf_create_from_str("std"), g->std_package);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,7 +48,7 @@ void codegen_print_timing_report(CodeGen *g, FILE *f);
48void codegen_link(CodeGen *g);48void codegen_link(CodeGen *g);
49void codegen_build_and_link(CodeGen *g);49void codegen_build_and_link(CodeGen *g);
5050
51PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path);51ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path);
52void codegen_add_assembly(CodeGen *g, Buf *path);52void codegen_add_assembly(CodeGen *g, Buf *path);
53void codegen_add_object(CodeGen *g, Buf *object_path);53void codegen_add_object(CodeGen *g, Buf *object_path);
5454
src/ir.cpp+34-84
...@@ -258,7 +258,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {...@@ -258,7 +258,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
258 case ZigTypeIdPointer:258 case ZigTypeIdPointer:
259 case ZigTypeIdUndefined:259 case ZigTypeIdUndefined:
260 case ZigTypeIdNull:260 case ZigTypeIdNull:
261 case ZigTypeIdNamespace:
262 case ZigTypeIdBoundFn:261 case ZigTypeIdBoundFn:
263 case ZigTypeIdErrorSet:262 case ZigTypeIdErrorSet:
264 case ZigTypeIdOpaque:263 case ZigTypeIdOpaque:
...@@ -1123,11 +1122,11 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *...@@ -1123,11 +1122,11 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
1123 return &const_instruction->base;1122 return &const_instruction->base;
1124}1123}
11251124
1126static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) {1125static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1127 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);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 const_instruction->base.value.special = ConstValSpecialStatic;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 return &const_instruction->base;1130 return &const_instruction->base;
1132}1131}
11331132
...@@ -3824,7 +3823,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3824,7 +3823,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3824 if (tld)3823 if (tld)
3825 return ir_build_decl_ref(irb, scope, node, tld, lval);3824 return ir_build_decl_ref(irb, scope, node, tld, lval);
38263825
3827 if (node->owner->any_imports_failed) {3826 if (get_container_scope(node->owner)->any_imports_failed) {
3828 // skip the error message since we had a failing import in this file3827 // skip the error message since we had a failing import in this file
3829 // if an import breaks we don't need redundant undeclared identifier errors3828 // if an import breaks we don't need redundant undeclared identifier errors
3830 return irb->codegen->invalid_instruction;3829 return irb->codegen->invalid_instruction;
...@@ -6620,9 +6619,12 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char...@@ -6620,9 +6619,12 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
6620 buf_appendf(name, ")");6619 buf_appendf(name, ")");
6621 return name;6620 return name;
6622 } else {6621 } else {
6623 //Note: C-imports do not have valid location information6622 // Note: C-imports do not have valid location information
6623 // TODO this will get fixed by https://github.com/ziglang/zig/issues/2015
6624 return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name,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}
66286630
...@@ -12065,7 +12067,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -12065,7 +12067,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
12065 case ZigTypeIdErrorSet:12067 case ZigTypeIdErrorSet:
12066 case ZigTypeIdFn:12068 case ZigTypeIdFn:
12067 case ZigTypeIdOpaque:12069 case ZigTypeIdOpaque:
12068 case ZigTypeIdNamespace:
12069 case ZigTypeIdBoundFn:12070 case ZigTypeIdBoundFn:
12070 case ZigTypeIdArgTuple:12071 case ZigTypeIdArgTuple:
12071 case ZigTypeIdPromise:12072 case ZigTypeIdPromise:
...@@ -13407,7 +13408,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -13407,7 +13408,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
13407 case ZigTypeIdOptional:13408 case ZigTypeIdOptional:
13408 case ZigTypeIdErrorUnion:13409 case ZigTypeIdErrorUnion:
13409 case ZigTypeIdErrorSet:13410 case ZigTypeIdErrorSet:
13410 case ZigTypeIdNamespace:
13411 case ZigTypeIdBoundFn:13411 case ZigTypeIdBoundFn:
13412 case ZigTypeIdArgTuple:13412 case ZigTypeIdArgTuple:
13413 case ZigTypeIdOpaque:13413 case ZigTypeIdOpaque:
...@@ -13432,7 +13432,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -13432,7 +13432,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
13432 case ZigTypeIdErrorSet:13432 case ZigTypeIdErrorSet:
13433 case ZigTypeIdVector:13433 case ZigTypeIdVector:
13434 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));13434 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
13435 case ZigTypeIdNamespace:
13436 case ZigTypeIdBoundFn:13435 case ZigTypeIdBoundFn:
13437 case ZigTypeIdArgTuple:13436 case ZigTypeIdArgTuple:
13438 case ZigTypeIdOpaque:13437 case ZigTypeIdOpaque:
...@@ -14616,7 +14615,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_...@@ -14616,7 +14615,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_
14616 case ZigTypeIdEnum:14615 case ZigTypeIdEnum:
14617 case ZigTypeIdUnion:14616 case ZigTypeIdUnion:
14618 case ZigTypeIdFn:14617 case ZigTypeIdFn:
14619 case ZigTypeIdNamespace:
14620 case ZigTypeIdBoundFn:14618 case ZigTypeIdBoundFn:
14621 case ZigTypeIdArgTuple:14619 case ZigTypeIdArgTuple:
14622 case ZigTypeIdPromise:14620 case ZigTypeIdPromise:
...@@ -15368,7 +15366,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -15368,7 +15366,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
15368 auto entry = container_scope->decl_table.maybe_get(field_name);15366 auto entry = container_scope->decl_table.maybe_get(field_name);
15369 Tld *tld = entry ? entry->value : nullptr;15367 Tld *tld = entry ? entry->value : nullptr;
15370 if (tld && tld->id == TldIdFn) {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 if (tld->resolution == TldResolutionInvalid)15370 if (tld->resolution == TldResolutionInvalid)
15373 return ira->codegen->invalid_instruction;15371 return ira->codegen->invalid_instruction;
15374 TldFn *tld_fn = (TldFn *)tld;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,8 +15555,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
1555715555
1555815556
15559static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {15557static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
15560 bool pointer_only = false;15558 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node);
15561 resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
15562 if (tld->resolution == TldResolutionInvalid)15559 if (tld->resolution == TldResolutionInvalid)
15563 return ira->codegen->invalid_instruction;15560 return ira->codegen->invalid_instruction;
1556415561
...@@ -15971,37 +15968,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -15971,37 +15968,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
15971 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));15968 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
15972 return ira->codegen->invalid_instruction;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 } else {15971 } else {
16006 ir_add_error_node(ira, field_ptr_instruction->base.source_node,15972 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
16007 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));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,7 +16247,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
16281 case ZigTypeIdEnum:16247 case ZigTypeIdEnum:
16282 case ZigTypeIdUnion:16248 case ZigTypeIdUnion:
16283 case ZigTypeIdFn:16249 case ZigTypeIdFn:
16284 case ZigTypeIdNamespace:
16285 case ZigTypeIdBoundFn:16250 case ZigTypeIdBoundFn:
16286 case ZigTypeIdPromise:16251 case ZigTypeIdPromise:
16287 case ZigTypeIdVector:16252 case ZigTypeIdVector:
...@@ -16402,7 +16367,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -16402,7 +16367,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
16402 case ZigTypeIdEnum:16367 case ZigTypeIdEnum:
16403 case ZigTypeIdUnion:16368 case ZigTypeIdUnion:
16404 case ZigTypeIdFn:16369 case ZigTypeIdFn:
16405 case ZigTypeIdNamespace:
16406 case ZigTypeIdBoundFn:16370 case ZigTypeIdBoundFn:
16407 case ZigTypeIdPromise:16371 case ZigTypeIdPromise:
16408 case ZigTypeIdVector:16372 case ZigTypeIdVector:
...@@ -16452,7 +16416,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -16452,7 +16416,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
16452 case ZigTypeIdComptimeInt:16416 case ZigTypeIdComptimeInt:
16453 case ZigTypeIdBoundFn:16417 case ZigTypeIdBoundFn:
16454 case ZigTypeIdMetaType:16418 case ZigTypeIdMetaType:
16455 case ZigTypeIdNamespace:
16456 case ZigTypeIdArgTuple:16419 case ZigTypeIdArgTuple:
16457 case ZigTypeIdOpaque:16420 case ZigTypeIdOpaque:
16458 ir_add_error_node(ira, size_of_instruction->base.source_node,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,7 +16823,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16860 case ZigTypeIdPointer:16823 case ZigTypeIdPointer:
16861 case ZigTypeIdPromise:16824 case ZigTypeIdPromise:
16862 case ZigTypeIdFn:16825 case ZigTypeIdFn:
16863 case ZigTypeIdNamespace:
16864 case ZigTypeIdErrorSet: {16826 case ZigTypeIdErrorSet: {
16865 if (pointee_val) {16827 if (pointee_val) {
16866 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);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,25 +16971,25 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
17009 return ira->codegen->invalid_instruction;16971 return ira->codegen->invalid_instruction;
1701016972
17011 AstNode *source_node = import_instruction->base.source_node;16973 AstNode *source_node = import_instruction->base.source_node;
17012 ImportTableEntry *import = source_node->owner;16974 ZigType *import = source_node->owner;
1701316975
17014 Buf *import_target_path;16976 Buf *import_target_path;
17015 Buf *search_dir;16977 Buf *search_dir;
17016 assert(import->package);16978 assert(import->data.structure.root_struct->package);
17017 PackageTableEntry *target_package;16979 ZigPackage *target_package;
17018 auto package_entry = import->package->package_table.maybe_get(import_target_str);16980 auto package_entry = import->data.structure.root_struct->package->package_table.maybe_get(import_target_str);
17019 if (package_entry) {16981 if (package_entry) {
17020 target_package = package_entry->value;16982 target_package = package_entry->value;
17021 import_target_path = &target_package->root_src_path;16983 import_target_path = &target_package->root_src_path;
17022 search_dir = &target_package->root_src_dir;16984 search_dir = &target_package->root_src_dir;
17023 } else {16985 } else {
17024 // try it as a filename16986 // try it as a filename
17025 target_package = import->package;16987 target_package = import->data.structure.root_struct->package;
17026 import_target_path = import_target_str;16988 import_target_path = import_target_str;
1702716989
17028 // search relative to importing file16990 // search relative to importing file
17029 search_dir = buf_alloc();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 }
1703216994
17033 Buf full_path = BUF_INIT;16995 Buf full_path = BUF_INIT;
...@@ -17041,10 +17003,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio...@@ -17041,10 +17003,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
1704117003
17042 auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);17004 auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);
17043 if (import_entry) {17005 if (import_entry) {
17044 IrInstruction *result = ir_const(ira, &import_instruction->base,17006 return ir_const_type(ira, &import_instruction->base, import_entry->value);
17045 ira->codegen->builtin_types.entry_namespace);
17046 result->value.data.x_import = import_entry->value;
17047 return result;
17048 }17007 }
1704917008
17050 if ((err = file_fetch(ira->codegen, resolved_path, import_code))) {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,13 +17018,11 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
17059 }17018 }
17060 }17019 }
1706117020
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);
1706317022
17064 scan_import(ira->codegen, target_import);17023 scan_import(ira->codegen, target_import);
1706517024
17066 IrInstruction *result = ir_const(ira, &import_instruction->base, ira->codegen->builtin_types.entry_namespace);17025 return ir_const_type(ira, &import_instruction->base, target_import);
17067 result->value.data.x_import = target_import;
17068 return result;
17069}17026}
1707017027
17071static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {17028static 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,7 +17698,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
17741 while ((curr_entry = decl_it.next()) != nullptr) {17698 while ((curr_entry = decl_it.next()) != nullptr) {
17742 // If the definition is unresolved, force it to be resolved again.17699 // If the definition is unresolved, force it to be resolved again.
17743 if (curr_entry->value->resolution == TldResolutionUnresolved) {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 if (curr_entry->value->resolution != TldResolutionOk) {17702 if (curr_entry->value->resolution != TldResolutionOk) {
17746 return ErrorSemanticAnalyzeFail;17703 return ErrorSemanticAnalyzeFail;
17747 }17704 }
...@@ -18056,7 +18013,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy...@@ -18056,7 +18013,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
18056 case ZigTypeIdComptimeInt:18013 case ZigTypeIdComptimeInt:
18057 case ZigTypeIdUndefined:18014 case ZigTypeIdUndefined:
18058 case ZigTypeIdNull:18015 case ZigTypeIdNull:
18059 case ZigTypeIdNamespace:
18060 case ZigTypeIdArgTuple:18016 case ZigTypeIdArgTuple:
18061 case ZigTypeIdOpaque:18017 case ZigTypeIdOpaque:
18062 *out = nullptr;18018 *out = nullptr;
...@@ -18702,14 +18658,14 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -18702,14 +18658,14 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
18702 if (type_is_invalid(cimport_result->type))18658 if (type_is_invalid(cimport_result->type))
18703 return ira->codegen->invalid_instruction;18659 return ira->codegen->invalid_instruction;
1870418660
18705 ImportTableEntry *child_import = allocate<ImportTableEntry>(1);18661 RootStruct *root_struct = allocate<RootStruct>(1);
18706 child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import);18662 root_struct->package = new_anonymous_package();
18707 child_import->c_import_node = node;18663 root_struct->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);
18708 child_import->package = new_anonymous_package();18664 root_struct->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
18709 child_import->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);18665 root_struct->c_import_node = node;
18710 child_import->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);18666 root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
18711 child_import->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
18712 buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str(".")));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);
1871318669
18714 ZigList<ErrorMsg *> errors = {0};18670 ZigList<ErrorMsg *> errors = {0};
1871518671
...@@ -18738,14 +18694,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -18738,14 +18694,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
18738 if (ira->codegen->verbose_cimport) {18694 if (ira->codegen->verbose_cimport) {
18739 fprintf(stderr, "\nC imports:\n");18695 fprintf(stderr, "\nC imports:\n");
18740 fprintf(stderr, "-----------\n");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 }
1874318699
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);
1874518701
18746 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_namespace);18702 return ir_const_type(ira, &instruction->base, child_import);
18747 result->value.data.x_import = child_import;
18748 return result;
18749}18703}
1875018704
18751static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {18705static 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,10 +18773,10 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
18819 if (!rel_file_path)18773 if (!rel_file_path)
18820 return ira->codegen->invalid_instruction;18774 return ira->codegen->invalid_instruction;
1882118775
18822 ImportTableEntry *import = get_scope_import(instruction->base.scope);18776 ZigType *import = get_scope_import(instruction->base.scope);
18823 // figure out absolute path to resource18777 // figure out absolute path to resource
18824 Buf source_dir_path = BUF_INIT;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);
1882618780
18827 Buf *resolve_paths[] = {18781 Buf *resolve_paths[] = {
18828 &source_dir_path,18782 &source_dir_path,
...@@ -20179,7 +20133,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -20179,7 +20133,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
20179 case ZigTypeIdComptimeInt:20133 case ZigTypeIdComptimeInt:
20180 case ZigTypeIdUndefined:20134 case ZigTypeIdUndefined:
20181 case ZigTypeIdNull:20135 case ZigTypeIdNull:
20182 case ZigTypeIdNamespace:
20183 case ZigTypeIdBoundFn:20136 case ZigTypeIdBoundFn:
20184 case ZigTypeIdArgTuple:20137 case ZigTypeIdArgTuple:
20185 case ZigTypeIdVoid:20138 case ZigTypeIdVoid:
...@@ -21025,7 +20978,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -21025,7 +20978,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
21025 case ZigTypeIdOpaque:20978 case ZigTypeIdOpaque:
21026 case ZigTypeIdBoundFn:20979 case ZigTypeIdBoundFn:
21027 case ZigTypeIdArgTuple:20980 case ZigTypeIdArgTuple:
21028 case ZigTypeIdNamespace:
21029 case ZigTypeIdUnreachable:20981 case ZigTypeIdUnreachable:
21030 case ZigTypeIdComptimeFloat:20982 case ZigTypeIdComptimeFloat:
21031 case ZigTypeIdComptimeInt:20983 case ZigTypeIdComptimeInt:
...@@ -21185,7 +21137,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -21185,7 +21137,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
21185 case ZigTypeIdOpaque:21137 case ZigTypeIdOpaque:
21186 case ZigTypeIdBoundFn:21138 case ZigTypeIdBoundFn:
21187 case ZigTypeIdArgTuple:21139 case ZigTypeIdArgTuple:
21188 case ZigTypeIdNamespace:
21189 case ZigTypeIdUnreachable:21140 case ZigTypeIdUnreachable:
21190 case ZigTypeIdComptimeFloat:21141 case ZigTypeIdComptimeFloat:
21191 case ZigTypeIdComptimeInt:21142 case ZigTypeIdComptimeInt:
...@@ -21343,7 +21294,6 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -21343,7 +21294,6 @@ static bool type_can_bit_cast(ZigType *t) {
21343 case ZigTypeIdOpaque:21294 case ZigTypeIdOpaque:
21344 case ZigTypeIdBoundFn:21295 case ZigTypeIdBoundFn:
21345 case ZigTypeIdArgTuple:21296 case ZigTypeIdArgTuple:
21346 case ZigTypeIdNamespace:
21347 case ZigTypeIdUnreachable:21297 case ZigTypeIdUnreachable:
21348 case ZigTypeIdComptimeFloat:21298 case ZigTypeIdComptimeFloat:
21349 case ZigTypeIdComptimeInt:21299 case ZigTypeIdComptimeInt:
...@@ -21516,7 +21466,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -21516,7 +21466,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
21516 Tld *tld = instruction->tld;21466 Tld *tld = instruction->tld;
21517 LVal lval = instruction->lval;21467 LVal lval = instruction->lval;
2151821468
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 if (tld->resolution == TldResolutionInvalid)21470 if (tld->resolution == TldResolutionInvalid)
21521 return ira->codegen->invalid_instruction;21471 return ira->codegen->invalid_instruction;
2152221472
src/main.cpp+5-5
...@@ -215,7 +215,7 @@ struct CliPkg {...@@ -215,7 +215,7 @@ struct CliPkg {
215 CliPkg *parent;215 CliPkg *parent;
216};216};
217217
218static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {218static void add_package(CodeGen *g, CliPkg *cli_pkg, ZigPackage *pkg) {
219 for (size_t i = 0; i < cli_pkg->children.length; i += 1) {219 for (size_t i = 0; i < cli_pkg->children.length; i += 1) {
220 CliPkg *child_cli_pkg = cli_pkg->children.at(i);220 CliPkg *child_cli_pkg = cli_pkg->children.at(i);
221221
...@@ -223,10 +223,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {...@@ -223,10 +223,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
223 Buf *basename = buf_alloc();223 Buf *basename = buf_alloc();
224 os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename);224 os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename);
225225
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 auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg);227 auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg);
228 if (entry) {228 if (entry) {
229 PackageTableEntry *existing_pkg = entry->value;229 ZigPackage *existing_pkg = entry->value;
230 Buf *full_path = buf_alloc();230 Buf *full_path = buf_alloc();
231 os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);231 os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);
232 fprintf(stderr, "Unable to add package '%s'->'%s': already exists as '%s'\n",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,7 +543,7 @@ int main(int argc, char **argv) {
543 return EXIT_FAILURE;543 return EXIT_FAILURE;
544 }544 }
545545
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 buf_ptr(&build_file_basename));547 buf_ptr(&build_file_basename));
548 g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg);548 g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg);
549 g->enable_cache = get_cache_opt(enable_cache, true);549 g->enable_cache = get_cache_opt(enable_cache, true);
...@@ -1145,7 +1145,7 @@ int main(int argc, char **argv) {...@@ -1145,7 +1145,7 @@ int main(int argc, char **argv) {
1145 }1145 }
1146 } else if (cmd == CmdTranslateC) {1146 } else if (cmd == CmdTranslateC) {
1147 codegen_translate_c(g, in_file_buf);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 if (timing_info)1149 if (timing_info)
1150 codegen_print_timing_report(g, stdout);1150 codegen_print_timing_report(g, stdout);
1151 return EXIT_SUCCESS;1151 return EXIT_SUCCESS;
src/parser.cpp+10-8
...@@ -18,7 +18,7 @@ struct ParseContext {...@@ -18,7 +18,7 @@ struct ParseContext {
18 Buf *buf;18 Buf *buf;
19 size_t current_token;19 size_t current_token;
20 ZigList<Token> *tokens;20 ZigList<Token> *tokens;
21 ImportTableEntry *owner;21 ZigType *owner;
22 ErrColor err_color;22 ErrColor err_color;
23};23};
2424
...@@ -130,8 +130,10 @@ static void ast_error(ParseContext *pc, Token *token, const char *format, ...) {...@@ -130,8 +130,10 @@ static void ast_error(ParseContext *pc, Token *token, const char *format, ...) {
130 va_end(ap);130 va_end(ap);
131131
132132
133 ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,133 ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
134 pc->owner->source_code, pc->owner->line_offsets, msg);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 err->line_start = token->start_line;137 err->line_start = token->start_line;
136 err->column_start = token->start_column;138 err->column_start = token->start_column;
137139
...@@ -148,8 +150,10 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const...@@ -148,8 +150,10 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const
148 Buf *msg = buf_vprintf(format, ap);150 Buf *msg = buf_vprintf(format, ap);
149 va_end(ap);151 va_end(ap);
150152
151 ErrorMsg *err = err_msg_create_with_line(pc->owner->path, node->line, node->column,153 ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
152 pc->owner->source_code, pc->owner->line_offsets, msg);154 node->line, node->column,
155 pc->owner->data.structure.root_struct->source_code,
156 pc->owner->data.structure.root_struct->line_offsets, msg);
153157
154 print_err_msg(err, pc->err_color);158 print_err_msg(err, pc->err_color);
155 exit(EXIT_FAILURE);159 exit(EXIT_FAILURE);
...@@ -570,9 +574,7 @@ static void ast_parse_asm_template(ParseContext *pc, AstNode *node) {...@@ -570,9 +574,7 @@ static void ast_parse_asm_template(ParseContext *pc, AstNode *node) {
570 }574 }
571}575}
572576
573AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,577AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color) {
574 ErrColor err_color)
575{
576 ParseContext pc = {};578 ParseContext pc = {};
577 pc.err_color = err_color;579 pc.err_color = err_color;
578 pc.owner = owner;580 pc.owner = owner;
src/parser.hpp+1-1
...@@ -16,7 +16,7 @@ ATTRIBUTE_PRINTF(2, 3)...@@ -16,7 +16,7 @@ ATTRIBUTE_PRINTF(2, 3)
16void ast_token_error(Token *token, const char *format, ...);16void ast_token_error(Token *token, const char *format, ...);
1717
1818
19AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color);19AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color);
2020
21void ast_print(AstNode *node, int indent);21void ast_print(AstNode *node, int indent);
2222
src/translate_c.cpp+5-4
...@@ -76,7 +76,7 @@ struct TransScopeWhile {...@@ -76,7 +76,7 @@ struct TransScopeWhile {
76};76};
7777
78struct Context {78struct Context {
79 ImportTableEntry *import;79 ZigType *import;
80 ZigList<ErrorMsg *> *errors;80 ZigList<ErrorMsg *> *errors;
81 VisibMod visib_mod;81 VisibMod visib_mod;
82 bool want_export;82 bool want_export;
...@@ -4732,7 +4732,7 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) {...@@ -4732,7 +4732,7 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) {
4732 }4732 }
4733}4733}
47344734
4735Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source,4735Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source,
4736 CodeGen *codegen, AstNode *source_node)4736 CodeGen *codegen, AstNode *source_node)
4737{4737{
4738 Error err;4738 Error err;
...@@ -4748,7 +4748,7 @@ Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *so...@@ -4748,7 +4748,7 @@ Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *so
4748 return err;4748 return err;
4749}4749}
47504750
4751Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file,4751Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file,
4752 CodeGen *codegen, AstNode *source_node)4752 CodeGen *codegen, AstNode *source_node)
4753{4753{
4754 Context context = {0};4754 Context context = {0};
...@@ -4958,7 +4958,8 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const...@@ -4958,7 +4958,8 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const
4958 render_macros(c);4958 render_macros(c);
4959 render_aliases(c);4959 render_aliases(c);
49604960
4961 import->root = c->root;4961 import->data.structure.decl_node = c->root;
4962 import->data.structure.decls_scope->base.source_node = c->root;
49624963
4963 return ErrorNone;4964 return ErrorNone;
4964}4965}
src/translate_c.hpp+2-2
...@@ -11,10 +11,10 @@...@@ -11,10 +11,10 @@
1111
12#include "all_types.hpp"12#include "all_types.hpp"
1313
14Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file,14Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file,
15 CodeGen *codegen, AstNode *source_node);15 CodeGen *codegen, AstNode *source_node);
1616
17Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source,17Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source,
18 CodeGen *codegen, AstNode *source_node);18 CodeGen *codegen, AstNode *source_node);
1919
20#endif20#endif
std/hash_map.zig-2
...@@ -486,7 +486,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type...@@ -486,7 +486,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type
486 builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng),486 builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng),
487 builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng),487 builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng),
488488
489 builtin.TypeId.Namespace,
490 builtin.TypeId.BoundFn,489 builtin.TypeId.BoundFn,
491 builtin.TypeId.ComptimeFloat,490 builtin.TypeId.ComptimeFloat,
492 builtin.TypeId.ComptimeInt,491 builtin.TypeId.ComptimeInt,
...@@ -532,7 +531,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool {...@@ -532,7 +531,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool {
532 builtin.TypeId.Float,531 builtin.TypeId.Float,
533 builtin.TypeId.ComptimeFloat,532 builtin.TypeId.ComptimeFloat,
534 builtin.TypeId.ComptimeInt,533 builtin.TypeId.ComptimeInt,
535 builtin.TypeId.Namespace,
536 builtin.TypeId.Promise,534 builtin.TypeId.Promise,
537 builtin.TypeId.Enum,535 builtin.TypeId.Enum,
538 builtin.TypeId.BoundFn,536 builtin.TypeId.BoundFn,
std/testing.zig-1
...@@ -44,7 +44,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -44,7 +44,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
44 TypeId.ComptimeFloat,44 TypeId.ComptimeFloat,
45 TypeId.ComptimeInt,45 TypeId.ComptimeInt,
46 TypeId.Enum,46 TypeId.Enum,
47 TypeId.Namespace,
48 TypeId.Fn,47 TypeId.Fn,
49 TypeId.Promise,48 TypeId.Promise,
50 TypeId.Vector,49 TypeId.Vector,
test/compile_errors.zig+41-41
...@@ -2,6 +2,47 @@ const tests = @import("tests.zig");...@@ -2,6 +2,47 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub 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 cases.addTest(46 cases.addTest(
6 "not an enum type",47 "not an enum type",
7 \\export fn entry() void {48 \\export fn entry() void {
...@@ -917,23 +958,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -917,23 +958,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
917 ".tmp_source.zig:1:1: error: non-extern function has no body",958 ".tmp_source.zig:1:1: error: non-extern function has no body",
918 );959 );
919960
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 cases.add(961 cases.add(
938 "@handle() called outside of function definition",962 "@handle() called outside of function definition",
939 \\var handle_undef: promise = undefined;963 \\var handle_undef: promise = undefined;
...@@ -1182,19 +1206,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1182,19 +1206,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1182 break :x tc;1206 break :x tc;
1183 });1207 });
11841208
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 cases.add(1209 cases.add(
1199 "@floatToInt comptime safety",1210 "@floatToInt comptime safety",
1200 \\comptime {1211 \\comptime {
...@@ -2622,17 +2633,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2622,17 +2633,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2622 ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'",2633 ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'",
2623 );2634 );
26242635
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 cases.add(2636 cases.add(
2637 "noalias on non pointer param",2637 "noalias on non pointer param",
2638 \\fn f(noalias x: i32) void {}2638 \\fn f(noalias x: i32) void {}
test/stage1/behavior/misc.zig+1-1
...@@ -469,7 +469,7 @@ test "@typeId" {...@@ -469,7 +469,7 @@ test "@typeId" {
469 expect(@typeId(AUnionEnum) == Tid.Union);469 expect(@typeId(AUnionEnum) == Tid.Union);
470 expect(@typeId(AUnion) == Tid.Union);470 expect(@typeId(AUnion) == Tid.Union);
471 expect(@typeId(fn () void) == Tid.Fn);471 expect(@typeId(fn () void) == Tid.Fn);
472 expect(@typeId(@typeOf(builtin)) == Tid.Namespace);472 expect(@typeId(@typeOf(builtin)) == Tid.Type);
473 // TODO bound fn473 // TODO bound fn
474 // TODO arg tuple474 // TODO arg tuple
475 // TODO opaque475 // TODO opaque
test/stage1/behavior/type_info.zig+1-1
...@@ -186,7 +186,7 @@ fn testUnion() void {...@@ -186,7 +186,7 @@ fn testUnion() void {
186 expect(TypeId(typeinfo_info) == TypeId.Union);186 expect(TypeId(typeinfo_info) == TypeId.Union);
187 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);187 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
188 expect(typeinfo_info.Union.tag_type.? == TypeId);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 expect(typeinfo_info.Union.fields[4].enum_field != null);190 expect(typeinfo_info.Union.fields[4].enum_field != null);
191 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);191 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
192 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));192 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));