authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 12:30:57-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 12:30:57-04:00
logc9474faa4e6cfd6480c1bd24216c26f4320e3c29
tree4bf022698f229cd276b598ed95aa30a61e882674
parentf27d82fe90e1d0007bf2d3ef52eac8cdbc381e0d
parent7c9f7b72c59e7c6de38038f512ae332fc164e8d7
signaturelock-open Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into llvm7


33 files changed, 5794 insertions(+), 3670 deletions(-)

CMakeLists.txt+14-9
......@@ -199,7 +199,7 @@ else()
199199 if(MSVC)
200200 set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -D_CRT_SECURE_NO_WARNINGS /w")
201201 else()
202 set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment -Wno-class-memaccess -Wno-unknown-warning-option")
202 set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment")
203203 endif()
204204 set_target_properties(embedded_lld_lib PROPERTIES
205205 COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS}
......@@ -775,20 +775,25 @@ include_directories(
775775 "${CMAKE_SOURCE_DIR}/src"
776776)
777777
778if(MSVC)
779 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w")
780elseif(MINGW)
781 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
782else()
783 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -Wall")
778# These have to go before the -Wno- flags
779set(EXE_CFLAGS "-std=c++11")
780if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
781 if(MSVC)
782 set(EXE_CFLAGS "${EXE_CFLAGS} /w")
783 elseif(MINGW)
784 set(EXE_CFLAGS "${EXE_CFLAGS} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
785 else()
786 set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall")
787 endif()
784788endif()
785789
786790if(MSVC)
787 set(EXE_CFLAGS "-std=c++11")
791 set(EXE_CFLAGS "${EXE_CFLAGS}")
788792else()
789 set(EXE_CFLAGS "-std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
793 set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
790794endif()
791795
796
792797set(EXE_LDFLAGS " ")
793798if(MINGW)
794799 set(EXE_LDFLAGS "-static -static-libgcc -static-libstdc++")
doc/langref.html.in+1-1
......@@ -1587,7 +1587,7 @@ test "pointer casting" {
15871587 // operation that Zig cannot protect you against. Use @ptrCast only when other
15881588 // conversions are not possible.
15891589 const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 };
1590 const u32_ptr = @ptrCast(*const u32, &bytes[0]);
1590 const u32_ptr = @ptrCast(*const u32, &bytes);
15911591 assert(u32_ptr.* == 0x12121212);
15921592
15931593 // Even this example is contrived - there are better ways to do the above than
src/all_types.hpp+249-174
......@@ -20,12 +20,12 @@
2020
2121struct AstNode;
2222struct ImportTableEntry;
23struct FnTableEntry;
23struct ZigFn;
2424struct Scope;
2525struct ScopeBlock;
2626struct ScopeFnDef;
27struct TypeTableEntry;
28struct VariableTableEntry;
27struct ZigType;
28struct ZigVar;
2929struct ErrorTableEntry;
3030struct BuiltinFnEntry;
3131struct TypeStructField;
......@@ -40,10 +40,17 @@ struct Tld;
4040struct TldExport;
4141struct IrAnalyze;
4242
43enum X64CABIClass {
44 X64CABIClass_Unknown,
45 X64CABIClass_MEMORY,
46 X64CABIClass_INTEGER,
47 X64CABIClass_SSE,
48};
49
4350struct IrExecutable {
4451 ZigList<IrBasicBlock *> basic_block_list;
4552 Buf *name;
46 FnTableEntry *name_fn;
53 ZigFn *name_fn;
4754 size_t mem_slot_count;
4855 size_t next_debug_id;
4956 size_t *backward_branch_count;
......@@ -51,7 +58,7 @@ struct IrExecutable {
5158 bool invalid;
5259 bool is_inline;
5360 bool is_generic_instantiation;
54 FnTableEntry *fn_entry;
61 ZigFn *fn_entry;
5562 Buf *c_import_buf;
5663 AstNode *source_node;
5764 IrExecutable *parent_exec;
......@@ -69,7 +76,7 @@ struct IrExecutable {
6976 IrBasicBlock *coro_normal_final;
7077 IrBasicBlock *coro_suspend_block;
7178 IrBasicBlock *coro_final_cleanup_block;
72 VariableTableEntry *coro_allocator_var;
79 ZigVar *coro_allocator_var;
7380};
7481
7582enum OutType {
......@@ -191,7 +198,7 @@ struct ConstPtrValue {
191198 uint64_t addr;
192199 } hard_coded_addr;
193200 struct {
194 FnTableEntry *fn_entry;
201 ZigFn *fn_entry;
195202 } fn;
196203 } data;
197204};
......@@ -202,7 +209,7 @@ struct ConstErrValue {
202209};
203210
204211struct ConstBoundFnValue {
205 FnTableEntry *fn;
212 ZigFn *fn;
206213 IrInstruction *first_arg;
207214};
208215
......@@ -251,7 +258,7 @@ struct ConstGlobalRefs {
251258};
252259
253260struct ConstExprValue {
254 TypeTableEntry *type;
261 ZigType *type;
255262 ConstValSpecial special;
256263 ConstGlobalRefs *global_refs;
257264
......@@ -265,7 +272,7 @@ struct ConstExprValue {
265272 float128_t x_f128;
266273 bool x_bool;
267274 ConstBoundFnValue x_bound_fn;
268 TypeTableEntry *x_type;
275 ZigType *x_type;
269276 ConstExprValue *x_optional;
270277 ConstErrValue x_err_union;
271278 ErrorTableEntry *x_err_set;
......@@ -337,7 +344,7 @@ struct Tld {
337344struct TldVar {
338345 Tld base;
339346
340 VariableTableEntry *var;
347 ZigVar *var;
341348 Buf *extern_lib_name;
342349 Buf *section_name;
343350};
......@@ -345,7 +352,7 @@ struct TldVar {
345352struct TldFn {
346353 Tld base;
347354
348 FnTableEntry *fn_entry;
355 ZigFn *fn_entry;
349356 Buf *extern_lib_name;
350357};
351358
......@@ -353,7 +360,7 @@ struct TldContainer {
353360 Tld base;
354361
355362 ScopeDecls *decls_scope;
356 TypeTableEntry *type_entry;
363 ZigType *type_entry;
357364};
358365
359366struct TldCompTime {
......@@ -370,7 +377,7 @@ struct TypeEnumField {
370377struct TypeUnionField {
371378 Buf *name;
372379 TypeEnumField *enum_field;
373 TypeTableEntry *type_entry;
380 ZigType *type_entry;
374381 AstNode *decl_node;
375382 uint32_t gen_index;
376383};
......@@ -973,11 +980,11 @@ struct AstNode {
973980// this struct is allocated with allocate_nonzero
974981struct FnTypeParamInfo {
975982 bool is_noalias;
976 TypeTableEntry *type;
983 ZigType *type;
977984};
978985
979986struct GenericFnTypeId {
980 FnTableEntry *fn_entry;
987 ZigFn *fn_entry;
981988 ConstExprValue *params;
982989 size_t param_count;
983990};
......@@ -986,14 +993,14 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
986993bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);
987994
988995struct FnTypeId {
989 TypeTableEntry *return_type;
996 ZigType *return_type;
990997 FnTypeParamInfo *param_info;
991998 size_t param_count;
992999 size_t next_param_index;
9931000 bool is_var_args;
9941001 CallingConvention cc;
9951002 uint32_t alignment;
996 TypeTableEntry *async_allocator_type;
1003 ZigType *async_allocator_type;
9971004};
9981005
9991006uint32_t fn_type_id_hash(FnTypeId*);
......@@ -1004,34 +1011,34 @@ enum PtrLen {
10041011 PtrLenSingle,
10051012};
10061013
1007struct TypeTableEntryPointer {
1008 TypeTableEntry *child_type;
1014struct ZigTypePointer {
1015 ZigType *child_type;
10091016 PtrLen ptr_len;
10101017 bool is_const;
10111018 bool is_volatile;
10121019 uint32_t alignment;
10131020 uint32_t bit_offset;
10141021 uint32_t unaligned_bit_count;
1015 TypeTableEntry *slice_parent;
1022 ZigType *slice_parent;
10161023};
10171024
1018struct TypeTableEntryInt {
1025struct ZigTypeInt {
10191026 uint32_t bit_count;
10201027 bool is_signed;
10211028};
10221029
1023struct TypeTableEntryFloat {
1030struct ZigTypeFloat {
10241031 size_t bit_count;
10251032};
10261033
1027struct TypeTableEntryArray {
1028 TypeTableEntry *child_type;
1034struct ZigTypeArray {
1035 ZigType *child_type;
10291036 uint64_t len;
10301037};
10311038
10321039struct TypeStructField {
10331040 Buf *name;
1034 TypeTableEntry *type_entry;
1041 ZigType *type_entry;
10351042 size_t src_index;
10361043 size_t gen_index;
10371044 // offset from the memory at gen_index
......@@ -1040,7 +1047,7 @@ struct TypeStructField {
10401047 size_t unaligned_bit_count;
10411048 AstNode *decl_node;
10421049};
1043struct TypeTableEntryStruct {
1050struct ZigTypeStruct {
10441051 AstNode *decl_node;
10451052 ContainerLayout layout;
10461053 uint32_t src_field_count;
......@@ -1068,28 +1075,28 @@ struct TypeTableEntryStruct {
10681075 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
10691076};
10701077
1071struct TypeTableEntryOptional {
1072 TypeTableEntry *child_type;
1078struct ZigTypeOptional {
1079 ZigType *child_type;
10731080};
10741081
1075struct TypeTableEntryErrorUnion {
1076 TypeTableEntry *err_set_type;
1077 TypeTableEntry *payload_type;
1082struct ZigTypeErrorUnion {
1083 ZigType *err_set_type;
1084 ZigType *payload_type;
10781085};
10791086
1080struct TypeTableEntryErrorSet {
1087struct ZigTypeErrorSet {
10811088 uint32_t err_count;
10821089 ErrorTableEntry **errors;
1083 FnTableEntry *infer_fn;
1090 ZigFn *infer_fn;
10841091};
10851092
1086struct TypeTableEntryEnum {
1093struct ZigTypeEnum {
10871094 AstNode *decl_node;
10881095 ContainerLayout layout;
10891096 uint32_t src_field_count;
10901097 TypeEnumField *fields;
10911098 bool is_invalid; // true if any fields are invalid
1092 TypeTableEntry *tag_int_type;
1099 ZigType *tag_int_type;
10931100
10941101 ScopeDecls *decls_scope;
10951102
......@@ -1107,17 +1114,17 @@ struct TypeTableEntryEnum {
11071114 HashMap<Buf *, TypeEnumField *, buf_hash, buf_eql_buf> fields_by_name;
11081115};
11091116
1110uint32_t type_ptr_hash(const TypeTableEntry *ptr);
1111bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b);
1117uint32_t type_ptr_hash(const ZigType *ptr);
1118bool type_ptr_eql(const ZigType *a, const ZigType *b);
11121119
1113struct TypeTableEntryUnion {
1120struct ZigTypeUnion {
11141121 AstNode *decl_node;
11151122 ContainerLayout layout;
11161123 uint32_t src_field_count;
11171124 uint32_t gen_field_count;
11181125 TypeUnionField *fields;
11191126 bool is_invalid; // true if any fields are invalid
1120 TypeTableEntry *tag_type; // always an enum or null
1127 ZigType *tag_type; // always an enum or null
11211128 LLVMTypeRef union_type_ref;
11221129
11231130 ScopeDecls *decls_scope;
......@@ -1142,7 +1149,7 @@ struct TypeTableEntryUnion {
11421149 bool have_explicit_tag_type;
11431150
11441151 uint32_t union_size_bytes;
1145 TypeTableEntry *most_aligned_union_member;
1152 ZigType *most_aligned_union_member;
11461153
11471154 HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;
11481155};
......@@ -1151,61 +1158,61 @@ struct FnGenParamInfo {
11511158 size_t src_index;
11521159 size_t gen_index;
11531160 bool is_byval;
1154 TypeTableEntry *type;
1161 ZigType *type;
11551162};
11561163
1157struct TypeTableEntryFn {
1164struct ZigTypeFn {
11581165 FnTypeId fn_type_id;
11591166 bool is_generic;
1160 TypeTableEntry *gen_return_type;
1167 ZigType *gen_return_type;
11611168 size_t gen_param_count;
11621169 FnGenParamInfo *gen_param_info;
11631170
11641171 LLVMTypeRef raw_type_ref;
11651172
1166 TypeTableEntry *bound_fn_parent;
1173 ZigType *bound_fn_parent;
11671174};
11681175
1169struct TypeTableEntryBoundFn {
1170 TypeTableEntry *fn_type;
1176struct ZigTypeBoundFn {
1177 ZigType *fn_type;
11711178};
11721179
1173struct TypeTableEntryPromise {
1180struct ZigTypePromise {
11741181 // null if `promise` instead of `promise->T`
1175 TypeTableEntry *result_type;
1176};
1177
1178enum TypeTableEntryId {
1179 TypeTableEntryIdInvalid,
1180 TypeTableEntryIdMetaType,
1181 TypeTableEntryIdVoid,
1182 TypeTableEntryIdBool,
1183 TypeTableEntryIdUnreachable,
1184 TypeTableEntryIdInt,
1185 TypeTableEntryIdFloat,
1186 TypeTableEntryIdPointer,
1187 TypeTableEntryIdArray,
1188 TypeTableEntryIdStruct,
1189 TypeTableEntryIdComptimeFloat,
1190 TypeTableEntryIdComptimeInt,
1191 TypeTableEntryIdUndefined,
1192 TypeTableEntryIdNull,
1193 TypeTableEntryIdOptional,
1194 TypeTableEntryIdErrorUnion,
1195 TypeTableEntryIdErrorSet,
1196 TypeTableEntryIdEnum,
1197 TypeTableEntryIdUnion,
1198 TypeTableEntryIdFn,
1199 TypeTableEntryIdNamespace,
1200 TypeTableEntryIdBlock,
1201 TypeTableEntryIdBoundFn,
1202 TypeTableEntryIdArgTuple,
1203 TypeTableEntryIdOpaque,
1204 TypeTableEntryIdPromise,
1205};
1206
1207struct TypeTableEntry {
1208 TypeTableEntryId id;
1182 ZigType *result_type;
1183};
1184
1185enum ZigTypeId {
1186 ZigTypeIdInvalid,
1187 ZigTypeIdMetaType,
1188 ZigTypeIdVoid,
1189 ZigTypeIdBool,
1190 ZigTypeIdUnreachable,
1191 ZigTypeIdInt,
1192 ZigTypeIdFloat,
1193 ZigTypeIdPointer,
1194 ZigTypeIdArray,
1195 ZigTypeIdStruct,
1196 ZigTypeIdComptimeFloat,
1197 ZigTypeIdComptimeInt,
1198 ZigTypeIdUndefined,
1199 ZigTypeIdNull,
1200 ZigTypeIdOptional,
1201 ZigTypeIdErrorUnion,
1202 ZigTypeIdErrorSet,
1203 ZigTypeIdEnum,
1204 ZigTypeIdUnion,
1205 ZigTypeIdFn,
1206 ZigTypeIdNamespace,
1207 ZigTypeIdBlock,
1208 ZigTypeIdBoundFn,
1209 ZigTypeIdArgTuple,
1210 ZigTypeIdOpaque,
1211 ZigTypeIdPromise,
1212};
1213
1214struct ZigType {
1215 ZigTypeId id;
12091216 Buf name;
12101217
12111218 LLVMTypeRef type_ref;
......@@ -1216,26 +1223,26 @@ struct TypeTableEntry {
12161223 bool gen_h_loop_flag;
12171224
12181225 union {
1219 TypeTableEntryPointer pointer;
1220 TypeTableEntryInt integral;
1221 TypeTableEntryFloat floating;
1222 TypeTableEntryArray array;
1223 TypeTableEntryStruct structure;
1224 TypeTableEntryOptional maybe;
1225 TypeTableEntryErrorUnion error_union;
1226 TypeTableEntryErrorSet error_set;
1227 TypeTableEntryEnum enumeration;
1228 TypeTableEntryUnion unionation;
1229 TypeTableEntryFn fn;
1230 TypeTableEntryBoundFn bound_fn;
1231 TypeTableEntryPromise promise;
1226 ZigTypePointer pointer;
1227 ZigTypeInt integral;
1228 ZigTypeFloat floating;
1229 ZigTypeArray array;
1230 ZigTypeStruct structure;
1231 ZigTypeOptional maybe;
1232 ZigTypeErrorUnion error_union;
1233 ZigTypeErrorSet error_set;
1234 ZigTypeEnum enumeration;
1235 ZigTypeUnion unionation;
1236 ZigTypeFn fn;
1237 ZigTypeBoundFn bound_fn;
1238 ZigTypePromise promise;
12321239 } data;
12331240
12341241 // use these fields to make sure we don't duplicate type table entries for the same type
1235 TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const]
1236 TypeTableEntry *optional_parent;
1237 TypeTableEntry *promise_parent;
1238 TypeTableEntry *promise_frame_parent;
1242 ZigType *pointer_parent[2]; // [0 - mut, 1 - const]
1243 ZigType *optional_parent;
1244 ZigType *promise_parent;
1245 ZigType *promise_frame_parent;
12391246 // If we generate a constant name value for this type, we memoize it here.
12401247 // The type of this is array
12411248 ConstExprValue *cached_const_name_val;
......@@ -1282,7 +1289,7 @@ struct FnExport {
12821289 GlobalLinkageId linkage;
12831290};
12841291
1285struct FnTableEntry {
1292struct ZigFn {
12861293 LLVMValueRef llvm_value;
12871294 const char *llvm_name;
12881295 AstNode *proto_node;
......@@ -1291,11 +1298,11 @@ struct FnTableEntry {
12911298 Scope *child_scope; // parent is scope for last parameter
12921299 ScopeBlock *def_scope; // parent is child_scope
12931300 Buf symbol_name;
1294 TypeTableEntry *type_entry; // function type
1301 ZigType *type_entry; // function type
12951302 // in the case of normal functions this is the implicit return type
12961303 // in the case of async functions this is the implicit return type according to the
12971304 // zig source code, not according to zig ir
1298 TypeTableEntry *src_implicit_return_type;
1305 ZigType *src_implicit_return_type;
12991306 bool is_test;
13001307 FnInline fn_inline;
13011308 FnAnalState anal_state;
......@@ -1310,7 +1317,7 @@ struct FnTableEntry {
13101317 AstNode *fn_static_eval_set_node;
13111318
13121319 ZigList<IrInstruction *> alloca_list;
1313 ZigList<VariableTableEntry *> variable_list;
1320 ZigList<ZigVar *> variable_list;
13141321
13151322 Buf *section_name;
13161323 AstNode *set_alignstack_node;
......@@ -1323,8 +1330,8 @@ struct FnTableEntry {
13231330 bool calls_or_awaits_errorable_fn;
13241331};
13251332
1326uint32_t fn_table_entry_hash(FnTableEntry*);
1327bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b);
1333uint32_t fn_table_entry_hash(ZigFn*);
1334bool fn_table_entry_eql(ZigFn *a, ZigFn *b);
13281335
13291336enum BuiltinFnId {
13301337 BuiltinFnIdInvalid,
......@@ -1445,11 +1452,11 @@ uint32_t fn_eval_hash(Scope*);
14451452bool fn_eval_eql(Scope *a, Scope *b);
14461453
14471454struct TypeId {
1448 TypeTableEntryId id;
1455 ZigTypeId id;
14491456
14501457 union {
14511458 struct {
1452 TypeTableEntry *child_type;
1459 ZigType *child_type;
14531460 PtrLen ptr_len;
14541461 bool is_const;
14551462 bool is_volatile;
......@@ -1458,7 +1465,7 @@ struct TypeId {
14581465 uint32_t unaligned_bit_count;
14591466 } pointer;
14601467 struct {
1461 TypeTableEntry *child_type;
1468 ZigType *child_type;
14621469 uint64_t size;
14631470 } array;
14641471 struct {
......@@ -1466,8 +1473,8 @@ struct TypeId {
14661473 uint32_t bit_count;
14671474 } integer;
14681475 struct {
1469 TypeTableEntry *err_set_type;
1470 TypeTableEntry *payload_type;
1476 ZigType *err_set_type;
1477 ZigType *payload_type;
14711478 } error_union;
14721479 } data;
14731480};
......@@ -1563,17 +1570,17 @@ struct CodeGen {
15631570 // reminder: hash tables must be initialized before use
15641571 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
15651572 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
1566 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;
1567 HashMap<TypeId, TypeTableEntry *, type_id_hash, type_id_eql> type_table;
1568 HashMap<FnTypeId *, TypeTableEntry *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
1573 HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
1574 HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
1575 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
15691576 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;
1570 HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
1577 HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
15711578 HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
15721579 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
15731580 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> exported_symbol_names;
15741581 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
15751582 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
1576 HashMap<const TypeTableEntry *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1583 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
15771584
15781585
15791586 ZigList<ImportTableEntry *> import_queue;
......@@ -1586,38 +1593,38 @@ struct CodeGen {
15861593 uint32_t next_unresolved_index;
15871594
15881595 struct {
1589 TypeTableEntry *entry_bool;
1590 TypeTableEntry *entry_c_int[CIntTypeCount];
1591 TypeTableEntry *entry_c_longdouble;
1592 TypeTableEntry *entry_c_void;
1593 TypeTableEntry *entry_u8;
1594 TypeTableEntry *entry_u16;
1595 TypeTableEntry *entry_u32;
1596 TypeTableEntry *entry_u29;
1597 TypeTableEntry *entry_u64;
1598 TypeTableEntry *entry_i8;
1599 TypeTableEntry *entry_i32;
1600 TypeTableEntry *entry_i64;
1601 TypeTableEntry *entry_isize;
1602 TypeTableEntry *entry_usize;
1603 TypeTableEntry *entry_f16;
1604 TypeTableEntry *entry_f32;
1605 TypeTableEntry *entry_f64;
1606 TypeTableEntry *entry_f128;
1607 TypeTableEntry *entry_void;
1608 TypeTableEntry *entry_unreachable;
1609 TypeTableEntry *entry_type;
1610 TypeTableEntry *entry_invalid;
1611 TypeTableEntry *entry_namespace;
1612 TypeTableEntry *entry_block;
1613 TypeTableEntry *entry_num_lit_int;
1614 TypeTableEntry *entry_num_lit_float;
1615 TypeTableEntry *entry_undef;
1616 TypeTableEntry *entry_null;
1617 TypeTableEntry *entry_var;
1618 TypeTableEntry *entry_global_error_set;
1619 TypeTableEntry *entry_arg_tuple;
1620 TypeTableEntry *entry_promise;
1596 ZigType *entry_bool;
1597 ZigType *entry_c_int[CIntTypeCount];
1598 ZigType *entry_c_longdouble;
1599 ZigType *entry_c_void;
1600 ZigType *entry_u8;
1601 ZigType *entry_u16;
1602 ZigType *entry_u32;
1603 ZigType *entry_u29;
1604 ZigType *entry_u64;
1605 ZigType *entry_i8;
1606 ZigType *entry_i32;
1607 ZigType *entry_i64;
1608 ZigType *entry_isize;
1609 ZigType *entry_usize;
1610 ZigType *entry_f16;
1611 ZigType *entry_f32;
1612 ZigType *entry_f64;
1613 ZigType *entry_f128;
1614 ZigType *entry_void;
1615 ZigType *entry_unreachable;
1616 ZigType *entry_type;
1617 ZigType *entry_invalid;
1618 ZigType *entry_namespace;
1619 ZigType *entry_block;
1620 ZigType *entry_num_lit_int;
1621 ZigType *entry_num_lit_float;
1622 ZigType *entry_undef;
1623 ZigType *entry_null;
1624 ZigType *entry_var;
1625 ZigType *entry_global_error_set;
1626 ZigType *entry_arg_tuple;
1627 ZigType *entry_promise;
16211628 } builtin_types;
16221629
16231630 EmitFileType emit_file_type;
......@@ -1672,14 +1679,14 @@ struct CodeGen {
16721679 const char *linker_script;
16731680
16741681 // The function definitions this module includes.
1675 ZigList<FnTableEntry *> fn_defs;
1682 ZigList<ZigFn *> fn_defs;
16761683 size_t fn_defs_index;
16771684 ZigList<TldVar *> global_vars;
16781685
16791686 OutType out_type;
1680 FnTableEntry *cur_fn;
1681 FnTableEntry *main_fn;
1682 FnTableEntry *panic_fn;
1687 ZigFn *cur_fn;
1688 ZigFn *main_fn;
1689 ZigFn *panic_fn;
16831690 LLVMValueRef cur_ret_ptr;
16841691 LLVMValueRef cur_fn_val;
16851692 LLVMValueRef cur_err_ret_trace_val_arg;
......@@ -1732,12 +1739,12 @@ struct CodeGen {
17321739 const char **llvm_argv;
17331740 size_t llvm_argv_len;
17341741
1735 ZigList<FnTableEntry *> test_fns;
1736 TypeTableEntry *test_fn_type;
1742 ZigList<ZigFn *> test_fns;
1743 ZigType *test_fn_type;
17371744
17381745 bool each_lib_rpath;
17391746
1740 TypeTableEntry *err_tag_type;
1747 ZigType *err_tag_type;
17411748 ZigList<ZigLLVMDIEnumerator *> err_enumerators;
17421749 ZigList<ErrorTableEntry *> errors_by_index;
17431750 bool generate_error_name_table;
......@@ -1761,15 +1768,15 @@ struct CodeGen {
17611768
17621769 ZigList<TimeEvent> timing_events;
17631770
1764 Buf *cache_dir;
1771 Buf cache_dir;
17651772 Buf *out_h_path;
17661773
1767 ZigList<FnTableEntry *> inline_fns;
1774 ZigList<ZigFn *> inline_fns;
17681775 ZigList<AstNode *> tld_ref_source_node_stack;
17691776
1770 TypeTableEntry *align_amt_type;
1771 TypeTableEntry *stack_trace_type;
1772 TypeTableEntry *ptr_to_stack_trace_type;
1777 ZigType *align_amt_type;
1778 ZigType *stack_trace_type;
1779 ZigType *ptr_to_stack_trace_type;
17731780
17741781 ZigList<ZigLLVMDIType **> error_di_types;
17751782
......@@ -1784,7 +1791,7 @@ enum VarLinkage {
17841791 VarLinkageExternal,
17851792};
17861793
1787struct VariableTableEntry {
1794struct ZigVar {
17881795 Buf name;
17891796 ConstExprValue *value;
17901797 LLVMValueRef value_ref;
......@@ -1809,14 +1816,14 @@ struct VariableTableEntry {
18091816 // In an inline loop, multiple variables may be created,
18101817 // In this case, a reference to a variable should follow
18111818 // this pointer to the redefined variable.
1812 VariableTableEntry *next_var;
1819 ZigVar *next_var;
18131820};
18141821
18151822struct ErrorTableEntry {
18161823 Buf name;
18171824 uint32_t value;
18181825 AstNode *decl_node;
1819 TypeTableEntry *set_with_only_this_in_it;
1826 ZigType *set_with_only_this_in_it;
18201827 // If we generate a constant error name value for this error, we memoize it here.
18211828 // The type of this is array
18221829 ConstExprValue *cached_error_name_val;
......@@ -1834,6 +1841,7 @@ enum ScopeId {
18341841 ScopeIdFnDef,
18351842 ScopeIdCompTime,
18361843 ScopeIdCoroPrelude,
1844 ScopeIdRuntime,
18371845};
18381846
18391847struct Scope {
......@@ -1859,7 +1867,7 @@ struct ScopeDecls {
18591867 AstNode *fast_math_set_node;
18601868 ImportTableEntry *import;
18611869 // If this is a scope from a container, this is the type entry, otherwise null
1862 TypeTableEntry *container_type;
1870 ZigType *container_type;
18631871};
18641872
18651873// This scope comes from a block expression in user code.
......@@ -1901,7 +1909,7 @@ struct ScopeVarDecl {
19011909 Scope base;
19021910
19031911 // The variable that creates this scope
1904 VariableTableEntry *var;
1912 ZigVar *var;
19051913};
19061914
19071915// This scope is created for a @cImport
......@@ -1926,6 +1934,15 @@ struct ScopeLoop {
19261934 ZigList<IrBasicBlock *> *incoming_blocks;
19271935};
19281936
1937// This scope blocks certain things from working such as comptime continue
1938// inside a runtime if expression.
1939// NodeTypeIfBoolExpr, NodeTypeWhileExpr, NodeTypeForExpr
1940struct ScopeRuntime {
1941 Scope base;
1942
1943 IrInstruction *is_comptime;
1944};
1945
19291946// This scope is created for a suspend block in order to have labeled
19301947// suspend for breaking out of a suspend and for detecting if a suspend
19311948// block is inside a suspend block.
......@@ -1948,7 +1965,7 @@ struct ScopeCompTime {
19481965struct ScopeFnDef {
19491966 Scope base;
19501967
1951 FnTableEntry *fn_entry;
1968 ZigFn *fn_entry;
19521969};
19531970
19541971// This scope is created to indicate that the code in the scope
......@@ -2145,6 +2162,7 @@ enum IrInstructionId {
21452162 IrInstructionIdErrSetCast,
21462163 IrInstructionIdToBytes,
21472164 IrInstructionIdFromBytes,
2165 IrInstructionIdCheckRuntimeScope,
21482166};
21492167
21502168struct IrInstruction {
......@@ -2279,7 +2297,7 @@ struct IrInstructionBinOp {
22792297struct IrInstructionDeclVar {
22802298 IrInstruction base;
22812299
2282 VariableTableEntry *var;
2300 ZigVar *var;
22832301 IrInstruction *var_type;
22842302 IrInstruction *align_value;
22852303 IrInstruction *init_value;
......@@ -2336,14 +2354,15 @@ struct IrInstructionElemPtr {
23362354struct IrInstructionVarPtr {
23372355 IrInstruction base;
23382356
2339 VariableTableEntry *var;
2357 ZigVar *var;
2358 ScopeFnDef *crossed_fndef_scope;
23402359};
23412360
23422361struct IrInstructionCall {
23432362 IrInstruction base;
23442363
23452364 IrInstruction *fn_ref;
2346 FnTableEntry *fn_entry;
2365 ZigFn *fn_entry;
23472366 size_t arg_count;
23482367 IrInstruction **args;
23492368 bool is_comptime;
......@@ -2373,7 +2392,7 @@ struct IrInstructionCast {
23732392 IrInstruction base;
23742393
23752394 IrInstruction *value;
2376 TypeTableEntry *dest_type;
2395 ZigType *dest_type;
23772396 CastOp cast_op;
23782397 LLVMValueRef tmp_ptr;
23792398};
......@@ -2410,7 +2429,7 @@ struct IrInstructionStructInitField {
24102429struct IrInstructionStructInit {
24112430 IrInstruction base;
24122431
2413 TypeTableEntry *struct_type;
2432 ZigType *struct_type;
24142433 size_t field_count;
24152434 IrInstructionStructInitField *fields;
24162435 LLVMValueRef tmp_ptr;
......@@ -2419,7 +2438,7 @@ struct IrInstructionStructInit {
24192438struct IrInstructionUnionInit {
24202439 IrInstruction base;
24212440
2422 TypeTableEntry *union_type;
2441 ZigType *union_type;
24232442 TypeUnionField *field;
24242443 IrInstruction *init_value;
24252444 LLVMValueRef tmp_ptr;
......@@ -2506,7 +2525,7 @@ struct IrInstructionAsm {
25062525 // Most information on inline assembly comes from the source node.
25072526 IrInstruction **input_list;
25082527 IrInstruction **output_types;
2509 VariableTableEntry **output_vars;
2528 ZigVar **output_vars;
25102529 size_t return_count;
25112530 bool has_side_effects;
25122531};
......@@ -2648,7 +2667,7 @@ struct IrInstructionCmpxchg {
26482667 IrInstruction *failure_order_value;
26492668
26502669 // if this instruction gets to runtime then we know these values:
2651 TypeTableEntry *type;
2670 ZigType *type;
26522671 AtomicOrder success_order;
26532672 AtomicOrder failure_order;
26542673
......@@ -2818,7 +2837,7 @@ struct IrInstructionOverflowOp {
28182837 IrInstruction *op2;
28192838 IrInstruction *result_ptr;
28202839
2821 TypeTableEntry *result_ptr_type;
2840 ZigType *result_ptr_type;
28222841};
28232842
28242843struct IrInstructionAlignOf {
......@@ -3234,6 +3253,13 @@ struct IrInstructionSqrt {
32343253 IrInstruction *op;
32353254};
32363255
3256struct IrInstructionCheckRuntimeScope {
3257 IrInstruction base;
3258
3259 IrInstruction *scope_is_comptime;
3260 IrInstruction *is_comptime;
3261};
3262
32373263static const size_t slice_ptr_index = 0;
32383264static const size_t slice_len_index = 1;
32393265
......@@ -3263,4 +3289,53 @@ enum FloatMode {
32633289 FloatModeStrict,
32643290};
32653291
3292enum FnWalkId {
3293 FnWalkIdAttrs,
3294 FnWalkIdCall,
3295 FnWalkIdTypes,
3296 FnWalkIdVars,
3297 FnWalkIdInits,
3298};
3299
3300struct FnWalkAttrs {
3301 ZigFn *fn;
3302 unsigned gen_i;
3303};
3304
3305struct FnWalkCall {
3306 ZigList<LLVMValueRef> *gen_param_values;
3307 IrInstructionCall *inst;
3308 bool is_var_args;
3309};
3310
3311struct FnWalkTypes {
3312 ZigList<ZigLLVMDIType *> *param_di_types;
3313 ZigList<LLVMTypeRef> *gen_param_types;
3314};
3315
3316struct FnWalkVars {
3317 ImportTableEntry *import;
3318 LLVMValueRef llvm_fn;
3319 ZigFn *fn;
3320 ZigVar *var;
3321 unsigned gen_i;
3322};
3323
3324struct FnWalkInits {
3325 LLVMValueRef llvm_fn;
3326 ZigFn *fn;
3327 unsigned gen_i;
3328};
3329
3330struct FnWalk {
3331 FnWalkId id;
3332 union {
3333 FnWalkAttrs attrs;
3334 FnWalkCall call;
3335 FnWalkTypes types;
3336 FnWalkVars vars;
3337 FnWalkInits inits;
3338 } data;
3339};
3340
32663341#endif
src/analyze.cpp+1089-974
......@@ -19,13 +19,13 @@
1919
2020static const size_t default_backward_branch_quota = 1000;
2121
22static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type);
23static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type);
22static Error resolve_enum_type(CodeGen *g, ZigType *enum_type);
23static Error resolve_struct_type(CodeGen *g, ZigType *struct_type);
2424
25static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type);
26static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
27static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
28static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
25static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type);
26static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type);
27static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type);
28static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry);
2929
3030ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
3131 if (node->owner->c_import_node != nullptr) {
......@@ -70,24 +70,24 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m
7070 return err;
7171}
7272
73TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {
74 TypeTableEntry *entry = allocate<TypeTableEntry>(1);
73ZigType *new_type_table_entry(ZigTypeId id) {
74 ZigType *entry = allocate<ZigType>(1);
7575 entry->id = id;
7676 return entry;
7777}
7878
79static ScopeDecls **get_container_scope_ptr(TypeTableEntry *type_entry) {
80 if (type_entry->id == TypeTableEntryIdStruct) {
79static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) {
80 if (type_entry->id == ZigTypeIdStruct) {
8181 return &type_entry->data.structure.decls_scope;
82 } else if (type_entry->id == TypeTableEntryIdEnum) {
82 } else if (type_entry->id == ZigTypeIdEnum) {
8383 return &type_entry->data.enumeration.decls_scope;
84 } else if (type_entry->id == TypeTableEntryIdUnion) {
84 } else if (type_entry->id == ZigTypeIdUnion) {
8585 return &type_entry->data.unionation.decls_scope;
8686 }
8787 zig_unreachable();
8888}
8989
90ScopeDecls *get_container_scope(TypeTableEntry *type_entry) {
90ScopeDecls *get_container_scope(ZigType *type_entry) {
9191 return *get_container_scope_ptr(type_entry);
9292}
9393
......@@ -97,7 +97,7 @@ void init_scope(Scope *dest, ScopeId id, AstNode *source_node, Scope *parent) {
9797 dest->parent = parent;
9898}
9999
100ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import) {
100ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) {
101101 assert(node == nullptr || node->type == NodeTypeRoot || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
102102 ScopeDecls *scope = allocate<ScopeDecls>(1);
103103 init_scope(&scope->base, ScopeIdDecls, node, parent);
......@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {
129129 return scope;
130130}
131131
132Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var) {
132Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var) {
133133 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
134134 init_scope(&scope->base, ScopeIdVarDecl, node, parent);
135135 scope->var = var;
......@@ -157,6 +157,13 @@ ScopeLoop *create_loop_scope(AstNode *node, Scope *parent) {
157157 return scope;
158158}
159159
160Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime) {
161 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
162 scope->is_comptime = is_comptime;
163 init_scope(&scope->base, ScopeIdRuntime, node, parent);
164 return &scope->base;
165}
166
160167ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
161168 assert(node->type == NodeTypeSuspend);
162169 ScopeSuspend *scope = allocate<ScopeSuspend>(1);
......@@ -164,7 +171,7 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
164171 return scope;
165172}
166173
167ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) {
174ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry) {
168175 ScopeFnDef *scope = allocate<ScopeFnDef>(1);
169176 init_scope(&scope->base, ScopeIdFnDef, node, parent);
170177 scope->fn_entry = fn_entry;
......@@ -196,8 +203,8 @@ ImportTableEntry *get_scope_import(Scope *scope) {
196203 zig_unreachable();
197204}
198205
199static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node, Scope *parent_scope) {
200 TypeTableEntry *entry = new_type_table_entry(id);
206static ZigType *new_container_type_entry(ZigTypeId id, AstNode *source_node, Scope *parent_scope) {
207 ZigType *entry = new_type_table_entry(id);
201208 *get_container_scope_ptr(entry) = create_decls_scope(source_node, parent_scope, entry, get_scope_import(parent_scope));
202209 return entry;
203210}
......@@ -211,131 +218,131 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {
211218 return (upper >= x) ? base : (base + 1);
212219}
213220
214AstNode *type_decl_node(TypeTableEntry *type_entry) {
221AstNode *type_decl_node(ZigType *type_entry) {
215222 switch (type_entry->id) {
216 case TypeTableEntryIdInvalid:
223 case ZigTypeIdInvalid:
217224 zig_unreachable();
218 case TypeTableEntryIdStruct:
225 case ZigTypeIdStruct:
219226 return type_entry->data.structure.decl_node;
220 case TypeTableEntryIdEnum:
227 case ZigTypeIdEnum:
221228 return type_entry->data.enumeration.decl_node;
222 case TypeTableEntryIdUnion:
229 case ZigTypeIdUnion:
223230 return type_entry->data.unionation.decl_node;
224 case TypeTableEntryIdOpaque:
225 case TypeTableEntryIdMetaType:
226 case TypeTableEntryIdVoid:
227 case TypeTableEntryIdBool:
228 case TypeTableEntryIdUnreachable:
229 case TypeTableEntryIdInt:
230 case TypeTableEntryIdFloat:
231 case TypeTableEntryIdPointer:
232 case TypeTableEntryIdArray:
233 case TypeTableEntryIdComptimeFloat:
234 case TypeTableEntryIdComptimeInt:
235 case TypeTableEntryIdUndefined:
236 case TypeTableEntryIdNull:
237 case TypeTableEntryIdOptional:
238 case TypeTableEntryIdErrorUnion:
239 case TypeTableEntryIdErrorSet:
240 case TypeTableEntryIdFn:
241 case TypeTableEntryIdNamespace:
242 case TypeTableEntryIdBlock:
243 case TypeTableEntryIdBoundFn:
244 case TypeTableEntryIdArgTuple:
245 case TypeTableEntryIdPromise:
231 case ZigTypeIdOpaque:
232 case ZigTypeIdMetaType:
233 case ZigTypeIdVoid:
234 case ZigTypeIdBool:
235 case ZigTypeIdUnreachable:
236 case ZigTypeIdInt:
237 case ZigTypeIdFloat:
238 case ZigTypeIdPointer:
239 case ZigTypeIdArray:
240 case ZigTypeIdComptimeFloat:
241 case ZigTypeIdComptimeInt:
242 case ZigTypeIdUndefined:
243 case ZigTypeIdNull:
244 case ZigTypeIdOptional:
245 case ZigTypeIdErrorUnion:
246 case ZigTypeIdErrorSet:
247 case ZigTypeIdFn:
248 case ZigTypeIdNamespace:
249 case ZigTypeIdBlock:
250 case ZigTypeIdBoundFn:
251 case ZigTypeIdArgTuple:
252 case ZigTypeIdPromise:
246253 return nullptr;
247254 }
248255 zig_unreachable();
249256}
250257
251bool type_is_complete(TypeTableEntry *type_entry) {
258bool type_is_complete(ZigType *type_entry) {
252259 switch (type_entry->id) {
253 case TypeTableEntryIdInvalid:
260 case ZigTypeIdInvalid:
254261 zig_unreachable();
255 case TypeTableEntryIdStruct:
262 case ZigTypeIdStruct:
256263 return type_entry->data.structure.complete;
257 case TypeTableEntryIdEnum:
264 case ZigTypeIdEnum:
258265 return type_entry->data.enumeration.complete;
259 case TypeTableEntryIdUnion:
266 case ZigTypeIdUnion:
260267 return type_entry->data.unionation.complete;
261 case TypeTableEntryIdOpaque:
268 case ZigTypeIdOpaque:
262269 return false;
263 case TypeTableEntryIdMetaType:
264 case TypeTableEntryIdVoid:
265 case TypeTableEntryIdBool:
266 case TypeTableEntryIdUnreachable:
267 case TypeTableEntryIdInt:
268 case TypeTableEntryIdFloat:
269 case TypeTableEntryIdPointer:
270 case TypeTableEntryIdArray:
271 case TypeTableEntryIdComptimeFloat:
272 case TypeTableEntryIdComptimeInt:
273 case TypeTableEntryIdUndefined:
274 case TypeTableEntryIdNull:
275 case TypeTableEntryIdOptional:
276 case TypeTableEntryIdErrorUnion:
277 case TypeTableEntryIdErrorSet:
278 case TypeTableEntryIdFn:
279 case TypeTableEntryIdNamespace:
280 case TypeTableEntryIdBlock:
281 case TypeTableEntryIdBoundFn:
282 case TypeTableEntryIdArgTuple:
283 case TypeTableEntryIdPromise:
270 case ZigTypeIdMetaType:
271 case ZigTypeIdVoid:
272 case ZigTypeIdBool:
273 case ZigTypeIdUnreachable:
274 case ZigTypeIdInt:
275 case ZigTypeIdFloat:
276 case ZigTypeIdPointer:
277 case ZigTypeIdArray:
278 case ZigTypeIdComptimeFloat:
279 case ZigTypeIdComptimeInt:
280 case ZigTypeIdUndefined:
281 case ZigTypeIdNull:
282 case ZigTypeIdOptional:
283 case ZigTypeIdErrorUnion:
284 case ZigTypeIdErrorSet:
285 case ZigTypeIdFn:
286 case ZigTypeIdNamespace:
287 case ZigTypeIdBlock:
288 case ZigTypeIdBoundFn:
289 case ZigTypeIdArgTuple:
290 case ZigTypeIdPromise:
284291 return true;
285292 }
286293 zig_unreachable();
287294}
288295
289bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
296bool type_has_zero_bits_known(ZigType *type_entry) {
290297 switch (type_entry->id) {
291 case TypeTableEntryIdInvalid:
298 case ZigTypeIdInvalid:
292299 zig_unreachable();
293 case TypeTableEntryIdStruct:
300 case ZigTypeIdStruct:
294301 return type_entry->data.structure.zero_bits_known;
295 case TypeTableEntryIdEnum:
302 case ZigTypeIdEnum:
296303 return type_entry->data.enumeration.zero_bits_known;
297 case TypeTableEntryIdUnion:
304 case ZigTypeIdUnion:
298305 return type_entry->data.unionation.zero_bits_known;
299 case TypeTableEntryIdMetaType:
300 case TypeTableEntryIdVoid:
301 case TypeTableEntryIdBool:
302 case TypeTableEntryIdUnreachable:
303 case TypeTableEntryIdInt:
304 case TypeTableEntryIdFloat:
305 case TypeTableEntryIdPointer:
306 case TypeTableEntryIdArray:
307 case TypeTableEntryIdComptimeFloat:
308 case TypeTableEntryIdComptimeInt:
309 case TypeTableEntryIdUndefined:
310 case TypeTableEntryIdNull:
311 case TypeTableEntryIdOptional:
312 case TypeTableEntryIdErrorUnion:
313 case TypeTableEntryIdErrorSet:
314 case TypeTableEntryIdFn:
315 case TypeTableEntryIdNamespace:
316 case TypeTableEntryIdBlock:
317 case TypeTableEntryIdBoundFn:
318 case TypeTableEntryIdArgTuple:
319 case TypeTableEntryIdOpaque:
320 case TypeTableEntryIdPromise:
306 case ZigTypeIdMetaType:
307 case ZigTypeIdVoid:
308 case ZigTypeIdBool:
309 case ZigTypeIdUnreachable:
310 case ZigTypeIdInt:
311 case ZigTypeIdFloat:
312 case ZigTypeIdPointer:
313 case ZigTypeIdArray:
314 case ZigTypeIdComptimeFloat:
315 case ZigTypeIdComptimeInt:
316 case ZigTypeIdUndefined:
317 case ZigTypeIdNull:
318 case ZigTypeIdOptional:
319 case ZigTypeIdErrorUnion:
320 case ZigTypeIdErrorSet:
321 case ZigTypeIdFn:
322 case ZigTypeIdNamespace:
323 case ZigTypeIdBlock:
324 case ZigTypeIdBoundFn:
325 case ZigTypeIdArgTuple:
326 case ZigTypeIdOpaque:
327 case ZigTypeIdPromise:
321328 return true;
322329 }
323330 zig_unreachable();
324331}
325332
326333
327uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
334uint64_t type_size(CodeGen *g, ZigType *type_entry) {
328335 assert(type_is_complete(type_entry));
329336
330337 if (!type_has_bits(type_entry))
331338 return 0;
332339
333 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
340 if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
334341 uint64_t size_in_bits = type_size_bits(g, type_entry);
335342 return (size_in_bits + 7) / 8;
336 } else if (type_entry->id == TypeTableEntryIdArray) {
337 TypeTableEntry *child_type = type_entry->data.array.child_type;
338 if (child_type->id == TypeTableEntryIdStruct &&
343 } else if (type_entry->id == ZigTypeIdArray) {
344 ZigType *child_type = type_entry->data.array.child_type;
345 if (child_type->id == ZigTypeIdStruct &&
339346 child_type->data.structure.layout == ContainerLayoutPacked)
340347 {
341348 uint64_t size_in_bits = type_size_bits(g, type_entry);
......@@ -346,21 +353,21 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
346353 return LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref);
347354}
348355
349uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
356uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) {
350357 assert(type_is_complete(type_entry));
351358
352359 if (!type_has_bits(type_entry))
353360 return 0;
354361
355 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
362 if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
356363 uint64_t result = 0;
357364 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
358365 result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry);
359366 }
360367 return result;
361 } else if (type_entry->id == TypeTableEntryIdArray) {
362 TypeTableEntry *child_type = type_entry->data.array.child_type;
363 if (child_type->id == TypeTableEntryIdStruct &&
368 } else if (type_entry->id == ZigTypeIdArray) {
369 ZigType *child_type = type_entry->data.array.child_type;
370 if (child_type->id == ZigTypeIdStruct &&
364371 child_type->data.structure.layout == ContainerLayoutPacked)
365372 {
366373 return type_entry->data.array.len * type_size_bits(g, child_type);
......@@ -370,7 +377,7 @@ uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
370377 return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref);
371378}
372379
373Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
380Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) {
374381 Error err;
375382 if ((err = type_ensure_zero_bits_known(g, type_entry)))
376383 return err;
......@@ -387,23 +394,23 @@ Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
387394 return type_entry->is_copyable;
388395}
389396
390static bool is_slice(TypeTableEntry *type) {
391 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;
397static bool is_slice(ZigType *type) {
398 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
392399}
393400
394TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
401ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
395402 return get_int_type(g, false, bits_needed_for_unsigned(x));
396403}
397404
398TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
405ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
399406 if (result_type != nullptr && result_type->promise_parent != nullptr) {
400407 return result_type->promise_parent;
401408 } else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) {
402409 return g->builtin_types.entry_promise;
403410 }
404411
405 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
406 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPromise);
412 ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
413 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
407414 entry->type_ref = u8_ptr_type->type_ref;
408415 entry->zero_bits = false;
409416 entry->data.promise.result_type = result_type;
......@@ -421,17 +428,17 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
421428 return entry;
422429}
423430
424TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
431ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
425432 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
426433{
427434 assert(!type_is_invalid(child_type));
428 assert(ptr_len == PtrLenSingle || child_type->id != TypeTableEntryIdOpaque);
435 assert(ptr_len == PtrLenSingle || child_type->id != ZigTypeIdOpaque);
429436
430437 TypeId type_id = {};
431 TypeTableEntry **parent_pointer = nullptr;
438 ZigType **parent_pointer = nullptr;
432439 uint32_t abi_alignment = get_abi_alignment(g, child_type);
433440 if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) {
434 type_id.id = TypeTableEntryIdPointer;
441 type_id.id = ZigTypeIdPointer;
435442 type_id.data.pointer.child_type = child_type;
436443 type_id.data.pointer.is_const = is_const;
437444 type_id.data.pointer.is_volatile = is_volatile;
......@@ -454,7 +461,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
454461
455462 assertNoError(type_ensure_zero_bits_known(g, child_type));
456463
457 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer);
464 ZigType *entry = new_type_table_entry(ZigTypeIdPointer);
458465 entry->is_copyable = true;
459466
460467 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
......@@ -471,7 +478,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
471478 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
472479 }
473480
474 assert(child_type->id != TypeTableEntryIdInvalid);
481 assert(child_type->id != ZigTypeIdInvalid);
475482
476483 entry->zero_bits = !type_has_bits(child_type);
477484
......@@ -480,7 +487,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
480487 if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||
481488 ptr_len != PtrLenSingle)
482489 {
483 TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false);
490 ZigType *peer_type = get_pointer_to_type(g, child_type, false);
484491 entry->type_ref = peer_type->type_ref;
485492 entry->di_type = peer_type->di_type;
486493 } else {
......@@ -513,18 +520,18 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
513520 return entry;
514521}
515522
516TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) {
523ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {
517524 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle,
518525 get_abi_alignment(g, child_type), 0, 0);
519526}
520527
521TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) {
528ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type) {
522529 if (return_type->promise_frame_parent != nullptr) {
523530 return return_type->promise_frame_parent;
524531 }
525532
526 TypeTableEntry *atomic_state_type = g->builtin_types.entry_usize;
527 TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false);
533 ZigType *atomic_state_type = g->builtin_types.entry_usize;
534 ZigType *result_ptr_type = get_pointer_to_type(g, return_type, false);
528535
529536 ZigList<const char *> field_names = {};
530537 field_names.append(ATOMIC_STATE_FIELD_NAME);
......@@ -536,7 +543,7 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
536543 field_names.append(RETURN_ADDRESSES_FIELD_NAME);
537544 }
538545
539 ZigList<TypeTableEntry *> field_types = {};
546 ZigList<ZigType *> field_types = {};
540547 field_types.append(atomic_state_type);
541548 field_types.append(return_type);
542549 field_types.append(result_ptr_type);
......@@ -548,20 +555,20 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
548555
549556 assert(field_names.length == field_types.length);
550557 Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name));
551 TypeTableEntry *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length);
558 ZigType *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length);
552559
553560 return_type->promise_frame_parent = entry;
554561 return entry;
555562}
556563
557TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
564ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
558565 if (child_type->optional_parent) {
559 TypeTableEntry *entry = child_type->optional_parent;
566 ZigType *entry = child_type->optional_parent;
560567 return entry;
561568 } else {
562569 assertNoError(ensure_complete_type(g, child_type));
563570
564 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
571 ZigType *entry = new_type_table_entry(ZigTypeIdOptional);
565572 assert(child_type->type_ref || child_type->zero_bits);
566573 entry->is_copyable = type_is_copyable(g, child_type).unwrap();
567574
......@@ -599,7 +606,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
599606 uint64_t val_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, child_type->type_ref);
600607 uint64_t val_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
601608
602 TypeTableEntry *bool_type = g->builtin_types.entry_bool;
609 ZigType *bool_type = g->builtin_types.entry_bool;
603610 uint64_t maybe_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, bool_type->type_ref);
604611 uint64_t maybe_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, bool_type->type_ref);
605612 uint64_t maybe_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
......@@ -638,12 +645,12 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
638645 }
639646}
640647
641TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) {
642 assert(err_set_type->id == TypeTableEntryIdErrorSet);
648ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) {
649 assert(err_set_type->id == ZigTypeIdErrorSet);
643650 assert(!type_is_invalid(payload_type));
644651
645652 TypeId type_id = {};
646 type_id.id = TypeTableEntryIdErrorUnion;
653 type_id.id = ZigTypeIdErrorUnion;
647654 type_id.data.error_union.err_set_type = err_set_type;
648655 type_id.data.error_union.payload_type = payload_type;
649656
......@@ -652,7 +659,7 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
652659 return existing_entry->value;
653660 }
654661
655 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorUnion);
662 ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion);
656663 entry->is_copyable = true;
657664 assert(payload_type->di_type);
658665 assertNoError(ensure_complete_type(g, payload_type));
......@@ -733,20 +740,20 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
733740 return entry;
734741}
735742
736TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size) {
743ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {
737744 TypeId type_id = {};
738 type_id.id = TypeTableEntryIdArray;
745 type_id.id = ZigTypeIdArray;
739746 type_id.data.array.child_type = child_type;
740747 type_id.data.array.size = array_size;
741748 auto existing_entry = g->type_table.maybe_get(type_id);
742749 if (existing_entry) {
743 TypeTableEntry *entry = existing_entry->value;
750 ZigType *entry = existing_entry->value;
744751 return entry;
745752 }
746753
747754 assertNoError(ensure_complete_type(g, child_type));
748755
749 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArray);
756 ZigType *entry = new_type_table_entry(ZigTypeIdArray);
750757 entry->zero_bits = (array_size == 0) || child_type->zero_bits;
751758 entry->is_copyable = false;
752759
......@@ -773,7 +780,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
773780 return entry;
774781}
775782
776static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, TypeTableEntry *entry) {
783static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *entry) {
777784 unsigned element_count = 2;
778785 Buf *ptr_field_name = buf_create_from_str("ptr");
779786 Buf *len_field_name = buf_create_from_str("len");
......@@ -804,16 +811,16 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ
804811 }
805812}
806813
807TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
808 assert(ptr_type->id == TypeTableEntryIdPointer);
814ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
815 assert(ptr_type->id == ZigTypeIdPointer);
809816 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);
810817
811 TypeTableEntry **parent_pointer = &ptr_type->data.pointer.slice_parent;
818 ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent;
812819 if (*parent_pointer) {
813820 return *parent_pointer;
814821 }
815822
816 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct);
823 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
817824 entry->is_copyable = true;
818825
819826 // replace the & with [] to go from a ptr type name to a slice type name
......@@ -821,14 +828,14 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
821828 size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3;
822829 buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + name_offset);
823830
824 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
831 ZigType *child_type = ptr_type->data.pointer.child_type;
825832 uint32_t abi_alignment = get_abi_alignment(g, child_type);
826833 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
827834 ptr_type->data.pointer.alignment != abi_alignment)
828835 {
829 TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
836 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
830837 PtrLenUnknown, abi_alignment, 0, 0);
831 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
838 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
832839
833840 slice_type_common_init(g, ptr_type, entry);
834841
......@@ -845,18 +852,18 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
845852 // If the child type is []const T then we need to make sure the type ref
846853 // and debug info is the same as if the child type were []T.
847854 if (is_slice(child_type)) {
848 TypeTableEntry *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
849 assert(child_ptr_type->id == TypeTableEntryIdPointer);
850 TypeTableEntry *grand_child_type = child_ptr_type->data.pointer.child_type;
855 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
856 assert(child_ptr_type->id == ZigTypeIdPointer);
857 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
851858 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
852859 child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))
853860 {
854 TypeTableEntry *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
861 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
855862 PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0);
856 TypeTableEntry *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
857 TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
863 ZigType *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
864 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
858865 PtrLenUnknown, get_abi_alignment(g, bland_child_slice), 0, 0);
859 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
866 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
860867
861868 entry->type_ref = peer_slice_type->type_ref;
862869 entry->di_type = peer_slice_type->di_type;
......@@ -882,7 +889,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
882889 };
883890 LLVMStructSetBody(entry->type_ref, element_types, 1, false);
884891
885 TypeTableEntry *usize_type = g->builtin_types.entry_usize;
892 ZigType *usize_type = g->builtin_types.entry_usize;
886893 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
887894 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
888895 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
......@@ -921,7 +928,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
921928 uint64_t ptr_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->type_ref);
922929 uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
923930
924 TypeTableEntry *usize_type = g->builtin_types.entry_usize;
931 ZigType *usize_type = g->builtin_types.entry_usize;
925932 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
926933 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
927934 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
......@@ -964,8 +971,8 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
964971 return entry;
965972}
966973
967TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
968 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque);
974ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
975 ZigType *entry = new_type_table_entry(ZigTypeIdOpaque);
969976
970977 buf_init_from_str(&entry->name, name);
971978
......@@ -984,13 +991,13 @@ TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node,
984991 return entry;
985992}
986993
987TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {
988 TypeTableEntry *fn_type = fn_entry->type_entry;
989 assert(fn_type->id == TypeTableEntryIdFn);
994ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
995 ZigType *fn_type = fn_entry->type_entry;
996 assert(fn_type->id == ZigTypeIdFn);
990997 if (fn_type->data.fn.bound_fn_parent)
991998 return fn_type->data.fn.bound_fn_parent;
992999
993 TypeTableEntry *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn);
1000 ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn);
9941001 bound_fn_type->is_copyable = false;
9951002 bound_fn_type->data.bound_fn.fn_type = fn_type;
9961003 bound_fn_type->zero_bits = true;
......@@ -1002,11 +1009,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {
10021009 return bound_fn_type;
10031010}
10041011
1005bool calling_convention_does_first_arg_return(CallingConvention cc) {
1006 return cc == CallingConventionUnspecified;
1007}
1008
1009static const char *calling_convention_name(CallingConvention cc) {
1012const char *calling_convention_name(CallingConvention cc) {
10101013 switch (cc) {
10111014 case CallingConventionUnspecified: return "undefined";
10121015 case CallingConventionC: return "ccc";
......@@ -1030,7 +1033,7 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) {
10301033 zig_unreachable();
10311034}
10321035
1033static bool calling_convention_allows_zig_types(CallingConvention cc) {
1036bool calling_convention_allows_zig_types(CallingConvention cc) {
10341037 switch (cc) {
10351038 case CallingConventionUnspecified:
10361039 case CallingConventionAsync:
......@@ -1044,17 +1047,38 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {
10441047 zig_unreachable();
10451048}
10461049
1047TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) {
1050ZigType *get_ptr_to_stack_trace_type(CodeGen *g) {
10481051 if (g->stack_trace_type == nullptr) {
10491052 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
1050 assert(stack_trace_type_val->type->id == TypeTableEntryIdMetaType);
1053 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
10511054 g->stack_trace_type = stack_trace_type_val->data.x_type;
10521055 g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);
10531056 }
10541057 return g->ptr_to_stack_trace_type;
10551058}
10561059
1057TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1060bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
1061 if (fn_type_id->cc == CallingConventionUnspecified) {
1062 return handle_is_ptr(fn_type_id->return_type);
1063 }
1064 if (fn_type_id->cc != CallingConventionC) {
1065 return false;
1066 }
1067 if (type_is_c_abi_int(g, fn_type_id->return_type)) {
1068 return false;
1069 }
1070 if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
1071 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);
1072 if (abi_class == X64CABIClass_MEMORY) {
1073 return true;
1074 }
1075 zig_panic("TODO implement C ABI for x86_64 return types. type '%s'\nSee https://github.com/ziglang/zig/issues/1481",
1076 buf_ptr(&fn_type_id->return_type->name));
1077 }
1078 zig_panic("TODO implement C ABI for this architecture. See https://github.com/ziglang/zig/issues/1481");
1079}
1080
1081ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10581082 Error err;
10591083 auto table_entry = g->fn_type_table.maybe_get(fn_type_id);
10601084 if (table_entry) {
......@@ -1063,12 +1087,12 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10631087 if (fn_type_id->return_type != nullptr) {
10641088 if ((err = ensure_complete_type(g, fn_type_id->return_type)))
10651089 return g->builtin_types.entry_invalid;
1066 assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);
1090 assert(fn_type_id->return_type->id != ZigTypeIdOpaque);
10671091 } else {
10681092 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
10691093 }
10701094
1071 TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);
1095 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
10721096 fn_type->is_copyable = true;
10731097 fn_type->data.fn.fn_type_id = *fn_type_id;
10741098
......@@ -1087,7 +1111,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10871111 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
10881112 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
10891113
1090 TypeTableEntry *param_type = param_info->type;
1114 ZigType *param_type = param_info->type;
10911115 const char *comma = (i == 0) ? "" : ", ";
10921116 const char *noalias_str = param_info->is_noalias ? "noalias " : "";
10931117 buf_appendf(&fn_type->name, "%s%s%s", comma, noalias_str, buf_ptr(&param_type->name));
......@@ -1109,32 +1133,29 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
11091133 // next, loop over the parameters again and compute debug information
11101134 // and codegen information
11111135 if (!skip_debug_info) {
1112 bool first_arg_return = calling_convention_does_first_arg_return(fn_type_id->cc) &&
1113 handle_is_ptr(fn_type_id->return_type);
1136 bool first_arg_return = want_first_arg_sret(g, fn_type_id);
11141137 bool is_async = fn_type_id->cc == CallingConventionAsync;
1138 bool is_c_abi = fn_type_id->cc == CallingConventionC;
11151139 bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id);
11161140 // +1 for maybe making the first argument the return value
11171141 // +1 for maybe first argument the error return trace
11181142 // +2 for maybe arguments async allocator and error code pointer
1119 LLVMTypeRef *gen_param_types = allocate<LLVMTypeRef>(4 + fn_type_id->param_count);
1143 ZigList<LLVMTypeRef> gen_param_types = {};
11201144 // +1 because 0 is the return type and
11211145 // +1 for maybe making first arg ret val and
11221146 // +1 for maybe first argument the error return trace
11231147 // +2 for maybe arguments async allocator and error code pointer
1124 ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(5 + fn_type_id->param_count);
1125 param_di_types[0] = fn_type_id->return_type->di_type;
1126 size_t gen_param_index = 0;
1127 TypeTableEntry *gen_return_type;
1148 ZigList<ZigLLVMDIType *> param_di_types = {};
1149 param_di_types.append(fn_type_id->return_type->di_type);
1150 ZigType *gen_return_type;
11281151 if (is_async) {
11291152 gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
11301153 } else if (!type_has_bits(fn_type_id->return_type)) {
11311154 gen_return_type = g->builtin_types.entry_void;
11321155 } else if (first_arg_return) {
1133 TypeTableEntry *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);
1134 gen_param_types[gen_param_index] = gen_type->type_ref;
1135 gen_param_index += 1;
1136 // after the gen_param_index += 1 because 0 is the return type
1137 param_di_types[gen_param_index] = gen_type->di_type;
1156 ZigType *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);
1157 gen_param_types.append(gen_type->type_ref);
1158 param_di_types.append(gen_type->di_type);
11381159 gen_return_type = g->builtin_types.entry_void;
11391160 } else {
11401161 gen_return_type = fn_type_id->return_type;
......@@ -1142,36 +1163,30 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
11421163 fn_type->data.fn.gen_return_type = gen_return_type;
11431164
11441165 if (prefix_arg_error_return_trace) {
1145 TypeTableEntry *gen_type = get_ptr_to_stack_trace_type(g);
1146 gen_param_types[gen_param_index] = gen_type->type_ref;
1147 gen_param_index += 1;
1148 // after the gen_param_index += 1 because 0 is the return type
1149 param_di_types[gen_param_index] = gen_type->di_type;
1166 ZigType *gen_type = get_ptr_to_stack_trace_type(g);
1167 gen_param_types.append(gen_type->type_ref);
1168 param_di_types.append(gen_type->di_type);
11501169 }
11511170 if (is_async) {
11521171 {
11531172 // async allocator param
1154 TypeTableEntry *gen_type = fn_type_id->async_allocator_type;
1155 gen_param_types[gen_param_index] = gen_type->type_ref;
1156 gen_param_index += 1;
1157 // after the gen_param_index += 1 because 0 is the return type
1158 param_di_types[gen_param_index] = gen_type->di_type;
1173 ZigType *gen_type = fn_type_id->async_allocator_type;
1174 gen_param_types.append(gen_type->type_ref);
1175 param_di_types.append(gen_type->di_type);
11591176 }
11601177
11611178 {
11621179 // error code pointer
1163 TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
1164 gen_param_types[gen_param_index] = gen_type->type_ref;
1165 gen_param_index += 1;
1166 // after the gen_param_index += 1 because 0 is the return type
1167 param_di_types[gen_param_index] = gen_type->di_type;
1180 ZigType *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
1181 gen_param_types.append(gen_type->type_ref);
1182 param_di_types.append(gen_type->di_type);
11681183 }
11691184 }
11701185
11711186 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
11721187 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
11731188 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
1174 TypeTableEntry *type_entry = src_param_info->type;
1189 ZigType *type_entry = src_param_info->type;
11751190 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
11761191
11771192 gen_param_info->src_index = i;
......@@ -1180,31 +1195,39 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
11801195 if ((err = ensure_complete_type(g, type_entry)))
11811196 return g->builtin_types.entry_invalid;
11821197
1198 if (is_c_abi)
1199 continue;
1200
11831201 if (type_has_bits(type_entry)) {
1184 TypeTableEntry *gen_type;
1202 ZigType *gen_type;
11851203 if (handle_is_ptr(type_entry)) {
11861204 gen_type = get_pointer_to_type(g, type_entry, true);
11871205 gen_param_info->is_byval = true;
11881206 } else {
11891207 gen_type = type_entry;
11901208 }
1191 gen_param_types[gen_param_index] = gen_type->type_ref;
1192 gen_param_info->gen_index = gen_param_index;
1209 gen_param_info->gen_index = gen_param_types.length;
11931210 gen_param_info->type = gen_type;
1211 gen_param_types.append(gen_type->type_ref);
11941212
1195 gen_param_index += 1;
1196
1197 // after the gen_param_index += 1 because 0 is the return type
1198 param_di_types[gen_param_index] = gen_type->di_type;
1213 param_di_types.append(gen_type->di_type);
11991214 }
12001215 }
12011216
1202 fn_type->data.fn.gen_param_count = gen_param_index;
1217 if (is_c_abi) {
1218 FnWalk fn_walk = {};
1219 fn_walk.id = FnWalkIdTypes;
1220 fn_walk.data.types.param_di_types = &param_di_types;
1221 fn_walk.data.types.gen_param_types = &gen_param_types;
1222 walk_function_params(g, fn_type, &fn_walk);
1223 }
1224
1225 fn_type->data.fn.gen_param_count = gen_param_types.length;
12031226
12041227 fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref,
1205 gen_param_types, (unsigned int)gen_param_index, fn_type_id->is_var_args);
1228 gen_param_types.items, (unsigned int)gen_param_types.length, fn_type_id->is_var_args);
12061229 fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0);
1207 fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types, (int)(gen_param_index + 1), 0);
1230 fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types.items, (int)param_di_types.length, 0);
12081231 }
12091232
12101233 g->fn_type_table.put(&fn_type->data.fn.fn_type_id, fn_type);
......@@ -1212,23 +1235,23 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
12121235 return fn_type;
12131236}
12141237
1215static TypeTableEntryId container_to_type(ContainerKind kind) {
1238static ZigTypeId container_to_type(ContainerKind kind) {
12161239 switch (kind) {
12171240 case ContainerKindStruct:
1218 return TypeTableEntryIdStruct;
1241 return ZigTypeIdStruct;
12191242 case ContainerKindEnum:
1220 return TypeTableEntryIdEnum;
1243 return ZigTypeIdEnum;
12211244 case ContainerKindUnion:
1222 return TypeTableEntryIdUnion;
1245 return ZigTypeIdUnion;
12231246 }
12241247 zig_unreachable();
12251248}
12261249
1227TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
1250ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
12281251 AstNode *decl_node, const char *name, ContainerLayout layout)
12291252{
1230 TypeTableEntryId type_id = container_to_type(kind);
1231 TypeTableEntry *entry = new_container_type_entry(type_id, decl_node, scope);
1253 ZigTypeId type_id = container_to_type(kind);
1254 ZigType *entry = new_container_type_entry(type_id, decl_node, scope);
12321255
12331256 switch (kind) {
12341257 case ContainerKindStruct:
......@@ -1259,24 +1282,24 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
12591282 return entry;
12601283}
12611284
1262static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, TypeTableEntry *type_entry, Buf *type_name) {
1285static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) {
12631286 size_t backward_branch_count = 0;
12641287 return ir_eval_const_value(g, scope, node, type_entry,
12651288 &backward_branch_count, default_backward_branch_quota,
12661289 nullptr, nullptr, node, type_name, nullptr);
12671290}
12681291
1269TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1292ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
12701293 IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);
1271 if (result->value.type->id == TypeTableEntryIdInvalid)
1294 if (result->value.type->id == ZigTypeIdInvalid)
12721295 return g->builtin_types.entry_invalid;
12731296
12741297 assert(result->value.special != ConstValSpecialRuntime);
12751298 return result->value.data.x_type;
12761299}
12771300
1278TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1279 TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);
1301ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1302 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
12801303 fn_type->is_copyable = false;
12811304 buf_resize(&fn_type->name, 0);
12821305 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
......@@ -1343,9 +1366,9 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
13431366}
13441367
13451368static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) {
1346 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1369 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
13471370 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
1348 TypeTableEntry *str_type = get_slice_type(g, ptr_type);
1371 ZigType *str_type = get_slice_type(g, ptr_type);
13491372 IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);
13501373 if (type_is_invalid(instr->value.type))
13511374 return false;
......@@ -1375,71 +1398,71 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
13751398 return true;
13761399}
13771400
1378static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
1401static bool type_allowed_in_packed_struct(ZigType *type_entry) {
13791402 switch (type_entry->id) {
1380 case TypeTableEntryIdInvalid:
1403 case ZigTypeIdInvalid:
13811404 zig_unreachable();
1382 case TypeTableEntryIdMetaType:
1383 case TypeTableEntryIdUnreachable:
1384 case TypeTableEntryIdComptimeFloat:
1385 case TypeTableEntryIdComptimeInt:
1386 case TypeTableEntryIdUndefined:
1387 case TypeTableEntryIdNull:
1388 case TypeTableEntryIdErrorUnion:
1389 case TypeTableEntryIdErrorSet:
1390 case TypeTableEntryIdNamespace:
1391 case TypeTableEntryIdBlock:
1392 case TypeTableEntryIdBoundFn:
1393 case TypeTableEntryIdArgTuple:
1394 case TypeTableEntryIdOpaque:
1395 case TypeTableEntryIdPromise:
1405 case ZigTypeIdMetaType:
1406 case ZigTypeIdUnreachable:
1407 case ZigTypeIdComptimeFloat:
1408 case ZigTypeIdComptimeInt:
1409 case ZigTypeIdUndefined:
1410 case ZigTypeIdNull:
1411 case ZigTypeIdErrorUnion:
1412 case ZigTypeIdErrorSet:
1413 case ZigTypeIdNamespace:
1414 case ZigTypeIdBlock:
1415 case ZigTypeIdBoundFn:
1416 case ZigTypeIdArgTuple:
1417 case ZigTypeIdOpaque:
1418 case ZigTypeIdPromise:
13961419 return false;
1397 case TypeTableEntryIdVoid:
1398 case TypeTableEntryIdBool:
1399 case TypeTableEntryIdInt:
1400 case TypeTableEntryIdFloat:
1401 case TypeTableEntryIdPointer:
1402 case TypeTableEntryIdArray:
1403 case TypeTableEntryIdFn:
1420 case ZigTypeIdVoid:
1421 case ZigTypeIdBool:
1422 case ZigTypeIdInt:
1423 case ZigTypeIdFloat:
1424 case ZigTypeIdPointer:
1425 case ZigTypeIdArray:
1426 case ZigTypeIdFn:
14041427 return true;
1405 case TypeTableEntryIdStruct:
1428 case ZigTypeIdStruct:
14061429 return type_entry->data.structure.layout == ContainerLayoutPacked;
1407 case TypeTableEntryIdUnion:
1430 case ZigTypeIdUnion:
14081431 return type_entry->data.unionation.layout == ContainerLayoutPacked;
1409 case TypeTableEntryIdOptional:
1432 case ZigTypeIdOptional:
14101433 {
1411 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1434 ZigType *child_type = type_entry->data.maybe.child_type;
14121435 return type_is_codegen_pointer(child_type);
14131436 }
1414 case TypeTableEntryIdEnum:
1437 case ZigTypeIdEnum:
14151438 return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;
14161439 }
14171440 zig_unreachable();
14181441}
14191442
1420static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
1443static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
14211444 switch (type_entry->id) {
1422 case TypeTableEntryIdInvalid:
1445 case ZigTypeIdInvalid:
14231446 zig_unreachable();
1424 case TypeTableEntryIdMetaType:
1425 case TypeTableEntryIdComptimeFloat:
1426 case TypeTableEntryIdComptimeInt:
1427 case TypeTableEntryIdUndefined:
1428 case TypeTableEntryIdNull:
1429 case TypeTableEntryIdErrorUnion:
1430 case TypeTableEntryIdErrorSet:
1431 case TypeTableEntryIdNamespace:
1432 case TypeTableEntryIdBlock:
1433 case TypeTableEntryIdBoundFn:
1434 case TypeTableEntryIdArgTuple:
1435 case TypeTableEntryIdPromise:
1436 case TypeTableEntryIdVoid:
1447 case ZigTypeIdMetaType:
1448 case ZigTypeIdComptimeFloat:
1449 case ZigTypeIdComptimeInt:
1450 case ZigTypeIdUndefined:
1451 case ZigTypeIdNull:
1452 case ZigTypeIdErrorUnion:
1453 case ZigTypeIdErrorSet:
1454 case ZigTypeIdNamespace:
1455 case ZigTypeIdBlock:
1456 case ZigTypeIdBoundFn:
1457 case ZigTypeIdArgTuple:
1458 case ZigTypeIdPromise:
1459 case ZigTypeIdVoid:
14371460 return false;
1438 case TypeTableEntryIdOpaque:
1439 case TypeTableEntryIdUnreachable:
1440 case TypeTableEntryIdBool:
1461 case ZigTypeIdOpaque:
1462 case ZigTypeIdUnreachable:
1463 case ZigTypeIdBool:
14411464 return true;
1442 case TypeTableEntryIdInt:
1465 case ZigTypeIdInt:
14431466 switch (type_entry->data.integral.bit_count) {
14441467 case 8:
14451468 case 16:
......@@ -1450,36 +1473,36 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
14501473 default:
14511474 return false;
14521475 }
1453 case TypeTableEntryIdFloat:
1476 case ZigTypeIdFloat:
14541477 return true;
1455 case TypeTableEntryIdArray:
1478 case ZigTypeIdArray:
14561479 return type_allowed_in_extern(g, type_entry->data.array.child_type);
1457 case TypeTableEntryIdFn:
1480 case ZigTypeIdFn:
14581481 return type_entry->data.fn.fn_type_id.cc == CallingConventionC;
1459 case TypeTableEntryIdPointer:
1482 case ZigTypeIdPointer:
14601483 if (type_size(g, type_entry) == 0)
14611484 return false;
14621485 return true;
1463 case TypeTableEntryIdStruct:
1486 case ZigTypeIdStruct:
14641487 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
1465 case TypeTableEntryIdOptional:
1488 case ZigTypeIdOptional:
14661489 {
1467 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1468 if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) {
1490 ZigType *child_type = type_entry->data.maybe.child_type;
1491 if (child_type->id != ZigTypeIdPointer && child_type->id != ZigTypeIdFn) {
14691492 return false;
14701493 }
14711494 return type_allowed_in_extern(g, child_type);
14721495 }
1473 case TypeTableEntryIdEnum:
1496 case ZigTypeIdEnum:
14741497 return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;
1475 case TypeTableEntryIdUnion:
1498 case ZigTypeIdUnion:
14761499 return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;
14771500 }
14781501 zig_unreachable();
14791502}
14801503
1481TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
1482 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
1504ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1505 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
14831506 buf_resize(&err_set_type->name, 0);
14841507 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
14851508 err_set_type->is_copyable = true;
......@@ -1494,7 +1517,7 @@ TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
14941517 return err_set_type;
14951518}
14961519
1497static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, FnTableEntry *fn_entry) {
1520static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry) {
14981521 assert(proto_node->type == NodeTypeFnProto);
14991522 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
15001523 Error err;
......@@ -1517,7 +1540,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15171540 return g->builtin_types.entry_invalid;
15181541 }
15191542 if (param_node->data.param_decl.type != nullptr) {
1520 TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
1543 ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
15211544 if (type_is_invalid(type_entry)) {
15221545 return g->builtin_types.entry_invalid;
15231546 }
......@@ -1550,7 +1573,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15501573 return get_generic_fn_type(g, &fn_type_id);
15511574 }
15521575
1553 TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
1576 ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
15541577 if (type_is_invalid(type_entry)) {
15551578 return g->builtin_types.entry_invalid;
15561579 }
......@@ -1574,36 +1597,36 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15741597 }
15751598
15761599 switch (type_entry->id) {
1577 case TypeTableEntryIdInvalid:
1600 case ZigTypeIdInvalid:
15781601 zig_unreachable();
1579 case TypeTableEntryIdUnreachable:
1580 case TypeTableEntryIdUndefined:
1581 case TypeTableEntryIdNull:
1582 case TypeTableEntryIdArgTuple:
1583 case TypeTableEntryIdOpaque:
1602 case ZigTypeIdUnreachable:
1603 case ZigTypeIdUndefined:
1604 case ZigTypeIdNull:
1605 case ZigTypeIdArgTuple:
1606 case ZigTypeIdOpaque:
15841607 add_node_error(g, param_node->data.param_decl.type,
15851608 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
15861609 return g->builtin_types.entry_invalid;
1587 case TypeTableEntryIdComptimeFloat:
1588 case TypeTableEntryIdComptimeInt:
1589 case TypeTableEntryIdNamespace:
1590 case TypeTableEntryIdBlock:
1591 case TypeTableEntryIdBoundFn:
1592 case TypeTableEntryIdMetaType:
1593 case TypeTableEntryIdVoid:
1594 case TypeTableEntryIdBool:
1595 case TypeTableEntryIdInt:
1596 case TypeTableEntryIdFloat:
1597 case TypeTableEntryIdPointer:
1598 case TypeTableEntryIdArray:
1599 case TypeTableEntryIdStruct:
1600 case TypeTableEntryIdOptional:
1601 case TypeTableEntryIdErrorUnion:
1602 case TypeTableEntryIdErrorSet:
1603 case TypeTableEntryIdEnum:
1604 case TypeTableEntryIdUnion:
1605 case TypeTableEntryIdFn:
1606 case TypeTableEntryIdPromise:
1610 case ZigTypeIdComptimeFloat:
1611 case ZigTypeIdComptimeInt:
1612 case ZigTypeIdNamespace:
1613 case ZigTypeIdBlock:
1614 case ZigTypeIdBoundFn:
1615 case ZigTypeIdMetaType:
1616 case ZigTypeIdVoid:
1617 case ZigTypeIdBool:
1618 case ZigTypeIdInt:
1619 case ZigTypeIdFloat:
1620 case ZigTypeIdPointer:
1621 case ZigTypeIdArray:
1622 case ZigTypeIdStruct:
1623 case ZigTypeIdOptional:
1624 case ZigTypeIdErrorUnion:
1625 case ZigTypeIdErrorSet:
1626 case ZigTypeIdEnum:
1627 case ZigTypeIdUnion:
1628 case ZigTypeIdFn:
1629 case ZigTypeIdPromise:
16071630 if ((err = type_ensure_zero_bits_known(g, type_entry)))
16081631 return g->builtin_types.entry_invalid;
16091632 if (type_requires_comptime(type_entry)) {
......@@ -1638,21 +1661,21 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
16381661 //return get_generic_fn_type(g, &fn_type_id);
16391662 }
16401663
1641 TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
1664 ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
16421665 if (type_is_invalid(specified_return_type)) {
16431666 fn_type_id.return_type = g->builtin_types.entry_invalid;
16441667 return g->builtin_types.entry_invalid;
16451668 }
16461669
16471670 if (fn_proto->auto_err_set) {
1648 TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
1671 ZigType *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
16491672 fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type);
16501673 } else {
16511674 fn_type_id.return_type = specified_return_type;
16521675 }
16531676
16541677 if (!calling_convention_allows_zig_types(fn_type_id.cc) &&
1655 fn_type_id.return_type->id != TypeTableEntryIdVoid &&
1678 fn_type_id.return_type->id != ZigTypeIdVoid &&
16561679 !type_allowed_in_extern(g, fn_type_id.return_type))
16571680 {
16581681 add_node_error(g, fn_proto->return_type,
......@@ -1663,38 +1686,38 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
16631686 }
16641687
16651688 switch (fn_type_id.return_type->id) {
1666 case TypeTableEntryIdInvalid:
1689 case ZigTypeIdInvalid:
16671690 zig_unreachable();
16681691
1669 case TypeTableEntryIdUndefined:
1670 case TypeTableEntryIdNull:
1671 case TypeTableEntryIdArgTuple:
1672 case TypeTableEntryIdOpaque:
1692 case ZigTypeIdUndefined:
1693 case ZigTypeIdNull:
1694 case ZigTypeIdArgTuple:
1695 case ZigTypeIdOpaque:
16731696 add_node_error(g, fn_proto->return_type,
16741697 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
16751698 return g->builtin_types.entry_invalid;
16761699
1677 case TypeTableEntryIdComptimeFloat:
1678 case TypeTableEntryIdComptimeInt:
1679 case TypeTableEntryIdNamespace:
1680 case TypeTableEntryIdBlock:
1681 case TypeTableEntryIdBoundFn:
1682 case TypeTableEntryIdMetaType:
1683 case TypeTableEntryIdUnreachable:
1684 case TypeTableEntryIdVoid:
1685 case TypeTableEntryIdBool:
1686 case TypeTableEntryIdInt:
1687 case TypeTableEntryIdFloat:
1688 case TypeTableEntryIdPointer:
1689 case TypeTableEntryIdArray:
1690 case TypeTableEntryIdStruct:
1691 case TypeTableEntryIdOptional:
1692 case TypeTableEntryIdErrorUnion:
1693 case TypeTableEntryIdErrorSet:
1694 case TypeTableEntryIdEnum:
1695 case TypeTableEntryIdUnion:
1696 case TypeTableEntryIdFn:
1697 case TypeTableEntryIdPromise:
1700 case ZigTypeIdComptimeFloat:
1701 case ZigTypeIdComptimeInt:
1702 case ZigTypeIdNamespace:
1703 case ZigTypeIdBlock:
1704 case ZigTypeIdBoundFn:
1705 case ZigTypeIdMetaType:
1706 case ZigTypeIdUnreachable:
1707 case ZigTypeIdVoid:
1708 case ZigTypeIdBool:
1709 case ZigTypeIdInt:
1710 case ZigTypeIdFloat:
1711 case ZigTypeIdPointer:
1712 case ZigTypeIdArray:
1713 case ZigTypeIdStruct:
1714 case ZigTypeIdOptional:
1715 case ZigTypeIdErrorUnion:
1716 case ZigTypeIdErrorSet:
1717 case ZigTypeIdEnum:
1718 case ZigTypeIdUnion:
1719 case ZigTypeIdFn:
1720 case ZigTypeIdPromise:
16981721 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
16991722 return g->builtin_types.entry_invalid;
17001723 if (type_requires_comptime(fn_type_id.return_type)) {
......@@ -1716,15 +1739,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
17161739 return get_fn_type(g, &fn_type_id);
17171740}
17181741
1719bool type_is_invalid(TypeTableEntry *type_entry) {
1742bool type_is_invalid(ZigType *type_entry) {
17201743 switch (type_entry->id) {
1721 case TypeTableEntryIdInvalid:
1744 case ZigTypeIdInvalid:
17221745 return true;
1723 case TypeTableEntryIdStruct:
1746 case ZigTypeIdStruct:
17241747 return type_entry->data.structure.is_invalid;
1725 case TypeTableEntryIdEnum:
1748 case ZigTypeIdEnum:
17261749 return type_entry->data.enumeration.is_invalid;
1727 case TypeTableEntryIdUnion:
1750 case ZigTypeIdUnion:
17281751 return type_entry->data.unionation.is_invalid;
17291752 default:
17301753 return false;
......@@ -1733,8 +1756,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
17331756}
17341757
17351758
1736static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
1737 assert(enum_type->id == TypeTableEntryIdEnum);
1759static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1760 assert(enum_type->id == ZigTypeIdEnum);
17381761
17391762 if (enum_type->data.enumeration.is_invalid)
17401763 return ErrorSemanticAnalyzeFail;
......@@ -1808,7 +1831,7 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
18081831 return ErrorNone;
18091832 }
18101833
1811 TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
1834 ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
18121835
18131836 // create debug type for tag
18141837 uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);
......@@ -1827,10 +1850,10 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
18271850}
18281851
18291852
1830TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
1831 TypeTableEntry *field_types[], size_t field_count)
1853ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
1854 ZigType *field_types[], size_t field_count)
18321855{
1833 TypeTableEntry *struct_type = new_type_table_entry(TypeTableEntryIdStruct);
1856 ZigType *struct_type = new_type_table_entry(ZigTypeIdStruct);
18341857
18351858 buf_init_from_str(&struct_type->name, type_name);
18361859
......@@ -1874,7 +1897,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
18741897 if (type_struct_field->gen_index == SIZE_MAX) {
18751898 continue;
18761899 }
1877 TypeTableEntry *field_type = type_struct_field->type_entry;
1900 ZigType *field_type = type_struct_field->type_entry;
18781901 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref);
18791902 uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref);
18801903 uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, type_struct_field->gen_index);
......@@ -1906,8 +1929,8 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
19061929 return struct_type;
19071930}
19081931
1909static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
1910 assert(struct_type->id == TypeTableEntryIdStruct);
1932static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1933 assert(struct_type->id == ZigTypeIdStruct);
19111934
19121935 if (struct_type->data.structure.complete)
19131936 return ErrorNone;
......@@ -1950,7 +1973,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
19501973
19511974 for (size_t i = 0; i < field_count; i += 1) {
19521975 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
1953 TypeTableEntry *field_type = type_struct_field->type_entry;
1976 ZigType *field_type = type_struct_field->type_entry;
19541977
19551978 if ((err = ensure_complete_type(g, field_type))) {
19561979 struct_type->data.structure.is_invalid = true;
......@@ -2081,12 +2104,12 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
20812104 continue;
20822105 }
20832106
2084 TypeTableEntry *field_type = type_struct_field->type_entry;
2107 ZigType *field_type = type_struct_field->type_entry;
20852108
20862109 // if the field is a function, actually the debug info should be a pointer.
20872110 ZigLLVMDIType *field_di_type;
2088 if (field_type->id == TypeTableEntryIdFn) {
2089 TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true);
2111 if (field_type->id == ZigTypeIdFn) {
2112 ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true);
20902113 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);
20912114 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);
20922115 field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type,
......@@ -2140,8 +2163,8 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
21402163 return ErrorNone;
21412164}
21422165
2143static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
2144 assert(union_type->id == TypeTableEntryIdUnion);
2166static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2167 assert(union_type->id == ZigTypeIdUnion);
21452168
21462169 if (union_type->data.unionation.complete)
21472170 return ErrorNone;
......@@ -2172,7 +2195,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
21722195 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
21732196 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);
21742197
2175 TypeTableEntry *most_aligned_union_member = nullptr;
2198 ZigType *most_aligned_union_member = nullptr;
21762199 uint64_t size_of_most_aligned_member_in_bits = 0;
21772200 uint64_t biggest_align_in_bits = 0;
21782201 uint64_t biggest_size_in_bits = 0;
......@@ -2187,7 +2210,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
21872210 for (uint32_t i = 0; i < field_count; i += 1) {
21882211 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
21892212 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
2190 TypeTableEntry *field_type = union_field->type_entry;
2213 ZigType *field_type = union_field->type_entry;
21912214
21922215 if ((err = ensure_complete_type(g, field_type))) {
21932216 union_type->data.unionation.is_invalid = true;
......@@ -2252,13 +2275,13 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
22522275
22532276 uint64_t padding_in_bits = biggest_size_in_bits - size_of_most_aligned_member_in_bits;
22542277
2255 TypeTableEntry *tag_type = union_type->data.unionation.tag_type;
2278 ZigType *tag_type = union_type->data.unionation.tag_type;
22562279 if (tag_type == nullptr || tag_type->zero_bits) {
22572280 assert(most_aligned_union_member != nullptr);
22582281
22592282 if (padding_in_bits > 0) {
2260 TypeTableEntry *u8_type = get_int_type(g, false, 8);
2261 TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
2283 ZigType *u8_type = get_int_type(g, false, 8);
2284 ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
22622285 LLVMTypeRef union_element_types[] = {
22632286 most_aligned_union_member->type_ref,
22642287 padding_array->type_ref,
......@@ -2288,8 +2311,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
22882311
22892312 LLVMTypeRef union_type_ref;
22902313 if (padding_in_bits > 0) {
2291 TypeTableEntry *u8_type = get_int_type(g, false, 8);
2292 TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
2314 ZigType *u8_type = get_int_type(g, false, 8);
2315 ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
22932316 LLVMTypeRef union_element_types[] = {
22942317 most_aligned_union_member->type_ref,
22952318 padding_array->type_ref,
......@@ -2312,7 +2335,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
23122335 assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits);
23132336
23142337 // create llvm type for root struct
2315 TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type;
2338 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
23162339 uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);
23172340
23182341 if (align_of_tag_in_bits >= biggest_align_in_bits) {
......@@ -2380,8 +2403,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
23802403 return ErrorNone;
23812404}
23822405
2383static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2384 assert(enum_type->id == TypeTableEntryIdEnum);
2406static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2407 assert(enum_type->id == ZigTypeIdEnum);
23852408
23862409 if (enum_type->data.enumeration.zero_bits_known)
23872410 return ErrorNone;
......@@ -2421,7 +2444,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
24212444 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
24222445 occupied_tag_values.init(field_count);
24232446
2424 TypeTableEntry *tag_int_type;
2447 ZigType *tag_int_type;
24252448 if (enum_type->data.enumeration.layout == ContainerLayoutExtern) {
24262449 tag_int_type = get_c_int_type(g, CIntTypeInt);
24272450 } else {
......@@ -2430,10 +2453,10 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
24302453
24312454 // TODO: Are extern enums allowed to have an init_arg_expr?
24322455 if (decl_node->data.container_decl.init_arg_expr != nullptr) {
2433 TypeTableEntry *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
2456 ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
24342457 if (type_is_invalid(wanted_tag_int_type)) {
24352458 enum_type->data.enumeration.is_invalid = true;
2436 } else if (wanted_tag_int_type->id != TypeTableEntryIdInt) {
2459 } else if (wanted_tag_int_type->id != ZigTypeIdInt) {
24372460 enum_type->data.enumeration.is_invalid = true;
24382461 add_node_error(g, decl_node->data.container_decl.init_arg_expr,
24392462 buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name)));
......@@ -2482,12 +2505,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
24822505 // In a second pass we will fill in the unspecified ones.
24832506 if (tag_value != nullptr) {
24842507 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
2485 if (result_inst->value.type->id == TypeTableEntryIdInvalid) {
2508 if (result_inst->value.type->id == ZigTypeIdInvalid) {
24862509 enum_type->data.enumeration.is_invalid = true;
24872510 continue;
24882511 }
24892512 assert(result_inst->value.special != ConstValSpecialRuntime);
2490 assert(result_inst->value.type->id == TypeTableEntryIdInt);
2513 assert(result_inst->value.type->id == ZigTypeIdInt);
24912514 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
24922515 if (entry == nullptr) {
24932516 bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint);
......@@ -2543,8 +2566,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
25432566 return ErrorNone;
25442567}
25452568
2546static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2547 assert(struct_type->id == TypeTableEntryIdStruct);
2569static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2570 assert(struct_type->id == ZigTypeIdStruct);
25482571
25492572 Error err;
25502573
......@@ -2607,7 +2630,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
26072630 continue;
26082631 }
26092632
2610 TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
2633 ZigType *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
26112634 type_struct_field->type_entry = field_type;
26122635 type_struct_field->src_index = i;
26132636 type_struct_field->gen_index = SIZE_MAX;
......@@ -2662,8 +2685,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
26622685 return ErrorNone;
26632686}
26642687
2665static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2666 assert(union_type->id == TypeTableEntryIdUnion);
2688static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2689 assert(union_type->id == ZigTypeIdUnion);
26672690
26682691 Error err;
26692692
......@@ -2727,7 +2750,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
27272750 enum_type_node != nullptr;
27282751 bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto);
27292752 bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr);
2730 TypeTableEntry *tag_type;
2753 ZigType *tag_type;
27312754 bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety);
27322755 bool *covered_enum_fields;
27332756 ZigLLVMDIEnumerator **di_enumerators;
......@@ -2737,14 +2760,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
27372760
27382761 di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
27392762
2740 TypeTableEntry *tag_int_type;
2763 ZigType *tag_int_type;
27412764 if (enum_type_node != nullptr) {
27422765 tag_int_type = analyze_type_expr(g, scope, enum_type_node);
27432766 if (type_is_invalid(tag_int_type)) {
27442767 union_type->data.unionation.is_invalid = true;
27452768 return ErrorSemanticAnalyzeFail;
27462769 }
2747 if (tag_int_type->id != TypeTableEntryIdInt) {
2770 if (tag_int_type->id != ZigTypeIdInt) {
27482771 add_node_error(g, enum_type_node,
27492772 buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));
27502773 union_type->data.unionation.is_invalid = true;
......@@ -2755,7 +2778,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
27552778 }
27562779 abi_alignment_so_far = get_abi_alignment(g, tag_int_type);
27572780
2758 tag_type = new_type_table_entry(TypeTableEntryIdEnum);
2781 tag_type = new_type_table_entry(ZigTypeIdEnum);
27592782 buf_resize(&tag_type->name, 0);
27602783 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));
27612784 tag_type->is_copyable = true;
......@@ -2772,12 +2795,12 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
27722795 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
27732796 tag_type->data.enumeration.complete = true;
27742797 } else if (enum_type_node != nullptr) {
2775 TypeTableEntry *enum_type = analyze_type_expr(g, scope, enum_type_node);
2798 ZigType *enum_type = analyze_type_expr(g, scope, enum_type_node);
27762799 if (type_is_invalid(enum_type)) {
27772800 union_type->data.unionation.is_invalid = true;
27782801 return ErrorSemanticAnalyzeFail;
27792802 }
2780 if (enum_type->id != TypeTableEntryIdEnum) {
2803 if (enum_type->id != ZigTypeIdEnum) {
27812804 union_type->data.unionation.is_invalid = true;
27822805 add_node_error(g, enum_type_node,
27832806 buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name)));
......@@ -2809,7 +2832,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
28092832 continue;
28102833 }
28112834
2812 TypeTableEntry *field_type;
2835 ZigType *field_type;
28132836 if (field_node->data.struct_field.type == nullptr) {
28142837 if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) {
28152838 field_type = g->builtin_types.entry_void;
......@@ -2853,14 +2876,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
28532876 // In this first pass we resolve explicit tag values.
28542877 // In a second pass we will fill in the unspecified ones.
28552878 if (tag_value != nullptr) {
2856 TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type;
2879 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
28572880 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
2858 if (result_inst->value.type->id == TypeTableEntryIdInvalid) {
2881 if (result_inst->value.type->id == ZigTypeIdInvalid) {
28592882 union_type->data.unionation.is_invalid = true;
28602883 continue;
28612884 }
28622885 assert(result_inst->value.special != ConstValSpecialRuntime);
2863 assert(result_inst->value.type->id == TypeTableEntryIdInt);
2886 assert(result_inst->value.type->id == ZigTypeIdInt);
28642887 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
28652888 if (entry == nullptr) {
28662889 bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint);
......@@ -3031,8 +3054,8 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, uint8_t sep) {
30313054 buf_append_buf(buf, tld->name);
30323055}
30333056
3034FnTableEntry *create_fn_raw(FnInline inline_value) {
3035 FnTableEntry *fn_entry = allocate<FnTableEntry>(1);
3057ZigFn *create_fn_raw(FnInline inline_value) {
3058 ZigFn *fn_entry = allocate<ZigFn>(1);
30363059
30373060 fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
30383061 fn_entry->analyzed_executable.backward_branch_quota = default_backward_branch_quota;
......@@ -3043,12 +3066,12 @@ FnTableEntry *create_fn_raw(FnInline inline_value) {
30433066 return fn_entry;
30443067}
30453068
3046FnTableEntry *create_fn(AstNode *proto_node) {
3069ZigFn *create_fn(AstNode *proto_node) {
30473070 assert(proto_node->type == NodeTypeFnProto);
30483071 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
30493072
30503073 FnInline inline_value = fn_proto->is_inline ? FnInlineAlways : FnInlineAuto;
3051 FnTableEntry *fn_entry = create_fn_raw(inline_value);
3074 ZigFn *fn_entry = create_fn_raw(inline_value);
30523075
30533076 fn_entry->proto_node = proto_node;
30543077 fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr :
......@@ -3068,39 +3091,39 @@ static bool scope_is_root_decls(Scope *scope) {
30683091 zig_unreachable();
30693092}
30703093
3071static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {
3094static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, ZigType *fn_type) {
30723095 add_node_error(g, proto_node,
30733096 buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'",
30743097 buf_ptr(&fn_type->name)));
30753098}
30763099
3077static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
3100static void typecheck_panic_fn(CodeGen *g, ZigFn *panic_fn) {
30783101 AstNode *proto_node = panic_fn->proto_node;
30793102 assert(proto_node->type == NodeTypeFnProto);
3080 TypeTableEntry *fn_type = panic_fn->type_entry;
3103 ZigType *fn_type = panic_fn->type_entry;
30813104 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
30823105 if (fn_type_id->param_count != 2) {
30833106 return wrong_panic_prototype(g, proto_node, fn_type);
30843107 }
3085 TypeTableEntry *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
3108 ZigType *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
30863109 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
3087 TypeTableEntry *const_u8_slice = get_slice_type(g, const_u8_ptr);
3110 ZigType *const_u8_slice = get_slice_type(g, const_u8_ptr);
30883111 if (fn_type_id->param_info[0].type != const_u8_slice) {
30893112 return wrong_panic_prototype(g, proto_node, fn_type);
30903113 }
30913114
3092 TypeTableEntry *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g));
3115 ZigType *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g));
30933116 if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {
30943117 return wrong_panic_prototype(g, proto_node, fn_type);
30953118 }
30963119
3097 TypeTableEntry *actual_return_type = fn_type_id->return_type;
3120 ZigType *actual_return_type = fn_type_id->return_type;
30983121 if (actual_return_type != g->builtin_types.entry_unreachable) {
30993122 return wrong_panic_prototype(g, proto_node, fn_type);
31003123 }
31013124}
31023125
3103TypeTableEntry *get_test_fn_type(CodeGen *g) {
3126ZigType *get_test_fn_type(CodeGen *g) {
31043127 if (g->test_fn_type)
31053128 return g->test_fn_type;
31063129
......@@ -3111,7 +3134,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
31113134 return g->test_fn_type;
31123135}
31133136
3114void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
3137void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
31153138 if (ccc) {
31163139 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
31173140 g->have_c_main = true;
......@@ -3147,7 +3170,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
31473170
31483171 AstNode *fn_def_node = fn_proto->fn_def_node;
31493172
3150 FnTableEntry *fn_table_entry = create_fn(source_node);
3173 ZigFn *fn_table_entry = create_fn(source_node);
31513174 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
31523175
31533176 if (fn_proto->is_export) {
......@@ -3185,7 +3208,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
31853208 }
31863209 }
31873210
3188 if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {
3211 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
31893212 tld_fn->base.resolution = TldResolutionInvalid;
31903213 return;
31913214 }
......@@ -3208,7 +3231,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
32083231 }
32093232 }
32103233 } else if (source_node->type == NodeTypeTestDecl) {
3211 FnTableEntry *fn_table_entry = create_fn_raw(FnInlineAuto);
3234 ZigFn *fn_table_entry = create_fn_raw(FnInlineAuto);
32123235
32133236 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
32143237
......@@ -3273,7 +3296,7 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
32733296 }
32743297
32753298 {
3276 TypeTableEntry *type = get_primitive_type(g, tld->name);
3299 ZigType *type = get_primitive_type(g, tld->name);
32773300 if (type != nullptr) {
32783301 add_node_error(g, tld->source_node,
32793302 buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));
......@@ -3437,17 +3460,17 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
34373460}
34383461
34393462static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
3440 TypeTableEntry *type_entry = tld_container->type_entry;
3463 ZigType *type_entry = tld_container->type_entry;
34413464 assert(type_entry);
34423465
34433466 switch (type_entry->id) {
3444 case TypeTableEntryIdStruct:
3467 case ZigTypeIdStruct:
34453468 resolve_struct_type(g, tld_container->type_entry);
34463469 return;
3447 case TypeTableEntryIdEnum:
3470 case ZigTypeIdEnum:
34483471 resolve_enum_type(g, tld_container->type_entry);
34493472 return;
3450 case TypeTableEntryIdUnion:
3473 case ZigTypeIdUnion:
34513474 resolve_union_type(g, tld_container->type_entry);
34523475 return;
34533476 default:
......@@ -3455,38 +3478,38 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
34553478 }
34563479}
34573480
3458TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry) {
3481ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) {
34593482 switch (type_entry->id) {
3460 case TypeTableEntryIdInvalid:
3483 case ZigTypeIdInvalid:
34613484 return g->builtin_types.entry_invalid;
3462 case TypeTableEntryIdUnreachable:
3463 case TypeTableEntryIdUndefined:
3464 case TypeTableEntryIdNull:
3465 case TypeTableEntryIdBlock:
3466 case TypeTableEntryIdArgTuple:
3467 case TypeTableEntryIdOpaque:
3485 case ZigTypeIdUnreachable:
3486 case ZigTypeIdUndefined:
3487 case ZigTypeIdNull:
3488 case ZigTypeIdBlock:
3489 case ZigTypeIdArgTuple:
3490 case ZigTypeIdOpaque:
34683491 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
34693492 buf_ptr(&type_entry->name)));
34703493 return g->builtin_types.entry_invalid;
3471 case TypeTableEntryIdComptimeFloat:
3472 case TypeTableEntryIdComptimeInt:
3473 case TypeTableEntryIdNamespace:
3474 case TypeTableEntryIdMetaType:
3475 case TypeTableEntryIdVoid:
3476 case TypeTableEntryIdBool:
3477 case TypeTableEntryIdInt:
3478 case TypeTableEntryIdFloat:
3479 case TypeTableEntryIdPointer:
3480 case TypeTableEntryIdArray:
3481 case TypeTableEntryIdStruct:
3482 case TypeTableEntryIdOptional:
3483 case TypeTableEntryIdErrorUnion:
3484 case TypeTableEntryIdErrorSet:
3485 case TypeTableEntryIdEnum:
3486 case TypeTableEntryIdUnion:
3487 case TypeTableEntryIdFn:
3488 case TypeTableEntryIdBoundFn:
3489 case TypeTableEntryIdPromise:
3494 case ZigTypeIdComptimeFloat:
3495 case ZigTypeIdComptimeInt:
3496 case ZigTypeIdNamespace:
3497 case ZigTypeIdMetaType:
3498 case ZigTypeIdVoid:
3499 case ZigTypeIdBool:
3500 case ZigTypeIdInt:
3501 case ZigTypeIdFloat:
3502 case ZigTypeIdPointer:
3503 case ZigTypeIdArray:
3504 case ZigTypeIdStruct:
3505 case ZigTypeIdOptional:
3506 case ZigTypeIdErrorUnion:
3507 case ZigTypeIdErrorSet:
3508 case ZigTypeIdEnum:
3509 case ZigTypeIdUnion:
3510 case ZigTypeIdFn:
3511 case ZigTypeIdBoundFn:
3512 case ZigTypeIdPromise:
34903513 return type_entry;
34913514 }
34923515 zig_unreachable();
......@@ -3494,12 +3517,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
34943517
34953518// Set name to nullptr to make the variable anonymous (not visible to programmer).
34963519// TODO merge with definition of add_local_var in ir.cpp
3497VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
3520ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
34983521 bool is_const, ConstExprValue *value, Tld *src_tld)
34993522{
35003523 assert(value);
35013524
3502 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
3525 ZigVar *variable_entry = allocate<ZigVar>(1);
35033526 variable_entry->value = value;
35043527 variable_entry->parent_scope = parent_scope;
35053528 variable_entry->shadowable = false;
......@@ -3512,14 +3535,14 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
35123535 if (!type_is_invalid(value->type)) {
35133536 variable_entry->align_bytes = get_abi_alignment(g, value->type);
35143537
3515 VariableTableEntry *existing_var = find_variable(g, parent_scope, name);
3538 ZigVar *existing_var = find_variable(g, parent_scope, name, nullptr);
35163539 if (existing_var && !existing_var->shadowable) {
35173540 ErrorMsg *msg = add_node_error(g, source_node,
35183541 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
35193542 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
35203543 variable_entry->value->type = g->builtin_types.entry_invalid;
35213544 } else {
3522 TypeTableEntry *type = get_primitive_type(g, name);
3545 ZigType *type = get_primitive_type(g, name);
35233546 if (type != nullptr) {
35243547 add_node_error(g, source_node,
35253548 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
......@@ -3570,9 +3593,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
35703593 bool is_extern = var_decl->is_extern;
35713594 bool is_export = var_decl->is_export;
35723595
3573 TypeTableEntry *explicit_type = nullptr;
3596 ZigType *explicit_type = nullptr;
35743597 if (var_decl->type) {
3575 TypeTableEntry *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
3598 ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
35763599 explicit_type = validate_var_type(g, var_decl->type, proposed_type);
35773600 }
35783601
......@@ -3590,37 +3613,37 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
35903613 IrInstruction *init_value = nullptr;
35913614
35923615 // TODO more validation for types that can't be used for export/extern variables
3593 TypeTableEntry *implicit_type = nullptr;
3594 if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) {
3616 ZigType *implicit_type = nullptr;
3617 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {
35953618 implicit_type = explicit_type;
35963619 } else if (var_decl->expr) {
35973620 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);
35983621 assert(init_value);
35993622 implicit_type = init_value->value.type;
36003623
3601 if (implicit_type->id == TypeTableEntryIdUnreachable) {
3624 if (implicit_type->id == ZigTypeIdUnreachable) {
36023625 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
36033626 implicit_type = g->builtin_types.entry_invalid;
36043627 } else if ((!is_const || linkage == VarLinkageExternal) &&
3605 (implicit_type->id == TypeTableEntryIdComptimeFloat ||
3606 implicit_type->id == TypeTableEntryIdComptimeInt))
3628 (implicit_type->id == ZigTypeIdComptimeFloat ||
3629 implicit_type->id == ZigTypeIdComptimeInt))
36073630 {
36083631 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
36093632 implicit_type = g->builtin_types.entry_invalid;
3610 } else if (implicit_type->id == TypeTableEntryIdNull) {
3633 } else if (implicit_type->id == ZigTypeIdNull) {
36113634 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
36123635 implicit_type = g->builtin_types.entry_invalid;
3613 } else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) {
3636 } else if (implicit_type->id == ZigTypeIdMetaType && !is_const) {
36143637 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));
36153638 implicit_type = g->builtin_types.entry_invalid;
36163639 }
3617 assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime);
3640 assert(implicit_type->id == ZigTypeIdInvalid || init_value->value.special != ConstValSpecialRuntime);
36183641 } else if (linkage != VarLinkageExternal) {
36193642 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
36203643 implicit_type = g->builtin_types.entry_invalid;
36213644 }
36223645
3623 TypeTableEntry *type = explicit_type ? explicit_type : implicit_type;
3646 ZigType *type = explicit_type ? explicit_type : implicit_type;
36243647 assert(type != nullptr); // should have been caught by the parser
36253648
36263649 ConstExprValue *init_val = init_value ? &init_value->value : create_const_runtime(type);
......@@ -3719,12 +3742,16 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
37193742 return nullptr;
37203743}
37213744
3722VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
3745ZigVar *find_variable(CodeGen *g, Scope *scope, Buf *name, ScopeFnDef **crossed_fndef_scope) {
3746 ScopeFnDef *my_crossed_fndef_scope = nullptr;
37233747 while (scope) {
37243748 if (scope->id == ScopeIdVarDecl) {
37253749 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
3726 if (buf_eql_buf(name, &var_scope->var->name))
3750 if (buf_eql_buf(name, &var_scope->var->name)) {
3751 if (crossed_fndef_scope != nullptr)
3752 *crossed_fndef_scope = my_crossed_fndef_scope;
37273753 return var_scope->var;
3754 }
37283755 } else if (scope->id == ScopeIdDecls) {
37293756 ScopeDecls *decls_scope = (ScopeDecls *)scope;
37303757 auto entry = decls_scope->decl_table.maybe_get(name);
......@@ -3732,10 +3759,15 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
37323759 Tld *tld = entry->value;
37333760 if (tld->id == TldIdVar) {
37343761 TldVar *tld_var = (TldVar *)tld;
3735 if (tld_var->var)
3762 if (tld_var->var) {
3763 if (crossed_fndef_scope != nullptr)
3764 *crossed_fndef_scope = nullptr;
37363765 return tld_var->var;
3766 }
37373767 }
37383768 }
3769 } else if (scope->id == ScopeIdFnDef) {
3770 my_crossed_fndef_scope = (ScopeFnDef *)scope;
37393771 }
37403772 scope = scope->parent;
37413773 }
......@@ -3743,7 +3775,7 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
37433775 return nullptr;
37443776}
37453777
3746FnTableEntry *scope_fn_entry(Scope *scope) {
3778ZigFn *scope_fn_entry(Scope *scope) {
37473779 while (scope) {
37483780 if (scope->id == ScopeIdFnDef) {
37493781 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
......@@ -3754,7 +3786,7 @@ FnTableEntry *scope_fn_entry(Scope *scope) {
37543786 return nullptr;
37553787}
37563788
3757FnTableEntry *scope_get_fn_if_root(Scope *scope) {
3789ZigFn *scope_get_fn_if_root(Scope *scope) {
37583790 assert(scope);
37593791 scope = scope->parent;
37603792 while (scope) {
......@@ -3770,6 +3802,7 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
37703802 case ScopeIdSuspend:
37713803 case ScopeIdCompTime:
37723804 case ScopeIdCoroPrelude:
3805 case ScopeIdRuntime:
37733806 scope = scope->parent;
37743807 continue;
37753808 case ScopeIdFnDef:
......@@ -3781,8 +3814,8 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
37813814 return nullptr;
37823815}
37833816
3784TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
3785 assert(enum_type->id == TypeTableEntryIdEnum);
3817TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
3818 assert(enum_type->id == ZigTypeIdEnum);
37863819 if (enum_type->data.enumeration.src_field_count == 0)
37873820 return nullptr;
37883821 auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);
......@@ -3791,8 +3824,8 @@ TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
37913824 return entry->value;
37923825}
37933826
3794TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
3795 assert(type_entry->id == TypeTableEntryIdStruct);
3827TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {
3828 assert(type_entry->id == ZigTypeIdStruct);
37963829 assert(type_entry->data.structure.complete);
37973830 if (type_entry->data.structure.src_field_count == 0)
37983831 return nullptr;
......@@ -3802,8 +3835,8 @@ TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
38023835 return entry->value;
38033836}
38043837
3805TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
3806 assert(type_entry->id == TypeTableEntryIdUnion);
3838TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {
3839 assert(type_entry->id == ZigTypeIdUnion);
38073840 assert(type_entry->data.unionation.zero_bits_known);
38083841 if (type_entry->data.unionation.src_field_count == 0)
38093842 return nullptr;
......@@ -3813,8 +3846,8 @@ TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
38133846 return entry->value;
38143847}
38153848
3816TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) {
3817 assert(type_entry->id == TypeTableEntryIdUnion);
3849TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) {
3850 assert(type_entry->id == ZigTypeIdUnion);
38183851 assert(type_entry->data.unionation.zero_bits_known);
38193852 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
38203853 TypeUnionField *field = &type_entry->data.unionation.fields[i];
......@@ -3825,7 +3858,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt
38253858 return nullptr;
38263859}
38273860
3828TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag) {
3861TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) {
38293862 assert(enum_type->data.enumeration.zero_bits_known);
38303863 for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {
38313864 TypeEnumField *field = &enum_type->data.enumeration.fields[i];
......@@ -3837,143 +3870,143 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t
38373870}
38383871
38393872
3840static bool is_container(TypeTableEntry *type_entry) {
3873static bool is_container(ZigType *type_entry) {
38413874 switch (type_entry->id) {
3842 case TypeTableEntryIdInvalid:
3875 case ZigTypeIdInvalid:
38433876 zig_unreachable();
3844 case TypeTableEntryIdStruct:
3845 case TypeTableEntryIdEnum:
3846 case TypeTableEntryIdUnion:
3877 case ZigTypeIdStruct:
3878 case ZigTypeIdEnum:
3879 case ZigTypeIdUnion:
38473880 return true;
3848 case TypeTableEntryIdPointer:
3849 case TypeTableEntryIdMetaType:
3850 case TypeTableEntryIdVoid:
3851 case TypeTableEntryIdBool:
3852 case TypeTableEntryIdUnreachable:
3853 case TypeTableEntryIdInt:
3854 case TypeTableEntryIdFloat:
3855 case TypeTableEntryIdArray:
3856 case TypeTableEntryIdComptimeFloat:
3857 case TypeTableEntryIdComptimeInt:
3858 case TypeTableEntryIdUndefined:
3859 case TypeTableEntryIdNull:
3860 case TypeTableEntryIdOptional:
3861 case TypeTableEntryIdErrorUnion:
3862 case TypeTableEntryIdErrorSet:
3863 case TypeTableEntryIdFn:
3864 case TypeTableEntryIdNamespace:
3865 case TypeTableEntryIdBlock:
3866 case TypeTableEntryIdBoundFn:
3867 case TypeTableEntryIdArgTuple:
3868 case TypeTableEntryIdOpaque:
3869 case TypeTableEntryIdPromise:
3881 case ZigTypeIdPointer:
3882 case ZigTypeIdMetaType:
3883 case ZigTypeIdVoid:
3884 case ZigTypeIdBool:
3885 case ZigTypeIdUnreachable:
3886 case ZigTypeIdInt:
3887 case ZigTypeIdFloat:
3888 case ZigTypeIdArray:
3889 case ZigTypeIdComptimeFloat:
3890 case ZigTypeIdComptimeInt:
3891 case ZigTypeIdUndefined:
3892 case ZigTypeIdNull:
3893 case ZigTypeIdOptional:
3894 case ZigTypeIdErrorUnion:
3895 case ZigTypeIdErrorSet:
3896 case ZigTypeIdFn:
3897 case ZigTypeIdNamespace:
3898 case ZigTypeIdBlock:
3899 case ZigTypeIdBoundFn:
3900 case ZigTypeIdArgTuple:
3901 case ZigTypeIdOpaque:
3902 case ZigTypeIdPromise:
38703903 return false;
38713904 }
38723905 zig_unreachable();
38733906}
38743907
3875bool is_ref(TypeTableEntry *type_entry) {
3876 return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
3908bool is_ref(ZigType *type_entry) {
3909 return type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
38773910}
38783911
3879bool is_array_ref(TypeTableEntry *type_entry) {
3880 TypeTableEntry *array = is_ref(type_entry) ?
3912bool is_array_ref(ZigType *type_entry) {
3913 ZigType *array = is_ref(type_entry) ?
38813914 type_entry->data.pointer.child_type : type_entry;
3882 return array->id == TypeTableEntryIdArray;
3915 return array->id == ZigTypeIdArray;
38833916}
38843917
3885bool is_container_ref(TypeTableEntry *type_entry) {
3918bool is_container_ref(ZigType *type_entry) {
38863919 return is_ref(type_entry) ?
38873920 is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
38883921}
38893922
3890TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {
3923ZigType *container_ref_type(ZigType *type_entry) {
38913924 assert(is_container_ref(type_entry));
38923925 return is_ref(type_entry) ?
38933926 type_entry->data.pointer.child_type : type_entry;
38943927}
38953928
3896void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
3929void resolve_container_type(CodeGen *g, ZigType *type_entry) {
38973930 switch (type_entry->id) {
3898 case TypeTableEntryIdStruct:
3931 case ZigTypeIdStruct:
38993932 resolve_struct_type(g, type_entry);
39003933 break;
3901 case TypeTableEntryIdEnum:
3934 case ZigTypeIdEnum:
39023935 resolve_enum_type(g, type_entry);
39033936 break;
3904 case TypeTableEntryIdUnion:
3937 case ZigTypeIdUnion:
39053938 resolve_union_type(g, type_entry);
39063939 break;
3907 case TypeTableEntryIdPointer:
3908 case TypeTableEntryIdMetaType:
3909 case TypeTableEntryIdVoid:
3910 case TypeTableEntryIdBool:
3911 case TypeTableEntryIdUnreachable:
3912 case TypeTableEntryIdInt:
3913 case TypeTableEntryIdFloat:
3914 case TypeTableEntryIdArray:
3915 case TypeTableEntryIdComptimeFloat:
3916 case TypeTableEntryIdComptimeInt:
3917 case TypeTableEntryIdUndefined:
3918 case TypeTableEntryIdNull:
3919 case TypeTableEntryIdOptional:
3920 case TypeTableEntryIdErrorUnion:
3921 case TypeTableEntryIdErrorSet:
3922 case TypeTableEntryIdFn:
3923 case TypeTableEntryIdNamespace:
3924 case TypeTableEntryIdBlock:
3925 case TypeTableEntryIdBoundFn:
3926 case TypeTableEntryIdInvalid:
3927 case TypeTableEntryIdArgTuple:
3928 case TypeTableEntryIdOpaque:
3929 case TypeTableEntryIdPromise:
3940 case ZigTypeIdPointer:
3941 case ZigTypeIdMetaType:
3942 case ZigTypeIdVoid:
3943 case ZigTypeIdBool:
3944 case ZigTypeIdUnreachable:
3945 case ZigTypeIdInt:
3946 case ZigTypeIdFloat:
3947 case ZigTypeIdArray:
3948 case ZigTypeIdComptimeFloat:
3949 case ZigTypeIdComptimeInt:
3950 case ZigTypeIdUndefined:
3951 case ZigTypeIdNull:
3952 case ZigTypeIdOptional:
3953 case ZigTypeIdErrorUnion:
3954 case ZigTypeIdErrorSet:
3955 case ZigTypeIdFn:
3956 case ZigTypeIdNamespace:
3957 case ZigTypeIdBlock:
3958 case ZigTypeIdBoundFn:
3959 case ZigTypeIdInvalid:
3960 case ZigTypeIdArgTuple:
3961 case ZigTypeIdOpaque:
3962 case ZigTypeIdPromise:
39303963 zig_unreachable();
39313964 }
39323965}
39333966
3934TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
3935 if (type->id == TypeTableEntryIdPointer) return type;
3936 if (type->id == TypeTableEntryIdFn) return type;
3937 if (type->id == TypeTableEntryIdPromise) return type;
3938 if (type->id == TypeTableEntryIdOptional) {
3939 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;
3940 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;
3941 if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;
3967ZigType *get_codegen_ptr_type(ZigType *type) {
3968 if (type->id == ZigTypeIdPointer) return type;
3969 if (type->id == ZigTypeIdFn) return type;
3970 if (type->id == ZigTypeIdPromise) return type;
3971 if (type->id == ZigTypeIdOptional) {
3972 if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type;
3973 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
3974 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
39423975 }
39433976 return nullptr;
39443977}
39453978
3946bool type_is_codegen_pointer(TypeTableEntry *type) {
3979bool type_is_codegen_pointer(ZigType *type) {
39473980 return get_codegen_ptr_type(type) == type;
39483981}
39493982
3950uint32_t get_ptr_align(TypeTableEntry *type) {
3951 TypeTableEntry *ptr_type = get_codegen_ptr_type(type);
3952 if (ptr_type->id == TypeTableEntryIdPointer) {
3983uint32_t get_ptr_align(ZigType *type) {
3984 ZigType *ptr_type = get_codegen_ptr_type(type);
3985 if (ptr_type->id == ZigTypeIdPointer) {
39533986 return ptr_type->data.pointer.alignment;
3954 } else if (ptr_type->id == TypeTableEntryIdFn) {
3987 } else if (ptr_type->id == ZigTypeIdFn) {
39553988 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
3956 } else if (ptr_type->id == TypeTableEntryIdPromise) {
3989 } else if (ptr_type->id == ZigTypeIdPromise) {
39573990 return 1;
39583991 } else {
39593992 zig_unreachable();
39603993 }
39613994}
39623995
3963bool get_ptr_const(TypeTableEntry *type) {
3964 TypeTableEntry *ptr_type = get_codegen_ptr_type(type);
3965 if (ptr_type->id == TypeTableEntryIdPointer) {
3996bool get_ptr_const(ZigType *type) {
3997 ZigType *ptr_type = get_codegen_ptr_type(type);
3998 if (ptr_type->id == ZigTypeIdPointer) {
39663999 return ptr_type->data.pointer.is_const;
3967 } else if (ptr_type->id == TypeTableEntryIdFn) {
4000 } else if (ptr_type->id == ZigTypeIdFn) {
39684001 return true;
3969 } else if (ptr_type->id == TypeTableEntryIdPromise) {
4002 } else if (ptr_type->id == ZigTypeIdPromise) {
39704003 return true;
39714004 } else {
39724005 zig_unreachable();
39734006 }
39744007}
39754008
3976AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {
4009AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) {
39774010 if (fn_entry->param_source_nodes)
39784011 return fn_entry->param_source_nodes[index];
39794012 else if (fn_entry->proto_node)
......@@ -3982,8 +4015,8 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {
39824015 return nullptr;
39834016}
39844017
3985static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry) {
3986 TypeTableEntry *fn_type = fn_table_entry->type_entry;
4018static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4019 ZigType *fn_type = fn_table_entry->type_entry;
39874020 assert(!fn_type->data.fn.is_generic);
39884021 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
39894022 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
......@@ -4000,14 +4033,14 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
40004033 continue;
40014034 }
40024035
4003 TypeTableEntry *param_type = param_info->type;
4036 ZigType *param_type = param_info->type;
40044037 bool is_noalias = param_info->is_noalias;
40054038
40064039 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
40074040 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
40084041 }
40094042
4010 VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
4043 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
40114044 param_name, true, create_const_runtime(param_type), nullptr);
40124045 var->src_arg_index = i;
40134046 fn_table_entry->child_scope = var->child_scope;
......@@ -4023,8 +4056,8 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
40234056 }
40244057}
40254058
4026bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
4027 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
4059bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
4060 ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;
40284061 if (infer_fn != nullptr) {
40294062 if (infer_fn->anal_state == FnAnalStateInvalid) {
40304063 return false;
......@@ -4044,12 +4077,12 @@ bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNod
40444077 return true;
40454078}
40464079
4047void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node) {
4048 TypeTableEntry *fn_type = fn_table_entry->type_entry;
4080void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) {
4081 ZigType *fn_type = fn_table_entry->type_entry;
40494082 assert(!fn_type->data.fn.is_generic);
40504083 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
40514084
4052 TypeTableEntry *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable,
4085 ZigType *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable,
40534086 &fn_table_entry->analyzed_executable, fn_type_id->return_type, return_type_node);
40544087 fn_table_entry->src_implicit_return_type = block_return_type;
40554088
......@@ -4059,13 +4092,13 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
40594092 return;
40604093 }
40614094
4062 if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) {
4063 TypeTableEntry *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
4095 if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {
4096 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
40644097 if (return_err_set_type->data.error_set.infer_fn != nullptr) {
4065 TypeTableEntry *inferred_err_set_type;
4066 if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) {
4098 ZigType *inferred_err_set_type;
4099 if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorSet) {
40674100 inferred_err_set_type = fn_table_entry->src_implicit_return_type;
4068 } else if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorUnion) {
4101 } else if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorUnion) {
40694102 inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;
40704103 } else {
40714104 add_node_error(g, return_type_node,
......@@ -4105,7 +4138,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
41054138 fn_table_entry->anal_state = FnAnalStateComplete;
41064139}
41074140
4108static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
4141static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
41094142 assert(fn_table_entry->anal_state != FnAnalStateProbing);
41104143 if (fn_table_entry->anal_state != FnAnalStateReady)
41114144 return;
......@@ -4121,7 +4154,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
41214154
41224155 define_local_param_variables(g, fn_table_entry);
41234156
4124 TypeTableEntry *fn_type = fn_table_entry->type_entry;
4157 ZigType *fn_type = fn_table_entry->type_entry;
41254158 assert(!fn_type->data.fn.is_generic);
41264159
41274160 ir_gen_fn(g, fn_table_entry);
......@@ -4146,7 +4179,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
41464179 }
41474180
41484181 IrInstruction *use_target_value = src_use_node->data.use.value;
4149 if (use_target_value->value.type->id == TypeTableEntryIdInvalid) {
4182 if (use_target_value->value.type->id == ZigTypeIdInvalid) {
41504183 dst_use_node->owner->any_imports_failed = true;
41514184 return;
41524185 }
......@@ -4222,15 +4255,15 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
42224255 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
42234256 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
42244257
4225 if (result->value.type->id == TypeTableEntryIdInvalid)
4258 if (result->value.type->id == ZigTypeIdInvalid)
42264259 node->owner->any_imports_failed = true;
42274260
42284261 node->data.use.value = result;
42294262}
42304263
4231ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) {
4264ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) {
42324265 if (g->verbose_tokenize) {
4233 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path));
4266 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path));
42344267 fprintf(stderr, "----------------\n");
42354268 fprintf(stderr, "%s\n", buf_ptr(source_code));
42364269
......@@ -4242,7 +4275,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
42424275 tokenize(source_code, &tokenization);
42434276
42444277 if (tokenization.err) {
4245 ErrorMsg *err = err_msg_create_with_line(abs_full_path, tokenization.err_line, tokenization.err_column,
4278 ErrorMsg *err = err_msg_create_with_line(resolved_path, tokenization.err_line, tokenization.err_column,
42464279 source_code, tokenization.line_offsets, tokenization.err);
42474280
42484281 print_err_msg(err, g->err_color);
......@@ -4260,7 +4293,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
42604293 import_entry->package = package;
42614294 import_entry->source_code = source_code;
42624295 import_entry->line_offsets = tokenization.line_offsets;
4263 import_entry->path = abs_full_path;
4296 import_entry->path = resolved_path;
42644297
42654298 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
42664299 assert(import_entry->root);
......@@ -4270,10 +4303,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
42704303
42714304 Buf *src_dirname = buf_alloc();
42724305 Buf *src_basename = buf_alloc();
4273 os_path_split(abs_full_path, src_dirname, src_basename);
4306 os_path_split(resolved_path, src_dirname, src_basename);
42744307
42754308 import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
4276 g->import_table.put(abs_full_path, import_entry);
4309 g->import_table.put(resolved_path, import_entry);
42774310 g->import_queue.append(import_entry);
42784311
42794312 import_entry->decls_scope = create_decls_scope(import_entry->root, nullptr, nullptr, import_entry);
......@@ -4341,15 +4374,15 @@ void semantic_analyze(CodeGen *g) {
43414374 }
43424375
43434376 for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {
4344 FnTableEntry *fn_entry = g->fn_defs.at(g->fn_defs_index);
4377 ZigFn *fn_entry = g->fn_defs.at(g->fn_defs_index);
43454378 analyze_fn_body(g, fn_entry);
43464379 }
43474380 }
43484381}
43494382
4350TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
4383ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
43514384 TypeId type_id = {};
4352 type_id.id = TypeTableEntryIdInt;
4385 type_id.id = ZigTypeIdInt;
43534386 type_id.data.integer.is_signed = is_signed;
43544387 type_id.data.integer.bit_count = size_in_bits;
43554388
......@@ -4359,53 +4392,53 @@ TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
43594392 return entry->value;
43604393 }
43614394
4362 TypeTableEntry *new_entry = make_int_type(g, is_signed, size_in_bits);
4395 ZigType *new_entry = make_int_type(g, is_signed, size_in_bits);
43634396 g->type_table.put(type_id, new_entry);
43644397 return new_entry;
43654398}
43664399
4367TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) {
4400ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) {
43684401 return &g->builtin_types.entry_c_int[c_int_type];
43694402}
43704403
4371TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type) {
4404ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
43724405 return *get_c_int_type_ptr(g, c_int_type);
43734406}
43744407
4375bool handle_is_ptr(TypeTableEntry *type_entry) {
4408bool handle_is_ptr(ZigType *type_entry) {
43764409 switch (type_entry->id) {
4377 case TypeTableEntryIdInvalid:
4378 case TypeTableEntryIdMetaType:
4379 case TypeTableEntryIdComptimeFloat:
4380 case TypeTableEntryIdComptimeInt:
4381 case TypeTableEntryIdUndefined:
4382 case TypeTableEntryIdNull:
4383 case TypeTableEntryIdNamespace:
4384 case TypeTableEntryIdBlock:
4385 case TypeTableEntryIdBoundFn:
4386 case TypeTableEntryIdArgTuple:
4387 case TypeTableEntryIdOpaque:
4410 case ZigTypeIdInvalid:
4411 case ZigTypeIdMetaType:
4412 case ZigTypeIdComptimeFloat:
4413 case ZigTypeIdComptimeInt:
4414 case ZigTypeIdUndefined:
4415 case ZigTypeIdNull:
4416 case ZigTypeIdNamespace:
4417 case ZigTypeIdBlock:
4418 case ZigTypeIdBoundFn:
4419 case ZigTypeIdArgTuple:
4420 case ZigTypeIdOpaque:
43884421 zig_unreachable();
4389 case TypeTableEntryIdUnreachable:
4390 case TypeTableEntryIdVoid:
4391 case TypeTableEntryIdBool:
4392 case TypeTableEntryIdInt:
4393 case TypeTableEntryIdFloat:
4394 case TypeTableEntryIdPointer:
4395 case TypeTableEntryIdErrorSet:
4396 case TypeTableEntryIdFn:
4397 case TypeTableEntryIdEnum:
4398 case TypeTableEntryIdPromise:
4422 case ZigTypeIdUnreachable:
4423 case ZigTypeIdVoid:
4424 case ZigTypeIdBool:
4425 case ZigTypeIdInt:
4426 case ZigTypeIdFloat:
4427 case ZigTypeIdPointer:
4428 case ZigTypeIdErrorSet:
4429 case ZigTypeIdFn:
4430 case ZigTypeIdEnum:
4431 case ZigTypeIdPromise:
43994432 return false;
4400 case TypeTableEntryIdArray:
4401 case TypeTableEntryIdStruct:
4433 case ZigTypeIdArray:
4434 case ZigTypeIdStruct:
44024435 return type_has_bits(type_entry);
4403 case TypeTableEntryIdErrorUnion:
4436 case ZigTypeIdErrorUnion:
44044437 return type_has_bits(type_entry->data.error_union.payload_type);
4405 case TypeTableEntryIdOptional:
4438 case ZigTypeIdOptional:
44064439 return type_has_bits(type_entry->data.maybe.child_type) &&
44074440 !type_is_codegen_pointer(type_entry->data.maybe.child_type);
4408 case TypeTableEntryIdUnion:
4441 case ZigTypeIdUnion:
44094442 assert(type_entry->data.unionation.complete);
44104443 if (type_entry->data.unionation.gen_field_count == 0)
44114444 return false;
......@@ -4594,11 +4627,11 @@ static uint32_t hash_size(size_t x) {
45944627 return (uint32_t)(x % UINT32_MAX);
45954628}
45964629
4597uint32_t fn_table_entry_hash(FnTableEntry* value) {
4630uint32_t fn_table_entry_hash(ZigFn* value) {
45984631 return ptr_hash(value);
45994632}
46004633
4601bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b) {
4634bool fn_table_entry_eql(ZigFn *a, ZigFn *b) {
46024635 return ptr_eq(a, b);
46034636}
46044637
......@@ -4689,16 +4722,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
46894722static uint32_t hash_const_val(ConstExprValue *const_val) {
46904723 assert(const_val->special == ConstValSpecialStatic);
46914724 switch (const_val->type->id) {
4692 case TypeTableEntryIdOpaque:
4725 case ZigTypeIdOpaque:
46934726 zig_unreachable();
4694 case TypeTableEntryIdBool:
4727 case ZigTypeIdBool:
46954728 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
4696 case TypeTableEntryIdMetaType:
4729 case ZigTypeIdMetaType:
46974730 return hash_ptr(const_val->data.x_type);
4698 case TypeTableEntryIdVoid:
4731 case ZigTypeIdVoid:
46994732 return (uint32_t)4149439618;
4700 case TypeTableEntryIdInt:
4701 case TypeTableEntryIdComptimeInt:
4733 case ZigTypeIdInt:
4734 case ZigTypeIdComptimeInt:
47024735 {
47034736 uint32_t result = 1331471175;
47044737 for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {
......@@ -4707,7 +4740,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
47074740 }
47084741 return result;
47094742 }
4710 case TypeTableEntryIdEnum:
4743 case ZigTypeIdEnum:
47114744 {
47124745 uint32_t result = 31643936;
47134746 for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) {
......@@ -4716,7 +4749,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
47164749 }
47174750 return result;
47184751 }
4719 case TypeTableEntryIdFloat:
4752 case ZigTypeIdFloat:
47204753 switch (const_val->type->data.floating.bit_count) {
47214754 case 16:
47224755 {
......@@ -4746,39 +4779,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
47464779 default:
47474780 zig_unreachable();
47484781 }
4749 case TypeTableEntryIdComptimeFloat:
4782 case ZigTypeIdComptimeFloat:
47504783 {
47514784 float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
47524785 uint32_t ints[4];
47534786 memcpy(&ints[0], &f128, 16);
47544787 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;
47554788 }
4756 case TypeTableEntryIdArgTuple:
4789 case ZigTypeIdArgTuple:
47574790 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
47584791 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
4759 case TypeTableEntryIdFn:
4792 case ZigTypeIdFn:
47604793 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
47614794 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
47624795 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4763 case TypeTableEntryIdPointer:
4796 case ZigTypeIdPointer:
47644797 return hash_const_val_ptr(const_val);
4765 case TypeTableEntryIdPromise:
4798 case ZigTypeIdPromise:
47664799 // TODO better hashing algorithm
47674800 return 223048345;
4768 case TypeTableEntryIdUndefined:
4801 case ZigTypeIdUndefined:
47694802 return 162837799;
4770 case TypeTableEntryIdNull:
4803 case ZigTypeIdNull:
47714804 return 844854567;
4772 case TypeTableEntryIdArray:
4805 case ZigTypeIdArray:
47734806 // TODO better hashing algorithm
47744807 return 1166190605;
4775 case TypeTableEntryIdStruct:
4808 case ZigTypeIdStruct:
47764809 // TODO better hashing algorithm
47774810 return 1532530855;
4778 case TypeTableEntryIdUnion:
4811 case ZigTypeIdUnion:
47794812 // TODO better hashing algorithm
47804813 return 2709806591;
4781 case TypeTableEntryIdOptional:
4814 case ZigTypeIdOptional:
47824815 if (get_codegen_ptr_type(const_val->type) != nullptr) {
47834816 return hash_const_val(const_val) * 1992916303;
47844817 } else {
......@@ -4788,19 +4821,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
47884821 return 4016830364;
47894822 }
47904823 }
4791 case TypeTableEntryIdErrorUnion:
4824 case ZigTypeIdErrorUnion:
47924825 // TODO better hashing algorithm
47934826 return 3415065496;
4794 case TypeTableEntryIdErrorSet:
4827 case ZigTypeIdErrorSet:
47954828 assert(const_val->data.x_err_set != nullptr);
47964829 return const_val->data.x_err_set->value ^ 2630160122;
4797 case TypeTableEntryIdNamespace:
4830 case ZigTypeIdNamespace:
47984831 return hash_ptr(const_val->data.x_import);
4799 case TypeTableEntryIdBlock:
4832 case ZigTypeIdBlock:
48004833 return hash_ptr(const_val->data.x_block);
4801 case TypeTableEntryIdBoundFn:
4802 case TypeTableEntryIdInvalid:
4803 case TypeTableEntryIdUnreachable:
4834 case ZigTypeIdBoundFn:
4835 case ZigTypeIdInvalid:
4836 case ZigTypeIdUnreachable:
48044837 zig_unreachable();
48054838 }
48064839 zig_unreachable();
......@@ -4843,32 +4876,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
48434876static bool can_mutate_comptime_var_state(ConstExprValue *value) {
48444877 assert(value != nullptr);
48454878 switch (value->type->id) {
4846 case TypeTableEntryIdInvalid:
4879 case ZigTypeIdInvalid:
48474880 zig_unreachable();
4848 case TypeTableEntryIdMetaType:
4849 case TypeTableEntryIdVoid:
4850 case TypeTableEntryIdBool:
4851 case TypeTableEntryIdUnreachable:
4852 case TypeTableEntryIdInt:
4853 case TypeTableEntryIdFloat:
4854 case TypeTableEntryIdComptimeFloat:
4855 case TypeTableEntryIdComptimeInt:
4856 case TypeTableEntryIdUndefined:
4857 case TypeTableEntryIdNull:
4858 case TypeTableEntryIdNamespace:
4859 case TypeTableEntryIdBoundFn:
4860 case TypeTableEntryIdFn:
4861 case TypeTableEntryIdBlock:
4862 case TypeTableEntryIdOpaque:
4863 case TypeTableEntryIdPromise:
4864 case TypeTableEntryIdErrorSet:
4865 case TypeTableEntryIdEnum:
4881 case ZigTypeIdMetaType:
4882 case ZigTypeIdVoid:
4883 case ZigTypeIdBool:
4884 case ZigTypeIdUnreachable:
4885 case ZigTypeIdInt:
4886 case ZigTypeIdFloat:
4887 case ZigTypeIdComptimeFloat:
4888 case ZigTypeIdComptimeInt:
4889 case ZigTypeIdUndefined:
4890 case ZigTypeIdNull:
4891 case ZigTypeIdNamespace:
4892 case ZigTypeIdBoundFn:
4893 case ZigTypeIdFn:
4894 case ZigTypeIdBlock:
4895 case ZigTypeIdOpaque:
4896 case ZigTypeIdPromise:
4897 case ZigTypeIdErrorSet:
4898 case ZigTypeIdEnum:
48664899 return false;
48674900
4868 case TypeTableEntryIdPointer:
4901 case ZigTypeIdPointer:
48694902 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
48704903
4871 case TypeTableEntryIdArray:
4904 case ZigTypeIdArray:
48724905 if (value->type->data.array.len == 0)
48734906 return false;
48744907 if (value->data.x_array.special == ConstArraySpecialUndef)
......@@ -4879,78 +4912,78 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
48794912 }
48804913 return false;
48814914
4882 case TypeTableEntryIdStruct:
4915 case ZigTypeIdStruct:
48834916 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
48844917 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))
48854918 return true;
48864919 }
48874920 return false;
48884921
4889 case TypeTableEntryIdOptional:
4922 case ZigTypeIdOptional:
48904923 if (get_codegen_ptr_type(value->type) != nullptr)
48914924 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
48924925 if (value->data.x_optional == nullptr)
48934926 return false;
48944927 return can_mutate_comptime_var_state(value->data.x_optional);
48954928
4896 case TypeTableEntryIdErrorUnion:
4929 case ZigTypeIdErrorUnion:
48974930 if (value->data.x_err_union.err != nullptr)
48984931 return false;
48994932 assert(value->data.x_err_union.payload != nullptr);
49004933 return can_mutate_comptime_var_state(value->data.x_err_union.payload);
49014934
4902 case TypeTableEntryIdUnion:
4935 case ZigTypeIdUnion:
49034936 return can_mutate_comptime_var_state(value->data.x_union.payload);
49044937
4905 case TypeTableEntryIdArgTuple:
4938 case ZigTypeIdArgTuple:
49064939 zig_panic("TODO var args at comptime is currently not supported");
49074940 }
49084941 zig_unreachable();
49094942}
49104943
4911static bool return_type_is_cacheable(TypeTableEntry *return_type) {
4944static bool return_type_is_cacheable(ZigType *return_type) {
49124945 switch (return_type->id) {
4913 case TypeTableEntryIdInvalid:
4946 case ZigTypeIdInvalid:
49144947 zig_unreachable();
4915 case TypeTableEntryIdMetaType:
4916 case TypeTableEntryIdVoid:
4917 case TypeTableEntryIdBool:
4918 case TypeTableEntryIdUnreachable:
4919 case TypeTableEntryIdInt:
4920 case TypeTableEntryIdFloat:
4921 case TypeTableEntryIdComptimeFloat:
4922 case TypeTableEntryIdComptimeInt:
4923 case TypeTableEntryIdUndefined:
4924 case TypeTableEntryIdNull:
4925 case TypeTableEntryIdNamespace:
4926 case TypeTableEntryIdBoundFn:
4927 case TypeTableEntryIdFn:
4928 case TypeTableEntryIdBlock:
4929 case TypeTableEntryIdOpaque:
4930 case TypeTableEntryIdPromise:
4931 case TypeTableEntryIdErrorSet:
4932 case TypeTableEntryIdEnum:
4933 case TypeTableEntryIdPointer:
4948 case ZigTypeIdMetaType:
4949 case ZigTypeIdVoid:
4950 case ZigTypeIdBool:
4951 case ZigTypeIdUnreachable:
4952 case ZigTypeIdInt:
4953 case ZigTypeIdFloat:
4954 case ZigTypeIdComptimeFloat:
4955 case ZigTypeIdComptimeInt:
4956 case ZigTypeIdUndefined:
4957 case ZigTypeIdNull:
4958 case ZigTypeIdNamespace:
4959 case ZigTypeIdBoundFn:
4960 case ZigTypeIdFn:
4961 case ZigTypeIdBlock:
4962 case ZigTypeIdOpaque:
4963 case ZigTypeIdPromise:
4964 case ZigTypeIdErrorSet:
4965 case ZigTypeIdEnum:
4966 case ZigTypeIdPointer:
49344967 return true;
49354968
4936 case TypeTableEntryIdArray:
4937 case TypeTableEntryIdStruct:
4938 case TypeTableEntryIdUnion:
4969 case ZigTypeIdArray:
4970 case ZigTypeIdStruct:
4971 case ZigTypeIdUnion:
49394972 return false;
49404973
4941 case TypeTableEntryIdOptional:
4974 case ZigTypeIdOptional:
49424975 return return_type_is_cacheable(return_type->data.maybe.child_type);
49434976
4944 case TypeTableEntryIdErrorUnion:
4977 case ZigTypeIdErrorUnion:
49454978 return return_type_is_cacheable(return_type->data.error_union.payload_type);
49464979
4947 case TypeTableEntryIdArgTuple:
4980 case ZigTypeIdArgTuple:
49484981 zig_panic("TODO var args at comptime is currently not supported");
49494982 }
49504983 zig_unreachable();
49514984}
49524985
4953bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) {
4986bool fn_eval_cacheable(Scope *scope, ZigType *return_type) {
49544987 if (!return_type_is_cacheable(return_type))
49554988 return false;
49564989 while (scope) {
......@@ -5019,56 +5052,56 @@ bool fn_eval_eql(Scope *a, Scope *b) {
50195052 return false;
50205053}
50215054
5022bool type_has_bits(TypeTableEntry *type_entry) {
5055bool type_has_bits(ZigType *type_entry) {
50235056 assert(type_entry);
5024 assert(type_entry->id != TypeTableEntryIdInvalid);
5057 assert(type_entry->id != ZigTypeIdInvalid);
50255058 assert(type_has_zero_bits_known(type_entry));
50265059 return !type_entry->zero_bits;
50275060}
50285061
5029bool type_requires_comptime(TypeTableEntry *type_entry) {
5062bool type_requires_comptime(ZigType *type_entry) {
50305063 switch (type_entry->id) {
5031 case TypeTableEntryIdInvalid:
5032 case TypeTableEntryIdOpaque:
5064 case ZigTypeIdInvalid:
5065 case ZigTypeIdOpaque:
50335066 zig_unreachable();
5034 case TypeTableEntryIdComptimeFloat:
5035 case TypeTableEntryIdComptimeInt:
5036 case TypeTableEntryIdUndefined:
5037 case TypeTableEntryIdNull:
5038 case TypeTableEntryIdMetaType:
5039 case TypeTableEntryIdNamespace:
5040 case TypeTableEntryIdBlock:
5041 case TypeTableEntryIdBoundFn:
5042 case TypeTableEntryIdArgTuple:
5067 case ZigTypeIdComptimeFloat:
5068 case ZigTypeIdComptimeInt:
5069 case ZigTypeIdUndefined:
5070 case ZigTypeIdNull:
5071 case ZigTypeIdMetaType:
5072 case ZigTypeIdNamespace:
5073 case ZigTypeIdBlock:
5074 case ZigTypeIdBoundFn:
5075 case ZigTypeIdArgTuple:
50435076 return true;
5044 case TypeTableEntryIdArray:
5077 case ZigTypeIdArray:
50455078 return type_requires_comptime(type_entry->data.array.child_type);
5046 case TypeTableEntryIdStruct:
5079 case ZigTypeIdStruct:
50475080 assert(type_has_zero_bits_known(type_entry));
50485081 return type_entry->data.structure.requires_comptime;
5049 case TypeTableEntryIdUnion:
5082 case ZigTypeIdUnion:
50505083 assert(type_has_zero_bits_known(type_entry));
50515084 return type_entry->data.unionation.requires_comptime;
5052 case TypeTableEntryIdOptional:
5085 case ZigTypeIdOptional:
50535086 return type_requires_comptime(type_entry->data.maybe.child_type);
5054 case TypeTableEntryIdErrorUnion:
5087 case ZigTypeIdErrorUnion:
50555088 return type_requires_comptime(type_entry->data.error_union.payload_type);
5056 case TypeTableEntryIdPointer:
5057 if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) {
5089 case ZigTypeIdPointer:
5090 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
50585091 return false;
50595092 } else {
50605093 return type_requires_comptime(type_entry->data.pointer.child_type);
50615094 }
5062 case TypeTableEntryIdFn:
5095 case ZigTypeIdFn:
50635096 return type_entry->data.fn.is_generic;
5064 case TypeTableEntryIdEnum:
5065 case TypeTableEntryIdErrorSet:
5066 case TypeTableEntryIdBool:
5067 case TypeTableEntryIdInt:
5068 case TypeTableEntryIdFloat:
5069 case TypeTableEntryIdVoid:
5070 case TypeTableEntryIdUnreachable:
5071 case TypeTableEntryIdPromise:
5097 case ZigTypeIdEnum:
5098 case ZigTypeIdErrorSet:
5099 case ZigTypeIdBool:
5100 case ZigTypeIdInt:
5101 case ZigTypeIdFloat:
5102 case ZigTypeIdVoid:
5103 case ZigTypeIdUnreachable:
5104 case ZigTypeIdPromise:
50725105 return false;
50735106 }
50745107 zig_unreachable();
......@@ -5135,27 +5168,27 @@ ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {
51355168 return const_val;
51365169}
51375170
5138void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint) {
5171void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) {
51395172 const_val->special = ConstValSpecialStatic;
51405173 const_val->type = type;
51415174 bigint_init_bigint(&const_val->data.x_bigint, bigint);
51425175}
51435176
5144ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint) {
5177ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
51455178 ConstExprValue *const_val = create_const_vals(1);
51465179 init_const_bigint(const_val, type, bigint);
51475180 return const_val;
51485181}
51495182
51505183
5151void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative) {
5184void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) {
51525185 const_val->special = ConstValSpecialStatic;
51535186 const_val->type = type;
51545187 bigint_init_unsigned(&const_val->data.x_bigint, x);
51555188 const_val->data.x_bigint.is_negative = negative;
51565189}
51575190
5158ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative) {
5191ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
51595192 ConstExprValue *const_val = create_const_vals(1);
51605193 init_const_unsigned_negative(const_val, type, x, negative);
51615194 return const_val;
......@@ -5169,24 +5202,24 @@ ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {
51695202 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
51705203}
51715204
5172void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x) {
5205void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) {
51735206 const_val->special = ConstValSpecialStatic;
51745207 const_val->type = type;
51755208 bigint_init_signed(&const_val->data.x_bigint, x);
51765209}
51775210
5178ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) {
5211ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
51795212 ConstExprValue *const_val = create_const_vals(1);
51805213 init_const_signed(const_val, type, x);
51815214 return const_val;
51825215}
51835216
5184void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) {
5217void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
51855218 const_val->special = ConstValSpecialStatic;
51865219 const_val->type = type;
5187 if (type->id == TypeTableEntryIdComptimeFloat) {
5220 if (type->id == ZigTypeIdComptimeFloat) {
51885221 bigfloat_init_64(&const_val->data.x_bigfloat, value);
5189 } else if (type->id == TypeTableEntryIdFloat) {
5222 } else if (type->id == ZigTypeIdFloat) {
51905223 switch (type->data.floating.bit_count) {
51915224 case 16:
51925225 const_val->data.x_f16 = zig_double_to_f16(value);
......@@ -5208,19 +5241,19 @@ void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double va
52085241 }
52095242}
52105243
5211ConstExprValue *create_const_float(TypeTableEntry *type, double value) {
5244ConstExprValue *create_const_float(ZigType *type, double value) {
52125245 ConstExprValue *const_val = create_const_vals(1);
52135246 init_const_float(const_val, type, value);
52145247 return const_val;
52155248}
52165249
5217void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag) {
5250void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) {
52185251 const_val->special = ConstValSpecialStatic;
52195252 const_val->type = type;
52205253 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
52215254}
52225255
5223ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag) {
5256ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {
52245257 ConstExprValue *const_val = create_const_vals(1);
52255258 init_const_enum(const_val, type, tag);
52265259 return const_val;
......@@ -5239,24 +5272,24 @@ ConstExprValue *create_const_bool(CodeGen *g, bool value) {
52395272 return const_val;
52405273}
52415274
5242void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type) {
5275void init_const_runtime(ConstExprValue *const_val, ZigType *type) {
52435276 const_val->special = ConstValSpecialRuntime;
52445277 const_val->type = type;
52455278}
52465279
5247ConstExprValue *create_const_runtime(TypeTableEntry *type) {
5280ConstExprValue *create_const_runtime(ZigType *type) {
52485281 ConstExprValue *const_val = create_const_vals(1);
52495282 init_const_runtime(const_val, type);
52505283 return const_val;
52515284}
52525285
5253void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value) {
5286void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) {
52545287 const_val->special = ConstValSpecialStatic;
52555288 const_val->type = g->builtin_types.entry_type;
52565289 const_val->data.x_type = type_value;
52575290}
52585291
5259ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
5292ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {
52605293 ConstExprValue *const_val = create_const_vals(1);
52615294 init_const_type(g, const_val, type_value);
52625295 return const_val;
......@@ -5265,9 +5298,9 @@ ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
52655298void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
52665299 size_t start, size_t len, bool is_const)
52675300{
5268 assert(array_val->type->id == TypeTableEntryIdArray);
5301 assert(array_val->type->id == ZigTypeIdArray);
52695302
5270 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
5303 ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
52715304 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),
52725305 0, 0);
52735306
......@@ -5289,8 +5322,8 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
52895322void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
52905323 size_t elem_index, bool is_const, PtrLen ptr_len)
52915324{
5292 assert(array_val->type->id == TypeTableEntryIdArray);
5293 TypeTableEntry *child_type = array_val->type->data.array.child_type;
5325 assert(array_val->type->id == ZigTypeIdArray);
5326 ZigType *child_type = array_val->type->data.array.child_type;
52945327
52955328 const_val->special = ConstValSpecialStatic;
52965329 const_val->type = get_pointer_to_type_extra(g, child_type, is_const, false,
......@@ -5321,7 +5354,7 @@ ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bo
53215354 return const_val;
53225355}
53235356
5324void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type,
5357void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,
53255358 size_t addr, bool is_const)
53265359{
53275360 const_val->special = ConstValSpecialStatic;
......@@ -5330,7 +5363,7 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeT
53305363 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
53315364}
53325365
5333ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type,
5366ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
53345367 size_t addr, bool is_const)
53355368{
53365369 ConstExprValue *const_val = create_const_vals(1);
......@@ -5354,11 +5387,11 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
53545387
53555388void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
53565389 Error err;
5357 TypeTableEntry *wanted_type = const_val->type;
5358 if (wanted_type->id == TypeTableEntryIdArray) {
5390 ZigType *wanted_type = const_val->type;
5391 if (wanted_type->id == ZigTypeIdArray) {
53595392 const_val->special = ConstValSpecialStatic;
53605393 const_val->data.x_array.special = ConstArraySpecialUndef;
5361 } else if (wanted_type->id == TypeTableEntryIdStruct) {
5394 } else if (wanted_type->id == ZigTypeIdStruct) {
53625395 if ((err = ensure_complete_type(g, wanted_type))) {
53635396 return;
53645397 }
......@@ -5392,36 +5425,36 @@ ConstExprValue *create_const_vals(size_t count) {
53925425 return vals;
53935426}
53945427
5395Error ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry) {
5428Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {
53965429 if (type_is_invalid(type_entry))
53975430 return ErrorSemanticAnalyzeFail;
5398 if (type_entry->id == TypeTableEntryIdStruct) {
5431 if (type_entry->id == ZigTypeIdStruct) {
53995432 if (!type_entry->data.structure.complete)
54005433 return resolve_struct_type(g, type_entry);
5401 } else if (type_entry->id == TypeTableEntryIdEnum) {
5434 } else if (type_entry->id == ZigTypeIdEnum) {
54025435 if (!type_entry->data.enumeration.complete)
54035436 return resolve_enum_type(g, type_entry);
5404 } else if (type_entry->id == TypeTableEntryIdUnion) {
5437 } else if (type_entry->id == ZigTypeIdUnion) {
54055438 if (!type_entry->data.unionation.complete)
54065439 return resolve_union_type(g, type_entry);
54075440 }
54085441 return ErrorNone;
54095442}
54105443
5411Error type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry) {
5444Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {
54125445 if (type_is_invalid(type_entry))
54135446 return ErrorSemanticAnalyzeFail;
5414 if (type_entry->id == TypeTableEntryIdStruct) {
5447 if (type_entry->id == ZigTypeIdStruct) {
54155448 return resolve_struct_zero_bits(g, type_entry);
5416 } else if (type_entry->id == TypeTableEntryIdEnum) {
5449 } else if (type_entry->id == ZigTypeIdEnum) {
54175450 return resolve_enum_zero_bits(g, type_entry);
5418 } else if (type_entry->id == TypeTableEntryIdUnion) {
5451 } else if (type_entry->id == ZigTypeIdUnion) {
54195452 return resolve_union_zero_bits(g, type_entry);
54205453 }
54215454 return ErrorNone;
54225455}
54235456
5424bool ir_get_var_is_comptime(VariableTableEntry *var) {
5457bool ir_get_var_is_comptime(ZigVar *var) {
54255458 if (!var->is_comptime)
54265459 return false;
54275460 if (var->is_comptime->other)
......@@ -5480,11 +5513,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
54805513 assert(a->special == ConstValSpecialStatic);
54815514 assert(b->special == ConstValSpecialStatic);
54825515 switch (a->type->id) {
5483 case TypeTableEntryIdOpaque:
5516 case ZigTypeIdOpaque:
54845517 zig_unreachable();
5485 case TypeTableEntryIdEnum:
5518 case ZigTypeIdEnum:
54865519 return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;
5487 case TypeTableEntryIdUnion: {
5520 case ZigTypeIdUnion: {
54885521 ConstUnionValue *union1 = &a->data.x_union;
54895522 ConstUnionValue *union2 = &b->data.x_union;
54905523
......@@ -5499,15 +5532,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
54995532 }
55005533 return false;
55015534 }
5502 case TypeTableEntryIdMetaType:
5535 case ZigTypeIdMetaType:
55035536 return a->data.x_type == b->data.x_type;
5504 case TypeTableEntryIdVoid:
5537 case ZigTypeIdVoid:
55055538 return true;
5506 case TypeTableEntryIdErrorSet:
5539 case ZigTypeIdErrorSet:
55075540 return a->data.x_err_set->value == b->data.x_err_set->value;
5508 case TypeTableEntryIdBool:
5541 case ZigTypeIdBool:
55095542 return a->data.x_bool == b->data.x_bool;
5510 case TypeTableEntryIdFloat:
5543 case ZigTypeIdFloat:
55115544 assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);
55125545 switch (a->type->data.floating.bit_count) {
55135546 case 16:
......@@ -5521,15 +5554,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55215554 default:
55225555 zig_unreachable();
55235556 }
5524 case TypeTableEntryIdComptimeFloat:
5557 case ZigTypeIdComptimeFloat:
55255558 return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;
5526 case TypeTableEntryIdInt:
5527 case TypeTableEntryIdComptimeInt:
5559 case ZigTypeIdInt:
5560 case ZigTypeIdComptimeInt:
55285561 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
5529 case TypeTableEntryIdPointer:
5530 case TypeTableEntryIdFn:
5562 case ZigTypeIdPointer:
5563 case ZigTypeIdFn:
55315564 return const_values_equal_ptr(a, b);
5532 case TypeTableEntryIdArray: {
5565 case ZigTypeIdArray: {
55335566 assert(a->type->data.array.len == b->type->data.array.len);
55345567 assert(a->data.x_array.special != ConstArraySpecialUndef);
55355568 assert(b->data.x_array.special != ConstArraySpecialUndef);
......@@ -5545,7 +5578,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55455578
55465579 return true;
55475580 }
5548 case TypeTableEntryIdStruct:
5581 case ZigTypeIdStruct:
55495582 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
55505583 ConstExprValue *field_a = &a->data.x_struct.fields[i];
55515584 ConstExprValue *field_b = &b->data.x_struct.fields[i];
......@@ -5553,11 +5586,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55535586 return false;
55545587 }
55555588 return true;
5556 case TypeTableEntryIdUndefined:
5589 case ZigTypeIdUndefined:
55575590 zig_panic("TODO");
5558 case TypeTableEntryIdNull:
5591 case ZigTypeIdNull:
55595592 zig_panic("TODO");
5560 case TypeTableEntryIdOptional:
5593 case ZigTypeIdOptional:
55615594 if (get_codegen_ptr_type(a->type) != nullptr)
55625595 return const_values_equal_ptr(a, b);
55635596 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
......@@ -5565,26 +5598,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55655598 } else {
55665599 return const_values_equal(a->data.x_optional, b->data.x_optional);
55675600 }
5568 case TypeTableEntryIdErrorUnion:
5601 case ZigTypeIdErrorUnion:
55695602 zig_panic("TODO");
5570 case TypeTableEntryIdNamespace:
5603 case ZigTypeIdNamespace:
55715604 return a->data.x_import == b->data.x_import;
5572 case TypeTableEntryIdBlock:
5605 case ZigTypeIdBlock:
55735606 return a->data.x_block == b->data.x_block;
5574 case TypeTableEntryIdArgTuple:
5607 case ZigTypeIdArgTuple:
55755608 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
55765609 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
5577 case TypeTableEntryIdBoundFn:
5578 case TypeTableEntryIdInvalid:
5579 case TypeTableEntryIdUnreachable:
5580 case TypeTableEntryIdPromise:
5610 case ZigTypeIdBoundFn:
5611 case ZigTypeIdInvalid:
5612 case ZigTypeIdUnreachable:
5613 case ZigTypeIdPromise:
55815614 zig_unreachable();
55825615 }
55835616 zig_unreachable();
55845617}
55855618
5586void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max) {
5587 assert(int_type->id == TypeTableEntryIdInt);
5619void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) {
5620 assert(int_type->id == ZigTypeIdInt);
55885621 if (int_type->data.integral.bit_count == 0) {
55895622 bigint_init_unsigned(bigint, 0);
55905623 return;
......@@ -5620,21 +5653,21 @@ void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint
56205653 }
56215654}
56225655
5623void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) {
5624 if (type_entry->id == TypeTableEntryIdInt) {
5656void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {
5657 if (type_entry->id == ZigTypeIdInt) {
56255658 const_val->special = ConstValSpecialStatic;
56265659 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);
5627 } else if (type_entry->id == TypeTableEntryIdBool) {
5660 } else if (type_entry->id == ZigTypeIdBool) {
56285661 const_val->special = ConstValSpecialStatic;
56295662 const_val->data.x_bool = is_max;
5630 } else if (type_entry->id == TypeTableEntryIdVoid) {
5663 } else if (type_entry->id == ZigTypeIdVoid) {
56315664 // nothing to do
56325665 } else {
56335666 zig_unreachable();
56345667 }
56355668}
56365669
5637void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeTableEntry *type_entry) {
5670void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {
56385671 switch (const_val->data.x_ptr.special) {
56395672 case ConstPtrSpecialInvalid:
56405673 zig_unreachable();
......@@ -5661,7 +5694,7 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeT
56615694 return;
56625695 case ConstPtrSpecialFunction:
56635696 {
5664 FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
5697 ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
56655698 buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name));
56665699 return;
56675700 }
......@@ -5682,20 +5715,20 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
56825715 }
56835716 assert(const_val->type);
56845717
5685 TypeTableEntry *type_entry = const_val->type;
5718 ZigType *type_entry = const_val->type;
56865719 switch (type_entry->id) {
5687 case TypeTableEntryIdOpaque:
5720 case ZigTypeIdOpaque:
56885721 zig_unreachable();
5689 case TypeTableEntryIdInvalid:
5722 case ZigTypeIdInvalid:
56905723 buf_appendf(buf, "(invalid)");
56915724 return;
5692 case TypeTableEntryIdVoid:
5725 case ZigTypeIdVoid:
56935726 buf_appendf(buf, "{}");
56945727 return;
5695 case TypeTableEntryIdComptimeFloat:
5728 case ZigTypeIdComptimeFloat:
56965729 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
56975730 return;
5698 case TypeTableEntryIdFloat:
5731 case ZigTypeIdFloat:
56995732 switch (type_entry->data.floating.bit_count) {
57005733 case 16:
57015734 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
......@@ -5723,41 +5756,41 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
57235756 default:
57245757 zig_unreachable();
57255758 }
5726 case TypeTableEntryIdComptimeInt:
5727 case TypeTableEntryIdInt:
5759 case ZigTypeIdComptimeInt:
5760 case ZigTypeIdInt:
57285761 bigint_append_buf(buf, &const_val->data.x_bigint, 10);
57295762 return;
5730 case TypeTableEntryIdMetaType:
5763 case ZigTypeIdMetaType:
57315764 buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));
57325765 return;
5733 case TypeTableEntryIdUnreachable:
5766 case ZigTypeIdUnreachable:
57345767 buf_appendf(buf, "unreachable");
57355768 return;
5736 case TypeTableEntryIdBool:
5769 case ZigTypeIdBool:
57375770 {
57385771 const char *value = const_val->data.x_bool ? "true" : "false";
57395772 buf_appendf(buf, "%s", value);
57405773 return;
57415774 }
5742 case TypeTableEntryIdFn:
5775 case ZigTypeIdFn:
57435776 {
57445777 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
57455778 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
5746 FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
5779 ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
57475780 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
57485781 return;
57495782 }
5750 case TypeTableEntryIdPointer:
5783 case ZigTypeIdPointer:
57515784 return render_const_val_ptr(g, buf, const_val, type_entry);
5752 case TypeTableEntryIdBlock:
5785 case ZigTypeIdBlock:
57535786 {
57545787 AstNode *node = const_val->data.x_block->source_node;
57555788 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
57565789 return;
57575790 }
5758 case TypeTableEntryIdArray:
5791 case ZigTypeIdArray:
57595792 {
5760 TypeTableEntry *child_type = type_entry->data.array.child_type;
5793 ZigType *child_type = type_entry->data.array.child_type;
57615794 uint64_t len = type_entry->data.array.len;
57625795
57635796 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
......@@ -5766,7 +5799,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
57665799 }
57675800
57685801 // if it's []u8, assume UTF-8 and output a string
5769 if (child_type->id == TypeTableEntryIdInt &&
5802 if (child_type->id == ZigTypeIdInt &&
57705803 child_type->data.integral.bit_count == 8 &&
57715804 !child_type->data.integral.is_signed)
57725805 {
......@@ -5796,17 +5829,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
57965829 buf_appendf(buf, "}");
57975830 return;
57985831 }
5799 case TypeTableEntryIdNull:
5832 case ZigTypeIdNull:
58005833 {
58015834 buf_appendf(buf, "null");
58025835 return;
58035836 }
5804 case TypeTableEntryIdUndefined:
5837 case ZigTypeIdUndefined:
58055838 {
58065839 buf_appendf(buf, "undefined");
58075840 return;
58085841 }
5809 case TypeTableEntryIdOptional:
5842 case ZigTypeIdOptional:
58105843 {
58115844 if (get_codegen_ptr_type(const_val->type) != nullptr)
58125845 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
......@@ -5817,7 +5850,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
58175850 }
58185851 return;
58195852 }
5820 case TypeTableEntryIdNamespace:
5853 case ZigTypeIdNamespace:
58215854 {
58225855 ImportTableEntry *import = const_val->data.x_import;
58235856 if (import->c_import_node) {
......@@ -5827,51 +5860,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
58275860 }
58285861 return;
58295862 }
5830 case TypeTableEntryIdBoundFn:
5863 case ZigTypeIdBoundFn:
58315864 {
5832 FnTableEntry *fn_entry = const_val->data.x_bound_fn.fn;
5865 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
58335866 buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));
58345867 return;
58355868 }
5836 case TypeTableEntryIdStruct:
5869 case ZigTypeIdStruct:
58375870 {
58385871 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));
58395872 return;
58405873 }
5841 case TypeTableEntryIdEnum:
5874 case ZigTypeIdEnum:
58425875 {
58435876 TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);
58445877 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));
58455878 return;
58465879 }
5847 case TypeTableEntryIdErrorUnion:
5880 case ZigTypeIdErrorUnion:
58485881 {
58495882 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));
58505883 return;
58515884 }
5852 case TypeTableEntryIdUnion:
5885 case ZigTypeIdUnion:
58535886 {
58545887 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));
58555888 return;
58565889 }
5857 case TypeTableEntryIdErrorSet:
5890 case ZigTypeIdErrorSet:
58585891 {
58595892 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));
58605893 return;
58615894 }
5862 case TypeTableEntryIdArgTuple:
5895 case ZigTypeIdArgTuple:
58635896 {
58645897 buf_appendf(buf, "(args value)");
58655898 return;
58665899 }
5867 case TypeTableEntryIdPromise:
5900 case ZigTypeIdPromise:
58685901 zig_unreachable();
58695902 }
58705903 zig_unreachable();
58715904}
58725905
5873TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
5874 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
5906ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
5907 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
58755908 entry->is_copyable = true;
58765909 entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);
58775910 entry->zero_bits = (size_in_bits == 0);
......@@ -5905,32 +5938,32 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
59055938
59065939uint32_t type_id_hash(TypeId x) {
59075940 switch (x.id) {
5908 case TypeTableEntryIdInvalid:
5909 case TypeTableEntryIdOpaque:
5910 case TypeTableEntryIdMetaType:
5911 case TypeTableEntryIdVoid:
5912 case TypeTableEntryIdBool:
5913 case TypeTableEntryIdUnreachable:
5914 case TypeTableEntryIdFloat:
5915 case TypeTableEntryIdStruct:
5916 case TypeTableEntryIdComptimeFloat:
5917 case TypeTableEntryIdComptimeInt:
5918 case TypeTableEntryIdUndefined:
5919 case TypeTableEntryIdNull:
5920 case TypeTableEntryIdOptional:
5921 case TypeTableEntryIdErrorSet:
5922 case TypeTableEntryIdEnum:
5923 case TypeTableEntryIdUnion:
5924 case TypeTableEntryIdFn:
5925 case TypeTableEntryIdNamespace:
5926 case TypeTableEntryIdBlock:
5927 case TypeTableEntryIdBoundFn:
5928 case TypeTableEntryIdArgTuple:
5929 case TypeTableEntryIdPromise:
5941 case ZigTypeIdInvalid:
5942 case ZigTypeIdOpaque:
5943 case ZigTypeIdMetaType:
5944 case ZigTypeIdVoid:
5945 case ZigTypeIdBool:
5946 case ZigTypeIdUnreachable:
5947 case ZigTypeIdFloat:
5948 case ZigTypeIdStruct:
5949 case ZigTypeIdComptimeFloat:
5950 case ZigTypeIdComptimeInt:
5951 case ZigTypeIdUndefined:
5952 case ZigTypeIdNull:
5953 case ZigTypeIdOptional:
5954 case ZigTypeIdErrorSet:
5955 case ZigTypeIdEnum:
5956 case ZigTypeIdUnion:
5957 case ZigTypeIdFn:
5958 case ZigTypeIdNamespace:
5959 case ZigTypeIdBlock:
5960 case ZigTypeIdBoundFn:
5961 case ZigTypeIdArgTuple:
5962 case ZigTypeIdPromise:
59305963 zig_unreachable();
5931 case TypeTableEntryIdErrorUnion:
5964 case ZigTypeIdErrorUnion:
59325965 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
5933 case TypeTableEntryIdPointer:
5966 case ZigTypeIdPointer:
59345967 return hash_ptr(x.data.pointer.child_type) +
59355968 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
59365969 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
......@@ -5938,10 +5971,10 @@ uint32_t type_id_hash(TypeId x) {
59385971 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
59395972 (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +
59405973 (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);
5941 case TypeTableEntryIdArray:
5974 case ZigTypeIdArray:
59425975 return hash_ptr(x.data.array.child_type) +
59435976 ((uint32_t)x.data.array.size ^ (uint32_t)2122979968);
5944 case TypeTableEntryIdInt:
5977 case ZigTypeIdInt:
59455978 return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +
59465979 (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);
59475980 }
......@@ -5952,34 +5985,34 @@ bool type_id_eql(TypeId a, TypeId b) {
59525985 if (a.id != b.id)
59535986 return false;
59545987 switch (a.id) {
5955 case TypeTableEntryIdInvalid:
5956 case TypeTableEntryIdMetaType:
5957 case TypeTableEntryIdVoid:
5958 case TypeTableEntryIdBool:
5959 case TypeTableEntryIdUnreachable:
5960 case TypeTableEntryIdFloat:
5961 case TypeTableEntryIdStruct:
5962 case TypeTableEntryIdComptimeFloat:
5963 case TypeTableEntryIdComptimeInt:
5964 case TypeTableEntryIdUndefined:
5965 case TypeTableEntryIdNull:
5966 case TypeTableEntryIdOptional:
5967 case TypeTableEntryIdPromise:
5968 case TypeTableEntryIdErrorSet:
5969 case TypeTableEntryIdEnum:
5970 case TypeTableEntryIdUnion:
5971 case TypeTableEntryIdFn:
5972 case TypeTableEntryIdNamespace:
5973 case TypeTableEntryIdBlock:
5974 case TypeTableEntryIdBoundFn:
5975 case TypeTableEntryIdArgTuple:
5976 case TypeTableEntryIdOpaque:
5988 case ZigTypeIdInvalid:
5989 case ZigTypeIdMetaType:
5990 case ZigTypeIdVoid:
5991 case ZigTypeIdBool:
5992 case ZigTypeIdUnreachable:
5993 case ZigTypeIdFloat:
5994 case ZigTypeIdStruct:
5995 case ZigTypeIdComptimeFloat:
5996 case ZigTypeIdComptimeInt:
5997 case ZigTypeIdUndefined:
5998 case ZigTypeIdNull:
5999 case ZigTypeIdOptional:
6000 case ZigTypeIdPromise:
6001 case ZigTypeIdErrorSet:
6002 case ZigTypeIdEnum:
6003 case ZigTypeIdUnion:
6004 case ZigTypeIdFn:
6005 case ZigTypeIdNamespace:
6006 case ZigTypeIdBlock:
6007 case ZigTypeIdBoundFn:
6008 case ZigTypeIdArgTuple:
6009 case ZigTypeIdOpaque:
59776010 zig_unreachable();
5978 case TypeTableEntryIdErrorUnion:
6011 case ZigTypeIdErrorUnion:
59796012 return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&
59806013 a.data.error_union.payload_type == b.data.error_union.payload_type;
59816014
5982 case TypeTableEntryIdPointer:
6015 case ZigTypeIdPointer:
59836016 return a.data.pointer.child_type == b.data.pointer.child_type &&
59846017 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
59856018 a.data.pointer.is_const == b.data.pointer.is_const &&
......@@ -5987,10 +6020,10 @@ bool type_id_eql(TypeId a, TypeId b) {
59876020 a.data.pointer.alignment == b.data.pointer.alignment &&
59886021 a.data.pointer.bit_offset == b.data.pointer.bit_offset &&
59896022 a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;
5990 case TypeTableEntryIdArray:
6023 case ZigTypeIdArray:
59916024 return a.data.array.child_type == b.data.array.child_type &&
59926025 a.data.array.size == b.data.array.size;
5993 case TypeTableEntryIdInt:
6026 case ZigTypeIdInt:
59946027 return a.data.integer.is_signed == b.data.integer.is_signed &&
59956028 a.data.integer.bit_count == b.data.integer.bit_count;
59966029 }
......@@ -6042,7 +6075,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
60426075}
60436076
60446077void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
6045 assert(const_val->type->id == TypeTableEntryIdArray);
6078 assert(const_val->type->id == ZigTypeIdArray);
60466079 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
60476080 const_val->data.x_array.special = ConstArraySpecialNone;
60486081 size_t elem_count = const_val->type->data.array.len;
......@@ -6063,47 +6096,47 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
60636096
60646097ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {
60656098 assert(value->type);
6066 TypeTableEntry *type_entry = value->type;
6067 if (type_entry->id == TypeTableEntryIdArray) {
6099 ZigType *type_entry = value->type;
6100 if (type_entry->id == ZigTypeIdArray) {
60686101 expand_undef_array(g, value);
60696102 return &value->data.x_array.s_none.parent;
6070 } else if (type_entry->id == TypeTableEntryIdStruct) {
6103 } else if (type_entry->id == ZigTypeIdStruct) {
60716104 return &value->data.x_struct.parent;
6072 } else if (type_entry->id == TypeTableEntryIdUnion) {
6105 } else if (type_entry->id == ZigTypeIdUnion) {
60736106 return &value->data.x_union.parent;
60746107 }
60756108 return nullptr;
60766109}
60776110
6078static const TypeTableEntryId all_type_ids[] = {
6079 TypeTableEntryIdMetaType,
6080 TypeTableEntryIdVoid,
6081 TypeTableEntryIdBool,
6082 TypeTableEntryIdUnreachable,
6083 TypeTableEntryIdInt,
6084 TypeTableEntryIdFloat,
6085 TypeTableEntryIdPointer,
6086 TypeTableEntryIdArray,
6087 TypeTableEntryIdStruct,
6088 TypeTableEntryIdComptimeFloat,
6089 TypeTableEntryIdComptimeInt,
6090 TypeTableEntryIdUndefined,
6091 TypeTableEntryIdNull,
6092 TypeTableEntryIdOptional,
6093 TypeTableEntryIdErrorUnion,
6094 TypeTableEntryIdErrorSet,
6095 TypeTableEntryIdEnum,
6096 TypeTableEntryIdUnion,
6097 TypeTableEntryIdFn,
6098 TypeTableEntryIdNamespace,
6099 TypeTableEntryIdBlock,
6100 TypeTableEntryIdBoundFn,
6101 TypeTableEntryIdArgTuple,
6102 TypeTableEntryIdOpaque,
6103 TypeTableEntryIdPromise,
6111static const ZigTypeId all_type_ids[] = {
6112 ZigTypeIdMetaType,
6113 ZigTypeIdVoid,
6114 ZigTypeIdBool,
6115 ZigTypeIdUnreachable,
6116 ZigTypeIdInt,
6117 ZigTypeIdFloat,
6118 ZigTypeIdPointer,
6119 ZigTypeIdArray,
6120 ZigTypeIdStruct,
6121 ZigTypeIdComptimeFloat,
6122 ZigTypeIdComptimeInt,
6123 ZigTypeIdUndefined,
6124 ZigTypeIdNull,
6125 ZigTypeIdOptional,
6126 ZigTypeIdErrorUnion,
6127 ZigTypeIdErrorSet,
6128 ZigTypeIdEnum,
6129 ZigTypeIdUnion,
6130 ZigTypeIdFn,
6131 ZigTypeIdNamespace,
6132 ZigTypeIdBlock,
6133 ZigTypeIdBoundFn,
6134 ZigTypeIdArgTuple,
6135 ZigTypeIdOpaque,
6136 ZigTypeIdPromise,
61046137};
61056138
6106TypeTableEntryId type_id_at_index(size_t index) {
6139ZigTypeId type_id_at_index(size_t index) {
61076140 assert(index < array_length(all_type_ids));
61086141 return all_type_ids[index];
61096142}
......@@ -6112,119 +6145,119 @@ size_t type_id_len() {
61126145 return array_length(all_type_ids);
61136146}
61146147
6115size_t type_id_index(TypeTableEntry *entry) {
6148size_t type_id_index(ZigType *entry) {
61166149 switch (entry->id) {
6117 case TypeTableEntryIdInvalid:
6150 case ZigTypeIdInvalid:
61186151 zig_unreachable();
6119 case TypeTableEntryIdMetaType:
6152 case ZigTypeIdMetaType:
61206153 return 0;
6121 case TypeTableEntryIdVoid:
6154 case ZigTypeIdVoid:
61226155 return 1;
6123 case TypeTableEntryIdBool:
6156 case ZigTypeIdBool:
61246157 return 2;
6125 case TypeTableEntryIdUnreachable:
6158 case ZigTypeIdUnreachable:
61266159 return 3;
6127 case TypeTableEntryIdInt:
6160 case ZigTypeIdInt:
61286161 return 4;
6129 case TypeTableEntryIdFloat:
6162 case ZigTypeIdFloat:
61306163 return 5;
6131 case TypeTableEntryIdPointer:
6164 case ZigTypeIdPointer:
61326165 return 6;
6133 case TypeTableEntryIdArray:
6166 case ZigTypeIdArray:
61346167 return 7;
6135 case TypeTableEntryIdStruct:
6168 case ZigTypeIdStruct:
61366169 if (entry->data.structure.is_slice)
61376170 return 6;
61386171 return 8;
6139 case TypeTableEntryIdComptimeFloat:
6172 case ZigTypeIdComptimeFloat:
61406173 return 9;
6141 case TypeTableEntryIdComptimeInt:
6174 case ZigTypeIdComptimeInt:
61426175 return 10;
6143 case TypeTableEntryIdUndefined:
6176 case ZigTypeIdUndefined:
61446177 return 11;
6145 case TypeTableEntryIdNull:
6178 case ZigTypeIdNull:
61466179 return 12;
6147 case TypeTableEntryIdOptional:
6180 case ZigTypeIdOptional:
61486181 return 13;
6149 case TypeTableEntryIdErrorUnion:
6182 case ZigTypeIdErrorUnion:
61506183 return 14;
6151 case TypeTableEntryIdErrorSet:
6184 case ZigTypeIdErrorSet:
61526185 return 15;
6153 case TypeTableEntryIdEnum:
6186 case ZigTypeIdEnum:
61546187 return 16;
6155 case TypeTableEntryIdUnion:
6188 case ZigTypeIdUnion:
61566189 return 17;
6157 case TypeTableEntryIdFn:
6190 case ZigTypeIdFn:
61586191 return 18;
6159 case TypeTableEntryIdNamespace:
6192 case ZigTypeIdNamespace:
61606193 return 19;
6161 case TypeTableEntryIdBlock:
6194 case ZigTypeIdBlock:
61626195 return 20;
6163 case TypeTableEntryIdBoundFn:
6196 case ZigTypeIdBoundFn:
61646197 return 21;
6165 case TypeTableEntryIdArgTuple:
6198 case ZigTypeIdArgTuple:
61666199 return 22;
6167 case TypeTableEntryIdOpaque:
6200 case ZigTypeIdOpaque:
61686201 return 23;
6169 case TypeTableEntryIdPromise:
6202 case ZigTypeIdPromise:
61706203 return 24;
61716204 }
61726205 zig_unreachable();
61736206}
61746207
6175const char *type_id_name(TypeTableEntryId id) {
6208const char *type_id_name(ZigTypeId id) {
61766209 switch (id) {
6177 case TypeTableEntryIdInvalid:
6210 case ZigTypeIdInvalid:
61786211 zig_unreachable();
6179 case TypeTableEntryIdMetaType:
6212 case ZigTypeIdMetaType:
61806213 return "Type";
6181 case TypeTableEntryIdVoid:
6214 case ZigTypeIdVoid:
61826215 return "Void";
6183 case TypeTableEntryIdBool:
6216 case ZigTypeIdBool:
61846217 return "Bool";
6185 case TypeTableEntryIdUnreachable:
6218 case ZigTypeIdUnreachable:
61866219 return "NoReturn";
6187 case TypeTableEntryIdInt:
6220 case ZigTypeIdInt:
61886221 return "Int";
6189 case TypeTableEntryIdFloat:
6222 case ZigTypeIdFloat:
61906223 return "Float";
6191 case TypeTableEntryIdPointer:
6224 case ZigTypeIdPointer:
61926225 return "Pointer";
6193 case TypeTableEntryIdArray:
6226 case ZigTypeIdArray:
61946227 return "Array";
6195 case TypeTableEntryIdStruct:
6228 case ZigTypeIdStruct:
61966229 return "Struct";
6197 case TypeTableEntryIdComptimeFloat:
6230 case ZigTypeIdComptimeFloat:
61986231 return "ComptimeFloat";
6199 case TypeTableEntryIdComptimeInt:
6232 case ZigTypeIdComptimeInt:
62006233 return "ComptimeInt";
6201 case TypeTableEntryIdUndefined:
6234 case ZigTypeIdUndefined:
62026235 return "Undefined";
6203 case TypeTableEntryIdNull:
6236 case ZigTypeIdNull:
62046237 return "Null";
6205 case TypeTableEntryIdOptional:
6238 case ZigTypeIdOptional:
62066239 return "Optional";
6207 case TypeTableEntryIdErrorUnion:
6240 case ZigTypeIdErrorUnion:
62086241 return "ErrorUnion";
6209 case TypeTableEntryIdErrorSet:
6242 case ZigTypeIdErrorSet:
62106243 return "ErrorSet";
6211 case TypeTableEntryIdEnum:
6244 case ZigTypeIdEnum:
62126245 return "Enum";
6213 case TypeTableEntryIdUnion:
6246 case ZigTypeIdUnion:
62146247 return "Union";
6215 case TypeTableEntryIdFn:
6248 case ZigTypeIdFn:
62166249 return "Fn";
6217 case TypeTableEntryIdNamespace:
6250 case ZigTypeIdNamespace:
62186251 return "Namespace";
6219 case TypeTableEntryIdBlock:
6252 case ZigTypeIdBlock:
62206253 return "Block";
6221 case TypeTableEntryIdBoundFn:
6254 case ZigTypeIdBoundFn:
62226255 return "BoundFn";
6223 case TypeTableEntryIdArgTuple:
6256 case ZigTypeIdArgTuple:
62246257 return "ArgTuple";
6225 case TypeTableEntryIdOpaque:
6258 case ZigTypeIdOpaque:
62266259 return "Opaque";
6227 case TypeTableEntryIdPromise:
6260 case ZigTypeIdPromise:
62286261 return "Promise";
62296262 }
62306263 zig_unreachable();
......@@ -6258,31 +6291,31 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
62586291 return link_lib;
62596292}
62606293
6261uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) {
6294uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {
62626295 assertNoError(type_ensure_zero_bits_known(g, type_entry));
62636296 if (type_entry->zero_bits) return 0;
62646297
62656298 // We need to make this function work without requiring ensure_complete_type
62666299 // so that we can have structs with fields that are pointers to their own type.
6267 if (type_entry->id == TypeTableEntryIdStruct) {
6300 if (type_entry->id == ZigTypeIdStruct) {
62686301 assert(type_entry->data.structure.abi_alignment != 0);
62696302 return type_entry->data.structure.abi_alignment;
6270 } else if (type_entry->id == TypeTableEntryIdUnion) {
6303 } else if (type_entry->id == ZigTypeIdUnion) {
62716304 assert(type_entry->data.unionation.abi_alignment != 0);
62726305 return type_entry->data.unionation.abi_alignment;
6273 } else if (type_entry->id == TypeTableEntryIdOpaque) {
6306 } else if (type_entry->id == ZigTypeIdOpaque) {
62746307 return 1;
62756308 } else {
62766309 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
62776310 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
6278 if (type_entry->id == TypeTableEntryIdPromise && llvm_alignment < 8) {
6311 if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) {
62796312 return 8;
62806313 }
62816314 return llvm_alignment;
62826315 }
62836316}
62846317
6285TypeTableEntry *get_align_amt_type(CodeGen *g) {
6318ZigType *get_align_amt_type(CodeGen *g) {
62866319 if (g->align_amt_type == nullptr) {
62876320 // according to LLVM the maximum alignment is 1 << 29.
62886321 g->align_amt_type = get_int_type(g, false, 29);
......@@ -6290,11 +6323,11 @@ TypeTableEntry *get_align_amt_type(CodeGen *g) {
62906323 return g->align_amt_type;
62916324}
62926325
6293uint32_t type_ptr_hash(const TypeTableEntry *ptr) {
6326uint32_t type_ptr_hash(const ZigType *ptr) {
62946327 return hash_ptr((void*)ptr);
62956328}
62966329
6297bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b) {
6330bool type_ptr_eql(const ZigType *a, const ZigType *b) {
62986331 return a == b;
62996332}
63006333
......@@ -6308,8 +6341,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
63086341 return var_value;
63096342}
63106343
6311bool type_is_global_error_set(TypeTableEntry *err_set_type) {
6312 assert(err_set_type->id == TypeTableEntryIdErrorSet);
6344bool type_is_global_error_set(ZigType *err_set_type) {
6345 assert(err_set_type->id == ZigTypeIdErrorSet);
63136346 assert(err_set_type->data.error_set.infer_fn == nullptr);
63146347 return err_set_type->data.error_set.err_count == UINT32_MAX;
63156348}
......@@ -6318,15 +6351,15 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {
63186351 return g->pointer_size_bytes * 2;
63196352}
63206353
6321bool type_can_fail(TypeTableEntry *type_entry) {
6322 return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet;
6354bool type_can_fail(ZigType *type_entry) {
6355 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
63236356}
63246357
63256358bool fn_type_can_fail(FnTypeId *fn_type_id) {
63266359 return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;
63276360}
63286361
6329TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name) {
6362ZigType *get_primitive_type(CodeGen *g, Buf *name) {
63306363 if (buf_len(name) >= 2) {
63316364 uint8_t first_c = buf_ptr(name)[0];
63326365 if (first_c == 'i' || first_c == 'u') {
......@@ -6350,3 +6383,85 @@ not_integer:
63506383 }
63516384 return nullptr;
63526385}
6386
6387X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
6388 size_t ty_size = type_size(g, ty);
6389 if (get_codegen_ptr_type(ty) != nullptr)
6390 return X64CABIClass_INTEGER;
6391 switch (ty->id) {
6392 case ZigTypeIdEnum:
6393 case ZigTypeIdInt:
6394 case ZigTypeIdBool:
6395 return X64CABIClass_INTEGER;
6396 case ZigTypeIdFloat:
6397 return X64CABIClass_SSE;
6398 case ZigTypeIdStruct: {
6399 // "If the size of an object is larger than four eightbytes, or it contains unaligned
6400 // fields, it has class MEMORY"
6401 if (ty_size > 32)
6402 return X64CABIClass_MEMORY;
6403 if (ty->data.structure.layout != ContainerLayoutExtern) {
6404 // TODO determine whether packed structs have any unaligned fields
6405 return X64CABIClass_Unknown;
6406 }
6407 // "If the size of the aggregate exceeds two eightbytes and the first eight-
6408 // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument
6409 // is passed in memory."
6410 if (ty_size > 16) {
6411 // Zig doesn't support vectors and large fp registers yet, so this will always
6412 // be memory.
6413 return X64CABIClass_MEMORY;
6414 }
6415 X64CABIClass working_class = X64CABIClass_Unknown;
6416 for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
6417 X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry);
6418 if (field_class == X64CABIClass_Unknown)
6419 return X64CABIClass_Unknown;
6420 if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) {
6421 working_class = field_class;
6422 }
6423 }
6424 return working_class;
6425 }
6426 case ZigTypeIdUnion: {
6427 // "If the size of an object is larger than four eightbytes, or it contains unaligned
6428 // fields, it has class MEMORY"
6429 if (ty_size > 32)
6430 return X64CABIClass_MEMORY;
6431 if (ty->data.unionation.layout != ContainerLayoutExtern)
6432 return X64CABIClass_MEMORY;
6433 // "If the size of the aggregate exceeds two eightbytes and the first eight-
6434 // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument
6435 // is passed in memory."
6436 if (ty_size > 16) {
6437 // Zig doesn't support vectors and large fp registers yet, so this will always
6438 // be memory.
6439 return X64CABIClass_MEMORY;
6440 }
6441 X64CABIClass working_class = X64CABIClass_Unknown;
6442 for (uint32_t i = 0; i < ty->data.unionation.src_field_count; i += 1) {
6443 X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.unionation.fields->type_entry);
6444 if (field_class == X64CABIClass_Unknown)
6445 return X64CABIClass_Unknown;
6446 if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) {
6447 working_class = field_class;
6448 }
6449 }
6450 return working_class;
6451 }
6452 default:
6453 return X64CABIClass_Unknown;
6454 }
6455}
6456
6457// NOTE this does not depend on x86_64
6458bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {
6459 return (ty->id == ZigTypeIdInt ||
6460 ty->id == ZigTypeIdFloat ||
6461 ty->id == ZigTypeIdBool ||
6462 ty->id == ZigTypeIdEnum ||
6463 ty->id == ZigTypeIdVoid ||
6464 ty->id == ZigTypeIdUnreachable ||
6465 get_codegen_ptr_type(ty) != nullptr);
6466}
6467
src/analyze.hpp+106-98
......@@ -14,103 +14,104 @@
1414void semantic_analyze(CodeGen *g);
1515ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
1616ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
17TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
18TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
19TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
17ZigType *new_type_table_entry(ZigTypeId id);
18ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
19ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
2020 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
21uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
22uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
24TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
25TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
26TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
27TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type);
28TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
29TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type);
30TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
21uint64_t type_size(CodeGen *g, ZigType *type_entry);
22uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
23ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
24ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
25ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
26ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
27ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
28ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
29ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
30ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
3131 AstNode *decl_node, const char *name, ContainerLayout layout);
32TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
33TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type);
34TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);
35TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
36TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
37 TypeTableEntry *field_types[], size_t field_count);
38TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type);
39TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type);
40TypeTableEntry *get_test_fn_type(CodeGen *g);
41bool handle_is_ptr(TypeTableEntry *type_entry);
32ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
33ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
34ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
35ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
36ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
37 ZigType *field_types[], size_t field_count);
38ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
39ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type);
40ZigType *get_test_fn_type(CodeGen *g);
41bool handle_is_ptr(ZigType *type_entry);
4242void find_libc_include_path(CodeGen *g);
4343void find_libc_lib_path(CodeGen *g);
4444
45bool type_has_bits(TypeTableEntry *type_entry);
45bool type_has_bits(ZigType *type_entry);
4646
4747
4848ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
4949
5050
51VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
51ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
5252Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
5353void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
54bool type_is_codegen_pointer(TypeTableEntry *type);
55
56TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type);
57uint32_t get_ptr_align(TypeTableEntry *type);
58bool get_ptr_const(TypeTableEntry *type);
59TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
60TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
61bool type_is_complete(TypeTableEntry *type_entry);
62bool type_is_invalid(TypeTableEntry *type_entry);
63bool type_is_global_error_set(TypeTableEntry *err_set_type);
64bool type_has_zero_bits_known(TypeTableEntry *type_entry);
65void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
66ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
67TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
68TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
69TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name);
70TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag);
71TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag);
72
73bool is_ref(TypeTableEntry *type_entry);
74bool is_array_ref(TypeTableEntry *type_entry);
75bool is_container_ref(TypeTableEntry *type_entry);
54bool type_is_codegen_pointer(ZigType *type);
55
56ZigType *get_codegen_ptr_type(ZigType *type);
57uint32_t get_ptr_align(ZigType *type);
58bool get_ptr_const(ZigType *type);
59ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
60ZigType *container_ref_type(ZigType *type_entry);
61bool type_is_complete(ZigType *type_entry);
62bool type_is_invalid(ZigType *type_entry);
63bool type_is_global_error_set(ZigType *err_set_type);
64bool type_has_zero_bits_known(ZigType *type_entry);
65void resolve_container_type(CodeGen *g, ZigType *type_entry);
66ScopeDecls *get_container_scope(ZigType *type_entry);
67TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name);
68TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name);
69TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name);
70TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag);
71TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);
72
73bool is_ref(ZigType *type_entry);
74bool is_array_ref(ZigType *type_entry);
75bool is_container_ref(ZigType *type_entry);
7676void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
7777void scan_import(CodeGen *g, ImportTableEntry *import);
7878void preview_use_decl(CodeGen *g, AstNode *node);
7979void resolve_use_decl(CodeGen *g, AstNode *node);
80FnTableEntry *scope_fn_entry(Scope *scope);
80ZigFn *scope_fn_entry(Scope *scope);
8181ImportTableEntry *get_scope_import(Scope *scope);
8282void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
83VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
83ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
8484 bool is_const, ConstExprValue *init_value, Tld *src_tld);
85TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
86FnTableEntry *create_fn(AstNode *proto_node);
87FnTableEntry *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
85ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
86ZigFn *create_fn(AstNode *proto_node);
87ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
8888void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);
89AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index);
90FnTableEntry *scope_get_fn_if_root(Scope *scope);
91bool type_requires_comptime(TypeTableEntry *type_entry);
92Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry);
93Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry);
94void complete_enum(CodeGen *g, TypeTableEntry *enum_type);
95bool ir_get_var_is_comptime(VariableTableEntry *var);
89AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
90ZigFn *scope_get_fn_if_root(Scope *scope);
91bool type_requires_comptime(ZigType *type_entry);
92Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
93Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
94void complete_enum(CodeGen *g, ZigType *enum_type);
95bool ir_get_var_is_comptime(ZigVar *var);
9696bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
97void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max);
98void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max);
97void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);
98void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
9999
100100void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);
101void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node);
101void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node);
102102
103103ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
104104ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);
105105ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);
106Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var);
106Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var);
107107ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
108108ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);
109109ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);
110ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry);
111ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import);
110ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry);
111ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
112112Scope *create_comptime_scope(AstNode *node, Scope *parent);
113113Scope *create_coro_prelude_scope(AstNode *node, Scope *parent);
114Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime);
114115
115116void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
116117ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
......@@ -118,39 +119,39 @@ ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
118119void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
119120ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
120121
121void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint);
122ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint);
122void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
123ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
123124
124void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative);
125ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative);
125void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);
126ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
126127
127void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x);
128ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x);
128void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);
129ConstExprValue *create_const_signed(ZigType *type, int64_t x);
129130
130131void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);
131132ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
132133
133void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value);
134ConstExprValue *create_const_float(TypeTableEntry *type, double value);
134void init_const_float(ConstExprValue *const_val, ZigType *type, double value);
135ConstExprValue *create_const_float(ZigType *type, double value);
135136
136void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag);
137ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag);
137void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);
138ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);
138139
139140void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
140141ConstExprValue *create_const_bool(CodeGen *g, bool value);
141142
142void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value);
143ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value);
143void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);
144ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);
144145
145void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type);
146ConstExprValue *create_const_runtime(TypeTableEntry *type);
146void init_const_runtime(ConstExprValue *const_val, ZigType *type);
147ConstExprValue *create_const_runtime(ZigType *type);
147148
148149void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);
149150ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);
150151
151void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type,
152void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,
152153 size_t addr, bool is_const);
153ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type,
154ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
154155 size_t addr, bool is_const);
155156
156157void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
......@@ -169,41 +170,48 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val);
169170
170171ConstExprValue *create_const_vals(size_t count);
171172
172TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
173ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
173174ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value);
174175void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
175176void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);
176177
177const char *type_id_name(TypeTableEntryId id);
178TypeTableEntryId type_id_at_index(size_t index);
178const char *type_id_name(ZigTypeId id);
179ZigTypeId type_id_at_index(size_t index);
179180size_t type_id_len();
180size_t type_id_index(TypeTableEntry *entry);
181TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
182Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry);
181size_t type_id_index(ZigType *entry);
182ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
183Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry);
183184LinkLib *create_link_lib(Buf *name);
184bool calling_convention_does_first_arg_return(CallingConvention cc);
185185LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
186186
187uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry);
188TypeTableEntry *get_align_amt_type(CodeGen *g);
187uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
188ZigType *get_align_amt_type(CodeGen *g);
189189PackageTableEntry *new_anonymous_package(void);
190190
191191Buf *const_value_to_buffer(ConstExprValue *const_val);
192void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
192void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
193193
194194
195195ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
196TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);
197bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node);
196ZigType *get_ptr_to_stack_trace_type(CodeGen *g);
197bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);
198198
199TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
199ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);
200200
201201uint32_t get_coro_frame_align_bytes(CodeGen *g);
202202bool fn_type_can_fail(FnTypeId *fn_type_id);
203bool type_can_fail(TypeTableEntry *type_entry);
204bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type);
205AstNode *type_decl_node(TypeTableEntry *type_entry);
203bool type_can_fail(ZigType *type_entry);
204bool fn_eval_cacheable(Scope *scope, ZigType *return_type);
205AstNode *type_decl_node(ZigType *type_entry);
206206
207TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name);
207ZigType *get_primitive_type(CodeGen *g, Buf *name);
208
209bool calling_convention_allows_zig_types(CallingConvention cc);
210const char *calling_convention_name(CallingConvention cc);
211
212void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);
213X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty);
214bool type_is_c_abi_int(CodeGen *g, ZigType *ty);
215bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);
208216
209217#endif
src/buffer.hpp+5
......@@ -173,4 +173,9 @@ static inline void buf_upcase(Buf *buf) {
173173 }
174174}
175175
176static inline Slice<uint8_t> buf_to_slice(Buf *buf) {
177 return Slice<uint8_t>{reinterpret_cast<uint8_t*>(buf_ptr(buf)), buf_len(buf)};
178}
179
180
176181#endif
src/codegen.cpp+906-603
......@@ -243,7 +243,7 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
243243 g->root_out_name = out_name;
244244}
245245
246void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir) {
246void codegen_set_cache_dir(CodeGen *g, Buf cache_dir) {
247247 g->cache_dir = cache_dir;
248248}
249249
......@@ -358,6 +358,10 @@ static void addLLVMArgAttr(LLVMValueRef fn_val, unsigned param_index, const char
358358 return addLLVMAttr(fn_val, param_index + 1, attr_name);
359359}
360360
361static void addLLVMArgAttrInt(LLVMValueRef fn_val, unsigned param_index, const char *attr_name, uint64_t attr_val) {
362 return addLLVMAttrInt(fn_val, param_index + 1, attr_name, attr_val);
363}
364
361365static bool is_symbol_available(CodeGen *g, Buf *name) {
362366 return g->exported_symbol_names.maybe_get(name) == nullptr && g->external_prototypes.maybe_get(name) == nullptr;
363367}
......@@ -430,23 +434,23 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) {
430434 zig_unreachable();
431435}
432436
433static uint32_t get_err_ret_trace_arg_index(CodeGen *g, FnTableEntry *fn_table_entry) {
437static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {
434438 if (!g->have_err_ret_tracing) {
435439 return UINT32_MAX;
436440 }
437441 if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {
438442 return 0;
439443 }
440 TypeTableEntry *fn_type = fn_table_entry->type_entry;
444 ZigType *fn_type = fn_table_entry->type_entry;
441445 if (!fn_type_can_fail(&fn_type->data.fn.fn_type_id)) {
442446 return UINT32_MAX;
443447 }
444 TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
448 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
445449 bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type);
446450 return first_arg_ret ? 1 : 0;
447451}
448452
449static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
453static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
450454 if (fn_table_entry->llvm_value)
451455 return fn_table_entry->llvm_value;
452456
......@@ -466,7 +470,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
466470 }
467471
468472 bool external_linkage = linkage != GlobalLinkageIdInternal;
469 if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall && external_linkage &&
473 CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;
474 if (cc == CallingConventionStdcall && external_linkage &&
470475 g->zig_target.arch.arch == ZigLLVM_x86)
471476 {
472477 // prevent llvm name mangling
......@@ -474,7 +479,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
474479 }
475480
476481
477 TypeTableEntry *fn_type = fn_table_entry->type_entry;
482 ZigType *fn_type = fn_table_entry->type_entry;
478483 LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref;
479484 if (fn_table_entry->body_node == nullptr) {
480485 LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name));
......@@ -510,17 +515,17 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
510515 break;
511516 }
512517
513 if (fn_type->data.fn.fn_type_id.cc == CallingConventionNaked) {
518 if (cc == CallingConventionNaked) {
514519 addLLVMFnAttr(fn_table_entry->llvm_value, "naked");
515520 } else {
516521 LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));
517522 }
518 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
523 if (cc == CallingConventionAsync) {
519524 addLLVMFnAttr(fn_table_entry->llvm_value, "optnone");
520525 addLLVMFnAttr(fn_table_entry->llvm_value, "noinline");
521526 }
522527
523 bool want_cold = fn_table_entry->is_cold || fn_type->data.fn.fn_type_id.cc == CallingConventionCold;
528 bool want_cold = fn_table_entry->is_cold || cc == CallingConventionCold;
524529 if (want_cold) {
525530 ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);
526531 }
......@@ -532,8 +537,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
532537 LLVMSetUnnamedAddr(fn_table_entry->llvm_value, true);
533538 }
534539
535 TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
536 if (return_type->id == TypeTableEntryIdUnreachable) {
540 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
541 if (return_type->id == ZigTypeIdUnreachable) {
537542 addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");
538543 }
539544
......@@ -572,41 +577,26 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
572577 // use the ABI alignment, which is fine.
573578 }
574579
580 unsigned init_gen_i = 0;
575581 if (!type_has_bits(return_type)) {
576582 // nothing to do
577583 } else if (type_is_codegen_pointer(return_type)) {
578584 addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull");
579 } else if (handle_is_ptr(return_type) &&
580 calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc))
581 {
585 } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
582586 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");
583587 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull");
588 if (cc == CallingConventionC) {
589 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "noalias");
590 }
591 init_gen_i = 1;
584592 }
585593
586
587594 // set parameter attributes
588 for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) {
589 FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
590 size_t gen_index = gen_info->gen_index;
591 bool is_byval = gen_info->is_byval;
592
593 if (gen_index == SIZE_MAX) {
594 continue;
595 }
596
597 FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i];
598
599 TypeTableEntry *param_type = gen_info->type;
600 if (param_info->is_noalias) {
601 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias");
602 }
603 if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) {
604 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly");
605 }
606 if (param_type->id == TypeTableEntryIdPointer) {
607 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull");
608 }
609 }
595 FnWalk fn_walk = {};
596 fn_walk.id = FnWalkIdAttrs;
597 fn_walk.data.attrs.fn = fn_table_entry;
598 fn_walk.data.attrs.gen_i = init_gen_i;
599 walk_function_params(g, fn_type, &fn_walk);
610600
611601 uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry);
612602 if (err_ret_trace_arg_index != UINT32_MAX) {
......@@ -628,7 +618,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
628618 {
629619 assert(scope->parent);
630620 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
631 FnTableEntry *fn_table_entry = fn_scope->fn_entry;
621 ZigFn *fn_table_entry = fn_scope->fn_entry;
632622 if (!fn_table_entry->proto_node)
633623 return get_di_scope(g, scope->parent);
634624 unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ?
......@@ -678,6 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
678668 case ScopeIdSuspend:
679669 case ScopeIdCompTime:
680670 case ScopeIdCoroPrelude:
671 case ScopeIdRuntime:
681672 return get_di_scope(g, scope->parent);
682673 }
683674 zig_unreachable();
......@@ -687,12 +678,12 @@ static void clear_debug_source_node(CodeGen *g) {
687678 ZigLLVMClearCurrentDebugLocation(g->builder);
688679}
689680
690static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
681static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,
691682 const char *signed_name, const char *unsigned_name)
692683{
693684 char fn_name[64];
694685
695 assert(type_entry->id == TypeTableEntryIdInt);
686 assert(type_entry->id == ZigTypeIdInt);
696687 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
697688 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);
698689
......@@ -711,8 +702,8 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
711702 return fn_val;
712703}
713704
714static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {
715 assert(type_entry->id == TypeTableEntryIdInt);
705static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {
706 assert(type_entry->id == ZigTypeIdInt);
716707
717708 ZigLLVMFnKey key = {};
718709 key.id = ZigLLVMFnIdOverflowArithmetic;
......@@ -741,8 +732,8 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
741732 return fn_val;
742733}
743734
744static LLVMValueRef get_float_fn(CodeGen *g, TypeTableEntry *type_entry, ZigLLVMFnId fn_id) {
745 assert(type_entry->id == TypeTableEntryIdFloat);
735static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) {
736 assert(type_entry->id == ZigTypeIdFloat);
746737
747738 ZigLLVMFnKey key = {};
748739 key.id = fn_id;
......@@ -786,8 +777,8 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR
786777 return instruction;
787778}
788779
789static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, TypeTableEntry *ptr_type) {
790 assert(ptr_type->id == TypeTableEntryIdPointer);
780static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) {
781 assert(ptr_type->id == ZigTypeIdPointer);
791782 return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
792783}
793784
......@@ -804,17 +795,17 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
804795 return result;
805796}
806797
807static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, const char *name) {
808 assert(ptr_type->id == TypeTableEntryIdPointer);
798static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
799 assert(ptr_type->id == ZigTypeIdPointer);
809800 return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);
810801}
811802
812static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type, TypeTableEntry *ptr_type) {
803static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
813804 if (type_has_bits(type)) {
814805 if (handle_is_ptr(type)) {
815806 return ptr;
816807 } else {
817 assert(ptr_type->id == TypeTableEntryIdPointer);
808 assert(ptr_type->id == ZigTypeIdPointer);
818809 return gen_load(g, ptr, ptr_type, "");
819810 }
820811 } else {
......@@ -917,9 +908,9 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
917908 assert(val->global_refs->llvm_global);
918909 }
919910
920 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
911 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
921912 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
922 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
913 ZigType *str_type = get_slice_type(g, u8_ptr_type);
923914 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));
924915}
925916
......@@ -928,7 +919,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
928919 LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);
929920 LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);
930921 if (stack_trace_arg == nullptr) {
931 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
922 ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
932923 stack_trace_arg = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
933924 }
934925 LLVMValueRef args[] = {
......@@ -1166,7 +1157,7 @@ static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
11661157 if (g->return_address_fn_val)
11671158 return g->return_address_fn_val;
11681159
1169 TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
1160 ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
11701161
11711162 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
11721163 &g->builtin_types.entry_i32->type_ref, 1, false);
......@@ -1217,7 +1208,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
12171208 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
12181209 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, "");
12191210
1220 TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
1211 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
12211212 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
12221213 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
12231214 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
......@@ -1317,7 +1308,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
13171308 (unsigned)src_index_field_index, "");
13181309 LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
13191310 (unsigned)src_addresses_field_index, "");
1320 TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
1311 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
13211312 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
13221313 LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");
13231314 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
......@@ -1459,7 +1450,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
14591450 LLVMSetUnnamedAddr(global_array, true);
14601451 LLVMSetAlignment(global_array, u8_align_bytes);
14611452
1462 TypeTableEntry *usize = g->builtin_types.entry_usize;
1453 ZigType *usize = g->builtin_types.entry_usize;
14631454 LLVMValueRef full_buf_ptr_indices[] = {
14641455 LLVMConstNull(usize->type_ref),
14651456 LLVMConstNull(usize->type_ref),
......@@ -1467,9 +1458,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
14671458 LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2);
14681459
14691460
1470 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1461 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
14711462 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
1472 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
1463 ZigType *str_type = get_slice_type(g, u8_ptr_type);
14731464 LLVMValueRef global_slice_fields[] = {
14741465 full_buf_ptr,
14751466 LLVMConstNull(usize->type_ref),
......@@ -1575,7 +1566,7 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc
15751566 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
15761567 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, scope);
15771568 if (err_ret_trace_val == nullptr) {
1578 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
1569 ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
15791570 err_ret_trace_val = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
15801571 }
15811572 LLVMValueRef args[] = {
......@@ -1621,24 +1612,24 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
16211612 LLVMPositionBuilderAtEnd(g->builder, ok_block);
16221613}
16231614
1624static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type,
1625 TypeTableEntry *wanted_type, LLVMValueRef expr_val)
1615static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type,
1616 ZigType *wanted_type, LLVMValueRef expr_val)
16261617{
16271618 assert(actual_type->id == wanted_type->id);
16281619
16291620 uint64_t actual_bits;
16301621 uint64_t wanted_bits;
1631 if (actual_type->id == TypeTableEntryIdFloat) {
1622 if (actual_type->id == ZigTypeIdFloat) {
16321623 actual_bits = actual_type->data.floating.bit_count;
16331624 wanted_bits = wanted_type->data.floating.bit_count;
1634 } else if (actual_type->id == TypeTableEntryIdInt) {
1625 } else if (actual_type->id == ZigTypeIdInt) {
16351626 actual_bits = actual_type->data.integral.bit_count;
16361627 wanted_bits = wanted_type->data.integral.bit_count;
16371628 } else {
16381629 zig_unreachable();
16391630 }
16401631
1641 if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&
1632 if (actual_bits >= wanted_bits && actual_type->id == ZigTypeIdInt &&
16421633 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
16431634 want_runtime_safety)
16441635 {
......@@ -1658,9 +1649,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
16581649 if (actual_bits == wanted_bits) {
16591650 return expr_val;
16601651 } else if (actual_bits < wanted_bits) {
1661 if (actual_type->id == TypeTableEntryIdFloat) {
1652 if (actual_type->id == ZigTypeIdFloat) {
16621653 return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");
1663 } else if (actual_type->id == TypeTableEntryIdInt) {
1654 } else if (actual_type->id == ZigTypeIdInt) {
16641655 if (actual_type->data.integral.is_signed) {
16651656 return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");
16661657 } else {
......@@ -1670,9 +1661,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
16701661 zig_unreachable();
16711662 }
16721663 } else if (actual_bits > wanted_bits) {
1673 if (actual_type->id == TypeTableEntryIdFloat) {
1664 if (actual_type->id == ZigTypeIdFloat) {
16741665 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1675 } else if (actual_type->id == TypeTableEntryIdInt) {
1666 } else if (actual_type->id == ZigTypeIdInt) {
16761667 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
16771668 if (!want_runtime_safety) {
16781669 return trunc_val;
......@@ -1701,7 +1692,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
17011692 }
17021693}
17031694
1704static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddSubMul op,
1695static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *type_entry, AddSubMul op,
17051696 LLVMValueRef val1, LLVMValueRef val2)
17061697{
17071698 LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op);
......@@ -1761,11 +1752,11 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) {
17611752 }
17621753}
17631754
1764static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type,
1755static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
17651756 LLVMValueRef value)
17661757{
1767 assert(ptr_type->id == TypeTableEntryIdPointer);
1768 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
1758 assert(ptr_type->id == ZigTypeIdPointer);
1759 ZigType *child_type = ptr_type->data.pointer.child_type;
17691760
17701761 if (!type_has_bits(child_type))
17711762 return nullptr;
......@@ -1779,7 +1770,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
17791770 LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, value, ptr_u8, "");
17801771 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, ptr, ptr_u8, "");
17811772
1782 TypeTableEntry *usize = g->builtin_types.entry_usize;
1773 ZigType *usize = g->builtin_types.entry_usize;
17831774 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, child_type->type_ref);
17841775 uint64_t align_bytes = ptr_type->data.pointer.alignment;
17851776 assert(size_bytes > 0);
......@@ -1819,7 +1810,8 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
18191810 return nullptr;
18201811}
18211812
1822static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
1813static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
1814 assert(var->di_loc_var != nullptr);
18231815 AstNode *source_node = var->decl_node;
18241816 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
18251817 (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));
......@@ -1838,9 +1830,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
18381830 // values are rendered with a type other than the one we expect
18391831 if (handle_is_ptr(instruction->value.type)) {
18401832 render_const_val_global(g, &instruction->value, "");
1841 TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
1833 ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
18421834 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, "");
1843 } else if (instruction->value.type->id == TypeTableEntryIdPointer) {
1835 } else if (instruction->value.type->id == ZigTypeIdPointer) {
18441836 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");
18451837 } else {
18461838 instruction->llvm_value = instruction->value.global_refs->llvm_value;
......@@ -1850,6 +1842,353 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
18501842 return instruction->llvm_value;
18511843}
18521844
1845ATTRIBUTE_NORETURN
1846static void report_errors_and_exit(CodeGen *g) {
1847 assert(g->errors.length != 0);
1848 for (size_t i = 0; i < g->errors.length; i += 1) {
1849 ErrorMsg *err = g->errors.at(i);
1850 print_err_msg(err, g->err_color);
1851 }
1852 exit(1);
1853}
1854
1855static void report_errors_and_maybe_exit(CodeGen *g) {
1856 if (g->errors.length != 0) {
1857 report_errors_and_exit(g);
1858 }
1859}
1860
1861ATTRIBUTE_NORETURN
1862static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) {
1863 ErrorMsg *msg = add_node_error(g, source_node,
1864 buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481"));
1865 add_error_note(g, msg, source_node,
1866 buf_sprintf("pointers, integers, floats, bools, and enums work on all targets"));
1867 report_errors_and_exit(g);
1868}
1869
1870static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) {
1871 assert(alignment > 0);
1872 LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name);
1873 LLVMSetAlignment(result, alignment);
1874 return result;
1875}
1876
1877static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) {
1878 // Initialized from the type for some walks, but because of C var args,
1879 // initialized based on callsite instructions for that one.
1880 FnTypeParamInfo *param_info = nullptr;
1881 ZigType *ty;
1882 ZigType *dest_ty = nullptr;
1883 AstNode *source_node = nullptr;
1884 LLVMValueRef val;
1885 LLVMValueRef llvm_fn;
1886 unsigned di_arg_index;
1887 ZigVar *var;
1888 switch (fn_walk->id) {
1889 case FnWalkIdAttrs:
1890 if (src_i >= fn_type->data.fn.fn_type_id.param_count)
1891 return false;
1892 param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
1893 ty = param_info->type;
1894 source_node = fn_walk->data.attrs.fn->proto_node;
1895 llvm_fn = fn_walk->data.attrs.fn->llvm_value;
1896 break;
1897 case FnWalkIdCall: {
1898 if (src_i >= fn_walk->data.call.inst->arg_count)
1899 return false;
1900 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
1901 ty = arg->value.type;
1902 source_node = arg->source_node;
1903 val = ir_llvm_value(g, arg);
1904 break;
1905 }
1906 case FnWalkIdTypes:
1907 if (src_i >= fn_type->data.fn.fn_type_id.param_count)
1908 return false;
1909 param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
1910 ty = param_info->type;
1911 break;
1912 case FnWalkIdVars:
1913 assert(src_i < fn_type->data.fn.fn_type_id.param_count);
1914 param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
1915 ty = param_info->type;
1916 var = fn_walk->data.vars.var;
1917 source_node = var->decl_node;
1918 llvm_fn = fn_walk->data.vars.llvm_fn;
1919 break;
1920 case FnWalkIdInits:
1921 if (src_i >= fn_type->data.fn.fn_type_id.param_count)
1922 return false;
1923 param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
1924 ty = param_info->type;
1925 var = fn_walk->data.inits.fn->variable_list.at(src_i);
1926 source_node = fn_walk->data.inits.fn->proto_node;
1927 llvm_fn = fn_walk->data.inits.llvm_fn;
1928 break;
1929 }
1930
1931 if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat ||
1932 ty->id == ZigTypeIdInt // TODO investigate if we need to change this
1933 ) {
1934 switch (fn_walk->id) {
1935 case FnWalkIdAttrs: {
1936 ZigType *ptr_type = get_codegen_ptr_type(ty);
1937 if (ptr_type != nullptr) {
1938 if (ty->id != ZigTypeIdOptional) {
1939 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
1940 }
1941 if (ptr_type->data.pointer.is_const) {
1942 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "readonly");
1943 }
1944 if (param_info->is_noalias) {
1945 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "noalias");
1946 }
1947 }
1948 fn_walk->data.attrs.gen_i += 1;
1949 break;
1950 }
1951 case FnWalkIdCall:
1952 fn_walk->data.call.gen_param_values->append(val);
1953 break;
1954 case FnWalkIdTypes:
1955 fn_walk->data.types.gen_param_types->append(ty->type_ref);
1956 fn_walk->data.types.param_di_types->append(ty->di_type);
1957 break;
1958 case FnWalkIdVars: {
1959 var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
1960 di_arg_index = fn_walk->data.vars.gen_i;
1961 fn_walk->data.vars.gen_i += 1;
1962 dest_ty = ty;
1963 goto var_ok;
1964 }
1965 case FnWalkIdInits:
1966 clear_debug_source_node(g);
1967 gen_store_untyped(g, LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i), var->value_ref, var->align_bytes, false);
1968 if (var->decl_node) {
1969 gen_var_debug_decl(g, var);
1970 }
1971 fn_walk->data.inits.gen_i += 1;
1972 break;
1973 }
1974 return true;
1975 }
1976
1977 // Arrays are just pointers
1978 if (ty->id == ZigTypeIdArray) {
1979 assert(handle_is_ptr(ty));
1980 switch (fn_walk->id) {
1981 case FnWalkIdAttrs:
1982 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
1983 addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty));
1984 fn_walk->data.attrs.gen_i += 1;
1985 break;
1986 case FnWalkIdCall:
1987 fn_walk->data.call.gen_param_values->append(val);
1988 break;
1989 case FnWalkIdTypes: {
1990 ZigType *gen_type = get_pointer_to_type(g, ty, true);
1991 fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
1992 fn_walk->data.types.param_di_types->append(gen_type->di_type);
1993 break;
1994 }
1995 case FnWalkIdVars: {
1996 var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i);
1997 di_arg_index = fn_walk->data.vars.gen_i;
1998 dest_ty = get_pointer_to_type(g, ty, false);
1999 fn_walk->data.vars.gen_i += 1;
2000 goto var_ok;
2001 }
2002 case FnWalkIdInits:
2003 if (var->decl_node) {
2004 gen_var_debug_decl(g, var);
2005 }
2006 fn_walk->data.inits.gen_i += 1;
2007 break;
2008 }
2009 return true;
2010 }
2011
2012 if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
2013 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);
2014 size_t ty_size = type_size(g, ty);
2015 if (abi_class == X64CABIClass_MEMORY) {
2016 assert(handle_is_ptr(ty));
2017 switch (fn_walk->id) {
2018 case FnWalkIdAttrs:
2019 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval");
2020 addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty));
2021 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
2022 fn_walk->data.attrs.gen_i += 1;
2023 break;
2024 case FnWalkIdCall:
2025 fn_walk->data.call.gen_param_values->append(val);
2026 break;
2027 case FnWalkIdTypes: {
2028 ZigType *gen_type = get_pointer_to_type(g, ty, true);
2029 fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
2030 fn_walk->data.types.param_di_types->append(gen_type->di_type);
2031 break;
2032 }
2033 case FnWalkIdVars: {
2034 di_arg_index = fn_walk->data.vars.gen_i;
2035 var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i);
2036 dest_ty = get_pointer_to_type(g, ty, false);
2037 fn_walk->data.vars.gen_i += 1;
2038 goto var_ok;
2039 }
2040 case FnWalkIdInits:
2041 if (var->decl_node) {
2042 gen_var_debug_decl(g, var);
2043 }
2044 fn_walk->data.inits.gen_i += 1;
2045 break;
2046 }
2047 return true;
2048 } else if (abi_class == X64CABIClass_INTEGER) {
2049 switch (fn_walk->id) {
2050 case FnWalkIdAttrs:
2051 fn_walk->data.attrs.gen_i += 1;
2052 break;
2053 case FnWalkIdCall: {
2054 LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0);
2055 LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, "");
2056 LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, "");
2057 fn_walk->data.call.gen_param_values->append(loaded);
2058 break;
2059 }
2060 case FnWalkIdTypes: {
2061 ZigType *gen_type = get_int_type(g, false, ty_size * 8);
2062 fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
2063 fn_walk->data.types.param_di_types->append(gen_type->di_type);
2064 break;
2065 }
2066 case FnWalkIdVars: {
2067 di_arg_index = fn_walk->data.vars.gen_i;
2068 var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
2069 fn_walk->data.vars.gen_i += 1;
2070 dest_ty = ty;
2071 goto var_ok;
2072 }
2073 case FnWalkIdInits: {
2074 clear_debug_source_node(g);
2075 LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i);
2076 LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0);
2077 LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, "");
2078 gen_store_untyped(g, arg, bitcasted, var->align_bytes, false);
2079 if (var->decl_node) {
2080 gen_var_debug_decl(g, var);
2081 }
2082 fn_walk->data.inits.gen_i += 1;
2083 break;
2084 }
2085 }
2086 return true;
2087 }
2088 }
2089 if (source_node != nullptr) {
2090 give_up_with_c_abi_error(g, source_node);
2091 }
2092 // otherwise allow codegen code to report a compile error
2093 return false;
2094
2095var_ok:
2096 if (dest_ty != nullptr && var->decl_node) {
2097 // arg index + 1 because the 0 index is return value
2098 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
2099 buf_ptr(&var->name), fn_walk->data.vars.import->di_file,
2100 (unsigned)(var->decl_node->line + 1),
2101 dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1);
2102 }
2103 return true;
2104}
2105
2106void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2107 CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
2108 if (cc == CallingConventionC) {
2109 size_t src_i = 0;
2110 for (;;) {
2111 if (!iter_function_params_c_abi(g, fn_type, fn_walk, src_i))
2112 break;
2113 src_i += 1;
2114 }
2115 return;
2116 }
2117 if (fn_walk->id == FnWalkIdCall) {
2118 IrInstructionCall *instruction = fn_walk->data.call.inst;
2119 bool is_var_args = fn_walk->data.call.is_var_args;
2120 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2121 IrInstruction *param_instruction = instruction->args[call_i];
2122 ZigType *param_type = param_instruction->value.type;
2123 if (is_var_args || type_has_bits(param_type)) {
2124 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
2125 assert(param_value);
2126 fn_walk->data.call.gen_param_values->append(param_value);
2127 }
2128 }
2129 return;
2130 }
2131 size_t next_var_i = 0;
2132 for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) {
2133 FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
2134 size_t gen_index = gen_info->gen_index;
2135
2136 if (gen_index == SIZE_MAX) {
2137 continue;
2138 }
2139
2140 switch (fn_walk->id) {
2141 case FnWalkIdAttrs: {
2142 LLVMValueRef llvm_fn = fn_walk->data.attrs.fn->llvm_value;
2143 bool is_byval = gen_info->is_byval;
2144 FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i];
2145
2146 ZigType *param_type = gen_info->type;
2147 if (param_info->is_noalias) {
2148 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "noalias");
2149 }
2150 if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {
2151 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly");
2152 }
2153 if (param_type->id == ZigTypeIdPointer) {
2154 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull");
2155 }
2156 break;
2157 }
2158 case FnWalkIdInits: {
2159 ZigFn *fn_table_entry = fn_walk->data.inits.fn;
2160 LLVMValueRef llvm_fn = fn_table_entry->llvm_value;
2161 ZigVar *variable = fn_table_entry->variable_list.at(next_var_i);
2162 assert(variable->src_arg_index != SIZE_MAX);
2163 next_var_i += 1;
2164
2165 assert(variable);
2166 assert(variable->value_ref);
2167
2168 if (!handle_is_ptr(variable->value->type)) {
2169 clear_debug_source_node(g);
2170 gen_store_untyped(g, LLVMGetParam(llvm_fn, (unsigned)variable->gen_arg_index), variable->value_ref,
2171 variable->align_bytes, false);
2172 }
2173
2174 if (variable->decl_node) {
2175 gen_var_debug_decl(g, variable);
2176 }
2177 break;
2178 }
2179 case FnWalkIdCall:
2180 // handled before for loop
2181 zig_unreachable();
2182 case FnWalkIdTypes:
2183 // Not called for non-c-abi
2184 zig_unreachable();
2185 case FnWalkIdVars:
2186 // iter_function_params_c_abi is called directly for this one
2187 zig_unreachable();
2188 }
2189 }
2190}
2191
18532192static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
18542193 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
18552194{
......@@ -1866,24 +2205,22 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
18662205
18672206static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {
18682207 LLVMValueRef value = ir_llvm_value(g, return_instruction->value);
1869 TypeTableEntry *return_type = return_instruction->value->value.type;
1870
1871 if (handle_is_ptr(return_type)) {
1872 if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {
1873 assert(g->cur_ret_ptr);
1874 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
1875 LLVMBuildRetVoid(g->builder);
1876 } else {
1877 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
1878 LLVMBuildRet(g->builder, by_val_value);
1879 }
2208 ZigType *return_type = return_instruction->value->value.type;
2209
2210 if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) {
2211 assert(g->cur_ret_ptr);
2212 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
2213 LLVMBuildRetVoid(g->builder);
2214 } else if (handle_is_ptr(return_type)) {
2215 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
2216 LLVMBuildRet(g->builder, by_val_value);
18802217 } else {
18812218 LLVMBuildRet(g->builder, value);
18822219 }
18832220 return nullptr;
18842221}
18852222
1886static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
2223static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,
18872224 LLVMValueRef val1, LLVMValueRef val2)
18882225{
18892226 // for unsigned left shifting, we do the lossy shift, then logically shift
......@@ -1891,7 +2228,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
18912228 // if the values don't match, we have an overflow
18922229 // for signed left shifting we do the same except arithmetic shift right
18932230
1894 assert(type_entry->id == TypeTableEntryIdInt);
2231 assert(type_entry->id == ZigTypeIdInt);
18952232
18962233 LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");
18972234 LLVMValueRef orig_val;
......@@ -1913,10 +2250,10 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
19132250 return result;
19142251}
19152252
1916static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
2253static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,
19172254 LLVMValueRef val1, LLVMValueRef val2)
19182255{
1919 assert(type_entry->id == TypeTableEntryIdInt);
2256 assert(type_entry->id == ZigTypeIdInt);
19202257
19212258 LLVMValueRef result;
19222259 if (type_entry->data.integral.is_signed) {
......@@ -1938,16 +2275,16 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
19382275 return result;
19392276}
19402277
1941static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {
1942 if (type_entry->id == TypeTableEntryIdInt)
2278static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
2279 if (type_entry->id == ZigTypeIdInt)
19432280 return val;
19442281
19452282 LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);
19462283 return LLVMBuildCall(g->builder, floor_fn, &val, 1, "");
19472284}
19482285
1949static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {
1950 if (type_entry->id == TypeTableEntryIdInt)
2286static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
2287 if (type_entry->id == ZigTypeIdInt)
19512288 return val;
19522289
19532290 LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil);
......@@ -1980,16 +2317,16 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {
19802317
19812318static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
19822319 LLVMValueRef val1, LLVMValueRef val2,
1983 TypeTableEntry *type_entry, DivKind div_kind)
2320 ZigType *type_entry, DivKind div_kind)
19842321{
19852322 ZigLLVMSetFastMath(g->builder, want_fast_math);
19862323
19872324 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
1988 if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {
2325 if (want_runtime_safety && (want_fast_math || type_entry->id != ZigTypeIdFloat)) {
19892326 LLVMValueRef is_zero_bit;
1990 if (type_entry->id == TypeTableEntryIdInt) {
2327 if (type_entry->id == ZigTypeIdInt) {
19912328 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");
1992 } else if (type_entry->id == TypeTableEntryIdFloat) {
2329 } else if (type_entry->id == ZigTypeIdFloat) {
19932330 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
19942331 } else {
19952332 zig_unreachable();
......@@ -2003,7 +2340,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
20032340
20042341 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);
20052342
2006 if (type_entry->id == TypeTableEntryIdInt && type_entry->data.integral.is_signed) {
2343 if (type_entry->id == ZigTypeIdInt && type_entry->data.integral.is_signed) {
20072344 LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);
20082345 BigInt int_min_bi = {0};
20092346 eval_min_max_value_int(g, type_entry, &int_min_bi, false);
......@@ -2022,7 +2359,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
20222359 }
20232360 }
20242361
2025 if (type_entry->id == TypeTableEntryIdFloat) {
2362 if (type_entry->id == ZigTypeIdFloat) {
20262363 LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");
20272364 switch (div_kind) {
20282365 case DivKindFloat:
......@@ -2073,7 +2410,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
20732410 zig_unreachable();
20742411 }
20752412
2076 assert(type_entry->id == TypeTableEntryIdInt);
2413 assert(type_entry->id == ZigTypeIdInt);
20772414
20782415 switch (div_kind) {
20792416 case DivKindFloat:
......@@ -2139,17 +2476,17 @@ enum RemKind {
21392476
21402477static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
21412478 LLVMValueRef val1, LLVMValueRef val2,
2142 TypeTableEntry *type_entry, RemKind rem_kind)
2479 ZigType *type_entry, RemKind rem_kind)
21432480{
21442481 ZigLLVMSetFastMath(g->builder, want_fast_math);
21452482
21462483 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
21472484 if (want_runtime_safety) {
21482485 LLVMValueRef is_zero_bit;
2149 if (type_entry->id == TypeTableEntryIdInt) {
2486 if (type_entry->id == ZigTypeIdInt) {
21502487 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;
21512488 is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");
2152 } else if (type_entry->id == TypeTableEntryIdFloat) {
2489 } else if (type_entry->id == ZigTypeIdFloat) {
21532490 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
21542491 } else {
21552492 zig_unreachable();
......@@ -2164,7 +2501,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
21642501 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
21652502 }
21662503
2167 if (type_entry->id == TypeTableEntryIdFloat) {
2504 if (type_entry->id == ZigTypeIdFloat) {
21682505 if (rem_kind == RemKindRem) {
21692506 return LLVMBuildFRem(g->builder, val1, val2, "");
21702507 } else {
......@@ -2175,7 +2512,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
21752512 return LLVMBuildSelect(g->builder, ltz, c, a, "");
21762513 }
21772514 } else {
2178 assert(type_entry->id == TypeTableEntryIdInt);
2515 assert(type_entry->id == ZigTypeIdInt);
21792516 if (type_entry->data.integral.is_signed) {
21802517 if (rem_kind == RemKindRem) {
21812518 return LLVMBuildSRem(g->builder, val1, val2, "");
......@@ -2203,12 +2540,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22032540 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
22042541 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
22052542 op_id == IrBinOpBitShiftRightExact ||
2206 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||
2207 (op1->value.type->id == TypeTableEntryIdPointer &&
2543 (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) ||
2544 (op1->value.type->id == ZigTypeIdPointer &&
22082545 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
22092546 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
22102547 );
2211 TypeTableEntry *type_entry = op1->value.type;
2548 ZigType *type_entry = op1->value.type;
22122549
22132550 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
22142551 ir_want_runtime_safety(g, &bin_op_instruction->base);
......@@ -2234,16 +2571,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22342571 case IrBinOpCmpGreaterThan:
22352572 case IrBinOpCmpLessOrEq:
22362573 case IrBinOpCmpGreaterOrEq:
2237 if (type_entry->id == TypeTableEntryIdFloat) {
2574 if (type_entry->id == ZigTypeIdFloat) {
22382575 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
22392576 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
22402577 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
2241 } else if (type_entry->id == TypeTableEntryIdInt) {
2578 } else if (type_entry->id == ZigTypeIdInt) {
22422579 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);
22432580 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
2244 } else if (type_entry->id == TypeTableEntryIdEnum ||
2245 type_entry->id == TypeTableEntryIdErrorSet ||
2246 type_entry->id == TypeTableEntryIdBool ||
2581 } else if (type_entry->id == ZigTypeIdEnum ||
2582 type_entry->id == ZigTypeIdErrorSet ||
2583 type_entry->id == ZigTypeIdBool ||
22472584 get_codegen_ptr_type(type_entry) != nullptr)
22482585 {
22492586 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
......@@ -2253,14 +2590,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22532590 }
22542591 case IrBinOpAdd:
22552592 case IrBinOpAddWrap:
2256 if (type_entry->id == TypeTableEntryIdPointer) {
2593 if (type_entry->id == ZigTypeIdPointer) {
22572594 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
22582595 // TODO runtime safety
22592596 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
2260 } else if (type_entry->id == TypeTableEntryIdFloat) {
2597 } else if (type_entry->id == ZigTypeIdFloat) {
22612598 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
22622599 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
2263 } else if (type_entry->id == TypeTableEntryIdInt) {
2600 } else if (type_entry->id == ZigTypeIdInt) {
22642601 bool is_wrapping = (op_id == IrBinOpAddWrap);
22652602 if (is_wrapping) {
22662603 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
......@@ -2283,7 +2620,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22832620 case IrBinOpBitShiftLeftLossy:
22842621 case IrBinOpBitShiftLeftExact:
22852622 {
2286 assert(type_entry->id == TypeTableEntryIdInt);
2623 assert(type_entry->id == ZigTypeIdInt);
22872624 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
22882625 type_entry, op2_value);
22892626 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
......@@ -2300,7 +2637,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
23002637 case IrBinOpBitShiftRightLossy:
23012638 case IrBinOpBitShiftRightExact:
23022639 {
2303 assert(type_entry->id == TypeTableEntryIdInt);
2640 assert(type_entry->id == ZigTypeIdInt);
23042641 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
23052642 type_entry, op2_value);
23062643 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
......@@ -2320,15 +2657,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
23202657 }
23212658 case IrBinOpSub:
23222659 case IrBinOpSubWrap:
2323 if (type_entry->id == TypeTableEntryIdPointer) {
2660 if (type_entry->id == ZigTypeIdPointer) {
23242661 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
23252662 // TODO runtime safety
23262663 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
23272664 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2328 } else if (type_entry->id == TypeTableEntryIdFloat) {
2665 } else if (type_entry->id == ZigTypeIdFloat) {
23292666 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
23302667 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
2331 } else if (type_entry->id == TypeTableEntryIdInt) {
2668 } else if (type_entry->id == ZigTypeIdInt) {
23322669 bool is_wrapping = (op_id == IrBinOpSubWrap);
23332670 if (is_wrapping) {
23342671 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
......@@ -2344,10 +2681,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
23442681 }
23452682 case IrBinOpMult:
23462683 case IrBinOpMultWrap:
2347 if (type_entry->id == TypeTableEntryIdFloat) {
2684 if (type_entry->id == ZigTypeIdFloat) {
23482685 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
23492686 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
2350 } else if (type_entry->id == TypeTableEntryIdInt) {
2687 } else if (type_entry->id == ZigTypeIdInt) {
23512688 bool is_wrapping = (op_id == IrBinOpMultWrap);
23522689 if (is_wrapping) {
23532690 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
......@@ -2383,8 +2720,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
23832720 zig_unreachable();
23842721}
23852722
2386static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *int_type, LLVMValueRef target_val) {
2387 assert(err_set_type->id == TypeTableEntryIdErrorSet);
2723static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) {
2724 assert(err_set_type->id == ZigTypeIdErrorSet);
23882725
23892726 if (type_is_global_error_set(err_set_type)) {
23902727 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);
......@@ -2434,8 +2771,8 @@ static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, Type
24342771static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
24352772 IrInstructionCast *cast_instruction)
24362773{
2437 TypeTableEntry *actual_type = cast_instruction->value->value.type;
2438 TypeTableEntry *wanted_type = cast_instruction->base.value.type;
2774 ZigType *actual_type = cast_instruction->value->value.type;
2775 ZigType *wanted_type = cast_instruction->base.value.type;
24392776 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
24402777 assert(expr_val);
24412778
......@@ -2448,15 +2785,15 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
24482785 case CastOpResizeSlice:
24492786 {
24502787 assert(cast_instruction->tmp_ptr);
2451 assert(wanted_type->id == TypeTableEntryIdStruct);
2788 assert(wanted_type->id == ZigTypeIdStruct);
24522789 assert(wanted_type->data.structure.is_slice);
2453 assert(actual_type->id == TypeTableEntryIdStruct);
2790 assert(actual_type->id == ZigTypeIdStruct);
24542791 assert(actual_type->data.structure.is_slice);
24552792
2456 TypeTableEntry *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
2457 TypeTableEntry *actual_child_type = actual_pointer_type->data.pointer.child_type;
2458 TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
2459 TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
2793 ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
2794 ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type;
2795 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
2796 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
24602797
24612798
24622799 size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index;
......@@ -2511,12 +2848,12 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
25112848 case CastOpBytesToSlice:
25122849 {
25132850 assert(cast_instruction->tmp_ptr);
2514 assert(wanted_type->id == TypeTableEntryIdStruct);
2851 assert(wanted_type->id == ZigTypeIdStruct);
25152852 assert(wanted_type->data.structure.is_slice);
2516 assert(actual_type->id == TypeTableEntryIdArray);
2853 assert(actual_type->id == ZigTypeIdArray);
25172854
2518 TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
2519 TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
2855 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
2856 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
25202857
25212858
25222859 size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
......@@ -2535,14 +2872,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
25352872 return cast_instruction->tmp_ptr;
25362873 }
25372874 case CastOpIntToFloat:
2538 assert(actual_type->id == TypeTableEntryIdInt);
2875 assert(actual_type->id == ZigTypeIdInt);
25392876 if (actual_type->data.integral.is_signed) {
25402877 return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");
25412878 } else {
25422879 return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");
25432880 }
25442881 case CastOpFloatToInt: {
2545 assert(wanted_type->id == TypeTableEntryIdInt);
2882 assert(wanted_type->id == ZigTypeIdInt);
25462883 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));
25472884
25482885 bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);
......@@ -2577,8 +2914,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
25772914 return result;
25782915 }
25792916 case CastOpBoolToInt:
2580 assert(wanted_type->id == TypeTableEntryIdInt);
2581 assert(actual_type->id == TypeTableEntryIdBool);
2917 assert(wanted_type->id == ZigTypeIdInt);
2918 assert(actual_type->id == ZigTypeIdBool);
25822919 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
25832920 case CastOpErrSet:
25842921 if (ir_want_runtime_safety(g, &cast_instruction->base)) {
......@@ -2589,9 +2926,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
25892926 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");
25902927 case CastOpPtrOfArrayToSlice: {
25912928 assert(cast_instruction->tmp_ptr);
2592 assert(actual_type->id == TypeTableEntryIdPointer);
2593 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
2594 assert(array_type->id == TypeTableEntryIdArray);
2929 assert(actual_type->id == ZigTypeIdPointer);
2930 ZigType *array_type = actual_type->data.pointer.child_type;
2931 assert(array_type->id == ZigTypeIdArray);
25952932
25962933 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
25972934 slice_ptr_index, "");
......@@ -2617,7 +2954,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
26172954static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
26182955 IrInstructionPtrCast *instruction)
26192956{
2620 TypeTableEntry *wanted_type = instruction->base.value.type;
2957 ZigType *wanted_type = instruction->base.value.type;
26212958 if (!type_has_bits(wanted_type)) {
26222959 return nullptr;
26232960 }
......@@ -2628,7 +2965,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
26282965static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
26292966 IrInstructionBitCast *instruction)
26302967{
2631 TypeTableEntry *wanted_type = instruction->base.value.type;
2968 ZigType *wanted_type = instruction->base.value.type;
26322969 LLVMValueRef value = ir_llvm_value(g, instruction->value);
26332970 return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, "");
26342971}
......@@ -2636,11 +2973,11 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
26362973static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
26372974 IrInstructionWidenOrShorten *instruction)
26382975{
2639 TypeTableEntry *actual_type = instruction->target->value.type;
2976 ZigType *actual_type = instruction->target->value.type;
26402977 // TODO instead of this logic, use the Noop instruction to change the type from
26412978 // enum_tag to the underlying int type
2642 TypeTableEntry *int_type;
2643 if (actual_type->id == TypeTableEntryIdEnum) {
2979 ZigType *int_type;
2980 if (actual_type->id == ZigTypeIdEnum) {
26442981 int_type = actual_type->data.enumeration.tag_int_type;
26452982 } else {
26462983 int_type = actual_type;
......@@ -2651,21 +2988,21 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
26512988}
26522989
26532990static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {
2654 TypeTableEntry *wanted_type = instruction->base.value.type;
2991 ZigType *wanted_type = instruction->base.value.type;
26552992 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
26562993 return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, "");
26572994}
26582995
26592996static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {
2660 TypeTableEntry *wanted_type = instruction->base.value.type;
2997 ZigType *wanted_type = instruction->base.value.type;
26612998 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
26622999 return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, "");
26633000}
26643001
26653002static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
2666 TypeTableEntry *wanted_type = instruction->base.value.type;
2667 assert(wanted_type->id == TypeTableEntryIdEnum);
2668 TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;
3003 ZigType *wanted_type = instruction->base.value.type;
3004 assert(wanted_type->id == ZigTypeIdEnum);
3005 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
26693006
26703007 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
26713008 LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
......@@ -2690,11 +3027,11 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
26903027}
26913028
26923029static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
2693 TypeTableEntry *wanted_type = instruction->base.value.type;
2694 assert(wanted_type->id == TypeTableEntryIdErrorSet);
3030 ZigType *wanted_type = instruction->base.value.type;
3031 assert(wanted_type->id == ZigTypeIdErrorSet);
26953032
2696 TypeTableEntry *actual_type = instruction->target->value.type;
2697 assert(actual_type->id == TypeTableEntryIdInt);
3033 ZigType *actual_type = instruction->target->value.type;
3034 assert(actual_type->id == ZigTypeIdInt);
26983035 assert(!actual_type->data.integral.is_signed);
26993036
27003037 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
......@@ -2707,17 +3044,17 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
27073044}
27083045
27093046static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
2710 TypeTableEntry *wanted_type = instruction->base.value.type;
2711 assert(wanted_type->id == TypeTableEntryIdInt);
3047 ZigType *wanted_type = instruction->base.value.type;
3048 assert(wanted_type->id == ZigTypeIdInt);
27123049 assert(!wanted_type->data.integral.is_signed);
27133050
2714 TypeTableEntry *actual_type = instruction->target->value.type;
3051 ZigType *actual_type = instruction->target->value.type;
27153052 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
27163053
2717 if (actual_type->id == TypeTableEntryIdErrorSet) {
3054 if (actual_type->id == ZigTypeIdErrorSet) {
27183055 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
27193056 g->err_tag_type, wanted_type, target_val);
2720 } else if (actual_type->id == TypeTableEntryIdErrorUnion) {
3057 } else if (actual_type->id == ZigTypeIdErrorUnion) {
27213058 // this should have been a compile time constant
27223059 assert(type_has_bits(actual_type->data.error_union.err_set_type));
27233060
......@@ -2761,7 +3098,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
27613098static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
27623099 IrUnOp op_id = un_op_instruction->op_id;
27633100 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
2764 TypeTableEntry *expr_type = un_op_instruction->value->value.type;
3101 ZigType *expr_type = un_op_instruction->value->value.type;
27653102
27663103 switch (op_id) {
27673104 case IrUnOpInvalid:
......@@ -2771,10 +3108,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
27713108 case IrUnOpNegation:
27723109 case IrUnOpNegationWrap:
27733110 {
2774 if (expr_type->id == TypeTableEntryIdFloat) {
3111 if (expr_type->id == ZigTypeIdFloat) {
27753112 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
27763113 return LLVMBuildFNeg(g->builder, expr, "");
2777 } else if (expr_type->id == TypeTableEntryIdInt) {
3114 } else if (expr_type->id == ZigTypeIdInt) {
27783115 if (op_id == IrUnOpNegationWrap) {
27793116 return LLVMBuildNeg(g->builder, expr, "");
27803117 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
......@@ -2805,7 +3142,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrI
28053142static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
28063143 IrInstructionDeclVar *decl_var_instruction)
28073144{
2808 VariableTableEntry *var = decl_var_instruction->var;
3145 ZigVar *var = decl_var_instruction->var;
28093146
28103147 if (!type_has_bits(var->value->type))
28113148 return nullptr;
......@@ -2823,13 +3160,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
28233160
28243161 if (have_init_expr) {
28253162 assert(var->value->type == init_value->value.type);
2826 TypeTableEntry *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
3163 ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
28273164 PtrLenSingle, var->align_bytes, 0, 0);
28283165 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
28293166 } else {
28303167 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
28313168 if (want_safe) {
2832 TypeTableEntry *usize = g->builtin_types.entry_usize;
3169 ZigType *usize = g->builtin_types.entry_usize;
28333170 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);
28343171 assert(size_bytes > 0);
28353172
......@@ -2849,13 +3186,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
28493186}
28503187
28513188static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) {
2852 TypeTableEntry *child_type = instruction->base.value.type;
3189 ZigType *child_type = instruction->base.value.type;
28533190 if (!type_has_bits(child_type))
28543191 return nullptr;
28553192
28563193 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
2857 TypeTableEntry *ptr_type = instruction->ptr->value.type;
2858 assert(ptr_type->id == TypeTableEntryIdPointer);
3194 ZigType *ptr_type = instruction->ptr->value.type;
3195 assert(ptr_type->id == ZigTypeIdPointer);
28593196
28603197 uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;
28613198 if (unaligned_bit_count == 0)
......@@ -2880,8 +3217,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
28803217 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
28813218 LLVMValueRef value = ir_llvm_value(g, instruction->value);
28823219
2883 assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);
2884 TypeTableEntry *ptr_type = instruction->ptr->value.type;
3220 assert(instruction->ptr->value.type->id == ZigTypeIdPointer);
3221 ZigType *ptr_type = instruction->ptr->value.type;
28853222
28863223 gen_assign_raw(g, ptr, ptr_type, value);
28873224
......@@ -2889,7 +3226,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
28893226}
28903227
28913228static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
2892 VariableTableEntry *var = instruction->var;
3229 ZigVar *var = instruction->var;
28933230 if (type_has_bits(var->value->type)) {
28943231 assert(var->value_ref);
28953232 return var->value_ref;
......@@ -2900,9 +3237,9 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
29003237
29013238static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
29023239 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
2903 TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type;
2904 assert(array_ptr_type->id == TypeTableEntryIdPointer);
2905 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
3240 ZigType *array_ptr_type = instruction->array_ptr->value.type;
3241 assert(array_ptr_type->id == ZigTypeIdPointer);
3242 ZigType *array_type = array_ptr_type->data.pointer.child_type;
29063243 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
29073244 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
29083245 assert(subscript_value);
......@@ -2912,11 +3249,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29123249
29133250 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
29143251
2915 if (array_type->id == TypeTableEntryIdArray ||
2916 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
3252 if (array_type->id == ZigTypeIdArray ||
3253 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
29173254 {
2918 if (array_type->id == TypeTableEntryIdPointer) {
2919 assert(array_type->data.pointer.child_type->id == TypeTableEntryIdArray);
3255 if (array_type->id == ZigTypeIdPointer) {
3256 assert(array_type->data.pointer.child_type->id == ZigTypeIdArray);
29203257 array_type = array_type->data.pointer.child_type;
29213258 }
29223259 if (safety_check_on) {
......@@ -2927,8 +3264,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29273264 if (array_ptr_type->data.pointer.unaligned_bit_count != 0) {
29283265 return array_ptr_ptr;
29293266 }
2930 TypeTableEntry *child_type = array_type->data.array.child_type;
2931 if (child_type->id == TypeTableEntryIdStruct &&
3267 ZigType *child_type = array_type->data.array.child_type;
3268 if (child_type->id == ZigTypeIdStruct &&
29323269 child_type->data.structure.layout == ContainerLayoutPacked)
29333270 {
29343271 size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;
......@@ -2951,13 +3288,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29513288 subscript_value
29523289 };
29533290 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");
2954 } else if (array_type->id == TypeTableEntryIdPointer) {
3291 } else if (array_type->id == ZigTypeIdPointer) {
29553292 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
29563293 LLVMValueRef indices[] = {
29573294 subscript_value
29583295 };
29593296 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
2960 } else if (array_type->id == TypeTableEntryIdStruct) {
3297 } else if (array_type->id == ZigTypeIdStruct) {
29613298 assert(array_type->data.structure.is_slice);
29623299 if (!type_has_bits(instruction->base.value.type)) {
29633300 if (safety_check_on) {
......@@ -2990,8 +3327,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29903327
29913328static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {
29923329 return g->have_err_ret_tracing &&
2993 (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion ||
2994 fn_type_id->return_type->id == TypeTableEntryIdErrorSet ||
3330 (fn_type_id->return_type->id == ZigTypeIdErrorUnion ||
3331 fn_type_id->return_type->id == ZigTypeIdErrorSet ||
29953332 fn_type_id->cc == CallingConventionAsync);
29963333}
29973334
......@@ -3047,7 +3384,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {
30473384
30483385static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
30493386 LLVMValueRef fn_val;
3050 TypeTableEntry *fn_type;
3387 ZigType *fn_type;
30513388 if (instruction->fn_entry) {
30523389 fn_val = fn_llvm_value(g, instruction->fn_entry);
30533390 fn_type = instruction->fn_entry->type_entry;
......@@ -3059,43 +3396,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
30593396
30603397 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
30613398
3062 TypeTableEntry *src_return_type = fn_type_id->return_type;
3399 ZigType *src_return_type = fn_type_id->return_type;
30633400 bool ret_has_bits = type_has_bits(src_return_type);
30643401
3065 bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) &&
3066 calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc);
3402 CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
3403
3404 bool first_arg_ret = ret_has_bits && want_first_arg_sret(g, fn_type_id);
30673405 bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id);
3068 // +2 for the async args
3069 size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0) + 2;
30703406 bool is_var_args = fn_type_id->is_var_args;
3071 LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
3072 size_t gen_param_index = 0;
3407 ZigList<LLVMValueRef> gen_param_values = {};
30733408 if (first_arg_ret) {
3074 gen_param_values[gen_param_index] = instruction->tmp_ptr;
3075 gen_param_index += 1;
3409 gen_param_values.append(instruction->tmp_ptr);
30763410 }
30773411 if (prefix_arg_err_ret_stack) {
3078 gen_param_values[gen_param_index] = get_cur_err_ret_trace_val(g, instruction->base.scope);
3079 gen_param_index += 1;
3412 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
30803413 }
30813414 if (instruction->is_async) {
3082 gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->async_allocator);
3083 gen_param_index += 1;
3415 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));
30843416
30853417 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");
3086 gen_param_values[gen_param_index] = err_val_ptr;
3087 gen_param_index += 1;
3088 }
3089 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
3090 IrInstruction *param_instruction = instruction->args[call_i];
3091 TypeTableEntry *param_type = param_instruction->value.type;
3092 if (is_var_args || type_has_bits(param_type)) {
3093 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
3094 assert(param_value);
3095 gen_param_values[gen_param_index] = param_value;
3096 gen_param_index += 1;
3097 }
3418 gen_param_values.append(err_val_ptr);
30983419 }
3420 FnWalk fn_walk = {};
3421 fn_walk.id = FnWalkIdCall;
3422 fn_walk.data.call.inst = instruction;
3423 fn_walk.data.call.is_var_args = is_var_args;
3424 fn_walk.data.call.gen_param_values = &gen_param_values;
3425 walk_function_params(g, fn_type, &fn_walk);
30993426
31003427 ZigLLVM_FnInline fn_inline;
31013428 switch (instruction->fn_inline) {
......@@ -3110,12 +3437,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
31103437 break;
31113438 }
31123439
3113 LLVMCallConv llvm_cc = get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc);
3440 LLVMCallConv llvm_cc = get_llvm_cc(g, cc);
31143441 LLVMValueRef result;
31153442
31163443 if (instruction->new_stack == nullptr) {
31173444 result = ZigLLVMBuildCall(g->builder, fn_val,
3118 gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, "");
3445 gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, "");
31193446 } else {
31203447 LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g);
31213448 LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g);
......@@ -3124,7 +3451,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
31243451 LLVMValueRef old_stack_ref = LLVMBuildCall(g->builder, stacksave_fn_val, nullptr, 0, "");
31253452 gen_set_stack_pointer(g, new_stack_addr);
31263453 result = ZigLLVMBuildCall(g->builder, fn_val,
3127 gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, "");
3454 gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, "");
31283455 LLVMBuildCall(g->builder, stackrestore_fn_val, &old_stack_ref, 1, "");
31293456 }
31303457
......@@ -3135,7 +3462,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
31353462 return instruction->tmp_ptr;
31363463 }
31373464
3138 if (src_return_type->id == TypeTableEntryIdUnreachable) {
3465 if (src_return_type->id == ZigTypeIdUnreachable) {
31393466 return LLVMBuildUnreachable(g->builder);
31403467 } else if (!ret_has_bits) {
31413468 return nullptr;
......@@ -3155,14 +3482,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
31553482 IrInstructionStructFieldPtr *instruction)
31563483{
31573484 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
3158 // not necessarily a pointer. could be TypeTableEntryIdStruct
3159 TypeTableEntry *struct_ptr_type = instruction->struct_ptr->value.type;
3485 // not necessarily a pointer. could be ZigTypeIdStruct
3486 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;
31603487 TypeStructField *field = instruction->field;
31613488
31623489 if (!type_has_bits(field->type_entry))
31633490 return nullptr;
31643491
3165 if (struct_ptr_type->id == TypeTableEntryIdPointer &&
3492 if (struct_ptr_type->id == ZigTypeIdPointer &&
31663493 struct_ptr_type->data.pointer.unaligned_bit_count != 0)
31673494 {
31683495 return struct_ptr;
......@@ -3175,10 +3502,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
31753502static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
31763503 IrInstructionUnionFieldPtr *instruction)
31773504{
3178 TypeTableEntry *union_ptr_type = instruction->union_ptr->value.type;
3179 assert(union_ptr_type->id == TypeTableEntryIdPointer);
3180 TypeTableEntry *union_type = union_ptr_type->data.pointer.child_type;
3181 assert(union_type->id == TypeTableEntryIdUnion);
3505 ZigType *union_ptr_type = instruction->union_ptr->value.type;
3506 assert(union_ptr_type->id == ZigTypeIdPointer);
3507 ZigType *union_type = union_ptr_type->data.pointer.child_type;
3508 assert(union_type->id == ZigTypeIdUnion);
31823509
31833510 TypeUnionField *field = instruction->field;
31843511
......@@ -3304,7 +3631,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
33043631 }
33053632
33063633 if (!is_return) {
3307 VariableTableEntry *variable = instruction->output_vars[i];
3634 ZigVar *variable = instruction->output_vars[i];
33083635 assert(variable);
33093636 param_types[param_index] = LLVMTypeOf(variable->value_ref);
33103637 param_values[param_index] = variable->value_ref;
......@@ -3345,9 +3672,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
33453672 return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
33463673}
33473674
3348static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {
3349 assert(maybe_type->id == TypeTableEntryIdOptional);
3350 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
3675static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
3676 assert(maybe_type->id == ZigTypeIdOptional);
3677 ZigType *child_type = maybe_type->data.maybe.child_type;
33513678 if (child_type->zero_bits) {
33523679 return maybe_handle;
33533680 } else {
......@@ -3370,11 +3697,11 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable
33703697static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
33713698 IrInstructionUnwrapOptional *instruction)
33723699{
3373 TypeTableEntry *ptr_type = instruction->value->value.type;
3374 assert(ptr_type->id == TypeTableEntryIdPointer);
3375 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
3376 assert(maybe_type->id == TypeTableEntryIdOptional);
3377 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
3700 ZigType *ptr_type = instruction->value->value.type;
3701 assert(ptr_type->id == ZigTypeIdPointer);
3702 ZigType *maybe_type = ptr_type->data.pointer.child_type;
3703 assert(maybe_type->id == ZigTypeIdOptional);
3704 ZigType *child_type = maybe_type->data.maybe.child_type;
33783705 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
33793706 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
33803707 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
......@@ -3401,7 +3728,7 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
34013728 }
34023729}
34033730
3404static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {
3731static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *int_type, BuiltinFnId fn_id) {
34053732 ZigLLVMFnKey key = {};
34063733 const char *fn_name;
34073734 uint32_t n_args;
......@@ -3444,7 +3771,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
34443771}
34453772
34463773static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
3447 TypeTableEntry *int_type = instruction->value->value.type;
3774 ZigType *int_type = instruction->value->value.type;
34483775 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
34493776 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
34503777 LLVMValueRef params[] {
......@@ -3456,7 +3783,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
34563783}
34573784
34583785static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
3459 TypeTableEntry *int_type = instruction->value->value.type;
3786 ZigType *int_type = instruction->value->value.type;
34603787 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
34613788 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
34623789 LLVMValueRef params[] {
......@@ -3468,7 +3795,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
34683795}
34693796
34703797static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {
3471 TypeTableEntry *int_type = instruction->value->value.type;
3798 ZigType *int_type = instruction->value->value.type;
34723799 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
34733800 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
34743801 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
......@@ -3545,15 +3872,15 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
35453872 return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, "");
35463873}
35473874
3548static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_type) {
3549 assert(enum_type->id == TypeTableEntryIdEnum);
3875static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
3876 assert(enum_type->id == ZigTypeIdEnum);
35503877 if (enum_type->data.enumeration.name_function)
35513878 return enum_type->data.enumeration.name_function;
35523879
3553 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
3880 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
35543881 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
3555 TypeTableEntry *u8_slice_type = get_slice_type(g, u8_ptr_type);
3556 TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
3882 ZigType *u8_slice_type = get_slice_type(g, u8_ptr_type);
3883 ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
35573884
35583885 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0),
35593886 &tag_int_type->type_ref, 1, false);
......@@ -3571,7 +3898,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
35713898
35723899 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
35733900 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
3574 FnTableEntry *prev_cur_fn = g->cur_fn;
3901 ZigFn *prev_cur_fn = g->cur_fn;
35753902 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
35763903
35773904 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
......@@ -3586,7 +3913,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
35863913 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, tag_int_value, bad_value_block, field_count);
35873914
35883915
3589 TypeTableEntry *usize = g->builtin_types.entry_usize;
3916 ZigType *usize = g->builtin_types.entry_usize;
35903917 LLVMValueRef array_ptr_indices[] = {
35913918 LLVMConstNull(usize->type_ref),
35923919 LLVMConstNull(usize->type_ref),
......@@ -3643,8 +3970,8 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
36433970static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
36443971 IrInstructionTagName *instruction)
36453972{
3646 TypeTableEntry *enum_type = instruction->target->value.type;
3647 assert(enum_type->id == TypeTableEntryIdEnum);
3973 ZigType *enum_type = instruction->target->value.type;
3974 assert(enum_type->id == ZigTypeIdEnum);
36483975
36493976 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);
36503977
......@@ -3656,10 +3983,10 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
36563983static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
36573984 IrInstructionFieldParentPtr *instruction)
36583985{
3659 TypeTableEntry *container_ptr_type = instruction->base.value.type;
3660 assert(container_ptr_type->id == TypeTableEntryIdPointer);
3986 ZigType *container_ptr_type = instruction->base.value.type;
3987 assert(container_ptr_type->id == ZigTypeIdPointer);
36613988
3662 TypeTableEntry *container_type = container_ptr_type->data.pointer.child_type;
3989 ZigType *container_type = container_ptr_type->data.pointer.child_type;
36633990
36643991 size_t byte_offset = LLVMOffsetOfElement(g->target_data_ref,
36653992 container_type->type_ref, instruction->field->gen_index);
......@@ -3669,7 +3996,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
36693996 if (byte_offset == 0) {
36703997 return LLVMBuildBitCast(g->builder, field_ptr_val, container_ptr_type->type_ref, "");
36713998 } else {
3672 TypeTableEntry *usize = g->builtin_types.entry_usize;
3999 ZigType *usize = g->builtin_types.entry_usize;
36734000
36744001 LLVMValueRef field_ptr_int = LLVMBuildPtrToInt(g->builder, field_ptr_val,
36754002 usize->type_ref, "");
......@@ -3690,32 +4017,32 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
36904017 return target_val;
36914018 }
36924019
3693 TypeTableEntry *target_type = instruction->base.value.type;
4020 ZigType *target_type = instruction->base.value.type;
36944021 uint32_t align_bytes;
36954022 LLVMValueRef ptr_val;
36964023
3697 if (target_type->id == TypeTableEntryIdPointer) {
4024 if (target_type->id == ZigTypeIdPointer) {
36984025 align_bytes = target_type->data.pointer.alignment;
36994026 ptr_val = target_val;
3700 } else if (target_type->id == TypeTableEntryIdFn) {
4027 } else if (target_type->id == ZigTypeIdFn) {
37014028 align_bytes = target_type->data.fn.fn_type_id.alignment;
37024029 ptr_val = target_val;
3703 } else if (target_type->id == TypeTableEntryIdOptional &&
3704 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
4030 } else if (target_type->id == ZigTypeIdOptional &&
4031 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
37054032 {
37064033 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
37074034 ptr_val = target_val;
3708 } else if (target_type->id == TypeTableEntryIdOptional &&
3709 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
4035 } else if (target_type->id == ZigTypeIdOptional &&
4036 target_type->data.maybe.child_type->id == ZigTypeIdFn)
37104037 {
37114038 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
37124039 ptr_val = target_val;
3713 } else if (target_type->id == TypeTableEntryIdOptional &&
3714 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)
4040 } else if (target_type->id == ZigTypeIdOptional &&
4041 target_type->data.maybe.child_type->id == ZigTypeIdPromise)
37154042 {
37164043 zig_panic("TODO audit this function");
3717 } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) {
3718 TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
4044 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
4045 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
37194046 align_bytes = slice_ptr_type->data.pointer.alignment;
37204047
37214048 size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index;
......@@ -3727,7 +4054,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
37274054
37284055 assert(align_bytes != 1);
37294056
3730 TypeTableEntry *usize = g->builtin_types.entry_usize;
4057 ZigType *usize = g->builtin_types.entry_usize;
37314058 LLVMValueRef ptr_as_int_val = LLVMBuildPtrToInt(g->builder, ptr_val, usize->type_ref, "");
37324059 LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->type_ref, align_bytes - 1, false);
37334060 LLVMValueRef anded_val = LLVMBuildAnd(g->builder, ptr_as_int_val, alignment_minus_1, "");
......@@ -3751,7 +4078,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
37514078{
37524079 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope);
37534080 if (cur_err_ret_trace_val == nullptr) {
3754 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
4081 ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
37554082 return LLVMConstNull(ptr_to_stack_trace_type->type_ref);
37564083 }
37574084 return cur_err_ret_trace_val;
......@@ -3811,9 +4138,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
38114138 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
38124139 success_order, failure_order, instruction->is_weak);
38134140
3814 TypeTableEntry *maybe_type = instruction->base.value.type;
3815 assert(maybe_type->id == TypeTableEntryIdOptional);
3816 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
4141 ZigType *maybe_type = instruction->base.value.type;
4142 assert(maybe_type->id == ZigTypeIdOptional);
4143 ZigType *child_type = maybe_type->data.maybe.child_type;
38174144
38184145 if (type_is_codegen_pointer(child_type)) {
38194146 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
......@@ -3843,8 +4170,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst
38434170
38444171static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
38454172 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3846 TypeTableEntry *dest_type = instruction->base.value.type;
3847 TypeTableEntry *src_type = instruction->target->value.type;
4173 ZigType *dest_type = instruction->base.value.type;
4174 ZigType *src_type = instruction->target->value.type;
38484175 if (dest_type == src_type) {
38494176 // no-op
38504177 return target_val;
......@@ -3865,8 +4192,8 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
38654192
38664193 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
38674194
3868 TypeTableEntry *ptr_type = instruction->dest_ptr->value.type;
3869 assert(ptr_type->id == TypeTableEntryIdPointer);
4195 ZigType *ptr_type = instruction->dest_ptr->value.type;
4196 assert(ptr_type->id == ZigTypeIdPointer);
38704197
38714198 ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, char_val, len_val, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
38724199 return nullptr;
......@@ -3882,11 +4209,11 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
38824209 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
38834210 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
38844211
3885 TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type;
3886 TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type;
4212 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;
4213 ZigType *src_ptr_type = instruction->src_ptr->value.type;
38874214
3888 assert(dest_ptr_type->id == TypeTableEntryIdPointer);
3889 assert(src_ptr_type->id == TypeTableEntryIdPointer);
4215 assert(dest_ptr_type->id == ZigTypeIdPointer);
4216 assert(src_ptr_type->id == ZigTypeIdPointer);
38904217
38914218 bool is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile);
38924219
......@@ -3899,19 +4226,19 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
38994226 assert(instruction->tmp_ptr);
39004227
39014228 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
3902 TypeTableEntry *array_ptr_type = instruction->ptr->value.type;
3903 assert(array_ptr_type->id == TypeTableEntryIdPointer);
3904 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
4229 ZigType *array_ptr_type = instruction->ptr->value.type;
4230 assert(array_ptr_type->id == ZigTypeIdPointer);
4231 ZigType *array_type = array_ptr_type->data.pointer.child_type;
39054232 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
39064233
39074234 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
39084235
39094236 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
39104237
3911 if (array_type->id == TypeTableEntryIdArray ||
3912 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
4238 if (array_type->id == ZigTypeIdArray ||
4239 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
39134240 {
3914 if (array_type->id == TypeTableEntryIdPointer) {
4241 if (array_type->id == ZigTypeIdPointer) {
39154242 array_type = array_type->data.pointer.child_type;
39164243 }
39174244 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
......@@ -3952,7 +4279,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
39524279 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
39534280
39544281 return tmp_struct_ptr;
3955 } else if (array_type->id == TypeTableEntryIdPointer) {
4282 } else if (array_type->id == ZigTypeIdPointer) {
39564283 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
39574284 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
39584285 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
......@@ -3974,7 +4301,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
39744301 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
39754302
39764303 return tmp_struct_ptr;
3977 } else if (array_type->id == TypeTableEntryIdStruct) {
4304 } else if (array_type->id == ZigTypeIdStruct) {
39784305 assert(array_type->data.structure.is_slice);
39794306 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
39804307 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
......@@ -4050,7 +4377,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
40504377 if (g->frame_address_fn_val)
40514378 return g->frame_address_fn_val;
40524379
4053 TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
4380 ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
40544381
40554382 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
40564383 &g->builtin_types.entry_i32->type_ref, 1, false);
......@@ -4088,8 +4415,8 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
40884415}
40894416
40904417static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
4091 TypeTableEntry *int_type = instruction->result_ptr_type;
4092 assert(int_type->id == TypeTableEntryIdInt);
4418 ZigType *int_type = instruction->result_ptr_type;
4419 assert(int_type->id == ZigTypeIdInt);
40934420
40944421 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
40954422 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
......@@ -4128,8 +4455,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
41284455 return render_shl_with_overflow(g, instruction);
41294456 }
41304457
4131 TypeTableEntry *int_type = instruction->result_ptr_type;
4132 assert(int_type->id == TypeTableEntryIdInt);
4458 ZigType *int_type = instruction->result_ptr_type;
4459 assert(int_type->id == ZigTypeIdInt);
41334460
41344461 LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);
41354462
......@@ -4151,8 +4478,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
41514478}
41524479
41534480static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {
4154 TypeTableEntry *err_union_type = instruction->value->value.type;
4155 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
4481 ZigType *err_union_type = instruction->value->value.type;
4482 ZigType *payload_type = err_union_type->data.error_union.payload_type;
41564483 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);
41574484
41584485 LLVMValueRef err_val;
......@@ -4168,10 +4495,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
41684495}
41694496
41704497static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
4171 TypeTableEntry *ptr_type = instruction->value->value.type;
4172 assert(ptr_type->id == TypeTableEntryIdPointer);
4173 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
4174 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
4498 ZigType *ptr_type = instruction->value->value.type;
4499 assert(ptr_type->id == ZigTypeIdPointer);
4500 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4501 ZigType *payload_type = err_union_type->data.error_union.payload_type;
41754502 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
41764503 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
41774504
......@@ -4184,10 +4511,10 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
41844511}
41854512
41864513static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
4187 TypeTableEntry *ptr_type = instruction->value->value.type;
4188 assert(ptr_type->id == TypeTableEntryIdPointer);
4189 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
4190 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
4514 ZigType *ptr_type = instruction->value->value.type;
4515 assert(ptr_type->id == ZigTypeIdPointer);
4516 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4517 ZigType *payload_type = err_union_type->data.error_union.payload_type;
41914518 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
41924519 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
41934520
......@@ -4223,11 +4550,11 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
42234550}
42244551
42254552static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
4226 TypeTableEntry *wanted_type = instruction->base.value.type;
4553 ZigType *wanted_type = instruction->base.value.type;
42274554
4228 assert(wanted_type->id == TypeTableEntryIdOptional);
4555 assert(wanted_type->id == ZigTypeIdOptional);
42294556
4230 TypeTableEntry *child_type = wanted_type->data.maybe.child_type;
4557 ZigType *child_type = wanted_type->data.maybe.child_type;
42314558
42324559 if (child_type->zero_bits) {
42334560 return LLVMConstInt(LLVMInt1Type(), 1, false);
......@@ -4250,12 +4577,12 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
42504577}
42514578
42524579static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
4253 TypeTableEntry *wanted_type = instruction->base.value.type;
4580 ZigType *wanted_type = instruction->base.value.type;
42544581
4255 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
4582 assert(wanted_type->id == ZigTypeIdErrorUnion);
42564583
4257 TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
4258 TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;
4584 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4585 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
42594586
42604587 LLVMValueRef err_val = ir_llvm_value(g, instruction->value);
42614588
......@@ -4271,12 +4598,12 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
42714598}
42724599
42734600static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
4274 TypeTableEntry *wanted_type = instruction->base.value.type;
4601 ZigType *wanted_type = instruction->base.value.type;
42754602
4276 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
4603 assert(wanted_type->id == ZigTypeIdErrorUnion);
42774604
4278 TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
4279 TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;
4605 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4606 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
42804607
42814608 if (!type_has_bits(err_set_type)) {
42824609 return ir_llvm_value(g, instruction->value);
......@@ -4301,10 +4628,10 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
43014628}
43024629
43034630static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
4304 TypeTableEntry *union_type = instruction->value->value.type;
4631 ZigType *union_type = instruction->value->value.type;
43054632 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
43064633
4307 TypeTableEntry *tag_type = union_type->data.unionation.tag_type;
4634 ZigType *tag_type = union_type->data.unionation.tag_type;
43084635 if (!type_has_bits(tag_type))
43094636 return nullptr;
43104637
......@@ -4314,7 +4641,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
43144641
43154642 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
43164643 union_type->data.unionation.gen_tag_index, "");
4317 TypeTableEntry *ptr_type = get_pointer_to_type(g, tag_type, false);
4644 ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);
43184645 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
43194646}
43204647
......@@ -4331,7 +4658,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
43314658
43324659 uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry);
43334660
4334 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
4661 ZigType *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
43354662 false, false, PtrLenSingle, field_align_bytes,
43364663 (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);
43374664
......@@ -4347,14 +4674,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
43474674 return nullptr;
43484675
43494676 uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);
4350 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
4677 ZigType *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
43514678 false, false, PtrLenSingle, field_align_bytes,
43524679 0, 0);
43534680
43544681 LLVMValueRef uncasted_union_ptr;
43554682 // Even if safety is off in this block, if the union type has the safety field, we have to populate it
43564683 // correctly. Otherwise safety code somewhere other than here could fail.
4357 TypeTableEntry *union_type = instruction->union_type;
4684 ZigType *union_type = instruction->union_type;
43584685 if (union_type->data.unionation.gen_tag_index != SIZE_MAX) {
43594686 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
43604687 union_type->data.unionation.gen_tag_index, "");
......@@ -4380,14 +4707,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
43804707static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable,
43814708 IrInstructionContainerInitList *instruction)
43824709{
4383 TypeTableEntry *array_type = instruction->base.value.type;
4384 assert(array_type->id == TypeTableEntryIdArray);
4710 ZigType *array_type = instruction->base.value.type;
4711 assert(array_type->id == ZigTypeIdArray);
43854712 LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;
43864713 assert(tmp_array_ptr);
43874714
43884715 size_t field_count = instruction->item_count;
43894716
4390 TypeTableEntry *child_type = array_type->data.array.child_type;
4717 ZigType *child_type = array_type->data.array.child_type;
43914718 for (size_t i = 0; i < field_count; i += 1) {
43924719 LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]);
43934720 LLVMValueRef indices[] = {
......@@ -4511,13 +4838,13 @@ static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable,
45114838 return LLVMBuildBitCast(g->builder, uncasted_result, instruction->base.value.type->type_ref, "");
45124839}
45134840
4514static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, TypeTableEntry *fn_type) {
4841static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, ZigType *fn_type) {
45154842 if (g->coro_alloc_helper_fn_val != nullptr)
45164843 return g->coro_alloc_helper_fn_val;
45174844
4518 assert(fn_type->id == TypeTableEntryIdFn);
4845 assert(fn_type->id == ZigTypeIdFn);
45194846
4520 TypeTableEntry *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
4847 ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
45214848
45224849 LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref);
45234850 LLVMTypeRef *alloc_fn_arg_types = allocate<LLVMTypeRef>(LLVMCountParamTypes(alloc_raw_fn_type_ref));
......@@ -4545,7 +4872,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
45454872
45464873 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
45474874 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
4548 FnTableEntry *prev_cur_fn = g->cur_fn;
4875 ZigFn *prev_cur_fn = g->cur_fn;
45494876 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
45504877
45514878 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
......@@ -4596,9 +4923,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
45964923
45974924 LLVMPositionBuilderAtEnd(g->builder, ok_block);
45984925 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");
4599 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
4926 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
46004927 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
4601 TypeTableEntry *slice_type = get_slice_type(g, u8_ptr_type);
4928 ZigType *slice_type = get_slice_type(g, u8_ptr_type);
46024929 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
46034930 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
46044931 LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, "");
......@@ -4643,8 +4970,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
46434970 IrInstructionAtomicRmw *instruction)
46444971{
46454972 bool is_signed;
4646 TypeTableEntry *operand_type = instruction->operand->value.type;
4647 if (operand_type->id == TypeTableEntryIdInt) {
4973 ZigType *operand_type = instruction->operand->value.type;
4974 if (operand_type->id == ZigTypeIdInt) {
46484975 is_signed = operand_type->data.integral.is_signed;
46494976 } else {
46504977 is_signed = false;
......@@ -4699,7 +5026,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e
46995026
47005027static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {
47015028 LLVMValueRef op = ir_llvm_value(g, instruction->op);
4702 assert(instruction->base.value.type->id == TypeTableEntryIdFloat);
5029 assert(instruction->base.value.type->id == ZigTypeIdFloat);
47035030 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);
47045031 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
47055032}
......@@ -4780,6 +5107,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
47805107 case IrInstructionIdFromBytes:
47815108 case IrInstructionIdToBytes:
47825109 case IrInstructionIdEnumToInt:
5110 case IrInstructionIdCheckRuntimeScope:
47835111 zig_unreachable();
47845112
47855113 case IrInstructionIdReturn:
......@@ -4946,7 +5274,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
49465274 zig_unreachable();
49475275}
49485276
4949static void ir_render(CodeGen *g, FnTableEntry *fn_entry) {
5277static void ir_render(CodeGen *g, ZigFn *fn_entry) {
49505278 assert(fn_entry);
49515279
49525280 IrExecutable *executable = &fn_entry->analyzed_executable;
......@@ -4999,14 +5327,14 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
49995327
50005328 LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr)));
50015329 if (el_type == LLVMArrayTypeKind) {
5002 TypeTableEntry *usize = g->builtin_types.entry_usize;
5330 ZigType *usize = g->builtin_types.entry_usize;
50035331 LLVMValueRef indices[] = {
50045332 LLVMConstNull(usize->type_ref),
50055333 LLVMConstInt(usize->type_ref, index, false),
50065334 };
50075335 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
50085336 } else if (el_type == LLVMStructTypeKind) {
5009 TypeTableEntry *u32 = g->builtin_types.entry_u32;
5337 ZigType *u32 = g->builtin_types.entry_u32;
50105338 LLVMValueRef indices[] = {
50115339 LLVMConstNull(u32->type_ref),
50125340 LLVMConstInt(u32->type_ref, index, false),
......@@ -5022,7 +5350,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s
50225350 ConstParent *parent = &struct_const_val->data.x_struct.parent;
50235351 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);
50245352
5025 TypeTableEntry *u32 = g->builtin_types.entry_u32;
5353 ZigType *u32 = g->builtin_types.entry_u32;
50265354 LLVMValueRef indices[] = {
50275355 LLVMConstNull(u32->type_ref),
50285356 LLVMConstInt(u32->type_ref, field_index, false),
......@@ -5034,7 +5362,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
50345362 ConstParent *parent = &union_const_val->data.x_union.parent;
50355363 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);
50365364
5037 TypeTableEntry *u32 = g->builtin_types.entry_u32;
5365 ZigType *u32 = g->builtin_types.entry_u32;
50385366 LLVMValueRef indices[] = {
50395367 LLVMConstNull(u32->type_ref),
50405368 LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload
......@@ -5052,59 +5380,59 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
50525380 break;
50535381 }
50545382
5055 TypeTableEntry *type_entry = const_val->type;
5383 ZigType *type_entry = const_val->type;
50565384 assert(!type_entry->zero_bits);
50575385 switch (type_entry->id) {
5058 case TypeTableEntryIdInvalid:
5059 case TypeTableEntryIdMetaType:
5060 case TypeTableEntryIdUnreachable:
5061 case TypeTableEntryIdComptimeFloat:
5062 case TypeTableEntryIdComptimeInt:
5063 case TypeTableEntryIdUndefined:
5064 case TypeTableEntryIdNull:
5065 case TypeTableEntryIdErrorUnion:
5066 case TypeTableEntryIdErrorSet:
5067 case TypeTableEntryIdNamespace:
5068 case TypeTableEntryIdBlock:
5069 case TypeTableEntryIdBoundFn:
5070 case TypeTableEntryIdArgTuple:
5071 case TypeTableEntryIdVoid:
5072 case TypeTableEntryIdOpaque:
5386 case ZigTypeIdInvalid:
5387 case ZigTypeIdMetaType:
5388 case ZigTypeIdUnreachable:
5389 case ZigTypeIdComptimeFloat:
5390 case ZigTypeIdComptimeInt:
5391 case ZigTypeIdUndefined:
5392 case ZigTypeIdNull:
5393 case ZigTypeIdErrorUnion:
5394 case ZigTypeIdErrorSet:
5395 case ZigTypeIdNamespace:
5396 case ZigTypeIdBlock:
5397 case ZigTypeIdBoundFn:
5398 case ZigTypeIdArgTuple:
5399 case ZigTypeIdVoid:
5400 case ZigTypeIdOpaque:
50735401 zig_unreachable();
5074 case TypeTableEntryIdBool:
5402 case ZigTypeIdBool:
50755403 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);
5076 case TypeTableEntryIdEnum:
5404 case ZigTypeIdEnum:
50775405 {
50785406 assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);
50795407 LLVMValueRef int_val = gen_const_val(g, const_val, "");
50805408 return LLVMConstZExt(int_val, big_int_type_ref);
50815409 }
5082 case TypeTableEntryIdInt:
5410 case ZigTypeIdInt:
50835411 {
50845412 LLVMValueRef int_val = gen_const_val(g, const_val, "");
50855413 return LLVMConstZExt(int_val, big_int_type_ref);
50865414 }
5087 case TypeTableEntryIdFloat:
5415 case ZigTypeIdFloat:
50885416 {
50895417 LLVMValueRef float_val = gen_const_val(g, const_val, "");
50905418 LLVMValueRef int_val = LLVMConstFPToUI(float_val,
50915419 LLVMIntType((unsigned)type_entry->data.floating.bit_count));
50925420 return LLVMConstZExt(int_val, big_int_type_ref);
50935421 }
5094 case TypeTableEntryIdPointer:
5095 case TypeTableEntryIdFn:
5096 case TypeTableEntryIdOptional:
5097 case TypeTableEntryIdPromise:
5422 case ZigTypeIdPointer:
5423 case ZigTypeIdFn:
5424 case ZigTypeIdOptional:
5425 case ZigTypeIdPromise:
50985426 {
50995427 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
51005428 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);
51015429 return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);
51025430 }
5103 case TypeTableEntryIdArray:
5431 case ZigTypeIdArray:
51045432 zig_panic("TODO bit pack an array");
5105 case TypeTableEntryIdUnion:
5433 case ZigTypeIdUnion:
51065434 zig_panic("TODO bit pack a union");
5107 case TypeTableEntryIdStruct:
5435 case ZigTypeIdStruct:
51085436 {
51095437 assert(type_entry->data.structure.layout == ContainerLayoutPacked);
51105438 bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type
......@@ -5137,7 +5465,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
51375465
51385466// We have this because union constants can't be represented by the official union type,
51395467// and this property bubbles up in whatever aggregate type contains a union constant
5140static bool is_llvm_value_unnamed_type(TypeTableEntry *type_entry, LLVMValueRef val) {
5468static bool is_llvm_value_unnamed_type(ZigType *type_entry, LLVMValueRef val) {
51415469 return LLVMTypeOf(val) != type_entry->type_ref;
51425470}
51435471
......@@ -5162,10 +5490,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
51625490 render_const_val_global(g, const_val, name);
51635491 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
51645492 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
5165 assert(array_const_val->type->id == TypeTableEntryIdArray);
5493 assert(array_const_val->type->id == ZigTypeIdArray);
51665494 if (array_const_val->type->zero_bits) {
51675495 // make this a null pointer
5168 TypeTableEntry *usize = g->builtin_types.entry_usize;
5496 ZigType *usize = g->builtin_types.entry_usize;
51695497 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
51705498 const_val->type->type_ref);
51715499 render_const_val_global(g, const_val, "");
......@@ -5182,10 +5510,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
51825510 {
51835511 render_const_val_global(g, const_val, name);
51845512 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
5185 assert(struct_const_val->type->id == TypeTableEntryIdStruct);
5513 assert(struct_const_val->type->id == ZigTypeIdStruct);
51865514 if (struct_const_val->type->zero_bits) {
51875515 // make this a null pointer
5188 TypeTableEntry *usize = g->builtin_types.entry_usize;
5516 ZigType *usize = g->builtin_types.entry_usize;
51895517 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
51905518 const_val->type->type_ref);
51915519 render_const_val_global(g, const_val, "");
......@@ -5205,7 +5533,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
52055533 {
52065534 render_const_val_global(g, const_val, name);
52075535 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;
5208 TypeTableEntry *usize = g->builtin_types.entry_usize;
5536 ZigType *usize = g->builtin_types.entry_usize;
52095537 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, addr_value, false),
52105538 const_val->type->type_ref);
52115539 render_const_val_global(g, const_val, "");
......@@ -5218,7 +5546,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
52185546}
52195547
52205548static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {
5221 TypeTableEntry *type_entry = const_val->type;
5549 ZigType *type_entry = const_val->type;
52225550 assert(!type_entry->zero_bits);
52235551
52245552 switch (const_val->special) {
......@@ -5231,13 +5559,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
52315559 }
52325560
52335561 switch (type_entry->id) {
5234 case TypeTableEntryIdInt:
5562 case ZigTypeIdInt:
52355563 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);
5236 case TypeTableEntryIdErrorSet:
5564 case ZigTypeIdErrorSet:
52375565 assert(const_val->data.x_err_set != nullptr);
52385566 return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,
52395567 const_val->data.x_err_set->value, false);
5240 case TypeTableEntryIdFloat:
5568 case ZigTypeIdFloat:
52415569 switch (type_entry->data.floating.bit_count) {
52425570 case 16:
52435571 return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16));
......@@ -5257,15 +5585,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
52575585 default:
52585586 zig_unreachable();
52595587 }
5260 case TypeTableEntryIdBool:
5588 case ZigTypeIdBool:
52615589 if (const_val->data.x_bool) {
52625590 return LLVMConstAllOnes(LLVMInt1Type());
52635591 } else {
52645592 return LLVMConstNull(LLVMInt1Type());
52655593 }
5266 case TypeTableEntryIdOptional:
5594 case ZigTypeIdOptional:
52675595 {
5268 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
5596 ZigType *child_type = type_entry->data.maybe.child_type;
52695597 if (child_type->zero_bits) {
52705598 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
52715599 } else if (type_is_codegen_pointer(child_type)) {
......@@ -5296,7 +5624,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
52965624 }
52975625 }
52985626 }
5299 case TypeTableEntryIdStruct:
5627 case ZigTypeIdStruct:
53005628 {
53015629 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
53025630 size_t src_field_count = type_entry->data.structure.src_field_count;
......@@ -5372,7 +5700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
53725700 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);
53735701 }
53745702 }
5375 case TypeTableEntryIdArray:
5703 case ZigTypeIdArray:
53765704 {
53775705 uint64_t len = type_entry->data.array.len;
53785706 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
......@@ -5394,12 +5722,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
53945722 return LLVMConstArray(element_type_ref, values, (unsigned)len);
53955723 }
53965724 }
5397 case TypeTableEntryIdUnion:
5725 case ZigTypeIdUnion:
53985726 {
53995727 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
54005728
54015729 if (type_entry->data.unionation.gen_field_count == 0) {
5402 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) {
5730 if (type_entry->data.unionation.tag_type == nullptr) {
54035731 return nullptr;
54045732 } else {
54055733 return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref,
......@@ -5458,18 +5786,18 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
54585786
54595787 }
54605788
5461 case TypeTableEntryIdEnum:
5789 case ZigTypeIdEnum:
54625790 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);
5463 case TypeTableEntryIdFn:
5791 case ZigTypeIdFn:
54645792 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
54655793 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
54665794 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
5467 case TypeTableEntryIdPointer:
5795 case ZigTypeIdPointer:
54685796 return gen_const_val_ptr(g, const_val, name);
5469 case TypeTableEntryIdErrorUnion:
5797 case ZigTypeIdErrorUnion:
54705798 {
5471 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
5472 TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;
5799 ZigType *payload_type = type_entry->data.error_union.payload_type;
5800 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
54735801 if (!type_has_bits(payload_type)) {
54745802 assert(type_has_bits(err_set_type));
54755803 uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0;
......@@ -5502,21 +5830,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
55025830 }
55035831 }
55045832 }
5505 case TypeTableEntryIdVoid:
5833 case ZigTypeIdVoid:
55065834 return nullptr;
5507 case TypeTableEntryIdInvalid:
5508 case TypeTableEntryIdMetaType:
5509 case TypeTableEntryIdUnreachable:
5510 case TypeTableEntryIdComptimeFloat:
5511 case TypeTableEntryIdComptimeInt:
5512 case TypeTableEntryIdUndefined:
5513 case TypeTableEntryIdNull:
5514 case TypeTableEntryIdNamespace:
5515 case TypeTableEntryIdBlock:
5516 case TypeTableEntryIdBoundFn:
5517 case TypeTableEntryIdArgTuple:
5518 case TypeTableEntryIdOpaque:
5519 case TypeTableEntryIdPromise:
5835 case ZigTypeIdInvalid:
5836 case ZigTypeIdMetaType:
5837 case ZigTypeIdUnreachable:
5838 case ZigTypeIdComptimeFloat:
5839 case ZigTypeIdComptimeInt:
5840 case ZigTypeIdUndefined:
5841 case ZigTypeIdNull:
5842 case ZigTypeIdNamespace:
5843 case ZigTypeIdBlock:
5844 case ZigTypeIdBoundFn:
5845 case ZigTypeIdArgTuple:
5846 case ZigTypeIdOpaque:
5847 case ZigTypeIdPromise:
55205848 zig_unreachable();
55215849
55225850 }
......@@ -5559,9 +5887,9 @@ static void generate_error_name_table(CodeGen *g) {
55595887
55605888 assert(g->errors_by_index.length > 0);
55615889
5562 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5890 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
55635891 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
5564 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
5892 ZigType *str_type = get_slice_type(g, u8_ptr_type);
55655893
55665894 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
55675895 values[0] = LLVMGetUndef(str_type->type_ref);
......@@ -5597,7 +5925,7 @@ static void generate_error_name_table(CodeGen *g) {
55975925 LLVMSetAlignment(g->err_name_table, LLVMABIAlignmentOfType(g->target_data_ref, LLVMTypeOf(err_name_table_init)));
55985926}
55995927
5600static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
5928static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
56015929 IrExecutable *executable = &fn->analyzed_executable;
56025930 assert(executable->basic_block_list.length > 0);
56035931 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
......@@ -5608,8 +5936,8 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
56085936 LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);
56095937}
56105938
5611static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,
5612 TypeTableEntry *type_entry)
5939static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
5940 ZigType *type_entry)
56135941{
56145942 if (g->strip_debug_symbols) {
56155943 return;
......@@ -5630,33 +5958,16 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
56305958 // TODO ^^ make an actual global variable
56315959}
56325960
5633static LLVMValueRef build_alloca(CodeGen *g, TypeTableEntry *type_entry, const char *name, uint32_t alignment) {
5634 assert(alignment > 0);
5635 LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name);
5636 LLVMSetAlignment(result, alignment);
5637 return result;
5638}
5639
56405961static void ensure_cache_dir(CodeGen *g) {
56415962 int err;
5642 if ((err = os_make_path(g->cache_dir))) {
5963 if ((err = os_make_path(&g->cache_dir))) {
56435964 zig_panic("unable to make cache dir: %s", err_str(err));
56445965 }
56455966}
56465967
5647static void report_errors_and_maybe_exit(CodeGen *g) {
5648 if (g->errors.length != 0) {
5649 for (size_t i = 0; i < g->errors.length; i += 1) {
5650 ErrorMsg *err = g->errors.at(i);
5651 print_err_msg(err, g->err_color);
5652 }
5653 exit(1);
5654 }
5655}
5656
56575968static void validate_inline_fns(CodeGen *g) {
56585969 for (size_t i = 0; i < g->inline_fns.length; i += 1) {
5659 FnTableEntry *fn_entry = g->inline_fns.at(i);
5970 ZigFn *fn_entry = g->inline_fns.at(i);
56605971 LLVMValueRef fn_val = LLVMGetNamedFunction(g->module, fn_entry->llvm_name);
56615972 if (fn_val != nullptr) {
56625973 add_node_error(g, fn_entry->proto_node, buf_sprintf("unable to inline function"));
......@@ -5697,13 +6008,13 @@ static void do_code_gen(CodeGen *g) {
56976008 // Generate module level variables
56986009 for (size_t i = 0; i < g->global_vars.length; i += 1) {
56996010 TldVar *tld_var = g->global_vars.at(i);
5700 VariableTableEntry *var = tld_var->var;
6011 ZigVar *var = tld_var->var;
57016012
5702 if (var->value->type->id == TypeTableEntryIdComptimeFloat) {
6013 if (var->value->type->id == ZigTypeIdComptimeFloat) {
57036014 // Generate debug info for it but that's it.
57046015 ConstExprValue *const_val = var->value;
57056016 assert(const_val->special != ConstValSpecialRuntime);
5706 TypeTableEntry *var_type = g->builtin_types.entry_f128;
6017 ZigType *var_type = g->builtin_types.entry_f128;
57076018 ConstExprValue coerced_value;
57086019 coerced_value.special = ConstValSpecialStatic;
57096020 coerced_value.type = var_type;
......@@ -5713,7 +6024,7 @@ static void do_code_gen(CodeGen *g) {
57136024 continue;
57146025 }
57156026
5716 if (var->value->type->id == TypeTableEntryIdComptimeInt) {
6027 if (var->value->type->id == ZigTypeIdComptimeInt) {
57176028 // Generate debug info for it but that's it.
57186029 ConstExprValue *const_val = var->value;
57196030 assert(const_val->special != ConstValSpecialRuntime);
......@@ -5721,7 +6032,7 @@ static void do_code_gen(CodeGen *g) {
57216032 if (bits_needed < 8) {
57226033 bits_needed = 8;
57236034 }
5724 TypeTableEntry *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed);
6035 ZigType *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed);
57256036 LLVMValueRef init_val = bigint_to_llvm_const(var_type->type_ref, &const_val->data.x_bigint);
57266037 gen_global_var(g, var, init_val, var_type);
57276038 continue;
......@@ -5761,7 +6072,7 @@ static void do_code_gen(CodeGen *g) {
57616072 LLVMSetAlignment(global_value, var->align_bytes);
57626073
57636074 // TODO debug info for function pointers
5764 if (var->gen_is_const && var->value->type->id != TypeTableEntryIdFn) {
6075 if (var->gen_is_const && var->value->type->id != ZigTypeIdFn) {
57656076 gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);
57666077 }
57676078
......@@ -5773,12 +6084,15 @@ static void do_code_gen(CodeGen *g) {
57736084
57746085 // Generate function definitions.
57756086 for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
5776 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);
6087 ZigFn *fn_table_entry = g->fn_defs.at(fn_i);
6088 FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
6089 CallingConvention cc = fn_type_id->cc;
6090 bool is_c_abi = cc == CallingConventionC;
57776091
57786092 LLVMValueRef fn = fn_llvm_value(g, fn_table_entry);
57796093 g->cur_fn = fn_table_entry;
57806094 g->cur_fn_val = fn;
5781 TypeTableEntry *return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type;
6095 ZigType *return_type = fn_type_id->return_type;
57826096 if (handle_is_ptr(return_type)) {
57836097 g->cur_ret_ptr = LLVMGetParam(fn, 0);
57846098 } else {
......@@ -5797,11 +6111,11 @@ static void do_code_gen(CodeGen *g) {
57976111 }
57986112
57996113 // error return tracing setup
5800 bool is_async = fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
6114 bool is_async = cc == CallingConventionAsync;
58016115 bool have_err_ret_trace_stack = g->have_err_ret_tracing && fn_table_entry->calls_or_awaits_errorable_fn && !is_async && !have_err_ret_trace_arg;
58026116 LLVMValueRef err_ret_array_val = nullptr;
58036117 if (have_err_ret_trace_stack) {
5804 TypeTableEntry *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count);
6118 ZigType *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count);
58056119 err_ret_array_val = build_alloca(g, array_type, "error_return_trace_addresses", get_abi_alignment(g, array_type));
58066120 g->cur_err_ret_trace_val_stack = build_alloca(g, g->stack_trace_type, "error_return_trace", get_abi_alignment(g, g->stack_trace_type));
58076121 } else {
......@@ -5812,14 +6126,14 @@ static void do_code_gen(CodeGen *g) {
58126126 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
58136127 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
58146128 LLVMValueRef *slot;
5815 TypeTableEntry *slot_type = instruction->value.type;
6129 ZigType *slot_type = instruction->value.type;
58166130 if (instruction->id == IrInstructionIdCast) {
58176131 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
58186132 slot = &cast_instruction->tmp_ptr;
58196133 } else if (instruction->id == IrInstructionIdRef) {
58206134 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;
58216135 slot = &ref_instruction->tmp_ptr;
5822 assert(instruction->value.type->id == TypeTableEntryIdPointer);
6136 assert(instruction->value.type->id == ZigTypeIdPointer);
58236137 slot_type = instruction->value.type->data.pointer.child_type;
58246138 } else if (instruction->id == IrInstructionIdContainerInitList) {
58256139 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
......@@ -5856,9 +6170,17 @@ static void do_code_gen(CodeGen *g) {
58566170
58576171 ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);
58586172
6173 unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
6174
58596175 // create debug variable declarations for variables and allocate all local variables
6176 FnWalk fn_walk_var = {};
6177 fn_walk_var.id = FnWalkIdVars;
6178 fn_walk_var.data.vars.import = import;
6179 fn_walk_var.data.vars.fn = fn_table_entry;
6180 fn_walk_var.data.vars.llvm_fn = fn;
6181 fn_walk_var.data.vars.gen_i = gen_i_init;
58606182 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
5861 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
6183 ZigVar *var = fn_table_entry->variable_list.at(var_i);
58626184
58636185 if (!type_has_bits(var->value->type)) {
58646186 continue;
......@@ -5875,9 +6197,12 @@ static void do_code_gen(CodeGen *g) {
58756197 buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
58766198 var->value->type->di_type, !g->strip_debug_symbols, 0);
58776199
6200 } else if (is_c_abi) {
6201 fn_walk_var.data.vars.var = var;
6202 iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk_var, var->src_arg_index);
58786203 } else {
58796204 assert(var->gen_arg_index != SIZE_MAX);
5880 TypeTableEntry *gen_type;
6205 ZigType *gen_type;
58816206 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];
58826207
58836208 if (handle_is_ptr(var->value->type)) {
......@@ -5903,7 +6228,7 @@ static void do_code_gen(CodeGen *g) {
59036228
59046229 // finishing error return trace setup. we have to do this after all the allocas.
59056230 if (have_err_ret_trace_stack) {
5906 TypeTableEntry *usize = g->builtin_types.entry_usize;
6231 ZigType *usize = g->builtin_types.entry_usize;
59076232 size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
59086233 LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, "");
59096234 gen_store_untyped(g, LLVMConstNull(usize->type_ref), index_field_ptr, 0, false);
......@@ -5911,14 +6236,14 @@ static void do_code_gen(CodeGen *g) {
59116236 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
59126237 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, "");
59136238
5914 TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
6239 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
59156240 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
59166241 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
59176242 LLVMValueRef zero = LLVMConstNull(usize->type_ref);
59186243 LLVMValueRef indices[] = {zero, zero};
59196244 LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP(g->builder, err_ret_array_val,
59206245 indices, 2, "");
5921 TypeTableEntry *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false);
6246 ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false);
59226247 gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type);
59236248
59246249 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
......@@ -5926,33 +6251,14 @@ static void do_code_gen(CodeGen *g) {
59266251 gen_store(g, LLVMConstInt(usize->type_ref, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false));
59276252 }
59286253
5929 FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
5930
59316254 // create debug variable declarations for parameters
59326255 // rely on the first variables in the variable_list being parameters.
5933 size_t next_var_i = 0;
5934 for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) {
5935 FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];
5936 if (info->gen_index == SIZE_MAX)
5937 continue;
5938
5939 VariableTableEntry *variable = fn_table_entry->variable_list.at(next_var_i);
5940 assert(variable->src_arg_index != SIZE_MAX);
5941 next_var_i += 1;
5942
5943 assert(variable);
5944 assert(variable->value_ref);
5945
5946 if (!handle_is_ptr(variable->value->type)) {
5947 clear_debug_source_node(g);
5948 gen_store_untyped(g, LLVMGetParam(fn, (unsigned)variable->gen_arg_index), variable->value_ref,
5949 variable->align_bytes, false);
5950 }
5951
5952 if (variable->decl_node) {
5953 gen_var_debug_decl(g, variable);
5954 }
5955 }
6256 FnWalk fn_walk_init = {};
6257 fn_walk_init.id = FnWalkIdInits;
6258 fn_walk_init.data.inits.fn = fn_table_entry;
6259 fn_walk_init.data.inits.llvm_fn = fn;
6260 fn_walk_init.data.inits.gen_i = gen_i_init;
6261 walk_function_params(g, fn_table_entry->type_entry, &fn_walk_init);
59566262
59576263 ir_render(g, fn_table_entry);
59586264
......@@ -6007,7 +6313,7 @@ static void do_code_gen(CodeGen *g) {
60076313 }
60086314
60096315 Buf *output_path = buf_alloc();
6010 os_path_join(g->cache_dir, o_basename, output_path);
6316 os_path_join(&g->cache_dir, o_basename, output_path);
60116317 ensure_cache_dir(g);
60126318
60136319 bool is_small = g->build_mode == BuildModeSmallRelease;
......@@ -6030,6 +6336,7 @@ static void do_code_gen(CodeGen *g) {
60306336 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
60316337 }
60326338 validate_inline_fns(g);
6339 g->link_objects.append(output_path);
60336340 break;
60346341
60356342 case EmitFileTypeLLVMIr:
......@@ -6039,6 +6346,7 @@ static void do_code_gen(CodeGen *g) {
60396346 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
60406347 }
60416348 validate_inline_fns(g);
6349 g->link_objects.append(output_path);
60426350 break;
60436351
60446352 default:
......@@ -6080,51 +6388,51 @@ static const GlobalLinkageValue global_linkage_values[] = {
60806388static void define_builtin_types(CodeGen *g) {
60816389 {
60826390 // if this type is anywhere in the AST, we should never hit codegen.
6083 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInvalid);
6391 ZigType *entry = new_type_table_entry(ZigTypeIdInvalid);
60846392 buf_init_from_str(&entry->name, "(invalid)");
60856393 entry->zero_bits = true;
60866394 g->builtin_types.entry_invalid = entry;
60876395 }
60886396 {
6089 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNamespace);
6397 ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
60906398 buf_init_from_str(&entry->name, "(namespace)");
60916399 entry->zero_bits = true;
60926400 g->builtin_types.entry_namespace = entry;
60936401 }
60946402 {
6095 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBlock);
6403 ZigType *entry = new_type_table_entry(ZigTypeIdBlock);
60966404 buf_init_from_str(&entry->name, "(block)");
60976405 entry->zero_bits = true;
60986406 g->builtin_types.entry_block = entry;
60996407 }
61006408 {
6101 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat);
6409 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
61026410 buf_init_from_str(&entry->name, "comptime_float");
61036411 entry->zero_bits = true;
61046412 g->builtin_types.entry_num_lit_float = entry;
61056413 g->primitive_type_table.put(&entry->name, entry);
61066414 }
61076415 {
6108 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeInt);
6416 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeInt);
61096417 buf_init_from_str(&entry->name, "comptime_int");
61106418 entry->zero_bits = true;
61116419 g->builtin_types.entry_num_lit_int = entry;
61126420 g->primitive_type_table.put(&entry->name, entry);
61136421 }
61146422 {
6115 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefined);
6423 ZigType *entry = new_type_table_entry(ZigTypeIdUndefined);
61166424 buf_init_from_str(&entry->name, "(undefined)");
61176425 entry->zero_bits = true;
61186426 g->builtin_types.entry_undef = entry;
61196427 }
61206428 {
6121 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNull);
6429 ZigType *entry = new_type_table_entry(ZigTypeIdNull);
61226430 buf_init_from_str(&entry->name, "(null)");
61236431 entry->zero_bits = true;
61246432 g->builtin_types.entry_null = entry;
61256433 }
61266434 {
6127 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple);
6435 ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
61286436 buf_init_from_str(&entry->name, "(args)");
61296437 entry->zero_bits = true;
61306438 g->builtin_types.entry_arg_tuple = entry;
......@@ -6135,7 +6443,7 @@ static void define_builtin_types(CodeGen *g) {
61356443 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
61366444 bool is_signed = info->is_signed;
61376445
6138 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
6446 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
61396447 entry->type_ref = LLVMIntType(size_in_bits);
61406448
61416449 buf_init_from_str(&entry->name, info->name);
......@@ -6152,7 +6460,7 @@ static void define_builtin_types(CodeGen *g) {
61526460 }
61536461
61546462 {
6155 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBool);
6463 ZigType *entry = new_type_table_entry(ZigTypeIdBool);
61566464 entry->type_ref = LLVMInt1Type();
61576465 buf_init_from_str(&entry->name, "bool");
61586466 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
......@@ -6166,7 +6474,7 @@ static void define_builtin_types(CodeGen *g) {
61666474 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
61676475 bool is_signed = is_signed_list[sign_i];
61686476
6169 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
6477 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
61706478 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
61716479
61726480 const char u_or_i = is_signed ? 'i' : 'u';
......@@ -6193,8 +6501,8 @@ static void define_builtin_types(CodeGen *g) {
61936501 const char *name,
61946502 uint32_t bit_count,
61956503 LLVMTypeRef type_ref,
6196 TypeTableEntry **field) {
6197 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);
6504 ZigType **field) {
6505 ZigType *entry = new_type_table_entry(ZigTypeIdFloat);
61986506 entry->type_ref = type_ref;
61996507 buf_init_from_str(&entry->name, name);
62006508 entry->data.floating.bit_count = bit_count;
......@@ -6213,7 +6521,7 @@ static void define_builtin_types(CodeGen *g) {
62136521 add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);
62146522
62156523 {
6216 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVoid);
6524 ZigType *entry = new_type_table_entry(ZigTypeIdVoid);
62176525 entry->type_ref = LLVMVoidType();
62186526 entry->zero_bits = true;
62196527 buf_init_from_str(&entry->name, "void");
......@@ -6224,7 +6532,7 @@ static void define_builtin_types(CodeGen *g) {
62246532 g->primitive_type_table.put(&entry->name, entry);
62256533 }
62266534 {
6227 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);
6535 ZigType *entry = new_type_table_entry(ZigTypeIdUnreachable);
62286536 entry->type_ref = LLVMVoidType();
62296537 entry->zero_bits = true;
62306538 buf_init_from_str(&entry->name, "noreturn");
......@@ -6233,7 +6541,7 @@ static void define_builtin_types(CodeGen *g) {
62336541 g->primitive_type_table.put(&entry->name, entry);
62346542 }
62356543 {
6236 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMetaType);
6544 ZigType *entry = new_type_table_entry(ZigTypeIdMetaType);
62376545 buf_init_from_str(&entry->name, "type");
62386546 entry->zero_bits = true;
62396547 g->builtin_types.entry_type = entry;
......@@ -6255,7 +6563,7 @@ static void define_builtin_types(CodeGen *g) {
62556563 }
62566564
62576565 {
6258 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);
6566 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
62596567 buf_init_from_str(&entry->name, "error");
62606568 entry->data.error_set.err_count = UINT32_MAX;
62616569
......@@ -6277,7 +6585,7 @@ static void define_builtin_types(CodeGen *g) {
62776585 g->primitive_type_table.put(&entry->name, entry);
62786586 }
62796587 {
6280 TypeTableEntry *entry = get_promise_type(g, nullptr);
6588 ZigType *entry = get_promise_type(g, nullptr);
62816589 g->primitive_type_table.put(&entry->name, entry);
62826590 }
62836591
......@@ -6530,7 +6838,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
65306838 buf_appendf(contents, "pub const TypeId = enum {\n");
65316839 size_t field_count = type_id_len();
65326840 for (size_t i = 0; i < field_count; i += 1) {
6533 const TypeTableEntryId id = type_id_at_index(i);
6841 const ZigTypeId id = type_id_at_index(i);
65346842 buf_appendf(contents, " %s,\n", type_id_name(id));
65356843 }
65366844 buf_appendf(contents, "};\n\n");
......@@ -6769,25 +7077,22 @@ static void define_builtin_compile_vars(CodeGen *g) {
67697077
67707078 const char *builtin_zig_basename = "builtin.zig";
67717079 Buf *builtin_zig_path = buf_alloc();
6772 os_path_join(g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
7080 os_path_join(&g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
67737081
67747082 Buf *contents = codegen_generate_builtin_source(g);
67757083 ensure_cache_dir(g);
67767084 os_write_file(builtin_zig_path, contents);
67777085
6778 int err;
6779 Buf *abs_full_path = buf_alloc();
6780 if ((err = os_path_real(builtin_zig_path, abs_full_path))) {
6781 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));
6782 exit(1);
6783 }
7086 Buf *resolved_path = buf_alloc();
7087 Buf *resolve_paths[] = {builtin_zig_path};
7088 *resolved_path = os_path_resolve(resolve_paths, 1);
67847089
67857090 assert(g->root_package);
67867091 assert(g->std_package);
6787 g->compile_var_package = new_package(buf_ptr(g->cache_dir), builtin_zig_basename);
7092 g->compile_var_package = new_package(buf_ptr(&g->cache_dir), builtin_zig_basename);
67887093 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
67897094 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
6790 g->compile_var_import = add_source_file(g, g->compile_var_package, abs_full_path, contents);
7095 g->compile_var_import = add_source_file(g, g->compile_var_package, resolved_path, contents);
67917096 scan_import(g, g->compile_var_import);
67927097}
67937098
......@@ -6943,17 +7248,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
69437248 Buf *code_basename = buf_create_from_str(basename);
69447249 Buf path_to_code_src = BUF_INIT;
69457250 os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);
6946 Buf *abs_full_path = buf_alloc();
6947 int err;
6948 if ((err = os_path_real(&path_to_code_src, abs_full_path))) {
6949 zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
6950 }
7251
7252 Buf *resolve_paths[] = {&path_to_code_src};
7253 Buf *resolved_path = buf_alloc();
7254 *resolved_path = os_path_resolve(resolve_paths, 1);
69517255 Buf *import_code = buf_alloc();
6952 if ((err = os_fetch_file_path(abs_full_path, import_code, false))) {
7256 int err;
7257 if ((err = os_fetch_file_path(resolved_path, import_code, false))) {
69537258 zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
69547259 }
69557260
6956 return add_source_file(g, package, abs_full_path, import_code);
7261 return add_source_file(g, package, resolved_path, import_code);
69577262}
69587263
69597264static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {
......@@ -6978,14 +7283,14 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
69787283 exit(0);
69797284 }
69807285
6981 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
7286 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
69827287 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
6983 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
6984 TypeTableEntry *fn_type = get_test_fn_type(g);
7288 ZigType *str_type = get_slice_type(g, u8_ptr_type);
7289 ZigType *fn_type = get_test_fn_type(g);
69857290
69867291 const char *field_names[] = { "name", "func", };
6987 TypeTableEntry *field_types[] = { str_type, fn_type, };
6988 TypeTableEntry *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);
7292 ZigType *field_types[] = { str_type, fn_type, };
7293 ZigType *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);
69897294
69907295 ConstExprValue *test_fn_array = create_const_vals(1);
69917296 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length);
......@@ -6993,7 +7298,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
69937298 test_fn_array->data.x_array.s_none.elements = create_const_vals(g->test_fns.length);
69947299
69957300 for (size_t i = 0; i < g->test_fns.length; i += 1) {
6996 FnTableEntry *test_fn_entry = g->test_fns.at(i);
7301 ZigFn *test_fn_entry = g->test_fns.at(i);
69977302
69987303 ConstExprValue *this_val = &test_fn_array->data.x_array.s_none.elements[i];
69997304 this_val->special = ConstValSpecialStatic;
......@@ -7031,20 +7336,18 @@ static void gen_root_source(CodeGen *g) {
70317336 Buf *rel_full_path = buf_alloc();
70327337 os_path_join(&g->root_package->root_src_dir, &g->root_package->root_src_path, rel_full_path);
70337338
7034 Buf *abs_full_path = buf_alloc();
7035 int err;
7036 if ((err = os_path_real(rel_full_path, abs_full_path))) {
7037 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
7038 exit(1);
7039 }
7339 Buf *resolved_path = buf_alloc();
7340 Buf *resolve_paths[] = {rel_full_path};
7341 *resolved_path = os_path_resolve(resolve_paths, 1);
70407342
70417343 Buf *source_code = buf_alloc();
7344 int err;
70427345 if ((err = os_fetch_file_path(rel_full_path, source_code, true))) {
70437346 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
70447347 exit(1);
70457348 }
70467349
7047 g->root_import = add_source_file(g, g->root_package, abs_full_path, source_code);
7350 g->root_import = add_source_file(g, g->root_package, resolved_path, source_code);
70487351
70497352 assert(g->root_out_name);
70507353 assert(g->out_type != OutTypeUnknown);
......@@ -7129,66 +7432,66 @@ static const char *c_int_type_names[] = {
71297432};
71307433
71317434struct GenH {
7132 ZigList<TypeTableEntry *> types_to_declare;
7435 ZigList<ZigType *> types_to_declare;
71337436};
71347437
7135static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry) {
7438static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_entry) {
71367439 if (type_entry->gen_h_loop_flag)
71377440 return;
71387441 type_entry->gen_h_loop_flag = true;
71397442
71407443 switch (type_entry->id) {
7141 case TypeTableEntryIdInvalid:
7142 case TypeTableEntryIdMetaType:
7143 case TypeTableEntryIdComptimeFloat:
7144 case TypeTableEntryIdComptimeInt:
7145 case TypeTableEntryIdUndefined:
7146 case TypeTableEntryIdNull:
7147 case TypeTableEntryIdNamespace:
7148 case TypeTableEntryIdBlock:
7149 case TypeTableEntryIdBoundFn:
7150 case TypeTableEntryIdArgTuple:
7151 case TypeTableEntryIdErrorUnion:
7152 case TypeTableEntryIdErrorSet:
7153 case TypeTableEntryIdPromise:
7444 case ZigTypeIdInvalid:
7445 case ZigTypeIdMetaType:
7446 case ZigTypeIdComptimeFloat:
7447 case ZigTypeIdComptimeInt:
7448 case ZigTypeIdUndefined:
7449 case ZigTypeIdNull:
7450 case ZigTypeIdNamespace:
7451 case ZigTypeIdBlock:
7452 case ZigTypeIdBoundFn:
7453 case ZigTypeIdArgTuple:
7454 case ZigTypeIdErrorUnion:
7455 case ZigTypeIdErrorSet:
7456 case ZigTypeIdPromise:
71547457 zig_unreachable();
7155 case TypeTableEntryIdVoid:
7156 case TypeTableEntryIdUnreachable:
7157 case TypeTableEntryIdBool:
7158 case TypeTableEntryIdInt:
7159 case TypeTableEntryIdFloat:
7458 case ZigTypeIdVoid:
7459 case ZigTypeIdUnreachable:
7460 case ZigTypeIdBool:
7461 case ZigTypeIdInt:
7462 case ZigTypeIdFloat:
71607463 return;
7161 case TypeTableEntryIdOpaque:
7464 case ZigTypeIdOpaque:
71627465 gen_h->types_to_declare.append(type_entry);
71637466 return;
7164 case TypeTableEntryIdStruct:
7467 case ZigTypeIdStruct:
71657468 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
71667469 TypeStructField *field = &type_entry->data.structure.fields[i];
71677470 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
71687471 }
71697472 gen_h->types_to_declare.append(type_entry);
71707473 return;
7171 case TypeTableEntryIdUnion:
7474 case ZigTypeIdUnion:
71727475 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
71737476 TypeUnionField *field = &type_entry->data.unionation.fields[i];
71747477 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
71757478 }
71767479 gen_h->types_to_declare.append(type_entry);
71777480 return;
7178 case TypeTableEntryIdEnum:
7481 case ZigTypeIdEnum:
71797482 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
71807483 gen_h->types_to_declare.append(type_entry);
71817484 return;
7182 case TypeTableEntryIdPointer:
7485 case ZigTypeIdPointer:
71837486 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
71847487 return;
7185 case TypeTableEntryIdArray:
7488 case ZigTypeIdArray:
71867489 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
71877490 return;
7188 case TypeTableEntryIdOptional:
7491 case ZigTypeIdOptional:
71897492 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
71907493 return;
7191 case TypeTableEntryIdFn:
7494 case ZigTypeIdFn:
71927495 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
71937496 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
71947497 }
......@@ -7197,7 +7500,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
71977500 }
71987501}
71997502
7200static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf *out_buf) {
7503static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_buf) {
72017504 assert(type_entry);
72027505
72037506 for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
......@@ -7228,17 +7531,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
72287531 prepend_c_type_to_decl_list(g, gen_h, type_entry);
72297532
72307533 switch (type_entry->id) {
7231 case TypeTableEntryIdVoid:
7534 case ZigTypeIdVoid:
72327535 buf_init_from_str(out_buf, "void");
72337536 break;
7234 case TypeTableEntryIdBool:
7537 case ZigTypeIdBool:
72357538 buf_init_from_str(out_buf, "bool");
72367539 g->c_want_stdbool = true;
72377540 break;
7238 case TypeTableEntryIdUnreachable:
7541 case ZigTypeIdUnreachable:
72397542 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");
72407543 break;
7241 case TypeTableEntryIdFloat:
7544 case ZigTypeIdFloat:
72427545 switch (type_entry->data.floating.bit_count) {
72437546 case 32:
72447547 buf_init_from_str(out_buf, "float");
......@@ -7256,17 +7559,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
72567559 zig_unreachable();
72577560 }
72587561 break;
7259 case TypeTableEntryIdInt:
7562 case ZigTypeIdInt:
72607563 g->c_want_stdint = true;
72617564 buf_resize(out_buf, 0);
72627565 buf_appendf(out_buf, "%sint%" PRIu32 "_t",
72637566 type_entry->data.integral.is_signed ? "" : "u",
72647567 type_entry->data.integral.bit_count);
72657568 break;
7266 case TypeTableEntryIdPointer:
7569 case ZigTypeIdPointer:
72677570 {
72687571 Buf child_buf = BUF_INIT;
7269 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
7572 ZigType *child_type = type_entry->data.pointer.child_type;
72707573 get_c_type(g, gen_h, child_type, &child_buf);
72717574
72727575 const char *const_str = type_entry->data.pointer.is_const ? "const " : "";
......@@ -7274,9 +7577,9 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
72747577 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
72757578 break;
72767579 }
7277 case TypeTableEntryIdOptional:
7580 case ZigTypeIdOptional:
72787581 {
7279 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
7582 ZigType *child_type = type_entry->data.maybe.child_type;
72807583 if (child_type->zero_bits) {
72817584 buf_init_from_str(out_buf, "bool");
72827585 return;
......@@ -7286,28 +7589,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
72867589 zig_unreachable();
72877590 }
72887591 }
7289 case TypeTableEntryIdStruct:
7290 case TypeTableEntryIdOpaque:
7592 case ZigTypeIdStruct:
7593 case ZigTypeIdOpaque:
72917594 {
72927595 buf_init_from_str(out_buf, "struct ");
72937596 buf_append_buf(out_buf, &type_entry->name);
72947597 return;
72957598 }
7296 case TypeTableEntryIdUnion:
7599 case ZigTypeIdUnion:
72977600 {
72987601 buf_init_from_str(out_buf, "union ");
72997602 buf_append_buf(out_buf, &type_entry->name);
73007603 return;
73017604 }
7302 case TypeTableEntryIdEnum:
7605 case ZigTypeIdEnum:
73037606 {
73047607 buf_init_from_str(out_buf, "enum ");
73057608 buf_append_buf(out_buf, &type_entry->name);
73067609 return;
73077610 }
7308 case TypeTableEntryIdArray:
7611 case ZigTypeIdArray:
73097612 {
7310 TypeTableEntryArray *array_data = &type_entry->data.array;
7613 ZigTypeArray *array_data = &type_entry->data.array;
73117614
73127615 Buf *child_buf = buf_alloc();
73137616 get_c_type(g, gen_h, array_data->child_type, child_buf);
......@@ -7316,21 +7619,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
73167619 buf_appendf(out_buf, "%s", buf_ptr(child_buf));
73177620 return;
73187621 }
7319 case TypeTableEntryIdErrorUnion:
7320 case TypeTableEntryIdErrorSet:
7321 case TypeTableEntryIdFn:
7622 case ZigTypeIdErrorUnion:
7623 case ZigTypeIdErrorSet:
7624 case ZigTypeIdFn:
73227625 zig_panic("TODO implement get_c_type for more types");
7323 case TypeTableEntryIdInvalid:
7324 case TypeTableEntryIdMetaType:
7325 case TypeTableEntryIdBoundFn:
7326 case TypeTableEntryIdNamespace:
7327 case TypeTableEntryIdBlock:
7328 case TypeTableEntryIdComptimeFloat:
7329 case TypeTableEntryIdComptimeInt:
7330 case TypeTableEntryIdUndefined:
7331 case TypeTableEntryIdNull:
7332 case TypeTableEntryIdArgTuple:
7333 case TypeTableEntryIdPromise:
7626 case ZigTypeIdInvalid:
7627 case ZigTypeIdMetaType:
7628 case ZigTypeIdBoundFn:
7629 case ZigTypeIdNamespace:
7630 case ZigTypeIdBlock:
7631 case ZigTypeIdComptimeFloat:
7632 case ZigTypeIdComptimeInt:
7633 case ZigTypeIdUndefined:
7634 case ZigTypeIdNull:
7635 case ZigTypeIdArgTuple:
7636 case ZigTypeIdPromise:
73347637 zig_unreachable();
73357638 }
73367639}
......@@ -7395,7 +7698,7 @@ static void gen_h_file(CodeGen *g) {
73957698 Buf h_buf = BUF_INIT;
73967699 buf_resize(&h_buf, 0);
73977700 for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
7398 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);
7701 ZigFn *fn_table_entry = g->fn_defs.at(fn_def_i);
73997702
74007703 if (fn_table_entry->export_list.length == 0)
74017704 continue;
......@@ -7421,7 +7724,7 @@ static void gen_h_file(CodeGen *g) {
74217724 const char *restrict_str = param_info->is_noalias ? "restrict" : "";
74227725 get_c_type(g, gen_h, param_info->type, &param_type_c);
74237726
7424 if (param_info->type->id == TypeTableEntryIdArray) {
7727 if (param_info->type->id == ZigTypeIdArray) {
74257728 // Arrays decay to pointers
74267729 buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),
74277730 restrict_str, buf_ptr(param_name));
......@@ -7467,32 +7770,32 @@ static void gen_h_file(CodeGen *g) {
74677770 fprintf(out_h, "\n");
74687771
74697772 for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
7470 TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i);
7773 ZigType *type_entry = gen_h->types_to_declare.at(type_i);
74717774 switch (type_entry->id) {
7472 case TypeTableEntryIdInvalid:
7473 case TypeTableEntryIdMetaType:
7474 case TypeTableEntryIdVoid:
7475 case TypeTableEntryIdBool:
7476 case TypeTableEntryIdUnreachable:
7477 case TypeTableEntryIdInt:
7478 case TypeTableEntryIdFloat:
7479 case TypeTableEntryIdPointer:
7480 case TypeTableEntryIdComptimeFloat:
7481 case TypeTableEntryIdComptimeInt:
7482 case TypeTableEntryIdArray:
7483 case TypeTableEntryIdUndefined:
7484 case TypeTableEntryIdNull:
7485 case TypeTableEntryIdErrorUnion:
7486 case TypeTableEntryIdErrorSet:
7487 case TypeTableEntryIdNamespace:
7488 case TypeTableEntryIdBlock:
7489 case TypeTableEntryIdBoundFn:
7490 case TypeTableEntryIdArgTuple:
7491 case TypeTableEntryIdOptional:
7492 case TypeTableEntryIdFn:
7493 case TypeTableEntryIdPromise:
7775 case ZigTypeIdInvalid:
7776 case ZigTypeIdMetaType:
7777 case ZigTypeIdVoid:
7778 case ZigTypeIdBool:
7779 case ZigTypeIdUnreachable:
7780 case ZigTypeIdInt:
7781 case ZigTypeIdFloat:
7782 case ZigTypeIdPointer:
7783 case ZigTypeIdComptimeFloat:
7784 case ZigTypeIdComptimeInt:
7785 case ZigTypeIdArray:
7786 case ZigTypeIdUndefined:
7787 case ZigTypeIdNull:
7788 case ZigTypeIdErrorUnion:
7789 case ZigTypeIdErrorSet:
7790 case ZigTypeIdNamespace:
7791 case ZigTypeIdBlock:
7792 case ZigTypeIdBoundFn:
7793 case ZigTypeIdArgTuple:
7794 case ZigTypeIdOptional:
7795 case ZigTypeIdFn:
7796 case ZigTypeIdPromise:
74947797 zig_unreachable();
7495 case TypeTableEntryIdEnum:
7798 case ZigTypeIdEnum:
74967799 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
74977800 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
74987801 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
......@@ -7510,7 +7813,7 @@ static void gen_h_file(CodeGen *g) {
75107813 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
75117814 }
75127815 break;
7513 case TypeTableEntryIdStruct:
7816 case ZigTypeIdStruct:
75147817 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
75157818 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
75167819 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
......@@ -7519,7 +7822,7 @@ static void gen_h_file(CodeGen *g) {
75197822 Buf *type_name_buf = buf_alloc();
75207823 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
75217824
7522 if (struct_field->type_entry->id == TypeTableEntryIdArray) {
7825 if (struct_field->type_entry->id == ZigTypeIdArray) {
75237826 fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
75247827 buf_ptr(struct_field->name),
75257828 struct_field->type_entry->data.array.len);
......@@ -7533,7 +7836,7 @@ static void gen_h_file(CodeGen *g) {
75337836 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
75347837 }
75357838 break;
7536 case TypeTableEntryIdUnion:
7839 case ZigTypeIdUnion:
75377840 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
75387841 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
75397842 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
......@@ -7548,7 +7851,7 @@ static void gen_h_file(CodeGen *g) {
75487851 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
75497852 }
75507853 break;
7551 case TypeTableEntryIdOpaque:
7854 case ZigTypeIdOpaque:
75527855 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
75537856 break;
75547857 }
src/codegen.hpp+1-2
......@@ -47,7 +47,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script);
4747void codegen_set_test_filter(CodeGen *g, Buf *filter);
4848void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);
4949void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch);
50void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir);
50void codegen_set_cache_dir(CodeGen *g, Buf cache_dir);
5151void codegen_set_output_h_path(CodeGen *g, Buf *h_path);
5252void codegen_add_time_event(CodeGen *g, const char *name);
5353void codegen_print_timing_report(CodeGen *g, FILE *f);
......@@ -61,5 +61,4 @@ void codegen_translate_c(CodeGen *g, Buf *path);
6161
6262Buf *codegen_generate_builtin_source(CodeGen *g);
6363
64
6564#endif
src/ir.cpp+1985-1726
......@@ -33,7 +33,7 @@ struct IrAnalyze {
3333 IrExecContext exec_context;
3434 size_t old_bb_index;
3535 size_t instruction_index;
36 TypeTableEntry *explicit_return_type;
36 ZigType *explicit_return_type;
3737 ZigList<IrInstruction *> src_implicit_return_type_list;
3838 IrBasicBlock *const_predecessor_bb;
3939};
......@@ -99,38 +99,38 @@ struct ConstCastOnly {
9999};
100100
101101struct ConstCastTypeMismatch {
102 TypeTableEntry *wanted_type;
103 TypeTableEntry *actual_type;
102 ZigType *wanted_type;
103 ZigType *actual_type;
104104};
105105
106106struct ConstCastOptionalMismatch {
107107 ConstCastOnly child;
108 TypeTableEntry *wanted_child;
109 TypeTableEntry *actual_child;
108 ZigType *wanted_child;
109 ZigType *actual_child;
110110};
111111
112112struct ConstCastPointerMismatch {
113113 ConstCastOnly child;
114 TypeTableEntry *wanted_child;
115 TypeTableEntry *actual_child;
114 ZigType *wanted_child;
115 ZigType *actual_child;
116116};
117117
118118struct ConstCastSliceMismatch {
119119 ConstCastOnly child;
120 TypeTableEntry *wanted_child;
121 TypeTableEntry *actual_child;
120 ZigType *wanted_child;
121 ZigType *actual_child;
122122};
123123
124124struct ConstCastErrUnionErrSetMismatch {
125125 ConstCastOnly child;
126 TypeTableEntry *wanted_err_set;
127 TypeTableEntry *actual_err_set;
126 ZigType *wanted_err_set;
127 ZigType *actual_err_set;
128128};
129129
130130struct ConstCastErrUnionPayloadMismatch {
131131 ConstCastOnly child;
132 TypeTableEntry *wanted_payload;
133 TypeTableEntry *actual_payload;
132 ZigType *wanted_payload;
133 ZigType *actual_payload;
134134};
135135
136136struct ConstCastErrSetMismatch {
......@@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch {
139139
140140static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
141141static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);
142static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
143static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);
142static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
143static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
144144static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);
145145static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
146146static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
147 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
149static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
147 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
149static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
150150static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
151static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align);
152static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align);
151static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
152static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
153static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);
154static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);
153155
154ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
156static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
155157 assert(get_codegen_ptr_type(const_val->type) != nullptr);
156158 assert(const_val->special == ConstValSpecialStatic);
157159 ConstExprValue *result;
......@@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
181183 return result;
182184}
183185
186static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
187 if (a == b)
188 return true;
189
190 if (a->id == b->id)
191 return true;
192
193 if (get_codegen_ptr_type(a) != nullptr && get_codegen_ptr_type(b) != nullptr)
194 return true;
195
196 return false;
197}
198
199ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
200 ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val);
201 if (const_val->type->id == ZigTypeIdPointer) {
202 assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type));
203 }
204 return result;
205}
206
184207static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
185208 if (exec->is_inline)
186209 return true;
......@@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) {
213236 return result;
214237}
215238
216static FnTableEntry *exec_fn_entry(IrExecutable *exec) {
239static ZigFn *exec_fn_entry(IrExecutable *exec) {
217240 return exec->fn_entry;
218241}
219242
......@@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {
230253}
231254
232255static bool instr_is_unreachable(IrInstruction *instruction) {
233 return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable;
256 return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable;
234257}
235258
236259static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {
......@@ -254,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb)
254277 ir_ref_bb(instruction->owner_bb);
255278}
256279
257static void ir_ref_var(VariableTableEntry *var) {
280static void ir_ref_var(ZigVar *var) {
258281 var->ref_count += 1;
259282}
260283
......@@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) {
832855 return IrInstructionIdSqrt;
833856}
834857
858static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {
859 return IrInstructionIdCheckRuntimeScope;
860}
861
835862template<typename T>
836863static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
837864 T *special_instruction = allocate<T>(1);
......@@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod
851878 return special_instruction;
852879}
853880
854static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, TypeTableEntry *dest_type,
881static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,
855882 IrInstruction *value, CastOp cast_op)
856883{
857884 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);
......@@ -904,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
904931}
905932
906933static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,
907 TypeTableEntry *type_entry)
934 ZigType *type_entry)
908935{
909936 assert(type_entry);
910937 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
......@@ -975,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s
9751002}
9761003
9771004static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
978 TypeTableEntry *type_entry)
1005 ZigType *type_entry)
9791006{
9801007 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
9811008 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
......@@ -985,14 +1012,14 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
9851012}
9861013
9871014static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
988 TypeTableEntry *type_entry)
1015 ZigType *type_entry)
9891016{
9901017 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
9911018 ir_instruction_append(irb->current_basic_block, instruction);
9921019 return instruction;
9931020}
9941021
995static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) {
1022static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
9961023 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
9971024 const_instruction->base.value.type = fn_entry->type_entry;
9981025 const_instruction->base.value.special = ConstValSpecialStatic;
......@@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
10021029 return &const_instruction->base;
10031030}
10041031
1005static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) {
1032static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
10061033 IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry);
10071034 ir_instruction_append(irb->current_basic_block, instruction);
10081035 return instruction;
......@@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode
10351062}
10361063
10371064static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,
1038 FnTableEntry *fn_entry, IrInstruction *first_arg)
1065 ZigFn *fn_entry, IrInstruction *first_arg)
10391066{
10401067 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
10411068 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);
......@@ -1087,15 +1114,22 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
10871114 return new_instruction;
10881115}
10891116
1090static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
1117static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
1118 ScopeFnDef *crossed_fndef_scope)
1119{
10911120 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
10921121 instruction->var = var;
1122 instruction->crossed_fndef_scope = crossed_fndef_scope;
10931123
10941124 ir_ref_var(var);
10951125
10961126 return &instruction->base;
10971127}
10981128
1129static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
1130 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
1131}
1132
10991133static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
11001134 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
11011135{
......@@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio
11721206}
11731207
11741208static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node,
1175 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1209 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
11761210 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
11771211 IrInstruction *new_stack)
11781212{
......@@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
12001234}
12011235
12021236static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction,
1203 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1237 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
12041238 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
12051239 IrInstruction *new_stack)
12061240{
......@@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
13491383}
13501384
13511385static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node,
1352 TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields)
1386 ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields)
13531387{
13541388 IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node);
13551389 struct_init_instruction->struct_type = struct_type;
......@@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode
13631397}
13641398
13651399static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction,
1366 TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields)
1400 ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields)
13671401{
13681402 IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope,
13691403 old_instruction->source_node, struct_type, field_count, fields);
......@@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o
13721406}
13731407
13741408static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node,
1375 TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value)
1409 ZigType *union_type, TypeUnionField *field, IrInstruction *init_value)
13761410{
13771411 IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node);
13781412 union_init_instruction->union_type = union_type;
......@@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode
13851419}
13861420
13871421static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction,
1388 TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value)
1422 ZigType *union_type, TypeUnionField *field, IrInstruction *init_value)
13891423{
13901424 IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope,
13911425 old_instruction->source_node, union_type, field, init_value);
......@@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old
14321466}
14331467
14341468static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,
1435 VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
1469 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
14361470{
14371471 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);
14381472 decl_var_instruction->base.value.special = ConstValSpecialStatic;
......@@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
14501484}
14511485
14521486static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction,
1453 VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
1487 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
14541488{
14551489 IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,
14561490 old_instruction->source_node, var, var_type, align_value, init_value);
......@@ -1595,7 +1629,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
15951629}
15961630
15971631static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list,
1598 IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)
1632 IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
15991633{
16001634 IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);
16011635 instruction->input_list = input_list;
......@@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source
16191653}
16201654
16211655static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list,
1622 IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)
1656 IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
16231657{
16241658 IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,
16251659 old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects);
......@@ -1946,7 +1980,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so
19461980 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
19471981 IrInstruction *success_order_value, IrInstruction *failure_order_value,
19481982 bool is_weak,
1949 TypeTableEntry *type, AtomicOrder success_order, AtomicOrder failure_order)
1983 ZigType *type, AtomicOrder success_order, AtomicOrder failure_order)
19501984{
19511985 IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node);
19521986 instruction->type_value = type_value;
......@@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in
22592293
22602294static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,
22612295 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
2262 IrInstruction *result_ptr, TypeTableEntry *result_ptr_type)
2296 IrInstruction *result_ptr, ZigType *result_ptr_type)
22632297{
22642298 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);
22652299 instruction->op = op;
......@@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
22792313
22802314static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction,
22812315 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
2282 IrInstruction *result_ptr, TypeTableEntry *result_ptr_type)
2316 IrInstruction *result_ptr, ZigType *result_ptr_type)
22832317{
22842318 IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node,
22852319 op, type_value, op1, op2, result_ptr, result_ptr_type);
......@@ -2974,6 +3008,17 @@ static IrInstruction *ir_build_sqrt(IrBuilder *irb, Scope *scope, AstNode *sourc
29743008 return &instruction->base;
29753009}
29763010
3011static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {
3012 IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);
3013 instruction->scope_is_comptime = scope_is_comptime;
3014 instruction->is_comptime = is_comptime;
3015
3016 ir_ref_instruction(scope_is_comptime, irb->current_basic_block);
3017 ir_ref_instruction(is_comptime, irb->current_basic_block);
3018
3019 return &instruction->base;
3020}
3021
29773022static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
29783023 results[ReturnKindUnconditional] = 0;
29793024 results[ReturnKindError] = 0;
......@@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
29993044 case ScopeIdLoop:
30003045 case ScopeIdSuspend:
30013046 case ScopeIdCompTime:
3047 case ScopeIdRuntime:
30023048 scope = scope->parent;
30033049 continue;
30043050 case ScopeIdDeferExpr:
......@@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
30333079 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
30343080 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
30353081 if (defer_expr_value != irb->codegen->invalid_instruction) {
3036 if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) {
3082 if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == ZigTypeIdUnreachable) {
30373083 is_noreturn = true;
30383084 } else {
30393085 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));
......@@ -3051,6 +3097,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
30513097 case ScopeIdLoop:
30523098 case ScopeIdSuspend:
30533099 case ScopeIdCompTime:
3100 case ScopeIdRuntime:
30543101 scope = scope->parent;
30553102 continue;
30563103 case ScopeIdDeferExpr:
......@@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
30983145}
30993146
31003147static bool exec_is_async(IrExecutable *exec) {
3101 FnTableEntry *fn_entry = exec_fn_entry(exec);
3148 ZigFn *fn_entry = exec_fn_entry(exec);
31023149 return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
31033150}
31043151
......@@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode
31603207static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {
31613208 assert(node->type == NodeTypeReturnExpr);
31623209
3163 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
3210 ZigFn *fn_entry = exec_fn_entry(irb->exec);
31643211 if (!fn_entry) {
31653212 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
31663213 return irb->codegen->invalid_instruction;
......@@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
31843231 IrInstruction *return_value;
31853232 if (expr_node) {
31863233 // Temporarily set this so that if we return a type it gets the name of the function
3187 FnTableEntry *prev_name_fn = irb->exec->name_fn;
3234 ZigFn *prev_name_fn = irb->exec->name_fn;
31883235 irb->exec->name_fn = exec_fn_entry(irb->exec);
31893236 return_value = ir_gen_node(irb, expr_node, scope);
31903237 irb->exec->name_fn = prev_name_fn;
......@@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
32803327 zig_unreachable();
32813328}
32823329
3283static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
3330static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
32843331 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
32853332 bool skip_name_check)
32863333{
3287 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
3334 ZigVar *variable_entry = allocate<ZigVar>(1);
32883335 variable_entry->parent_scope = parent_scope;
32893336 variable_entry->shadowable = is_shadowable;
32903337 variable_entry->mem_slot_index = SIZE_MAX;
......@@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
32963343 buf_init_from_buf(&variable_entry->name, name);
32973344
32983345 if (!skip_name_check) {
3299 VariableTableEntry *existing_var = find_variable(codegen, parent_scope, name);
3346 ZigVar *existing_var = find_variable(codegen, parent_scope, name, nullptr);
33003347 if (existing_var && !existing_var->shadowable) {
33013348 ErrorMsg *msg = add_node_error(codegen, node,
33023349 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
33033350 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
33043351 variable_entry->value->type = codegen->builtin_types.entry_invalid;
33053352 } else {
3306 TypeTableEntry *type = get_primitive_type(codegen, name);
3353 ZigType *type = get_primitive_type(codegen, name);
33073354 if (type != nullptr) {
33083355 add_node_error(codegen, node,
33093356 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
......@@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
33373384
33383385// Set name to nullptr to make the variable anonymous (not visible to programmer).
33393386// After you call this function var->child_scope has the variable in scope
3340static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
3387static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
33413388 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
33423389{
33433390 bool is_underscored = name ? buf_eql_str(name, "_") : false;
3344 VariableTableEntry *var = create_local_var(irb->codegen, node, scope,
3391 ZigVar *var = create_local_var(irb->codegen, node, scope,
33453392 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
33463393 (is_underscored ? true : is_shadowable), is_comptime, false);
33473394 if (is_comptime != nullptr || gen_is_const) {
......@@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
33633410 Scope *outer_block_scope = &scope_block->base;
33643411 Scope *child_scope = outer_block_scope;
33653412
3366 FnTableEntry *fn_entry = scope_fn_entry(parent_scope);
3413 ZigFn *fn_entry = scope_fn_entry(parent_scope);
33673414 if (fn_entry && fn_entry->child_scope == parent_scope) {
33683415 fn_entry->def_scope = scope_block;
33693416 }
......@@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
37493796 return &const_instruction->base;
37503797 }
37513798
3752 TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name);
3799 ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name);
37533800 if (primitive_type != nullptr) {
37543801 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
37553802 if (lval == LValPtr) {
......@@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
37593806 }
37603807 }
37613808
3762 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3809 ScopeFnDef *crossed_fndef_scope;
3810 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
37633811 if (var) {
3764 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3812 IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
37653813 if (lval == LValPtr)
37663814 return var_ptr;
37673815 else
......@@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
49805028
49815029 ir_set_cursor_at_end_and_append_block(irb, then_block);
49825030
4983 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope);
5031 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5032 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, subexpr_scope);
49845033 if (then_expr_result == irb->codegen->invalid_instruction)
49855034 return then_expr_result;
49865035 IrBasicBlock *after_then_block = irb->current_basic_block;
......@@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
49905039 ir_set_cursor_at_end_and_append_block(irb, else_block);
49915040 IrInstruction *else_expr_result;
49925041 if (else_node) {
4993 else_expr_result = ir_gen_node(irb, else_node, scope);
5042 else_expr_result = ir_gen_node(irb, else_node, subexpr_scope);
49945043 if (else_expr_result == irb->codegen->invalid_instruction)
49955044 return else_expr_result;
49965045 } else {
......@@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
52175266
52185267 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
52195268 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);
5220 VariableTableEntry *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
5269 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
52215270 is_const, is_const, is_shadowable, is_comptime);
52225271 // we detect IrInstructionIdDeclVar in gen_block to make sure the next node
52235272 // is inside var->child_scope
......@@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
52715320 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
52725321 ir_build_br(irb, scope, node, cond_block, is_comptime);
52735322
5323 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
52745324 Buf *var_symbol = node->data.while_expr.var_symbol;
52755325 Buf *err_symbol = node->data.while_expr.err_symbol;
52765326 if (err_symbol != nullptr) {
......@@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
52785328
52795329 Scope *payload_scope;
52805330 AstNode *symbol_node = node; // TODO make more accurate
5281 VariableTableEntry *payload_var;
5331 ZigVar *payload_var;
52825332 if (var_symbol) {
52835333 // TODO make it an error to write to payload variable
5284 payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
5334 payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
52855335 true, false, false, is_comptime);
52865336 payload_scope = payload_var->child_scope;
52875337 } else {
5288 payload_scope = scope;
5338 payload_scope = subexpr_scope;
52895339 }
5290 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
5340 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);
52915341 if (err_val_ptr == irb->codegen->invalid_instruction)
52925342 return err_val_ptr;
52935343 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);
......@@ -5342,7 +5392,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
53425392
53435393 // TODO make it an error to write to error variable
53445394 AstNode *err_symbol_node = else_node; // TODO make more accurate
5345 VariableTableEntry *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
5395 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
53465396 true, false, false, is_comptime);
53475397 Scope *err_scope = err_var->child_scope;
53485398 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
......@@ -5367,12 +5417,14 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
53675417 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
53685418 } else if (var_symbol != nullptr) {
53695419 ir_set_cursor_at_end_and_append_block(irb, cond_block);
5420 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
53705421 // TODO make it an error to write to payload variable
53715422 AstNode *symbol_node = node; // TODO make more accurate
5372 VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
5423
5424 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
53735425 true, false, false, is_comptime);
53745426 Scope *child_scope = payload_var->child_scope;
5375 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
5427 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);
53765428 if (maybe_val_ptr == irb->codegen->invalid_instruction)
53775429 return maybe_val_ptr;
53785430 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
......@@ -5456,7 +5508,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
54565508 ZigList<IrInstruction *> incoming_values = {0};
54575509 ZigList<IrBasicBlock *> incoming_blocks = {0};
54585510
5459 ScopeLoop *loop_scope = create_loop_scope(node, scope);
5511 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5512
5513 ScopeLoop *loop_scope = create_loop_scope(node, subexpr_scope);
54605514 loop_scope->break_block = end_block;
54615515 loop_scope->continue_block = continue_block;
54625516 loop_scope->is_comptime = is_comptime;
......@@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
54745528
54755529 if (continue_expr_node) {
54765530 ir_set_cursor_at_end_and_append_block(irb, continue_block);
5477 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope);
5531 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
54785532 if (expr_result == irb->codegen->invalid_instruction)
54795533 return expr_result;
54805534 if (!instr_is_unreachable(expr_result))
......@@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
54855539 if (else_node) {
54865540 ir_set_cursor_at_end_and_append_block(irb, else_block);
54875541
5488 else_result = ir_gen_node(irb, else_node, scope);
5542 else_result = ir_gen_node(irb, else_node, subexpr_scope);
54895543 if (else_result == irb->codegen->invalid_instruction)
54905544 return else_result;
54915545 if (!instr_is_unreachable(else_result))
......@@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
55395593
55405594 // TODO make it an error to write to element variable or i variable.
55415595 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
5542 VariableTableEntry *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
5596 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
55435597 Scope *child_scope = elem_var->child_scope;
55445598
55455599 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
......@@ -5547,7 +5601,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
55475601 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
55485602
55495603 AstNode *index_var_source_node;
5550 VariableTableEntry *index_var;
5604 ZigVar *index_var;
55515605 if (index_node) {
55525606 index_var_source_node = index_node;
55535607 Buf *index_var_name = index_node->data.symbol_expr.symbol;
......@@ -5640,7 +5694,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
56405694 if (!scope->parent)
56415695 return ir_build_const_import(irb, scope, node, node->owner);
56425696
5643 FnTableEntry *fn_entry = scope_get_fn_if_root(scope);
5697 ZigFn *fn_entry = scope_get_fn_if_root(scope);
56445698 if (fn_entry)
56455699 return ir_build_const_fn(irb, scope, node, fn_entry);
56465700
......@@ -5650,7 +5704,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
56505704
56515705 if (scope->id == ScopeIdDecls) {
56525706 ScopeDecls *decls_scope = (ScopeDecls *)scope;
5653 TypeTableEntry *container_type = decls_scope->container_type;
5707 ZigType *container_type = decls_scope->container_type;
56545708 assert(container_type);
56555709 return ir_build_const_type(irb, scope, node, container_type);
56565710 }
......@@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
57525806
57535807 IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);
57545808 IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length);
5755 VariableTableEntry **output_vars = allocate<VariableTableEntry *>(node->data.asm_expr.output_list.length);
5809 ZigVar **output_vars = allocate<ZigVar *>(node->data.asm_expr.output_list.length);
57565810 size_t return_count = 0;
57575811 bool is_volatile = node->data.asm_expr.is_volatile;
57585812 if (!is_volatile && node->data.asm_expr.output_list.length == 0) {
......@@ -5776,7 +5830,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
57765830 output_types[i] = return_type;
57775831 } else {
57785832 Buf *variable_name = asm_output->variable_name;
5779 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
5833 // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how
5834 // inline assembly works. https://github.com/ziglang/zig/issues/215
5835 ZigVar *var = find_variable(irb->codegen, scope, variable_name, nullptr);
57805836 if (var) {
57815837 output_vars[i] = var;
57825838 } else {
......@@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
58285884
58295885 ir_set_cursor_at_end_and_append_block(irb, then_block);
58305886
5887 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
58315888 Scope *var_scope;
58325889 if (var_symbol) {
58335890 IrInstruction *var_type = nullptr;
58345891 bool is_shadowable = false;
58355892 bool is_const = true;
5836 VariableTableEntry *var = ir_create_var(irb, node, scope,
5893 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
58375894 var_symbol, is_const, is_const, is_shadowable, is_comptime);
58385895
5839 IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, scope, node, maybe_val_ptr, false);
5840 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value);
5841 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
5896 IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false);
5897 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
5898 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
58425899 var_scope = var->child_scope;
58435900 } else {
5844 var_scope = scope;
5901 var_scope = subexpr_scope;
58455902 }
58465903 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
58475904 if (then_expr_result == irb->codegen->invalid_instruction)
......@@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
58535910 ir_set_cursor_at_end_and_append_block(irb, else_block);
58545911 IrInstruction *else_expr_result;
58555912 if (else_node) {
5856 else_expr_result = ir_gen_node(irb, else_node, scope);
5913 else_expr_result = ir_gen_node(irb, else_node, subexpr_scope);
58575914 if (else_expr_result == irb->codegen->invalid_instruction)
58585915 return else_expr_result;
58595916 } else {
......@@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
59025959
59035960 ir_set_cursor_at_end_and_append_block(irb, ok_block);
59045961
5962 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
59055963 Scope *var_scope;
59065964 if (var_symbol) {
59075965 IrInstruction *var_type = nullptr;
59085966 bool is_shadowable = false;
5909 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, err_val);
5910 VariableTableEntry *var = ir_create_var(irb, node, scope,
5967 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
5968 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
59115969 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
59125970
5913 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, scope, node, err_val_ptr, false);
5914 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value);
5915 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
5971 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);
5972 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
5973 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
59165974 var_scope = var->child_scope;
59175975 } else {
5918 var_scope = scope;
5976 var_scope = subexpr_scope;
59195977 }
59205978 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
59215979 if (then_expr_result == irb->codegen->invalid_instruction)
......@@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
59335991 IrInstruction *var_type = nullptr;
59345992 bool is_shadowable = false;
59355993 bool is_const = true;
5936 VariableTableEntry *var = ir_create_var(irb, node, scope,
5994 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
59375995 err_symbol, is_const, is_const, is_shadowable, is_comptime);
59385996
5939 IrInstruction *var_value = ir_build_unwrap_err_code(irb, scope, node, err_val_ptr);
5940 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
5997 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
5998 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
59415999 err_var_scope = var->child_scope;
59426000 } else {
5943 err_var_scope = scope;
6001 err_var_scope = subexpr_scope;
59446002 }
59456003 else_expr_result = ir_gen_node(irb, else_node, err_var_scope);
59466004 if (else_expr_result == irb->codegen->invalid_instruction)
......@@ -5981,7 +6039,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
59816039
59826040 bool is_shadowable = false;
59836041 bool is_const = true;
5984 VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope,
6042 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
59856043 var_name, is_const, is_const, is_shadowable, var_is_comptime);
59866044 child_scope = var->child_scope;
59876045 IrInstruction *var_value;
......@@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
60376095 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
60386096
60396097 // First do the else and the ranges
6098 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
60406099 Scope *comptime_scope = create_comptime_scope(node, scope);
60416100 AstNode *else_prong = nullptr;
60426101 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
......@@ -6054,7 +6113,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
60546113
60556114 IrBasicBlock *prev_block = irb->current_basic_block;
60566115 ir_set_cursor_at_end_and_append_block(irb, else_block);
6057 if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
6116 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
60586117 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
60596118 {
60606119 return irb->codegen->invalid_instruction;
......@@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
61216180 range_block_no, is_comptime));
61226181
61236182 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);
6124 if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
6183 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
61256184 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
61266185 {
61276186 return irb->codegen->invalid_instruction;
......@@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
61656224
61666225 IrBasicBlock *prev_block = irb->current_basic_block;
61676226 ir_set_cursor_at_end_and_append_block(irb, prong_block);
6168 if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
6227 if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
61696228 is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values))
61706229 {
61716230 return irb->codegen->invalid_instruction;
......@@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
63086367 // * defer expression scope => error, cannot break out of defer expression
63096368 // * loop scope => OK
63106369
6370 ZigList<ScopeRuntime *> runtime_scopes = {};
6371
63116372 Scope *search_scope = continue_scope;
63126373 ScopeLoop *loop_scope;
63136374 for (;;) {
......@@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
63306391 loop_scope = this_loop_scope;
63316392 break;
63326393 }
6394 } else if (search_scope->id == ScopeIdRuntime) {
6395 ScopeRuntime *scope_runtime = (ScopeRuntime *)search_scope;
6396 runtime_scopes.append(scope_runtime);
63336397 }
63346398 search_scope = search_scope->parent;
63356399 }
......@@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
63416405 is_comptime = loop_scope->is_comptime;
63426406 }
63436407
6408 for (size_t i = 0; i < runtime_scopes.length; i += 1) {
6409 ScopeRuntime *scope_runtime = runtime_scopes.at(i);
6410 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
6411 }
6412
63446413 IrBasicBlock *dest_block = loop_scope->continue_block;
63456414 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
63466415 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
......@@ -6435,7 +6504,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
64356504 Buf *var_name = var_node->data.symbol_expr.symbol;
64366505 bool is_const = true;
64376506 bool is_shadowable = false;
6438 VariableTableEntry *var = ir_create_var(irb, node, parent_scope, var_name,
6507 ZigVar *var = ir_create_var(irb, node, parent_scope, var_name,
64396508 is_const, is_const, is_shadowable, is_comptime);
64406509 err_scope = var->child_scope;
64416510 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
......@@ -6507,7 +6576,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
65076576 init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope);
65086577
65096578 ContainerLayout layout = node->data.container_decl.layout;
6510 TypeTableEntry *container_type = get_partial_container_type(irb->codegen, parent_scope,
6579 ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope,
65116580 kind, node, buf_ptr(name), layout);
65126581 ScopeDecls *child_scope = get_container_scope(container_type);
65136582
......@@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
65276596}
65286597
65296598// errors should be populated with set1's values
6530static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) {
6531 assert(set1->id == TypeTableEntryIdErrorSet);
6532 assert(set2->id == TypeTableEntryIdErrorSet);
6599static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {
6600 assert(set1->id == ZigTypeIdErrorSet);
6601 assert(set2->id == ZigTypeIdErrorSet);
65336602
6534 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
6603 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
65356604 buf_resize(&err_set_type->name, 0);
65366605 buf_appendf(&err_set_type->name, "error{");
65376606
......@@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors,
65806649
65816650}
65826651
6583static TypeTableEntry *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,
6652static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,
65846653 ErrorTableEntry *err_entry)
65856654{
6586 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
6655 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
65876656 buf_resize(&err_set_type->name, 0);
65886657 buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));
65896658 err_set_type->is_copyable = true;
......@@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
66056674 uint32_t err_count = node->data.err_set_decl.decls.length;
66066675
66076676 Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);
6608 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
6677 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
66096678 buf_init_from_buf(&err_set_type->name, type_name);
66106679 err_set_type->is_copyable = true;
66116680 err_set_type->data.error_set.err_count = err_count;
......@@ -6854,7 +6923,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68546923 if (target_inst == irb->codegen->invalid_instruction)
68556924 return irb->codegen->invalid_instruction;
68566925
6857 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
6926 ZigFn *fn_entry = exec_fn_entry(irb->exec);
68586927 if (!fn_entry) {
68596928 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
68606929 return irb->codegen->invalid_instruction;
......@@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
69176986 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
69186987 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
69196988
6920 VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr,
6989 ZigVar *result_var = ir_create_var(irb, node, scope, nullptr,
69216990 false, false, true, const_bool_false);
69226991 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
69236992 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
......@@ -7031,7 +7100,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
70317100static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
70327101 assert(node->type == NodeTypeSuspend);
70337102
7034 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
7103 ZigFn *fn_entry = exec_fn_entry(irb->exec);
70357104 if (!fn_entry) {
70367105 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
70377106 return irb->codegen->invalid_instruction;
......@@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
73207389 // Entry block gets a reference because we enter it to begin.
73217390 ir_ref_bb(irb->current_basic_block);
73227391
7323 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
7392 ZigFn *fn_entry = exec_fn_entry(irb->exec);
73247393 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
73257394 IrInstruction *coro_id;
73267395 IrInstruction *u8_ptr_type;
73277396 IrInstruction *const_bool_false;
73287397 IrInstruction *coro_promise_ptr;
73297398 IrInstruction *err_ret_trace_ptr;
7330 TypeTableEntry *return_type;
7399 ZigType *return_type;
73317400 Buf *result_ptr_field_name;
7332 VariableTableEntry *coro_size_var;
7401 ZigVar *coro_size_var;
73337402 if (is_async) {
73347403 // create the coro promise
73357404 Scope *coro_scope = create_coro_prelude_scope(node, scope);
73367405 const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);
7337 VariableTableEntry *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7406 ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
73387407
73397408 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
73407409 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);
7341 TypeTableEntry *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
7410 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
73427411 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
73437412 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
73447413 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
73457414 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
73467415
7347 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7416 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
73487417 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
73497418 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
73507419 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
......@@ -7531,7 +7600,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
75317600 return true;
75327601}
75337602
7534bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {
7603bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
75357604 assert(fn_entry);
75367605
75377606 IrExecutable *ir_executable = &fn_entry->ir_executable;
......@@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
75667635 return ir_add_error_node(ira, source_instruction->source_node, msg);
75677636}
75687637
7638static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) {
7639 ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val);
7640 assert(val != nullptr);
7641 assert(const_val->type->id == ZigTypeIdPointer);
7642 ZigType *expected_type = const_val->type->data.pointer.child_type;
7643 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {
7644 ir_add_error_node(ira, source_node,
7645 buf_sprintf("TODO handle comptime reinterpreted pointer. See https://github.com/ziglang/zig/issues/955"));
7646 return nullptr;
7647 }
7648 return val;
7649}
7650
75697651static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
75707652 IrBasicBlock *bb = exec->basic_block_list.at(0);
75717653 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
......@@ -7596,17 +7678,17 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
75967678 return true;
75977679}
75987680
7599static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) {
7600 return ((num_lit_type->id == TypeTableEntryIdComptimeFloat &&
7601 (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) ||
7602 (num_lit_type->id == TypeTableEntryIdComptimeInt &&
7603 (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt)));
7681static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {
7682 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
7683 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
7684 (num_lit_type->id == ZigTypeIdComptimeInt &&
7685 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
76047686}
76057687
76067688static bool float_has_fraction(ConstExprValue *const_val) {
7607 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
7689 if (const_val->type->id == ZigTypeIdComptimeFloat) {
76087690 return bigfloat_has_fraction(&const_val->data.x_bigfloat);
7609 } else if (const_val->type->id == TypeTableEntryIdFloat) {
7691 } else if (const_val->type->id == ZigTypeIdFloat) {
76107692 switch (const_val->type->data.floating.bit_count) {
76117693 case 16:
76127694 {
......@@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {
76327714}
76337715
76347716static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
7635 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
7717 if (const_val->type->id == ZigTypeIdComptimeFloat) {
76367718 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
7637 } else if (const_val->type->id == TypeTableEntryIdFloat) {
7719 } else if (const_val->type->id == ZigTypeIdFloat) {
76387720 switch (const_val->type->data.floating.bit_count) {
76397721 case 16:
76407722 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
......@@ -7670,9 +7752,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
76707752}
76717753
76727754static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
7673 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
7755 if (const_val->type->id == ZigTypeIdComptimeFloat) {
76747756 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
7675 } else if (const_val->type->id == TypeTableEntryIdFloat) {
7757 } else if (const_val->type->id == ZigTypeIdFloat) {
76767758 switch (const_val->type->data.floating.bit_count) {
76777759 case 16:
76787760 {
......@@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
77177799}
77187800
77197801static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
7720 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
7802 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
77217803 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
7722 } else if (dest_val->type->id == TypeTableEntryIdFloat) {
7804 } else if (dest_val->type->id == ZigTypeIdFloat) {
77237805 switch (dest_val->type->data.floating.bit_count) {
77247806 case 16:
77257807 dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);
......@@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
77427824}
77437825
77447826static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
7745 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
7827 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
77467828 bigfloat_init_16(&dest_val->data.x_bigfloat, x);
7747 } else if (dest_val->type->id == TypeTableEntryIdFloat) {
7829 } else if (dest_val->type->id == ZigTypeIdFloat) {
77487830 switch (dest_val->type->data.floating.bit_count) {
77497831 case 16:
77507832 dest_val->data.x_f16 = x;
......@@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
77677849}
77687850
77697851static void float_init_f32(ConstExprValue *dest_val, float x) {
7770 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
7852 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
77717853 bigfloat_init_32(&dest_val->data.x_bigfloat, x);
7772 } else if (dest_val->type->id == TypeTableEntryIdFloat) {
7854 } else if (dest_val->type->id == ZigTypeIdFloat) {
77737855 switch (dest_val->type->data.floating.bit_count) {
77747856 case 16:
77757857 dest_val->data.x_f16 = zig_double_to_f16(x);
......@@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
77967878}
77977879
77987880static void float_init_f64(ConstExprValue *dest_val, double x) {
7799 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
7881 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
78007882 bigfloat_init_64(&dest_val->data.x_bigfloat, x);
7801 } else if (dest_val->type->id == TypeTableEntryIdFloat) {
7883 } else if (dest_val->type->id == ZigTypeIdFloat) {
78027884 switch (dest_val->type->data.floating.bit_count) {
78037885 case 16:
78047886 dest_val->data.x_f16 = zig_double_to_f16(x);
......@@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
78257907}
78267908
78277909static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
7828 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
7910 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
78297911 bigfloat_init_128(&dest_val->data.x_bigfloat, x);
7830 } else if (dest_val->type->id == TypeTableEntryIdFloat) {
7912 } else if (dest_val->type->id == ZigTypeIdFloat) {
78317913 switch (dest_val->type->data.floating.bit_count) {
78327914 case 16:
78337915 dest_val->data.x_f16 = f128M_to_f16(&x);
......@@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
78587940}
78597941
78607942static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
7861 if (src_val->type->id == TypeTableEntryIdComptimeFloat) {
7943 if (src_val->type->id == ZigTypeIdComptimeFloat) {
78627944 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
7863 } else if (src_val->type->id == TypeTableEntryIdFloat) {
7945 } else if (src_val->type->id == ZigTypeIdFloat) {
78647946 switch (src_val->type->data.floating.bit_count) {
78657947 case 16:
78667948 float_init_f16(dest_val, src_val->data.x_f16);
......@@ -7884,9 +7966,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
78847966
78857967static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
78867968 assert(op1->type == op2->type);
7887 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
7969 if (op1->type->id == ZigTypeIdComptimeFloat) {
78887970 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
7889 } else if (op1->type->id == TypeTableEntryIdFloat) {
7971 } else if (op1->type->id == ZigTypeIdFloat) {
78907972 switch (op1->type->data.floating.bit_count) {
78917973 case 16:
78927974 if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {
......@@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
79298011}
79308012
79318013static Cmp float_cmp_zero(ConstExprValue *op) {
7932 if (op->type->id == TypeTableEntryIdComptimeFloat) {
8014 if (op->type->id == ZigTypeIdComptimeFloat) {
79338015 return bigfloat_cmp_zero(&op->data.x_bigfloat);
7934 } else if (op->type->id == TypeTableEntryIdFloat) {
8016 } else if (op->type->id == ZigTypeIdFloat) {
79358017 switch (op->type->data.floating.bit_count) {
79368018 case 16:
79378019 {
......@@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
79818063static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
79828064 assert(op1->type == op2->type);
79838065 out_val->type = op1->type;
7984 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8066 if (op1->type->id == ZigTypeIdComptimeFloat) {
79858067 bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
7986 } else if (op1->type->id == TypeTableEntryIdFloat) {
8068 } else if (op1->type->id == ZigTypeIdFloat) {
79878069 switch (op1->type->data.floating.bit_count) {
79888070 case 16:
79898071 out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16);
......@@ -8008,9 +8090,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
80088090static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
80098091 assert(op1->type == op2->type);
80108092 out_val->type = op1->type;
8011 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8093 if (op1->type->id == ZigTypeIdComptimeFloat) {
80128094 bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8013 } else if (op1->type->id == TypeTableEntryIdFloat) {
8095 } else if (op1->type->id == ZigTypeIdFloat) {
80148096 switch (op1->type->data.floating.bit_count) {
80158097 case 16:
80168098 out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16);
......@@ -8035,9 +8117,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
80358117static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
80368118 assert(op1->type == op2->type);
80378119 out_val->type = op1->type;
8038 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8120 if (op1->type->id == ZigTypeIdComptimeFloat) {
80398121 bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8040 } else if (op1->type->id == TypeTableEntryIdFloat) {
8122 } else if (op1->type->id == ZigTypeIdFloat) {
80418123 switch (op1->type->data.floating.bit_count) {
80428124 case 16:
80438125 out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16);
......@@ -8062,9 +8144,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
80628144static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
80638145 assert(op1->type == op2->type);
80648146 out_val->type = op1->type;
8065 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8147 if (op1->type->id == ZigTypeIdComptimeFloat) {
80668148 bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8067 } else if (op1->type->id == TypeTableEntryIdFloat) {
8149 } else if (op1->type->id == ZigTypeIdFloat) {
80688150 switch (op1->type->data.floating.bit_count) {
80698151 case 16:
80708152 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
......@@ -8089,9 +8171,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
80898171static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
80908172 assert(op1->type == op2->type);
80918173 out_val->type = op1->type;
8092 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8174 if (op1->type->id == ZigTypeIdComptimeFloat) {
80938175 bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8094 } else if (op1->type->id == TypeTableEntryIdFloat) {
8176 } else if (op1->type->id == ZigTypeIdFloat) {
80958177 switch (op1->type->data.floating.bit_count) {
80968178 case 16:
80978179 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
......@@ -8118,9 +8200,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
81188200static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
81198201 assert(op1->type == op2->type);
81208202 out_val->type = op1->type;
8121 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8203 if (op1->type->id == ZigTypeIdComptimeFloat) {
81228204 bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8123 } else if (op1->type->id == TypeTableEntryIdFloat) {
8205 } else if (op1->type->id == ZigTypeIdFloat) {
81248206 switch (op1->type->data.floating.bit_count) {
81258207 case 16:
81268208 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
......@@ -8147,9 +8229,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
81478229static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
81488230 assert(op1->type == op2->type);
81498231 out_val->type = op1->type;
8150 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8232 if (op1->type->id == ZigTypeIdComptimeFloat) {
81518233 bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8152 } else if (op1->type->id == TypeTableEntryIdFloat) {
8234 } else if (op1->type->id == ZigTypeIdFloat) {
81538235 switch (op1->type->data.floating.bit_count) {
81548236 case 16:
81558237 out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16);
......@@ -8192,9 +8274,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
81928274static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
81938275 assert(op1->type == op2->type);
81948276 out_val->type = op1->type;
8195 if (op1->type->id == TypeTableEntryIdComptimeFloat) {
8277 if (op1->type->id == ZigTypeIdComptimeFloat) {
81968278 bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8197 } else if (op1->type->id == TypeTableEntryIdFloat) {
8279 } else if (op1->type->id == ZigTypeIdFloat) {
81988280 switch (op1->type->data.floating.bit_count) {
81998281 case 16:
82008282 out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16);
......@@ -8218,9 +8300,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
82188300
82198301static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
82208302 out_val->type = op->type;
8221 if (op->type->id == TypeTableEntryIdComptimeFloat) {
8303 if (op->type->id == ZigTypeIdComptimeFloat) {
82228304 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
8223 } else if (op->type->id == TypeTableEntryIdFloat) {
8305 } else if (op->type->id == ZigTypeIdFloat) {
82248306 switch (op->type->data.floating.bit_count) {
82258307 case 16:
82268308 {
......@@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
82488330}
82498331
82508332void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
8251 if (op->type->id == TypeTableEntryIdFloat) {
8333 if (op->type->id == ZigTypeIdFloat) {
82528334 switch (op->type->data.floating.bit_count) {
82538335 case 16:
82548336 memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian
......@@ -8271,7 +8353,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
82718353}
82728354
82738355void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
8274 if (val->type->id == TypeTableEntryIdFloat) {
8356 if (val->type->id == ZigTypeIdFloat) {
82758357 switch (val->type->data.floating.bit_count) {
82768358 case 16:
82778359 memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian
......@@ -8293,7 +8375,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
82938375 }
82948376}
82958377
8296static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type,
8378static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type,
82978379 bool explicit_cast)
82988380{
82998381 if (type_is_invalid(other_type)) {
......@@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
83038385 ConstExprValue *const_val = &instruction->value;
83048386 assert(const_val->special != ConstValSpecialRuntime);
83058387
8306 bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt ||
8307 const_val->type->id == TypeTableEntryIdComptimeInt);
8308 bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat ||
8309 const_val->type->id == TypeTableEntryIdComptimeFloat);
8310 if (other_type->id == TypeTableEntryIdFloat) {
8388 bool const_val_is_int = (const_val->type->id == ZigTypeIdInt ||
8389 const_val->type->id == ZigTypeIdComptimeInt);
8390 bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat ||
8391 const_val->type->id == ZigTypeIdComptimeFloat);
8392 if (other_type->id == ZigTypeIdFloat) {
83118393 return true;
8312 } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) {
8394 } else if (other_type->id == ZigTypeIdInt && const_val_is_int) {
83138395 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
83148396 Buf *val_buf = buf_alloc();
83158397 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
......@@ -8326,11 +8408,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
83268408 }
83278409 } else if (const_val_fits_in_num_lit(const_val, other_type)) {
83288410 return true;
8329 } else if (other_type->id == TypeTableEntryIdOptional) {
8330 TypeTableEntry *child_type = other_type->data.maybe.child_type;
8411 } else if (other_type->id == ZigTypeIdOptional) {
8412 ZigType *child_type = other_type->data.maybe.child_type;
83318413 if (const_val_fits_in_num_lit(const_val, child_type)) {
83328414 return true;
8333 } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) {
8415 } else if (child_type->id == ZigTypeIdInt && const_val_is_int) {
83348416 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
83358417 Buf *val_buf = buf_alloc();
83368418 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
......@@ -8346,11 +8428,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
83468428 {
83478429 return true;
83488430 }
8349 } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) {
8431 } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) {
83508432 return true;
83518433 }
83528434 }
8353 if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) &&
8435 if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) &&
83548436 const_val_is_float)
83558437 {
83568438 if (float_has_fraction(const_val)) {
......@@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
83638445 buf_ptr(&other_type->name)));
83648446 return false;
83658447 } else {
8366 if (other_type->id == TypeTableEntryIdComptimeInt) {
8448 if (other_type->id == ZigTypeIdComptimeInt) {
83678449 return true;
83688450 } else {
83698451 BigInt bigint;
......@@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
83958477 return false;
83968478}
83978479
8398static bool is_slice(TypeTableEntry *type) {
8399 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;
8480static bool is_slice(ZigType *type) {
8481 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
84008482}
84018483
8402static bool slice_is_const(TypeTableEntry *type) {
8484static bool slice_is_const(ZigType *type) {
84038485 assert(is_slice(type));
84048486 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
84058487}
84068488
8407static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2,
8489static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2,
84088490 AstNode *source_node)
84098491{
8410 assert(set1->id == TypeTableEntryIdErrorSet);
8411 assert(set2->id == TypeTableEntryIdErrorSet);
8492 assert(set1->id == ZigTypeIdErrorSet);
8493 assert(set2->id == ZigTypeIdErrorSet);
84128494
84138495 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
84148496 return ira->codegen->builtin_types.entry_invalid;
......@@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
84308512 }
84318513 ZigList<ErrorTableEntry *> intersection_list = {};
84328514
8433 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
8515 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
84348516 buf_resize(&err_set_type->name, 0);
84358517 buf_appendf(&err_set_type->name, "error{");
84368518
......@@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
84598541}
84608542
84618543
8462static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *wanted_type,
8463 TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable)
8544static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,
8545 ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable)
84648546{
84658547 CodeGen *g = ira->codegen;
84668548 ConstCastOnly result = {};
......@@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
84728554 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively
84738555 // but not if we want a mutable pointer
84748556 // and not if the actual pointer has zero bits
8475 if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional &&
8476 wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
8477 actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type))
8557 if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&
8558 wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&
8559 actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))
84788560 {
84798561 ConstCastOnly child = types_match_const_cast_only(ira,
84808562 wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);
......@@ -8487,10 +8569,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
84878569 }
84888570
84898571 // *T and [*]T can always cast to *c_void
8490 if (wanted_type->id == TypeTableEntryIdPointer &&
8572 if (wanted_type->id == ZigTypeIdPointer &&
84918573 wanted_type->data.pointer.ptr_len == PtrLenSingle &&
84928574 wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&
8493 actual_type->id == TypeTableEntryIdPointer &&
8575 actual_type->id == ZigTypeIdPointer &&
84948576 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
84958577 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
84968578 {
......@@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
84998581 }
85008582
85018583 // pointer const
8502 if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) {
8584 if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) {
85038585 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
85048586 actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);
85058587 if (child.id != ConstCastResultIdOk) {
......@@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
85238605
85248606 // slice const
85258607 if (is_slice(wanted_type) && is_slice(actual_type)) {
8526 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
8527 TypeTableEntry *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
8608 ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
8609 ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
85288610 if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
85298611 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&
85308612 actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset &&
......@@ -8545,7 +8627,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
85458627 }
85468628
85478629 // maybe
8548 if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {
8630 if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) {
85498631 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,
85508632 actual_type->data.maybe.child_type, source_node, wanted_is_mutable);
85518633 if (child.id != ConstCastResultIdOk) {
......@@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
85598641 }
85608642
85618643 // error union
8562 if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {
8644 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) {
85638645 ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,
85648646 actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);
85658647 if (payload_child.id != ConstCastResultIdOk) {
......@@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
85848666 }
85858667
85868668 // error set
8587 if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {
8588 TypeTableEntry *contained_set = actual_type;
8589 TypeTableEntry *container_set = wanted_type;
8669 if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) {
8670 ZigType *contained_set = actual_type;
8671 ZigType *container_set = wanted_type;
85908672
85918673 // if the container set is inferred, then this will always work.
85928674 if (container_set->data.error_set.infer_fn != nullptr) {
......@@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
86298711 }
86308712
86318713 if (wanted_type == ira->codegen->builtin_types.entry_promise &&
8632 actual_type->id == TypeTableEntryIdPromise)
8714 actual_type->id == ZigTypeIdPromise)
86338715 {
86348716 return result;
86358717 }
86368718
86378719 // fn
8638 if (wanted_type->id == TypeTableEntryIdFn &&
8639 actual_type->id == TypeTableEntryIdFn)
8720 if (wanted_type->id == ZigTypeIdFn &&
8721 actual_type->id == ZigTypeIdFn)
86408722 {
86418723 if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
86428724 result.id = ConstCastResultIdFnAlign;
......@@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
86558737 return result;
86568738 }
86578739 if (!wanted_type->data.fn.is_generic &&
8658 actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable)
8740 actual_type->data.fn.fn_type_id.return_type->id != ZigTypeIdUnreachable)
86598741 {
86608742 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,
86618743 actual_type->data.fn.fn_type_id.return_type, source_node, false);
......@@ -8725,7 +8807,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
87258807 *errors = reallocate(*errors, old_errors_count, *errors_count);
87268808}
87278809
8728static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, TypeTableEntry *expected_type, IrInstruction **instructions, size_t instruction_count) {
8810static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, IrInstruction **instructions, size_t instruction_count) {
87298811 Error err;
87308812 assert(instruction_count >= 1);
87318813 IrInstruction *prev_inst = instructions[0];
......@@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
87348816 }
87358817 ErrorTableEntry **errors = nullptr;
87368818 size_t errors_count = 0;
8737 TypeTableEntry *err_set_type = nullptr;
8738 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
8819 ZigType *err_set_type = nullptr;
8820 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
87398821 if (type_is_global_error_set(prev_inst->value.type)) {
87408822 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
87418823 } else {
......@@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
87538835 }
87548836 }
87558837
8756 bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull);
8838 bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
87578839 bool convert_to_const_slice = false;
87588840 for (size_t i = 1; i < instruction_count; i += 1) {
87598841 IrInstruction *cur_inst = instructions[i];
8760 TypeTableEntry *cur_type = cur_inst->value.type;
8761 TypeTableEntry *prev_type = prev_inst->value.type;
8842 ZigType *cur_type = cur_inst->value.type;
8843 ZigType *prev_type = prev_inst->value.type;
87628844
87638845 if (type_is_invalid(cur_type)) {
87648846 return cur_type;
87658847 }
87668848
8767 if (prev_type->id == TypeTableEntryIdUnreachable) {
8849 if (prev_type->id == ZigTypeIdUnreachable) {
87688850 prev_inst = cur_inst;
87698851 continue;
87708852 }
87718853
8772 if (cur_type->id == TypeTableEntryIdUnreachable) {
8854 if (cur_type->id == ZigTypeIdUnreachable) {
87738855 continue;
87748856 }
87758857
8776 if (prev_type->id == TypeTableEntryIdErrorSet) {
8858 if (prev_type->id == ZigTypeIdErrorSet) {
87778859 assert(err_set_type != nullptr);
8778 if (cur_type->id == TypeTableEntryIdErrorSet) {
8860 if (cur_type->id == ZigTypeIdErrorSet) {
87798861 if (type_is_global_error_set(err_set_type)) {
87808862 continue;
87818863 }
......@@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
88398921 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);
88408922 assert(errors != nullptr);
88418923 continue;
8842 } else if (cur_type->id == TypeTableEntryIdErrorUnion) {
8924 } else if (cur_type->id == ZigTypeIdErrorUnion) {
88438925 if (type_is_global_error_set(err_set_type)) {
88448926 prev_inst = cur_inst;
88458927 continue;
88468928 }
8847 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
8929 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
88488930 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
88498931 return ira->codegen->builtin_types.entry_invalid;
88508932 }
......@@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
88978979 }
88988980 }
88998981
8900 if (cur_type->id == TypeTableEntryIdErrorSet) {
8901 if (prev_type->id == TypeTableEntryIdArray) {
8982 if (cur_type->id == ZigTypeIdErrorSet) {
8983 if (prev_type->id == ZigTypeIdArray) {
89028984 convert_to_const_slice = true;
89038985 }
89048986 if (type_is_global_error_set(cur_type)) {
......@@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
89158997 update_errors_helper(ira->codegen, &errors, &errors_count);
89168998
89178999 if (err_set_type == nullptr) {
8918 if (prev_type->id == TypeTableEntryIdErrorUnion) {
9000 if (prev_type->id == ZigTypeIdErrorUnion) {
89199001 err_set_type = prev_type->data.error_union.err_set_type;
89209002 } else {
89219003 err_set_type = cur_type;
......@@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
89489030 continue;
89499031 }
89509032
8951 if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) {
8952 TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type;
8953 TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type;
9033 if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) {
9034 ZigType *prev_payload_type = prev_type->data.error_union.payload_type;
9035 ZigType *cur_payload_type = cur_type->data.error_union.payload_type;
89549036
89559037 bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type,
89569038 source_node, false).id == ConstCastResultIdOk;
......@@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
89629044 prev_inst = cur_inst;
89639045 }
89649046
8965 TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
8966 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
9047 ZigType *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
9048 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
89679049
89689050 if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
89699051 return ira->codegen->builtin_types.entry_invalid;
......@@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
90329114 }
90339115 }
90349116
9035 if (prev_type->id == TypeTableEntryIdNull) {
9117 if (prev_type->id == ZigTypeIdNull) {
90369118 prev_inst = cur_inst;
90379119 continue;
90389120 }
90399121
9040 if (cur_type->id == TypeTableEntryIdNull) {
9122 if (cur_type->id == ZigTypeIdNull) {
90419123 any_are_null = true;
90429124 continue;
90439125 }
......@@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
90519133 continue;
90529134 }
90539135
9054 if (prev_type->id == TypeTableEntryIdInt &&
9055 cur_type->id == TypeTableEntryIdInt &&
9136 if (prev_type->id == ZigTypeIdInt &&
9137 cur_type->id == ZigTypeIdInt &&
90569138 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)
90579139 {
90589140 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {
......@@ -9061,26 +9143,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
90619143 continue;
90629144 }
90639145
9064 if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) {
9146 if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) {
90659147 if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {
90669148 prev_inst = cur_inst;
90679149 }
90689150 continue;
90699151 }
90709152
9071 if (prev_type->id == TypeTableEntryIdErrorUnion &&
9153 if (prev_type->id == ZigTypeIdErrorUnion &&
90729154 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,
90739155 source_node, false).id == ConstCastResultIdOk)
90749156 {
90759157 continue;
90769158 }
90779159
9078 if (cur_type->id == TypeTableEntryIdErrorUnion &&
9160 if (cur_type->id == ZigTypeIdErrorUnion &&
90799161 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,
90809162 source_node, false).id == ConstCastResultIdOk)
90819163 {
90829164 if (err_set_type != nullptr) {
9083 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
9165 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
90849166 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
90859167 return ira->codegen->builtin_types.entry_invalid;
90869168 }
......@@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
90989180 continue;
90999181 }
91009182
9101 if (prev_type->id == TypeTableEntryIdOptional &&
9183 if (prev_type->id == ZigTypeIdOptional &&
91029184 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,
91039185 source_node, false).id == ConstCastResultIdOk)
91049186 {
91059187 continue;
91069188 }
91079189
9108 if (cur_type->id == TypeTableEntryIdOptional &&
9190 if (cur_type->id == ZigTypeIdOptional &&
91099191 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,
91109192 source_node, false).id == ConstCastResultIdOk)
91119193 {
......@@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91139195 continue;
91149196 }
91159197
9116 if (cur_type->id == TypeTableEntryIdUndefined) {
9198 if (cur_type->id == ZigTypeIdUndefined) {
91179199 continue;
91189200 }
91199201
9120 if (prev_type->id == TypeTableEntryIdUndefined) {
9202 if (prev_type->id == ZigTypeIdUndefined) {
91219203 prev_inst = cur_inst;
91229204 continue;
91239205 }
91249206
9125 if (prev_type->id == TypeTableEntryIdComptimeInt ||
9126 prev_type->id == TypeTableEntryIdComptimeFloat)
9207 if (prev_type->id == ZigTypeIdComptimeInt ||
9208 prev_type->id == ZigTypeIdComptimeFloat)
91279209 {
91289210 if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {
91299211 prev_inst = cur_inst;
......@@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91339215 }
91349216 }
91359217
9136 if (cur_type->id == TypeTableEntryIdComptimeInt ||
9137 cur_type->id == TypeTableEntryIdComptimeFloat)
9218 if (cur_type->id == ZigTypeIdComptimeInt ||
9219 cur_type->id == ZigTypeIdComptimeFloat)
91389220 {
91399221 if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {
91409222 continue;
......@@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91439225 }
91449226 }
91459227
9146 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
9228 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
91479229 cur_type->data.array.len != prev_type->data.array.len &&
91489230 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
91499231 source_node, false).id == ConstCastResultIdOk)
......@@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91539235 continue;
91549236 }
91559237
9156 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
9238 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
91579239 cur_type->data.array.len != prev_type->data.array.len &&
91589240 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
91599241 source_node, false).id == ConstCastResultIdOk)
......@@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91629244 continue;
91639245 }
91649246
9165 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
9247 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
91669248 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
91679249 cur_type->data.array.len == 0) &&
91689250 types_match_const_cast_only(ira,
......@@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91739255 continue;
91749256 }
91759257
9176 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
9258 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
91779259 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
91789260 prev_type->data.array.len == 0) &&
91799261 types_match_const_cast_only(ira,
......@@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91859267 continue;
91869268 }
91879269
9188 if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion &&
9270 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
91899271 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
91909272 {
91919273 if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type)))
......@@ -9195,7 +9277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
91959277 }
91969278 }
91979279
9198 if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion &&
9280 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion &&
91999281 (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
92009282 {
92019283 if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type)))
......@@ -9220,33 +9302,33 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
92209302 free(errors);
92219303
92229304 if (convert_to_const_slice) {
9223 assert(prev_inst->value.type->id == TypeTableEntryIdArray);
9224 TypeTableEntry *ptr_type = get_pointer_to_type_extra(
9305 assert(prev_inst->value.type->id == ZigTypeIdArray);
9306 ZigType *ptr_type = get_pointer_to_type_extra(
92259307 ira->codegen, prev_inst->value.type->data.array.child_type,
92269308 true, false, PtrLenUnknown,
92279309 get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),
92289310 0, 0);
9229 TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type);
9311 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
92309312 if (err_set_type != nullptr) {
92319313 return get_error_union_type(ira->codegen, err_set_type, slice_type);
92329314 } else {
92339315 return slice_type;
92349316 }
92359317 } else if (err_set_type != nullptr) {
9236 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
9318 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
92379319 return err_set_type;
9238 } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) {
9320 } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {
92399321 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type);
9240 } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) {
9322 } else if (expected_type != nullptr && expected_type->id == ZigTypeIdErrorUnion) {
92419323 return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);
92429324 } else {
9243 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
9244 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
9325 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9326 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
92459327 {
92469328 ir_add_error_node(ira, source_node,
92479329 buf_sprintf("unable to make error union out of number literal"));
92489330 return ira->codegen->builtin_types.entry_invalid;
9249 } else if (prev_inst->value.type->id == TypeTableEntryIdNull) {
9331 } else if (prev_inst->value.type->id == ZigTypeIdNull) {
92509332 ir_add_error_node(ira, source_node,
92519333 buf_sprintf("unable to make error union out of null literal"));
92529334 return ira->codegen->builtin_types.entry_invalid;
......@@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
92549336 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);
92559337 }
92569338 }
9257 } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) {
9258 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
9259 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
9339 } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {
9340 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9341 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
92609342 {
92619343 ir_add_error_node(ira, source_node,
92629344 buf_sprintf("unable to make maybe out of number literal"));
92639345 return ira->codegen->builtin_types.entry_invalid;
9264 } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) {
9346 } else if (prev_inst->value.type->id == ZigTypeIdOptional) {
92659347 return prev_inst->value.type;
92669348 } else {
92679349 return get_optional_type(ira->codegen, prev_inst->value.type);
......@@ -9271,9 +9353,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
92719353 }
92729354}
92739355
9274static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *type_entry) {
9356static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) {
92759357 if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) {
9276 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
9358 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
92779359 if (fn_entry != nullptr) {
92789360 fn_entry->alloca_list.append(instruction);
92799361 }
......@@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
92859367 *dest = *src;
92869368 if (!same_global_refs) {
92879369 dest->global_refs = global_refs;
9288 if (dest->type->id == TypeTableEntryIdStruct) {
9370 if (dest->type->id == ZigTypeIdStruct) {
92899371 dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);
92909372 memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);
92919373 }
......@@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
92949376
92959377static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
92969378 CastOp cast_op,
9297 ConstExprValue *other_val, TypeTableEntry *other_type,
9298 ConstExprValue *const_val, TypeTableEntry *new_type)
9379 ConstExprValue *other_val, ZigType *other_type,
9380 ConstExprValue *const_val, ZigType *new_type)
92999381{
93009382 const_val->special = other_val->special;
93019383
......@@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
93159397 break;
93169398 }
93179399 case CastOpNumLitToConcrete:
9318 if (other_val->type->id == TypeTableEntryIdComptimeFloat) {
9319 assert(new_type->id == TypeTableEntryIdFloat);
9400 if (other_val->type->id == ZigTypeIdComptimeFloat) {
9401 assert(new_type->id == ZigTypeIdFloat);
93209402 switch (new_type->data.floating.bit_count) {
93219403 case 16:
93229404 const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat);
......@@ -9333,7 +9415,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
93339415 default:
93349416 zig_unreachable();
93359417 }
9336 } else if (other_val->type->id == TypeTableEntryIdComptimeInt) {
9418 } else if (other_val->type->id == ZigTypeIdComptimeInt) {
93379419 bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);
93389420 } else {
93399421 zig_unreachable();
......@@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
93469428 zig_unreachable();
93479429 case CastOpIntToFloat:
93489430 {
9349 assert(new_type->id == TypeTableEntryIdFloat);
9431 assert(new_type->id == ZigTypeIdFloat);
93509432
93519433 BigFloat bigfloat;
93529434 bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);
......@@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
93719453 }
93729454 case CastOpFloatToInt:
93739455 float_init_bigint(&const_val->data.x_bigint, other_val);
9374 if (new_type->id == TypeTableEntryIdInt) {
9456 if (new_type->id == ZigTypeIdInt) {
93759457 if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,
93769458 new_type->data.integral.is_signed))
93779459 {
......@@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
93959477 return true;
93969478}
93979479static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
9398 TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca)
9480 ZigType *wanted_type, CastOp cast_op, bool need_alloca)
93999481{
94009482 if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) &&
94019483 cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice)
......@@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
94199501}
94209502
94219503static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
9422 IrInstruction *value, TypeTableEntry *wanted_type)
9504 IrInstruction *value, ZigType *wanted_type)
94239505{
9424 assert(value->value.type->id == TypeTableEntryIdPointer);
9506 assert(value->value.type->id == ZigTypeIdPointer);
94259507 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
94269508
94279509 if (instr_is_comptime(value)) {
9428 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value);
9510 ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);
9511 if (pointee == nullptr)
9512 return ira->codegen->invalid_instruction;
94299513 if (pointee->special != ConstValSpecialRuntime) {
94309514 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
94319515 source_instr->source_node, wanted_type);
......@@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
94469530}
94479531
94489532static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
9449 IrInstruction *value, TypeTableEntry *wanted_type)
9533 IrInstruction *value, ZigType *wanted_type)
94509534{
94519535 wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
94529536
94539537 if (instr_is_comptime(value)) {
9454 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value);
9538 ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);
9539 if (pointee == nullptr)
9540 return ira->codegen->invalid_instruction;
94559541 if (pointee->special != ConstValSpecialRuntime) {
9456 assert(value->value.type->id == TypeTableEntryIdPointer);
9457 TypeTableEntry *array_type = value->value.type->data.pointer.child_type;
9542 assert(value->value.type->id == ZigTypeIdPointer);
9543 ZigType *array_type = value->value.type->data.pointer.child_type;
94589544 assert(is_slice(wanted_type));
94599545 bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
94609546
......@@ -9475,10 +9561,10 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
94759561 return result;
94769562}
94779563
9478static bool is_container(TypeTableEntry *type) {
9479 return type->id == TypeTableEntryIdStruct ||
9480 type->id == TypeTableEntryIdEnum ||
9481 type->id == TypeTableEntryIdUnion;
9564static bool is_container(ZigType *type) {
9565 return type->id == ZigTypeIdStruct ||
9566 type->id == ZigTypeIdEnum ||
9567 type->id == ZigTypeIdUnion;
94829568}
94839569
94849570static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
......@@ -9496,6 +9582,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr
94969582 return new_bb;
94979583}
94989584
9585static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
9586 assert(ref_old_instruction != nullptr);
9587 IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
9588 if (new_bb->must_be_comptime_source_instr) {
9589 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
9590 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
9591 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
9592 buf_sprintf("compile-time variable assigned here"));
9593 return nullptr;
9594 }
9595 return new_bb;
9596}
9597
94999598static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
95009599 ira->instruction_index = 0;
95019600 ira->old_irb.current_basic_block = old_bb;
......@@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
95419640 }
95429641}
95439642
9544static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) {
9643static ZigType *ir_unreach_error(IrAnalyze *ira) {
95459644 ira->old_bb_index = SIZE_MAX;
95469645 ira->new_irb.exec->invalid = true;
95479646 return ira->codegen->builtin_types.entry_unreachable;
......@@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
95649663 return true;
95659664}
95669665
9567static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
9666static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
95689667 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
95699668 if (!ir_emit_backward_branch(ira, source_instruction))
95709669 return ir_unreach_error(ira);
......@@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru
95759674 return ira->codegen->builtin_types.entry_unreachable;
95769675}
95779676
9578static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) {
9579 if (result_type->id == TypeTableEntryIdUnreachable)
9677static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) {
9678 if (result_type->id == ZigTypeIdUnreachable)
95809679 ir_finish_bb(ira);
95819680 return result_type;
95829681}
......@@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in
95959694 return &new_instruction->value;
95969695}
95979696
9598static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
9697static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
95999698 ir_build_const_from(ira, instruction);
96009699 return ira->codegen->builtin_types.entry_void;
96019700}
96029701
96039702static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
9604 ConstExprValue *pointee, TypeTableEntry *pointee_type,
9703 ConstExprValue *pointee, ZigType *pointee_type,
96059704 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
96069705{
9607 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
9706 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
96089707 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);
96099708 IrInstruction *const_instr = ir_get_const(ira, instruction);
96109709 ConstExprValue *const_val = &const_instr->value;
......@@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
96159714 return const_instr;
96169715}
96179716
9618static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
9619 ConstExprValue *pointee, TypeTableEntry *pointee_type,
9717static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
9718 ConstExprValue *pointee, ZigType *pointee_type,
96209719 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile)
96219720{
96229721 IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee,
......@@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
96269725 return const_instr->value.type;
96279726}
96289727
9629static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) {
9728static ZigType *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) {
96309729 ConstExprValue *const_val = ir_build_const_from(ira, instruction);
96319730 bigint_init_unsigned(&const_val->data.x_bigint, value);
96329731 return ira->codegen->builtin_types.entry_usize;
......@@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
96599758}
96609759
96619760IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
9662 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
9663 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
9761 ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
9762 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
96649763 IrExecutable *parent_exec)
96659764{
96669765 if (expected_type != nullptr && type_is_invalid(expected_type))
......@@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
96979796 analyzed_executable->backward_branch_count = backward_branch_count;
96989797 analyzed_executable->backward_branch_quota = backward_branch_quota;
96999798 analyzed_executable->begin_scope = scope;
9700 TypeTableEntry *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node);
9799 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node);
97019800 if (type_is_invalid(result_type))
97029801 return codegen->invalid_instruction;
97039802
......@@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
97109809 return ir_exec_const_result(codegen, analyzed_executable);
97119810}
97129811
9713static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
9812static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
97149813 if (type_is_invalid(type_value->value.type))
97159814 return ira->codegen->builtin_types.entry_invalid;
97169815
9717 if (type_value->value.type->id != TypeTableEntryIdMetaType) {
9816 if (type_value->value.type->id != ZigTypeIdMetaType) {
97189817 ir_add_error(ira, type_value,
97199818 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
97209819 return ira->codegen->builtin_types.entry_invalid;
......@@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value
97279826 return const_val->data.x_type;
97289827}
97299828
9730static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9829static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
97319830 if (fn_value == ira->codegen->invalid_instruction)
97329831 return nullptr;
97339832
97349833 if (type_is_invalid(fn_value->value.type))
97359834 return nullptr;
97369835
9737 if (fn_value->value.type->id != TypeTableEntryIdFn) {
9836 if (fn_value->value.type->id != ZigTypeIdFn) {
97389837 ir_add_error_node(ira, fn_value->source_node,
97399838 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));
97409839 return nullptr;
......@@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
97489847 return const_val->data.x_ptr.data.fn.fn_entry;
97499848}
97509849
9751static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
9752 assert(wanted_type->id == TypeTableEntryIdOptional);
9850static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9851 assert(wanted_type->id == ZigTypeIdOptional);
97539852
97549853 if (instr_is_comptime(value)) {
9755 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
9854 ZigType *payload_type = wanted_type->data.maybe.child_type;
97569855 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
97579856 if (type_is_invalid(casted_payload->value.type))
97589857 return ira->codegen->invalid_instruction;
......@@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
97819880}
97829881
97839882static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
9784 IrInstruction *value, TypeTableEntry *wanted_type)
9883 IrInstruction *value, ZigType *wanted_type)
97859884{
9786 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
9885 assert(wanted_type->id == ZigTypeIdErrorUnion);
97879886
97889887 if (instr_is_comptime(value)) {
9789 TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
9888 ZigType *payload_type = wanted_type->data.error_union.payload_type;
97909889 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
97919890 if (type_is_invalid(casted_payload->value.type))
97929891 return ira->codegen->invalid_instruction;
......@@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
98129911}
98139912
98149913static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
9815 TypeTableEntry *wanted_type)
9914 ZigType *wanted_type)
98169915{
9817 assert(value->value.type->id == TypeTableEntryIdErrorSet);
9818 assert(wanted_type->id == TypeTableEntryIdErrorSet);
9916 assert(value->value.type->id == ZigTypeIdErrorSet);
9917 assert(wanted_type->id == ZigTypeIdErrorSet);
98199918
98209919 if (instr_is_comptime(value)) {
98219920 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
98549953 return result;
98559954}
98569955
9857static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
9858 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
9956static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9957 assert(wanted_type->id == ZigTypeIdErrorUnion);
98599958
98609959 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
98619960
......@@ -9881,7 +9980,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
98819980}
98829981
98839982static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr,
9884 IrInstruction *value, TypeTableEntry *wanted_type)
9983 IrInstruction *value, ZigType *wanted_type)
98859984{
98869985 if (instr_is_comptime(value)) {
98879986 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
990510004 source_instr->source_node, value, true, false);
990610005 new_instruction->value.type = wanted_type;
990710006
9908 TypeTableEntry *child_type = wanted_type->data.pointer.child_type;
10007 ZigType *child_type = wanted_type->data.pointer.child_type;
990910008 if (type_has_bits(child_type)) {
9910 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
10009 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
991110010 assert(fn_entry);
991210011 fn_entry->alloca_list.append(new_instruction);
991310012 }
......@@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
991610015 }
991710016}
991810017
9919static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
9920 assert(wanted_type->id == TypeTableEntryIdOptional);
10018static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
10019 assert(wanted_type->id == ZigTypeIdOptional);
992110020 assert(instr_is_comptime(value));
992210021
992310022 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
995010049 get_abi_alignment(ira->codegen, value->value.type));
995110050 }
995210051
9953 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
10052 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
995410053 is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
995510054 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
995610055 source_instruction->source_node, value, is_const, is_volatile);
995710056 new_instruction->value.type = ptr_type;
995810057 new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;
995910058 if (type_has_bits(ptr_type)) {
9960 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
10059 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
996110060 assert(fn_entry);
996210061 fn_entry->alloca_list.append(new_instruction);
996310062 }
......@@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
996510064}
996610065
996710066static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
9968 IrInstruction *array_arg, TypeTableEntry *wanted_type)
10067 IrInstruction *array_arg, ZigType *wanted_type)
996910068{
997010069 assert(is_slice(wanted_type));
997110070 // In this function we honor the const-ness of wanted_type, because
......@@ -9973,14 +10072,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
997310072
997410073 IrInstruction *array_ptr = nullptr;
997510074 IrInstruction *array;
9976 if (array_arg->value.type->id == TypeTableEntryIdPointer) {
10075 if (array_arg->value.type->id == ZigTypeIdPointer) {
997710076 array = ir_get_deref(ira, source_instr, array_arg);
997810077 array_ptr = array_arg;
997910078 } else {
998010079 array = array_arg;
998110080 }
9982 TypeTableEntry *array_type = array->value.type;
9983 assert(array_type->id == TypeTableEntryIdArray);
10081 ZigType *array_type = array->value.type;
10082 assert(array_type->id == ZigTypeIdArray);
998410083
998510084 if (instr_is_comptime(array)) {
998610085 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
......@@ -10011,12 +10110,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1001110110}
1001210111
1001310112static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr,
10014 IrInstruction *target, TypeTableEntry *wanted_type)
10113 IrInstruction *target, ZigType *wanted_type)
1001510114{
1001610115 Error err;
10017 assert(wanted_type->id == TypeTableEntryIdInt);
10116 assert(wanted_type->id == ZigTypeIdInt);
1001810117
10019 TypeTableEntry *actual_type = target->value.type;
10118 ZigType *actual_type = target->value.type;
1002010119 if ((err = ensure_complete_type(ira->codegen, actual_type)))
1002110120 return ira->codegen->invalid_instruction;
1002210121
......@@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1002810127 return ira->codegen->invalid_instruction;
1002910128 }
1003010129
10031 assert(actual_type->id == TypeTableEntryIdEnum);
10130 assert(actual_type->id == ZigTypeIdEnum);
1003210131
1003310132 if (instr_is_comptime(target)) {
1003410133 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
......@@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1004710146}
1004810147
1004910148static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
10050 IrInstruction *target, TypeTableEntry *wanted_type)
10149 IrInstruction *target, ZigType *wanted_type)
1005110150{
10052 assert(target->value.type->id == TypeTableEntryIdUnion);
10053 assert(wanted_type->id == TypeTableEntryIdEnum);
10151 assert(target->value.type->id == ZigTypeIdUnion);
10152 assert(wanted_type->id == ZigTypeIdEnum);
1005410153 assert(wanted_type == target->value.type->data.unionation.tag_type);
1005510154
1005610155 if (instr_is_comptime(target)) {
......@@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1007210171}
1007310172
1007410173static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,
10075 IrInstruction *target, TypeTableEntry *wanted_type)
10174 IrInstruction *target, ZigType *wanted_type)
1007610175{
1007710176 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
1007810177 source_instr->source_node, wanted_type);
......@@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
1008110180}
1008210181
1008310182static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,
10084 IrInstruction *target, TypeTableEntry *wanted_type)
10183 IrInstruction *target, ZigType *wanted_type)
1008510184{
1008610185 Error err;
10087 assert(wanted_type->id == TypeTableEntryIdUnion);
10088 assert(target->value.type->id == TypeTableEntryIdEnum);
10186 assert(wanted_type->id == ZigTypeIdUnion);
10187 assert(target->value.type->id == ZigTypeIdEnum);
1008910188
1009010189 if (instr_is_comptime(target)) {
1009110190 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
......@@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1014010239}
1014110240
1014210241static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
10143 IrInstruction *target, TypeTableEntry *wanted_type)
10242 IrInstruction *target, ZigType *wanted_type)
1014410243{
10145 assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat);
10244 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1014610245
1014710246 if (instr_is_comptime(target)) {
1014810247 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
1014910248 if (!val)
1015010249 return ira->codegen->invalid_instruction;
10151 if (wanted_type->id == TypeTableEntryIdInt) {
10250 if (wanted_type->id == ZigTypeIdInt) {
1015210251 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
1015310252 ir_add_error(ira, source_instr,
1015410253 buf_sprintf("attempt to cast negative value to unsigned integer"));
......@@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1016610265 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
1016710266 source_instr->source_node, wanted_type);
1016810267 result->value.type = wanted_type;
10169 if (wanted_type->id == TypeTableEntryIdInt) {
10268 if (wanted_type->id == ZigTypeIdInt) {
1017010269 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
1017110270 } else {
1017210271 float_init_float(&result->value, val);
......@@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1018110280}
1018210281
1018310282static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,
10184 IrInstruction *target, TypeTableEntry *wanted_type)
10283 IrInstruction *target, ZigType *wanted_type)
1018510284{
1018610285 Error err;
10187 assert(wanted_type->id == TypeTableEntryIdEnum);
10286 assert(wanted_type->id == ZigTypeIdEnum);
1018810287
10189 TypeTableEntry *actual_type = target->value.type;
10288 ZigType *actual_type = target->value.type;
1019010289
1019110290 if ((err = ensure_complete_type(ira->codegen, wanted_type)))
1019210291 return ira->codegen->invalid_instruction;
......@@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1019910298 return ira->codegen->invalid_instruction;
1020010299 }
1020110300
10202 assert(actual_type->id == TypeTableEntryIdInt);
10301 assert(actual_type->id == ZigTypeIdInt);
1020310302
1020410303 if (instr_is_comptime(target)) {
1020510304 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
......@@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1023110330}
1023210331
1023310332static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
10234 IrInstruction *target, TypeTableEntry *wanted_type)
10333 IrInstruction *target, ZigType *wanted_type)
1023510334{
1023610335 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
1023710336 if (!val)
......@@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1023910338
1024010339 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
1024110340 source_instr->source_node, wanted_type);
10242 if (wanted_type->id == TypeTableEntryIdComptimeFloat) {
10341 if (wanted_type->id == ZigTypeIdComptimeFloat) {
1024310342 float_init_float(&result->value, val);
10244 } else if (wanted_type->id == TypeTableEntryIdComptimeInt) {
10343 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
1024510344 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
1024610345 } else {
1024710346 zig_unreachable();
......@@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1025010349}
1025110350
1025210351static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10253 TypeTableEntry *wanted_type)
10352 ZigType *wanted_type)
1025410353{
10255 assert(target->value.type->id == TypeTableEntryIdInt);
10354 assert(target->value.type->id == ZigTypeIdInt);
1025610355 assert(!target->value.type->data.integral.is_signed);
10257 assert(wanted_type->id == TypeTableEntryIdErrorSet);
10356 assert(wanted_type->id == ZigTypeIdErrorSet);
1025810357
1025910358 if (instr_is_comptime(target)) {
1026010359 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
......@@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1031510414}
1031610415
1031710416static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10318 TypeTableEntry *wanted_type)
10417 ZigType *wanted_type)
1031910418{
10320 assert(wanted_type->id == TypeTableEntryIdInt);
10419 assert(wanted_type->id == ZigTypeIdInt);
1032110420
10322 TypeTableEntry *err_type = target->value.type;
10421 ZigType *err_type = target->value.type;
1032310422
1032410423 if (instr_is_comptime(target)) {
1032510424 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
......@@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1033010429 source_instr->source_node, wanted_type);
1033110430
1033210431 ErrorTableEntry *err;
10333 if (err_type->id == TypeTableEntryIdErrorUnion) {
10432 if (err_type->id == ZigTypeIdErrorUnion) {
1033410433 err = val->data.x_err_union.err;
10335 } else if (err_type->id == TypeTableEntryIdErrorSet) {
10434 } else if (err_type->id == ZigTypeIdErrorSet) {
1033610435 err = val->data.x_err_set;
1033710436 } else {
1033810437 zig_unreachable();
......@@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1035310452 return result;
1035410453 }
1035510454
10356 TypeTableEntry *err_set_type;
10357 if (err_type->id == TypeTableEntryIdErrorUnion) {
10455 ZigType *err_set_type;
10456 if (err_type->id == ZigTypeIdErrorUnion) {
1035810457 err_set_type = err_type->data.error_union.err_set_type;
10359 } else if (err_type->id == TypeTableEntryIdErrorSet) {
10458 } else if (err_type->id == ZigTypeIdErrorSet) {
1036010459 err_set_type = err_type;
1036110460 } else {
1036210461 zig_unreachable();
......@@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1039510494}
1039610495
1039710496static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10398 TypeTableEntry *wanted_type)
10497 ZigType *wanted_type)
1039910498{
10400 assert(wanted_type->id == TypeTableEntryIdPointer);
10499 assert(wanted_type->id == ZigTypeIdPointer);
1040110500 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment);
10402 TypeTableEntry *array_type = wanted_type->data.pointer.child_type;
10403 assert(array_type->id == TypeTableEntryIdArray);
10501 ZigType *array_type = wanted_type->data.pointer.child_type;
10502 assert(array_type->id == ZigTypeIdArray);
1040410503 assert(array_type->data.array.len == 1);
1040510504
1040610505 if (instr_is_comptime(target)) {
......@@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1040810507 if (!val)
1040910508 return ira->codegen->invalid_instruction;
1041010509
10411 assert(val->type->id == TypeTableEntryIdPointer);
10412 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, val);
10510 assert(val->type->id == ZigTypeIdPointer);
10511 ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);
10512 if (pointee == nullptr)
10513 return ira->codegen->invalid_instruction;
1041310514 if (pointee->special != ConstValSpecialRuntime) {
1041410515 ConstExprValue *array_val = create_const_vals(1);
1041510516 array_val->special = ConstValSpecialStatic;
......@@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1052910630}
1053010631
1053110632static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
10532 TypeTableEntry *wanted_type, IrInstruction *value)
10633 ZigType *wanted_type, IrInstruction *value)
1053310634{
1053410635 Error err;
10535 TypeTableEntry *actual_type = value->value.type;
10636 ZigType *actual_type = value->value.type;
1053610637 AstNode *source_node = source_instr->source_node;
1053710638
1053810639 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
......@@ -10547,8 +10648,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1054710648 }
1054810649
1054910650 // widening conversion
10550 if (wanted_type->id == TypeTableEntryIdInt &&
10551 actual_type->id == TypeTableEntryIdInt &&
10651 if (wanted_type->id == ZigTypeIdInt &&
10652 actual_type->id == ZigTypeIdInt &&
1055210653 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
1055310654 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
1055410655 {
......@@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1055610657 }
1055710658
1055810659 // small enough unsigned ints can get casted to large enough signed ints
10559 if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed &&
10560 actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed &&
10660 if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed &&
10661 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
1056110662 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
1056210663 {
1056310664 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
1056410665 }
1056510666
1056610667 // float widening conversion
10567 if (wanted_type->id == TypeTableEntryIdFloat &&
10568 actual_type->id == TypeTableEntryIdFloat &&
10668 if (wanted_type->id == ZigTypeIdFloat &&
10669 actual_type->id == ZigTypeIdFloat &&
1056910670 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
1057010671 {
1057110672 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
......@@ -10573,9 +10674,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1057310674
1057410675
1057510676 // cast from [N]T to []const T
10576 if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) {
10577 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10578 assert(ptr_type->id == TypeTableEntryIdPointer);
10677 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
10678 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10679 assert(ptr_type->id == ZigTypeIdPointer);
1057910680 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1058010681 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
1058110682 source_node, false).id == ConstCastResultIdOk)
......@@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1058610687
1058710688 // cast from *const [N]T to []const T
1058810689 if (is_slice(wanted_type) &&
10589 actual_type->id == TypeTableEntryIdPointer &&
10690 actual_type->id == ZigTypeIdPointer &&
1059010691 actual_type->data.pointer.is_const &&
10591 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)
10692 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1059210693 {
10593 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10594 assert(ptr_type->id == TypeTableEntryIdPointer);
10694 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10695 assert(ptr_type->id == ZigTypeIdPointer);
1059510696
10596 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
10697 ZigType *array_type = actual_type->data.pointer.child_type;
1059710698
1059810699 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
1059910700 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type,
......@@ -10604,14 +10705,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1060410705 }
1060510706
1060610707 // cast from [N]T to *const []const T
10607 if (wanted_type->id == TypeTableEntryIdPointer &&
10708 if (wanted_type->id == ZigTypeIdPointer &&
1060810709 wanted_type->data.pointer.is_const &&
1060910710 is_slice(wanted_type->data.pointer.child_type) &&
10610 actual_type->id == TypeTableEntryIdArray)
10711 actual_type->id == ZigTypeIdArray)
1061110712 {
10612 TypeTableEntry *ptr_type =
10713 ZigType *ptr_type =
1061310714 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
10614 assert(ptr_type->id == TypeTableEntryIdPointer);
10715 assert(ptr_type->id == ZigTypeIdPointer);
1061510716 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1061610717 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
1061710718 source_node, false).id == ConstCastResultIdOk)
......@@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1062910730 }
1063010731
1063110732 // cast from [N]T to ?[]const T
10632 if (wanted_type->id == TypeTableEntryIdOptional &&
10733 if (wanted_type->id == ZigTypeIdOptional &&
1063310734 is_slice(wanted_type->data.maybe.child_type) &&
10634 actual_type->id == TypeTableEntryIdArray)
10735 actual_type->id == ZigTypeIdArray)
1063510736 {
10636 TypeTableEntry *ptr_type =
10737 ZigType *ptr_type =
1063710738 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
10638 assert(ptr_type->id == TypeTableEntryIdPointer);
10739 assert(ptr_type->id == ZigTypeIdPointer);
1063910740 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1064010741 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
1064110742 source_node, false).id == ConstCastResultIdOk)
......@@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1065310754 }
1065410755
1065510756 // *[N]T to [*]T
10656 if (wanted_type->id == TypeTableEntryIdPointer &&
10757 if (wanted_type->id == ZigTypeIdPointer &&
1065710758 wanted_type->data.pointer.ptr_len == PtrLenUnknown &&
10658 actual_type->id == TypeTableEntryIdPointer &&
10759 actual_type->id == ZigTypeIdPointer &&
1065910760 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10660 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&
10761 actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
1066110762 actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&
1066210763 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
1066310764 actual_type->data.pointer.child_type->data.array.child_type, source_node,
......@@ -10668,12 +10769,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1066810769
1066910770 // *[N]T to []T
1067010771 if (is_slice(wanted_type) &&
10671 actual_type->id == TypeTableEntryIdPointer &&
10772 actual_type->id == ZigTypeIdPointer &&
1067210773 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10673 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)
10774 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1067410775 {
10675 TypeTableEntry *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10676 assert(slice_ptr_type->id == TypeTableEntryIdPointer);
10776 ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10777 assert(slice_ptr_type->id == ZigTypeIdPointer);
1067710778 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
1067810779 actual_type->data.pointer.child_type->data.array.child_type, source_node,
1067910780 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)
......@@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1068510786
1068610787 // cast from T to ?T
1068710788 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism
10688 if (wanted_type->id == TypeTableEntryIdOptional) {
10689 TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;
10789 if (wanted_type->id == ZigTypeIdOptional) {
10790 ZigType *wanted_child_type = wanted_type->data.maybe.child_type;
1069010791 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
1069110792 false).id == ConstCastResultIdOk)
1069210793 {
1069310794 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
10694 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
10695 actual_type->id == TypeTableEntryIdComptimeFloat)
10795 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10796 actual_type->id == ZigTypeIdComptimeFloat)
1069610797 {
1069710798 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
1069810799 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
1069910800 } else {
1070010801 return ira->codegen->invalid_instruction;
1070110802 }
10702 } else if (wanted_child_type->id == TypeTableEntryIdPointer &&
10803 } else if (wanted_child_type->id == ZigTypeIdPointer &&
1070310804 wanted_child_type->data.pointer.is_const &&
10704 (actual_type->id == TypeTableEntryIdPointer || is_container(actual_type)))
10805 (actual_type->id == ZigTypeIdPointer || is_container(actual_type)))
1070510806 {
1070610807 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);
1070710808 if (type_is_invalid(cast1->value.type))
......@@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1071310814
1071410815 return cast2;
1071510816 } else if (
10716 wanted_child_type->id == TypeTableEntryIdPointer &&
10817 wanted_child_type->id == ZigTypeIdPointer &&
1071710818 wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&
10718 actual_type->id == TypeTableEntryIdPointer &&
10819 actual_type->id == ZigTypeIdPointer &&
1071910820 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10720 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&
10821 actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
1072110822 actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&
1072210823 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
1072310824 actual_type->data.pointer.child_type->data.array.child_type, source_node,
1072410825 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
1072510826 {
1072610827 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type);
10828 if (type_is_invalid(cast1->value.type))
10829 return ira->codegen->invalid_instruction;
1072710830 return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type);
1072810831 }
1072910832 }
1073010833
1073110834 // cast from null literal to maybe type
10732 if (wanted_type->id == TypeTableEntryIdOptional &&
10733 actual_type->id == TypeTableEntryIdNull)
10835 if (wanted_type->id == ZigTypeIdOptional &&
10836 actual_type->id == ZigTypeIdNull)
1073410837 {
1073510838 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
1073610839 }
1073710840
1073810841 // cast from child type of error type to error type
10739 if (wanted_type->id == TypeTableEntryIdErrorUnion) {
10842 if (wanted_type->id == ZigTypeIdErrorUnion) {
1074010843 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
1074110844 source_node, false).id == ConstCastResultIdOk)
1074210845 {
1074310846 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
10744 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
10745 actual_type->id == TypeTableEntryIdComptimeFloat)
10847 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10848 actual_type->id == ZigTypeIdComptimeFloat)
1074610849 {
1074710850 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
1074810851 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
......@@ -10753,13 +10856,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1075310856 }
1075410857
1075510858 // cast from [N]T to E![]const T
10756 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
10859 if (wanted_type->id == ZigTypeIdErrorUnion &&
1075710860 is_slice(wanted_type->data.error_union.payload_type) &&
10758 actual_type->id == TypeTableEntryIdArray)
10861 actual_type->id == ZigTypeIdArray)
1075910862 {
10760 TypeTableEntry *ptr_type =
10863 ZigType *ptr_type =
1076110864 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
10762 assert(ptr_type->id == TypeTableEntryIdPointer);
10865 assert(ptr_type->id == ZigTypeIdPointer);
1076310866 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1076410867 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
1076510868 source_node, false).id == ConstCastResultIdOk)
......@@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1077710880 }
1077810881
1077910882 // cast from error set to error union type
10780 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
10781 actual_type->id == TypeTableEntryIdErrorSet)
10883 if (wanted_type->id == ZigTypeIdErrorUnion &&
10884 actual_type->id == ZigTypeIdErrorSet)
1078210885 {
1078310886 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);
1078410887 }
1078510888
1078610889 // cast from T to E!?T
10787 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
10788 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&
10789 actual_type->id != TypeTableEntryIdOptional)
10890 if (wanted_type->id == ZigTypeIdErrorUnion &&
10891 wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional &&
10892 actual_type->id != ZigTypeIdOptional)
1079010893 {
10791 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
10894 ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
1079210895 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||
10793 actual_type->id == TypeTableEntryIdNull ||
10794 actual_type->id == TypeTableEntryIdComptimeInt ||
10795 actual_type->id == TypeTableEntryIdComptimeFloat)
10896 actual_type->id == ZigTypeIdNull ||
10897 actual_type->id == ZigTypeIdComptimeInt ||
10898 actual_type->id == ZigTypeIdComptimeFloat)
1079610899 {
1079710900 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
1079810901 if (type_is_invalid(cast1->value.type))
......@@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1080810911
1080910912 // cast from number literal to another type
1081010913 // cast from number literal to *const integer
10811 if (actual_type->id == TypeTableEntryIdComptimeFloat ||
10812 actual_type->id == TypeTableEntryIdComptimeInt)
10914 if (actual_type->id == ZigTypeIdComptimeFloat ||
10915 actual_type->id == ZigTypeIdComptimeInt)
1081310916 {
1081410917 if ((err = ensure_complete_type(ira->codegen, wanted_type)))
1081510918 return ira->codegen->invalid_instruction;
10816 if (wanted_type->id == TypeTableEntryIdEnum) {
10919 if (wanted_type->id == ZigTypeIdEnum) {
1081710920 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
1081810921 if (type_is_invalid(cast1->value.type))
1081910922 return ira->codegen->invalid_instruction;
......@@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1082310926 return ira->codegen->invalid_instruction;
1082410927
1082510928 return cast2;
10826 } else if (wanted_type->id == TypeTableEntryIdPointer &&
10929 } else if (wanted_type->id == ZigTypeIdPointer &&
1082710930 wanted_type->data.pointer.is_const)
1082810931 {
1082910932 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
......@@ -10837,15 +10940,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1083710940 return cast2;
1083810941 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
1083910942 CastOp op;
10840 if ((actual_type->id == TypeTableEntryIdComptimeFloat &&
10841 wanted_type->id == TypeTableEntryIdFloat) ||
10842 (actual_type->id == TypeTableEntryIdComptimeInt &&
10843 wanted_type->id == TypeTableEntryIdInt))
10943 if ((actual_type->id == ZigTypeIdComptimeFloat &&
10944 wanted_type->id == ZigTypeIdFloat) ||
10945 (actual_type->id == ZigTypeIdComptimeInt &&
10946 wanted_type->id == ZigTypeIdInt))
1084410947 {
1084510948 op = CastOpNumLitToConcrete;
10846 } else if (wanted_type->id == TypeTableEntryIdInt) {
10949 } else if (wanted_type->id == ZigTypeIdInt) {
1084710950 op = CastOpFloatToInt;
10848 } else if (wanted_type->id == TypeTableEntryIdFloat) {
10951 } else if (wanted_type->id == ZigTypeIdFloat) {
1084910952 op = CastOpIntToFloat;
1085010953 } else {
1085110954 zig_unreachable();
......@@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1085910962 // cast from typed number to integer or float literal.
1086010963 // works when the number is known at compile time
1086110964 if (instr_is_comptime(value) &&
10862 ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) ||
10863 (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat)))
10965 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
10966 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
1086410967 {
1086510968 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
1086610969 }
1086710970
1086810971 // cast from union to the enum type of the union
10869 if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) {
10972 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
1087010973 if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))
1087110974 return ira->codegen->invalid_instruction;
1087210975
......@@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1087610979 }
1087710980
1087810981 // enum to union which has the enum as the tag type
10879 if (wanted_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum &&
10982 if (wanted_type->id == ZigTypeIdUnion && actual_type->id == ZigTypeIdEnum &&
1088010983 (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||
1088110984 wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
1088210985 {
......@@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1088910992 }
1089010993
1089110994 // enum to &const union which has the enum as the tag type
10892 if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) {
10893 TypeTableEntry *union_type = wanted_type->data.pointer.child_type;
10995 if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) {
10996 ZigType *union_type = wanted_type->data.pointer.child_type;
1089410997 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
1089510998 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
1089610999 {
......@@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1091211015 }
1091311016
1091411017 // cast from *T to *[1]T
10915 if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
10916 actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
11018 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
11019 actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
1091711020 {
10918 TypeTableEntry *array_type = wanted_type->data.pointer.child_type;
10919 if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 &&
11021 ZigType *array_type = wanted_type->data.pointer.child_type;
11022 if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 &&
1092011023 types_match_const_cast_only(ira, array_type->data.array.child_type,
1092111024 actual_type->data.pointer.child_type, source_node,
1092211025 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
......@@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1093611039 }
1093711040
1093811041 // cast from T to *T where T is zero bits
10939 if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
11042 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
1094011043 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
1094111044 actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
1094211045 {
......@@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1095011053
1095111054
1095211055 // cast from undefined to anything
10953 if (actual_type->id == TypeTableEntryIdUndefined) {
11056 if (actual_type->id == ZigTypeIdUndefined) {
1095411057 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
1095511058 }
1095611059
1095711060 // cast from something to const pointer of it
1095811061 if (!type_requires_comptime(actual_type)) {
10959 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
11062 ZigType *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
1096011063 if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) {
1096111064 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
1096211065 }
......@@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1097011073 return ira->codegen->invalid_instruction;
1097111074}
1097211075
10973static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
11076static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
1097411077 assert(value);
1097511078 assert(value != ira->codegen->invalid_instruction);
1097611079 assert(!expected_type || !type_is_invalid(expected_type));
......@@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
1098011083 return value; // anything will do
1098111084 if (expected_type == value->value.type)
1098211085 return value; // match
10983 if (value->value.type->id == TypeTableEntryIdUnreachable)
11086 if (value->value.type->id == ZigTypeIdUnreachable)
1098411087 return value;
1098511088
1098611089 return ir_analyze_cast(ira, value, expected_type, value);
1098711090}
1098811091
1098911092static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
10990 TypeTableEntry *type_entry = ptr->value.type;
11093 ZigType *type_entry = ptr->value.type;
1099111094 if (type_is_invalid(type_entry)) {
1099211095 return ira->codegen->invalid_instruction;
10993 } else if (type_entry->id == TypeTableEntryIdPointer) {
10994 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
11096 } else if (type_entry->id == ZigTypeIdPointer) {
11097 ZigType *child_type = type_entry->data.pointer.child_type;
1099511098 if (instr_is_comptime(ptr)) {
1099611099 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||
1099711100 ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)
1099811101 {
10999 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &ptr->value);
11102 ConstExprValue *pointee = ir_const_ptr_pointee(ira, &ptr->value, source_instruction->source_node);
11103 if (pointee == nullptr)
11104 return ira->codegen->invalid_instruction;
1100011105 if (pointee->special != ConstValSpecialRuntime) {
1100111106 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
1100211107 source_instruction->source_node, child_type);
......@@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1101911124 }
1102011125}
1102111126
11022static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
11127static ZigType *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
1102311128 bool is_const, bool is_volatile)
1102411129{
1102511130 IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile);
......@@ -11054,7 +11159,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out
1105411159 return true;
1105511160}
1105611161
11057static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *int_type, uint64_t *out) {
11162static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {
1105811163 if (type_is_invalid(value->value.type))
1105911164 return false;
1106011165
......@@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
1110311208 return false;
1110411209
1110511210 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
11106 assert(atomic_order_val->type->id == TypeTableEntryIdMetaType);
11107 TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type;
11211 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
11212 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1110811213
1110911214 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
1111011215 if (type_is_invalid(casted_value->value.type))
......@@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
1112311228 return false;
1112411229
1112511230 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
11126 assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType);
11127 TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
11231 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
11232 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1112811233
1112911234 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
1113011235 if (type_is_invalid(casted_value->value.type))
......@@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
1114311248 return false;
1114411249
1114511250 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
11146 assert(global_linkage_val->type->id == TypeTableEntryIdMetaType);
11147 TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type;
11251 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
11252 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1114811253
1114911254 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
1115011255 if (type_is_invalid(casted_value->value.type))
......@@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
1116311268 return false;
1116411269
1116511270 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
11166 assert(float_mode_val->type->id == TypeTableEntryIdMetaType);
11167 TypeTableEntry *float_mode_type = float_mode_val->data.x_type;
11271 assert(float_mode_val->type->id == ZigTypeIdMetaType);
11272 ZigType *float_mode_type = float_mode_val->data.x_type;
1116811273
1116911274 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
1117011275 if (type_is_invalid(casted_value->value.type))
......@@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1118311288 if (type_is_invalid(value->value.type))
1118411289 return nullptr;
1118511290
11186 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
11291 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1118711292 true, false, PtrLenUnknown,
1118811293 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
11189 TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type);
11294 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
1119011295 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
1119111296 if (type_is_invalid(casted_value->value.type))
1119211297 return nullptr;
......@@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1121911324 return result;
1122011325}
1122111326
11222static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
11327static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
1122311328 IrInstructionAddImplicitReturnType *instruction)
1122411329{
1122511330 IrInstruction *value = instruction->value->other;
......@@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1123311338 return out_val->type;
1123411339}
1123511340
11236static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
11341static ZigType *ir_analyze_instruction_return(IrAnalyze *ira,
1123711342 IrInstructionReturn *return_instruction)
1123811343{
1123911344 IrInstruction *value = return_instruction->value->other;
......@@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
1124511350 return ir_unreach_error(ira);
1124611351
1124711352 if (casted_value->value.special == ConstValSpecialRuntime &&
11248 casted_value->value.type->id == TypeTableEntryIdPointer &&
11353 casted_value->value.type->id == ZigTypeIdPointer &&
1124911354 casted_value->value.data.rh_ptr == RuntimeHintPtrStack)
1125011355 {
1125111356 ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable"));
......@@ -11258,13 +11363,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
1125811363 return ir_finish_anal(ira, result->value.type);
1125911364}
1126011365
11261static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
11366static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
1126211367 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base);
1126311368 *out_val = const_instruction->base.value;
1126411369 return const_instruction->base.value.type;
1126511370}
1126611371
11267static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
11372static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1126811373 IrInstruction *op1 = bin_op_instruction->op1->other;
1126911374 if (type_is_invalid(op1->value.type))
1127011375 return ira->codegen->builtin_types.entry_invalid;
......@@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1127311378 if (type_is_invalid(op2->value.type))
1127411379 return ira->codegen->builtin_types.entry_invalid;
1127511380
11276 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
11381 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1127711382
1127811383 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
1127911384 if (casted_op1 == ira->codegen->invalid_instruction)
......@@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1129311398 if (op2_val == nullptr)
1129411399 return ira->codegen->builtin_types.entry_invalid;
1129511400
11296 assert(casted_op1->value.type->id == TypeTableEntryIdBool);
11297 assert(casted_op2->value.type->id == TypeTableEntryIdBool);
11401 assert(casted_op1->value.type->id == ZigTypeIdBool);
11402 assert(casted_op2->value.type->id == ZigTypeIdBool);
1129811403 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
1129911404 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;
1130011405 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {
......@@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
1133811443 }
1133911444}
1134011445
11341static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
11446static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1134211447 Error err;
1134311448 IrInstruction *op1 = bin_op_instruction->op1->other;
1134411449 IrInstruction *op2 = bin_op_instruction->op2->other;
......@@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1134711452 IrBinOp op_id = bin_op_instruction->op_id;
1134811453 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
1134911454 if (is_equality_cmp &&
11350 ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) ||
11351 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||
11352 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))
11455 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||
11456 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) ||
11457 (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull)))
1135311458 {
11354 if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {
11459 if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) {
1135511460 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
1135611461 out_val->data.x_bool = (op_id == IrBinOpCmpEq);
1135711462 return ira->codegen->builtin_types.entry_bool;
1135811463 }
1135911464 IrInstruction *maybe_op;
11360 if (op1->value.type->id == TypeTableEntryIdNull) {
11465 if (op1->value.type->id == ZigTypeIdNull) {
1136111466 maybe_op = op2;
11362 } else if (op2->value.type->id == TypeTableEntryIdNull) {
11467 } else if (op2->value.type->id == ZigTypeIdNull) {
1136311468 maybe_op = op1;
1136411469 } else {
1136511470 zig_unreachable();
......@@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1138611491 return ira->codegen->builtin_types.entry_bool;
1138711492 }
1138811493
11389 if (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) {
11494 if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) {
1139011495 if (!is_equality_cmp) {
1139111496 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
1139211497 return ira->codegen->builtin_types.entry_invalid;
1139311498 }
11394 TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
11499 ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
1139511500 if (type_is_invalid(intersect_type)) {
1139611501 return ira->codegen->builtin_types.entry_invalid;
1139711502 }
......@@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1147211577 }
1147311578
1147411579 IrInstruction *instructions[] = {op1, op2};
11475 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
11580 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
1147611581 if (type_is_invalid(resolved_type))
1147711582 return resolved_type;
1147811583 if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type)))
......@@ -11480,42 +11585,42 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1148011585
1148111586 bool operator_allowed;
1148211587 switch (resolved_type->id) {
11483 case TypeTableEntryIdInvalid:
11588 case ZigTypeIdInvalid:
1148411589 zig_unreachable(); // handled above
1148511590
11486 case TypeTableEntryIdComptimeFloat:
11487 case TypeTableEntryIdComptimeInt:
11488 case TypeTableEntryIdInt:
11489 case TypeTableEntryIdFloat:
11591 case ZigTypeIdComptimeFloat:
11592 case ZigTypeIdComptimeInt:
11593 case ZigTypeIdInt:
11594 case ZigTypeIdFloat:
1149011595 operator_allowed = true;
1149111596 break;
1149211597
11493 case TypeTableEntryIdBool:
11494 case TypeTableEntryIdMetaType:
11495 case TypeTableEntryIdVoid:
11496 case TypeTableEntryIdPointer:
11497 case TypeTableEntryIdErrorSet:
11498 case TypeTableEntryIdFn:
11499 case TypeTableEntryIdOpaque:
11500 case TypeTableEntryIdNamespace:
11501 case TypeTableEntryIdBlock:
11502 case TypeTableEntryIdBoundFn:
11503 case TypeTableEntryIdArgTuple:
11504 case TypeTableEntryIdPromise:
11505 case TypeTableEntryIdEnum:
11598 case ZigTypeIdBool:
11599 case ZigTypeIdMetaType:
11600 case ZigTypeIdVoid:
11601 case ZigTypeIdPointer:
11602 case ZigTypeIdErrorSet:
11603 case ZigTypeIdFn:
11604 case ZigTypeIdOpaque:
11605 case ZigTypeIdNamespace:
11606 case ZigTypeIdBlock:
11607 case ZigTypeIdBoundFn:
11608 case ZigTypeIdArgTuple:
11609 case ZigTypeIdPromise:
11610 case ZigTypeIdEnum:
1150611611 operator_allowed = is_equality_cmp;
1150711612 break;
1150811613
11509 case TypeTableEntryIdUnreachable:
11510 case TypeTableEntryIdArray:
11511 case TypeTableEntryIdStruct:
11512 case TypeTableEntryIdUndefined:
11513 case TypeTableEntryIdNull:
11514 case TypeTableEntryIdErrorUnion:
11515 case TypeTableEntryIdUnion:
11614 case ZigTypeIdUnreachable:
11615 case ZigTypeIdArray:
11616 case ZigTypeIdStruct:
11617 case ZigTypeIdUndefined:
11618 case ZigTypeIdNull:
11619 case ZigTypeIdErrorUnion:
11620 case ZigTypeIdUnion:
1151611621 operator_allowed = false;
1151711622 break;
11518 case TypeTableEntryIdOptional:
11623 case ZigTypeIdOptional:
1151911624 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
1152011625 break;
1152111626 }
......@@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1154311648 return ira->codegen->builtin_types.entry_invalid;
1154411649
1154511650 bool answer;
11546 if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {
11651 if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) {
1154711652 Cmp cmp_result = float_cmp(op1_val, op2_val);
1154811653 answer = resolve_cmp_op_id(op_id, cmp_result);
11549 } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) {
11654 } else if (resolved_type->id == ZigTypeIdComptimeInt || resolved_type->id == ZigTypeIdInt) {
1155011655 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
1155111656 answer = resolve_cmp_op_id(op_id, cmp_result);
1155211657 } else {
......@@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1156611671 }
1156711672
1156811673 // some comparisons with unsigned numbers can be evaluated
11569 if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) {
11674 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
1157011675 ConstExprValue *known_left_val;
1157111676 IrBinOp flipped_op_id;
1157211677 if (instr_is_comptime(casted_op1)) {
......@@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1161011715 return ira->codegen->builtin_types.entry_bool;
1161111716}
1161211717
11613static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11718static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
1161411719 IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val)
1161511720{
1161611721 bool is_int;
1161711722 bool is_float;
1161811723 Cmp op2_zcmp;
11619 if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) {
11724 if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) {
1162011725 is_int = true;
1162111726 is_float = false;
1162211727 op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);
11623 } else if (type_entry->id == TypeTableEntryIdFloat ||
11624 type_entry->id == TypeTableEntryIdComptimeFloat)
11728 } else if (type_entry->id == ZigTypeIdFloat ||
11729 type_entry->id == ZigTypeIdComptimeFloat)
1162511730 {
1162611731 is_int = false;
1162711732 is_float = true;
......@@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1167111776 bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
1167211777 break;
1167311778 case IrBinOpBitShiftLeftLossy:
11674 assert(type_entry->id == TypeTableEntryIdInt);
11779 assert(type_entry->id == ZigTypeIdInt);
1167511780 bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
1167611781 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
1167711782 break;
......@@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1169811803 }
1169911804 break;
1170011805 case IrBinOpAddWrap:
11701 assert(type_entry->id == TypeTableEntryIdInt);
11806 assert(type_entry->id == ZigTypeIdInt);
1170211807 bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
1170311808 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
1170411809 break;
......@@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1171011815 }
1171111816 break;
1171211817 case IrBinOpSubWrap:
11713 assert(type_entry->id == TypeTableEntryIdInt);
11818 assert(type_entry->id == ZigTypeIdInt);
1171411819 bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
1171511820 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
1171611821 break;
......@@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1172211827 }
1172311828 break;
1172411829 case IrBinOpMultWrap:
11725 assert(type_entry->id == TypeTableEntryIdInt);
11830 assert(type_entry->id == ZigTypeIdInt);
1172611831 bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
1172711832 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
1172811833 break;
......@@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1177711882 break;
1177811883 }
1177911884
11780 if (type_entry->id == TypeTableEntryIdInt) {
11885 if (type_entry->id == ZigTypeIdInt) {
1178111886 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
1178211887 type_entry->data.integral.is_signed))
1178311888 {
......@@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
1179011895 return 0;
1179111896}
1179211897
11793static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
11898static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1179411899 IrInstruction *op1 = bin_op_instruction->op1->other;
1179511900 if (type_is_invalid(op1->value.type))
1179611901 return ira->codegen->builtin_types.entry_invalid;
1179711902
11798 if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) {
11903 if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) {
1179911904 ir_add_error(ira, &bin_op_instruction->base,
1180011905 buf_sprintf("bit shifting operation expected integer type, found '%s'",
1180111906 buf_ptr(&op1->value.type->name)));
......@@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1180811913
1180911914 IrInstruction *casted_op2;
1181011915 IrBinOp op_id = bin_op_instruction->op_id;
11811 if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
11916 if (op1->value.type->id == ZigTypeIdComptimeInt) {
1181211917 casted_op2 = op2;
1181311918
1181411919 if (op_id == IrBinOpBitShiftLeftLossy) {
......@@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1182211927 return ira->codegen->builtin_types.entry_invalid;
1182311928 }
1182411929 } else {
11825 TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
11930 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
1182611931 op1->value.type->data.integral.bit_count - 1);
1182711932 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
11828 op2->value.type->id == TypeTableEntryIdComptimeInt) {
11933 op2->value.type->id == ZigTypeIdComptimeInt) {
1182911934 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,
1183011935 shift_amt_type->data.integral.bit_count,
1183111936 op2->value.data.x_bigint.is_negative)) {
......@@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1187911984
1188011985 ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);
1188111986 return op1->value.type;
11882 } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
11987 } else if (op1->value.type->id == ZigTypeIdComptimeInt) {
1188311988 ir_add_error(ira, &bin_op_instruction->base,
1188411989 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
1188511990 return ira->codegen->builtin_types.entry_invalid;
......@@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1189011995 return op1->value.type;
1189111996}
1189211997
11893static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
11998static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1189411999 IrInstruction *op1 = bin_op_instruction->op1->other;
1189512000 if (type_is_invalid(op1->value.type))
1189612001 return ira->codegen->builtin_types.entry_invalid;
......@@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1190212007 IrBinOp op_id = bin_op_instruction->op_id;
1190312008
1190412009 // look for pointer math
11905 if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
12010 if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
1190612011 (op_id == IrBinOpAdd || op_id == IrBinOpSub))
1190712012 {
1190812013 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
......@@ -11917,19 +12022,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1191712022 }
1191812023
1191912024 IrInstruction *instructions[] = {op1, op2};
11920 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
12025 ZigType *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
1192112026 if (type_is_invalid(resolved_type))
1192212027 return resolved_type;
1192312028
11924 bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt;
11925 bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat;
12029 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
12030 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
1192612031 bool is_signed_div = (
11927 (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) ||
11928 resolved_type->id == TypeTableEntryIdFloat ||
11929 (resolved_type->id == TypeTableEntryIdComptimeFloat &&
12032 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
12033 resolved_type->id == ZigTypeIdFloat ||
12034 (resolved_type->id == ZigTypeIdComptimeFloat &&
1193012035 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
1193112036 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
11932 (resolved_type->id == TypeTableEntryIdComptimeInt &&
12037 (resolved_type->id == ZigTypeIdComptimeInt &&
1193312038 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
1193412039 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
1193512040 );
......@@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1205112156 return ira->codegen->builtin_types.entry_invalid;
1205212157 }
1205312158
12054 if (resolved_type->id == TypeTableEntryIdComptimeInt) {
12159 if (resolved_type->id == ZigTypeIdComptimeInt) {
1205512160 if (op_id == IrBinOpAddWrap) {
1205612161 op_id = IrBinOpAdd;
1205712162 } else if (op_id == IrBinOpSubWrap) {
......@@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1211112216}
1211212217
1211312218
12114static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12219static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
1211512220 IrInstruction *op1 = instruction->op1->other;
12116 TypeTableEntry *op1_type = op1->value.type;
12221 ZigType *op1_type = op1->value.type;
1211712222 if (type_is_invalid(op1_type))
1211812223 return ira->codegen->builtin_types.entry_invalid;
1211912224
1212012225 IrInstruction *op2 = instruction->op2->other;
12121 TypeTableEntry *op2_type = op2->value.type;
12226 ZigType *op2_type = op2->value.type;
1212212227 if (type_is_invalid(op2_type))
1212312228 return ira->codegen->builtin_types.entry_invalid;
1212412229
......@@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1213312238 ConstExprValue *op1_array_val;
1213412239 size_t op1_array_index;
1213512240 size_t op1_array_end;
12136 TypeTableEntry *child_type;
12137 if (op1_type->id == TypeTableEntryIdArray) {
12241 ZigType *child_type;
12242 if (op1_type->id == ZigTypeIdArray) {
1213812243 child_type = op1_type->data.array.child_type;
1213912244 op1_array_val = op1_val;
1214012245 op1_array_index = 0;
1214112246 op1_array_end = op1_type->data.array.len;
12142 } else if (op1_type->id == TypeTableEntryIdPointer &&
12247 } else if (op1_type->id == ZigTypeIdPointer &&
1214312248 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
1214412249 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
1214512250 op1_val->data.x_ptr.data.base_array.is_cstr)
......@@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1214912254 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
1215012255 op1_array_end = op1_array_val->type->data.array.len - 1;
1215112256 } else if (is_slice(op1_type)) {
12152 TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
12257 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
1215312258 child_type = ptr_type->data.pointer.child_type;
1215412259 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];
1215512260 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
......@@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1216512270 ConstExprValue *op2_array_val;
1216612271 size_t op2_array_index;
1216712272 size_t op2_array_end;
12168 if (op2_type->id == TypeTableEntryIdArray) {
12273 if (op2_type->id == ZigTypeIdArray) {
1216912274 if (op2_type->data.array.child_type != child_type) {
1217012275 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
1217112276 buf_ptr(&child_type->name),
......@@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1217512280 op2_array_val = op2_val;
1217612281 op2_array_index = 0;
1217712282 op2_array_end = op2_array_val->type->data.array.len;
12178 } else if (op2_type->id == TypeTableEntryIdPointer &&
12283 } else if (op2_type->id == ZigTypeIdPointer &&
1217912284 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
1218012285 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
1218112286 op2_val->data.x_ptr.data.base_array.is_cstr)
......@@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1219012295 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
1219112296 op2_array_end = op2_array_val->type->data.array.len - 1;
1219212297 } else if (is_slice(op2_type)) {
12193 TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
12298 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
1219412299 if (ptr_type->data.pointer.child_type != child_type) {
1219512300 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
1219612301 buf_ptr(&child_type->name),
......@@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1221012315
1221112316 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1221212317
12213 TypeTableEntry *result_type;
12318 ZigType *result_type;
1221412319 ConstExprValue *out_array_val;
1221512320 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
12216 if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) {
12321 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
1221712322 result_type = get_array_type(ira->codegen, child_type, new_len);
1221812323
1221912324 out_array_val = out_val;
1222012325 } else if (is_slice(op1_type) || is_slice(op2_type)) {
12221 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
12326 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
1222212327 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
1222312328 result_type = get_slice_type(ira->codegen, ptr_type);
1222412329 out_array_val = create_const_vals(1);
......@@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1227912384 return result_type;
1228012385}
1228112386
12282static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12387static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
1228312388 IrInstruction *op1 = instruction->op1->other;
1228412389 if (type_is_invalid(op1->value.type))
1228512390 return ira->codegen->builtin_types.entry_invalid;
......@@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
1229612401 if (!ir_resolve_usize(ira, op2, &mult_amt))
1229712402 return ira->codegen->builtin_types.entry_invalid;
1229812403
12299 TypeTableEntry *array_type = op1->value.type;
12300 if (array_type->id != TypeTableEntryIdArray) {
12404 ZigType *array_type = op1->value.type;
12405 if (array_type->id != ZigTypeIdArray) {
1230112406 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
1230212407 return ira->codegen->builtin_types.entry_invalid;
1230312408 }
......@@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
1231512420 if (array_val->data.x_array.special == ConstArraySpecialUndef) {
1231612421 out_val->data.x_array.special = ConstArraySpecialUndef;
1231712422
12318 TypeTableEntry *child_type = array_type->data.array.child_type;
12423 ZigType *child_type = array_type->data.array.child_type;
1231912424 return get_array_type(ira->codegen, child_type, new_array_len);
1232012425 }
1232112426
......@@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
1233012435 }
1233112436 assert(i == new_array_len);
1233212437
12333 TypeTableEntry *child_type = array_type->data.array.child_type;
12438 ZigType *child_type = array_type->data.array.child_type;
1233412439 return get_array_type(ira->codegen, child_type, new_array_len);
1233512440}
1233612441
12337static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12338 TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other);
12442static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12443 ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other);
1233912444 if (type_is_invalid(op1_type))
1234012445 return ira->codegen->builtin_types.entry_invalid;
1234112446
12342 TypeTableEntry *op2_type = ir_resolve_type(ira, instruction->op2->other);
12447 ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other);
1234312448 if (type_is_invalid(op2_type))
1234412449 return ira->codegen->builtin_types.entry_invalid;
1234512450
......@@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
1236512470 assert(errors[error_entry->value] == nullptr);
1236612471 errors[error_entry->value] = error_entry;
1236712472 }
12368 TypeTableEntry *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type);
12473 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type);
1236912474 free(errors);
1237012475
1237112476
......@@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
1237412479 return ira->codegen->builtin_types.entry_type;
1237512480}
1237612481
12377static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
12482static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1237812483 IrBinOp op_id = bin_op_instruction->op_id;
1237912484 switch (op_id) {
1238012485 case IrBinOpInvalid:
......@@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi
1242112526 zig_unreachable();
1242212527}
1242312528
12424static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {
12529static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {
1242512530 Error err;
12426 VariableTableEntry *var = decl_var_instruction->var;
12531 ZigVar *var = decl_var_instruction->var;
1242712532
1242812533 IrInstruction *init_value = decl_var_instruction->init_value->other;
1242912534 if (type_is_invalid(init_value->value.type)) {
......@@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1243112536 return var->value->type;
1243212537 }
1243312538
12434 TypeTableEntry *explicit_type = nullptr;
12539 ZigType *explicit_type = nullptr;
1243512540 IrInstruction *var_type = nullptr;
1243612541 if (decl_var_instruction->var_type != nullptr) {
1243712542 var_type = decl_var_instruction->var_type->other;
12438 TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);
12543 ZigType *proposed_type = ir_resolve_type(ira, var_type);
1243912544 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
1244012545 if (type_is_invalid(explicit_type)) {
1244112546 var->value->type = ira->codegen->builtin_types.entry_invalid;
......@@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1245012555
1245112556 bool var_class_requires_const = false;
1245212557
12453 TypeTableEntry *result_type = casted_init_value->value.type;
12558 ZigType *result_type = casted_init_value->value.type;
1245412559 if (type_is_invalid(result_type)) {
1245512560 result_type = ira->codegen->builtin_types.entry_invalid;
1245612561 } else {
......@@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1246012565 }
1246112566
1246212567 if (!type_is_invalid(result_type)) {
12463 if (result_type->id == TypeTableEntryIdUnreachable ||
12464 result_type->id == TypeTableEntryIdOpaque)
12568 if (result_type->id == ZigTypeIdUnreachable ||
12569 result_type->id == ZigTypeIdOpaque)
1246512570 {
1246612571 ir_add_error_node(ira, source_node,
1246712572 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
......@@ -12476,7 +12581,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1247612581 }
1247712582 } else {
1247812583 if (casted_init_value->value.special == ConstValSpecialStatic &&
12479 casted_init_value->value.type->id == TypeTableEntryIdFn &&
12584 casted_init_value->value.type->id == ZigTypeIdFn &&
1248012585 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
1248112586 {
1248212587 var_class_requires_const = true;
......@@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1249612601 // This means that this is actually a different variable due to, e.g. an inline while loop.
1249712602 // We make a new variable so that it can hold a different type, and so the debug info can
1249812603 // be distinct.
12499 VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
12604 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
1250012605 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);
1250112606 new_var->owner_exec = var->owner_exec;
1250212607 new_var->align_bytes = var->align_bytes;
......@@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1254912654
1255012655 ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value);
1255112656
12552 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
12657 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
1255312658 if (fn_entry)
1255412659 fn_entry->variable_list.append(var);
1255512660
1255612661 return ira->codegen->builtin_types.entry_void;
1255712662}
1255812663
12559static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
12664static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
1256012665 IrInstruction *name = instruction->name->other;
1256112666 Buf *symbol_name = ir_resolve_str(ira, name);
1256212667 if (symbol_name == nullptr) {
......@@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1258512690 }
1258612691
1258712692 switch (target->value.type->id) {
12588 case TypeTableEntryIdInvalid:
12589 case TypeTableEntryIdUnreachable:
12693 case ZigTypeIdInvalid:
12694 case ZigTypeIdUnreachable:
1259012695 zig_unreachable();
12591 case TypeTableEntryIdFn: {
12696 case ZigTypeIdFn: {
1259212697 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);
12593 FnTableEntry *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
12698 ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
1259412699 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
1259512700 switch (cc) {
1259612701 case CallingConventionUnspecified: {
......@@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1261112716 break;
1261212717 }
1261312718 } break;
12614 case TypeTableEntryIdStruct:
12719 case ZigTypeIdStruct:
1261512720 if (is_slice(target->value.type)) {
1261612721 ir_add_error(ira, target,
1261712722 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));
......@@ -12621,26 +12726,26 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1262112726 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));
1262212727 }
1262312728 break;
12624 case TypeTableEntryIdUnion:
12729 case ZigTypeIdUnion:
1262512730 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {
1262612731 ErrorMsg *msg = ir_add_error(ira, target,
1262712732 buf_sprintf("exported union value must be declared extern"));
1262812733 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));
1262912734 }
1263012735 break;
12631 case TypeTableEntryIdEnum:
12736 case ZigTypeIdEnum:
1263212737 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {
1263312738 ErrorMsg *msg = ir_add_error(ira, target,
1263412739 buf_sprintf("exported enum value must be declared extern"));
1263512740 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));
1263612741 }
1263712742 break;
12638 case TypeTableEntryIdMetaType: {
12639 TypeTableEntry *type_value = target->value.data.x_type;
12743 case ZigTypeIdMetaType: {
12744 ZigType *type_value = target->value.data.x_type;
1264012745 switch (type_value->id) {
12641 case TypeTableEntryIdInvalid:
12746 case ZigTypeIdInvalid:
1264212747 zig_unreachable();
12643 case TypeTableEntryIdStruct:
12748 case ZigTypeIdStruct:
1264412749 if (is_slice(type_value)) {
1264512750 ir_add_error(ira, target,
1264612751 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
......@@ -12650,73 +12755,73 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1265012755 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
1265112756 }
1265212757 break;
12653 case TypeTableEntryIdUnion:
12758 case ZigTypeIdUnion:
1265412759 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
1265512760 ErrorMsg *msg = ir_add_error(ira, target,
1265612761 buf_sprintf("exported union must be declared extern"));
1265712762 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
1265812763 }
1265912764 break;
12660 case TypeTableEntryIdEnum:
12765 case ZigTypeIdEnum:
1266112766 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
1266212767 ErrorMsg *msg = ir_add_error(ira, target,
1266312768 buf_sprintf("exported enum must be declared extern"));
1266412769 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
1266512770 }
1266612771 break;
12667 case TypeTableEntryIdFn: {
12772 case ZigTypeIdFn: {
1266812773 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
1266912774 ir_add_error(ira, target,
1267012775 buf_sprintf("exported function type must specify calling convention"));
1267112776 }
1267212777 } break;
12673 case TypeTableEntryIdInt:
12674 case TypeTableEntryIdFloat:
12675 case TypeTableEntryIdPointer:
12676 case TypeTableEntryIdArray:
12677 case TypeTableEntryIdBool:
12778 case ZigTypeIdInt:
12779 case ZigTypeIdFloat:
12780 case ZigTypeIdPointer:
12781 case ZigTypeIdArray:
12782 case ZigTypeIdBool:
1267812783 break;
12679 case TypeTableEntryIdMetaType:
12680 case TypeTableEntryIdVoid:
12681 case TypeTableEntryIdUnreachable:
12682 case TypeTableEntryIdComptimeFloat:
12683 case TypeTableEntryIdComptimeInt:
12684 case TypeTableEntryIdUndefined:
12685 case TypeTableEntryIdNull:
12686 case TypeTableEntryIdOptional:
12687 case TypeTableEntryIdErrorUnion:
12688 case TypeTableEntryIdErrorSet:
12689 case TypeTableEntryIdNamespace:
12690 case TypeTableEntryIdBlock:
12691 case TypeTableEntryIdBoundFn:
12692 case TypeTableEntryIdArgTuple:
12693 case TypeTableEntryIdOpaque:
12694 case TypeTableEntryIdPromise:
12784 case ZigTypeIdMetaType:
12785 case ZigTypeIdVoid:
12786 case ZigTypeIdUnreachable:
12787 case ZigTypeIdComptimeFloat:
12788 case ZigTypeIdComptimeInt:
12789 case ZigTypeIdUndefined:
12790 case ZigTypeIdNull:
12791 case ZigTypeIdOptional:
12792 case ZigTypeIdErrorUnion:
12793 case ZigTypeIdErrorSet:
12794 case ZigTypeIdNamespace:
12795 case ZigTypeIdBlock:
12796 case ZigTypeIdBoundFn:
12797 case ZigTypeIdArgTuple:
12798 case ZigTypeIdOpaque:
12799 case ZigTypeIdPromise:
1269512800 ir_add_error(ira, target,
1269612801 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
1269712802 break;
1269812803 }
1269912804 } break;
12700 case TypeTableEntryIdVoid:
12701 case TypeTableEntryIdBool:
12702 case TypeTableEntryIdInt:
12703 case TypeTableEntryIdFloat:
12704 case TypeTableEntryIdPointer:
12705 case TypeTableEntryIdArray:
12706 case TypeTableEntryIdComptimeFloat:
12707 case TypeTableEntryIdComptimeInt:
12708 case TypeTableEntryIdUndefined:
12709 case TypeTableEntryIdNull:
12710 case TypeTableEntryIdOptional:
12711 case TypeTableEntryIdErrorUnion:
12712 case TypeTableEntryIdErrorSet:
12805 case ZigTypeIdVoid:
12806 case ZigTypeIdBool:
12807 case ZigTypeIdInt:
12808 case ZigTypeIdFloat:
12809 case ZigTypeIdPointer:
12810 case ZigTypeIdArray:
12811 case ZigTypeIdComptimeFloat:
12812 case ZigTypeIdComptimeInt:
12813 case ZigTypeIdUndefined:
12814 case ZigTypeIdNull:
12815 case ZigTypeIdOptional:
12816 case ZigTypeIdErrorUnion:
12817 case ZigTypeIdErrorSet:
1271312818 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
12714 case TypeTableEntryIdNamespace:
12715 case TypeTableEntryIdBlock:
12716 case TypeTableEntryIdBoundFn:
12717 case TypeTableEntryIdArgTuple:
12718 case TypeTableEntryIdOpaque:
12719 case TypeTableEntryIdPromise:
12819 case ZigTypeIdNamespace:
12820 case ZigTypeIdBlock:
12821 case ZigTypeIdBoundFn:
12822 case ZigTypeIdArgTuple:
12823 case ZigTypeIdOpaque:
12824 case ZigTypeIdPromise:
1272012825 ir_add_error(ira, target,
1272112826 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
1272212827 break;
......@@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1272712832}
1272812833
1272912834static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
12730 FnTableEntry *fn_entry = exec_fn_entry(exec);
12835 ZigFn *fn_entry = exec_fn_entry(exec);
1273112836 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
1273212837}
1273312838
12734static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
12839static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1273512840 IrInstructionErrorReturnTrace *instruction)
1273612841{
1273712842 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
12738 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);
12739 TypeTableEntry *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
12843 ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);
12844 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
1274012845 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
1274112846 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1274212847 assert(get_codegen_ptr_type(optional_type) != nullptr);
......@@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1275712862 }
1275812863}
1275912864
12760static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
12865static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira,
1276112866 IrInstructionErrorUnion *instruction)
1276212867{
12763 TypeTableEntry *err_set_type = ir_resolve_type(ira, instruction->err_set->other);
12868 ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->other);
1276412869 if (type_is_invalid(err_set_type))
1276512870 return ira->codegen->builtin_types.entry_invalid;
1276612871
12767 TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload->other);
12872 ZigType *payload_type = ir_resolve_type(ira, instruction->payload->other);
1276812873 if (type_is_invalid(payload_type))
1276912874 return ira->codegen->builtin_types.entry_invalid;
1277012875
12771 if (err_set_type->id != TypeTableEntryIdErrorSet) {
12876 if (err_set_type->id != ZigTypeIdErrorSet) {
1277212877 ir_add_error(ira, instruction->err_set->other,
1277312878 buf_sprintf("expected error set type, found type '%s'",
1277412879 buf_ptr(&err_set_type->name)));
1277512880 return ira->codegen->builtin_types.entry_invalid;
1277612881 }
1277712882
12778 TypeTableEntry *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
12883 ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
1277912884
1278012885 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1278112886 out_val->data.x_type = result_type;
......@@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
1278312888}
1278412889
1278512890IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) {
12786 FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
12891 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
1278712892 if (parent_fn_entry == nullptr) {
1278812893 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
1278912894 return ira->codegen->invalid_instruction;
......@@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
1280712912 }
1280812913 case ImplicitAllocatorIdLocalVar:
1280912914 {
12810 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
12915 ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
1281112916 assert(coro_allocator_var != nullptr);
1281212917 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
1281312918 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
......@@ -12818,38 +12923,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
1281812923 zig_unreachable();
1281912924}
1282012925
12821static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type,
12926static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry, ZigType *fn_type,
1282212927 IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst)
1282312928{
1282412929 Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);
1282512930 //Buf *free_field_name = buf_create_from_str("freeFn");
12826 assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer);
12827 TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type;
12931 assert(async_allocator_inst->value.type->id == ZigTypeIdPointer);
12932 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
1282812933 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,
1282912934 async_allocator_inst, container_type);
1283012935 if (type_is_invalid(field_ptr_inst->value.type)) {
1283112936 return ira->codegen->invalid_instruction;
1283212937 }
12833 TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
12834 assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer);
12938 ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
12939 assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer);
1283512940
12836 TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
12837 if (alloc_fn_type->id != TypeTableEntryIdFn) {
12941 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
12942 if (alloc_fn_type->id != ZigTypeIdFn) {
1283812943 ir_add_error(ira, &call_instruction->base,
1283912944 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));
1284012945 return ira->codegen->invalid_instruction;
1284112946 }
1284212947
12843 TypeTableEntry *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
12844 if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) {
12948 ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
12949 if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) {
1284512950 ir_add_error(ira, fn_ref,
1284612951 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));
1284712952 return ira->codegen->invalid_instruction;
1284812953 }
12849 TypeTableEntry *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type;
12850 TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
12851 TypeTableEntry *promise_type = get_promise_type(ira->codegen, return_type);
12852 TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
12954 ZigType *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type;
12955 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
12956 ZigType *promise_type = get_promise_type(ira->codegen, return_type);
12957 ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
1285312958
1285412959 IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node,
1285512960 fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr);
......@@ -12866,7 +12971,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1286612971 IrInstruction *casted_arg;
1286712972 if (param_decl_node->data.param_decl.var_token == nullptr) {
1286812973 AstNode *param_type_node = param_decl_node->data.param_decl.type;
12869 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
12974 ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
1287012975 if (type_is_invalid(param_type))
1287112976 return false;
1287212977
......@@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1288212987 return false;
1288312988
1288412989 Buf *param_name = param_decl_node->data.param_decl.name;
12885 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
12990 ZigVar *var = add_variable(ira->codegen, param_decl_node,
1288612991 *exec_scope, param_name, true, arg_val, nullptr);
1288712992 *exec_scope = var->child_scope;
1288812993 *next_proto_i += 1;
......@@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1289312998static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
1289412999 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,
1289513000 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,
12896 FnTableEntry *impl_fn)
13001 ZigFn *impl_fn)
1289713002{
1289813003 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
1289913004 assert(param_decl_node->type == NodeTypeParamDecl);
......@@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1290613011 } else {
1290713012 if (param_decl_node->data.param_decl.var_token == nullptr) {
1290813013 AstNode *param_type_node = param_decl_node->data.param_decl.type;
12909 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
13014 ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
1291013015 if (type_is_invalid(param_type))
1291113016 return false;
1291213017
......@@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1292013025 }
1292113026
1292213027 bool comptime_arg = param_decl_node->data.param_decl.is_inline ||
12923 casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat;
13028 casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;
1292413029
1292513030 ConstExprValue *arg_val;
1292613031
......@@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1294013045 Buf *param_name = param_decl_node->data.param_decl.name;
1294113046 if (!param_name) return false;
1294213047 if (!is_var_args) {
12943 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
13048 ZigVar *var = add_variable(ira->codegen, param_decl_node,
1294413049 *child_scope, param_name, true, arg_val, nullptr);
1294513050 *child_scope = var->child_scope;
1294613051 var->shadowable = !comptime_arg;
1294713052
1294813053 *next_proto_i += 1;
12949 } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt ||
12950 casted_arg->value.type->id == TypeTableEntryIdComptimeFloat)
13054 } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||
13055 casted_arg->value.type->id == ZigTypeIdComptimeFloat)
1295113056 {
1295213057 ir_add_error(ira, casted_arg,
1295313058 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
......@@ -12972,7 +13077,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1297213077 return true;
1297313078}
1297413079
12975static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) {
13080static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {
1297613081 size_t next_var_i = 0;
1297713082 FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;
1297813083 assert(gen_param_info != nullptr);
......@@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
1299113096}
1299213097
1299313098static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12994 VariableTableEntry *var)
13099 ZigVar *var)
1299513100{
1299613101 Error err;
1299713102 while (var->next_var != nullptr) {
......@@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1300213107 assert(ira->codegen->errors.length != 0);
1300313108 return ira->codegen->invalid_instruction;
1300413109 }
13005 assert(var->value->type);
13006 if (type_is_invalid(var->value->type))
13110 if (var->value->type == nullptr || type_is_invalid(var->value->type))
1300713111 return ira->codegen->invalid_instruction;
1300813112
1300913113 bool comptime_var_mem = ir_get_var_is_comptime(var);
......@@ -13061,8 +13165,8 @@ no_mem_slot:
1306113165 return var_ptr_instruction;
1306213166}
1306313167
13064static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,
13065 FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref,
13168static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,
13169 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
1306613170 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)
1306713171{
1306813172 Error err;
......@@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1308213186 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
1308313187 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
1308413188 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value;
13085 if (arg_tuple_value->type->id == TypeTableEntryIdArgTuple) {
13189 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
1308613190 call_param_count -= 1;
1308713191 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
1308813192 arg_tuple_value->data.x_arg_tuple.start_index;
......@@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1315013254
1315113255 size_t next_proto_i = 0;
1315213256 if (first_arg_ptr) {
13153 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
13257 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1315413258
1315513259 bool first_arg_known_bare = false;
1315613260 if (fn_type_id->next_param_index >= 1) {
13157 TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
13261 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1315813262 if (type_is_invalid(param_type))
1315913263 return ira->codegen->builtin_types.entry_invalid;
13160 first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
13264 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1316113265 }
1316213266
1316313267 IrInstruction *first_arg;
......@@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1319013294 }
1319113295
1319213296 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
13193 TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
13297 ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
1319413298 if (type_is_invalid(specified_return_type))
1319513299 return ira->codegen->builtin_types.entry_invalid;
13196 TypeTableEntry *return_type;
13197 TypeTableEntry *inferred_err_set_type = nullptr;
13300 ZigType *return_type;
13301 ZigType *inferred_err_set_type = nullptr;
1319813302 if (fn_proto_node->data.fn_proto.auto_err_set) {
1319913303 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
1320013304 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
......@@ -13219,16 +13323,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1321913323
1322013324 if (inferred_err_set_type != nullptr) {
1322113325 inferred_err_set_type->data.error_set.infer_fn = nullptr;
13222 if (result->value.type->id == TypeTableEntryIdErrorUnion) {
13326 if (result->value.type->id == ZigTypeIdErrorUnion) {
1322313327 if (result->value.data.x_err_union.err != nullptr) {
1322413328 inferred_err_set_type->data.error_set.err_count = 1;
1322513329 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
1322613330 inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err;
1322713331 }
13228 TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
13332 ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
1322913333 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;
1323013334 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;
13231 } else if (result->value.type->id == TypeTableEntryIdErrorSet) {
13335 } else if (result->value.type->id == ZigTypeIdErrorSet) {
1323213336 inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;
1323313337 inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;
1323413338 }
......@@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1324913353
1325013354 IrInstruction *casted_new_stack = nullptr;
1325113355 if (call_instruction->new_stack != nullptr) {
13252 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
13356 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1325313357 false, false, PtrLenUnknown,
1325413358 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
13255 TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
13359 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
1325613360 IrInstruction *new_stack = call_instruction->new_stack->other;
1325713361 if (type_is_invalid(new_stack->value.type))
1325813362 return ira->codegen->builtin_types.entry_invalid;
......@@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1327613380 if (type_is_invalid(arg->value.type))
1327713381 return ira->codegen->builtin_types.entry_invalid;
1327813382
13279 if (arg->value.type->id == TypeTableEntryIdArgTuple) {
13383 if (arg->value.type->id == ZigTypeIdArgTuple) {
1328013384 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;
1328113385 } else {
1328213386 new_fn_arg_count += 1;
......@@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1328713391
1328813392 // Fork a scope of the function with known values for the parameters.
1328913393 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
13290 FnTableEntry *impl_fn = create_fn(fn_proto_node);
13394 ZigFn *impl_fn = create_fn(fn_proto_node);
1329113395 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
1329213396 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
1329313397 impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn);
......@@ -13306,14 +13410,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1330613410 size_t next_proto_i = 0;
1330713411
1330813412 if (first_arg_ptr) {
13309 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
13413 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1331013414
1331113415 bool first_arg_known_bare = false;
1331213416 if (fn_type_id->next_param_index >= 1) {
13313 TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
13417 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1331413418 if (type_is_invalid(param_type))
1331513419 return ira->codegen->builtin_types.entry_invalid;
13316 first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
13420 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1331713421 }
1331813422
1331913423 IrInstruction *first_arg;
......@@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1333513439 bool found_first_var_arg = false;
1333613440 size_t first_var_arg;
1333713441
13338 FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
13442 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
1333913443 assert(parent_fn_entry);
1334013444 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1334113445 IrInstruction *arg = call_instruction->args[call_i]->other;
1334213446 if (type_is_invalid(arg->value.type))
1334313447 return ira->codegen->builtin_types.entry_invalid;
1334413448
13345 if (arg->value.type->id == TypeTableEntryIdArgTuple) {
13449 if (arg->value.type->id == ZigTypeIdArgTuple) {
1334613450 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;
1334713451 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
1334813452 {
......@@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1335413458 found_first_var_arg = true;
1335513459 }
1335613460
13357 VariableTableEntry *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
13461 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
1335813462 if (arg_var == nullptr) {
1335913463 ir_add_error(ira, arg,
1336013464 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
......@@ -13401,7 +13505,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1340113505
1340213506 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,
1340313507 first_var_arg, inst_fn_type_id.param_count);
13404 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
13508 ZigVar *var = add_variable(ira->codegen, param_decl_node,
1340513509 impl_fn->child_scope, param_name, true, var_args_val, nullptr);
1340613510 impl_fn->child_scope = var->child_scope;
1340713511 }
......@@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1342013524
1342113525 if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
1342213526 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
13423 TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
13527 ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
1342413528 if (type_is_invalid(specified_return_type))
1342513529 return ira->codegen->builtin_types.entry_invalid;
1342613530 if (fn_proto_node->data.fn_proto.auto_err_set) {
13427 TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
13531 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
1342813532 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
1342913533 } else {
1343013534 inst_fn_type_id.return_type = specified_return_type;
......@@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1344213546 if (call_instruction->is_async) {
1344313547 AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;
1344413548 if (async_allocator_type_node != nullptr) {
13445 TypeTableEntry *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node);
13549 ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node);
1344613550 if (type_is_invalid(async_allocator_type))
1344713551 return ira->codegen->builtin_types.entry_invalid;
1344813552 inst_fn_type_id.async_allocator_type = async_allocator_type;
......@@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1348613590 ira->codegen->fn_defs.append(impl_fn);
1348713591 }
1348813592
13489 TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type;
13593 ZigType *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type;
1349013594 if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) {
1349113595 parent_fn_entry->calls_or_awaits_errorable_fn = true;
1349213596 }
......@@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1351013614 return ir_finish_anal(ira, return_type);
1351113615 }
1351213616
13513 FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
13617 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
1351413618 assert(fn_type_id->return_type != nullptr);
1351513619 assert(parent_fn_entry != nullptr);
1351613620 if (fn_type_can_fail(fn_type_id)) {
......@@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1352113625 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
1352213626 size_t next_arg_index = 0;
1352313627 if (first_arg_ptr) {
13524 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
13628 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1352513629
13526 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
13630 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1352713631 if (type_is_invalid(param_type))
1352813632 return ira->codegen->builtin_types.entry_invalid;
1352913633
1353013634 IrInstruction *first_arg;
13531 if (param_type->id == TypeTableEntryIdPointer &&
13635 if (param_type->id == ZigTypeIdPointer &&
1353213636 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
1353313637 {
1353413638 first_arg = first_arg_ptr;
......@@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1355113655 return ira->codegen->builtin_types.entry_invalid;
1355213656 IrInstruction *casted_arg;
1355313657 if (next_arg_index < src_param_count) {
13554 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
13658 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1355513659 if (type_is_invalid(param_type))
1355613660 return ira->codegen->builtin_types.entry_invalid;
1355713661 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
......@@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1356713671
1356813672 assert(next_arg_index == call_param_count);
1356913673
13570 TypeTableEntry *return_type = fn_type_id->return_type;
13674 ZigType *return_type = fn_type_id->return_type;
1357113675 if (type_is_invalid(return_type))
1357213676 return ira->codegen->builtin_types.entry_invalid;
1357313677
......@@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1359513699 return ir_finish_anal(ira, result->value.type);
1359613700 }
1359713701
13702 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) {
13703 ir_add_error(ira, &call_instruction->base,
13704 buf_sprintf("no-inline call of inline function"));
13705 return ira->codegen->builtin_types.entry_invalid;
13706 }
1359813707
1359913708 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
1360013709 fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack);
......@@ -13603,7 +13712,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1360313712 return ir_finish_anal(ira, return_type);
1360413713}
1360513714
13606static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
13715static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
1360713716 IrInstruction *fn_ref = call_instruction->fn_ref->other;
1360813717 if (type_is_invalid(fn_ref->value.type))
1360913718 return ira->codegen->builtin_types.entry_invalid;
......@@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1361213721 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
1361313722
1361413723 if (is_comptime || instr_is_comptime(fn_ref)) {
13615 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
13616 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);
13724 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
13725 ZigType *dest_type = ir_resolve_type(ira, fn_ref);
1361713726 if (type_is_invalid(dest_type))
1361813727 return ira->codegen->builtin_types.entry_invalid;
1361913728
......@@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1363313742
1363413743 ir_link_new_instruction(cast_instruction, &call_instruction->base);
1363513744 return ir_finish_anal(ira, cast_instruction->value.type);
13636 } else if (fn_ref->value.type->id == TypeTableEntryIdFn) {
13637 FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);
13745 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
13746 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
1363813747 if (fn_table_entry == nullptr)
1363913748 return ira->codegen->builtin_types.entry_invalid;
1364013749 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1364113750 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
13642 } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {
13751 } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {
1364313752 assert(fn_ref->value.special == ConstValSpecialStatic);
13644 FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
13753 ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
1364513754 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;
1364613755 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1364713756 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);
......@@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1365213761 }
1365313762 }
1365413763
13655 if (fn_ref->value.type->id == TypeTableEntryIdFn) {
13764 if (fn_ref->value.type->id == ZigTypeIdFn) {
1365613765 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
1365713766 fn_ref, nullptr, false, FnInlineAuto);
1365813767 } else {
......@@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1366213771 }
1366313772}
1366413773
13665static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13774// out_val->type must be the type to read the pointer as
13775// if the type is different than the actual type then it does a comptime byte reinterpretation
13776static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
13777 ConstExprValue *out_val, ConstExprValue *ptr_val)
13778{
13779 assert(out_val->type != nullptr);
13780
13781 ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr_val);
13782
13783 size_t src_size = type_size(ira->codegen, pointee->type);
13784 size_t dst_size = type_size(ira->codegen, out_val->type);
13785
13786 if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {
13787 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
13788 return ErrorNone;
13789 }
13790
13791 if (dst_size > src_size) {
13792 ir_add_error_node(ira, source_node,
13793 buf_sprintf("attempt to read %zu bytes from pointer to %s which is %zu bytes",
13794 dst_size, buf_ptr(&pointee->type->name), src_size));
13795 return ErrorSemanticAnalyzeFail;
13796 }
13797
13798 Buf buf = BUF_INIT;
13799 buf_resize(&buf, src_size);
13800 buf_write_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), pointee);
13801 buf_read_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), out_val);
13802 return ErrorNone;
13803}
13804
13805static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13806 Error err;
1366613807 IrInstruction *value = un_op_instruction->value->other;
1366713808
13668 TypeTableEntry *ptr_type = value->value.type;
13669 TypeTableEntry *child_type;
13809 ZigType *ptr_type = value->value.type;
13810 ZigType *child_type;
1367013811 if (type_is_invalid(ptr_type)) {
1367113812 return ira->codegen->builtin_types.entry_invalid;
13672 } else if (ptr_type->id == TypeTableEntryIdPointer) {
13813 } else if (ptr_type->id == ZigTypeIdPointer) {
1367313814 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
1367413815 ir_add_error_node(ira, un_op_instruction->base.source_node,
1367513816 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
......@@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
1369213833 if (comptime_value == nullptr)
1369313834 return ira->codegen->builtin_types.entry_invalid;
1369413835
13695 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value);
13696 if (pointee->type == child_type) {
13697 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
13698 copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst);
13699 return child_type;
13700 }
13836 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
13837 out_val->type = child_type;
13838 if ((err = ir_read_const_ptr(ira, un_op_instruction->base.source_node, out_val, comptime_value)))
13839 return ira->codegen->builtin_types.entry_invalid;
13840 return child_type;
1370113841 }
1370213842
1370313843 ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);
1370413844 return child_type;
1370513845}
1370613846
13707static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13847static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
1370813848 Error err;
1370913849 IrInstruction *value = un_op_instruction->value->other;
13710 TypeTableEntry *type_entry = ir_resolve_type(ira, value);
13850 ZigType *type_entry = ir_resolve_type(ira, value);
1371113851 if (type_is_invalid(type_entry))
1371213852 return ira->codegen->builtin_types.entry_invalid;
1371313853 if ((err = ensure_complete_type(ira->codegen, type_entry)))
1371413854 return ira->codegen->builtin_types.entry_invalid;
1371513855
1371613856 switch (type_entry->id) {
13717 case TypeTableEntryIdInvalid:
13857 case ZigTypeIdInvalid:
1371813858 zig_unreachable();
13719 case TypeTableEntryIdMetaType:
13720 case TypeTableEntryIdVoid:
13721 case TypeTableEntryIdBool:
13722 case TypeTableEntryIdInt:
13723 case TypeTableEntryIdFloat:
13724 case TypeTableEntryIdPointer:
13725 case TypeTableEntryIdArray:
13726 case TypeTableEntryIdStruct:
13727 case TypeTableEntryIdComptimeFloat:
13728 case TypeTableEntryIdComptimeInt:
13729 case TypeTableEntryIdUndefined:
13730 case TypeTableEntryIdNull:
13731 case TypeTableEntryIdOptional:
13732 case TypeTableEntryIdErrorUnion:
13733 case TypeTableEntryIdErrorSet:
13734 case TypeTableEntryIdEnum:
13735 case TypeTableEntryIdUnion:
13736 case TypeTableEntryIdFn:
13737 case TypeTableEntryIdNamespace:
13738 case TypeTableEntryIdBlock:
13739 case TypeTableEntryIdBoundFn:
13740 case TypeTableEntryIdArgTuple:
13741 case TypeTableEntryIdPromise:
13859 case ZigTypeIdMetaType:
13860 case ZigTypeIdVoid:
13861 case ZigTypeIdBool:
13862 case ZigTypeIdInt:
13863 case ZigTypeIdFloat:
13864 case ZigTypeIdPointer:
13865 case ZigTypeIdArray:
13866 case ZigTypeIdStruct:
13867 case ZigTypeIdComptimeFloat:
13868 case ZigTypeIdComptimeInt:
13869 case ZigTypeIdUndefined:
13870 case ZigTypeIdNull:
13871 case ZigTypeIdOptional:
13872 case ZigTypeIdErrorUnion:
13873 case ZigTypeIdErrorSet:
13874 case ZigTypeIdEnum:
13875 case ZigTypeIdUnion:
13876 case ZigTypeIdFn:
13877 case ZigTypeIdNamespace:
13878 case ZigTypeIdBlock:
13879 case ZigTypeIdBoundFn:
13880 case ZigTypeIdArgTuple:
13881 case ZigTypeIdPromise:
1374213882 {
1374313883 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
1374413884 out_val->data.x_type = get_optional_type(ira->codegen, type_entry);
1374513885 return ira->codegen->builtin_types.entry_type;
1374613886 }
13747 case TypeTableEntryIdUnreachable:
13748 case TypeTableEntryIdOpaque:
13887 case ZigTypeIdUnreachable:
13888 case ZigTypeIdOpaque:
1374913889 ir_add_error_node(ira, un_op_instruction->base.source_node,
1375013890 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));
1375113891 return ira->codegen->builtin_types.entry_invalid;
......@@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
1375313893 zig_unreachable();
1375413894}
1375513895
13756static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13896static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
1375713897 IrInstruction *value = un_op_instruction->value->other;
13758 TypeTableEntry *expr_type = value->value.type;
13898 ZigType *expr_type = value->value.type;
1375913899 if (type_is_invalid(expr_type))
1376013900 return ira->codegen->builtin_types.entry_invalid;
1376113901
1376213902 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
1376313903
13764 bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat);
13904 bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat);
1376513905
13766 if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||
13767 expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op))
13906 if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) ||
13907 expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op))
1376813908 {
1376913909 if (instr_is_comptime(value)) {
1377013910 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
......@@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
1378013920 } else {
1378113921 bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);
1378213922 }
13783 if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) {
13923 if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) {
1378413924 return expr_type;
1378513925 }
1378613926
......@@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
1380013940 return ira->codegen->builtin_types.entry_invalid;
1380113941}
1380213942
13803static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
13943static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
1380413944 IrInstruction *value = instruction->value->other;
13805 TypeTableEntry *expr_type = value->value.type;
13945 ZigType *expr_type = value->value.type;
1380613946 if (type_is_invalid(expr_type))
1380713947 return ira->codegen->builtin_types.entry_invalid;
1380813948
13809 if (expr_type->id == TypeTableEntryIdInt) {
13949 if (expr_type->id == ZigTypeIdInt) {
1381013950 if (instr_is_comptime(value)) {
1381113951 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
1381213952 if (target_const_val == nullptr)
......@@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins
1382713967 return ira->codegen->builtin_types.entry_invalid;
1382813968}
1382913969
13830static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13970static ZigType *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
1383113971 IrUnOp op_id = un_op_instruction->op_id;
1383213972 switch (op_id) {
1383313973 case IrUnOpInvalid:
......@@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio
1384513985 zig_unreachable();
1384613986}
1384713987
13848static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
13988static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
1384913989 IrBasicBlock *old_dest_block = br_instruction->dest_block;
1385013990
1385113991 bool is_comptime;
......@@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
1385513995 if (is_comptime || old_dest_block->ref_count == 1)
1385613996 return ir_inline_bb(ira, &br_instruction->base, old_dest_block);
1385713997
13858 IrBasicBlock *new_bb = ir_get_new_bb(ira, old_dest_block, &br_instruction->base);
13859
13860 if (new_bb->must_be_comptime_source_instr) {
13861 ErrorMsg *msg = ir_add_error(ira, &br_instruction->base,
13862 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
13863 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
13864 buf_sprintf("compile-time variable assigned here"));
13998 IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
13999 if (new_bb == nullptr)
1386514000 return ir_unreach_error(ira);
13866 }
1386714001
1386814002 ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb);
1386914003 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
1387014004}
1387114005
13872static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
14006static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
1387314007 IrInstruction *condition = cond_br_instruction->condition->other;
1387414008 if (type_is_invalid(condition->value.type))
1387514009 return ir_unreach_error(ira);
......@@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct
1388914023 if (is_comptime || old_dest_block->ref_count == 1)
1389014024 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);
1389114025
13892 IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &cond_br_instruction->base);
14026 IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
14027 if (new_dest_block == nullptr)
14028 return ir_unreach_error(ira);
14029
1389314030 ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block);
1389414031 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
1389514032 }
1389614033
13897 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
14034 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1389814035 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
1389914036 if (casted_condition == ira->codegen->invalid_instruction)
1390014037 return ir_unreach_error(ira);
1390114038
1390214039 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
13903 IrBasicBlock *new_then_block = ir_get_new_bb(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
13904 IrBasicBlock *new_else_block = ir_get_new_bb(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
14040 IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
14041 if (new_then_block == nullptr)
14042 return ir_unreach_error(ira);
14043
14044 IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
14045 if (new_else_block == nullptr)
14046 return ir_unreach_error(ira);
14047
1390514048 ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base,
1390614049 casted_condition, new_then_block, new_else_block, nullptr);
1390714050 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
1390814051}
1390914052
13910static TypeTableEntry *ir_analyze_instruction_unreachable(IrAnalyze *ira,
14053static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira,
1391114054 IrInstructionUnreachable *unreachable_instruction)
1391214055{
1391314056 ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base);
1391414057 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
1391514058}
1391614059
13917static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
14060static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
1391814061 if (ira->const_predecessor_bb) {
1391914062 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
1392014063 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
......@@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
1394814091 IrInstruction *old_value = phi_instruction->incoming_values[i];
1394914092 assert(old_value);
1395014093 IrInstruction *new_value = old_value->other;
13951 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr)
14094 if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
1395214095 continue;
1395314096
1395414097 if (type_is_invalid(new_value->value.type))
......@@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
1397114114 return first_value->value.type;
1397214115 }
1397314116
13974 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
14117 ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
1397514118 new_incoming_values.items, new_incoming_values.length);
1397614119 if (type_is_invalid(resolved_type))
1397714120 return resolved_type;
1397814121
13979 if (resolved_type->id == TypeTableEntryIdComptimeFloat ||
13980 resolved_type->id == TypeTableEntryIdComptimeInt ||
13981 resolved_type->id == TypeTableEntryIdNull ||
13982 resolved_type->id == TypeTableEntryIdUndefined)
14122 if (resolved_type->id == ZigTypeIdComptimeFloat ||
14123 resolved_type->id == ZigTypeIdComptimeInt ||
14124 resolved_type->id == ZigTypeIdNull ||
14125 resolved_type->id == ZigTypeIdUndefined)
1398314126 {
1398414127 ir_add_error_node(ira, phi_instruction->base.source_node,
1398514128 buf_sprintf("unable to infer expression type"));
1398614129 return ira->codegen->builtin_types.entry_invalid;
1398714130 }
1398814131
13989 bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer);
14132 bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer);
1399014133
1399114134 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
1399214135 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
......@@ -14023,21 +14166,30 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
1402314166 return resolved_type;
1402414167}
1402514168
14026static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
14027 VariableTableEntry *var)
14028{
14169static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
1402914170 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
1403014171 ir_link_new_instruction(result, instruction);
1403114172 return result->value.type;
1403214173}
1403314174
14034static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
14035 VariableTableEntry *var = var_ptr_instruction->var;
14036 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
14175static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {
14176 ZigVar *var = instruction->var;
14177 IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);
14178 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
14179 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
14180 buf_sprintf("'%s' not accessible from inner function", buf_ptr(&var->name)));
14181 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
14182 buf_sprintf("crossed function definition here"));
14183 add_error_note(ira->codegen, msg, var->decl_node,
14184 buf_sprintf("declared here"));
14185 return ira->codegen->builtin_types.entry_invalid;
14186 }
14187 ir_link_new_instruction(result, &instruction->base);
14188 return result->value.type;
1403714189}
1403814190
14039static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {
14040 assert(ptr_type->id == TypeTableEntryIdPointer);
14191static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) {
14192 assert(ptr_type->id == ZigTypeIdPointer);
1404114193 return get_pointer_to_type_extra(g,
1404214194 ptr_type->data.pointer.child_type,
1404314195 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
......@@ -14046,15 +14198,15 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui
1404614198 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
1404714199}
1404814200
14049static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align) {
14201static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) {
1405014202 assert(is_slice(slice_type));
14051 TypeTableEntry *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry,
14203 ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry,
1405214204 new_align);
1405314205 return get_slice_type(g, ptr_type);
1405414206}
1405514207
14056static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) {
14057 assert(ptr_type->id == TypeTableEntryIdPointer);
14208static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
14209 assert(ptr_type->id == ZigTypeIdPointer);
1405814210 return get_pointer_to_type_extra(g,
1405914211 ptr_type->data.pointer.child_type,
1406014212 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
......@@ -14063,7 +14215,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL
1406314215 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
1406414216}
1406514217
14066static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
14218static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
1406714219 Error err;
1406814220 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
1406914221 if (type_is_invalid(array_ptr->value.type))
......@@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1407514227 if (type_is_invalid(elem_index->value.type))
1407614228 return ira->codegen->builtin_types.entry_invalid;
1407714229
14078 TypeTableEntry *ptr_type = orig_array_ptr_val->type;
14079 assert(ptr_type->id == TypeTableEntryIdPointer);
14230 ZigType *ptr_type = orig_array_ptr_val->type;
14231 assert(ptr_type->id == ZigTypeIdPointer);
1408014232
14081 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
14233 ZigType *array_type = ptr_type->data.pointer.child_type;
1408214234
1408314235 // At first return_type will be the pointer type we want to return, except with an optimistic alignment.
1408414236 // We will adjust return_type's alignment before returning it.
14085 TypeTableEntry *return_type;
14237 ZigType *return_type;
1408614238
1408714239 if (type_is_invalid(array_type)) {
1408814240 return array_type;
14089 } else if (array_type->id == TypeTableEntryIdArray ||
14090 (array_type->id == TypeTableEntryIdPointer &&
14241 } else if (array_type->id == ZigTypeIdArray ||
14242 (array_type->id == ZigTypeIdPointer &&
1409114243 array_type->data.pointer.ptr_len == PtrLenSingle &&
14092 array_type->data.pointer.child_type->id == TypeTableEntryIdArray))
14244 array_type->data.pointer.child_type->id == ZigTypeIdArray))
1409314245 {
14094 if (array_type->id == TypeTableEntryIdPointer) {
14246 if (array_type->id == ZigTypeIdPointer) {
1409514247 array_type = array_type->data.pointer.child_type;
1409614248 ptr_type = ptr_type->data.pointer.child_type;
1409714249 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
14098 orig_array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val);
14250 orig_array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
14251 elem_ptr_instruction->base.source_node);
14252 if (orig_array_ptr_val == nullptr)
14253 return ira->codegen->builtin_types.entry_invalid;
1409914254 }
1410014255 }
1410114256 if (array_type->data.array.len == 0) {
......@@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1410314258 buf_sprintf("index 0 outside array of size 0"));
1410414259 return ira->codegen->builtin_types.entry_invalid;
1410514260 }
14106 TypeTableEntry *child_type = array_type->data.array.child_type;
14261 ZigType *child_type = array_type->data.array.child_type;
1410714262 if (ptr_type->data.pointer.unaligned_bit_count == 0) {
1410814263 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
1410914264 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
......@@ -14122,7 +14277,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1412214277 elem_ptr_instruction->ptr_len,
1412314278 1, (uint32_t)bit_offset, (uint32_t)bit_width);
1412414279 }
14125 } else if (array_type->id == TypeTableEntryIdPointer) {
14280 } else if (array_type->id == ZigTypeIdPointer) {
1412614281 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
1412714282 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1412814283 buf_sprintf("index of single-item pointer"));
......@@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1413214287 } else if (is_slice(array_type)) {
1413314288 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
1413414289 elem_ptr_instruction->ptr_len);
14135 } else if (array_type->id == TypeTableEntryIdArgTuple) {
14290 } else if (array_type->id == ZigTypeIdArgTuple) {
1413614291 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
1413714292 if (!ptr_val)
1413814293 return ira->codegen->builtin_types.entry_invalid;
14139 ConstExprValue *args_val = const_ptr_pointee(ira->codegen, ptr_val);
14294 ConstExprValue *args_val = ir_const_ptr_pointee(ira, ptr_val, elem_ptr_instruction->base.source_node);
14295 if (args_val == nullptr)
14296 return ira->codegen->builtin_types.entry_invalid;
1414014297 size_t start = args_val->data.x_arg_tuple.start_index;
1414114298 size_t end = args_val->data.x_arg_tuple.end_index;
1414214299 uint64_t elem_index_val;
......@@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1415014307 return ira->codegen->builtin_types.entry_invalid;
1415114308 }
1415214309 size_t abs_index = start + index;
14153 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
14310 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
1415414311 assert(fn_entry);
14155 VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index);
14312 ZigVar *var = get_fn_var_by_index(fn_entry, abs_index);
1415614313 bool is_const = true;
1415714314 bool is_volatile = false;
1415814315 if (var) {
......@@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1416714324 return ira->codegen->builtin_types.entry_invalid;
1416814325 }
1416914326
14170 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
14327 ZigType *usize = ira->codegen->builtin_types.entry_usize;
1417114328 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
1417214329 if (casted_elem_index == ira->codegen->invalid_instruction)
1417314330 return ira->codegen->builtin_types.entry_invalid;
......@@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1418114338 uint64_t ptr_align = return_type->data.pointer.alignment;
1418214339 if (instr_is_comptime(casted_elem_index)) {
1418314340 uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);
14184 if (array_type->id == TypeTableEntryIdArray) {
14341 if (array_type->id == ZigTypeIdArray) {
1418514342 uint64_t array_len = array_type->data.array.len;
1418614343 if (index >= array_len) {
1418714344 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
......@@ -14212,120 +14369,126 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1421214369 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
1421314370 }
1421414371
14215 ConstExprValue *array_ptr_val;
1421614372 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
14217 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == TypeTableEntryIdArray) &&
14218 (array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val)) &&
14219 array_ptr_val->special != ConstValSpecialRuntime &&
14220 (array_type->id != TypeTableEntryIdPointer ||
14221 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
14373 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
14374 array_type->id == ZigTypeIdArray))
1422214375 {
14223 if (array_type->id == TypeTableEntryIdPointer) {
14224 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14225 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
14226 size_t new_index;
14227 size_t mem_size;
14228 size_t old_size;
14229 switch (array_ptr_val->data.x_ptr.special) {
14230 case ConstPtrSpecialInvalid:
14231 case ConstPtrSpecialDiscard:
14232 zig_unreachable();
14233 case ConstPtrSpecialRef:
14234 mem_size = 1;
14235 old_size = 1;
14236 new_index = index;
14237
14238 out_val->data.x_ptr.special = ConstPtrSpecialRef;
14239 out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
14240 break;
14241 case ConstPtrSpecialBaseArray:
14242 {
14243 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
14244 new_index = offset + index;
14245 mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
14246 old_size = mem_size - offset;
14247
14248 assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
14249
14250 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14251 out_val->data.x_ptr.data.base_array.array_val =
14252 array_ptr_val->data.x_ptr.data.base_array.array_val;
14253 out_val->data.x_ptr.data.base_array.elem_index = new_index;
14254 out_val->data.x_ptr.data.base_array.is_cstr =
14255 array_ptr_val->data.x_ptr.data.base_array.is_cstr;
14376 ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
14377 elem_ptr_instruction->base.source_node);
14378 if (array_ptr_val == nullptr)
14379 return ira->codegen->builtin_types.entry_invalid;
1425614380
14381 if (array_ptr_val->special != ConstValSpecialRuntime &&
14382 (array_type->id != ZigTypeIdPointer ||
14383 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
14384 {
14385 if (array_type->id == ZigTypeIdPointer) {
14386 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14387 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
14388 size_t new_index;
14389 size_t mem_size;
14390 size_t old_size;
14391 switch (array_ptr_val->data.x_ptr.special) {
14392 case ConstPtrSpecialInvalid:
14393 case ConstPtrSpecialDiscard:
14394 zig_unreachable();
14395 case ConstPtrSpecialRef:
14396 mem_size = 1;
14397 old_size = 1;
14398 new_index = index;
14399
14400 out_val->data.x_ptr.special = ConstPtrSpecialRef;
14401 out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
1425714402 break;
14258 }
14259 case ConstPtrSpecialBaseStruct:
14260 zig_panic("TODO elem ptr on a const inner struct");
14261 case ConstPtrSpecialHardCodedAddr:
14262 zig_unreachable();
14263 case ConstPtrSpecialFunction:
14264 zig_panic("TODO element ptr of a function casted to a ptr");
14265 }
14266 if (new_index >= mem_size) {
14267 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14268 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
14269 return ira->codegen->builtin_types.entry_invalid;
14270 }
14271 return return_type;
14272 } else if (is_slice(array_type)) {
14273 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
14274 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
14275 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
14276 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
14277 result->value.type = return_type;
14278 ir_link_new_instruction(result, &elem_ptr_instruction->base);
14403 case ConstPtrSpecialBaseArray:
14404 {
14405 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
14406 new_index = offset + index;
14407 mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
14408 old_size = mem_size - offset;
14409
14410 assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
14411
14412 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14413 out_val->data.x_ptr.data.base_array.array_val =
14414 array_ptr_val->data.x_ptr.data.base_array.array_val;
14415 out_val->data.x_ptr.data.base_array.elem_index = new_index;
14416 out_val->data.x_ptr.data.base_array.is_cstr =
14417 array_ptr_val->data.x_ptr.data.base_array.is_cstr;
14418
14419 break;
14420 }
14421 case ConstPtrSpecialBaseStruct:
14422 zig_panic("TODO elem ptr on a const inner struct");
14423 case ConstPtrSpecialHardCodedAddr:
14424 zig_unreachable();
14425 case ConstPtrSpecialFunction:
14426 zig_panic("TODO element ptr of a function casted to a ptr");
14427 }
14428 if (new_index >= mem_size) {
14429 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14430 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
14431 return ira->codegen->builtin_types.entry_invalid;
14432 }
1427914433 return return_type;
14280 }
14281 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
14282 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14283 uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
14284 if (index >= slice_len) {
14285 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14286 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
14287 index, slice_len));
14288 return ira->codegen->builtin_types.entry_invalid;
14289 }
14290 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
14291 switch (ptr_field->data.x_ptr.special) {
14292 case ConstPtrSpecialInvalid:
14293 case ConstPtrSpecialDiscard:
14294 zig_unreachable();
14295 case ConstPtrSpecialRef:
14296 out_val->data.x_ptr.special = ConstPtrSpecialRef;
14297 out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;
14298 break;
14299 case ConstPtrSpecialBaseArray:
14300 {
14301 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
14302 uint64_t new_index = offset + index;
14303 assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);
14304 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14305 out_val->data.x_ptr.data.base_array.array_val =
14306 ptr_field->data.x_ptr.data.base_array.array_val;
14307 out_val->data.x_ptr.data.base_array.elem_index = new_index;
14308 out_val->data.x_ptr.data.base_array.is_cstr =
14309 ptr_field->data.x_ptr.data.base_array.is_cstr;
14434 } else if (is_slice(array_type)) {
14435 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
14436 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
14437 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
14438 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
14439 result->value.type = return_type;
14440 ir_link_new_instruction(result, &elem_ptr_instruction->base);
14441 return return_type;
14442 }
14443 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
14444 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14445 uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
14446 if (index >= slice_len) {
14447 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14448 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
14449 index, slice_len));
14450 return ira->codegen->builtin_types.entry_invalid;
14451 }
14452 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
14453 switch (ptr_field->data.x_ptr.special) {
14454 case ConstPtrSpecialInvalid:
14455 case ConstPtrSpecialDiscard:
14456 zig_unreachable();
14457 case ConstPtrSpecialRef:
14458 out_val->data.x_ptr.special = ConstPtrSpecialRef;
14459 out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;
1431014460 break;
14311 }
14312 case ConstPtrSpecialBaseStruct:
14313 zig_panic("TODO elem ptr on a slice backed by const inner struct");
14314 case ConstPtrSpecialHardCodedAddr:
14315 zig_unreachable();
14316 case ConstPtrSpecialFunction:
14317 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
14461 case ConstPtrSpecialBaseArray:
14462 {
14463 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
14464 uint64_t new_index = offset + index;
14465 assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);
14466 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14467 out_val->data.x_ptr.data.base_array.array_val =
14468 ptr_field->data.x_ptr.data.base_array.array_val;
14469 out_val->data.x_ptr.data.base_array.elem_index = new_index;
14470 out_val->data.x_ptr.data.base_array.is_cstr =
14471 ptr_field->data.x_ptr.data.base_array.is_cstr;
14472 break;
14473 }
14474 case ConstPtrSpecialBaseStruct:
14475 zig_panic("TODO elem ptr on a slice backed by const inner struct");
14476 case ConstPtrSpecialHardCodedAddr:
14477 zig_unreachable();
14478 case ConstPtrSpecialFunction:
14479 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
14480 }
14481 return return_type;
14482 } else if (array_type->id == ZigTypeIdArray) {
14483 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14484 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14485 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
14486 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
14487 out_val->data.x_ptr.data.base_array.elem_index = index;
14488 return return_type;
14489 } else {
14490 zig_unreachable();
1431814491 }
14319 return return_type;
14320 } else if (array_type->id == TypeTableEntryIdArray) {
14321 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14322 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14323 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
14324 out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
14325 out_val->data.x_ptr.data.base_array.elem_index = index;
14326 return return_type;
14327 } else {
14328 zig_unreachable();
1432914492 }
1433014493 }
1433114494
......@@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1435114514}
1435214515
1435314516static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14354 TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
14355 IrInstruction *container_ptr, TypeTableEntry *container_type)
14517 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
14518 IrInstruction *container_ptr, ZigType *container_type)
1435614519{
1435714520 if (!is_slice(bare_struct_type)) {
1435814521 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
......@@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1436414527 if (tld->resolution == TldResolutionInvalid)
1436514528 return ira->codegen->invalid_instruction;
1436614529 TldFn *tld_fn = (TldFn *)tld;
14367 FnTableEntry *fn_entry = tld_fn->fn_entry;
14530 ZigFn *fn_entry = tld_fn->fn_entry;
1436814531 if (type_is_invalid(fn_entry->type_entry))
1436914532 return ira->codegen->invalid_instruction;
1437014533
......@@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1437614539 const char *prefix_name;
1437714540 if (is_slice(bare_struct_type)) {
1437814541 prefix_name = "";
14379 } else if (bare_struct_type->id == TypeTableEntryIdStruct) {
14542 } else if (bare_struct_type->id == ZigTypeIdStruct) {
1438014543 prefix_name = "struct ";
14381 } else if (bare_struct_type->id == TypeTableEntryIdEnum) {
14544 } else if (bare_struct_type->id == ZigTypeIdEnum) {
1438214545 prefix_name = "enum ";
14383 } else if (bare_struct_type->id == TypeTableEntryIdUnion) {
14546 } else if (bare_struct_type->id == ZigTypeIdUnion) {
1438414547 prefix_name = "union ";
1438514548 } else {
1438614549 prefix_name = "";
......@@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1439114554}
1439214555
1439314556static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
14394 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type)
14557 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)
1439514558{
1439614559 Error err;
1439714560
14398 TypeTableEntry *bare_type = container_ref_type(container_type);
14561 ZigType *bare_type = container_ref_type(container_type);
1439914562 if ((err = ensure_complete_type(ira->codegen, bare_type)))
1440014563 return ira->codegen->invalid_instruction;
1440114564
14402 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
14565 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1440314566 bool is_const = container_ptr->value.type->data.pointer.is_const;
1440414567 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;
14405 if (bare_type->id == TypeTableEntryIdStruct) {
14568 if (bare_type->id == ZigTypeIdStruct) {
1440614569 TypeStructField *field = find_struct_type_field(bare_type, field_name);
1440714570 if (field) {
1440814571 bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);
......@@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1441714580 return ira->codegen->invalid_instruction;
1441814581
1441914582 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14420 ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val);
14583 ConstExprValue *struct_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);
14584 if (struct_val == nullptr)
14585 return ira->codegen->invalid_instruction;
1442114586 if (type_is_invalid(struct_val->type))
1442214587 return ira->codegen->invalid_instruction;
1442314588 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
14424 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
14589 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
1442514590 is_const, is_volatile, PtrLenSingle, align_bytes,
1442614591 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
1442714592 (uint32_t)unaligned_bit_count_for_result_type);
......@@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1444714612 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
1444814613 source_instr, container_ptr, container_type);
1444914614 }
14450 } else if (bare_type->id == TypeTableEntryIdEnum) {
14615 } else if (bare_type->id == ZigTypeIdEnum) {
1445114616 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
1445214617 source_instr, container_ptr, container_type);
14453 } else if (bare_type->id == TypeTableEntryIdUnion) {
14618 } else if (bare_type->id == ZigTypeIdUnion) {
1445414619 TypeUnionField *field = find_union_type_field(bare_type, field_name);
1445514620 if (field) {
1445614621 if (instr_is_comptime(container_ptr)) {
......@@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1445914624 return ira->codegen->invalid_instruction;
1446014625
1446114626 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14462 ConstExprValue *union_val = const_ptr_pointee(ira->codegen, ptr_val);
14627 ConstExprValue *union_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);
14628 if (union_val == nullptr)
14629 return ira->codegen->invalid_instruction;
1446314630 if (type_is_invalid(union_val->type))
1446414631 return ira->codegen->invalid_instruction;
1446514632
......@@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1447614643
1447714644 ConstExprValue *payload_val = union_val->data.x_union.payload;
1447814645
14479 TypeTableEntry *field_type = field->type_entry;
14480 if (field_type->id == TypeTableEntryIdVoid) {
14646 ZigType *field_type = field->type_entry;
14647 if (field_type->id == ZigTypeIdVoid) {
1448114648 assert(payload_val == nullptr);
1448214649 payload_val = create_const_vals(1);
1448314650 payload_val->special = ConstValSpecialStatic;
1448414651 payload_val->type = field_type;
1448514652 }
1448614653
14487 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
14654 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
1448814655 is_const, is_volatile,
1448914656 PtrLenSingle,
1449014657 get_abi_alignment(ira->codegen, field_type), 0, 0);
......@@ -14531,7 +14698,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
1453114698}
1453214699
1453314700
14534static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
14701static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
1453514702 bool pointer_only = false;
1453614703 resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
1453714704 if (tld->resolution == TldResolutionInvalid)
......@@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
1454414711 case TldIdVar:
1454514712 {
1454614713 TldVar *tld_var = (TldVar *)tld;
14547 VariableTableEntry *var = tld_var->var;
14714 ZigVar *var = tld_var->var;
1454814715 if (tld_var->extern_lib_name != nullptr) {
1454914716 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
1455014717 }
......@@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
1455414721 case TldIdFn:
1455514722 {
1455614723 TldFn *tld_fn = (TldFn *)tld;
14557 FnTableEntry *fn_entry = tld_fn->fn_entry;
14724 ZigFn *fn_entry = tld_fn->fn_entry;
1455814725 assert(fn_entry->type_entry);
1455914726
1456014727 if (type_is_invalid(fn_entry->type_entry))
......@@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
1458214749 zig_unreachable();
1458314750}
1458414751
14585static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) {
14586 assert(err_set_type->id == TypeTableEntryIdErrorSet);
14752static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) {
14753 assert(err_set_type->id == ZigTypeIdErrorSet);
1458714754 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
1458814755 ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];
1458914756 if (buf_eql_buf(&err_table_entry->name, field_name)) {
......@@ -14593,14 +14760,14 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *
1459314760 return nullptr;
1459414761}
1459514762
14596static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
14763static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
1459714764 Error err;
1459814765 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
1459914766 if (type_is_invalid(container_ptr->value.type))
1460014767 return ira->codegen->builtin_types.entry_invalid;
1460114768
14602 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
14603 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
14769 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
14770 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1460414771
1460514772 Buf *field_name = field_ptr_instruction->field_name_buffer;
1460614773 if (!field_name) {
......@@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1461614783 if (type_is_invalid(container_type)) {
1461714784 return container_type;
1461814785 } else if (is_container_ref(container_type)) {
14619 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
14620 if (container_type->id == TypeTableEntryIdPointer) {
14621 TypeTableEntry *bare_type = container_ref_type(container_type);
14786 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14787 if (container_type->id == ZigTypeIdPointer) {
14788 ZigType *bare_type = container_ref_type(container_type);
1462214789 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
1462314790 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);
1462414791 ir_link_new_instruction(result, &field_ptr_instruction->base);
......@@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1463114798 } else if (is_array_ref(container_type)) {
1463214799 if (buf_eql_str(field_name, "len")) {
1463314800 ConstExprValue *len_val = create_const_vals(1);
14634 if (container_type->id == TypeTableEntryIdPointer) {
14801 if (container_type->id == ZigTypeIdPointer) {
1463514802 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
1463614803 } else {
1463714804 init_const_usize(ira->codegen, len_val, container_type->data.array.len);
1463814805 }
1463914806
14640 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
14807 ZigType *usize = ira->codegen->builtin_types.entry_usize;
1464114808 bool ptr_is_const = true;
1464214809 bool ptr_is_volatile = false;
1464314810 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
......@@ -14648,20 +14815,22 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1464814815 buf_ptr(&container_type->name)));
1464914816 return ira->codegen->builtin_types.entry_invalid;
1465014817 }
14651 } else if (container_type->id == TypeTableEntryIdArgTuple) {
14818 } else if (container_type->id == ZigTypeIdArgTuple) {
1465214819 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
1465314820 if (!container_ptr_val)
1465414821 return ira->codegen->builtin_types.entry_invalid;
1465514822
14656 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
14657 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
14823 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14824 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
14825 if (child_val == nullptr)
14826 return ira->codegen->builtin_types.entry_invalid;
1465814827
1465914828 if (buf_eql_str(field_name, "len")) {
1466014829 ConstExprValue *len_val = create_const_vals(1);
1466114830 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
1466214831 init_const_usize(ira->codegen, len_val, len);
1466314832
14664 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
14833 ZigType *usize = ira->codegen->builtin_types.entry_usize;
1466514834 bool ptr_is_const = true;
1466614835 bool ptr_is_volatile = false;
1466714836 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
......@@ -14672,14 +14841,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1467214841 buf_ptr(&container_type->name)));
1467314842 return ira->codegen->builtin_types.entry_invalid;
1467414843 }
14675 } else if (container_type->id == TypeTableEntryIdMetaType) {
14844 } else if (container_type->id == ZigTypeIdMetaType) {
1467614845 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
1467714846 if (!container_ptr_val)
1467814847 return ira->codegen->builtin_types.entry_invalid;
1467914848
14680 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
14681 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
14682 TypeTableEntry *child_type = child_val->data.x_type;
14849 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14850 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
14851 if (child_val == nullptr)
14852 return ira->codegen->builtin_types.entry_invalid;
14853 ZigType *child_type = child_val->data.x_type;
1468314854
1468414855 if (type_is_invalid(child_type)) {
1468514856 return ira->codegen->builtin_types.entry_invalid;
......@@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1468814859 bool ptr_is_const = true;
1468914860 bool ptr_is_volatile = false;
1469014861 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
14691 assert(ptr_field->type_entry->id == TypeTableEntryIdPointer);
14692 TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type;
14862 assert(ptr_field->type_entry->id == ZigTypeIdPointer);
14863 ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;
1469314864 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
1469414865 create_const_type(ira->codegen, child_type),
1469514866 ira->codegen->builtin_types.entry_type,
1469614867 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
1469714868 }
14698 if (child_type->id == TypeTableEntryIdEnum) {
14869 if (child_type->id == ZigTypeIdEnum) {
1469914870 if ((err = ensure_complete_type(ira->codegen, child_type)))
1470014871 return ira->codegen->builtin_types.entry_invalid;
1470114872
......@@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1471614887 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
1471714888 }
1471814889 }
14719 if (child_type->id == TypeTableEntryIdUnion &&
14890 if (child_type->id == ZigTypeIdUnion &&
1472014891 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
1472114892 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
1472214893 {
......@@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1472414895 return ira->codegen->builtin_types.entry_invalid;
1472514896 TypeUnionField *field = find_union_type_field(child_type, field_name);
1472614897 if (field) {
14727 TypeTableEntry *enum_type = child_type->data.unionation.tag_type;
14898 ZigType *enum_type = child_type->data.unionation.tag_type;
1472814899 bool ptr_is_const = true;
1472914900 bool ptr_is_volatile = false;
1473014901 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
......@@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1473614907 buf_sprintf("container '%s' has no member called '%s'",
1473714908 buf_ptr(&child_type->name), buf_ptr(field_name)));
1473814909 return ira->codegen->builtin_types.entry_invalid;
14739 } else if (child_type->id == TypeTableEntryIdErrorSet) {
14910 } else if (child_type->id == ZigTypeIdErrorSet) {
1474014911 ErrorTableEntry *err_entry;
14741 TypeTableEntry *err_set_type;
14912 ZigType *err_set_type;
1474214913 if (type_is_global_error_set(child_type)) {
1474314914 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);
1474414915 if (existing_entry) {
......@@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1478214953 bool ptr_is_volatile = false;
1478314954 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,
1478414955 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
14785 } else if (child_type->id == TypeTableEntryIdInt) {
14956 } else if (child_type->id == ZigTypeIdInt) {
1478614957 if (buf_eql_str(field_name, "bit_count")) {
1478714958 bool ptr_is_const = true;
1478814959 bool ptr_is_volatile = false;
......@@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1480414975 buf_ptr(&child_type->name), buf_ptr(field_name)));
1480514976 return ira->codegen->builtin_types.entry_invalid;
1480614977 }
14807 } else if (child_type->id == TypeTableEntryIdFloat) {
14978 } else if (child_type->id == ZigTypeIdFloat) {
1480814979 if (buf_eql_str(field_name, "bit_count")) {
1480914980 bool ptr_is_const = true;
1481014981 bool ptr_is_volatile = false;
......@@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1481914990 buf_ptr(&child_type->name), buf_ptr(field_name)));
1482014991 return ira->codegen->builtin_types.entry_invalid;
1482114992 }
14822 } else if (child_type->id == TypeTableEntryIdPointer) {
14993 } else if (child_type->id == ZigTypeIdPointer) {
1482314994 if (buf_eql_str(field_name, "Child")) {
1482414995 bool ptr_is_const = true;
1482514996 bool ptr_is_volatile = false;
......@@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1484115012 buf_ptr(&child_type->name), buf_ptr(field_name)));
1484215013 return ira->codegen->builtin_types.entry_invalid;
1484315014 }
14844 } else if (child_type->id == TypeTableEntryIdArray) {
15015 } else if (child_type->id == ZigTypeIdArray) {
1484515016 if (buf_eql_str(field_name, "Child")) {
1484615017 bool ptr_is_const = true;
1484715018 bool ptr_is_volatile = false;
......@@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1486315034 buf_ptr(&child_type->name), buf_ptr(field_name)));
1486415035 return ira->codegen->builtin_types.entry_invalid;
1486515036 }
14866 } else if (child_type->id == TypeTableEntryIdErrorUnion) {
15037 } else if (child_type->id == ZigTypeIdErrorUnion) {
1486715038 if (buf_eql_str(field_name, "Payload")) {
1486815039 bool ptr_is_const = true;
1486915040 bool ptr_is_volatile = false;
......@@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1488415055 buf_ptr(&child_type->name), buf_ptr(field_name)));
1488515056 return ira->codegen->builtin_types.entry_invalid;
1488615057 }
14887 } else if (child_type->id == TypeTableEntryIdOptional) {
15058 } else if (child_type->id == ZigTypeIdOptional) {
1488815059 if (buf_eql_str(field_name, "Child")) {
1488915060 bool ptr_is_const = true;
1489015061 bool ptr_is_volatile = false;
......@@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1489815069 buf_ptr(&child_type->name), buf_ptr(field_name)));
1489915070 return ira->codegen->builtin_types.entry_invalid;
1490015071 }
14901 } else if (child_type->id == TypeTableEntryIdFn) {
15072 } else if (child_type->id == ZigTypeIdFn) {
1490215073 if (buf_eql_str(field_name, "ReturnType")) {
1490315074 if (child_type->data.fn.fn_type_id.return_type == nullptr) {
1490415075 // Return type can only ever be null, if the function is generic
......@@ -14940,13 +15111,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1494015111 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
1494115112 return ira->codegen->builtin_types.entry_invalid;
1494215113 }
14943 } else if (container_type->id == TypeTableEntryIdNamespace) {
14944 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
15114 } else if (container_type->id == ZigTypeIdNamespace) {
15115 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1494515116 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
1494615117 if (!container_ptr_val)
1494715118 return ira->codegen->builtin_types.entry_invalid;
1494815119
14949 ConstExprValue *namespace_val = const_ptr_pointee(ira->codegen, container_ptr_val);
15120 ConstExprValue *namespace_val = ir_const_ptr_pointee(ira, container_ptr_val,
15121 field_ptr_instruction->base.source_node);
15122 if (namespace_val == nullptr)
15123 return ira->codegen->builtin_types.entry_invalid;
1495015124 assert(namespace_val->special == ConstValSpecialStatic);
1495115125
1495215126 ImportTableEntry *namespace_import = namespace_val->data.x_import;
......@@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1497515149 }
1497615150}
1497715151
14978static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) {
15152static ZigType *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) {
1497915153 IrInstruction *ptr = load_ptr_instruction->ptr->other;
1498015154 if (type_is_invalid(ptr->value.type))
1498115155 return ira->codegen->builtin_types.entry_invalid;
......@@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
1498615160 return result->value.type;
1498715161}
1498815162
14989static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
15163static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
1499015164 IrInstruction *ptr = store_ptr_instruction->ptr->other;
1499115165 if (type_is_invalid(ptr->value.type))
1499215166 return ptr->value.type;
......@@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1499515169 if (type_is_invalid(value->value.type))
1499615170 return value->value.type;
1499715171
14998 if (ptr->value.type->id != TypeTableEntryIdPointer) {
15172 if (ptr->value.type->id != ZigTypeIdPointer) {
1499915173 ir_add_error(ira, ptr,
1500015174 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
1500115175 return ira->codegen->builtin_types.entry_invalid;
......@@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1501015184 return ira->codegen->builtin_types.entry_invalid;
1501115185 }
1501215186
15013 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
15187 ZigType *child_type = ptr->value.type->data.pointer.child_type;
1501415188 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
1501515189 if (casted_value == ira->codegen->invalid_instruction)
1501615190 return ira->codegen->builtin_types.entry_invalid;
......@@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1502215196 }
1502315197 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {
1502415198 if (instr_is_comptime(casted_value)) {
15025 ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
15199 ConstExprValue *dest_val = ir_const_ptr_pointee(ira, &ptr->value, store_ptr_instruction->base.source_node);
15200 if (dest_val == nullptr)
15201 return ira->codegen->builtin_types.entry_invalid;
1502615202 if (dest_val->special != ConstValSpecialRuntime) {
1502715203 *dest_val = casted_value->value;
1502815204 if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
......@@ -15033,7 +15209,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1503315209 }
1503415210 ir_add_error(ira, &store_ptr_instruction->base,
1503515211 buf_sprintf("cannot store runtime value in compile time variable"));
15036 ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
15212 ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);
1503715213 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1503815214
1503915215 return ira->codegen->builtin_types.entry_invalid;
......@@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1504415220 return ira->codegen->builtin_types.entry_void;
1504515221}
1504615222
15047static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
15223static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
1504815224 IrInstruction *expr_value = typeof_instruction->value->other;
15049 TypeTableEntry *type_entry = expr_value->value.type;
15225 ZigType *type_entry = expr_value->value.type;
1505015226 if (type_is_invalid(type_entry))
1505115227 return ira->codegen->builtin_types.entry_invalid;
1505215228 switch (type_entry->id) {
15053 case TypeTableEntryIdInvalid:
15229 case ZigTypeIdInvalid:
1505415230 zig_unreachable(); // handled above
15055 case TypeTableEntryIdComptimeFloat:
15056 case TypeTableEntryIdComptimeInt:
15057 case TypeTableEntryIdUndefined:
15058 case TypeTableEntryIdNull:
15059 case TypeTableEntryIdNamespace:
15060 case TypeTableEntryIdBlock:
15061 case TypeTableEntryIdBoundFn:
15062 case TypeTableEntryIdMetaType:
15063 case TypeTableEntryIdVoid:
15064 case TypeTableEntryIdBool:
15065 case TypeTableEntryIdUnreachable:
15066 case TypeTableEntryIdInt:
15067 case TypeTableEntryIdFloat:
15068 case TypeTableEntryIdPointer:
15069 case TypeTableEntryIdArray:
15070 case TypeTableEntryIdStruct:
15071 case TypeTableEntryIdOptional:
15072 case TypeTableEntryIdErrorUnion:
15073 case TypeTableEntryIdErrorSet:
15074 case TypeTableEntryIdEnum:
15075 case TypeTableEntryIdUnion:
15076 case TypeTableEntryIdFn:
15077 case TypeTableEntryIdArgTuple:
15078 case TypeTableEntryIdOpaque:
15079 case TypeTableEntryIdPromise:
15231 case ZigTypeIdComptimeFloat:
15232 case ZigTypeIdComptimeInt:
15233 case ZigTypeIdUndefined:
15234 case ZigTypeIdNull:
15235 case ZigTypeIdNamespace:
15236 case ZigTypeIdBlock:
15237 case ZigTypeIdBoundFn:
15238 case ZigTypeIdMetaType:
15239 case ZigTypeIdVoid:
15240 case ZigTypeIdBool:
15241 case ZigTypeIdUnreachable:
15242 case ZigTypeIdInt:
15243 case ZigTypeIdFloat:
15244 case ZigTypeIdPointer:
15245 case ZigTypeIdArray:
15246 case ZigTypeIdStruct:
15247 case ZigTypeIdOptional:
15248 case ZigTypeIdErrorUnion:
15249 case ZigTypeIdErrorSet:
15250 case ZigTypeIdEnum:
15251 case ZigTypeIdUnion:
15252 case ZigTypeIdFn:
15253 case ZigTypeIdArgTuple:
15254 case ZigTypeIdOpaque:
15255 case ZigTypeIdPromise:
1508015256 {
1508115257 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
1508215258 out_val->data.x_type = type_entry;
......@@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
1508815264 zig_unreachable();
1508915265}
1509015266
15091static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
15267static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1509215268 IrInstructionToPtrType *to_ptr_type_instruction)
1509315269{
1509415270 IrInstruction *value = to_ptr_type_instruction->value->other;
15095 TypeTableEntry *type_entry = value->value.type;
15271 ZigType *type_entry = value->value.type;
1509615272 if (type_is_invalid(type_entry))
1509715273 return type_entry;
1509815274
15099 TypeTableEntry *ptr_type;
15100 if (type_entry->id == TypeTableEntryIdArray) {
15275 ZigType *ptr_type;
15276 if (type_entry->id == ZigTypeIdArray) {
1510115277 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
1510215278 } else if (is_slice(type_entry)) {
1510315279 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);
15104 } else if (type_entry->id == TypeTableEntryIdArgTuple) {
15280 } else if (type_entry->id == ZigTypeIdArgTuple) {
1510515281 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
1510615282 if (!arg_tuple_val)
1510715283 return ira->codegen->builtin_types.entry_invalid;
......@@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1511715293 return ira->codegen->builtin_types.entry_type;
1511815294}
1511915295
15120static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
15296static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
1512115297 IrInstructionPtrTypeChild *ptr_type_child_instruction)
1512215298{
1512315299 IrInstruction *type_value = ptr_type_child_instruction->value->other;
15124 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
15300 ZigType *type_entry = ir_resolve_type(ira, type_value);
1512515301 if (type_is_invalid(type_entry))
1512615302 return type_entry;
1512715303
15128 if (type_entry->id != TypeTableEntryIdPointer) {
15304 if (type_entry->id != ZigTypeIdPointer) {
1512915305 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
1513015306 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
1513115307 return ira->codegen->builtin_types.entry_invalid;
......@@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
1513615312 return ira->codegen->builtin_types.entry_type;
1513715313}
1513815314
15139static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
15315static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
1514015316 if (ira->new_irb.exec->is_inline) {
1514115317 // ignore setCold when running functions at compile time
1514215318 ir_build_const_from(ira, &instruction->base);
......@@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
1514815324 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
1514915325 return ira->codegen->builtin_types.entry_invalid;
1515015326
15151 FnTableEntry *fn_entry = scope_fn_entry(instruction->base.scope);
15327 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
1515215328 if (fn_entry == nullptr) {
1515315329 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));
1515415330 return ira->codegen->builtin_types.entry_invalid;
......@@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
1516615342 ir_build_const_from(ira, &instruction->base);
1516715343 return ira->codegen->builtin_types.entry_void;
1516815344}
15169static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15345static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1517015346 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
1517115347{
1517215348 if (ira->new_irb.exec->is_inline) {
......@@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1518715363 break;
1518815364 } else if (scope->id == ScopeIdFnDef) {
1518915365 ScopeFnDef *def_scope = (ScopeFnDef *)scope;
15190 FnTableEntry *target_fn = def_scope->fn_entry;
15366 ZigFn *target_fn = def_scope->fn_entry;
1519115367 assert(target_fn->def_scope != nullptr);
1519215368 safety_off_ptr = &target_fn->def_scope->safety_off;
1519315369 safety_set_node_ptr = &target_fn->def_scope->safety_set_node;
......@@ -15223,11 +15399,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1522315399 return ira->codegen->builtin_types.entry_void;
1522415400}
1522515401
15226static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15402static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1522715403 IrInstructionSetFloatMode *instruction)
1522815404{
1522915405 IrInstruction *target_instruction = instruction->scope_value->other;
15230 TypeTableEntry *target_type = target_instruction->value.type;
15406 ZigType *target_type = target_instruction->value.type;
1523115407 if (type_is_invalid(target_type))
1523215408 return ira->codegen->builtin_types.entry_invalid;
1523315409 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
......@@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1524215418
1524315419 bool *fast_math_on_ptr;
1524415420 AstNode **fast_math_set_node_ptr;
15245 if (target_type->id == TypeTableEntryIdBlock) {
15421 if (target_type->id == ZigTypeIdBlock) {
1524615422 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
1524715423 fast_math_on_ptr = &block_scope->fast_math_on;
1524815424 fast_math_set_node_ptr = &block_scope->fast_math_set_node;
15249 } else if (target_type->id == TypeTableEntryIdFn) {
15425 } else if (target_type->id == ZigTypeIdFn) {
1525015426 assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
15251 FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
15427 ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
1525215428 assert(target_fn->def_scope);
1525315429 fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
1525415430 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
15255 } else if (target_type->id == TypeTableEntryIdMetaType) {
15431 } else if (target_type->id == ZigTypeIdMetaType) {
1525615432 ScopeDecls *decls_scope;
15257 TypeTableEntry *type_arg = target_val->data.x_type;
15258 if (type_arg->id == TypeTableEntryIdStruct) {
15433 ZigType *type_arg = target_val->data.x_type;
15434 if (type_arg->id == ZigTypeIdStruct) {
1525915435 decls_scope = type_arg->data.structure.decls_scope;
15260 } else if (type_arg->id == TypeTableEntryIdEnum) {
15436 } else if (type_arg->id == ZigTypeIdEnum) {
1526115437 decls_scope = type_arg->data.enumeration.decls_scope;
15262 } else if (type_arg->id == TypeTableEntryIdUnion) {
15438 } else if (type_arg->id == ZigTypeIdUnion) {
1526315439 decls_scope = type_arg->data.unionation.decls_scope;
1526415440 } else {
1526515441 ir_add_error_node(ira, target_instruction->source_node,
......@@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1529415470 return ira->codegen->builtin_types.entry_void;
1529515471}
1529615472
15297static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15473static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1529815474 IrInstructionSliceType *slice_type_instruction)
1529915475{
1530015476 Error err;
......@@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1530415480 return ira->codegen->builtin_types.entry_invalid;
1530515481 }
1530615482
15307 TypeTableEntry *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other);
15483 ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other);
1530815484 if (type_is_invalid(child_type))
1530915485 return ira->codegen->builtin_types.entry_invalid;
1531015486
......@@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1531815494 bool is_volatile = slice_type_instruction->is_volatile;
1531915495
1532015496 switch (child_type->id) {
15321 case TypeTableEntryIdInvalid: // handled above
15497 case ZigTypeIdInvalid: // handled above
1532215498 zig_unreachable();
15323 case TypeTableEntryIdUnreachable:
15324 case TypeTableEntryIdUndefined:
15325 case TypeTableEntryIdNull:
15326 case TypeTableEntryIdBlock:
15327 case TypeTableEntryIdArgTuple:
15328 case TypeTableEntryIdOpaque:
15499 case ZigTypeIdUnreachable:
15500 case ZigTypeIdUndefined:
15501 case ZigTypeIdNull:
15502 case ZigTypeIdBlock:
15503 case ZigTypeIdArgTuple:
15504 case ZigTypeIdOpaque:
1532915505 ir_add_error_node(ira, slice_type_instruction->base.source_node,
1533015506 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));
1533115507 return ira->codegen->builtin_types.entry_invalid;
15332 case TypeTableEntryIdMetaType:
15333 case TypeTableEntryIdVoid:
15334 case TypeTableEntryIdBool:
15335 case TypeTableEntryIdInt:
15336 case TypeTableEntryIdFloat:
15337 case TypeTableEntryIdPointer:
15338 case TypeTableEntryIdArray:
15339 case TypeTableEntryIdStruct:
15340 case TypeTableEntryIdComptimeFloat:
15341 case TypeTableEntryIdComptimeInt:
15342 case TypeTableEntryIdOptional:
15343 case TypeTableEntryIdErrorUnion:
15344 case TypeTableEntryIdErrorSet:
15345 case TypeTableEntryIdEnum:
15346 case TypeTableEntryIdUnion:
15347 case TypeTableEntryIdFn:
15348 case TypeTableEntryIdNamespace:
15349 case TypeTableEntryIdBoundFn:
15350 case TypeTableEntryIdPromise:
15508 case ZigTypeIdMetaType:
15509 case ZigTypeIdVoid:
15510 case ZigTypeIdBool:
15511 case ZigTypeIdInt:
15512 case ZigTypeIdFloat:
15513 case ZigTypeIdPointer:
15514 case ZigTypeIdArray:
15515 case ZigTypeIdStruct:
15516 case ZigTypeIdComptimeFloat:
15517 case ZigTypeIdComptimeInt:
15518 case ZigTypeIdOptional:
15519 case ZigTypeIdErrorUnion:
15520 case ZigTypeIdErrorSet:
15521 case ZigTypeIdEnum:
15522 case ZigTypeIdUnion:
15523 case ZigTypeIdFn:
15524 case ZigTypeIdNamespace:
15525 case ZigTypeIdBoundFn:
15526 case ZigTypeIdPromise:
1535115527 {
1535215528 if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))
1535315529 return ira->codegen->builtin_types.entry_invalid;
15354 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
15530 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
1535515531 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0);
15356 TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type);
15532 ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type);
1535715533 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
1535815534 out_val->data.x_type = result_type;
1535915535 return ira->codegen->builtin_types.entry_type;
......@@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1536215538 zig_unreachable();
1536315539}
1536415540
15365static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {
15541static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {
1536615542 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
1536715543
1536815544 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
......@@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
1539215568 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
1539315569 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
1539415570
15395 TypeTableEntry *return_type = ira->codegen->builtin_types.entry_void;
15571 ZigType *return_type = ira->codegen->builtin_types.entry_void;
1539615572 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
1539715573 AsmOutput *asm_output = asm_expr->output_list.at(i);
1539815574 if (asm_output->return_type) {
......@@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
1541415590 return return_type;
1541515591}
1541615592
15417static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
15593static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,
1541815594 IrInstructionArrayType *array_type_instruction)
1541915595{
15596 Error err;
15597
1542015598 IrInstruction *size_value = array_type_instruction->size->other;
1542115599 uint64_t size;
1542215600 if (!ir_resolve_usize(ira, size_value, &size))
1542315601 return ira->codegen->builtin_types.entry_invalid;
1542415602
1542515603 IrInstruction *child_type_value = array_type_instruction->child_type->other;
15426 TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);
15604 ZigType *child_type = ir_resolve_type(ira, child_type_value);
1542715605 if (type_is_invalid(child_type))
1542815606 return ira->codegen->builtin_types.entry_invalid;
1542915607 switch (child_type->id) {
15430 case TypeTableEntryIdInvalid: // handled above
15608 case ZigTypeIdInvalid: // handled above
1543115609 zig_unreachable();
15432 case TypeTableEntryIdUnreachable:
15433 case TypeTableEntryIdUndefined:
15434 case TypeTableEntryIdNull:
15435 case TypeTableEntryIdBlock:
15436 case TypeTableEntryIdArgTuple:
15437 case TypeTableEntryIdOpaque:
15610 case ZigTypeIdUnreachable:
15611 case ZigTypeIdUndefined:
15612 case ZigTypeIdNull:
15613 case ZigTypeIdBlock:
15614 case ZigTypeIdArgTuple:
15615 case ZigTypeIdOpaque:
1543815616 ir_add_error_node(ira, array_type_instruction->base.source_node,
1543915617 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
1544015618 return ira->codegen->builtin_types.entry_invalid;
15441 case TypeTableEntryIdMetaType:
15442 case TypeTableEntryIdVoid:
15443 case TypeTableEntryIdBool:
15444 case TypeTableEntryIdInt:
15445 case TypeTableEntryIdFloat:
15446 case TypeTableEntryIdPointer:
15447 case TypeTableEntryIdArray:
15448 case TypeTableEntryIdStruct:
15449 case TypeTableEntryIdComptimeFloat:
15450 case TypeTableEntryIdComptimeInt:
15451 case TypeTableEntryIdOptional:
15452 case TypeTableEntryIdErrorUnion:
15453 case TypeTableEntryIdErrorSet:
15454 case TypeTableEntryIdEnum:
15455 case TypeTableEntryIdUnion:
15456 case TypeTableEntryIdFn:
15457 case TypeTableEntryIdNamespace:
15458 case TypeTableEntryIdBoundFn:
15459 case TypeTableEntryIdPromise:
15619 case ZigTypeIdMetaType:
15620 case ZigTypeIdVoid:
15621 case ZigTypeIdBool:
15622 case ZigTypeIdInt:
15623 case ZigTypeIdFloat:
15624 case ZigTypeIdPointer:
15625 case ZigTypeIdArray:
15626 case ZigTypeIdStruct:
15627 case ZigTypeIdComptimeFloat:
15628 case ZigTypeIdComptimeInt:
15629 case ZigTypeIdOptional:
15630 case ZigTypeIdErrorUnion:
15631 case ZigTypeIdErrorSet:
15632 case ZigTypeIdEnum:
15633 case ZigTypeIdUnion:
15634 case ZigTypeIdFn:
15635 case ZigTypeIdNamespace:
15636 case ZigTypeIdBoundFn:
15637 case ZigTypeIdPromise:
1546015638 {
15461 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
15639 if ((err = ensure_complete_type(ira->codegen, child_type)))
15640 return ira->codegen->builtin_types.entry_invalid;
15641 ZigType *result_type = get_array_type(ira->codegen, child_type, size);
1546215642 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
1546315643 out_val->data.x_type = result_type;
1546415644 return ira->codegen->builtin_types.entry_type;
......@@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1546715647 zig_unreachable();
1546815648}
1546915649
15470static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
15471 TypeTableEntry *promise_type;
15650static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
15651 ZigType *promise_type;
1547215652
1547315653 if (instruction->payload_type == nullptr) {
1547415654 promise_type = ira->codegen->builtin_types.entry_promise;
1547515655 } else {
15476 TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload_type->other);
15656 ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->other);
1547715657 if (type_is_invalid(payload_type))
1547815658 return ira->codegen->builtin_types.entry_invalid;
1547915659
......@@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns
1548515665 return ira->codegen->builtin_types.entry_type;
1548615666}
1548715667
15488static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
15668static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,
1548915669 IrInstructionSizeOf *size_of_instruction)
1549015670{
1549115671 Error err;
1549215672 IrInstruction *type_value = size_of_instruction->type_value->other;
15493 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
15673 ZigType *type_entry = ir_resolve_type(ira, type_value);
1549415674
1549515675 if ((err = ensure_complete_type(ira->codegen, type_entry)))
1549615676 return ira->codegen->builtin_types.entry_invalid;
1549715677
1549815678 switch (type_entry->id) {
15499 case TypeTableEntryIdInvalid: // handled above
15679 case ZigTypeIdInvalid: // handled above
1550015680 zig_unreachable();
15501 case TypeTableEntryIdUnreachable:
15502 case TypeTableEntryIdUndefined:
15503 case TypeTableEntryIdNull:
15504 case TypeTableEntryIdBlock:
15505 case TypeTableEntryIdComptimeFloat:
15506 case TypeTableEntryIdComptimeInt:
15507 case TypeTableEntryIdBoundFn:
15508 case TypeTableEntryIdMetaType:
15509 case TypeTableEntryIdNamespace:
15510 case TypeTableEntryIdArgTuple:
15511 case TypeTableEntryIdOpaque:
15681 case ZigTypeIdUnreachable:
15682 case ZigTypeIdUndefined:
15683 case ZigTypeIdNull:
15684 case ZigTypeIdBlock:
15685 case ZigTypeIdComptimeFloat:
15686 case ZigTypeIdComptimeInt:
15687 case ZigTypeIdBoundFn:
15688 case ZigTypeIdMetaType:
15689 case ZigTypeIdNamespace:
15690 case ZigTypeIdArgTuple:
15691 case ZigTypeIdOpaque:
1551215692 ir_add_error_node(ira, size_of_instruction->base.source_node,
1551315693 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
1551415694 return ira->codegen->builtin_types.entry_invalid;
15515 case TypeTableEntryIdVoid:
15516 case TypeTableEntryIdBool:
15517 case TypeTableEntryIdInt:
15518 case TypeTableEntryIdFloat:
15519 case TypeTableEntryIdPointer:
15520 case TypeTableEntryIdArray:
15521 case TypeTableEntryIdStruct:
15522 case TypeTableEntryIdOptional:
15523 case TypeTableEntryIdErrorUnion:
15524 case TypeTableEntryIdErrorSet:
15525 case TypeTableEntryIdEnum:
15526 case TypeTableEntryIdUnion:
15527 case TypeTableEntryIdFn:
15528 case TypeTableEntryIdPromise:
15695 case ZigTypeIdVoid:
15696 case ZigTypeIdBool:
15697 case ZigTypeIdInt:
15698 case ZigTypeIdFloat:
15699 case ZigTypeIdPointer:
15700 case ZigTypeIdArray:
15701 case ZigTypeIdStruct:
15702 case ZigTypeIdOptional:
15703 case ZigTypeIdErrorUnion:
15704 case ZigTypeIdErrorSet:
15705 case ZigTypeIdEnum:
15706 case ZigTypeIdUnion:
15707 case ZigTypeIdFn:
15708 case ZigTypeIdPromise:
1552915709 {
1553015710 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
1553115711 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);
......@@ -15536,14 +15716,14 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
1553615716 zig_unreachable();
1553715717}
1553815718
15539static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
15719static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
1554015720 IrInstruction *value = instruction->value->other;
1554115721 if (type_is_invalid(value->value.type))
1554215722 return ira->codegen->builtin_types.entry_invalid;
1554315723
15544 TypeTableEntry *type_entry = value->value.type;
15724 ZigType *type_entry = value->value.type;
1554515725
15546 if (type_entry->id == TypeTableEntryIdOptional) {
15726 if (type_entry->id == ZigTypeIdOptional) {
1554715727 if (instr_is_comptime(value)) {
1554815728 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
1554915729 if (!maybe_val)
......@@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1555615736
1555715737 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
1555815738 return ira->codegen->builtin_types.entry_bool;
15559 } else if (type_entry->id == TypeTableEntryIdNull) {
15739 } else if (type_entry->id == ZigTypeIdNull) {
1556015740 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1556115741 out_val->data.x_bool = false;
1556215742 return ira->codegen->builtin_types.entry_bool;
......@@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1556715747 }
1556815748}
1556915749
15570static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15750static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1557115751 IrInstructionUnwrapOptional *unwrap_maybe_instruction)
1557215752{
1557315753 IrInstruction *value = unwrap_maybe_instruction->value->other;
1557415754 if (type_is_invalid(value->value.type))
1557515755 return ira->codegen->builtin_types.entry_invalid;
1557615756
15577 TypeTableEntry *ptr_type = value->value.type;
15578 assert(ptr_type->id == TypeTableEntryIdPointer);
15757 ZigType *ptr_type = value->value.type;
15758 assert(ptr_type->id == ZigTypeIdPointer);
1557915759
15580 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
15760 ZigType *type_entry = ptr_type->data.pointer.child_type;
1558115761 if (type_is_invalid(type_entry)) {
1558215762 return ira->codegen->builtin_types.entry_invalid;
15583 } else if (type_entry->id != TypeTableEntryIdOptional) {
15763 } else if (type_entry->id != ZigTypeIdOptional) {
1558415764 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
1558515765 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
1558615766 return ira->codegen->builtin_types.entry_invalid;
1558715767 }
15588 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
15589 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
15768 ZigType *child_type = type_entry->data.maybe.child_type;
15769 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
1559015770 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
1559115771 PtrLenSingle,
1559215772 get_abi_alignment(ira->codegen, child_type), 0, 0);
......@@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1559515775 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
1559615776 if (!val)
1559715777 return ira->codegen->builtin_types.entry_invalid;
15598 ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val);
15778 ConstExprValue *maybe_val = ir_const_ptr_pointee(ira, val, unwrap_maybe_instruction->base.source_node);
15779 if (maybe_val == nullptr)
15780 return ira->codegen->builtin_types.entry_invalid;
1559915781
1560015782 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
1560115783 if (optional_value_is_null(maybe_val)) {
......@@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1561915801 return result_type;
1562015802}
1562115803
15622static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
15804static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
1562315805 IrInstruction *value = ctz_instruction->value->other;
1562415806 if (type_is_invalid(value->value.type)) {
1562515807 return ira->codegen->builtin_types.entry_invalid;
15626 } else if (value->value.type->id == TypeTableEntryIdInt) {
15627 TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,
15808 } else if (value->value.type->id == ZigTypeIdInt) {
15809 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
1562815810 value->value.type->data.integral.bit_count);
1562915811 if (value->value.special != ConstValSpecialRuntime) {
1563015812 size_t result = bigint_ctz(&value->value.data.x_bigint,
......@@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
1564315825 }
1564415826}
1564515827
15646static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
15828static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
1564715829 IrInstruction *value = clz_instruction->value->other;
1564815830 if (type_is_invalid(value->value.type)) {
1564915831 return ira->codegen->builtin_types.entry_invalid;
15650 } else if (value->value.type->id == TypeTableEntryIdInt) {
15651 TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,
15832 } else if (value->value.type->id == ZigTypeIdInt) {
15833 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
1565215834 value->value.type->data.integral.bit_count);
1565315835 if (value->value.special != ConstValSpecialRuntime) {
1565415836 size_t result = bigint_clz(&value->value.data.x_bigint,
......@@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
1566715849 }
1566815850}
1566915851
15670static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
15852static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
1567115853 IrInstruction *value = instruction->value->other;
1567215854 if (type_is_invalid(value->value.type))
1567315855 return ira->codegen->builtin_types.entry_invalid;
1567415856
15675 if (value->value.type->id != TypeTableEntryIdInt && value->value.type->id != TypeTableEntryIdComptimeInt) {
15857 if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) {
1567615858 ir_add_error(ira, value,
1567715859 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
1567815860 return ira->codegen->builtin_types.entry_invalid;
......@@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru
1568815870 bigint_init_unsigned(&out_val->data.x_bigint, result);
1568915871 return ira->codegen->builtin_types.entry_num_lit_int;
1569015872 }
15691 if (value->value.type->id == TypeTableEntryIdComptimeInt) {
15873 if (value->value.type->id == ZigTypeIdComptimeInt) {
1569215874 Buf *val_buf = buf_alloc();
1569315875 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
1569415876 ir_add_error(ira, &instruction->base,
......@@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
1571315895 if (type_is_invalid(value->value.type))
1571415896 return ira->codegen->invalid_instruction;
1571515897
15716 if (value->value.type->id == TypeTableEntryIdEnum) {
15898 if (value->value.type->id == ZigTypeIdEnum) {
1571715899 return value;
1571815900 }
1571915901
15720 if (value->value.type->id != TypeTableEntryIdUnion) {
15902 if (value->value.type->id != ZigTypeIdUnion) {
1572115903 ir_add_error(ira, value,
1572215904 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));
1572315905 return ira->codegen->invalid_instruction;
......@@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
1573115913 return ira->codegen->invalid_instruction;
1573215914 }
1573315915
15734 TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type;
15735 assert(tag_type->id == TypeTableEntryIdEnum);
15916 ZigType *tag_type = value->value.type->data.unionation.tag_type;
15917 assert(tag_type->id == ZigTypeIdEnum);
1573615918
1573715919 if (instr_is_comptime(value)) {
1573815920 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
1575215934 return result;
1575315935}
1575415936
15755static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15937static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1575615938 IrInstructionSwitchBr *switch_br_instruction)
1575715939{
1575815940 IrInstruction *target_value = switch_br_instruction->target_value->other;
......@@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1578415966 if (type_is_invalid(case_value->value.type))
1578515967 return ir_unreach_error(ira);
1578615968
15787 if (case_value->value.type->id == TypeTableEntryIdEnum) {
15969 if (case_value->value.type->id == ZigTypeIdEnum) {
1578815970 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);
1578915971 if (type_is_invalid(case_value->value.type))
1579015972 return ir_unreach_error(ira);
......@@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1583116013 if (type_is_invalid(new_value->value.type))
1583216014 continue;
1583316015
15834 if (new_value->value.type->id == TypeTableEntryIdEnum) {
16016 if (new_value->value.type->id == ZigTypeIdEnum) {
1583516017 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);
1583616018 if (type_is_invalid(new_value->value.type))
1583716019 continue;
......@@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1586016042 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
1586116043}
1586216044
15863static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16045static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1586416046 IrInstructionSwitchTarget *switch_target_instruction)
1586516047{
1586616048 Error err;
......@@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1586816050 if (type_is_invalid(target_value_ptr->value.type))
1586916051 return ira->codegen->builtin_types.entry_invalid;
1587016052
15871 if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {
16053 if (target_value_ptr->value.type->id == ZigTypeIdMetaType) {
1587216054 assert(instr_is_comptime(target_value_ptr));
15873 TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;
15874 assert(ptr_type->id == TypeTableEntryIdPointer);
16055 ZigType *ptr_type = target_value_ptr->value.data.x_type;
16056 assert(ptr_type->id == ZigTypeIdPointer);
1587516057 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
1587616058 out_val->type = ira->codegen->builtin_types.entry_type;
1587716059 out_val->data.x_type = ptr_type->data.pointer.child_type;
1587816060 return out_val->type;
1587916061 }
1588016062
15881 if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {
16063 if (target_value_ptr->value.type->id != ZigTypeIdPointer) {
1588216064 ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
1588316065 return ira->codegen->builtin_types.entry_invalid;
1588416066 }
1588516067
15886 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
16068 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
1588716069 ConstExprValue *pointee_val = nullptr;
1588816070 if (instr_is_comptime(target_value_ptr)) {
15889 pointee_val = const_ptr_pointee(ira->codegen, &target_value_ptr->value);
16071 pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node);
16072 if (pointee_val == nullptr)
16073 return ira->codegen->builtin_types.entry_invalid;
16074
1589016075 if (pointee_val->special == ConstValSpecialRuntime)
1589116076 pointee_val = nullptr;
1589216077 }
......@@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1589416079 return ira->codegen->builtin_types.entry_invalid;
1589516080
1589616081 switch (target_type->id) {
15897 case TypeTableEntryIdInvalid:
16082 case ZigTypeIdInvalid:
1589816083 zig_unreachable();
15899 case TypeTableEntryIdMetaType:
15900 case TypeTableEntryIdVoid:
15901 case TypeTableEntryIdBool:
15902 case TypeTableEntryIdInt:
15903 case TypeTableEntryIdFloat:
15904 case TypeTableEntryIdComptimeFloat:
15905 case TypeTableEntryIdComptimeInt:
15906 case TypeTableEntryIdPointer:
15907 case TypeTableEntryIdPromise:
15908 case TypeTableEntryIdFn:
15909 case TypeTableEntryIdNamespace:
15910 case TypeTableEntryIdErrorSet:
16084 case ZigTypeIdMetaType:
16085 case ZigTypeIdVoid:
16086 case ZigTypeIdBool:
16087 case ZigTypeIdInt:
16088 case ZigTypeIdFloat:
16089 case ZigTypeIdComptimeFloat:
16090 case ZigTypeIdComptimeInt:
16091 case ZigTypeIdPointer:
16092 case ZigTypeIdPromise:
16093 case ZigTypeIdFn:
16094 case ZigTypeIdNamespace:
16095 case ZigTypeIdErrorSet:
1591116096 if (pointee_val) {
1591216097 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
1591316098 copy_const_val(out_val, pointee_val, true);
......@@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1591716102
1591816103 ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);
1591916104 return target_type;
15920 case TypeTableEntryIdUnion: {
16105 case ZigTypeIdUnion: {
1592116106 AstNode *decl_node = target_type->data.unionation.decl_node;
1592216107 if (!decl_node->data.container_decl.auto_enum &&
1592316108 decl_node->data.container_decl.init_arg_expr == nullptr)
......@@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1592816113 buf_sprintf("consider 'union(enum)' here"));
1592916114 return ira->codegen->builtin_types.entry_invalid;
1593016115 }
15931 TypeTableEntry *tag_type = target_type->data.unionation.tag_type;
16116 ZigType *tag_type = target_type->data.unionation.tag_type;
1593216117 assert(tag_type != nullptr);
15933 assert(tag_type->id == TypeTableEntryIdEnum);
16118 assert(tag_type->id == ZigTypeIdEnum);
1593416119 if (pointee_val) {
1593516120 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
1593616121 bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag);
......@@ -15953,7 +16138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1595316138 ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);
1595416139 return tag_type;
1595516140 }
15956 case TypeTableEntryIdEnum: {
16141 case ZigTypeIdEnum: {
1595716142 if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))
1595816143 return ira->codegen->builtin_types.entry_invalid;
1595916144 if (target_type->data.enumeration.src_field_count < 2) {
......@@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1597516160 ir_link_new_instruction(enum_value, &switch_target_instruction->base);
1597616161 return target_type;
1597716162 }
15978 case TypeTableEntryIdErrorUnion:
15979 case TypeTableEntryIdUnreachable:
15980 case TypeTableEntryIdArray:
15981 case TypeTableEntryIdStruct:
15982 case TypeTableEntryIdUndefined:
15983 case TypeTableEntryIdNull:
15984 case TypeTableEntryIdOptional:
15985 case TypeTableEntryIdBlock:
15986 case TypeTableEntryIdBoundFn:
15987 case TypeTableEntryIdArgTuple:
15988 case TypeTableEntryIdOpaque:
16163 case ZigTypeIdErrorUnion:
16164 case ZigTypeIdUnreachable:
16165 case ZigTypeIdArray:
16166 case ZigTypeIdStruct:
16167 case ZigTypeIdUndefined:
16168 case ZigTypeIdNull:
16169 case ZigTypeIdOptional:
16170 case ZigTypeIdBlock:
16171 case ZigTypeIdBoundFn:
16172 case ZigTypeIdArgTuple:
16173 case ZigTypeIdOpaque:
1598916174 ir_add_error(ira, &switch_target_instruction->base,
1599016175 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
1599116176 return ira->codegen->builtin_types.entry_invalid;
......@@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1599316178 zig_unreachable();
1599416179}
1599516180
15996static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
16181static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
1599716182 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
1599816183 if (type_is_invalid(target_value_ptr->value.type))
1599916184 return ira->codegen->builtin_types.entry_invalid;
......@@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1600216187 if (type_is_invalid(prong_value->value.type))
1600316188 return ira->codegen->builtin_types.entry_invalid;
1600416189
16005 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
16006 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
16007 if (target_type->id == TypeTableEntryIdUnion) {
16190 assert(target_value_ptr->value.type->id == ZigTypeIdPointer);
16191 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
16192 if (target_type->id == ZigTypeIdUnion) {
1600816193 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);
1600916194 if (!prong_val)
1601016195 return ira->codegen->builtin_types.entry_invalid;
1601116196
16012 assert(prong_value->value.type->id == TypeTableEntryIdEnum);
16197 assert(prong_value->value.type->id == ZigTypeIdEnum);
1601316198 TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);
1601416199
1601516200 if (instr_is_comptime(target_value_ptr)) {
......@@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1601716202 if (!target_value_ptr)
1601816203 return ira->codegen->builtin_types.entry_invalid;
1601916204
16020 ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, target_val_ptr);
16205 ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, target_val_ptr, instruction->base.source_node);
16206 if (pointee_val == nullptr)
16207 return ira->codegen->builtin_types.entry_invalid;
16208
1602116209 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1602216210 out_val->data.x_ptr.special = ConstPtrSpecialRef;
1602316211 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
......@@ -16035,14 +16223,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1603516223 }
1603616224}
1603716225
16038static TypeTableEntry *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
16226static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
1603916227 IrInstruction *value = instruction->value->other;
1604016228 IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value);
1604116229 ir_link_new_instruction(new_instruction, &instruction->base);
1604216230 return new_instruction->value.type;
1604316231}
1604416232
16045static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
16233static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
1604616234 IrInstruction *name_value = import_instruction->name->other;
1604716235 Buf *import_target_str = ir_resolve_str(ira, name_value);
1604816236 if (!import_target_str)
......@@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1607416262 os_path_join(search_dir, import_target_path, &full_path);
1607516263
1607616264 Buf *import_code = buf_alloc();
16077 Buf *abs_full_path = buf_alloc();
16078 int err;
16079 if ((err = os_path_real(&full_path, abs_full_path))) {
16080 if (err == ErrorFileNotFound) {
16081 ir_add_error_node(ira, source_node,
16082 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
16083 return ira->codegen->builtin_types.entry_invalid;
16084 } else {
16085 ira->codegen->error_during_imports = true;
16086 ir_add_error_node(ira, source_node,
16087 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
16088 return ira->codegen->builtin_types.entry_invalid;
16089 }
16090 }
16265 Buf *resolved_path = buf_alloc();
1609116266
16092 auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path);
16267 Buf *resolve_paths[] = { &full_path, };
16268 *resolved_path = os_path_resolve(resolve_paths, 1);
16269
16270 auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);
1609316271 if (import_entry) {
1609416272 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);
1609516273 out_val->data.x_import = import_entry->value;
1609616274 return ira->codegen->builtin_types.entry_namespace;
1609716275 }
1609816276
16099 if ((err = os_fetch_file_path(abs_full_path, import_code, true))) {
16277 int err;
16278 if ((err = os_fetch_file_path(resolved_path, import_code, true))) {
1610016279 if (err == ErrorFileNotFound) {
1610116280 ir_add_error_node(ira, source_node,
1610216281 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
......@@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1610716286 return ira->codegen->builtin_types.entry_invalid;
1610816287 }
1610916288 }
16110 ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, abs_full_path, import_code);
16289 ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code);
1611116290
1611216291 scan_import(ira->codegen, target_import);
1611316292
......@@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1611716296
1611816297}
1611916298
16120static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
16299static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira,
1612116300 IrInstructionArrayLen *array_len_instruction)
1612216301{
1612316302 IrInstruction *array_value = array_len_instruction->array_value->other;
16124 TypeTableEntry *type_entry = array_value->value.type;
16303 ZigType *type_entry = array_value->value.type;
1612516304 if (type_is_invalid(type_entry)) {
1612616305 return ira->codegen->builtin_types.entry_invalid;
16127 } else if (type_entry->id == TypeTableEntryIdArray) {
16306 } else if (type_entry->id == ZigTypeIdArray) {
1612816307 return ir_analyze_const_usize(ira, &array_len_instruction->base,
1612916308 type_entry->data.array.len);
1613016309 } else if (is_slice(type_entry)) {
......@@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
1614816327 }
1614916328}
1615016329
16151static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
16330static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
1615216331 IrInstruction *value = ref_instruction->value->other;
1615316332 return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
1615416333}
1615516334
16156static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,
16157 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16335static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,
16336 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
1615816337{
1615916338 Error err;
16160 assert(container_type->id == TypeTableEntryIdUnion);
16339 assert(container_type->id == ZigTypeIdUnion);
1616116340
1616216341 if ((err = ensure_complete_type(ira->codegen, container_type)))
1616316342 return ira->codegen->builtin_types.entry_invalid;
......@@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
1621916398 return container_type;
1622016399}
1622116400
16222static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
16223 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16401static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
16402 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
1622416403{
1622516404 Error err;
16226 if (container_type->id == TypeTableEntryIdUnion) {
16405 if (container_type->id == ZigTypeIdUnion) {
1622716406 return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);
1622816407 }
16229 if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {
16408 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
1623016409 ir_add_error(ira, instruction,
1623116410 buf_sprintf("type '%s' does not support struct initialization syntax",
1623216411 buf_ptr(&container_type->name)));
......@@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
1633916518 return container_type;
1634016519}
1634116520
16342static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16521static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1634316522 IrInstructionContainerInitList *instruction)
1634416523{
1634516524 IrInstruction *container_type_value = instruction->container_type->other;
......@@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1634716526 return ira->codegen->builtin_types.entry_invalid;
1634816527
1634916528 size_t elem_count = instruction->item_count;
16350 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {
16351 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
16529 if (container_type_value->value.type->id == ZigTypeIdMetaType) {
16530 ZigType *container_type = ir_resolve_type(ira, container_type_value);
1635216531 if (type_is_invalid(container_type))
1635316532 return ira->codegen->builtin_types.entry_invalid;
1635416533
16355 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
16534 if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
1635616535 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
1635716536 0, nullptr);
16358 } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) {
16537 } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
1635916538 // array is same as slice init but we make a compile error if the length is wrong
16360 TypeTableEntry *child_type;
16361 if (container_type->id == TypeTableEntryIdArray) {
16539 ZigType *child_type;
16540 if (container_type->id == ZigTypeIdArray) {
1636216541 child_type = container_type->data.array.child_type;
1636316542 if (container_type->data.array.len != elem_count) {
16364 TypeTableEntry *literal_type = get_array_type(ira->codegen, child_type, elem_count);
16543 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);
1636516544
1636616545 ir_add_error(ira, &instruction->base,
1636716546 buf_sprintf("expected %s literal, found %s literal",
......@@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1636916548 return ira->codegen->builtin_types.entry_invalid;
1637016549 }
1637116550 } else {
16372 TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
16373 assert(pointer_type->id == TypeTableEntryIdPointer);
16551 ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
16552 assert(pointer_type->id == ZigTypeIdPointer);
1637416553 child_type = pointer_type->data.pointer.child_type;
1637516554 }
1637616555
16377 TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
16556 ZigType *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
1637816557
1637916558 ConstExprValue const_val = {};
1638016559 const_val.special = ConstValSpecialStatic;
......@@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1643716616 container_type_value, elem_count, new_items);
1643816617 ir_add_alloca(ira, new_instruction, fixed_size_array_type);
1643916618 return fixed_size_array_type;
16440 } else if (container_type->id == TypeTableEntryIdVoid) {
16619 } else if (container_type->id == ZigTypeIdVoid) {
1644116620 if (elem_count != 0) {
1644216621 ir_add_error_node(ira, instruction->base.source_node,
1644316622 buf_sprintf("void expression expects no arguments"));
......@@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1645716636 }
1645816637}
1645916638
16460static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
16639static ZigType *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
1646116640 IrInstruction *container_type_value = instruction->container_type->other;
16462 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
16641 ZigType *container_type = ir_resolve_type(ira, container_type_value);
1646316642 if (type_is_invalid(container_type))
1646416643 return ira->codegen->builtin_types.entry_invalid;
1646516644
......@@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i
1646716646 instruction->field_count, instruction->fields);
1646816647}
1646916648
16470static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
16649static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
1647116650 IrInstruction *target_type_value, bool is_max)
1647216651{
16473 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
16652 ZigType *target_type = ir_resolve_type(ira, target_type_value);
1647416653 if (type_is_invalid(target_type))
1647516654 return ira->codegen->builtin_types.entry_invalid;
1647616655 switch (target_type->id) {
16477 case TypeTableEntryIdInvalid:
16656 case ZigTypeIdInvalid:
1647816657 zig_unreachable();
16479 case TypeTableEntryIdInt:
16658 case ZigTypeIdInt:
1648016659 {
1648116660 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
1648216661 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
1648316662 return ira->codegen->builtin_types.entry_num_lit_int;
1648416663 }
16485 case TypeTableEntryIdBool:
16486 case TypeTableEntryIdVoid:
16664 case ZigTypeIdBool:
16665 case ZigTypeIdVoid:
1648716666 {
1648816667 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
1648916668 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
1649016669 return target_type;
1649116670 }
16492 case TypeTableEntryIdEnum:
16493 case TypeTableEntryIdFloat:
16494 case TypeTableEntryIdMetaType:
16495 case TypeTableEntryIdUnreachable:
16496 case TypeTableEntryIdPointer:
16497 case TypeTableEntryIdPromise:
16498 case TypeTableEntryIdArray:
16499 case TypeTableEntryIdStruct:
16500 case TypeTableEntryIdComptimeFloat:
16501 case TypeTableEntryIdComptimeInt:
16502 case TypeTableEntryIdUndefined:
16503 case TypeTableEntryIdNull:
16504 case TypeTableEntryIdOptional:
16505 case TypeTableEntryIdErrorUnion:
16506 case TypeTableEntryIdErrorSet:
16507 case TypeTableEntryIdUnion:
16508 case TypeTableEntryIdFn:
16509 case TypeTableEntryIdNamespace:
16510 case TypeTableEntryIdBlock:
16511 case TypeTableEntryIdBoundFn:
16512 case TypeTableEntryIdArgTuple:
16513 case TypeTableEntryIdOpaque:
16671 case ZigTypeIdEnum:
16672 case ZigTypeIdFloat:
16673 case ZigTypeIdMetaType:
16674 case ZigTypeIdUnreachable:
16675 case ZigTypeIdPointer:
16676 case ZigTypeIdPromise:
16677 case ZigTypeIdArray:
16678 case ZigTypeIdStruct:
16679 case ZigTypeIdComptimeFloat:
16680 case ZigTypeIdComptimeInt:
16681 case ZigTypeIdUndefined:
16682 case ZigTypeIdNull:
16683 case ZigTypeIdOptional:
16684 case ZigTypeIdErrorUnion:
16685 case ZigTypeIdErrorSet:
16686 case ZigTypeIdUnion:
16687 case ZigTypeIdFn:
16688 case ZigTypeIdNamespace:
16689 case ZigTypeIdBlock:
16690 case ZigTypeIdBoundFn:
16691 case ZigTypeIdArgTuple:
16692 case ZigTypeIdOpaque:
1651416693 {
1651516694 const char *err_format = is_max ?
1651616695 "no max value available for type '%s'" :
......@@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
1652316702 zig_unreachable();
1652416703}
1652516704
16526static TypeTableEntry *ir_analyze_instruction_min_value(IrAnalyze *ira,
16705static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira,
1652716706 IrInstructionMinValue *instruction)
1652816707{
1652916708 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false);
1653016709}
1653116710
16532static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira,
16711static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira,
1653316712 IrInstructionMaxValue *instruction)
1653416713{
1653516714 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true);
1653616715}
1653716716
16538static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
16717static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira,
1653916718 IrInstructionCompileErr *instruction)
1654016719{
1654116720 IrInstruction *msg_value = instruction->msg->other;
......@@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
1655916738 return ira->codegen->builtin_types.entry_invalid;
1656016739}
1656116740
16562static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
16741static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
1656316742 Buf buf = BUF_INIT;
1656416743 fprintf(stderr, "| ");
1656516744 for (size_t i = 0; i < instruction->msg_count; i += 1) {
......@@ -16579,7 +16758,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
1657916758 return ira->codegen->builtin_types.entry_void;
1658016759}
1658116760
16582static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
16761static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
1658316762 IrInstruction *value = instruction->value->other;
1658416763 if (type_is_invalid(value->value.type))
1658516764 return ira->codegen->builtin_types.entry_invalid;
......@@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
1658816767 if (type_is_invalid(casted_value->value.type))
1658916768 return ira->codegen->builtin_types.entry_invalid;
1659016769
16591 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
16770 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1659216771 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
16593 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
16772 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1659416773 if (casted_value->value.special == ConstValSpecialStatic) {
1659516774 ErrorTableEntry *err = casted_value->value.data.x_err_set;
1659616775 if (!err->cached_error_name_val) {
......@@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
1660716786 return str_type;
1660816787}
1660916788
16610static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
16789static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
1661116790 Error err;
1661216791 IrInstruction *target = instruction->target->other;
1661316792 if (type_is_invalid(target->value.type))
1661416793 return ira->codegen->builtin_types.entry_invalid;
1661516794
16616 assert(target->value.type->id == TypeTableEntryIdEnum);
16795 assert(target->value.type->id == ZigTypeIdEnum);
1661716796
1661816797 if (instr_is_comptime(target)) {
1661916798 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
......@@ -16628,7 +16807,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
1662816807 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
1662916808 instruction->base.source_node, target);
1663016809 ir_link_new_instruction(result, &instruction->base);
16631 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(
16810 ZigType *u8_ptr_type = get_pointer_to_type_extra(
1663216811 ira->codegen, ira->codegen->builtin_types.entry_u8,
1663316812 true, false, PtrLenUnknown,
1663416813 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
......@@ -16637,12 +16816,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
1663716816 return result->value.type;
1663816817}
1663916818
16640static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16819static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1664116820 IrInstructionFieldParentPtr *instruction)
1664216821{
1664316822 Error err;
1664416823 IrInstruction *type_value = instruction->type_value->other;
16645 TypeTableEntry *container_type = ir_resolve_type(ira, type_value);
16824 ZigType *container_type = ir_resolve_type(ira, type_value);
1664616825 if (type_is_invalid(container_type))
1664716826 return ira->codegen->builtin_types.entry_invalid;
1664816827
......@@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1665516834 if (type_is_invalid(field_ptr->value.type))
1665616835 return ira->codegen->builtin_types.entry_invalid;
1665716836
16658 if (container_type->id != TypeTableEntryIdStruct) {
16837 if (container_type->id != ZigTypeIdStruct) {
1665916838 ir_add_error(ira, type_value,
1666016839 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
1666116840 return ira->codegen->builtin_types.entry_invalid;
......@@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1667216851 return ira->codegen->builtin_types.entry_invalid;
1667316852 }
1667416853
16675 if (field_ptr->value.type->id != TypeTableEntryIdPointer) {
16854 if (field_ptr->value.type->id != ZigTypeIdPointer) {
1667616855 ir_add_error(ira, field_ptr,
1667716856 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));
1667816857 return ira->codegen->builtin_types.entry_invalid;
......@@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1668216861 uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry);
1668316862 uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);
1668416863
16685 TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
16864 ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
1668616865 field_ptr->value.type->data.pointer.is_const,
1668716866 field_ptr->value.type->data.pointer.is_volatile,
1668816867 PtrLenSingle,
......@@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1669116870 if (type_is_invalid(casted_field_ptr->value.type))
1669216871 return ira->codegen->builtin_types.entry_invalid;
1669316872
16694 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
16873 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
1669516874 casted_field_ptr->value.type->data.pointer.is_const,
1669616875 casted_field_ptr->value.type->data.pointer.is_volatile,
1669716876 PtrLenSingle,
......@@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1673016909 return result_type;
1673116910}
1673216911
16733static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
16912static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1673416913 IrInstructionOffsetOf *instruction)
1673516914{
1673616915 Error err;
1673716916 IrInstruction *type_value = instruction->type_value->other;
16738 TypeTableEntry *container_type = ir_resolve_type(ira, type_value);
16917 ZigType *container_type = ir_resolve_type(ira, type_value);
1673916918 if (type_is_invalid(container_type))
1674016919 return ira->codegen->builtin_types.entry_invalid;
1674116920
......@@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1674716926 if (!field_name)
1674816927 return ira->codegen->builtin_types.entry_invalid;
1674916928
16750 if (container_type->id != TypeTableEntryIdStruct) {
16929 if (container_type->id != ZigTypeIdStruct) {
1675116930 ir_add_error(ira, type_value,
1675216931 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
1675316932 return ira->codegen->builtin_types.entry_invalid;
......@@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1677316952 return ira->codegen->builtin_types.entry_num_lit_int;
1677416953}
1677516954
16776static void ensure_field_index(TypeTableEntry *type, const char *field_name, size_t index)
16955static void ensure_field_index(ZigType *type, const char *field_name, size_t index)
1677716956{
1677816957 Buf *field_name_buf;
1677916958
......@@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz
1678416963 (buf_deinit(field_name_buf), true));
1678516964}
1678616965
16787static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, TypeTableEntry *root) {
16966static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {
1678816967 Error err;
1678916968 static ConstExprValue *type_info_var = nullptr;
16790 static TypeTableEntry *type_info_type = nullptr;
16969 static ZigType *type_info_type = nullptr;
1679116970 if (type_info_var == nullptr) {
1679216971 type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
16793 assert(type_info_var->type->id == TypeTableEntryIdMetaType);
16972 assert(type_info_var->type->id == ZigTypeIdMetaType);
1679416973
1679516974 assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));
1679616975 type_info_type = type_info_var->data.x_type;
16797 assert(type_info_type->id == TypeTableEntryIdUnion);
16976 assert(type_info_type->id == ZigTypeIdUnion);
1679816977 }
1679916978
1680016979 if (type_name == nullptr && root == nullptr)
......@@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
1680216981 else if (type_name == nullptr)
1680316982 return root;
1680416983
16805 TypeTableEntry *root_type = (root == nullptr) ? type_info_type : root;
16984 ZigType *root_type = (root == nullptr) ? type_info_type : root;
1680616985
1680716986 ScopeDecls *type_info_scope = get_container_scope(root_type);
1680816987 assert(type_info_scope != nullptr);
......@@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
1681516994 TldVar *tld = (TldVar *)entry;
1681616995 assert(tld->base.id == TldIdVar);
1681716996
16818 VariableTableEntry *var = tld->var;
16997 ZigVar *var = tld->var;
1681916998
1682016999 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
1682117000 return ira->codegen->builtin_types.entry_invalid;
16822 assert(var->value->type->id == TypeTableEntryIdMetaType);
17001 assert(var->value->type->id == ZigTypeIdMetaType);
1682317002 return var->value->data.x_type;
1682417003}
1682517004
1682617005static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
1682717006 Error err;
16828 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
17007 ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
1682917008 if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
1683017009 return err;
1683117010
......@@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1683317012 ensure_field_index(type_info_definition_type, "is_pub", 1);
1683417013 ensure_field_index(type_info_definition_type, "data", 2);
1683517014
16836 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
17015 ZigType *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
1683717016 if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))
1683817017 return err;
1683917018
16840 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
17019 ZigType *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
1684117020 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))
1684217021 return err;
1684317022
16844 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
17023 ZigType *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
1684517024 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))
1684617025 return err;
1684717026
......@@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1686217041 // Skip comptime blocks and test functions.
1686317042 if (curr_entry->value->id != TldIdCompTime) {
1686417043 if (curr_entry->value->id == TldIdFn) {
16865 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
17044 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
1686617045 if (fn_entry->is_test)
1686717046 continue;
1686817047 }
......@@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1688817067 if (curr_entry->value->id == TldIdCompTime) {
1688917068 continue;
1689017069 } else if (curr_entry->value->id == TldIdFn) {
16891 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
17070 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
1689217071 if (fn_entry->is_test)
1689317072 continue;
1689417073 }
......@@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1691317092 switch (curr_entry->value->id) {
1691417093 case TldIdVar:
1691517094 {
16916 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
17095 ZigVar *var = ((TldVar *)curr_entry->value)->var;
1691717096 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
1691817097 return ErrorSemanticAnalyzeFail;
1691917098
16920 if (var->value->type->id == TypeTableEntryIdMetaType)
17099 if (var->value->type->id == ZigTypeIdMetaType)
1692117100 {
1692217101 // We have a variable of type 'type', so it's actually a type definition.
1692317102 // 0: Data.Type: type
......@@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1694417123 // 2: Data.Fn: Data.FnDef
1694517124 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2);
1694617125
16947 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
17126 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
1694817127 assert(!fn_entry->is_test);
1694917128
1695017129 AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
......@@ -16992,7 +17171,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1699217171 // lib_name: ?[]const u8
1699317172 ensure_field_index(fn_def_val->type, "lib_name", 6);
1699417173 fn_def_fields[6].special = ConstValSpecialStatic;
16995 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(
17174 ZigType *u8_ptr = get_pointer_to_type_extra(
1699617175 ira->codegen, ira->codegen->builtin_types.entry_u8,
1699717176 true, false, PtrLenUnknown,
1699817177 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
......@@ -17030,7 +17209,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1703017209
1703117210 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)
1703217211 {
17033 VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index);
17212 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
1703417213 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];
1703517214 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);
1703617215 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);
......@@ -17044,7 +17223,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1704417223 }
1704517224 case TldIdContainer:
1704617225 {
17047 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
17226 ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
1704817227 if ((err = ensure_complete_type(ira->codegen, type_entry)))
1704917228 return ErrorSemanticAnalyzeFail;
1705017229
......@@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1707117250 return ErrorNone;
1707217251}
1707317252
17074static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) {
17075 TypeTableEntry *attrs_type;
17253static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
17254 ZigType *attrs_type;
1707617255 uint32_t size_enum_index;
1707717256 if (is_slice(ptr_type_entry)) {
1707817257 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
1707917258 size_enum_index = 2;
17080 } else if (ptr_type_entry->id == TypeTableEntryIdPointer) {
17259 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
1708117260 attrs_type = ptr_type_entry;
1708217261 size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;
1708317262 } else {
1708417263 zig_unreachable();
1708517264 }
1708617265
17087 TypeTableEntry *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
17266 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
1708817267 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type));
1708917268
1709017269 ConstExprValue *result = create_const_vals(1);
......@@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
1709617275
1709717276 // size: Size
1709817277 ensure_field_index(result->type, "size", 0);
17099 TypeTableEntry *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
17278 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
1710017279 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type));
1710117280 fields[0].special = ConstValSpecialStatic;
1710217281 fields[0].type = type_info_pointer_size_type;
......@@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
1712717306};
1712817307
1712917308static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,
17130 TypeTableEntry *type_info_enum_field_type)
17309 ZigType *type_info_enum_field_type)
1713117310{
1713217311 enum_field_val->special = ConstValSpecialStatic;
1713317312 enum_field_val->type = type_info_enum_field_type;
......@@ -17144,7 +17323,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
1714417323 enum_field_val->data.x_struct.fields = inner_fields;
1714517324}
1714617325
17147static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, ConstExprValue **out) {
17326static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) {
1714817327 Error err;
1714917328 assert(type_entry != nullptr);
1715017329 assert(!type_is_invalid(type_entry));
......@@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1715917338 ConstExprValue *result = nullptr;
1716017339 switch (type_entry->id)
1716117340 {
17162 case TypeTableEntryIdInvalid:
17341 case ZigTypeIdInvalid:
1716317342 zig_unreachable();
17164 case TypeTableEntryIdMetaType:
17165 case TypeTableEntryIdVoid:
17166 case TypeTableEntryIdBool:
17167 case TypeTableEntryIdUnreachable:
17168 case TypeTableEntryIdComptimeFloat:
17169 case TypeTableEntryIdComptimeInt:
17170 case TypeTableEntryIdUndefined:
17171 case TypeTableEntryIdNull:
17172 case TypeTableEntryIdNamespace:
17173 case TypeTableEntryIdBlock:
17174 case TypeTableEntryIdArgTuple:
17175 case TypeTableEntryIdOpaque:
17343 case ZigTypeIdMetaType:
17344 case ZigTypeIdVoid:
17345 case ZigTypeIdBool:
17346 case ZigTypeIdUnreachable:
17347 case ZigTypeIdComptimeFloat:
17348 case ZigTypeIdComptimeInt:
17349 case ZigTypeIdUndefined:
17350 case ZigTypeIdNull:
17351 case ZigTypeIdNamespace:
17352 case ZigTypeIdBlock:
17353 case ZigTypeIdArgTuple:
17354 case ZigTypeIdOpaque:
1717617355 *out = nullptr;
1717717356 return ErrorNone;
1717817357 default:
......@@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1718617365
1718717366 // Fallthrough if we don't find one.
1718817367 }
17189 case TypeTableEntryIdInt:
17368 case ZigTypeIdInt:
1719017369 {
1719117370 result = create_const_vals(1);
1719217371 result->special = ConstValSpecialStatic;
......@@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1720817387
1720917388 break;
1721017389 }
17211 case TypeTableEntryIdFloat:
17390 case ZigTypeIdFloat:
1721217391 {
1721317392 result = create_const_vals(1);
1721417393 result->special = ConstValSpecialStatic;
......@@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1722517404
1722617405 break;
1722717406 }
17228 case TypeTableEntryIdPointer:
17407 case ZigTypeIdPointer:
1722917408 {
1723017409 result = create_ptr_like_type_info(ira, type_entry);
1723117410 break;
1723217411 }
17233 case TypeTableEntryIdArray:
17412 case ZigTypeIdArray:
1723417413 {
1723517414 result = create_const_vals(1);
1723617415 result->special = ConstValSpecialStatic;
......@@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1725217431
1725317432 break;
1725417433 }
17255 case TypeTableEntryIdOptional:
17434 case ZigTypeIdOptional:
1725617435 {
1725717436 result = create_const_vals(1);
1725817437 result->special = ConstValSpecialStatic;
......@@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1726917448
1727017449 break;
1727117450 }
17272 case TypeTableEntryIdPromise:
17451 case ZigTypeIdPromise:
1727317452 {
1727417453 result = create_const_vals(1);
1727517454 result->special = ConstValSpecialStatic;
......@@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1729517474
1729617475 break;
1729717476 }
17298 case TypeTableEntryIdEnum:
17477 case ZigTypeIdEnum:
1729917478 {
1730017479 result = create_const_vals(1);
1730117480 result->special = ConstValSpecialStatic;
......@@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1731717496 // fields: []TypeInfo.EnumField
1731817497 ensure_field_index(result->type, "fields", 2);
1731917498
17320 TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
17499 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
1732117500 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
1732217501
1732317502 ConstExprValue *enum_field_array = create_const_vals(1);
......@@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1734517524
1734617525 break;
1734717526 }
17348 case TypeTableEntryIdErrorSet:
17527 case ZigTypeIdErrorSet:
1734917528 {
1735017529 result = create_const_vals(1);
1735117530 result->special = ConstValSpecialStatic;
......@@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1735717536 // errors: []TypeInfo.Error
1735817537 ensure_field_index(result->type, "errors", 0);
1735917538
17360 TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
17539 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
1736117540 uint32_t error_count = type_entry->data.error_set.err_count;
1736217541 ConstExprValue *error_array = create_const_vals(1);
1736317542 error_array->special = ConstValSpecialStatic;
......@@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1739417573
1739517574 break;
1739617575 }
17397 case TypeTableEntryIdErrorUnion:
17576 case ZigTypeIdErrorUnion:
1739817577 {
1739917578 result = create_const_vals(1);
1740017579 result->special = ConstValSpecialStatic;
......@@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1741717596
1741817597 break;
1741917598 }
17420 case TypeTableEntryIdUnion:
17599 case ZigTypeIdUnion:
1742117600 {
1742217601 result = create_const_vals(1);
1742317602 result->special = ConstValSpecialStatic;
......@@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1745117630 // fields: []TypeInfo.UnionField
1745217631 ensure_field_index(result->type, "fields", 2);
1745317632
17454 TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);
17633 ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);
1745517634 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
1745617635
1745717636 ConstExprValue *union_field_array = create_const_vals(1);
......@@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1746317642
1746417643 init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false);
1746517644
17466 TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
17645 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
1746717646
1746817647 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
1746917648 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];
......@@ -17502,7 +17681,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1750217681
1750317682 break;
1750417683 }
17505 case TypeTableEntryIdStruct:
17684 case ZigTypeIdStruct:
1750617685 {
1750717686 if (type_entry->data.structure.is_slice) {
1750817687 result = create_ptr_like_type_info(ira, type_entry);
......@@ -17524,7 +17703,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1752417703 // fields: []TypeInfo.StructField
1752517704 ensure_field_index(result->type, "fields", 1);
1752617705
17527 TypeTableEntry *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);
17706 ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);
1752817707 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
1752917708
1753017709 ConstExprValue *struct_field_array = create_const_vals(1);
......@@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1757617755
1757717756 break;
1757817757 }
17579 case TypeTableEntryIdFn:
17758 case ZigTypeIdFn:
1758017759 {
1758117760 result = create_const_vals(1);
1758217761 result->special = ConstValSpecialStatic;
......@@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1762917808 fields[4].data.x_optional = async_alloc_type;
1763017809 }
1763117810 // args: []TypeInfo.FnArg
17632 TypeTableEntry *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
17811 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
1763317812 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
1763417813 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
1763517814
......@@ -17681,10 +17860,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1768117860
1768217861 break;
1768317862 }
17684 case TypeTableEntryIdBoundFn:
17863 case ZigTypeIdBoundFn:
1768517864 {
17686 TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type;
17687 assert(fn_type->id == TypeTableEntryIdFn);
17865 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
17866 assert(fn_type->id == ZigTypeIdFn);
1768817867 if ((err = ir_make_type_info_value(ira, fn_type, &result)))
1768917868 return err;
1769017869
......@@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1769817877 return ErrorNone;
1769917878}
1770017879
17701static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
17880static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira,
1770217881 IrInstructionTypeInfo *instruction)
1770317882{
1770417883 Error err;
1770517884 IrInstruction *type_value = instruction->type_value->other;
17706 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
17885 ZigType *type_entry = ir_resolve_type(ira, type_value);
1770717886 if (type_is_invalid(type_entry))
1770817887 return ira->codegen->builtin_types.entry_invalid;
1770917888
17710 TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
17889 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1771117890
1771217891 ConstExprValue *payload;
1771317892 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))
......@@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1771917898 out_val->data.x_union.payload = payload;
1772017899
1772117900 if (payload != nullptr) {
17722 assert(payload->type->id == TypeTableEntryIdStruct);
17901 assert(payload->type->id == ZigTypeIdStruct);
1772317902 payload->data.x_struct.parent.id = ConstParentIdUnion;
1772417903 payload->data.x_struct.parent.data.p_union.union_val = out_val;
1772517904 }
......@@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1772717906 return result_type;
1772817907}
1772917908
17730static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,
17909static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira,
1773117910 IrInstructionTypeId *instruction)
1773217911{
1773317912 IrInstruction *type_value = instruction->type_value->other;
17734 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
17913 ZigType *type_entry = ir_resolve_type(ira, type_value);
1773517914 if (type_is_invalid(type_entry))
1773617915 return ira->codegen->builtin_types.entry_invalid;
1773717916
1773817917 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");
17739 assert(var_value->type->id == TypeTableEntryIdMetaType);
17740 TypeTableEntry *result_type = var_value->data.x_type;
17918 assert(var_value->type->id == ZigTypeIdMetaType);
17919 ZigType *result_type = var_value->data.x_type;
1774117920
1774217921 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1774317922 bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry));
1774417923 return result_type;
1774517924}
1774617925
17747static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
17926static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
1774817927 IrInstructionSetEvalBranchQuota *instruction)
1774917928{
1775017929 if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) {
......@@ -17765,9 +17944,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i
1776517944 return ira->codegen->builtin_types.entry_void;
1776617945}
1776717946
17768static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
17947static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
1776917948 IrInstruction *type_value = instruction->type_value->other;
17770 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
17949 ZigType *type_entry = ir_resolve_type(ira, type_value);
1777117950 if (type_is_invalid(type_entry))
1777217951 return ira->codegen->builtin_types.entry_invalid;
1777317952
......@@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru
1777917958 return out_val->type;
1778017959}
1778117960
17782static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
17961static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
1778317962 AstNode *node = instruction->base.source_node;
1778417963 assert(node->type == NodeTypeFnCallExpr);
1778517964 AstNode *block_node = node->data.fn_call_expr.params.at(0);
......@@ -17787,7 +17966,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1778717966 ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope);
1778817967
1778917968 // Execute the C import block like an inline function
17790 TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void;
17969 ZigType *void_type = ira->codegen->builtin_types.entry_void;
1779117970 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
1779217971 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
1779317972 &cimport_scope->buf, block_node, nullptr, nullptr);
......@@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1783818017 return ira->codegen->builtin_types.entry_namespace;
1783918018}
1784018019
17841static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
18020static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
1784218021 IrInstruction *name_value = instruction->name->other;
1784318022 if (type_is_invalid(name_value->value.type))
1784418023 return ira->codegen->builtin_types.entry_invalid;
......@@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
1785718036 return ira->codegen->builtin_types.entry_void;
1785818037}
1785918038
17860static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
18039static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
1786118040 IrInstruction *name = instruction->name->other;
1786218041 if (type_is_invalid(name->value.type))
1786318042 return ira->codegen->builtin_types.entry_invalid;
......@@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
1788418063 return ira->codegen->builtin_types.entry_void;
1788518064}
1788618065
17887static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
18066static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
1788818067 IrInstruction *name = instruction->name->other;
1788918068 if (type_is_invalid(name->value.type))
1789018069 return ira->codegen->builtin_types.entry_invalid;
......@@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
1790318082 return ira->codegen->builtin_types.entry_void;
1790418083}
1790518084
17906static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
18085static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
1790718086 IrInstruction *name = instruction->name->other;
1790818087 if (type_is_invalid(name->value.type))
1790918088 return ira->codegen->builtin_types.entry_invalid;
......@@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
1791718096 Buf source_dir_path = BUF_INIT;
1791818097 os_path_dirname(import->path, &source_dir_path);
1791918098
17920 Buf file_path = BUF_INIT;
17921 os_path_resolve(&source_dir_path, rel_file_path, &file_path);
18099 Buf *resolve_paths[] = {
18100 &source_dir_path,
18101 rel_file_path,
18102 };
18103 Buf file_path = os_path_resolve(resolve_paths, 2);
1792218104
1792318105 // load from file system into const expr
1792418106 Buf *file_contents = buf_alloc();
......@@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
1794218124 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents));
1794318125}
1794418126
17945static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
17946 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);
18127static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
18128 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);
1794718129 if (type_is_invalid(operand_type))
1794818130 return ira->codegen->builtin_types.entry_invalid;
1794918131
......@@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1795218134 return ira->codegen->builtin_types.entry_invalid;
1795318135
1795418136 // TODO let this be volatile
17955 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
18137 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
1795618138 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
1795718139 if (type_is_invalid(casted_ptr->value.type))
1795818140 return ira->codegen->builtin_types.entry_invalid;
......@@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1802318205 return result->value.type;
1802418206}
1802518207
18026static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
18208static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
1802718209 IrInstruction *order_value = instruction->order_value->other;
1802818210 if (type_is_invalid(order_value->value.type))
1802918211 return ira->codegen->builtin_types.entry_invalid;
......@@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
1803618218 return ira->codegen->builtin_types.entry_void;
1803718219}
1803818220
18039static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
18221static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
1804018222 IrInstruction *dest_type_value = instruction->dest_type->other;
18041 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
18223 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
1804218224 if (type_is_invalid(dest_type))
1804318225 return ira->codegen->builtin_types.entry_invalid;
1804418226
18045 if (dest_type->id != TypeTableEntryIdInt &&
18046 dest_type->id != TypeTableEntryIdComptimeInt)
18227 if (dest_type->id != ZigTypeIdInt &&
18228 dest_type->id != ZigTypeIdComptimeInt)
1804718229 {
1804818230 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
1804918231 return ira->codegen->builtin_types.entry_invalid;
1805018232 }
1805118233
1805218234 IrInstruction *target = instruction->target->other;
18053 TypeTableEntry *src_type = target->value.type;
18235 ZigType *src_type = target->value.type;
1805418236 if (type_is_invalid(src_type))
1805518237 return ira->codegen->builtin_types.entry_invalid;
1805618238
18057 if (src_type->id != TypeTableEntryIdInt &&
18058 src_type->id != TypeTableEntryIdComptimeInt)
18239 if (src_type->id != ZigTypeIdInt &&
18240 src_type->id != ZigTypeIdComptimeInt)
1805918241 {
1806018242 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
1806118243 return ira->codegen->builtin_types.entry_invalid;
......@@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
1808418266 return dest_type;
1808518267}
1808618268
18087static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
18088 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18269static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
18270 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
1808918271 if (type_is_invalid(dest_type))
1809018272 return ira->codegen->builtin_types.entry_invalid;
1809118273
18092 if (dest_type->id != TypeTableEntryIdInt) {
18274 if (dest_type->id != ZigTypeIdInt) {
1809318275 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
1809418276 return ira->codegen->builtin_types.entry_invalid;
1809518277 }
......@@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
1809818280 if (type_is_invalid(target->value.type))
1809918281 return ira->codegen->builtin_types.entry_invalid;
1810018282
18101 if (target->value.type->id == TypeTableEntryIdComptimeInt) {
18283 if (target->value.type->id == ZigTypeIdComptimeInt) {
1810218284 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
1810318285 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,
1810418286 CastOpNumLitToConcrete, false);
......@@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
1811118293 }
1811218294 }
1811318295
18114 if (target->value.type->id != TypeTableEntryIdInt) {
18296 if (target->value.type->id != ZigTypeIdInt) {
1811518297 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
1811618298 buf_ptr(&target->value.type->name)));
1811718299 return ira->codegen->builtin_types.entry_invalid;
......@@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
1812518307 return dest_type;
1812618308}
1812718309
18128static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
18129 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18310static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
18311 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
1813018312 if (type_is_invalid(dest_type))
1813118313 return ira->codegen->builtin_types.entry_invalid;
1813218314
18133 if (dest_type->id != TypeTableEntryIdFloat) {
18315 if (dest_type->id != ZigTypeIdFloat) {
1813418316 ir_add_error(ira, instruction->dest_type,
1813518317 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
1813618318 return ira->codegen->builtin_types.entry_invalid;
......@@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
1814018322 if (type_is_invalid(target->value.type))
1814118323 return ira->codegen->builtin_types.entry_invalid;
1814218324
18143 if (target->value.type->id == TypeTableEntryIdComptimeInt ||
18144 target->value.type->id == TypeTableEntryIdComptimeFloat)
18325 if (target->value.type->id == ZigTypeIdComptimeInt ||
18326 target->value.type->id == ZigTypeIdComptimeFloat)
1814518327 {
1814618328 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
1814718329 CastOp op;
18148 if (target->value.type->id == TypeTableEntryIdComptimeInt) {
18330 if (target->value.type->id == ZigTypeIdComptimeInt) {
1814918331 op = CastOpIntToFloat;
1815018332 } else {
1815118333 op = CastOpNumLitToConcrete;
......@@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
1816018342 }
1816118343 }
1816218344
18163 if (target->value.type->id != TypeTableEntryIdFloat) {
18345 if (target->value.type->id != ZigTypeIdFloat) {
1816418346 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
1816518347 buf_ptr(&target->value.type->name)));
1816618348 return ira->codegen->builtin_types.entry_invalid;
......@@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
1817318355 return dest_type;
1817418356}
1817518357
18176static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
18177 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18358static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
18359 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
1817818360 if (type_is_invalid(dest_type))
1817918361 return ira->codegen->builtin_types.entry_invalid;
1818018362
18181 if (dest_type->id != TypeTableEntryIdErrorSet) {
18363 if (dest_type->id != ZigTypeIdErrorSet) {
1818218364 ir_add_error(ira, instruction->dest_type,
1818318365 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
1818418366 return ira->codegen->builtin_types.entry_invalid;
......@@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
1818818370 if (type_is_invalid(target->value.type))
1818918371 return ira->codegen->builtin_types.entry_invalid;
1819018372
18191 if (target->value.type->id != TypeTableEntryIdErrorSet) {
18373 if (target->value.type->id != ZigTypeIdErrorSet) {
1819218374 ir_add_error(ira, instruction->target,
1819318375 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));
1819418376 return ira->codegen->builtin_types.entry_invalid;
......@@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
1820118383 return dest_type;
1820218384}
1820318385
18204static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
18205 TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);
18386static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
18387 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);
1820618388 if (type_is_invalid(dest_child_type))
1820718389 return ira->codegen->builtin_types.entry_invalid;
1820818390
......@@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
1821318395 bool src_ptr_const;
1821418396 bool src_ptr_volatile;
1821518397 uint32_t src_ptr_align;
18216 if (target->value.type->id == TypeTableEntryIdPointer) {
18398 if (target->value.type->id == ZigTypeIdPointer) {
1821718399 src_ptr_const = target->value.type->data.pointer.is_const;
1821818400 src_ptr_volatile = target->value.type->data.pointer.is_volatile;
1821918401 src_ptr_align = target->value.type->data.pointer.alignment;
1822018402 } else if (is_slice(target->value.type)) {
18221 TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
18403 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
1822218404 src_ptr_const = src_ptr_type->data.pointer.is_const;
1822318405 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
1822418406 src_ptr_align = src_ptr_type->data.pointer.alignment;
......@@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
1822818410 src_ptr_align = get_abi_alignment(ira->codegen, target->value.type);
1822918411 }
1823018412
18231 TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
18413 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
1823218414 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
1823318415 src_ptr_align, 0, 0);
18234 TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
18416 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
1823518417
18236 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
18418 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1823718419 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
1823818420 src_ptr_align, 0, 0);
18239 TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
18421 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
1824018422
1824118423 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
1824218424 if (type_is_invalid(casted_value->value.type))
......@@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
1828118463 return dest_slice_type;
1828218464}
1828318465
18284static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
18466static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
1828518467 IrInstruction *target = instruction->target->other;
1828618468 if (type_is_invalid(target->value.type))
1828718469 return ira->codegen->builtin_types.entry_invalid;
......@@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc
1829218474 return ira->codegen->builtin_types.entry_invalid;
1829318475 }
1829418476
18295 TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
18477 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
1829618478
18297 TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
18479 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1829818480 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
1829918481 src_ptr_type->data.pointer.alignment, 0, 0);
18300 TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
18482 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
1830118483
1830218484 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true);
1830318485 ir_link_new_instruction(result, &instruction->base);
1830418486 return dest_slice_type;
1830518487}
1830618488
18307static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
18308 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18489static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
18490 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
1830918491 if (type_is_invalid(dest_type))
1831018492 return ira->codegen->builtin_types.entry_invalid;
1831118493
......@@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
1831318495 if (type_is_invalid(target->value.type))
1831418496 return ira->codegen->builtin_types.entry_invalid;
1831518497
18316 if (target->value.type->id != TypeTableEntryIdInt && target->value.type->id != TypeTableEntryIdComptimeInt) {
18498 if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) {
1831718499 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
1831818500 buf_ptr(&target->value.type->name)));
1831918501 return ira->codegen->builtin_types.entry_invalid;
......@@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
1832418506 return dest_type;
1832518507}
1832618508
18327static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
18328 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18509static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
18510 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
1832918511 if (type_is_invalid(dest_type))
1833018512 return ira->codegen->builtin_types.entry_invalid;
1833118513
......@@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns
1833318515 if (type_is_invalid(target->value.type))
1833418516 return ira->codegen->builtin_types.entry_invalid;
1833518517
18518 if (target->value.type->id == ZigTypeIdComptimeInt) {
18519 IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type);
18520 if (type_is_invalid(casted_value->value.type))
18521 return ira->codegen->builtin_types.entry_invalid;
18522 ir_link_new_instruction(casted_value, &instruction->base);
18523 return casted_value->value.type;
18524 }
18525
18526 if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {
18527 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
18528 buf_ptr(&target->value.type->name)));
18529 return ira->codegen->builtin_types.entry_invalid;
18530 }
18531
1833618532 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
1833718533 ir_link_new_instruction(result, &instruction->base);
1833818534 return dest_type;
1833918535}
1834018536
18341static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
18537static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
1834218538 IrInstruction *target = instruction->target->other;
1834318539 if (type_is_invalid(target->value.type))
1834418540 return ira->codegen->builtin_types.entry_invalid;
1834518541
1834618542 IrInstruction *casted_target;
18347 if (target->value.type->id == TypeTableEntryIdErrorSet) {
18543 if (target->value.type->id == ZigTypeIdErrorSet) {
1834818544 casted_target = target;
1834918545 } else {
1835018546 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
......@@ -18357,7 +18553,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr
1835718553 return result->value.type;
1835818554}
1835918555
18360static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
18556static ZigType *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
1836118557 IrInstruction *target = instruction->target->other;
1836218558 if (type_is_invalid(target->value.type))
1836318559 return ira->codegen->builtin_types.entry_invalid;
......@@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr
1837118567 return result->value.type;
1837218568}
1837318569
18374static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
18570static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
1837518571 IrInstruction *target = instruction->target->other;
1837618572 if (type_is_invalid(target->value.type))
1837718573 return ira->codegen->builtin_types.entry_invalid;
1837818574
18379 if (target->value.type->id != TypeTableEntryIdBool) {
18575 if (target->value.type->id != ZigTypeIdBool) {
1838018576 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
1838118577 buf_ptr(&target->value.type->name)));
1838218578 return ira->codegen->builtin_types.entry_invalid;
......@@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst
1839218588 return ira->codegen->builtin_types.entry_num_lit_int;
1839318589 }
1839418590
18395 TypeTableEntry *u1_type = get_int_type(ira->codegen, false, 1);
18591 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
1839618592 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);
1839718593 ir_link_new_instruction(result, &instruction->base);
1839818594 return u1_type;
1839918595}
1840018596
18401static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
18597static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
1840218598 IrInstruction *is_signed_value = instruction->is_signed->other;
1840318599 bool is_signed;
1840418600 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
......@@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
1841418610 return ira->codegen->builtin_types.entry_type;
1841518611}
1841618612
18417static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
18613static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
1841818614 IrInstruction *value = instruction->value->other;
1841918615 if (type_is_invalid(value->value.type))
1842018616 return ira->codegen->builtin_types.entry_invalid;
1842118617
18422 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
18618 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1842318619
1842418620 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
1842518621 if (type_is_invalid(casted_value->value.type))
......@@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
1843918635 return bool_type;
1844018636}
1844118637
18442static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
18638static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
1844318639 IrInstruction *dest_ptr = instruction->dest_ptr->other;
1844418640 if (type_is_invalid(dest_ptr->value.type))
1844518641 return ira->codegen->builtin_types.entry_invalid;
......@@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1845218648 if (type_is_invalid(count_value->value.type))
1845318649 return ira->codegen->builtin_types.entry_invalid;
1845418650
18455 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
18456 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
18651 ZigType *dest_uncasted_type = dest_ptr->value.type;
18652 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
1845718653 dest_uncasted_type->data.pointer.is_volatile;
1845818654
18459 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
18460 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
18461 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
18655 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18656 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18657 uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
1846218658 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
18463 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
18659 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
1846418660 PtrLenUnknown, dest_align, 0, 0);
1846518661
1846618662 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
......@@ -18531,7 +18727,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1853118727 return ira->codegen->builtin_types.entry_void;
1853218728}
1853318729
18534static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
18730static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
1853518731 IrInstruction *dest_ptr = instruction->dest_ptr->other;
1853618732 if (type_is_invalid(dest_ptr->value.type))
1853718733 return ira->codegen->builtin_types.entry_invalid;
......@@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1854418740 if (type_is_invalid(count_value->value.type))
1854518741 return ira->codegen->builtin_types.entry_invalid;
1854618742
18547 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
18548 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
18549 TypeTableEntry *src_uncasted_type = src_ptr->value.type;
18550 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
18743 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18744 ZigType *dest_uncasted_type = dest_ptr->value.type;
18745 ZigType *src_uncasted_type = src_ptr->value.type;
18746 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
1855118747 dest_uncasted_type->data.pointer.is_volatile;
18552 bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) &&
18748 bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&
1855318749 src_uncasted_type->data.pointer.is_volatile;
18554 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
18750 uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
1855518751 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
18556 uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ?
18752 uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ?
1855718753 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
1855818754
18559 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
18560 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
18755 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18756 ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
1856118757 PtrLenUnknown, dest_align, 0, 0);
18562 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
18758 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
1856318759 PtrLenUnknown, src_align, 0, 0);
1856418760
1856518761 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
......@@ -18666,20 +18862,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1866618862 return ira->codegen->builtin_types.entry_void;
1866718863}
1866818864
18669static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
18865static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
1867018866 IrInstruction *ptr_ptr = instruction->ptr->other;
1867118867 if (type_is_invalid(ptr_ptr->value.type))
1867218868 return ira->codegen->builtin_types.entry_invalid;
1867318869
18674 TypeTableEntry *ptr_type = ptr_ptr->value.type;
18675 assert(ptr_type->id == TypeTableEntryIdPointer);
18676 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
18870 ZigType *ptr_type = ptr_ptr->value.type;
18871 assert(ptr_type->id == ZigTypeIdPointer);
18872 ZigType *array_type = ptr_type->data.pointer.child_type;
1867718873
1867818874 IrInstruction *start = instruction->start->other;
1867918875 if (type_is_invalid(start->value.type))
1868018876 return ira->codegen->builtin_types.entry_invalid;
1868118877
18682 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
18878 ZigType *usize = ira->codegen->builtin_types.entry_usize;
1868318879 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
1868418880 if (type_is_invalid(casted_start->value.type))
1868518881 return ira->codegen->builtin_types.entry_invalid;
......@@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1869618892 end = nullptr;
1869718893 }
1869818894
18699 TypeTableEntry *return_type;
18895 ZigType *return_type;
1870018896
18701 if (array_type->id == TypeTableEntryIdArray) {
18897 if (array_type->id == ZigTypeIdArray) {
1870218898 uint32_t byte_alignment = ptr_type->data.pointer.alignment;
1870318899 if (array_type->data.array.len == 0 && byte_alignment == 0) {
1870418900 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
1870518901 }
1870618902 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
1870718903 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
18708 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
18904 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
1870918905 ptr_type->data.pointer.is_const || is_comptime_const,
1871018906 ptr_type->data.pointer.is_volatile,
1871118907 PtrLenUnknown,
1871218908 byte_alignment, 0, 0);
1871318909 return_type = get_slice_type(ira->codegen, slice_ptr_type);
18714 } else if (array_type->id == TypeTableEntryIdPointer) {
18910 } else if (array_type->id == ZigTypeIdPointer) {
1871518911 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
18716 TypeTableEntry *main_type = array_type->data.pointer.child_type;
18717 if (main_type->id == TypeTableEntryIdArray) {
18718 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
18912 ZigType *main_type = array_type->data.pointer.child_type;
18913 if (main_type->id == ZigTypeIdArray) {
18914 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
1871918915 main_type->data.pointer.child_type,
1872018916 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
1872118917 PtrLenUnknown,
......@@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1872618922 return ira->codegen->builtin_types.entry_invalid;
1872718923 }
1872818924 } else {
18729 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
18925 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
1873018926 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
1873118927 PtrLenUnknown,
1873218928 array_type->data.pointer.alignment, 0, 0);
......@@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1873718933 }
1873818934 }
1873918935 } else if (is_slice(array_type)) {
18740 TypeTableEntry *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
18936 ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
1874118937 return_type = get_slice_type(ira->codegen, ptr_type);
1874218938 } else {
1874318939 ir_add_error(ira, &instruction->base,
......@@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1875418950 size_t abs_offset;
1875518951 size_t rel_end;
1875618952 bool ptr_is_undef = false;
18757 if (array_type->id == TypeTableEntryIdArray ||
18758 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
18953 if (array_type->id == ZigTypeIdArray ||
18954 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
1875918955 {
18760 if (array_type->id == TypeTableEntryIdPointer) {
18761 TypeTableEntry *child_array_type = array_type->data.pointer.child_type;
18762 assert(child_array_type->id == TypeTableEntryIdArray);
18763 parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18764 array_val = const_ptr_pointee(ira->codegen, parent_ptr);
18956 if (array_type->id == ZigTypeIdPointer) {
18957 ZigType *child_array_type = array_type->data.pointer.child_type;
18958 assert(child_array_type->id == ZigTypeIdArray);
18959 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18960 if (parent_ptr == nullptr)
18961 return ira->codegen->builtin_types.entry_invalid;
18962
18963 array_val = ir_const_ptr_pointee(ira, parent_ptr, instruction->base.source_node);
18964 if (array_val == nullptr)
18965 return ira->codegen->builtin_types.entry_invalid;
18966
1876518967 rel_end = child_array_type->data.array.len;
1876618968 abs_offset = 0;
1876718969 } else {
18768 array_val = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18970 array_val = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18971 if (array_val == nullptr)
18972 return ira->codegen->builtin_types.entry_invalid;
1876918973 rel_end = array_type->data.array.len;
1877018974 parent_ptr = nullptr;
1877118975 abs_offset = 0;
1877218976 }
18773 } else if (array_type->id == TypeTableEntryIdPointer) {
18977 } else if (array_type->id == ZigTypeIdPointer) {
1877418978 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
18775 parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18979 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18980 if (parent_ptr == nullptr)
18981 return ira->codegen->builtin_types.entry_invalid;
18982
1877618983 if (parent_ptr->special == ConstValSpecialUndef) {
1877718984 array_val = nullptr;
1877818985 abs_offset = 0;
......@@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1880319010 zig_panic("TODO slice of ptr cast from function");
1880419011 }
1880519012 } else if (is_slice(array_type)) {
18806 ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
19013 ConstExprValue *slice_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
19014 if (slice_ptr == nullptr)
19015 return ira->codegen->builtin_types.entry_invalid;
19016
1880719017 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
1880819018 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];
1880919019
......@@ -18871,11 +19081,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1887119081 size_t index = abs_offset + start_scalar;
1887219082 bool is_const = slice_is_const(return_type);
1887319083 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);
18874 if (array_type->id == TypeTableEntryIdArray) {
19084 if (array_type->id == ZigTypeIdArray) {
1887519085 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
1887619086 } else if (is_slice(array_type)) {
1887719087 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
18878 } else if (array_type->id == TypeTableEntryIdPointer) {
19088 } else if (array_type->id == ZigTypeIdPointer) {
1887919089 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
1888019090 }
1888119091 } else if (ptr_is_undef) {
......@@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1891719127 return return_type;
1891819128}
1891919129
18920static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
19130static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
1892119131 Error err;
1892219132 IrInstruction *container = instruction->container->other;
1892319133 if (type_is_invalid(container->value.type))
1892419134 return ira->codegen->builtin_types.entry_invalid;
18925 TypeTableEntry *container_type = ir_resolve_type(ira, container);
19135 ZigType *container_type = ir_resolve_type(ira, container);
1892619136
1892719137 if ((err = ensure_complete_type(ira->codegen, container_type)))
1892819138 return ira->codegen->builtin_types.entry_invalid;
......@@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1893019140 uint64_t result;
1893119141 if (type_is_invalid(container_type)) {
1893219142 return ira->codegen->builtin_types.entry_invalid;
18933 } else if (container_type->id == TypeTableEntryIdEnum) {
19143 } else if (container_type->id == ZigTypeIdEnum) {
1893419144 result = container_type->data.enumeration.src_field_count;
18935 } else if (container_type->id == TypeTableEntryIdStruct) {
19145 } else if (container_type->id == ZigTypeIdStruct) {
1893619146 result = container_type->data.structure.src_field_count;
18937 } else if (container_type->id == TypeTableEntryIdUnion) {
19147 } else if (container_type->id == ZigTypeIdUnion) {
1893819148 result = container_type->data.unionation.src_field_count;
18939 } else if (container_type->id == TypeTableEntryIdErrorSet) {
19149 } else if (container_type->id == ZigTypeIdErrorSet) {
1894019150 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
1894119151 return ira->codegen->builtin_types.entry_invalid;
1894219152 }
......@@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1895519165 return ira->codegen->builtin_types.entry_num_lit_int;
1895619166}
1895719167
18958static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
19168static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
1895919169 Error err;
1896019170 IrInstruction *container_type_value = instruction->container_type->other;
18961 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
19171 ZigType *container_type = ir_resolve_type(ira, container_type_value);
1896219172 if (type_is_invalid(container_type))
1896319173 return ira->codegen->builtin_types.entry_invalid;
1896419174
......@@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
1897119181 if (!ir_resolve_usize(ira, index_value, &member_index))
1897219182 return ira->codegen->builtin_types.entry_invalid;
1897319183
18974 if (container_type->id == TypeTableEntryIdStruct) {
19184 if (container_type->id == ZigTypeIdStruct) {
1897519185 if (member_index >= container_type->data.structure.src_field_count) {
1897619186 ir_add_error(ira, index_value,
1897719187 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
......@@ -18983,7 +19193,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
1898319193 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1898419194 out_val->data.x_type = field->type_entry;
1898519195 return ira->codegen->builtin_types.entry_type;
18986 } else if (container_type->id == TypeTableEntryIdUnion) {
19196 } else if (container_type->id == ZigTypeIdUnion) {
1898719197 if (member_index >= container_type->data.unionation.src_field_count) {
1898819198 ir_add_error(ira, index_value,
1898919199 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
......@@ -19002,10 +19212,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
1900219212 }
1900319213}
1900419214
19005static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
19215static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
1900619216 Error err;
1900719217 IrInstruction *container_type_value = instruction->container_type->other;
19008 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
19218 ZigType *container_type = ir_resolve_type(ira, container_type_value);
1900919219 if (type_is_invalid(container_type))
1901019220 return ira->codegen->builtin_types.entry_invalid;
1901119221
......@@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
1901719227 if (!ir_resolve_usize(ira, index_value, &member_index))
1901819228 return ira->codegen->builtin_types.entry_invalid;
1901919229
19020 if (container_type->id == TypeTableEntryIdStruct) {
19230 if (container_type->id == ZigTypeIdStruct) {
1902119231 if (member_index >= container_type->data.structure.src_field_count) {
1902219232 ir_add_error(ira, index_value,
1902319233 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
......@@ -19029,7 +19239,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
1902919239 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1903019240 init_const_str_lit(ira->codegen, out_val, field->name);
1903119241 return out_val->type;
19032 } else if (container_type->id == TypeTableEntryIdEnum) {
19242 } else if (container_type->id == ZigTypeIdEnum) {
1903319243 if (member_index >= container_type->data.enumeration.src_field_count) {
1903419244 ir_add_error(ira, index_value,
1903519245 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
......@@ -19041,7 +19251,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
1904119251 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1904219252 init_const_str_lit(ira->codegen, out_val, field->name);
1904319253 return out_val->type;
19044 } else if (container_type->id == TypeTableEntryIdUnion) {
19254 } else if (container_type->id == ZigTypeIdUnion) {
1904519255 if (member_index >= container_type->data.unionation.src_field_count) {
1904619256 ir_add_error(ira, index_value,
1904719257 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
......@@ -19060,76 +19270,76 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
1906019270 }
1906119271}
1906219272
19063static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
19273static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
1906419274 ir_build_breakpoint_from(&ira->new_irb, &instruction->base);
1906519275 return ira->codegen->builtin_types.entry_void;
1906619276}
1906719277
19068static TypeTableEntry *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
19278static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
1906919279 ir_build_return_address_from(&ira->new_irb, &instruction->base);
1907019280
19071 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
19072 TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
19281 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
19282 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
1907319283 return u8_ptr_const;
1907419284}
1907519285
19076static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
19286static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
1907719287 ir_build_frame_address_from(&ira->new_irb, &instruction->base);
1907819288
19079 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
19080 TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
19289 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
19290 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
1908119291 return u8_ptr_const;
1908219292}
1908319293
19084static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
19294static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
1908519295 ir_build_handle_from(&ira->new_irb, &instruction->base);
1908619296
19087 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
19297 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
1908819298 assert(fn_entry != nullptr);
1908919299 return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
1909019300}
1909119301
19092static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
19302static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
1909319303 Error err;
1909419304 IrInstruction *type_value = instruction->type_value->other;
1909519305 if (type_is_invalid(type_value->value.type))
1909619306 return ira->codegen->builtin_types.entry_invalid;
19097 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
19307 ZigType *type_entry = ir_resolve_type(ira, type_value);
1909819308
1909919309 if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry)))
1910019310 return ira->codegen->builtin_types.entry_invalid;
1910119311
1910219312 switch (type_entry->id) {
19103 case TypeTableEntryIdInvalid:
19313 case ZigTypeIdInvalid:
1910419314 zig_unreachable();
19105 case TypeTableEntryIdMetaType:
19106 case TypeTableEntryIdUnreachable:
19107 case TypeTableEntryIdComptimeFloat:
19108 case TypeTableEntryIdComptimeInt:
19109 case TypeTableEntryIdUndefined:
19110 case TypeTableEntryIdNull:
19111 case TypeTableEntryIdNamespace:
19112 case TypeTableEntryIdBlock:
19113 case TypeTableEntryIdBoundFn:
19114 case TypeTableEntryIdArgTuple:
19115 case TypeTableEntryIdVoid:
19116 case TypeTableEntryIdOpaque:
19315 case ZigTypeIdMetaType:
19316 case ZigTypeIdUnreachable:
19317 case ZigTypeIdComptimeFloat:
19318 case ZigTypeIdComptimeInt:
19319 case ZigTypeIdUndefined:
19320 case ZigTypeIdNull:
19321 case ZigTypeIdNamespace:
19322 case ZigTypeIdBlock:
19323 case ZigTypeIdBoundFn:
19324 case ZigTypeIdArgTuple:
19325 case ZigTypeIdVoid:
19326 case ZigTypeIdOpaque:
1911719327 ir_add_error(ira, instruction->type_value,
1911819328 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
1911919329 return ira->codegen->builtin_types.entry_invalid;
19120 case TypeTableEntryIdBool:
19121 case TypeTableEntryIdInt:
19122 case TypeTableEntryIdFloat:
19123 case TypeTableEntryIdPointer:
19124 case TypeTableEntryIdPromise:
19125 case TypeTableEntryIdArray:
19126 case TypeTableEntryIdStruct:
19127 case TypeTableEntryIdOptional:
19128 case TypeTableEntryIdErrorUnion:
19129 case TypeTableEntryIdErrorSet:
19130 case TypeTableEntryIdEnum:
19131 case TypeTableEntryIdUnion:
19132 case TypeTableEntryIdFn:
19330 case ZigTypeIdBool:
19331 case ZigTypeIdInt:
19332 case ZigTypeIdFloat:
19333 case ZigTypeIdPointer:
19334 case ZigTypeIdPromise:
19335 case ZigTypeIdArray:
19336 case ZigTypeIdStruct:
19337 case ZigTypeIdOptional:
19338 case ZigTypeIdErrorUnion:
19339 case ZigTypeIdErrorSet:
19340 case ZigTypeIdEnum:
19341 case ZigTypeIdUnion:
19342 case ZigTypeIdFn:
1913319343 {
1913419344 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);
1913519345 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
1914019350 zig_unreachable();
1914119351}
1914219352
19143static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
19353static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
1914419354 IrInstruction *type_value = instruction->type_value->other;
1914519355 if (type_is_invalid(type_value->value.type))
1914619356 return ira->codegen->builtin_types.entry_invalid;
1914719357
19148 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
19358 ZigType *dest_type = ir_resolve_type(ira, type_value);
1914919359 if (type_is_invalid(dest_type))
1915019360 return ira->codegen->builtin_types.entry_invalid;
1915119361
19152 if (dest_type->id != TypeTableEntryIdInt) {
19362 if (dest_type->id != ZigTypeIdInt) {
1915319363 ir_add_error(ira, type_value,
1915419364 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
1915519365 return ira->codegen->builtin_types.entry_invalid;
......@@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1916919379
1917019380 IrInstruction *casted_op2;
1917119381 if (instruction->op == IrOverflowOpShl) {
19172 TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
19382 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
1917319383 dest_type->data.integral.bit_count - 1);
1917419384 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
1917519385 } else {
......@@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1918219392 if (type_is_invalid(result_ptr->value.type))
1918319393 return ira->codegen->builtin_types.entry_invalid;
1918419394
19185 TypeTableEntry *expected_ptr_type;
19186 if (result_ptr->value.type->id == TypeTableEntryIdPointer) {
19395 ZigType *expected_ptr_type;
19396 if (result_ptr->value.type->id == ZigTypeIdPointer) {
1918719397 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
1918819398 false, result_ptr->value.type->data.pointer.is_volatile,
1918919399 PtrLenSingle,
......@@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1920319413 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1920419414 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;
1920519415 BigInt *op2_bigint = &casted_op2->value.data.x_bigint;
19206 ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, &casted_result_ptr->value);
19416 ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, &casted_result_ptr->value, casted_result_ptr->source_node);
19417 if (pointee_val == nullptr)
19418 return ira->codegen->builtin_types.entry_invalid;
1920719419 BigInt *dest_bigint = &pointee_val->data.x_bigint;
1920819420 switch (instruction->op) {
1920919421 case IrOverflowOpAdd:
......@@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1923719449 return ira->codegen->builtin_types.entry_bool;
1923819450}
1923919451
19240static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
19452static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
1924119453 IrInstruction *value = instruction->value->other;
1924219454 if (type_is_invalid(value->value.type))
1924319455 return ira->codegen->builtin_types.entry_invalid;
1924419456
19245 TypeTableEntry *type_entry = value->value.type;
19457 ZigType *type_entry = value->value.type;
1924619458 if (type_is_invalid(type_entry)) {
1924719459 return ira->codegen->builtin_types.entry_invalid;
19248 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
19460 } else if (type_entry->id == ZigTypeIdErrorUnion) {
1924919461 if (instr_is_comptime(value)) {
1925019462 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
1925119463 if (!err_union_val)
......@@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1925819470 }
1925919471 }
1926019472
19261 TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;
19473 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
1926219474 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
1926319475 return ira->codegen->builtin_types.entry_invalid;
1926419476 }
......@@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1927319485
1927419486 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
1927519487 return ira->codegen->builtin_types.entry_bool;
19276 } else if (type_entry->id == TypeTableEntryIdErrorSet) {
19488 } else if (type_entry->id == ZigTypeIdErrorSet) {
1927719489 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1927819490 out_val->data.x_bool = true;
1927919491 return ira->codegen->builtin_types.entry_bool;
......@@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1928419496 }
1928519497}
1928619498
19287static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
19499static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1928819500 IrInstructionUnwrapErrCode *instruction)
1928919501{
1929019502 IrInstruction *value = instruction->value->other;
1929119503 if (type_is_invalid(value->value.type))
1929219504 return ira->codegen->builtin_types.entry_invalid;
19293 TypeTableEntry *ptr_type = value->value.type;
19505 ZigType *ptr_type = value->value.type;
1929419506
1929519507 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
19296 assert(ptr_type->id == TypeTableEntryIdPointer);
19508 assert(ptr_type->id == ZigTypeIdPointer);
1929719509
19298 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
19510 ZigType *type_entry = ptr_type->data.pointer.child_type;
1929919511 if (type_is_invalid(type_entry)) {
1930019512 return ira->codegen->builtin_types.entry_invalid;
19301 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
19513 } else if (type_entry->id == ZigTypeIdErrorUnion) {
1930219514 if (instr_is_comptime(value)) {
1930319515 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
1930419516 if (!ptr_val)
1930519517 return ira->codegen->builtin_types.entry_invalid;
19306 ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
19518 ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);
19519 if (err_union_val == nullptr)
19520 return ira->codegen->builtin_types.entry_invalid;
1930719521 if (err_union_val->special != ConstValSpecialRuntime) {
1930819522 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
1930919523 assert(err);
......@@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1932319537 }
1932419538}
1932519539
19326static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
19540static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1932719541 IrInstructionUnwrapErrPayload *instruction)
1932819542{
1932919543 assert(instruction->value->other);
1933019544 IrInstruction *value = instruction->value->other;
1933119545 if (type_is_invalid(value->value.type))
1933219546 return ira->codegen->builtin_types.entry_invalid;
19333 TypeTableEntry *ptr_type = value->value.type;
19547 ZigType *ptr_type = value->value.type;
1933419548
1933519549 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
19336 assert(ptr_type->id == TypeTableEntryIdPointer);
19550 assert(ptr_type->id == ZigTypeIdPointer);
1933719551
19338 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
19552 ZigType *type_entry = ptr_type->data.pointer.child_type;
1933919553 if (type_is_invalid(type_entry)) {
1934019554 return ira->codegen->builtin_types.entry_invalid;
19341 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
19342 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
19555 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19556 ZigType *payload_type = type_entry->data.error_union.payload_type;
1934319557 if (type_is_invalid(payload_type)) {
1934419558 return ira->codegen->builtin_types.entry_invalid;
1934519559 }
19346 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
19560 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
1934719561 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
1934819562 PtrLenSingle,
1934919563 get_abi_alignment(ira->codegen, payload_type), 0, 0);
......@@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1935119565 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
1935219566 if (!ptr_val)
1935319567 return ira->codegen->builtin_types.entry_invalid;
19354 ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
19568 ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);
19569 if (err_union_val == nullptr)
19570 return ira->codegen->builtin_types.entry_invalid;
1935519571 if (err_union_val->special != ConstValSpecialRuntime) {
1935619572 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
1935719573 if (err != nullptr) {
......@@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1937719593
1937819594}
1937919595
19380static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
19596static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
19597 Error err;
1938119598 AstNode *proto_node = instruction->base.source_node;
1938219599 assert(proto_node->type == NodeTypeFnProto);
1938319600
......@@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1941919636 IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other;
1942019637 if (type_is_invalid(param_type_value->value.type))
1942119638 return ira->codegen->builtin_types.entry_invalid;
19422 param_info->type = ir_resolve_type(ira, param_type_value);
19423 if (type_is_invalid(param_info->type))
19639 ZigType *param_type = ir_resolve_type(ira, param_type_value);
19640 if (type_is_invalid(param_type))
19641 return ira->codegen->builtin_types.entry_invalid;
19642 if ((err = type_ensure_zero_bits_known(ira->codegen, param_type)))
1942419643 return ira->codegen->builtin_types.entry_invalid;
19644 if (type_requires_comptime(param_type)) {
19645 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
19646 ir_add_error(ira, &instruction->base,
19647 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
19648 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
19649 return ira->codegen->builtin_types.entry_invalid;
19650 }
19651 param_info->type = param_type;
19652 fn_type_id.next_param_index += 1;
19653 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19654 out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id);
19655 return ira->codegen->builtin_types.entry_type;
19656 }
19657 param_info->type = param_type;
1942519658 }
1942619659
1942719660 }
......@@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1943519668 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
1943619669 if (type_is_invalid(fn_type_id.return_type))
1943719670 return ira->codegen->builtin_types.entry_invalid;
19438 if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) {
19671 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
1943919672 ir_add_error(ira, instruction->return_type,
1944019673 buf_sprintf("return type cannot be opaque"));
1944119674 return ira->codegen->builtin_types.entry_invalid;
......@@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1945819691 return ira->codegen->builtin_types.entry_type;
1945919692}
1946019693
19461static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
19694static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
1946219695 IrInstruction *value = instruction->value->other;
1946319696 if (type_is_invalid(value->value.type))
1946419697 return ira->codegen->builtin_types.entry_invalid;
......@@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn
1946819701 return ira->codegen->builtin_types.entry_bool;
1946919702}
1947019703
19471static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19704static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
1947219705 IrInstructionCheckSwitchProngs *instruction)
1947319706{
1947419707 IrInstruction *target_value = instruction->target_value->other;
19475 TypeTableEntry *switch_type = target_value->value.type;
19708 ZigType *switch_type = target_value->value.type;
1947619709 if (type_is_invalid(switch_type))
1947719710 return ira->codegen->builtin_types.entry_invalid;
1947819711
19479 if (switch_type->id == TypeTableEntryIdEnum) {
19712 if (switch_type->id == ZigTypeIdEnum) {
1948019713 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
1948119714 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
1948219715
......@@ -19491,7 +19724,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1949119724 if (type_is_invalid(end_value->value.type))
1949219725 return ira->codegen->builtin_types.entry_invalid;
1949319726
19494 if (start_value->value.type->id != TypeTableEntryIdEnum) {
19727 if (start_value->value.type->id != ZigTypeIdEnum) {
1949519728 ir_add_error(ira, range->start, buf_sprintf("not an enum type"));
1949619729 return ira->codegen->builtin_types.entry_invalid;
1949719730 }
......@@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1949919732 BigInt start_index;
1950019733 bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);
1950119734
19502 assert(end_value->value.type->id == TypeTableEntryIdEnum);
19735 assert(end_value->value.type->id == ZigTypeIdEnum);
1950319736 BigInt end_index;
1950419737 bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);
1950519738
......@@ -19535,7 +19768,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1953519768 }
1953619769 }
1953719770 }
19538 } else if (switch_type->id == TypeTableEntryIdErrorSet) {
19771 } else if (switch_type->id == ZigTypeIdErrorSet) {
1953919772 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
1954019773 return ira->codegen->builtin_types.entry_invalid;
1954119774 }
......@@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1955319786 if (type_is_invalid(end_value->value.type))
1955419787 return ira->codegen->builtin_types.entry_invalid;
1955519788
19556 assert(start_value->value.type->id == TypeTableEntryIdErrorSet);
19789 assert(start_value->value.type->id == ZigTypeIdErrorSet);
1955719790 uint32_t start_index = start_value->value.data.x_err_set->value;
1955819791
19559 assert(end_value->value.type->id == TypeTableEntryIdErrorSet);
19792 assert(end_value->value.type->id == ZigTypeIdErrorSet);
1956019793 uint32_t end_index = end_value->value.data.x_err_set->value;
1956119794
1956219795 if (start_index != end_index) {
......@@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1959219825 }
1959319826
1959419827 free(field_prev_uses);
19595 } else if (switch_type->id == TypeTableEntryIdInt) {
19828 } else if (switch_type->id == ZigTypeIdInt) {
1959619829 RangeSet rs = {0};
1959719830 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
1959819831 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
......@@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1961919852 if (!end_val)
1962019853 return ira->codegen->builtin_types.entry_invalid;
1962119854
19622 assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);
19623 assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);
19855 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
19856 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
1962419857 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
1962519858 start_value->source_node);
1962619859 if (prev_node != nullptr) {
......@@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1964819881 return ira->codegen->builtin_types.entry_void;
1964919882}
1965019883
19651static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
19884static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
1965219885 IrInstructionCheckStatementIsVoid *instruction)
1965319886{
1965419887 IrInstruction *statement_value = instruction->statement_value->other;
19655 TypeTableEntry *statement_type = statement_value->value.type;
19888 ZigType *statement_type = statement_value->value.type;
1965619889 if (type_is_invalid(statement_type))
1965719890 return ira->codegen->builtin_types.entry_invalid;
1965819891
19659 if (statement_type->id != TypeTableEntryIdVoid) {
19892 if (statement_type->id != ZigTypeIdVoid) {
1966019893 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
1966119894 }
1966219895
......@@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze
1966419897 return ira->codegen->builtin_types.entry_void;
1966519898}
1966619899
19667static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
19900static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
1966819901 IrInstruction *msg = instruction->msg->other;
1966919902 if (type_is_invalid(msg->value.type))
1967019903 return ir_unreach_error(ira);
......@@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
1967419907 return ir_unreach_error(ira);
1967519908 }
1967619909
19677 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
19910 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1967819911 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
19679 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
19912 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1968019913 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
1968119914 if (type_is_invalid(casted_msg->value.type))
1968219915 return ir_unreach_error(ira);
......@@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
1968819921}
1968919922
1969019923static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
19691 TypeTableEntry *target_type = target->value.type;
19924 ZigType *target_type = target->value.type;
1969219925 assert(!type_is_invalid(target_type));
1969319926
19694 TypeTableEntry *result_type;
19927 ZigType *result_type;
1969519928 uint32_t old_align_bytes;
1969619929
19697 if (target_type->id == TypeTableEntryIdPointer) {
19930 if (target_type->id == ZigTypeIdPointer) {
1969819931 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
1969919932 old_align_bytes = target_type->data.pointer.alignment;
19700 } else if (target_type->id == TypeTableEntryIdFn) {
19933 } else if (target_type->id == ZigTypeIdFn) {
1970119934 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
1970219935 old_align_bytes = fn_type_id.alignment;
1970319936 fn_type_id.alignment = align_bytes;
1970419937 result_type = get_fn_type(ira->codegen, &fn_type_id);
19705 } else if (target_type->id == TypeTableEntryIdOptional &&
19706 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
19938 } else if (target_type->id == ZigTypeIdOptional &&
19939 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
1970719940 {
19708 TypeTableEntry *ptr_type = target_type->data.maybe.child_type;
19941 ZigType *ptr_type = target_type->data.maybe.child_type;
1970919942 old_align_bytes = ptr_type->data.pointer.alignment;
19710 TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
19943 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
1971119944
1971219945 result_type = get_optional_type(ira->codegen, better_ptr_type);
19713 } else if (target_type->id == TypeTableEntryIdOptional &&
19714 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
19946 } else if (target_type->id == ZigTypeIdOptional &&
19947 target_type->data.maybe.child_type->id == ZigTypeIdFn)
1971519948 {
1971619949 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;
1971719950 old_align_bytes = fn_type_id.alignment;
1971819951 fn_type_id.alignment = align_bytes;
19719 TypeTableEntry *fn_type = get_fn_type(ira->codegen, &fn_type_id);
19952 ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id);
1972019953 result_type = get_optional_type(ira->codegen, fn_type);
1972119954 } else if (is_slice(target_type)) {
19722 TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
19955 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
1972319956 old_align_bytes = slice_ptr_type->data.pointer.alignment;
19724 TypeTableEntry *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
19957 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
1972519958 result_type = get_slice_type(ira->codegen, result_ptr_type);
1972619959 } else {
1972719960 ir_add_error(ira, target,
......@@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
1975919992 return result;
1976019993}
1976119994
19762static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
19995static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
1976319996 Error err;
1976419997
1976519998 IrInstruction *dest_type_value = instruction->dest_type->other;
19766 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
19999 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
1976720000 if (type_is_invalid(dest_type))
1976820001 return ira->codegen->builtin_types.entry_invalid;
1976920002
1977020003 IrInstruction *ptr = instruction->ptr->other;
19771 TypeTableEntry *src_type = ptr->value.type;
20004 ZigType *src_type = ptr->value.type;
1977220005 if (type_is_invalid(src_type))
1977320006 return ira->codegen->builtin_types.entry_invalid;
1977420007
......@@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
1983520068static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
1983620069 assert(val->special == ConstValSpecialStatic);
1983720070 switch (val->type->id) {
19838 case TypeTableEntryIdInvalid:
19839 case TypeTableEntryIdMetaType:
19840 case TypeTableEntryIdOpaque:
19841 case TypeTableEntryIdBoundFn:
19842 case TypeTableEntryIdArgTuple:
19843 case TypeTableEntryIdNamespace:
19844 case TypeTableEntryIdBlock:
19845 case TypeTableEntryIdUnreachable:
19846 case TypeTableEntryIdComptimeFloat:
19847 case TypeTableEntryIdComptimeInt:
19848 case TypeTableEntryIdUndefined:
19849 case TypeTableEntryIdNull:
19850 case TypeTableEntryIdPromise:
20071 case ZigTypeIdInvalid:
20072 case ZigTypeIdMetaType:
20073 case ZigTypeIdOpaque:
20074 case ZigTypeIdBoundFn:
20075 case ZigTypeIdArgTuple:
20076 case ZigTypeIdNamespace:
20077 case ZigTypeIdBlock:
20078 case ZigTypeIdUnreachable:
20079 case ZigTypeIdComptimeFloat:
20080 case ZigTypeIdComptimeInt:
20081 case ZigTypeIdUndefined:
20082 case ZigTypeIdNull:
20083 case ZigTypeIdPromise:
1985120084 zig_unreachable();
19852 case TypeTableEntryIdVoid:
20085 case ZigTypeIdVoid:
1985320086 return;
19854 case TypeTableEntryIdBool:
20087 case ZigTypeIdBool:
1985520088 buf[0] = val->data.x_bool ? 1 : 0;
1985620089 return;
19857 case TypeTableEntryIdInt:
20090 case ZigTypeIdInt:
1985820091 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
1985920092 codegen->is_big_endian);
1986020093 return;
19861 case TypeTableEntryIdFloat:
20094 case ZigTypeIdFloat:
1986220095 float_write_ieee597(val, buf, codegen->is_big_endian);
1986320096 return;
19864 case TypeTableEntryIdPointer:
20097 case ZigTypeIdPointer:
1986520098 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
1986620099 BigInt bn;
1986720100 bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr);
......@@ -19870,7 +20103,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1987020103 } else {
1987120104 zig_unreachable();
1987220105 }
19873 case TypeTableEntryIdArray:
20106 case ZigTypeIdArray:
1987420107 {
1987520108 size_t buf_i = 0;
1987620109 expand_undef_array(codegen, val);
......@@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1988120114 }
1988220115 }
1988320116 return;
19884 case TypeTableEntryIdStruct:
20117 case ZigTypeIdStruct:
1988520118 zig_panic("TODO buf_write_value_bytes struct type");
19886 case TypeTableEntryIdOptional:
20119 case ZigTypeIdOptional:
1988720120 zig_panic("TODO buf_write_value_bytes maybe type");
19888 case TypeTableEntryIdErrorUnion:
20121 case ZigTypeIdErrorUnion:
1988920122 zig_panic("TODO buf_write_value_bytes error union");
19890 case TypeTableEntryIdErrorSet:
20123 case ZigTypeIdErrorSet:
1989120124 zig_panic("TODO buf_write_value_bytes pure error type");
19892 case TypeTableEntryIdEnum:
20125 case ZigTypeIdEnum:
1989320126 zig_panic("TODO buf_write_value_bytes enum type");
19894 case TypeTableEntryIdFn:
20127 case ZigTypeIdFn:
1989520128 zig_panic("TODO buf_write_value_bytes fn type");
19896 case TypeTableEntryIdUnion:
20129 case ZigTypeIdUnion:
1989720130 zig_panic("TODO buf_write_value_bytes union type");
1989820131 }
1989920132 zig_unreachable();
......@@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1990220135static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
1990320136 assert(val->special == ConstValSpecialStatic);
1990420137 switch (val->type->id) {
19905 case TypeTableEntryIdInvalid:
19906 case TypeTableEntryIdMetaType:
19907 case TypeTableEntryIdOpaque:
19908 case TypeTableEntryIdBoundFn:
19909 case TypeTableEntryIdArgTuple:
19910 case TypeTableEntryIdNamespace:
19911 case TypeTableEntryIdBlock:
19912 case TypeTableEntryIdUnreachable:
19913 case TypeTableEntryIdComptimeFloat:
19914 case TypeTableEntryIdComptimeInt:
19915 case TypeTableEntryIdUndefined:
19916 case TypeTableEntryIdNull:
19917 case TypeTableEntryIdPromise:
20138 case ZigTypeIdInvalid:
20139 case ZigTypeIdMetaType:
20140 case ZigTypeIdOpaque:
20141 case ZigTypeIdBoundFn:
20142 case ZigTypeIdArgTuple:
20143 case ZigTypeIdNamespace:
20144 case ZigTypeIdBlock:
20145 case ZigTypeIdUnreachable:
20146 case ZigTypeIdComptimeFloat:
20147 case ZigTypeIdComptimeInt:
20148 case ZigTypeIdUndefined:
20149 case ZigTypeIdNull:
20150 case ZigTypeIdPromise:
1991820151 zig_unreachable();
19919 case TypeTableEntryIdVoid:
20152 case ZigTypeIdVoid:
1992020153 return;
19921 case TypeTableEntryIdBool:
20154 case ZigTypeIdBool:
1992220155 val->data.x_bool = (buf[0] != 0);
1992320156 return;
19924 case TypeTableEntryIdInt:
20157 case ZigTypeIdInt:
1992520158 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
1992620159 codegen->is_big_endian, val->type->data.integral.is_signed);
1992720160 return;
19928 case TypeTableEntryIdFloat:
20161 case ZigTypeIdFloat:
1992920162 float_read_ieee597(val, buf, codegen->is_big_endian);
1993020163 return;
19931 case TypeTableEntryIdPointer:
20164 case ZigTypeIdPointer:
1993220165 {
1993320166 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1993420167 BigInt bn;
......@@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1993720170 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
1993820171 return;
1993920172 }
19940 case TypeTableEntryIdArray:
20173 case ZigTypeIdArray:
1994120174 zig_panic("TODO buf_read_value_bytes array type");
19942 case TypeTableEntryIdStruct:
20175 case ZigTypeIdStruct:
1994320176 zig_panic("TODO buf_read_value_bytes struct type");
19944 case TypeTableEntryIdOptional:
20177 case ZigTypeIdOptional:
1994520178 zig_panic("TODO buf_read_value_bytes maybe type");
19946 case TypeTableEntryIdErrorUnion:
20179 case ZigTypeIdErrorUnion:
1994720180 zig_panic("TODO buf_read_value_bytes error union");
19948 case TypeTableEntryIdErrorSet:
20181 case ZigTypeIdErrorSet:
1994920182 zig_panic("TODO buf_read_value_bytes pure error type");
19950 case TypeTableEntryIdEnum:
20183 case ZigTypeIdEnum:
1995120184 zig_panic("TODO buf_read_value_bytes enum type");
19952 case TypeTableEntryIdFn:
20185 case ZigTypeIdFn:
1995320186 zig_panic("TODO buf_read_value_bytes fn type");
19954 case TypeTableEntryIdUnion:
20187 case ZigTypeIdUnion:
1995520188 zig_panic("TODO buf_read_value_bytes union type");
1995620189 }
1995720190 zig_unreachable();
1995820191}
1995920192
19960static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
20193static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
1996120194 Error err;
1996220195 IrInstruction *dest_type_value = instruction->dest_type->other;
19963 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
20196 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
1996420197 if (type_is_invalid(dest_type))
1996520198 return ira->codegen->builtin_types.entry_invalid;
1996620199
1996720200 IrInstruction *value = instruction->value->other;
19968 TypeTableEntry *src_type = value->value.type;
20201 ZigType *src_type = value->value.type;
1996920202 if (type_is_invalid(src_type))
1997020203 return ira->codegen->builtin_types.entry_invalid;
1997120204
......@@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
1998220215 }
1998320216
1998420217 switch (src_type->id) {
19985 case TypeTableEntryIdInvalid:
19986 case TypeTableEntryIdMetaType:
19987 case TypeTableEntryIdOpaque:
19988 case TypeTableEntryIdBoundFn:
19989 case TypeTableEntryIdArgTuple:
19990 case TypeTableEntryIdNamespace:
19991 case TypeTableEntryIdBlock:
19992 case TypeTableEntryIdUnreachable:
19993 case TypeTableEntryIdComptimeFloat:
19994 case TypeTableEntryIdComptimeInt:
19995 case TypeTableEntryIdUndefined:
19996 case TypeTableEntryIdNull:
20218 case ZigTypeIdInvalid:
20219 case ZigTypeIdMetaType:
20220 case ZigTypeIdOpaque:
20221 case ZigTypeIdBoundFn:
20222 case ZigTypeIdArgTuple:
20223 case ZigTypeIdNamespace:
20224 case ZigTypeIdBlock:
20225 case ZigTypeIdUnreachable:
20226 case ZigTypeIdComptimeFloat:
20227 case ZigTypeIdComptimeInt:
20228 case ZigTypeIdUndefined:
20229 case ZigTypeIdNull:
1999720230 ir_add_error(ira, dest_type_value,
1999820231 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
1999920232 return ira->codegen->builtin_types.entry_invalid;
......@@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
2000820241 }
2000920242
2001020243 switch (dest_type->id) {
20011 case TypeTableEntryIdInvalid:
20012 case TypeTableEntryIdMetaType:
20013 case TypeTableEntryIdOpaque:
20014 case TypeTableEntryIdBoundFn:
20015 case TypeTableEntryIdArgTuple:
20016 case TypeTableEntryIdNamespace:
20017 case TypeTableEntryIdBlock:
20018 case TypeTableEntryIdUnreachable:
20019 case TypeTableEntryIdComptimeFloat:
20020 case TypeTableEntryIdComptimeInt:
20021 case TypeTableEntryIdUndefined:
20022 case TypeTableEntryIdNull:
20244 case ZigTypeIdInvalid:
20245 case ZigTypeIdMetaType:
20246 case ZigTypeIdOpaque:
20247 case ZigTypeIdBoundFn:
20248 case ZigTypeIdArgTuple:
20249 case ZigTypeIdNamespace:
20250 case ZigTypeIdBlock:
20251 case ZigTypeIdUnreachable:
20252 case ZigTypeIdComptimeFloat:
20253 case ZigTypeIdComptimeInt:
20254 case ZigTypeIdUndefined:
20255 case ZigTypeIdNull:
2002320256 ir_add_error(ira, dest_type_value,
2002420257 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
2002520258 return ira->codegen->builtin_types.entry_invalid;
......@@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
2005720290 return dest_type;
2005820291}
2005920292
20060static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
20293static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
2006120294 Error err;
2006220295 IrInstruction *dest_type_value = instruction->dest_type->other;
20063 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
20296 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2006420297 if (type_is_invalid(dest_type))
2006520298 return ira->codegen->builtin_types.entry_invalid;
2006620299
......@@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
2010220335 return dest_type;
2010320336}
2010420337
20105static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20338static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2010620339 IrInstructionDeclRef *instruction)
2010720340{
2010820341 Tld *tld = instruction->tld;
......@@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2011920352 case TldIdVar:
2012020353 {
2012120354 TldVar *tld_var = (TldVar *)tld;
20122 VariableTableEntry *var = tld_var->var;
20355 ZigVar *var = tld_var->var;
2012320356
2012420357 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
2012520358 if (type_is_invalid(var_ptr->value.type))
......@@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2014120374 case TldIdFn:
2014220375 {
2014320376 TldFn *tld_fn = (TldFn *)tld;
20144 FnTableEntry *fn_entry = tld_fn->fn_entry;
20377 ZigFn *fn_entry = tld_fn->fn_entry;
2014520378 assert(fn_entry->type_entry);
2014620379
2014720380 if (tld_fn->extern_lib_name != nullptr) {
......@@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2016320396 zig_unreachable();
2016420397}
2016520398
20166static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
20399static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
2016720400 IrInstruction *target = instruction->target->other;
2016820401 if (type_is_invalid(target->value.type))
2016920402 return ira->codegen->builtin_types.entry_invalid;
2017020403
20171 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
20404 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2017220405
2017320406 if (get_codegen_ptr_type(target->value.type) == nullptr) {
2017420407 ir_add_error(ira, target,
......@@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
2018620419 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
2018720420 if (!val)
2018820421 return ira->codegen->builtin_types.entry_invalid;
20189 if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
20422 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
2019020423 IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,
2019120424 instruction->base.source_node, usize);
2019220425 bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
......@@ -20202,16 +20435,16 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
2020220435 return usize;
2020320436}
2020420437
20205static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
20438static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
2020620439 Error err;
20207 TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other);
20440 ZigType *child_type = ir_resolve_type(ira, instruction->child_type->other);
2020820441 if (type_is_invalid(child_type))
2020920442 return ira->codegen->builtin_types.entry_invalid;
2021020443
20211 if (child_type->id == TypeTableEntryIdUnreachable) {
20444 if (child_type->id == ZigTypeIdUnreachable) {
2021220445 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
2021320446 return ira->codegen->builtin_types.entry_invalid;
20214 } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) {
20447 } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) {
2021520448 ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));
2021620449 return ira->codegen->builtin_types.entry_invalid;
2021720450 }
......@@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
2023520468 return ira->codegen->builtin_types.entry_type;
2023620469}
2023720470
20238static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
20471static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
2023920472 uint32_t align_bytes;
2024020473 IrInstruction *align_bytes_inst = instruction->align_bytes->other;
2024120474 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
......@@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr
2025320486 return result->value.type;
2025420487}
2025520488
20256static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
20489static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
2025720490 Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node);
2025820491 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
2025920492 out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,
......@@ -20261,7 +20494,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst
2026120494 return ira->codegen->builtin_types.entry_type;
2026220495}
2026320496
20264static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
20497static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
2026520498 uint32_t align_bytes;
2026620499 IrInstruction *align_bytes_inst = instruction->align_bytes->other;
2026720500 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
......@@ -20272,7 +20505,7 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
2027220505 return ira->codegen->builtin_types.entry_invalid;
2027320506 }
2027420507
20275 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
20508 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
2027620509 if (fn_entry == nullptr) {
2027720510 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
2027820511 return ira->codegen->builtin_types.entry_invalid;
......@@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
2030120534 return ira->codegen->builtin_types.entry_void;
2030220535}
2030320536
20304static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
20537static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
2030520538 IrInstruction *fn_type_inst = instruction->fn_type->other;
20306 TypeTableEntry *fn_type = ir_resolve_type(ira, fn_type_inst);
20539 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
2030720540 if (type_is_invalid(fn_type))
2030820541 return ira->codegen->builtin_types.entry_invalid;
2030920542
......@@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
2031220545 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
2031320546 return ira->codegen->builtin_types.entry_invalid;
2031420547
20315 if (fn_type->id != TypeTableEntryIdFn) {
20548 if (fn_type->id != ZigTypeIdFn) {
2031620549 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
2031720550 return ira->codegen->builtin_types.entry_invalid;
2031820551 }
......@@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
2034020573 return ira->codegen->builtin_types.entry_type;
2034120574}
2034220575
20343static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
20576static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
2034420577 Error err;
2034520578 IrInstruction *target_inst = instruction->target->other;
20346 TypeTableEntry *enum_type = ir_resolve_type(ira, target_inst);
20579 ZigType *enum_type = ir_resolve_type(ira, target_inst);
2034720580 if (type_is_invalid(enum_type))
2034820581 return ira->codegen->builtin_types.entry_invalid;
2034920582
20350 if (enum_type->id == TypeTableEntryIdEnum) {
20583 if (enum_type->id == ZigTypeIdEnum) {
2035120584 if ((err = ensure_complete_type(ira->codegen, enum_type)))
2035220585 return ira->codegen->builtin_types.entry_invalid;
2035320586
2035420587 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
2035520588 out_val->data.x_type = enum_type->data.enumeration.tag_int_type;
2035620589 return ira->codegen->builtin_types.entry_type;
20357 } else if (enum_type->id == TypeTableEntryIdUnion) {
20590 } else if (enum_type->id == ZigTypeIdUnion) {
2035820591 if ((err = ensure_complete_type(ira->codegen, enum_type)))
2035920592 return ira->codegen->builtin_types.entry_invalid;
2036020593
......@@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc
2037820611 }
2037920612}
2038020613
20381static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
20614static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
2038220615 IrInstruction *target_inst = instruction->target->other;
2038320616 if (type_is_invalid(target_inst->value.type))
2038420617 return ira->codegen->builtin_types.entry_invalid;
......@@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi
2039320626 return result->value.type;
2039420627}
2039520628
20396static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
20629static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
2039720630 IrInstruction *promise_ptr = instruction->promise_ptr->other;
2039820631 if (type_is_invalid(promise_ptr->value.type))
2039920632 return ira->codegen->builtin_types.entry_invalid;
......@@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct
2040520638 return result->value.type;
2040620639}
2040720640
20408static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
20641static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
2040920642 IrInstruction *coro_id = instruction->coro_id->other;
2041020643 if (type_is_invalid(coro_id->value.type))
2041120644 return ira->codegen->builtin_types.entry_invalid;
......@@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr
2041720650 return result->value.type;
2041820651}
2041920652
20420static TypeTableEntry *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
20653static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
2042120654 IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
2042220655 ir_link_new_instruction(result, &instruction->base);
2042320656 result->value.type = ira->codegen->builtin_types.entry_usize;
2042420657 return result->value.type;
2042520658}
2042620659
20427static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
20660static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
2042820661 IrInstruction *coro_id = instruction->coro_id->other;
2042920662 if (type_is_invalid(coro_id->value.type))
2043020663 return ira->codegen->builtin_types.entry_invalid;
......@@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
2043320666 if (type_is_invalid(coro_mem_ptr->value.type))
2043420667 return ira->codegen->builtin_types.entry_invalid;
2043520668
20436 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
20669 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
2043720670 assert(fn_entry != nullptr);
2043820671 IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
2043920672 coro_id, coro_mem_ptr);
......@@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
2044220675 return result->value.type;
2044320676}
2044420677
20445static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
20678static ZigType *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
2044620679 IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id);
2044720680 ir_link_new_instruction(result, &instruction->base);
2044820681 return result->value.type;
2044920682}
2045020683
20451static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) {
20684static ZigType *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) {
2045220685 IrInstruction *err_val = instruction->err_val->other;
2045320686 if (type_is_invalid(err_val->value.type))
2045420687 return ir_unreach_error(ira);
......@@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir
2045920692 return ir_finish_anal(ira, result->value.type);
2046020693}
2046120694
20462static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
20695static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
2046320696 IrInstruction *save_point = nullptr;
2046420697 if (instruction->save_point != nullptr) {
2046520698 save_point = instruction->save_point->other;
......@@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns
2047820711 return result->value.type;
2047920712}
2048020713
20481static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
20714static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
2048220715 IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope,
2048320716 instruction->base.source_node);
2048420717 ir_link_new_instruction(result, &instruction->base);
......@@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc
2048620719 return result->value.type;
2048720720}
2048820721
20489static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
20722static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
2049020723 IrInstruction *coro_id = instruction->coro_id->other;
2049120724 if (type_is_invalid(coro_id->value.type))
2049220725 return ira->codegen->builtin_types.entry_invalid;
......@@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru
2049820731 IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope,
2049920732 instruction->base.source_node, coro_id, coro_handle);
2050020733 ir_link_new_instruction(result, &instruction->base);
20501 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
20734 ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
2050220735 result->value.type = get_optional_type(ira->codegen, ptr_type);
2050320736 return result->value.type;
2050420737}
2050520738
20506static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
20739static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
2050720740 IrInstruction *awaiter_handle = instruction->awaiter_handle->other;
2050820741 if (type_is_invalid(awaiter_handle->value.type))
2050920742 return ira->codegen->builtin_types.entry_invalid;
......@@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst
2051920752 return result->value.type;
2052020753}
2052120754
20522static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
20755static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
2052320756 IrInstruction *coro_handle = instruction->coro_handle->other;
2052420757 if (type_is_invalid(coro_handle->value.type))
2052520758 return ira->codegen->builtin_types.entry_invalid;
......@@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru
2053120764 return result->value.type;
2053220765}
2053320766
20534static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
20767static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
2053520768 IrInstruction *coro_handle = instruction->coro_handle->other;
2053620769 if (type_is_invalid(coro_handle->value.type))
2053720770 return ira->codegen->builtin_types.entry_invalid;
2053820771
20539 if (coro_handle->value.type->id != TypeTableEntryIdPromise ||
20772 if (coro_handle->value.type->id != ZigTypeIdPromise ||
2054020773 coro_handle->value.type->data.promise.result_type == nullptr)
2054120774 {
2054220775 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
......@@ -20544,7 +20777,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
2054420777 return ira->codegen->builtin_types.entry_invalid;
2054520778 }
2054620779
20547 TypeTableEntry *coro_frame_type = get_promise_frame_type(ira->codegen,
20780 ZigType *coro_frame_type = get_promise_frame_type(ira->codegen,
2054820781 coro_handle->value.type->data.promise.result_type);
2054920782
2055020783 IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope,
......@@ -20554,7 +20787,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
2055420787 return result->value.type;
2055520788}
2055620789
20557static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) {
20790static ZigType *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) {
2055820791 IrInstruction *alloc_fn = instruction->alloc_fn->other;
2055920792 if (type_is_invalid(alloc_fn->value.type))
2056020793 return ira->codegen->builtin_types.entry_invalid;
......@@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira,
2056620799 IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope,
2056720800 instruction->base.source_node, alloc_fn, coro_size);
2056820801 ir_link_new_instruction(result, &instruction->base);
20569 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
20802 ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
2057020803 result->value.type = get_optional_type(ira->codegen, u8_ptr_type);
2057120804 return result->value.type;
2057220805}
2057320806
20574static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
20575 TypeTableEntry *operand_type = ir_resolve_type(ira, op);
20807static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
20808 ZigType *operand_type = ir_resolve_type(ira, op);
2057620809 if (type_is_invalid(operand_type))
2057720810 return ira->codegen->builtin_types.entry_invalid;
2057820811
20579 if (operand_type->id == TypeTableEntryIdInt) {
20812 if (operand_type->id == ZigTypeIdInt) {
2058020813 if (operand_type->data.integral.bit_count < 8) {
2058120814 ir_add_error(ira, op,
2058220815 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
......@@ -20603,8 +20836,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct
2060320836 return operand_type;
2060420837}
2060520838
20606static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
20607 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
20839static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
20840 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
2060820841 if (type_is_invalid(operand_type))
2060920842 return ira->codegen->builtin_types.entry_invalid;
2061020843
......@@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
2061320846 return ira->codegen->builtin_types.entry_invalid;
2061420847
2061520848 // TODO let this be volatile
20616 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
20849 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2061720850 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2061820851 if (type_is_invalid(casted_ptr->value.type))
2061920852 return ira->codegen->builtin_types.entry_invalid;
......@@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
2066120894 return result->value.type;
2066220895}
2066320896
20664static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
20665 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
20897static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
20898 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
2066620899 if (type_is_invalid(operand_type))
2066720900 return ira->codegen->builtin_types.entry_invalid;
2066820901
......@@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
2067020903 if (type_is_invalid(ptr_inst->value.type))
2067120904 return ira->codegen->builtin_types.entry_invalid;
2067220905
20673 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
20906 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
2067420907 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2067520908 if (type_is_invalid(casted_ptr->value.type))
2067620909 return ira->codegen->builtin_types.entry_invalid;
......@@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
2070420937 return result->value.type;
2070520938}
2070620939
20707static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
20708 TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other);
20940static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
20941 ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other);
2070920942 if (type_is_invalid(promise_type))
2071020943 return ira->codegen->builtin_types.entry_invalid;
2071120944
20712 if (promise_type->id != TypeTableEntryIdPromise || promise_type->data.promise.result_type == nullptr) {
20945 if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
2071320946 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
2071420947 buf_ptr(&promise_type->name)));
2071520948 return ira->codegen->builtin_types.entry_invalid;
......@@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira
2072020953 return ira->codegen->builtin_types.entry_type;
2072120954}
2072220955
20723static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
20724 TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);
20956static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
20957 ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);
2072520958 if (type_is_invalid(promise_result_type))
2072620959 return ira->codegen->builtin_types.entry_invalid;
2072720960
20728 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
20961 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
2072920962 assert(fn_entry != nullptr);
2073020963
2073120964 if (type_can_fail(promise_result_type)) {
......@@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira,
2073720970 return out_val->type;
2073820971}
2073920972
20740static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
20973static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
2074120974 IrInstructionMergeErrRetTraces *instruction)
2074220975{
2074320976 IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other;
2074420977 if (type_is_invalid(coro_promise_ptr->value.type))
2074520978 return ira->codegen->builtin_types.entry_invalid;
2074620979
20747 assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer);
20748 TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
20749 assert(promise_frame_type->id == TypeTableEntryIdStruct);
20750 TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
20980 assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer);
20981 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
20982 assert(promise_frame_type->id == ZigTypeIdStruct);
20983 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
2075120984
2075220985 if (!type_can_fail(promise_result_type)) {
2075320986 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -20770,7 +21003,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir
2077021003 return result->value.type;
2077121004}
2077221005
20773static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
21006static ZigType *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
2077421007 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
2077521008 instruction->base.source_node);
2077621009 ir_link_new_instruction(result, &instruction->base);
......@@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira,
2077821011 return result->value.type;
2077921012}
2078021013
20781static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) {
21014static ZigType *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) {
2078221015 IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other;
2078321016 if (type_is_invalid(err_ret_trace_ptr->value.type))
2078421017 return ira->codegen->builtin_types.entry_invalid;
......@@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *
2079021023 return result->value.type;
2079121024}
2079221025
20793static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
20794 TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other);
21026static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
21027 ZigType *float_type = ir_resolve_type(ira, instruction->type->other);
2079521028 if (type_is_invalid(float_type))
2079621029 return ira->codegen->builtin_types.entry_invalid;
2079721030
......@@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2079921032 if (type_is_invalid(op->value.type))
2080021033 return ira->codegen->builtin_types.entry_invalid;
2080121034
20802 bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat;
21035 bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat;
2080321036 if (!ok_type) {
2080421037 ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));
2080521038 return ira->codegen->builtin_types.entry_invalid;
......@@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2081621049
2081721050 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
2081821051
20819 if (float_type->id == TypeTableEntryIdComptimeFloat) {
21052 if (float_type->id == ZigTypeIdComptimeFloat) {
2082021053 bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);
20821 } else if (float_type->id == TypeTableEntryIdFloat) {
21054 } else if (float_type->id == ZigTypeIdFloat) {
2082221055 switch (float_type->data.floating.bit_count) {
2082321056 case 16:
2082421057 out_val->data.x_f16 = f16_sqrt(val->data.x_f16);
......@@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2084221075 return float_type;
2084321076 }
2084421077
20845 assert(float_type->id == TypeTableEntryIdFloat);
21078 assert(float_type->id == ZigTypeIdFloat);
2084621079 if (float_type->data.floating.bit_count != 16 &&
2084721080 float_type->data.floating.bit_count != 32 &&
2084821081 float_type->data.floating.bit_count != 64) {
......@@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2085721090 return result->value.type;
2085821091}
2085921092
20860static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
21093static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
2086121094 Error err;
2086221095 IrInstruction *target = instruction->target->other;
2086321096 if (type_is_invalid(target->value.type))
2086421097 return ira->codegen->builtin_types.entry_invalid;
2086521098
20866 if (target->value.type->id != TypeTableEntryIdEnum) {
21099 if (target->value.type->id != ZigTypeIdEnum) {
2086721100 ir_add_error(ira, instruction->target,
2086821101 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
2086921102 return ira->codegen->builtin_types.entry_invalid;
......@@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst
2087221105 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
2087321106 return ira->codegen->builtin_types.entry_invalid;
2087421107
20875 TypeTableEntry *tag_type = target->value.type->data.enumeration.tag_int_type;
21108 ZigType *tag_type = target->value.type->data.enumeration.tag_int_type;
2087621109
2087721110 IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type);
2087821111 ir_link_new_instruction(result, &instruction->base);
2087921112 return result->value.type;
2088021113}
2088121114
20882static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
21115static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
2088321116 Error err;
2088421117 IrInstruction *dest_type_value = instruction->dest_type->other;
20885 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
21118 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2088621119 if (type_is_invalid(dest_type))
2088721120 return ira->codegen->builtin_types.entry_invalid;
2088821121
20889 if (dest_type->id != TypeTableEntryIdEnum) {
21122 if (dest_type->id != ZigTypeIdEnum) {
2089021123 ir_add_error(ira, instruction->dest_type,
2089121124 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
2089221125 return ira->codegen->builtin_types.entry_invalid;
......@@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
2089521128 if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type)))
2089621129 return ira->codegen->builtin_types.entry_invalid;
2089721130
20898 TypeTableEntry *tag_type = dest_type->data.enumeration.tag_int_type;
21131 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2089921132
2090021133 IrInstruction *target = instruction->target->other;
2090121134 if (type_is_invalid(target->value.type))
......@@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
2091021143 return result->value.type;
2091121144}
2091221145
20913static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
21146static ZigType *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {
21147 IrInstruction *block_comptime_inst = instruction->scope_is_comptime->other;
21148 bool scope_is_comptime;
21149 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))
21150 return ira->codegen->builtin_types.entry_invalid;
21151
21152 IrInstruction *is_comptime_inst = instruction->is_comptime->other;
21153 bool is_comptime;
21154 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
21155 return ira->codegen->builtin_types.entry_invalid;
21156
21157 if (!scope_is_comptime && is_comptime) {
21158 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
21159 buf_sprintf("comptime control flow inside runtime block"));
21160 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
21161 buf_sprintf("runtime block created here"));
21162 return ira->codegen->builtin_types.entry_invalid;
21163 }
21164
21165 ir_build_const_from(ira, &instruction->base);
21166 return ira->codegen->builtin_types.entry_void;
21167}
21168
21169static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
2091421170 switch (instruction->id) {
2091521171 case IrInstructionIdInvalid:
2091621172 case IrInstructionIdWidenOrShorten:
......@@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
2118621442 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
2118721443 case IrInstructionIdEnumToInt:
2118821444 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
21445 case IrInstructionIdCheckRuntimeScope:
21446 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);
2118921447 }
2119021448 zig_unreachable();
2119121449}
2119221450
21193static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
21194 TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
21451static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
21452 ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
2119521453 instruction->value.type = instruction_type;
2119621454
2119721455 if (instruction->other) {
2119821456 instruction->other->value.type = instruction_type;
2119921457 } else {
21200 assert(instruction_type->id == TypeTableEntryIdInvalid ||
21201 instruction_type->id == TypeTableEntryIdUnreachable);
21458 assert(instruction_type->id == ZigTypeIdInvalid ||
21459 instruction_type->id == ZigTypeIdUnreachable);
2120221460 instruction->other = instruction;
2120321461 }
2120421462
......@@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
2120721465
2120821466// This function attempts to evaluate IR code while doing type checking and other analysis.
2120921467// It emits a new IrExecutable which is partially evaluated IR code.
21210TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
21211 TypeTableEntry *expected_type, AstNode *expected_type_source_node)
21468ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
21469 ZigType *expected_type, AstNode *expected_type_source_node)
2121221470{
2121321471 assert(!old_exec->invalid);
2121421472 assert(expected_type == nullptr || !type_is_invalid(expected_type));
......@@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
2121721475 old_exec->analysis = ira;
2121821476 ira->codegen = codegen;
2121921477
21220 FnTableEntry *fn_entry = exec_fn_entry(old_exec);
21478 ZigFn *fn_entry = exec_fn_entry(old_exec);
2122121479 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
2122221480 ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type;
2122321481
......@@ -21249,13 +21507,13 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
2124921507 continue;
2125021508 }
2125121509
21252 TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction);
21510 ZigType *return_type = ir_analyze_instruction(ira, old_instruction);
2125321511 if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) {
2125421512 return ira->codegen->builtin_types.entry_invalid;
2125521513 }
2125621514
2125721515 // unreachable instructions do their own control flow.
21258 if (return_type->id == TypeTableEntryIdUnreachable)
21516 if (return_type->id == ZigTypeIdUnreachable)
2125921517 continue;
2126021518
2126121519 ira->instruction_index += 1;
......@@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2130121559 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free
2130221560 case IrInstructionIdCheckSwitchProngs:
2130321561 case IrInstructionIdCheckStatementIsVoid:
21562 case IrInstructionIdCheckRuntimeScope:
2130421563 case IrInstructionIdPanic:
2130521564 case IrInstructionIdSetEvalBranchQuota:
2130621565 case IrInstructionIdPtrType:
src/ir.hpp+5-5
......@@ -11,15 +11,15 @@
1111#include "all_types.hpp"
1212
1313bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
14bool ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);
14bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
1515
1616IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
17 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
18 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
17 ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
18 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
1919 IrExecutable *parent_exec);
2020
21TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
22 TypeTableEntry *expected_type, AstNode *expected_type_source_node);
21ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
22 ZigType *expected_type, AstNode *expected_type_source_node);
2323
2424bool ir_has_side_effects(IrInstruction *instruction);
2525ConstExprValue *const_ptr_pointee(CodeGen *codegen, ConstExprValue *const_val);
src/ir_print.cpp+11
......@@ -957,6 +957,14 @@ static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instructi
957957 fprintf(irp->f, ")");
958958}
959959
960static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {
961 fprintf(irp->f, "@checkRuntimeScope(");
962 ir_print_other_instruction(irp, instruction->scope_is_comptime);
963 fprintf(irp->f, ",");
964 ir_print_other_instruction(irp, instruction->is_comptime);
965 fprintf(irp->f, ")");
966}
967
960968static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
961969 fprintf(irp->f, "inttoerr ");
962970 ir_print_other_instruction(irp, instruction->target);
......@@ -1749,6 +1757,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
17491757 case IrInstructionIdEnumToInt:
17501758 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
17511759 break;
1760 case IrInstructionIdCheckRuntimeScope:
1761 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
1762 break;
17521763 }
17531764 fprintf(irp->f, "\n");
17541765}
src/link.cpp+3-3
......@@ -66,7 +66,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
6666 const char *o_ext = target_o_file_ext(&child_gen->zig_target);
6767 Buf *o_out_name = buf_sprintf("%s%s", oname, o_ext);
6868 Buf *output_path = buf_alloc();
69 os_path_join(parent_gen->cache_dir, o_out_name, output_path);
69 os_path_join(&parent_gen->cache_dir, o_out_name, output_path);
7070 codegen_link(child_gen, buf_ptr(output_path));
7171
7272 codegen_destroy(child_gen);
......@@ -587,11 +587,11 @@ static void construct_linker_job_coff(LinkJob *lj) {
587587 buf_appendf(def_contents, "\n");
588588
589589 Buf *def_path = buf_alloc();
590 os_path_join(g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
590 os_path_join(&g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
591591 os_write_file(def_path, def_contents);
592592
593593 Buf *generated_lib_path = buf_alloc();
594 os_path_join(g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
594 os_path_join(&g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
595595
596596 gen_lib_args.resize(0);
597597 gen_lib_args.append("link");
src/main.cpp+13-13
......@@ -374,25 +374,26 @@ int main(int argc, char **argv) {
374374 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
375375 codegen_set_out_name(g, buf_create_from_str("build"));
376376
377 Buf build_file_abs = BUF_INIT;
378 os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs);
377 Buf *build_file_buf = buf_create_from_str(build_file);
378 Buf build_file_abs = os_path_resolve(&build_file_buf, 1);
379379 Buf build_file_basename = BUF_INIT;
380380 Buf build_file_dirname = BUF_INIT;
381381 os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename);
382382
383 Buf *full_cache_dir = buf_alloc();
383 Buf full_cache_dir = BUF_INIT;
384384 if (cache_dir == nullptr) {
385 os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), full_cache_dir);
385 os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir);
386386 } else {
387 os_path_resolve(buf_create_from_str("."), buf_create_from_str(cache_dir), full_cache_dir);
387 Buf *cache_dir_buf = buf_create_from_str(cache_dir);
388 full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
388389 }
389390
390391 Buf *path_to_build_exe = buf_alloc();
391 os_path_join(full_cache_dir, buf_create_from_str("build"), path_to_build_exe);
392 os_path_join(&full_cache_dir, buf_create_from_str("build"), path_to_build_exe);
392393 codegen_set_cache_dir(g, full_cache_dir);
393394
394395 args.items[1] = buf_ptr(&build_file_dirname);
395 args.items[2] = buf_ptr(full_cache_dir);
396 args.items[2] = buf_ptr(&full_cache_dir);
396397
397398 bool build_file_exists;
398399 if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {
......@@ -789,7 +790,7 @@ int main(int argc, char **argv) {
789790
790791 Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;
791792
792 Buf *full_cache_dir = buf_alloc();
793 Buf full_cache_dir = BUF_INIT;
793794 Buf *run_exec_path = buf_alloc();
794795 if (cmd == CmdRun) {
795796 if (buf_out_name == nullptr) {
......@@ -799,13 +800,12 @@ int main(int argc, char **argv) {
799800 Buf *global_cache_dir = buf_alloc();
800801 os_get_global_cache_directory(global_cache_dir);
801802 os_path_join(global_cache_dir, buf_out_name, run_exec_path);
802 os_path_resolve(buf_create_from_str("."), global_cache_dir, full_cache_dir);
803 full_cache_dir = os_path_resolve(&global_cache_dir, 1);
803804
804805 out_file = buf_ptr(run_exec_path);
805806 } else {
806 os_path_resolve(buf_create_from_str("."),
807 buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir),
808 full_cache_dir);
807 Buf *resolve_paths = buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir);
808 full_cache_dir = os_path_resolve(&resolve_paths, 1);
809809 }
810810
811811 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
......@@ -937,7 +937,7 @@ int main(int argc, char **argv) {
937937
938938 Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target));
939939 Buf *test_exe_path = buf_alloc();
940 os_path_join(full_cache_dir, test_exe_name, test_exe_path);
940 os_path_join(&full_cache_dir, test_exe_name, test_exe_path);
941941
942942 for (size_t i = 0; i < test_exec_args.length; i += 1) {
943943 if (test_exec_args.items[i] == nullptr) {
src/os.cpp+499-29
......@@ -57,6 +57,54 @@ static clock_serv_t cclock;
5757#include <errno.h>
5858#include <time.h>
5959
60// Ported from std/mem.zig.
61// Coordinate struct fields with memSplit function
62struct SplitIterator {
63 size_t index;
64 Slice<uint8_t> buffer;
65 Slice<uint8_t> split_bytes;
66};
67
68// Ported from std/mem.zig.
69static bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) {
70 for (size_t i = 0; i < self->split_bytes.len; i += 1) {
71 if (byte == self->split_bytes.ptr[i]) {
72 return true;
73 }
74 }
75 return false;
76}
77
78// Ported from std/mem.zig.
79static Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) {
80 // move to beginning of token
81 while (self->index < self->buffer.len &&
82 SplitIterator_isSplitByte(self, self->buffer.ptr[self->index]))
83 {
84 self->index += 1;
85 }
86 size_t start = self->index;
87 if (start == self->buffer.len) {
88 return {};
89 }
90
91 // move to end of token
92 while (self->index < self->buffer.len &&
93 !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index]))
94 {
95 self->index += 1;
96 }
97 size_t end = self->index;
98
99 return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end));
100}
101
102// Ported from std/mem.zig
103static SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) {
104 return SplitIterator{0, buffer, split_bytes};
105}
106
107
60108#if defined(ZIG_OS_POSIX)
61109static void populate_termination(Termination *term, int status) {
62110 if (WIFEXITED(status)) {
......@@ -266,15 +314,31 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {
266314#endif
267315}
268316
269bool os_path_is_absolute(Buf *path) {
270317#if defined(ZIG_OS_WINDOWS)
271 if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\"))
318// Ported from std/os/path.zig
319static bool isAbsoluteWindows(Slice<uint8_t> path) {
320 if (path.ptr[0] == '/')
272321 return true;
273322
274 if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':')
323 if (path.ptr[0] == '\\') {
275324 return true;
276
325 }
326 if (path.len < 3) {
327 return false;
328 }
329 if (path.ptr[1] == ':') {
330 if (path.ptr[2] == '/')
331 return true;
332 if (path.ptr[2] == '\\')
333 return true;
334 }
277335 return false;
336}
337#endif
338
339bool os_path_is_absolute(Buf *path) {
340#if defined(ZIG_OS_WINDOWS)
341 return isAbsoluteWindows(buf_to_slice(path));
278342#elif defined(ZIG_OS_POSIX)
279343 return buf_ptr(path)[0] == '/';
280344#else
......@@ -282,14 +346,423 @@ bool os_path_is_absolute(Buf *path) {
282346#endif
283347}
284348
285void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path) {
286 if (os_path_is_absolute(target_path)) {
287 buf_init_from_buf(out_abs_path, target_path);
288 return;
349#if defined(ZIG_OS_WINDOWS)
350
351enum WindowsPathKind {
352 WindowsPathKindNone,
353 WindowsPathKindDrive,
354 WindowsPathKindNetworkShare,
355};
356
357struct WindowsPath {
358 Slice<uint8_t> disk_designator;
359 WindowsPathKind kind;
360 bool is_abs;
361};
362
363
364// Ported from std/os/path.zig
365static WindowsPath windowsParsePath(Slice<uint8_t> path) {
366 if (path.len >= 2 && path.ptr[1] == ':') {
367 return WindowsPath{
368 path.slice(0, 2),
369 WindowsPathKindDrive,
370 isAbsoluteWindows(path),
371 };
372 }
373 if (path.len >= 1 && (path.ptr[0] == '/' || path.ptr[0] == '\\') &&
374 (path.len == 1 || (path.ptr[1] != '/' && path.ptr[1] != '\\')))
375 {
376 return WindowsPath{
377 path.slice(0, 0),
378 WindowsPathKindNone,
379 true,
380 };
381 }
382 WindowsPath relative_path = {
383 str(""),
384 WindowsPathKindNone,
385 false,
386 };
387 if (path.len < strlen("//a/b")) {
388 return relative_path;
289389 }
290390
291 os_path_join(ref_path, target_path, out_abs_path);
292 return;
391 {
392 if (memStartsWith(path, str("//"))) {
393 if (path.ptr[2] == '/') {
394 return relative_path;
395 }
396
397 SplitIterator it = memSplit(path, str("/"));
398 {
399 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
400 if (!opt_component.is_some) return relative_path;
401 }
402 {
403 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
404 if (!opt_component.is_some) return relative_path;
405 }
406 return WindowsPath{
407 path.slice(0, it.index),
408 WindowsPathKindNetworkShare,
409 isAbsoluteWindows(path),
410 };
411 }
412 }
413 {
414 if (memStartsWith(path, str("\\\\"))) {
415 if (path.ptr[2] == '\\') {
416 return relative_path;
417 }
418
419 SplitIterator it = memSplit(path, str("\\"));
420 {
421 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
422 if (!opt_component.is_some) return relative_path;
423 }
424 {
425 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
426 if (!opt_component.is_some) return relative_path;
427 }
428 return WindowsPath{
429 path.slice(0, it.index),
430 WindowsPathKindNetworkShare,
431 isAbsoluteWindows(path),
432 };
433 }
434 }
435 return relative_path;
436}
437
438// Ported from std/os/path.zig
439static uint8_t asciiUpper(uint8_t byte) {
440 if (byte >= 'a' && byte <= 'z') {
441 return 'A' + (byte - 'a');
442 }
443 return byte;
444}
445
446// Ported from std/os/path.zig
447static bool asciiEqlIgnoreCase(Slice<uint8_t> s1, Slice<uint8_t> s2) {
448 if (s1.len != s2.len)
449 return false;
450 for (size_t i = 0; i < s1.len; i += 1) {
451 if (asciiUpper(s1.ptr[i]) != asciiUpper(s2.ptr[i]))
452 return false;
453 }
454 return true;
455}
456
457// Ported from std/os/path.zig
458static bool compareDiskDesignators(WindowsPathKind kind, Slice<uint8_t> p1, Slice<uint8_t> p2) {
459 switch (kind) {
460 case WindowsPathKindNone:
461 assert(p1.len == 0);
462 assert(p2.len == 0);
463 return true;
464 case WindowsPathKindDrive:
465 return asciiUpper(p1.ptr[0]) == asciiUpper(p2.ptr[0]);
466 case WindowsPathKindNetworkShare:
467 uint8_t sep1 = p1.ptr[0];
468 uint8_t sep2 = p2.ptr[0];
469
470 SplitIterator it1 = memSplit(p1, {&sep1, 1});
471 SplitIterator it2 = memSplit(p2, {&sep2, 1});
472
473 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
474 return asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value) &&
475 asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value);
476 }
477 zig_unreachable();
478}
479
480// Ported from std/os/path.zig
481static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) {
482 if (paths_len == 0) {
483 Buf cwd = BUF_INIT;
484 int err;
485 if ((err = os_get_cwd(&cwd))) {
486 zig_panic("get cwd failed");
487 }
488 return cwd;
489 }
490
491 // determine which disk designator we will result with, if any
492 char result_drive_buf[3] = {'_', ':', '\0'}; // 0 needed for strlen later
493 Slice<uint8_t> result_disk_designator = str("");
494 WindowsPathKind have_drive_kind = WindowsPathKindNone;
495 bool have_abs_path = false;
496 size_t first_index = 0;
497 size_t max_size = 0;
498 for (size_t i = 0; i < paths_len; i += 1) {
499 Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
500 WindowsPath parsed = windowsParsePath(p);
501 if (parsed.is_abs) {
502 have_abs_path = true;
503 first_index = i;
504 max_size = result_disk_designator.len;
505 }
506 switch (parsed.kind) {
507 case WindowsPathKindDrive:
508 result_drive_buf[0] = asciiUpper(parsed.disk_designator.ptr[0]);
509 result_disk_designator = str(result_drive_buf);
510 have_drive_kind = WindowsPathKindDrive;
511 break;
512 case WindowsPathKindNetworkShare:
513 result_disk_designator = parsed.disk_designator;
514 have_drive_kind = WindowsPathKindNetworkShare;
515 break;
516 case WindowsPathKindNone:
517 break;
518 }
519 max_size += p.len + 1;
520 }
521
522 // if we will result with a disk designator, loop again to determine
523 // which is the last time the disk designator is absolutely specified, if any
524 // and count up the max bytes for paths related to this disk designator
525 if (have_drive_kind != WindowsPathKindNone) {
526 have_abs_path = false;
527 first_index = 0;
528 max_size = result_disk_designator.len;
529 bool correct_disk_designator = false;
530
531 for (size_t i = 0; i < paths_len; i += 1) {
532 Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
533 WindowsPath parsed = windowsParsePath(p);
534 if (parsed.kind != WindowsPathKindNone) {
535 if (parsed.kind == have_drive_kind) {
536 correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
537 } else {
538 continue;
539 }
540 }
541 if (!correct_disk_designator) {
542 continue;
543 }
544 if (parsed.is_abs) {
545 first_index = i;
546 max_size = result_disk_designator.len;
547 have_abs_path = true;
548 }
549 max_size += p.len + 1;
550 }
551 }
552
553 // Allocate result and fill in the disk designator, calling getCwd if we have to.
554 Slice<uint8_t> result;
555 size_t result_index = 0;
556
557 if (have_abs_path) {
558 switch (have_drive_kind) {
559 case WindowsPathKindDrive: {
560 result = Slice<uint8_t>::alloc(max_size);
561
562 memCopy(result, result_disk_designator);
563 result_index += result_disk_designator.len;
564 break;
565 }
566 case WindowsPathKindNetworkShare: {
567 result = Slice<uint8_t>::alloc(max_size);
568 SplitIterator it = memSplit(buf_to_slice(paths_ptr[first_index]), str("/\\"));
569 Slice<uint8_t> server_name = SplitIterator_next(&it).value;
570 Slice<uint8_t> other_name = SplitIterator_next(&it).value;
571
572 result.ptr[result_index] = '\\';
573 result_index += 1;
574 result.ptr[result_index] = '\\';
575 result_index += 1;
576 memCopy(result.sliceFrom(result_index), server_name);
577 result_index += server_name.len;
578 result.ptr[result_index] = '\\';
579 result_index += 1;
580 memCopy(result.sliceFrom(result_index), other_name);
581 result_index += other_name.len;
582
583 result_disk_designator = result.slice(0, result_index);
584 break;
585 }
586 case WindowsPathKindNone: {
587 Buf cwd = BUF_INIT;
588 int err;
589 if ((err = os_get_cwd(&cwd))) {
590 zig_panic("get cwd failed");
591 }
592 WindowsPath parsed_cwd = windowsParsePath(buf_to_slice(&cwd));
593 result = Slice<uint8_t>::alloc(max_size + parsed_cwd.disk_designator.len + 1);
594 memCopy(result, parsed_cwd.disk_designator);
595 result_index += parsed_cwd.disk_designator.len;
596 result_disk_designator = result.slice(0, parsed_cwd.disk_designator.len);
597 if (parsed_cwd.kind == WindowsPathKindDrive) {
598 result.ptr[0] = asciiUpper(result.ptr[0]);
599 }
600 have_drive_kind = parsed_cwd.kind;
601 break;
602 }
603 }
604 } else {
605 // TODO call get cwd for the result_disk_designator instead of the global one
606 Buf cwd = BUF_INIT;
607 int err;
608 if ((err = os_get_cwd(&cwd))) {
609 zig_panic("get cwd failed");
610 }
611 result = Slice<uint8_t>::alloc(max_size + buf_len(&cwd) + 1);
612
613 memCopy(result, buf_to_slice(&cwd));
614 result_index += buf_len(&cwd);
615 WindowsPath parsed_cwd = windowsParsePath(result.slice(0, result_index));
616 result_disk_designator = parsed_cwd.disk_designator;
617 if (parsed_cwd.kind == WindowsPathKindDrive) {
618 result.ptr[0] = asciiUpper(result.ptr[0]);
619 }
620 have_drive_kind = parsed_cwd.kind;
621 }
622
623 // Now we know the disk designator to use, if any, and what kind it is. And our result
624 // is big enough to append all the paths to.
625 bool correct_disk_designator = true;
626 for (size_t i = 0; i < paths_len; i += 1) {
627 Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
628 WindowsPath parsed = windowsParsePath(p);
629
630 if (parsed.kind != WindowsPathKindNone) {
631 if (parsed.kind == have_drive_kind) {
632 correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
633 } else {
634 continue;
635 }
636 }
637 if (!correct_disk_designator) {
638 continue;
639 }
640 SplitIterator it = memSplit(p.sliceFrom(parsed.disk_designator.len), str("/\\"));
641 while (true) {
642 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
643 if (!opt_component.is_some) break;
644 Slice<uint8_t> component = opt_component.value;
645 if (memEql(component, str("."))) {
646 continue;
647 } else if (memEql(component, str(".."))) {
648 while (true) {
649 if (result_index == 0 || result_index == result_disk_designator.len)
650 break;
651 result_index -= 1;
652 if (result.ptr[result_index] == '\\' || result.ptr[result_index] == '/')
653 break;
654 }
655 } else {
656 result.ptr[result_index] = '\\';
657 result_index += 1;
658 memCopy(result.sliceFrom(result_index), component);
659 result_index += component.len;
660 }
661 }
662 }
663
664 if (result_index == result_disk_designator.len) {
665 result.ptr[result_index] = '\\';
666 result_index += 1;
667 }
668
669 Buf return_value = BUF_INIT;
670 buf_init_from_mem(&return_value, (char *)result.ptr, result_index);
671 return return_value;
672}
673#endif
674
675#if defined(ZIG_OS_POSIX)
676// Ported from std/os/path.zig
677static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
678 if (paths_len == 0) {
679 Buf cwd = BUF_INIT;
680 int err;
681 if ((err = os_get_cwd(&cwd))) {
682 zig_panic("get cwd failed");
683 }
684 return cwd;
685 }
686
687 size_t first_index = 0;
688 bool have_abs = false;
689 size_t max_size = 0;
690 for (size_t i = 0; i < paths_len; i += 1) {
691 Buf *p = paths_ptr[i];
692 if (os_path_is_absolute(p)) {
693 first_index = i;
694 have_abs = true;
695 max_size = 0;
696 }
697 max_size += buf_len(p) + 1;
698 }
699
700 uint8_t *result_ptr;
701 size_t result_len;
702 size_t result_index = 0;
703
704 if (have_abs) {
705 result_len = max_size;
706 result_ptr = allocate_nonzero<uint8_t>(result_len);
707 } else {
708 Buf cwd = BUF_INIT;
709 int err;
710 if ((err = os_get_cwd(&cwd))) {
711 zig_panic("get cwd failed");
712 }
713 result_len = max_size + buf_len(&cwd) + 1;
714 result_ptr = allocate_nonzero<uint8_t>(result_len);
715 memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));
716 result_index += buf_len(&cwd);
717 }
718
719 for (size_t i = first_index; i < paths_len; i += 1) {
720 Buf *p = paths_ptr[i];
721 SplitIterator it = memSplit(buf_to_slice(p), str("/"));
722 while (true) {
723 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
724 if (!opt_component.is_some) break;
725 Slice<uint8_t> component = opt_component.value;
726
727 if (memEql<uint8_t>(component, str("."))) {
728 continue;
729 } else if (memEql<uint8_t>(component, str(".."))) {
730 while (true) {
731 if (result_index == 0)
732 break;
733 result_index -= 1;
734 if (result_ptr[result_index] == '/')
735 break;
736 }
737 } else {
738 result_ptr[result_index] = '/';
739 result_index += 1;
740 memcpy(result_ptr + result_index, component.ptr, component.len);
741 result_index += component.len;
742 }
743 }
744 }
745
746 if (result_index == 0) {
747 result_ptr[0] = '/';
748 result_index += 1;
749 }
750
751 Buf return_value = BUF_INIT;
752 buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
753 return return_value;
754}
755#endif
756
757// Ported from std/os/path.zig
758Buf os_path_resolve(Buf **paths_ptr, size_t paths_len) {
759#if defined(ZIG_OS_WINDOWS)
760 return os_path_resolve_windows(paths_ptr, paths_len);
761#elif defined(ZIG_OS_POSIX)
762 return os_path_resolve_posix(paths_ptr, paths_len);
763#else
764#error "missing os_path_resolve implementation"
765#endif
293766}
294767
295768int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
......@@ -558,7 +1031,7 @@ int os_exec_process(const char *exe, ZigList<const char *> &args,
5581031void os_write_file(Buf *full_path, Buf *contents) {
5591032 FILE *f = fopen(buf_ptr(full_path), "wb");
5601033 if (!f) {
561 zig_panic("open failed");
1034 zig_panic("os_write_file failed for %s", buf_ptr(full_path));
5621035 }
5631036 size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f);
5641037 if (amt_written != (size_t)buf_len(contents))
......@@ -645,21 +1118,19 @@ int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
6451118
6461119int os_get_cwd(Buf *out_cwd) {
6471120#if defined(ZIG_OS_WINDOWS)
648 buf_resize(out_cwd, 4096);
649 if (GetCurrentDirectory(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) {
1121 char buf[4096];
1122 if (GetCurrentDirectory(4096, buf) == 0) {
6501123 zig_panic("GetCurrentDirectory failed");
6511124 }
1125 buf_init_from_str(out_cwd, buf);
6521126 return 0;
6531127#elif defined(ZIG_OS_POSIX)
654 int err = ERANGE;
655 buf_resize(out_cwd, 512);
656 while (err == ERANGE) {
657 buf_resize(out_cwd, buf_len(out_cwd) * 2);
658 err = getcwd(buf_ptr(out_cwd), buf_len(out_cwd)) ? 0 : errno;
1128 char buf[PATH_MAX];
1129 char *res = getcwd(buf, PATH_MAX);
1130 if (res == nullptr) {
1131 zig_panic("unable to get cwd: %s", strerror(errno));
6591132 }
660 if (err)
661 zig_panic("unable to get cwd: %s", strerror(err));
662
1133 buf_init_from_str(out_cwd, res);
6631134 return 0;
6641135#else
6651136#error "missing os_get_cwd implementation"
......@@ -898,21 +1369,20 @@ double os_get_time(void) {
8981369}
8991370
9001371int os_make_path(Buf *path) {
901 Buf *resolved_path = buf_alloc();
902 os_path_resolve(buf_create_from_str("."), path, resolved_path);
1372 Buf resolved_path = os_path_resolve(&path, 1);
9031373
904 size_t end_index = buf_len(resolved_path);
1374 size_t end_index = buf_len(&resolved_path);
9051375 int err;
9061376 while (true) {
907 if ((err = os_make_dir(buf_slice(resolved_path, 0, end_index)))) {
1377 if ((err = os_make_dir(buf_slice(&resolved_path, 0, end_index)))) {
9081378 if (err == ErrorPathAlreadyExists) {
909 if (end_index == buf_len(resolved_path))
1379 if (end_index == buf_len(&resolved_path))
9101380 return 0;
9111381 } else if (err == ErrorFileNotFound) {
9121382 // march end_index backward until next path component
9131383 while (true) {
9141384 end_index -= 1;
915 if (os_is_sep(buf_ptr(resolved_path)[end_index]))
1385 if (os_is_sep(buf_ptr(&resolved_path)[end_index]))
9161386 break;
9171387 }
9181388 continue;
......@@ -920,12 +1390,12 @@ int os_make_path(Buf *path) {
9201390 return err;
9211391 }
9221392 }
923 if (end_index == buf_len(resolved_path))
1393 if (end_index == buf_len(&resolved_path))
9241394 return 0;
9251395 // march end_index forward until next path component
9261396 while (true) {
9271397 end_index += 1;
928 if (end_index == buf_len(resolved_path) || os_is_sep(buf_ptr(resolved_path)[end_index]))
1398 if (end_index == buf_len(&resolved_path) || os_is_sep(buf_ptr(&resolved_path)[end_index]))
9291399 break;
9301400 }
9311401 }
src/os.hpp+1-1
......@@ -49,7 +49,7 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);
4949void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);
5050void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);
5151int os_path_real(Buf *rel_path, Buf *out_abs_path);
52void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path);
52Buf os_path_resolve(Buf **paths_ptr, size_t paths_len);
5353bool os_path_is_absolute(Buf *path);
5454
5555int os_get_global_cache_directory(Buf *out_tmp_path);
src/util.hpp+68
......@@ -186,4 +186,72 @@ static inline double zig_f16_to_double(float16_t x) {
186186 return z;
187187}
188188
189template<typename T>
190struct Optional {
191 T value;
192 bool is_some;
193
194 static inline Optional<T> some(T x) {
195 return {x, true};
196 }
197};
198
199template<typename T>
200struct Slice {
201 T *ptr;
202 size_t len;
203
204 inline Slice<T> slice(size_t start, size_t end) {
205 assert(end <= len);
206 assert(end >= start);
207 return {
208 ptr + start,
209 end - start,
210 };
211 }
212
213 inline Slice<T> sliceFrom(size_t start) {
214 assert(start <= len);
215 return {
216 ptr + start,
217 len - start,
218 };
219 }
220
221 static inline Slice<T> alloc(size_t n) {
222 return {allocate_nonzero<T>(n), n};
223 }
224};
225
226static inline Slice<uint8_t> str(const char *literal) {
227 return {(uint8_t*)(literal), strlen(literal)};
228}
229
230// Ported from std/mem.zig
231template<typename T>
232static inline bool memEql(Slice<T> a, Slice<T> b) {
233 if (a.len != b.len)
234 return false;
235 for (size_t i = 0; i < a.len; i += 1) {
236 if (a.ptr[i] != b.ptr[i])
237 return false;
238 }
239 return true;
240}
241
242// Ported from std/mem.zig
243template<typename T>
244static inline bool memStartsWith(Slice<T> haystack, Slice<T> needle) {
245 if (needle.len > haystack.len)
246 return false;
247 return memEql(haystack.slice(0, needle.len), needle);
248}
249
250// Ported from std/mem.zig
251template<typename T>
252static inline void memCopy(Slice<T> dest, Slice<T> src) {
253 assert(dest.len >= src.len);
254 memcpy(dest.ptr, src.ptr, src.len * sizeof(T));
255}
256
189257#endif
std/array_list.zig+27-2
......@@ -62,6 +62,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
6262 return self.len;
6363 }
6464
65 pub fn capacity(self: Self) usize {
66 return self.items.len;
67 }
68
6569 /// ArrayList takes ownership of the passed in slice. The slice must have been
6670 /// allocated with `allocator`.
6771 /// Deinitialize with `deinit` or use `toOwnedSlice`.
......@@ -102,6 +106,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
102106 new_item_ptr.* = item;
103107 }
104108
109 pub fn appendAssumeCapacity(self: *Self, item: T) void {
110 const new_item_ptr = self.addOneAssumeCapacity();
111 new_item_ptr.* = item;
112 }
113
105114 /// Removes the element at the specified index and returns it.
106115 /// The empty slot is filled from the end of the list.
107116 pub fn swapRemove(self: *Self, i: usize) T {
......@@ -138,7 +147,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
138147 }
139148
140149 pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {
141 var better_capacity = self.items.len;
150 var better_capacity = self.capacity();
142151 if (better_capacity >= new_capacity) return;
143152 while (true) {
144153 better_capacity += better_capacity / 2 + 8;
......@@ -150,8 +159,13 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
150159 pub fn addOne(self: *Self) !*T {
151160 const new_length = self.len + 1;
152161 try self.ensureCapacity(new_length);
162 return self.addOneAssumeCapacity();
163 }
164
165 pub fn addOneAssumeCapacity(self: *Self) *T {
166 assert(self.count() < self.capacity());
153167 const result = &self.items[self.len];
154 self.len = new_length;
168 self.len += 1;
155169 return result;
156170 }
157171
......@@ -191,6 +205,17 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
191205 };
192206}
193207
208test "std.ArrayList.init" {
209 var bytes: [1024]u8 = undefined;
210 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
211
212 var list = ArrayList(i32).init(allocator);
213 defer list.deinit();
214
215 assert(list.count() == 0);
216 assert(list.capacity() == 0);
217}
218
194219test "std.ArrayList.basic" {
195220 var bytes: [1024]u8 = undefined;
196221 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
std/build.zig+27
......@@ -48,6 +48,12 @@ pub const Builder = struct {
4848 cache_root: []const u8,
4949 release_mode: ?builtin.Mode,
5050
51 pub const CStd = enum {
52 C89,
53 C99,
54 C11,
55 };
56
5157 const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
5258 const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
5359
......@@ -817,6 +823,7 @@ pub const LibExeObjStep = struct {
817823 frameworks: BufSet,
818824 verbose_link: bool,
819825 no_rosegment: bool,
826 c_std: Builder.CStd,
820827
821828 // zig only stuff
822829 root_src: ?[]const u8,
......@@ -918,6 +925,7 @@ pub const LibExeObjStep = struct {
918925 .object_src = undefined,
919926 .disable_libc = true,
920927 .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
928 .c_std = Builder.CStd.C99,
921929 };
922930 self.computeOutFileNames();
923931 return self;
......@@ -952,6 +960,7 @@ pub const LibExeObjStep = struct {
952960 .disable_libc = false,
953961 .is_zig = false,
954962 .linker_script = null,
963 .c_std = Builder.CStd.C99,
955964
956965 .root_src = undefined,
957966 .verbose_link = false,
......@@ -1392,6 +1401,13 @@ pub const LibExeObjStep = struct {
13921401
13931402 const is_darwin = self.target.isDarwin();
13941403
1404 const c_std_arg = switch (self.c_std) {
1405 Builder.CStd.C89 => "-std=c89",
1406 Builder.CStd.C99 => "-std=c99",
1407 Builder.CStd.C11 => "-std=c11",
1408 };
1409 try cc_args.append(c_std_arg);
1410
13951411 switch (self.kind) {
13961412 Kind.Obj => {
13971413 cc_args.append("-c") catch unreachable;
......@@ -1678,6 +1694,17 @@ pub const TestStep = struct {
16781694 self.filter = text;
16791695 }
16801696
1697 pub fn addObject(self: *TestStep, obj: *LibExeObjStep) void {
1698 assert(obj.kind == LibExeObjStep.Kind.Obj);
1699
1700 self.step.dependOn(&obj.step);
1701
1702 self.object_files.append(obj.getOutputPath()) catch unreachable;
1703
1704 // TODO should be some kind of isolated directory that only has this header in it
1705 self.include_dirs.append(self.builder.cache_root) catch unreachable;
1706 }
1707
16811708 pub fn addObjectFile(self: *TestStep, path: []const u8) void {
16821709 self.object_files.append(path) catch unreachable;
16831710 }
std/crypto/throughput_test.zig+1-1
......@@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void {
130130
131131pub fn main() !void {
132132 var stdout_file = try std.io.getStdOut();
133 var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
133 var stdout_out_stream = std.io.FileOutStream.init(stdout_file);
134134 const stdout = &stdout_out_stream.stream;
135135
136136 var buffer: [1024]u8 = undefined;
std/crypto/x25519.zig+12-1
......@@ -4,6 +4,7 @@
44
55const std = @import("../index.zig");
66const builtin = @import("builtin");
7const fmt = std.fmt;
78
89const Endian = builtin.Endian;
910const readInt = std.mem.readInt;
......@@ -114,7 +115,7 @@ pub const X25519 = struct {
114115 return !zerocmp(u8, out);
115116 }
116117
117 pub fn createPublicKey(public_key: []const u8, private_key: []const u8) bool {
118 pub fn createPublicKey(public_key: [] u8, private_key: []const u8) bool {
118119 var base_point = []u8{9} ++ []u8{0} ** 31;
119120 return create(public_key, private_key, base_point);
120121 }
......@@ -573,6 +574,16 @@ const Fe = struct {
573574 }
574575};
575576
577test "x25519 public key calculation from secret key" {
578 var sk: [32]u8 = undefined;
579 var pk_expected: [32]u8 = undefined;
580 var pk_calculated: [32]u8 = undefined;
581 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
582 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
583 std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk));
584 std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected));
585}
586
576587test "x25519 rfc7748 vector1" {
577588 const secret_key = "\xa5\x46\xe3\x6b\xf0\x52\x7c\x9d\x3b\x16\x15\x4b\x82\x46\x5e\xdd\x62\x14\x4c\x0a\xc1\xfc\x5a\x18\x50\x6a\x22\x44\xba\x44\x9a\xc4";
578589 const public_key = "\xe6\xdb\x68\x67\x58\x30\x30\xdb\x35\x94\xc1\xa4\x24\xb1\x5f\x7c\x72\x66\x24\xec\x26\xb3\x35\x3b\x10\xa9\x03\xa6\xd0\xab\x1c\x4c";
test/behavior.zig+1-1
......@@ -9,12 +9,12 @@ comptime {
99 _ = @import("cases/bitcast.zig");
1010 _ = @import("cases/bool.zig");
1111 _ = @import("cases/bugs/1111.zig");
12 _ = @import("cases/bugs/1230.zig");
1312 _ = @import("cases/bugs/1277.zig");
1413 _ = @import("cases/bugs/1421.zig");
1514 _ = @import("cases/bugs/394.zig");
1615 _ = @import("cases/bugs/655.zig");
1716 _ = @import("cases/bugs/656.zig");
17 _ = @import("cases/bugs/726.zig");
1818 _ = @import("cases/bugs/828.zig");
1919 _ = @import("cases/bugs/920.zig");
2020 _ = @import("cases/byval_arg_var.zig");
test/build_examples.zig+6
......@@ -28,4 +28,10 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {
2828 // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it
2929 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");
3030 }
31
32 if (!is_windows // TODO support compiling C files on windows with zig build system
33 and builtin.arch == builtin.Arch.x86_64 // TODO add C ABI support for other architectures
34 ) {
35 cases.addBuildFile("test/stage1/c_abi/build.zig");
36 }
3137}
test/cases/bugs/1230.zig deleted-14
......@@ -1,14 +0,0 @@
1const assert = @import("std").debug.assert;
2
3const S = extern struct {
4 x: i32,
5};
6
7extern fn ret_struct() S {
8 return S{ .x = 42 };
9}
10
11test "extern return small struct (bug 1230)" {
12 const s = ret_struct();
13 assert(s.x == 42);
14}
test/cases/bugs/726.zig created+16
......@@ -0,0 +1,16 @@
1const assert = @import("std").debug.assert;
2
3test "@ptrCast from const to nullable" {
4 const c: u8 = 4;
5 var x: ?*const u8 = @ptrCast(?*const u8, &c);
6 assert(x.?.* == 4);
7}
8
9test "@ptrCast from var in empty struct to nullable" {
10 const container = struct {
11 var c: u8 = 4;
12 };
13 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
14 assert(x.?.* == 4);
15}
16
test/cases/cast.zig+1
......@@ -356,6 +356,7 @@ fn testFloatToInts() void {
356356 expectFloatToInt(f32, 255.1, u8, 255);
357357 expectFloatToInt(f32, 127.2, i8, 127);
358358 expectFloatToInt(f32, -128.2, i8, -128);
359 expectFloatToInt(comptime_int, 1234, i16, 1234);
359360}
360361
361362fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
test/cases/eval.zig+8
......@@ -674,3 +674,11 @@ test "inline for with same type but different values" {
674674 }
675675 assert(res == 5);
676676}
677
678test "refer to the type of a generic function" {
679 const Func = fn (type) void;
680 const f: Func = doNothingWithType;
681 f(i32);
682}
683
684fn doNothingWithType(comptime T: type) void {}
test/cases/fn.zig+15
......@@ -176,3 +176,18 @@ test "pass by non-copying value as method, at comptime" {
176176 assert(pt.addPointCoords() == 3);
177177 }
178178}
179
180fn outer(y: u32) fn (u32) u32 {
181 const Y = @typeOf(y);
182 const st = struct {
183 fn get(z: u32) u32 {
184 return z + @sizeOf(Y);
185 }
186 };
187 return st.get;
188}
189
190test "return inner function which references comptime variable of outer function" {
191 var func = outer(10);
192 assert(func(3) == 7);
193}
test/cases/union.zig+13
......@@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool {
311311 const y = TaggedUnionWithAVoid{ .A = x };
312312 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
313313}
314
315pub const UnionEnumNoPayloads = union(enum) {
316 A,
317 B,
318};
319
320test "tagged union with no payloads" {
321 const a = UnionEnumNoPayloads{ .B = {} };
322 switch (a) {
323 @TagType(UnionEnumNoPayloads).A => @panic("wrong"),
324 @TagType(UnionEnumNoPayloads).B => {},
325 }
326}
test/compile_errors.zig+222-9
......@@ -1,6 +1,228 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "variable initialization compile error then referenced",
6 \\fn Undeclared() type {
7 \\ return T;
8 \\}
9 \\fn Gen() type {
10 \\ const X = Undeclared();
11 \\ return struct {
12 \\ x: X,
13 \\ };
14 \\}
15 \\export fn entry() void {
16 \\ const S = Gen();
17 \\}
18 ,
19 ".tmp_source.zig:2:12: error: use of undeclared identifier 'T'",
20 );
21
22 cases.add(
23 "refer to the type of a generic function",
24 \\export fn entry() void {
25 \\ const Func = fn (type) void;
26 \\ const f: Func = undefined;
27 \\ f(i32);
28 \\}
29 ,
30 ".tmp_source.zig:4:5: error: use of undefined value",
31 );
32
33 cases.add(
34 "accessing runtime parameter from outer function",
35 \\fn outer(y: u32) fn (u32) u32 {
36 \\ const st = struct {
37 \\ fn get(z: u32) u32 {
38 \\ return z + y;
39 \\ }
40 \\ };
41 \\ return st.get;
42 \\}
43 \\export fn entry() void {
44 \\ var func = outer(10);
45 \\ var x = func(3);
46 \\}
47 ,
48 ".tmp_source.zig:4:24: error: 'y' not accessible from inner function",
49 ".tmp_source.zig:3:28: note: crossed function definition here",
50 ".tmp_source.zig:1:10: note: declared here",
51 );
52
53 cases.add(
54 "non int passed to @intToFloat",
55 \\export fn entry() void {
56 \\ const x = @intToFloat(f32, 1.1);
57 \\}
58 ,
59 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
60 );
61
62 cases.add(
63 "non float passed to @floatToInt",
64 \\export fn entry() void {
65 \\ const x = @floatToInt(i32, i32(54));
66 \\}
67 ,
68 ".tmp_source.zig:2:35: error: expected float type, found 'i32'",
69 );
70
71 cases.add(
72 "out of range comptime_int passed to @floatToInt",
73 \\export fn entry() void {
74 \\ const x = @floatToInt(i8, 200);
75 \\}
76 ,
77 ".tmp_source.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
78 );
79
80 cases.add(
81 "load too many bytes from comptime reinterpreted pointer",
82 \\export fn entry() void {
83 \\ const float: f32 = 5.99999999999994648725e-01;
84 \\ const float_ptr = &float;
85 \\ const int_ptr = @ptrCast(*const i64, float_ptr);
86 \\ const int_val = int_ptr.*;
87 \\}
88 ,
89 ".tmp_source.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes",
90 );
91
92 cases.add(
93 "invalid type used in array type",
94 \\const Item = struct {
95 \\ field: SomeNonexistentType,
96 \\};
97 \\var items: [100]Item = undefined;
98 \\export fn entry() void {
99 \\ const a = items[0];
100 \\}
101 ,
102 ".tmp_source.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
103 );
104
105 cases.add(
106 "@noInlineCall on an inline function",
107 \\inline fn foo() void {}
108 \\
109 \\export fn entry() void {
110 \\ @noInlineCall(foo);
111 \\}
112 ,
113 ".tmp_source.zig:4:5: error: no-inline call of inline function",
114 );
115
116 cases.add(
117 "comptime continue inside runtime switch",
118 \\export fn entry() void {
119 \\ var p: i32 = undefined;
120 \\ comptime var q = true;
121 \\ inline while (q) {
122 \\ switch (p) {
123 \\ 11 => continue,
124 \\ else => {},
125 \\ }
126 \\ q = false;
127 \\ }
128 \\}
129 ,
130 ".tmp_source.zig:6:19: error: comptime control flow inside runtime block",
131 ".tmp_source.zig:5:9: note: runtime block created here",
132 );
133
134 cases.add(
135 "comptime continue inside runtime while error",
136 \\export fn entry() void {
137 \\ var p: error!usize = undefined;
138 \\ comptime var q = true;
139 \\ outer: inline while (q) {
140 \\ while (p) |_| {
141 \\ continue :outer;
142 \\ } else |_| {}
143 \\ q = false;
144 \\ }
145 \\}
146 ,
147 ".tmp_source.zig:6:13: error: comptime control flow inside runtime block",
148 ".tmp_source.zig:5:9: note: runtime block created here",
149 );
150
151 cases.add(
152 "comptime continue inside runtime while optional",
153 \\export fn entry() void {
154 \\ var p: ?usize = undefined;
155 \\ comptime var q = true;
156 \\ outer: inline while (q) {
157 \\ while (p) |_| continue :outer;
158 \\ q = false;
159 \\ }
160 \\}
161 ,
162 ".tmp_source.zig:5:23: error: comptime control flow inside runtime block",
163 ".tmp_source.zig:5:9: note: runtime block created here",
164 );
165
166 cases.add(
167 "comptime continue inside runtime while bool",
168 \\export fn entry() void {
169 \\ var p: usize = undefined;
170 \\ comptime var q = true;
171 \\ outer: inline while (q) {
172 \\ while (p == 11) continue :outer;
173 \\ q = false;
174 \\ }
175 \\}
176 ,
177 ".tmp_source.zig:5:25: error: comptime control flow inside runtime block",
178 ".tmp_source.zig:5:9: note: runtime block created here",
179 );
180
181 cases.add(
182 "comptime continue inside runtime if error",
183 \\export fn entry() void {
184 \\ var p: error!i32 = undefined;
185 \\ comptime var q = true;
186 \\ inline while (q) {
187 \\ if (p) |_| continue else |_| {}
188 \\ q = false;
189 \\ }
190 \\}
191 ,
192 ".tmp_source.zig:5:20: error: comptime control flow inside runtime block",
193 ".tmp_source.zig:5:9: note: runtime block created here",
194 );
195
196 cases.add(
197 "comptime continue inside runtime if optional",
198 \\export fn entry() void {
199 \\ var p: ?i32 = undefined;
200 \\ comptime var q = true;
201 \\ inline while (q) {
202 \\ if (p) |_| continue;
203 \\ q = false;
204 \\ }
205 \\}
206 ,
207 ".tmp_source.zig:5:20: error: comptime control flow inside runtime block",
208 ".tmp_source.zig:5:9: note: runtime block created here",
209 );
210
211 cases.add(
212 "comptime continue inside runtime if bool",
213 \\export fn entry() void {
214 \\ var p: usize = undefined;
215 \\ comptime var q = true;
216 \\ inline while (q) {
217 \\ if (p == 11) continue;
218 \\ q = false;
219 \\ }
220 \\}
221 ,
222 ".tmp_source.zig:5:22: error: comptime control flow inside runtime block",
223 ".tmp_source.zig:5:9: note: runtime block created here",
224 );
225
4226 cases.add(
5227 "switch with invalid expression parameter",
6228 \\export fn entry() void {
......@@ -340,15 +562,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
340562 ".tmp_source.zig:2:20: error: return type cannot be opaque",
341563 );
342564
343 cases.add(
344 "non int passed to @intToFloat",
345 \\export fn entry() void {
346 \\ const x = @intToFloat(f32, 1.1);
347 \\}
348 ,
349 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
350 );
351
352565 cases.add(
353566 "use implicit casts to assign null to non-nullable pointer",
354567 \\export fn entry() void {
test/gen_h.zig+24-4
......@@ -20,6 +20,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
2020 \\ A: i32,
2121 \\ B: f32,
2222 \\ C: bool,
23 \\ D: u64,
24 \\ E: u64,
25 \\ F: u64,
2326 \\};
2427 \\export fn entry(foo: Foo) void { }
2528 ,
......@@ -27,6 +30,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
2730 \\ int32_t A;
2831 \\ float B;
2932 \\ bool C;
33 \\ uint64_t D;
34 \\ uint64_t E;
35 \\ uint64_t F;
3036 \\};
3137 \\
3238 \\TEST_EXPORT void entry(struct Foo foo);
......@@ -34,17 +40,34 @@ pub fn addCases(cases: *tests.GenHContext) void {
3440 );
3541
3642 cases.add("declare union",
43 \\const Big = extern struct {
44 \\ A: u64,
45 \\ B: u64,
46 \\ C: u64,
47 \\ D: u64,
48 \\ E: u64,
49 \\};
3750 \\const Foo = extern union {
3851 \\ A: i32,
3952 \\ B: f32,
4053 \\ C: bool,
54 \\ D: Big,
4155 \\};
42 \\export fn entry(foo: Foo) void { }
56 \\export fn entry(foo: Foo) void {}
4357 ,
58 \\struct Big {
59 \\ uint64_t A;
60 \\ uint64_t B;
61 \\ uint64_t C;
62 \\ uint64_t D;
63 \\ uint64_t E;
64 \\};
65 \\
4466 \\union Foo {
4567 \\ int32_t A;
4668 \\ float B;
4769 \\ bool C;
70 \\ struct Big D;
4871 \\};
4972 \\
5073 \\TEST_EXPORT void entry(union Foo foo);
......@@ -85,7 +108,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
85108 \\export fn a(s: *S) u8 {
86109 \\ return s.a;
87110 \\}
88
89111 ,
90112 \\struct S;
91113 \\TEST_EXPORT uint8_t a(struct S * s);
......@@ -101,7 +123,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
101123 \\export fn a(s: *U) u8 {
102124 \\ return s.A;
103125 \\}
104
105126 ,
106127 \\union U;
107128 \\TEST_EXPORT uint8_t a(union U * s);
......@@ -117,7 +138,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
117138 \\export fn a(s: *E) u8 {
118139 \\ return @enumToInt(s.*);
119140 \\}
120
121141 ,
122142 \\enum E;
123143 \\TEST_EXPORT uint8_t a(enum E * s);
test/stage1/c_abi/build.zig created+18
......@@ -0,0 +1,18 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: *Builder) void {
4 const rel_opts = b.standardReleaseOptions();
5
6 const c_obj = b.addCObject("cfuncs", "cfuncs.c");
7 c_obj.setBuildMode(rel_opts);
8 c_obj.setNoStdLib(true);
9
10 const main = b.addTest("main.zig");
11 main.setBuildMode(rel_opts);
12 main.addObject(c_obj);
13
14 const test_step = b.step("test", "Test the program");
15 test_step.dependOn(&main.step);
16
17 b.default_step.dependOn(test_step);
18}
test/stage1/c_abi/cfuncs.c created+208
......@@ -0,0 +1,208 @@
1#include <inttypes.h>
2#include <stdlib.h>
3#include <stdbool.h>
4
5void zig_panic();
6
7static void assert_or_panic(bool ok) {
8 if (!ok) {
9 zig_panic();
10 }
11}
12
13void zig_u8(uint8_t);
14void zig_u16(uint16_t);
15void zig_u32(uint32_t);
16void zig_u64(uint64_t);
17void zig_i8(int8_t);
18void zig_i16(int16_t);
19void zig_i32(int32_t);
20void zig_i64(int64_t);
21
22void zig_f32(float);
23void zig_f64(double);
24
25void zig_ptr(void *);
26
27void zig_bool(bool);
28
29void zig_array(uint8_t[10]);
30
31struct BigStruct {
32 uint64_t a;
33 uint64_t b;
34 uint64_t c;
35 uint64_t d;
36 uint8_t e;
37};
38
39void zig_big_struct(struct BigStruct);
40
41union BigUnion {
42 struct BigStruct a;
43};
44
45void zig_big_union(union BigUnion);
46
47struct SmallStructInts {
48 uint8_t a;
49 uint8_t b;
50 uint8_t c;
51 uint8_t d;
52};
53void zig_small_struct_ints(struct SmallStructInts);
54
55struct SplitStructInts {
56 uint64_t a;
57 uint8_t b;
58 uint32_t c;
59};
60void zig_split_struct_ints(struct SplitStructInts);
61
62struct BigStruct zig_big_struct_both(struct BigStruct);
63
64void run_c_tests(void) {
65 zig_u8(0xff);
66 zig_u16(0xfffe);
67 zig_u32(0xfffffffd);
68 zig_u64(0xfffffffffffffffc);
69
70 zig_i8(-1);
71 zig_i16(-2);
72 zig_i32(-3);
73 zig_i64(-4);
74
75 zig_f32(12.34f);
76 zig_f64(56.78);
77
78 zig_ptr((void*)0xdeadbeefL);
79
80 zig_bool(true);
81
82 uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
83 zig_array(array);
84
85 {
86 struct BigStruct s = {1, 2, 3, 4, 5};
87 zig_big_struct(s);
88 }
89
90 {
91 struct SmallStructInts s = {1, 2, 3, 4};
92 zig_small_struct_ints(s);
93 }
94
95 {
96 struct SplitStructInts s = {1234, 100, 1337};
97 zig_split_struct_ints(s);
98 }
99
100 {
101 struct BigStruct s = {30, 31, 32, 33, 34};
102 struct BigStruct res = zig_big_struct_both(s);
103 assert_or_panic(res.a == 20);
104 assert_or_panic(res.b == 21);
105 assert_or_panic(res.c == 22);
106 assert_or_panic(res.d == 23);
107 assert_or_panic(res.e == 24);
108 }
109}
110
111void c_u8(uint8_t x) {
112 assert_or_panic(x == 0xff);
113}
114
115void c_u16(uint16_t x) {
116 assert_or_panic(x == 0xfffe);
117}
118
119void c_u32(uint32_t x) {
120 assert_or_panic(x == 0xfffffffd);
121}
122
123void c_u64(uint64_t x) {
124 assert_or_panic(x == 0xfffffffffffffffcULL);
125}
126
127void c_i8(int8_t x) {
128 assert_or_panic(x == -1);
129}
130
131void c_i16(int16_t x) {
132 assert_or_panic(x == -2);
133}
134
135void c_i32(int32_t x) {
136 assert_or_panic(x == -3);
137}
138
139void c_i64(int64_t x) {
140 assert_or_panic(x == -4);
141}
142
143void c_f32(float x) {
144 assert_or_panic(x == 12.34f);
145}
146
147void c_f64(double x) {
148 assert_or_panic(x == 56.78);
149}
150
151void c_ptr(void *x) {
152 assert_or_panic(x == (void*)0xdeadbeefL);
153}
154
155void c_bool(bool x) {
156 assert_or_panic(x);
157}
158
159void c_array(uint8_t x[10]) {
160 assert_or_panic(x[0] == '1');
161 assert_or_panic(x[1] == '2');
162 assert_or_panic(x[2] == '3');
163 assert_or_panic(x[3] == '4');
164 assert_or_panic(x[4] == '5');
165 assert_or_panic(x[5] == '6');
166 assert_or_panic(x[6] == '7');
167 assert_or_panic(x[7] == '8');
168 assert_or_panic(x[8] == '9');
169 assert_or_panic(x[9] == '0');
170}
171
172void c_big_struct(struct BigStruct x) {
173 assert_or_panic(x.a == 1);
174 assert_or_panic(x.b == 2);
175 assert_or_panic(x.c == 3);
176 assert_or_panic(x.d == 4);
177 assert_or_panic(x.e == 5);
178}
179
180void c_big_union(union BigUnion x) {
181 assert_or_panic(x.a.a == 1);
182 assert_or_panic(x.a.b == 2);
183 assert_or_panic(x.a.c == 3);
184 assert_or_panic(x.a.d == 4);
185}
186
187void c_small_struct_ints(struct SmallStructInts x) {
188 assert_or_panic(x.a == 1);
189 assert_or_panic(x.b == 2);
190 assert_or_panic(x.c == 3);
191 assert_or_panic(x.d == 4);
192}
193
194void c_split_struct_ints(struct SplitStructInts x) {
195 assert_or_panic(x.a == 1234);
196 assert_or_panic(x.b == 100);
197 assert_or_panic(x.c == 1337);
198}
199
200struct BigStruct c_big_struct_both(struct BigStruct x) {
201 assert_or_panic(x.a == 1);
202 assert_or_panic(x.b == 2);
203 assert_or_panic(x.c == 3);
204 assert_or_panic(x.d == 4);
205 assert_or_panic(x.e == 5);
206 struct BigStruct y = {10, 11, 12, 13, 14};
207 return y;
208}
test/stage1/c_abi/main.zig created+239
......@@ -0,0 +1,239 @@
1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
3
4extern fn run_c_tests() void;
5
6export fn zig_panic() noreturn {
7 @panic("zig_panic called from C");
8}
9
10test "C importing Zig ABI Tests" {
11 run_c_tests();
12}
13
14extern fn c_u8(u8) void;
15extern fn c_u16(u16) void;
16extern fn c_u32(u32) void;
17extern fn c_u64(u64) void;
18extern fn c_i8(i8) void;
19extern fn c_i16(i16) void;
20extern fn c_i32(i32) void;
21extern fn c_i64(i64) void;
22
23test "C ABI integers" {
24 c_u8(0xff);
25 c_u16(0xfffe);
26 c_u32(0xfffffffd);
27 c_u64(0xfffffffffffffffc);
28
29 c_i8(-1);
30 c_i16(-2);
31 c_i32(-3);
32 c_i64(-4);
33}
34
35export fn zig_u8(x: u8) void {
36 assertOrPanic(x == 0xff);
37}
38export fn zig_u16(x: u16) void {
39 assertOrPanic(x == 0xfffe);
40}
41export fn zig_u32(x: u32) void {
42 assertOrPanic(x == 0xfffffffd);
43}
44export fn zig_u64(x: u64) void {
45 assertOrPanic(x == 0xfffffffffffffffc);
46}
47export fn zig_i8(x: i8) void {
48 assertOrPanic(x == -1);
49}
50export fn zig_i16(x: i16) void {
51 assertOrPanic(x == -2);
52}
53export fn zig_i32(x: i32) void {
54 assertOrPanic(x == -3);
55}
56export fn zig_i64(x: i64) void {
57 assertOrPanic(x == -4);
58}
59
60extern fn c_f32(f32) void;
61extern fn c_f64(f64) void;
62
63test "C ABI floats" {
64 c_f32(12.34);
65 c_f64(56.78);
66}
67
68export fn zig_f32(x: f32) void {
69 assertOrPanic(x == 12.34);
70}
71export fn zig_f64(x: f64) void {
72 assertOrPanic(x == 56.78);
73}
74
75extern fn c_ptr(*c_void) void;
76
77test "C ABI pointer" {
78 c_ptr(@intToPtr(*c_void, 0xdeadbeef));
79}
80
81export fn zig_ptr(x: *c_void) void {
82 assertOrPanic(@ptrToInt(x) == 0xdeadbeef);
83}
84
85extern fn c_bool(bool) void;
86
87test "C ABI bool" {
88 c_bool(true);
89}
90
91export fn zig_bool(x: bool) void {
92 assertOrPanic(x);
93}
94
95extern fn c_array([10]u8) void;
96
97test "C ABI array" {
98 var array: [10]u8 = "1234567890";
99 c_array(array);
100}
101
102export fn zig_array(x: [10]u8) void {
103 assertOrPanic(std.mem.eql(u8, x, "1234567890"));
104}
105
106const BigStruct = extern struct {
107 a: u64,
108 b: u64,
109 c: u64,
110 d: u64,
111 e: u8,
112};
113extern fn c_big_struct(BigStruct) void;
114
115test "C ABI big struct" {
116 var s = BigStruct{
117 .a = 1,
118 .b = 2,
119 .c = 3,
120 .d = 4,
121 .e = 5,
122 };
123 c_big_struct(s);
124}
125
126export fn zig_big_struct(x: BigStruct) void {
127 assertOrPanic(x.a == 1);
128 assertOrPanic(x.b == 2);
129 assertOrPanic(x.c == 3);
130 assertOrPanic(x.d == 4);
131 assertOrPanic(x.e == 5);
132}
133
134const BigUnion = extern union {
135 a: BigStruct,
136};
137extern fn c_big_union(BigUnion) void;
138
139test "C ABI big union" {
140 var x = BigUnion{
141 .a = BigStruct{
142 .a = 1,
143 .b = 2,
144 .c = 3,
145 .d = 4,
146 .e = 5,
147 },
148 };
149 c_big_union(x);
150}
151
152export fn zig_big_union(x: BigUnion) void {
153 assertOrPanic(x.a.a == 1);
154 assertOrPanic(x.a.b == 2);
155 assertOrPanic(x.a.c == 3);
156 assertOrPanic(x.a.d == 4);
157 assertOrPanic(x.a.e == 5);
158}
159
160const SmallStructInts = extern struct {
161 a: u8,
162 b: u8,
163 c: u8,
164 d: u8,
165};
166extern fn c_small_struct_ints(SmallStructInts) void;
167
168test "C ABI small struct of ints" {
169 var s = SmallStructInts{
170 .a = 1,
171 .b = 2,
172 .c = 3,
173 .d = 4,
174 };
175 c_small_struct_ints(s);
176}
177
178export fn zig_small_struct_ints(x: SmallStructInts) void {
179 assertOrPanic(x.a == 1);
180 assertOrPanic(x.b == 2);
181 assertOrPanic(x.c == 3);
182 assertOrPanic(x.d == 4);
183}
184
185const SplitStructInt = extern struct {
186 a: u64,
187 b: u8,
188 c: u32,
189};
190extern fn c_split_struct_ints(SplitStructInt) void;
191
192test "C ABI split struct of ints" {
193 var s = SplitStructInt{
194 .a = 1234,
195 .b = 100,
196 .c = 1337,
197 };
198 c_split_struct_ints(s);
199}
200
201export fn zig_split_struct_ints(x: SplitStructInt) void {
202 assertOrPanic(x.a == 1234);
203 assertOrPanic(x.b == 100);
204 assertOrPanic(x.c == 1337);
205}
206
207extern fn c_big_struct_both(BigStruct) BigStruct;
208
209test "C ABI sret and byval together" {
210 var s = BigStruct{
211 .a = 1,
212 .b = 2,
213 .c = 3,
214 .d = 4,
215 .e = 5,
216 };
217 var y = c_big_struct_both(s);
218 assertOrPanic(y.a == 10);
219 assertOrPanic(y.b == 11);
220 assertOrPanic(y.c == 12);
221 assertOrPanic(y.d == 13);
222 assertOrPanic(y.e == 14);
223}
224
225export fn zig_big_struct_both(x: BigStruct) BigStruct {
226 assertOrPanic(x.a == 30);
227 assertOrPanic(x.b == 31);
228 assertOrPanic(x.c == 32);
229 assertOrPanic(x.d == 33);
230 assertOrPanic(x.e == 34);
231 var s = BigStruct{
232 .a = 20,
233 .b = 21,
234 .c = 22,
235 .d = 23,
236 .e = 24,
237 };
238 return s;
239}