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()...@@ -199,7 +199,7 @@ else()
199 if(MSVC)199 if(MSVC)
200 set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -D_CRT_SECURE_NO_WARNINGS /w")200 set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -D_CRT_SECURE_NO_WARNINGS /w")
201 else()201 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")
203 endif()203 endif()
204 set_target_properties(embedded_lld_lib PROPERTIES204 set_target_properties(embedded_lld_lib PROPERTIES
205 COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS}205 COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS}
...@@ -775,20 +775,25 @@ include_directories(...@@ -775,20 +775,25 @@ include_directories(
775 "${CMAKE_SOURCE_DIR}/src"775 "${CMAKE_SOURCE_DIR}/src"
776)776)
777777
778if(MSVC)778# These have to go before the -Wno- flags
779 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w")779set(EXE_CFLAGS "-std=c++11")
780elseif(MINGW)780if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
781 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")781 if(MSVC)
782else()782 set(EXE_CFLAGS "${EXE_CFLAGS} /w")
783 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -Wall")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()
784endif()788endif()
785789
786if(MSVC)790if(MSVC)
787 set(EXE_CFLAGS "-std=c++11")791 set(EXE_CFLAGS "${EXE_CFLAGS}")
788else()792else()
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")
790endif()794endif()
791795
796
792set(EXE_LDFLAGS " ")797set(EXE_LDFLAGS " ")
793if(MINGW)798if(MINGW)
794 set(EXE_LDFLAGS "-static -static-libgcc -static-libstdc++")799 set(EXE_LDFLAGS "-static -static-libgcc -static-libstdc++")
doc/langref.html.in+1-1
...@@ -1587,7 +1587,7 @@ test "pointer casting" {...@@ -1587,7 +1587,7 @@ test "pointer casting" {
1587 // operation that Zig cannot protect you against. Use @ptrCast only when other1587 // operation that Zig cannot protect you against. Use @ptrCast only when other
1588 // conversions are not possible.1588 // conversions are not possible.
1589 const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 };1589 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);
1591 assert(u32_ptr.* == 0x12121212);1591 assert(u32_ptr.* == 0x12121212);
15921592
1593 // Even this example is contrived - there are better ways to do the above than1593 // Even this example is contrived - there are better ways to do the above than
src/all_types.hpp+249-174
...@@ -20,12 +20,12 @@...@@ -20,12 +20,12 @@
2020
21struct AstNode;21struct AstNode;
22struct ImportTableEntry;22struct ImportTableEntry;
23struct FnTableEntry;23struct ZigFn;
24struct Scope;24struct Scope;
25struct ScopeBlock;25struct ScopeBlock;
26struct ScopeFnDef;26struct ScopeFnDef;
27struct TypeTableEntry;27struct ZigType;
28struct VariableTableEntry;28struct ZigVar;
29struct ErrorTableEntry;29struct ErrorTableEntry;
30struct BuiltinFnEntry;30struct BuiltinFnEntry;
31struct TypeStructField;31struct TypeStructField;
...@@ -40,10 +40,17 @@ struct Tld;...@@ -40,10 +40,17 @@ struct Tld;
40struct TldExport;40struct TldExport;
41struct IrAnalyze;41struct IrAnalyze;
4242
43enum X64CABIClass {
44 X64CABIClass_Unknown,
45 X64CABIClass_MEMORY,
46 X64CABIClass_INTEGER,
47 X64CABIClass_SSE,
48};
49
43struct IrExecutable {50struct IrExecutable {
44 ZigList<IrBasicBlock *> basic_block_list;51 ZigList<IrBasicBlock *> basic_block_list;
45 Buf *name;52 Buf *name;
46 FnTableEntry *name_fn;53 ZigFn *name_fn;
47 size_t mem_slot_count;54 size_t mem_slot_count;
48 size_t next_debug_id;55 size_t next_debug_id;
49 size_t *backward_branch_count;56 size_t *backward_branch_count;
...@@ -51,7 +58,7 @@ struct IrExecutable {...@@ -51,7 +58,7 @@ struct IrExecutable {
51 bool invalid;58 bool invalid;
52 bool is_inline;59 bool is_inline;
53 bool is_generic_instantiation;60 bool is_generic_instantiation;
54 FnTableEntry *fn_entry;61 ZigFn *fn_entry;
55 Buf *c_import_buf;62 Buf *c_import_buf;
56 AstNode *source_node;63 AstNode *source_node;
57 IrExecutable *parent_exec;64 IrExecutable *parent_exec;
...@@ -69,7 +76,7 @@ struct IrExecutable {...@@ -69,7 +76,7 @@ struct IrExecutable {
69 IrBasicBlock *coro_normal_final;76 IrBasicBlock *coro_normal_final;
70 IrBasicBlock *coro_suspend_block;77 IrBasicBlock *coro_suspend_block;
71 IrBasicBlock *coro_final_cleanup_block;78 IrBasicBlock *coro_final_cleanup_block;
72 VariableTableEntry *coro_allocator_var;79 ZigVar *coro_allocator_var;
73};80};
7481
75enum OutType {82enum OutType {
...@@ -191,7 +198,7 @@ struct ConstPtrValue {...@@ -191,7 +198,7 @@ struct ConstPtrValue {
191 uint64_t addr;198 uint64_t addr;
192 } hard_coded_addr;199 } hard_coded_addr;
193 struct {200 struct {
194 FnTableEntry *fn_entry;201 ZigFn *fn_entry;
195 } fn;202 } fn;
196 } data;203 } data;
197};204};
...@@ -202,7 +209,7 @@ struct ConstErrValue {...@@ -202,7 +209,7 @@ struct ConstErrValue {
202};209};
203210
204struct ConstBoundFnValue {211struct ConstBoundFnValue {
205 FnTableEntry *fn;212 ZigFn *fn;
206 IrInstruction *first_arg;213 IrInstruction *first_arg;
207};214};
208215
...@@ -251,7 +258,7 @@ struct ConstGlobalRefs {...@@ -251,7 +258,7 @@ struct ConstGlobalRefs {
251};258};
252259
253struct ConstExprValue {260struct ConstExprValue {
254 TypeTableEntry *type;261 ZigType *type;
255 ConstValSpecial special;262 ConstValSpecial special;
256 ConstGlobalRefs *global_refs;263 ConstGlobalRefs *global_refs;
257264
...@@ -265,7 +272,7 @@ struct ConstExprValue {...@@ -265,7 +272,7 @@ struct ConstExprValue {
265 float128_t x_f128;272 float128_t x_f128;
266 bool x_bool;273 bool x_bool;
267 ConstBoundFnValue x_bound_fn;274 ConstBoundFnValue x_bound_fn;
268 TypeTableEntry *x_type;275 ZigType *x_type;
269 ConstExprValue *x_optional;276 ConstExprValue *x_optional;
270 ConstErrValue x_err_union;277 ConstErrValue x_err_union;
271 ErrorTableEntry *x_err_set;278 ErrorTableEntry *x_err_set;
...@@ -337,7 +344,7 @@ struct Tld {...@@ -337,7 +344,7 @@ struct Tld {
337struct TldVar {344struct TldVar {
338 Tld base;345 Tld base;
339346
340 VariableTableEntry *var;347 ZigVar *var;
341 Buf *extern_lib_name;348 Buf *extern_lib_name;
342 Buf *section_name;349 Buf *section_name;
343};350};
...@@ -345,7 +352,7 @@ struct TldVar {...@@ -345,7 +352,7 @@ struct TldVar {
345struct TldFn {352struct TldFn {
346 Tld base;353 Tld base;
347354
348 FnTableEntry *fn_entry;355 ZigFn *fn_entry;
349 Buf *extern_lib_name;356 Buf *extern_lib_name;
350};357};
351358
...@@ -353,7 +360,7 @@ struct TldContainer {...@@ -353,7 +360,7 @@ struct TldContainer {
353 Tld base;360 Tld base;
354361
355 ScopeDecls *decls_scope;362 ScopeDecls *decls_scope;
356 TypeTableEntry *type_entry;363 ZigType *type_entry;
357};364};
358365
359struct TldCompTime {366struct TldCompTime {
...@@ -370,7 +377,7 @@ struct TypeEnumField {...@@ -370,7 +377,7 @@ struct TypeEnumField {
370struct TypeUnionField {377struct TypeUnionField {
371 Buf *name;378 Buf *name;
372 TypeEnumField *enum_field;379 TypeEnumField *enum_field;
373 TypeTableEntry *type_entry;380 ZigType *type_entry;
374 AstNode *decl_node;381 AstNode *decl_node;
375 uint32_t gen_index;382 uint32_t gen_index;
376};383};
...@@ -973,11 +980,11 @@ struct AstNode {...@@ -973,11 +980,11 @@ struct AstNode {
973// this struct is allocated with allocate_nonzero980// this struct is allocated with allocate_nonzero
974struct FnTypeParamInfo {981struct FnTypeParamInfo {
975 bool is_noalias;982 bool is_noalias;
976 TypeTableEntry *type;983 ZigType *type;
977};984};
978985
979struct GenericFnTypeId {986struct GenericFnTypeId {
980 FnTableEntry *fn_entry;987 ZigFn *fn_entry;
981 ConstExprValue *params;988 ConstExprValue *params;
982 size_t param_count;989 size_t param_count;
983};990};
...@@ -986,14 +993,14 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);...@@ -986,14 +993,14 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
986bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);993bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);
987994
988struct FnTypeId {995struct FnTypeId {
989 TypeTableEntry *return_type;996 ZigType *return_type;
990 FnTypeParamInfo *param_info;997 FnTypeParamInfo *param_info;
991 size_t param_count;998 size_t param_count;
992 size_t next_param_index;999 size_t next_param_index;
993 bool is_var_args;1000 bool is_var_args;
994 CallingConvention cc;1001 CallingConvention cc;
995 uint32_t alignment;1002 uint32_t alignment;
996 TypeTableEntry *async_allocator_type;1003 ZigType *async_allocator_type;
997};1004};
9981005
999uint32_t fn_type_id_hash(FnTypeId*);1006uint32_t fn_type_id_hash(FnTypeId*);
...@@ -1004,34 +1011,34 @@ enum PtrLen {...@@ -1004,34 +1011,34 @@ enum PtrLen {
1004 PtrLenSingle,1011 PtrLenSingle,
1005};1012};
10061013
1007struct TypeTableEntryPointer {1014struct ZigTypePointer {
1008 TypeTableEntry *child_type;1015 ZigType *child_type;
1009 PtrLen ptr_len;1016 PtrLen ptr_len;
1010 bool is_const;1017 bool is_const;
1011 bool is_volatile;1018 bool is_volatile;
1012 uint32_t alignment;1019 uint32_t alignment;
1013 uint32_t bit_offset;1020 uint32_t bit_offset;
1014 uint32_t unaligned_bit_count;1021 uint32_t unaligned_bit_count;
1015 TypeTableEntry *slice_parent;1022 ZigType *slice_parent;
1016};1023};
10171024
1018struct TypeTableEntryInt {1025struct ZigTypeInt {
1019 uint32_t bit_count;1026 uint32_t bit_count;
1020 bool is_signed;1027 bool is_signed;
1021};1028};
10221029
1023struct TypeTableEntryFloat {1030struct ZigTypeFloat {
1024 size_t bit_count;1031 size_t bit_count;
1025};1032};
10261033
1027struct TypeTableEntryArray {1034struct ZigTypeArray {
1028 TypeTableEntry *child_type;1035 ZigType *child_type;
1029 uint64_t len;1036 uint64_t len;
1030};1037};
10311038
1032struct TypeStructField {1039struct TypeStructField {
1033 Buf *name;1040 Buf *name;
1034 TypeTableEntry *type_entry;1041 ZigType *type_entry;
1035 size_t src_index;1042 size_t src_index;
1036 size_t gen_index;1043 size_t gen_index;
1037 // offset from the memory at gen_index1044 // offset from the memory at gen_index
...@@ -1040,7 +1047,7 @@ struct TypeStructField {...@@ -1040,7 +1047,7 @@ struct TypeStructField {
1040 size_t unaligned_bit_count;1047 size_t unaligned_bit_count;
1041 AstNode *decl_node;1048 AstNode *decl_node;
1042};1049};
1043struct TypeTableEntryStruct {1050struct ZigTypeStruct {
1044 AstNode *decl_node;1051 AstNode *decl_node;
1045 ContainerLayout layout;1052 ContainerLayout layout;
1046 uint32_t src_field_count;1053 uint32_t src_field_count;
...@@ -1068,28 +1075,28 @@ struct TypeTableEntryStruct {...@@ -1068,28 +1075,28 @@ struct TypeTableEntryStruct {
1068 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;1075 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
1069};1076};
10701077
1071struct TypeTableEntryOptional {1078struct ZigTypeOptional {
1072 TypeTableEntry *child_type;1079 ZigType *child_type;
1073};1080};
10741081
1075struct TypeTableEntryErrorUnion {1082struct ZigTypeErrorUnion {
1076 TypeTableEntry *err_set_type;1083 ZigType *err_set_type;
1077 TypeTableEntry *payload_type;1084 ZigType *payload_type;
1078};1085};
10791086
1080struct TypeTableEntryErrorSet {1087struct ZigTypeErrorSet {
1081 uint32_t err_count;1088 uint32_t err_count;
1082 ErrorTableEntry **errors;1089 ErrorTableEntry **errors;
1083 FnTableEntry *infer_fn;1090 ZigFn *infer_fn;
1084};1091};
10851092
1086struct TypeTableEntryEnum {1093struct ZigTypeEnum {
1087 AstNode *decl_node;1094 AstNode *decl_node;
1088 ContainerLayout layout;1095 ContainerLayout layout;
1089 uint32_t src_field_count;1096 uint32_t src_field_count;
1090 TypeEnumField *fields;1097 TypeEnumField *fields;
1091 bool is_invalid; // true if any fields are invalid1098 bool is_invalid; // true if any fields are invalid
1092 TypeTableEntry *tag_int_type;1099 ZigType *tag_int_type;
10931100
1094 ScopeDecls *decls_scope;1101 ScopeDecls *decls_scope;
10951102
...@@ -1107,17 +1114,17 @@ struct TypeTableEntryEnum {...@@ -1107,17 +1114,17 @@ struct TypeTableEntryEnum {
1107 HashMap<Buf *, TypeEnumField *, buf_hash, buf_eql_buf> fields_by_name;1114 HashMap<Buf *, TypeEnumField *, buf_hash, buf_eql_buf> fields_by_name;
1108};1115};
11091116
1110uint32_t type_ptr_hash(const TypeTableEntry *ptr);1117uint32_t type_ptr_hash(const ZigType *ptr);
1111bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b);1118bool type_ptr_eql(const ZigType *a, const ZigType *b);
11121119
1113struct TypeTableEntryUnion {1120struct ZigTypeUnion {
1114 AstNode *decl_node;1121 AstNode *decl_node;
1115 ContainerLayout layout;1122 ContainerLayout layout;
1116 uint32_t src_field_count;1123 uint32_t src_field_count;
1117 uint32_t gen_field_count;1124 uint32_t gen_field_count;
1118 TypeUnionField *fields;1125 TypeUnionField *fields;
1119 bool is_invalid; // true if any fields are invalid1126 bool is_invalid; // true if any fields are invalid
1120 TypeTableEntry *tag_type; // always an enum or null1127 ZigType *tag_type; // always an enum or null
1121 LLVMTypeRef union_type_ref;1128 LLVMTypeRef union_type_ref;
11221129
1123 ScopeDecls *decls_scope;1130 ScopeDecls *decls_scope;
...@@ -1142,7 +1149,7 @@ struct TypeTableEntryUnion {...@@ -1142,7 +1149,7 @@ struct TypeTableEntryUnion {
1142 bool have_explicit_tag_type;1149 bool have_explicit_tag_type;
11431150
1144 uint32_t union_size_bytes;1151 uint32_t union_size_bytes;
1145 TypeTableEntry *most_aligned_union_member;1152 ZigType *most_aligned_union_member;
11461153
1147 HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;1154 HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;
1148};1155};
...@@ -1151,61 +1158,61 @@ struct FnGenParamInfo {...@@ -1151,61 +1158,61 @@ struct FnGenParamInfo {
1151 size_t src_index;1158 size_t src_index;
1152 size_t gen_index;1159 size_t gen_index;
1153 bool is_byval;1160 bool is_byval;
1154 TypeTableEntry *type;1161 ZigType *type;
1155};1162};
11561163
1157struct TypeTableEntryFn {1164struct ZigTypeFn {
1158 FnTypeId fn_type_id;1165 FnTypeId fn_type_id;
1159 bool is_generic;1166 bool is_generic;
1160 TypeTableEntry *gen_return_type;1167 ZigType *gen_return_type;
1161 size_t gen_param_count;1168 size_t gen_param_count;
1162 FnGenParamInfo *gen_param_info;1169 FnGenParamInfo *gen_param_info;
11631170
1164 LLVMTypeRef raw_type_ref;1171 LLVMTypeRef raw_type_ref;
11651172
1166 TypeTableEntry *bound_fn_parent;1173 ZigType *bound_fn_parent;
1167};1174};
11681175
1169struct TypeTableEntryBoundFn {1176struct ZigTypeBoundFn {
1170 TypeTableEntry *fn_type;1177 ZigType *fn_type;
1171};1178};
11721179
1173struct TypeTableEntryPromise {1180struct ZigTypePromise {
1174 // null if `promise` instead of `promise->T`1181 // null if `promise` instead of `promise->T`
1175 TypeTableEntry *result_type;1182 ZigType *result_type;
1176};1183};
11771184
1178enum TypeTableEntryId {1185enum ZigTypeId {
1179 TypeTableEntryIdInvalid,1186 ZigTypeIdInvalid,
1180 TypeTableEntryIdMetaType,1187 ZigTypeIdMetaType,
1181 TypeTableEntryIdVoid,1188 ZigTypeIdVoid,
1182 TypeTableEntryIdBool,1189 ZigTypeIdBool,
1183 TypeTableEntryIdUnreachable,1190 ZigTypeIdUnreachable,
1184 TypeTableEntryIdInt,1191 ZigTypeIdInt,
1185 TypeTableEntryIdFloat,1192 ZigTypeIdFloat,
1186 TypeTableEntryIdPointer,1193 ZigTypeIdPointer,
1187 TypeTableEntryIdArray,1194 ZigTypeIdArray,
1188 TypeTableEntryIdStruct,1195 ZigTypeIdStruct,
1189 TypeTableEntryIdComptimeFloat,1196 ZigTypeIdComptimeFloat,
1190 TypeTableEntryIdComptimeInt,1197 ZigTypeIdComptimeInt,
1191 TypeTableEntryIdUndefined,1198 ZigTypeIdUndefined,
1192 TypeTableEntryIdNull,1199 ZigTypeIdNull,
1193 TypeTableEntryIdOptional,1200 ZigTypeIdOptional,
1194 TypeTableEntryIdErrorUnion,1201 ZigTypeIdErrorUnion,
1195 TypeTableEntryIdErrorSet,1202 ZigTypeIdErrorSet,
1196 TypeTableEntryIdEnum,1203 ZigTypeIdEnum,
1197 TypeTableEntryIdUnion,1204 ZigTypeIdUnion,
1198 TypeTableEntryIdFn,1205 ZigTypeIdFn,
1199 TypeTableEntryIdNamespace,1206 ZigTypeIdNamespace,
1200 TypeTableEntryIdBlock,1207 ZigTypeIdBlock,
1201 TypeTableEntryIdBoundFn,1208 ZigTypeIdBoundFn,
1202 TypeTableEntryIdArgTuple,1209 ZigTypeIdArgTuple,
1203 TypeTableEntryIdOpaque,1210 ZigTypeIdOpaque,
1204 TypeTableEntryIdPromise,1211 ZigTypeIdPromise,
1205};1212};
12061213
1207struct TypeTableEntry {1214struct ZigType {
1208 TypeTableEntryId id;1215 ZigTypeId id;
1209 Buf name;1216 Buf name;
12101217
1211 LLVMTypeRef type_ref;1218 LLVMTypeRef type_ref;
...@@ -1216,26 +1223,26 @@ struct TypeTableEntry {...@@ -1216,26 +1223,26 @@ struct TypeTableEntry {
1216 bool gen_h_loop_flag;1223 bool gen_h_loop_flag;
12171224
1218 union {1225 union {
1219 TypeTableEntryPointer pointer;1226 ZigTypePointer pointer;
1220 TypeTableEntryInt integral;1227 ZigTypeInt integral;
1221 TypeTableEntryFloat floating;1228 ZigTypeFloat floating;
1222 TypeTableEntryArray array;1229 ZigTypeArray array;
1223 TypeTableEntryStruct structure;1230 ZigTypeStruct structure;
1224 TypeTableEntryOptional maybe;1231 ZigTypeOptional maybe;
1225 TypeTableEntryErrorUnion error_union;1232 ZigTypeErrorUnion error_union;
1226 TypeTableEntryErrorSet error_set;1233 ZigTypeErrorSet error_set;
1227 TypeTableEntryEnum enumeration;1234 ZigTypeEnum enumeration;
1228 TypeTableEntryUnion unionation;1235 ZigTypeUnion unionation;
1229 TypeTableEntryFn fn;1236 ZigTypeFn fn;
1230 TypeTableEntryBoundFn bound_fn;1237 ZigTypeBoundFn bound_fn;
1231 TypeTableEntryPromise promise;1238 ZigTypePromise promise;
1232 } data;1239 } data;
12331240
1234 // use these fields to make sure we don't duplicate type table entries for the same type1241 // 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]1242 ZigType *pointer_parent[2]; // [0 - mut, 1 - const]
1236 TypeTableEntry *optional_parent;1243 ZigType *optional_parent;
1237 TypeTableEntry *promise_parent;1244 ZigType *promise_parent;
1238 TypeTableEntry *promise_frame_parent;1245 ZigType *promise_frame_parent;
1239 // If we generate a constant name value for this type, we memoize it here.1246 // If we generate a constant name value for this type, we memoize it here.
1240 // The type of this is array1247 // The type of this is array
1241 ConstExprValue *cached_const_name_val;1248 ConstExprValue *cached_const_name_val;
...@@ -1282,7 +1289,7 @@ struct FnExport {...@@ -1282,7 +1289,7 @@ struct FnExport {
1282 GlobalLinkageId linkage;1289 GlobalLinkageId linkage;
1283};1290};
12841291
1285struct FnTableEntry {1292struct ZigFn {
1286 LLVMValueRef llvm_value;1293 LLVMValueRef llvm_value;
1287 const char *llvm_name;1294 const char *llvm_name;
1288 AstNode *proto_node;1295 AstNode *proto_node;
...@@ -1291,11 +1298,11 @@ struct FnTableEntry {...@@ -1291,11 +1298,11 @@ struct FnTableEntry {
1291 Scope *child_scope; // parent is scope for last parameter1298 Scope *child_scope; // parent is scope for last parameter
1292 ScopeBlock *def_scope; // parent is child_scope1299 ScopeBlock *def_scope; // parent is child_scope
1293 Buf symbol_name;1300 Buf symbol_name;
1294 TypeTableEntry *type_entry; // function type1301 ZigType *type_entry; // function type
1295 // in the case of normal functions this is the implicit return type1302 // in the case of normal functions this is the implicit return type
1296 // in the case of async functions this is the implicit return type according to the1303 // in the case of async functions this is the implicit return type according to the
1297 // zig source code, not according to zig ir1304 // zig source code, not according to zig ir
1298 TypeTableEntry *src_implicit_return_type;1305 ZigType *src_implicit_return_type;
1299 bool is_test;1306 bool is_test;
1300 FnInline fn_inline;1307 FnInline fn_inline;
1301 FnAnalState anal_state;1308 FnAnalState anal_state;
...@@ -1310,7 +1317,7 @@ struct FnTableEntry {...@@ -1310,7 +1317,7 @@ struct FnTableEntry {
1310 AstNode *fn_static_eval_set_node;1317 AstNode *fn_static_eval_set_node;
13111318
1312 ZigList<IrInstruction *> alloca_list;1319 ZigList<IrInstruction *> alloca_list;
1313 ZigList<VariableTableEntry *> variable_list;1320 ZigList<ZigVar *> variable_list;
13141321
1315 Buf *section_name;1322 Buf *section_name;
1316 AstNode *set_alignstack_node;1323 AstNode *set_alignstack_node;
...@@ -1323,8 +1330,8 @@ struct FnTableEntry {...@@ -1323,8 +1330,8 @@ struct FnTableEntry {
1323 bool calls_or_awaits_errorable_fn;1330 bool calls_or_awaits_errorable_fn;
1324};1331};
13251332
1326uint32_t fn_table_entry_hash(FnTableEntry*);1333uint32_t fn_table_entry_hash(ZigFn*);
1327bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b);1334bool fn_table_entry_eql(ZigFn *a, ZigFn *b);
13281335
1329enum BuiltinFnId {1336enum BuiltinFnId {
1330 BuiltinFnIdInvalid,1337 BuiltinFnIdInvalid,
...@@ -1445,11 +1452,11 @@ uint32_t fn_eval_hash(Scope*);...@@ -1445,11 +1452,11 @@ uint32_t fn_eval_hash(Scope*);
1445bool fn_eval_eql(Scope *a, Scope *b);1452bool fn_eval_eql(Scope *a, Scope *b);
14461453
1447struct TypeId {1454struct TypeId {
1448 TypeTableEntryId id;1455 ZigTypeId id;
14491456
1450 union {1457 union {
1451 struct {1458 struct {
1452 TypeTableEntry *child_type;1459 ZigType *child_type;
1453 PtrLen ptr_len;1460 PtrLen ptr_len;
1454 bool is_const;1461 bool is_const;
1455 bool is_volatile;1462 bool is_volatile;
...@@ -1458,7 +1465,7 @@ struct TypeId {...@@ -1458,7 +1465,7 @@ struct TypeId {
1458 uint32_t unaligned_bit_count;1465 uint32_t unaligned_bit_count;
1459 } pointer;1466 } pointer;
1460 struct {1467 struct {
1461 TypeTableEntry *child_type;1468 ZigType *child_type;
1462 uint64_t size;1469 uint64_t size;
1463 } array;1470 } array;
1464 struct {1471 struct {
...@@ -1466,8 +1473,8 @@ struct TypeId {...@@ -1466,8 +1473,8 @@ struct TypeId {
1466 uint32_t bit_count;1473 uint32_t bit_count;
1467 } integer;1474 } integer;
1468 struct {1475 struct {
1469 TypeTableEntry *err_set_type;1476 ZigType *err_set_type;
1470 TypeTableEntry *payload_type;1477 ZigType *payload_type;
1471 } error_union;1478 } error_union;
1472 } data;1479 } data;
1473};1480};
...@@ -1563,17 +1570,17 @@ struct CodeGen {...@@ -1563,17 +1570,17 @@ struct CodeGen {
1563 // reminder: hash tables must be initialized before use1570 // reminder: hash tables must be initialized before use
1564 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;1571 HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
1565 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;1572 HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
1566 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;1573 HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
1567 HashMap<TypeId, TypeTableEntry *, type_id_hash, type_id_eql> type_table;1574 HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
1568 HashMap<FnTypeId *, TypeTableEntry *, fn_type_id_hash, fn_type_id_eql> fn_type_table;1575 HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
1569 HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;1576 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;
1571 HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;1578 HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
1572 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;1579 HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
1573 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> exported_symbol_names;1580 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> exported_symbol_names;
1574 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;1581 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
1575 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;1582 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
1579 ZigList<ImportTableEntry *> import_queue;1586 ZigList<ImportTableEntry *> import_queue;
...@@ -1586,38 +1593,38 @@ struct CodeGen {...@@ -1586,38 +1593,38 @@ struct CodeGen {
1586 uint32_t next_unresolved_index;1593 uint32_t next_unresolved_index;
15871594
1588 struct {1595 struct {
1589 TypeTableEntry *entry_bool;1596 ZigType *entry_bool;
1590 TypeTableEntry *entry_c_int[CIntTypeCount];1597 ZigType *entry_c_int[CIntTypeCount];
1591 TypeTableEntry *entry_c_longdouble;1598 ZigType *entry_c_longdouble;
1592 TypeTableEntry *entry_c_void;1599 ZigType *entry_c_void;
1593 TypeTableEntry *entry_u8;1600 ZigType *entry_u8;
1594 TypeTableEntry *entry_u16;1601 ZigType *entry_u16;
1595 TypeTableEntry *entry_u32;1602 ZigType *entry_u32;
1596 TypeTableEntry *entry_u29;1603 ZigType *entry_u29;
1597 TypeTableEntry *entry_u64;1604 ZigType *entry_u64;
1598 TypeTableEntry *entry_i8;1605 ZigType *entry_i8;
1599 TypeTableEntry *entry_i32;1606 ZigType *entry_i32;
1600 TypeTableEntry *entry_i64;1607 ZigType *entry_i64;
1601 TypeTableEntry *entry_isize;1608 ZigType *entry_isize;
1602 TypeTableEntry *entry_usize;1609 ZigType *entry_usize;
1603 TypeTableEntry *entry_f16;1610 ZigType *entry_f16;
1604 TypeTableEntry *entry_f32;1611 ZigType *entry_f32;
1605 TypeTableEntry *entry_f64;1612 ZigType *entry_f64;
1606 TypeTableEntry *entry_f128;1613 ZigType *entry_f128;
1607 TypeTableEntry *entry_void;1614 ZigType *entry_void;
1608 TypeTableEntry *entry_unreachable;1615 ZigType *entry_unreachable;
1609 TypeTableEntry *entry_type;1616 ZigType *entry_type;
1610 TypeTableEntry *entry_invalid;1617 ZigType *entry_invalid;
1611 TypeTableEntry *entry_namespace;1618 ZigType *entry_namespace;
1612 TypeTableEntry *entry_block;1619 ZigType *entry_block;
1613 TypeTableEntry *entry_num_lit_int;1620 ZigType *entry_num_lit_int;
1614 TypeTableEntry *entry_num_lit_float;1621 ZigType *entry_num_lit_float;
1615 TypeTableEntry *entry_undef;1622 ZigType *entry_undef;
1616 TypeTableEntry *entry_null;1623 ZigType *entry_null;
1617 TypeTableEntry *entry_var;1624 ZigType *entry_var;
1618 TypeTableEntry *entry_global_error_set;1625 ZigType *entry_global_error_set;
1619 TypeTableEntry *entry_arg_tuple;1626 ZigType *entry_arg_tuple;
1620 TypeTableEntry *entry_promise;1627 ZigType *entry_promise;
1621 } builtin_types;1628 } builtin_types;
16221629
1623 EmitFileType emit_file_type;1630 EmitFileType emit_file_type;
...@@ -1672,14 +1679,14 @@ struct CodeGen {...@@ -1672,14 +1679,14 @@ struct CodeGen {
1672 const char *linker_script;1679 const char *linker_script;
16731680
1674 // The function definitions this module includes.1681 // The function definitions this module includes.
1675 ZigList<FnTableEntry *> fn_defs;1682 ZigList<ZigFn *> fn_defs;
1676 size_t fn_defs_index;1683 size_t fn_defs_index;
1677 ZigList<TldVar *> global_vars;1684 ZigList<TldVar *> global_vars;
16781685
1679 OutType out_type;1686 OutType out_type;
1680 FnTableEntry *cur_fn;1687 ZigFn *cur_fn;
1681 FnTableEntry *main_fn;1688 ZigFn *main_fn;
1682 FnTableEntry *panic_fn;1689 ZigFn *panic_fn;
1683 LLVMValueRef cur_ret_ptr;1690 LLVMValueRef cur_ret_ptr;
1684 LLVMValueRef cur_fn_val;1691 LLVMValueRef cur_fn_val;
1685 LLVMValueRef cur_err_ret_trace_val_arg;1692 LLVMValueRef cur_err_ret_trace_val_arg;
...@@ -1732,12 +1739,12 @@ struct CodeGen {...@@ -1732,12 +1739,12 @@ struct CodeGen {
1732 const char **llvm_argv;1739 const char **llvm_argv;
1733 size_t llvm_argv_len;1740 size_t llvm_argv_len;
17341741
1735 ZigList<FnTableEntry *> test_fns;1742 ZigList<ZigFn *> test_fns;
1736 TypeTableEntry *test_fn_type;1743 ZigType *test_fn_type;
17371744
1738 bool each_lib_rpath;1745 bool each_lib_rpath;
17391746
1740 TypeTableEntry *err_tag_type;1747 ZigType *err_tag_type;
1741 ZigList<ZigLLVMDIEnumerator *> err_enumerators;1748 ZigList<ZigLLVMDIEnumerator *> err_enumerators;
1742 ZigList<ErrorTableEntry *> errors_by_index;1749 ZigList<ErrorTableEntry *> errors_by_index;
1743 bool generate_error_name_table;1750 bool generate_error_name_table;
...@@ -1761,15 +1768,15 @@ struct CodeGen {...@@ -1761,15 +1768,15 @@ struct CodeGen {
17611768
1762 ZigList<TimeEvent> timing_events;1769 ZigList<TimeEvent> timing_events;
17631770
1764 Buf *cache_dir;1771 Buf cache_dir;
1765 Buf *out_h_path;1772 Buf *out_h_path;
17661773
1767 ZigList<FnTableEntry *> inline_fns;1774 ZigList<ZigFn *> inline_fns;
1768 ZigList<AstNode *> tld_ref_source_node_stack;1775 ZigList<AstNode *> tld_ref_source_node_stack;
17691776
1770 TypeTableEntry *align_amt_type;1777 ZigType *align_amt_type;
1771 TypeTableEntry *stack_trace_type;1778 ZigType *stack_trace_type;
1772 TypeTableEntry *ptr_to_stack_trace_type;1779 ZigType *ptr_to_stack_trace_type;
17731780
1774 ZigList<ZigLLVMDIType **> error_di_types;1781 ZigList<ZigLLVMDIType **> error_di_types;
17751782
...@@ -1784,7 +1791,7 @@ enum VarLinkage {...@@ -1784,7 +1791,7 @@ enum VarLinkage {
1784 VarLinkageExternal,1791 VarLinkageExternal,
1785};1792};
17861793
1787struct VariableTableEntry {1794struct ZigVar {
1788 Buf name;1795 Buf name;
1789 ConstExprValue *value;1796 ConstExprValue *value;
1790 LLVMValueRef value_ref;1797 LLVMValueRef value_ref;
...@@ -1809,14 +1816,14 @@ struct VariableTableEntry {...@@ -1809,14 +1816,14 @@ struct VariableTableEntry {
1809 // In an inline loop, multiple variables may be created,1816 // In an inline loop, multiple variables may be created,
1810 // In this case, a reference to a variable should follow1817 // In this case, a reference to a variable should follow
1811 // this pointer to the redefined variable.1818 // this pointer to the redefined variable.
1812 VariableTableEntry *next_var;1819 ZigVar *next_var;
1813};1820};
18141821
1815struct ErrorTableEntry {1822struct ErrorTableEntry {
1816 Buf name;1823 Buf name;
1817 uint32_t value;1824 uint32_t value;
1818 AstNode *decl_node;1825 AstNode *decl_node;
1819 TypeTableEntry *set_with_only_this_in_it;1826 ZigType *set_with_only_this_in_it;
1820 // If we generate a constant error name value for this error, we memoize it here.1827 // If we generate a constant error name value for this error, we memoize it here.
1821 // The type of this is array1828 // The type of this is array
1822 ConstExprValue *cached_error_name_val;1829 ConstExprValue *cached_error_name_val;
...@@ -1834,6 +1841,7 @@ enum ScopeId {...@@ -1834,6 +1841,7 @@ enum ScopeId {
1834 ScopeIdFnDef,1841 ScopeIdFnDef,
1835 ScopeIdCompTime,1842 ScopeIdCompTime,
1836 ScopeIdCoroPrelude,1843 ScopeIdCoroPrelude,
1844 ScopeIdRuntime,
1837};1845};
18381846
1839struct Scope {1847struct Scope {
...@@ -1859,7 +1867,7 @@ struct ScopeDecls {...@@ -1859,7 +1867,7 @@ struct ScopeDecls {
1859 AstNode *fast_math_set_node;1867 AstNode *fast_math_set_node;
1860 ImportTableEntry *import;1868 ImportTableEntry *import;
1861 // If this is a scope from a container, this is the type entry, otherwise null1869 // If this is a scope from a container, this is the type entry, otherwise null
1862 TypeTableEntry *container_type;1870 ZigType *container_type;
1863};1871};
18641872
1865// This scope comes from a block expression in user code.1873// This scope comes from a block expression in user code.
...@@ -1901,7 +1909,7 @@ struct ScopeVarDecl {...@@ -1901,7 +1909,7 @@ struct ScopeVarDecl {
1901 Scope base;1909 Scope base;
19021910
1903 // The variable that creates this scope1911 // The variable that creates this scope
1904 VariableTableEntry *var;1912 ZigVar *var;
1905};1913};
19061914
1907// This scope is created for a @cImport1915// This scope is created for a @cImport
...@@ -1926,6 +1934,15 @@ struct ScopeLoop {...@@ -1926,6 +1934,15 @@ struct ScopeLoop {
1926 ZigList<IrBasicBlock *> *incoming_blocks;1934 ZigList<IrBasicBlock *> *incoming_blocks;
1927};1935};
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
1929// This scope is created for a suspend block in order to have labeled1946// This scope is created for a suspend block in order to have labeled
1930// suspend for breaking out of a suspend and for detecting if a suspend1947// suspend for breaking out of a suspend and for detecting if a suspend
1931// block is inside a suspend block.1948// block is inside a suspend block.
...@@ -1948,7 +1965,7 @@ struct ScopeCompTime {...@@ -1948,7 +1965,7 @@ struct ScopeCompTime {
1948struct ScopeFnDef {1965struct ScopeFnDef {
1949 Scope base;1966 Scope base;
19501967
1951 FnTableEntry *fn_entry;1968 ZigFn *fn_entry;
1952};1969};
19531970
1954// This scope is created to indicate that the code in the scope1971// This scope is created to indicate that the code in the scope
...@@ -2145,6 +2162,7 @@ enum IrInstructionId {...@@ -2145,6 +2162,7 @@ enum IrInstructionId {
2145 IrInstructionIdErrSetCast,2162 IrInstructionIdErrSetCast,
2146 IrInstructionIdToBytes,2163 IrInstructionIdToBytes,
2147 IrInstructionIdFromBytes,2164 IrInstructionIdFromBytes,
2165 IrInstructionIdCheckRuntimeScope,
2148};2166};
21492167
2150struct IrInstruction {2168struct IrInstruction {
...@@ -2279,7 +2297,7 @@ struct IrInstructionBinOp {...@@ -2279,7 +2297,7 @@ struct IrInstructionBinOp {
2279struct IrInstructionDeclVar {2297struct IrInstructionDeclVar {
2280 IrInstruction base;2298 IrInstruction base;
22812299
2282 VariableTableEntry *var;2300 ZigVar *var;
2283 IrInstruction *var_type;2301 IrInstruction *var_type;
2284 IrInstruction *align_value;2302 IrInstruction *align_value;
2285 IrInstruction *init_value;2303 IrInstruction *init_value;
...@@ -2336,14 +2354,15 @@ struct IrInstructionElemPtr {...@@ -2336,14 +2354,15 @@ struct IrInstructionElemPtr {
2336struct IrInstructionVarPtr {2354struct IrInstructionVarPtr {
2337 IrInstruction base;2355 IrInstruction base;
23382356
2339 VariableTableEntry *var;2357 ZigVar *var;
2358 ScopeFnDef *crossed_fndef_scope;
2340};2359};
23412360
2342struct IrInstructionCall {2361struct IrInstructionCall {
2343 IrInstruction base;2362 IrInstruction base;
23442363
2345 IrInstruction *fn_ref;2364 IrInstruction *fn_ref;
2346 FnTableEntry *fn_entry;2365 ZigFn *fn_entry;
2347 size_t arg_count;2366 size_t arg_count;
2348 IrInstruction **args;2367 IrInstruction **args;
2349 bool is_comptime;2368 bool is_comptime;
...@@ -2373,7 +2392,7 @@ struct IrInstructionCast {...@@ -2373,7 +2392,7 @@ struct IrInstructionCast {
2373 IrInstruction base;2392 IrInstruction base;
23742393
2375 IrInstruction *value;2394 IrInstruction *value;
2376 TypeTableEntry *dest_type;2395 ZigType *dest_type;
2377 CastOp cast_op;2396 CastOp cast_op;
2378 LLVMValueRef tmp_ptr;2397 LLVMValueRef tmp_ptr;
2379};2398};
...@@ -2410,7 +2429,7 @@ struct IrInstructionStructInitField {...@@ -2410,7 +2429,7 @@ struct IrInstructionStructInitField {
2410struct IrInstructionStructInit {2429struct IrInstructionStructInit {
2411 IrInstruction base;2430 IrInstruction base;
24122431
2413 TypeTableEntry *struct_type;2432 ZigType *struct_type;
2414 size_t field_count;2433 size_t field_count;
2415 IrInstructionStructInitField *fields;2434 IrInstructionStructInitField *fields;
2416 LLVMValueRef tmp_ptr;2435 LLVMValueRef tmp_ptr;
...@@ -2419,7 +2438,7 @@ struct IrInstructionStructInit {...@@ -2419,7 +2438,7 @@ struct IrInstructionStructInit {
2419struct IrInstructionUnionInit {2438struct IrInstructionUnionInit {
2420 IrInstruction base;2439 IrInstruction base;
24212440
2422 TypeTableEntry *union_type;2441 ZigType *union_type;
2423 TypeUnionField *field;2442 TypeUnionField *field;
2424 IrInstruction *init_value;2443 IrInstruction *init_value;
2425 LLVMValueRef tmp_ptr;2444 LLVMValueRef tmp_ptr;
...@@ -2506,7 +2525,7 @@ struct IrInstructionAsm {...@@ -2506,7 +2525,7 @@ struct IrInstructionAsm {
2506 // Most information on inline assembly comes from the source node.2525 // Most information on inline assembly comes from the source node.
2507 IrInstruction **input_list;2526 IrInstruction **input_list;
2508 IrInstruction **output_types;2527 IrInstruction **output_types;
2509 VariableTableEntry **output_vars;2528 ZigVar **output_vars;
2510 size_t return_count;2529 size_t return_count;
2511 bool has_side_effects;2530 bool has_side_effects;
2512};2531};
...@@ -2648,7 +2667,7 @@ struct IrInstructionCmpxchg {...@@ -2648,7 +2667,7 @@ struct IrInstructionCmpxchg {
2648 IrInstruction *failure_order_value;2667 IrInstruction *failure_order_value;
26492668
2650 // if this instruction gets to runtime then we know these values:2669 // if this instruction gets to runtime then we know these values:
2651 TypeTableEntry *type;2670 ZigType *type;
2652 AtomicOrder success_order;2671 AtomicOrder success_order;
2653 AtomicOrder failure_order;2672 AtomicOrder failure_order;
26542673
...@@ -2818,7 +2837,7 @@ struct IrInstructionOverflowOp {...@@ -2818,7 +2837,7 @@ struct IrInstructionOverflowOp {
2818 IrInstruction *op2;2837 IrInstruction *op2;
2819 IrInstruction *result_ptr;2838 IrInstruction *result_ptr;
28202839
2821 TypeTableEntry *result_ptr_type;2840 ZigType *result_ptr_type;
2822};2841};
28232842
2824struct IrInstructionAlignOf {2843struct IrInstructionAlignOf {
...@@ -3234,6 +3253,13 @@ struct IrInstructionSqrt {...@@ -3234,6 +3253,13 @@ struct IrInstructionSqrt {
3234 IrInstruction *op;3253 IrInstruction *op;
3235};3254};
32363255
3256struct IrInstructionCheckRuntimeScope {
3257 IrInstruction base;
3258
3259 IrInstruction *scope_is_comptime;
3260 IrInstruction *is_comptime;
3261};
3262
3237static const size_t slice_ptr_index = 0;3263static const size_t slice_ptr_index = 0;
3238static const size_t slice_len_index = 1;3264static const size_t slice_len_index = 1;
32393265
...@@ -3263,4 +3289,53 @@ enum FloatMode {...@@ -3263,4 +3289,53 @@ enum FloatMode {
3263 FloatModeStrict,3289 FloatModeStrict,
3264};3290};
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
3266#endif3341#endif
src/analyze.cpp+1089-974
...@@ -19,13 +19,13 @@...@@ -19,13 +19,13 @@
1919
20static const size_t default_backward_branch_quota = 1000;20static const size_t default_backward_branch_quota = 1000;
2121
22static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type);22static Error resolve_enum_type(CodeGen *g, ZigType *enum_type);
23static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_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);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, TypeTableEntry *enum_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, TypeTableEntry *union_type);27static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type);
28static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);28static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry);
2929
30ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {30ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
31 if (node->owner->c_import_node != nullptr) {31 if (node->owner->c_import_node != nullptr) {
...@@ -70,24 +70,24 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m...@@ -70,24 +70,24 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m
70 return err;70 return err;
71}71}
7272
73TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {73ZigType *new_type_table_entry(ZigTypeId id) {
74 TypeTableEntry *entry = allocate<TypeTableEntry>(1);74 ZigType *entry = allocate<ZigType>(1);
75 entry->id = id;75 entry->id = id;
76 return entry;76 return entry;
77}77}
7878
79static ScopeDecls **get_container_scope_ptr(TypeTableEntry *type_entry) {79static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) {
80 if (type_entry->id == TypeTableEntryIdStruct) {80 if (type_entry->id == ZigTypeIdStruct) {
81 return &type_entry->data.structure.decls_scope;81 return &type_entry->data.structure.decls_scope;
82 } else if (type_entry->id == TypeTableEntryIdEnum) {82 } else if (type_entry->id == ZigTypeIdEnum) {
83 return &type_entry->data.enumeration.decls_scope;83 return &type_entry->data.enumeration.decls_scope;
84 } else if (type_entry->id == TypeTableEntryIdUnion) {84 } else if (type_entry->id == ZigTypeIdUnion) {
85 return &type_entry->data.unionation.decls_scope;85 return &type_entry->data.unionation.decls_scope;
86 }86 }
87 zig_unreachable();87 zig_unreachable();
88}88}
8989
90ScopeDecls *get_container_scope(TypeTableEntry *type_entry) {90ScopeDecls *get_container_scope(ZigType *type_entry) {
91 return *get_container_scope_ptr(type_entry);91 return *get_container_scope_ptr(type_entry);
92}92}
9393
...@@ -97,7 +97,7 @@ void init_scope(Scope *dest, ScopeId id, AstNode *source_node, Scope *parent) {...@@ -97,7 +97,7 @@ void init_scope(Scope *dest, ScopeId id, AstNode *source_node, Scope *parent) {
97 dest->parent = parent;97 dest->parent = parent;
98}98}
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) {
101 assert(node == nullptr || node->type == NodeTypeRoot || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);101 assert(node == nullptr || node->type == NodeTypeRoot || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
102 ScopeDecls *scope = allocate<ScopeDecls>(1);102 ScopeDecls *scope = allocate<ScopeDecls>(1);
103 init_scope(&scope->base, ScopeIdDecls, node, parent);103 init_scope(&scope->base, ScopeIdDecls, node, parent);
...@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {...@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {
129 return scope;129 return scope;
130}130}
131131
132Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var) {132Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var) {
133 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);133 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
134 init_scope(&scope->base, ScopeIdVarDecl, node, parent);134 init_scope(&scope->base, ScopeIdVarDecl, node, parent);
135 scope->var = var;135 scope->var = var;
...@@ -157,6 +157,13 @@ ScopeLoop *create_loop_scope(AstNode *node, Scope *parent) {...@@ -157,6 +157,13 @@ ScopeLoop *create_loop_scope(AstNode *node, Scope *parent) {
157 return scope;157 return scope;
158}158}
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
160ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {167ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
161 assert(node->type == NodeTypeSuspend);168 assert(node->type == NodeTypeSuspend);
162 ScopeSuspend *scope = allocate<ScopeSuspend>(1);169 ScopeSuspend *scope = allocate<ScopeSuspend>(1);
...@@ -164,7 +171,7 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {...@@ -164,7 +171,7 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
164 return scope;171 return scope;
165}172}
166173
167ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) {174ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry) {
168 ScopeFnDef *scope = allocate<ScopeFnDef>(1);175 ScopeFnDef *scope = allocate<ScopeFnDef>(1);
169 init_scope(&scope->base, ScopeIdFnDef, node, parent);176 init_scope(&scope->base, ScopeIdFnDef, node, parent);
170 scope->fn_entry = fn_entry;177 scope->fn_entry = fn_entry;
...@@ -196,8 +203,8 @@ ImportTableEntry *get_scope_import(Scope *scope) {...@@ -196,8 +203,8 @@ ImportTableEntry *get_scope_import(Scope *scope) {
196 zig_unreachable();203 zig_unreachable();
197}204}
198205
199static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node, Scope *parent_scope) {206static ZigType *new_container_type_entry(ZigTypeId id, AstNode *source_node, Scope *parent_scope) {
200 TypeTableEntry *entry = new_type_table_entry(id);207 ZigType *entry = new_type_table_entry(id);
201 *get_container_scope_ptr(entry) = create_decls_scope(source_node, parent_scope, entry, get_scope_import(parent_scope));208 *get_container_scope_ptr(entry) = create_decls_scope(source_node, parent_scope, entry, get_scope_import(parent_scope));
202 return entry;209 return entry;
203}210}
...@@ -211,131 +218,131 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {...@@ -211,131 +218,131 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {
211 return (upper >= x) ? base : (base + 1);218 return (upper >= x) ? base : (base + 1);
212}219}
213220
214AstNode *type_decl_node(TypeTableEntry *type_entry) {221AstNode *type_decl_node(ZigType *type_entry) {
215 switch (type_entry->id) {222 switch (type_entry->id) {
216 case TypeTableEntryIdInvalid:223 case ZigTypeIdInvalid:
217 zig_unreachable();224 zig_unreachable();
218 case TypeTableEntryIdStruct:225 case ZigTypeIdStruct:
219 return type_entry->data.structure.decl_node;226 return type_entry->data.structure.decl_node;
220 case TypeTableEntryIdEnum:227 case ZigTypeIdEnum:
221 return type_entry->data.enumeration.decl_node;228 return type_entry->data.enumeration.decl_node;
222 case TypeTableEntryIdUnion:229 case ZigTypeIdUnion:
223 return type_entry->data.unionation.decl_node;230 return type_entry->data.unionation.decl_node;
224 case TypeTableEntryIdOpaque:231 case ZigTypeIdOpaque:
225 case TypeTableEntryIdMetaType:232 case ZigTypeIdMetaType:
226 case TypeTableEntryIdVoid:233 case ZigTypeIdVoid:
227 case TypeTableEntryIdBool:234 case ZigTypeIdBool:
228 case TypeTableEntryIdUnreachable:235 case ZigTypeIdUnreachable:
229 case TypeTableEntryIdInt:236 case ZigTypeIdInt:
230 case TypeTableEntryIdFloat:237 case ZigTypeIdFloat:
231 case TypeTableEntryIdPointer:238 case ZigTypeIdPointer:
232 case TypeTableEntryIdArray:239 case ZigTypeIdArray:
233 case TypeTableEntryIdComptimeFloat:240 case ZigTypeIdComptimeFloat:
234 case TypeTableEntryIdComptimeInt:241 case ZigTypeIdComptimeInt:
235 case TypeTableEntryIdUndefined:242 case ZigTypeIdUndefined:
236 case TypeTableEntryIdNull:243 case ZigTypeIdNull:
237 case TypeTableEntryIdOptional:244 case ZigTypeIdOptional:
238 case TypeTableEntryIdErrorUnion:245 case ZigTypeIdErrorUnion:
239 case TypeTableEntryIdErrorSet:246 case ZigTypeIdErrorSet:
240 case TypeTableEntryIdFn:247 case ZigTypeIdFn:
241 case TypeTableEntryIdNamespace:248 case ZigTypeIdNamespace:
242 case TypeTableEntryIdBlock:249 case ZigTypeIdBlock:
243 case TypeTableEntryIdBoundFn:250 case ZigTypeIdBoundFn:
244 case TypeTableEntryIdArgTuple:251 case ZigTypeIdArgTuple:
245 case TypeTableEntryIdPromise:252 case ZigTypeIdPromise:
246 return nullptr;253 return nullptr;
247 }254 }
248 zig_unreachable();255 zig_unreachable();
249}256}
250257
251bool type_is_complete(TypeTableEntry *type_entry) {258bool type_is_complete(ZigType *type_entry) {
252 switch (type_entry->id) {259 switch (type_entry->id) {
253 case TypeTableEntryIdInvalid:260 case ZigTypeIdInvalid:
254 zig_unreachable();261 zig_unreachable();
255 case TypeTableEntryIdStruct:262 case ZigTypeIdStruct:
256 return type_entry->data.structure.complete;263 return type_entry->data.structure.complete;
257 case TypeTableEntryIdEnum:264 case ZigTypeIdEnum:
258 return type_entry->data.enumeration.complete;265 return type_entry->data.enumeration.complete;
259 case TypeTableEntryIdUnion:266 case ZigTypeIdUnion:
260 return type_entry->data.unionation.complete;267 return type_entry->data.unionation.complete;
261 case TypeTableEntryIdOpaque:268 case ZigTypeIdOpaque:
262 return false;269 return false;
263 case TypeTableEntryIdMetaType:270 case ZigTypeIdMetaType:
264 case TypeTableEntryIdVoid:271 case ZigTypeIdVoid:
265 case TypeTableEntryIdBool:272 case ZigTypeIdBool:
266 case TypeTableEntryIdUnreachable:273 case ZigTypeIdUnreachable:
267 case TypeTableEntryIdInt:274 case ZigTypeIdInt:
268 case TypeTableEntryIdFloat:275 case ZigTypeIdFloat:
269 case TypeTableEntryIdPointer:276 case ZigTypeIdPointer:
270 case TypeTableEntryIdArray:277 case ZigTypeIdArray:
271 case TypeTableEntryIdComptimeFloat:278 case ZigTypeIdComptimeFloat:
272 case TypeTableEntryIdComptimeInt:279 case ZigTypeIdComptimeInt:
273 case TypeTableEntryIdUndefined:280 case ZigTypeIdUndefined:
274 case TypeTableEntryIdNull:281 case ZigTypeIdNull:
275 case TypeTableEntryIdOptional:282 case ZigTypeIdOptional:
276 case TypeTableEntryIdErrorUnion:283 case ZigTypeIdErrorUnion:
277 case TypeTableEntryIdErrorSet:284 case ZigTypeIdErrorSet:
278 case TypeTableEntryIdFn:285 case ZigTypeIdFn:
279 case TypeTableEntryIdNamespace:286 case ZigTypeIdNamespace:
280 case TypeTableEntryIdBlock:287 case ZigTypeIdBlock:
281 case TypeTableEntryIdBoundFn:288 case ZigTypeIdBoundFn:
282 case TypeTableEntryIdArgTuple:289 case ZigTypeIdArgTuple:
283 case TypeTableEntryIdPromise:290 case ZigTypeIdPromise:
284 return true;291 return true;
285 }292 }
286 zig_unreachable();293 zig_unreachable();
287}294}
288295
289bool type_has_zero_bits_known(TypeTableEntry *type_entry) {296bool type_has_zero_bits_known(ZigType *type_entry) {
290 switch (type_entry->id) {297 switch (type_entry->id) {
291 case TypeTableEntryIdInvalid:298 case ZigTypeIdInvalid:
292 zig_unreachable();299 zig_unreachable();
293 case TypeTableEntryIdStruct:300 case ZigTypeIdStruct:
294 return type_entry->data.structure.zero_bits_known;301 return type_entry->data.structure.zero_bits_known;
295 case TypeTableEntryIdEnum:302 case ZigTypeIdEnum:
296 return type_entry->data.enumeration.zero_bits_known;303 return type_entry->data.enumeration.zero_bits_known;
297 case TypeTableEntryIdUnion:304 case ZigTypeIdUnion:
298 return type_entry->data.unionation.zero_bits_known;305 return type_entry->data.unionation.zero_bits_known;
299 case TypeTableEntryIdMetaType:306 case ZigTypeIdMetaType:
300 case TypeTableEntryIdVoid:307 case ZigTypeIdVoid:
301 case TypeTableEntryIdBool:308 case ZigTypeIdBool:
302 case TypeTableEntryIdUnreachable:309 case ZigTypeIdUnreachable:
303 case TypeTableEntryIdInt:310 case ZigTypeIdInt:
304 case TypeTableEntryIdFloat:311 case ZigTypeIdFloat:
305 case TypeTableEntryIdPointer:312 case ZigTypeIdPointer:
306 case TypeTableEntryIdArray:313 case ZigTypeIdArray:
307 case TypeTableEntryIdComptimeFloat:314 case ZigTypeIdComptimeFloat:
308 case TypeTableEntryIdComptimeInt:315 case ZigTypeIdComptimeInt:
309 case TypeTableEntryIdUndefined:316 case ZigTypeIdUndefined:
310 case TypeTableEntryIdNull:317 case ZigTypeIdNull:
311 case TypeTableEntryIdOptional:318 case ZigTypeIdOptional:
312 case TypeTableEntryIdErrorUnion:319 case ZigTypeIdErrorUnion:
313 case TypeTableEntryIdErrorSet:320 case ZigTypeIdErrorSet:
314 case TypeTableEntryIdFn:321 case ZigTypeIdFn:
315 case TypeTableEntryIdNamespace:322 case ZigTypeIdNamespace:
316 case TypeTableEntryIdBlock:323 case ZigTypeIdBlock:
317 case TypeTableEntryIdBoundFn:324 case ZigTypeIdBoundFn:
318 case TypeTableEntryIdArgTuple:325 case ZigTypeIdArgTuple:
319 case TypeTableEntryIdOpaque:326 case ZigTypeIdOpaque:
320 case TypeTableEntryIdPromise:327 case ZigTypeIdPromise:
321 return true;328 return true;
322 }329 }
323 zig_unreachable();330 zig_unreachable();
324}331}
325332
326333
327uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {334uint64_t type_size(CodeGen *g, ZigType *type_entry) {
328 assert(type_is_complete(type_entry));335 assert(type_is_complete(type_entry));
329336
330 if (!type_has_bits(type_entry))337 if (!type_has_bits(type_entry))
331 return 0;338 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) {
334 uint64_t size_in_bits = type_size_bits(g, type_entry);341 uint64_t size_in_bits = type_size_bits(g, type_entry);
335 return (size_in_bits + 7) / 8;342 return (size_in_bits + 7) / 8;
336 } else if (type_entry->id == TypeTableEntryIdArray) {343 } else if (type_entry->id == ZigTypeIdArray) {
337 TypeTableEntry *child_type = type_entry->data.array.child_type;344 ZigType *child_type = type_entry->data.array.child_type;
338 if (child_type->id == TypeTableEntryIdStruct &&345 if (child_type->id == ZigTypeIdStruct &&
339 child_type->data.structure.layout == ContainerLayoutPacked)346 child_type->data.structure.layout == ContainerLayoutPacked)
340 {347 {
341 uint64_t size_in_bits = type_size_bits(g, type_entry);348 uint64_t size_in_bits = type_size_bits(g, type_entry);
...@@ -346,21 +353,21 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {...@@ -346,21 +353,21 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
346 return LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref);353 return LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref);
347}354}
348355
349uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {356uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) {
350 assert(type_is_complete(type_entry));357 assert(type_is_complete(type_entry));
351358
352 if (!type_has_bits(type_entry))359 if (!type_has_bits(type_entry))
353 return 0;360 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) {
356 uint64_t result = 0;363 uint64_t result = 0;
357 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {364 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
358 result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry);365 result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry);
359 }366 }
360 return result;367 return result;
361 } else if (type_entry->id == TypeTableEntryIdArray) {368 } else if (type_entry->id == ZigTypeIdArray) {
362 TypeTableEntry *child_type = type_entry->data.array.child_type;369 ZigType *child_type = type_entry->data.array.child_type;
363 if (child_type->id == TypeTableEntryIdStruct &&370 if (child_type->id == ZigTypeIdStruct &&
364 child_type->data.structure.layout == ContainerLayoutPacked)371 child_type->data.structure.layout == ContainerLayoutPacked)
365 {372 {
366 return type_entry->data.array.len * type_size_bits(g, child_type);373 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) {...@@ -370,7 +377,7 @@ uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
370 return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref);377 return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref);
371}378}
372379
373Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {380Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) {
374 Error err;381 Error err;
375 if ((err = type_ensure_zero_bits_known(g, type_entry)))382 if ((err = type_ensure_zero_bits_known(g, type_entry)))
376 return err;383 return err;
...@@ -387,23 +394,23 @@ Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {...@@ -387,23 +394,23 @@ Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
387 return type_entry->is_copyable;394 return type_entry->is_copyable;
388}395}
389396
390static bool is_slice(TypeTableEntry *type) {397static bool is_slice(ZigType *type) {
391 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;398 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
392}399}
393400
394TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {401ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
395 return get_int_type(g, false, bits_needed_for_unsigned(x));402 return get_int_type(g, false, bits_needed_for_unsigned(x));
396}403}
397404
398TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {405ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
399 if (result_type != nullptr && result_type->promise_parent != nullptr) {406 if (result_type != nullptr && result_type->promise_parent != nullptr) {
400 return result_type->promise_parent;407 return result_type->promise_parent;
401 } else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) {408 } else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) {
402 return g->builtin_types.entry_promise;409 return g->builtin_types.entry_promise;
403 }410 }
404411
405 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);412 ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
406 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPromise);413 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
407 entry->type_ref = u8_ptr_type->type_ref;414 entry->type_ref = u8_ptr_type->type_ref;
408 entry->zero_bits = false;415 entry->zero_bits = false;
409 entry->data.promise.result_type = result_type;416 entry->data.promise.result_type = result_type;
...@@ -421,17 +428,17 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {...@@ -421,17 +428,17 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
421 return entry;428 return entry;
422}429}
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,
425 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)432 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
426{433{
427 assert(!type_is_invalid(child_type));434 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
430 TypeId type_id = {};437 TypeId type_id = {};
431 TypeTableEntry **parent_pointer = nullptr;438 ZigType **parent_pointer = nullptr;
432 uint32_t abi_alignment = get_abi_alignment(g, child_type);439 uint32_t abi_alignment = get_abi_alignment(g, child_type);
433 if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) {440 if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) {
434 type_id.id = TypeTableEntryIdPointer;441 type_id.id = ZigTypeIdPointer;
435 type_id.data.pointer.child_type = child_type;442 type_id.data.pointer.child_type = child_type;
436 type_id.data.pointer.is_const = is_const;443 type_id.data.pointer.is_const = is_const;
437 type_id.data.pointer.is_volatile = is_volatile;444 type_id.data.pointer.is_volatile = is_volatile;
...@@ -454,7 +461,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -454,7 +461,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
454461
455 assertNoError(type_ensure_zero_bits_known(g, child_type));462 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);
458 entry->is_copyable = true;465 entry->is_copyable = true;
459466
460 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";467 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
...@@ -471,7 +478,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -471,7 +478,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
471 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));478 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
472 }479 }
473480
474 assert(child_type->id != TypeTableEntryIdInvalid);481 assert(child_type->id != ZigTypeIdInvalid);
475482
476 entry->zero_bits = !type_has_bits(child_type);483 entry->zero_bits = !type_has_bits(child_type);
477484
...@@ -480,7 +487,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -480,7 +487,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
480 if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||487 if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||
481 ptr_len != PtrLenSingle)488 ptr_len != PtrLenSingle)
482 {489 {
483 TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false);490 ZigType *peer_type = get_pointer_to_type(g, child_type, false);
484 entry->type_ref = peer_type->type_ref;491 entry->type_ref = peer_type->type_ref;
485 entry->di_type = peer_type->di_type;492 entry->di_type = peer_type->di_type;
486 } else {493 } else {
...@@ -513,18 +520,18 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -513,18 +520,18 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
513 return entry;520 return entry;
514}521}
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) {
517 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle,524 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle,
518 get_abi_alignment(g, child_type), 0, 0);525 get_abi_alignment(g, child_type), 0, 0);
519}526}
520527
521TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) {528ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type) {
522 if (return_type->promise_frame_parent != nullptr) {529 if (return_type->promise_frame_parent != nullptr) {
523 return return_type->promise_frame_parent;530 return return_type->promise_frame_parent;
524 }531 }
525532
526 TypeTableEntry *atomic_state_type = g->builtin_types.entry_usize;533 ZigType *atomic_state_type = g->builtin_types.entry_usize;
527 TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false);534 ZigType *result_ptr_type = get_pointer_to_type(g, return_type, false);
528535
529 ZigList<const char *> field_names = {};536 ZigList<const char *> field_names = {};
530 field_names.append(ATOMIC_STATE_FIELD_NAME);537 field_names.append(ATOMIC_STATE_FIELD_NAME);
...@@ -536,7 +543,7 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)...@@ -536,7 +543,7 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
536 field_names.append(RETURN_ADDRESSES_FIELD_NAME);543 field_names.append(RETURN_ADDRESSES_FIELD_NAME);
537 }544 }
538545
539 ZigList<TypeTableEntry *> field_types = {};546 ZigList<ZigType *> field_types = {};
540 field_types.append(atomic_state_type);547 field_types.append(atomic_state_type);
541 field_types.append(return_type);548 field_types.append(return_type);
542 field_types.append(result_ptr_type);549 field_types.append(result_ptr_type);
...@@ -548,20 +555,20 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)...@@ -548,20 +555,20 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
548555
549 assert(field_names.length == field_types.length);556 assert(field_names.length == field_types.length);
550 Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name));557 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
553 return_type->promise_frame_parent = entry;560 return_type->promise_frame_parent = entry;
554 return entry;561 return entry;
555}562}
556563
557TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {564ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
558 if (child_type->optional_parent) {565 if (child_type->optional_parent) {
559 TypeTableEntry *entry = child_type->optional_parent;566 ZigType *entry = child_type->optional_parent;
560 return entry;567 return entry;
561 } else {568 } else {
562 assertNoError(ensure_complete_type(g, child_type));569 assertNoError(ensure_complete_type(g, child_type));
563570
564 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);571 ZigType *entry = new_type_table_entry(ZigTypeIdOptional);
565 assert(child_type->type_ref || child_type->zero_bits);572 assert(child_type->type_ref || child_type->zero_bits);
566 entry->is_copyable = type_is_copyable(g, child_type).unwrap();573 entry->is_copyable = type_is_copyable(g, child_type).unwrap();
567574
...@@ -599,7 +606,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {...@@ -599,7 +606,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
599 uint64_t val_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, child_type->type_ref);606 uint64_t val_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, child_type->type_ref);
600 uint64_t val_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);607 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;
603 uint64_t maybe_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, bool_type->type_ref);610 uint64_t maybe_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, bool_type->type_ref);
604 uint64_t maybe_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, bool_type->type_ref);611 uint64_t maybe_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, bool_type->type_ref);
605 uint64_t maybe_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);612 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) {...@@ -638,12 +645,12 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
638 }645 }
639}646}
640647
641TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) {648ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) {
642 assert(err_set_type->id == TypeTableEntryIdErrorSet);649 assert(err_set_type->id == ZigTypeIdErrorSet);
643 assert(!type_is_invalid(payload_type));650 assert(!type_is_invalid(payload_type));
644651
645 TypeId type_id = {};652 TypeId type_id = {};
646 type_id.id = TypeTableEntryIdErrorUnion;653 type_id.id = ZigTypeIdErrorUnion;
647 type_id.data.error_union.err_set_type = err_set_type;654 type_id.data.error_union.err_set_type = err_set_type;
648 type_id.data.error_union.payload_type = payload_type;655 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...@@ -652,7 +659,7 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
652 return existing_entry->value;659 return existing_entry->value;
653 }660 }
654661
655 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorUnion);662 ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion);
656 entry->is_copyable = true;663 entry->is_copyable = true;
657 assert(payload_type->di_type);664 assert(payload_type->di_type);
658 assertNoError(ensure_complete_type(g, payload_type));665 assertNoError(ensure_complete_type(g, payload_type));
...@@ -733,20 +740,20 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T...@@ -733,20 +740,20 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
733 return entry;740 return entry;
734}741}
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) {
737 TypeId type_id = {};744 TypeId type_id = {};
738 type_id.id = TypeTableEntryIdArray;745 type_id.id = ZigTypeIdArray;
739 type_id.data.array.child_type = child_type;746 type_id.data.array.child_type = child_type;
740 type_id.data.array.size = array_size;747 type_id.data.array.size = array_size;
741 auto existing_entry = g->type_table.maybe_get(type_id);748 auto existing_entry = g->type_table.maybe_get(type_id);
742 if (existing_entry) {749 if (existing_entry) {
743 TypeTableEntry *entry = existing_entry->value;750 ZigType *entry = existing_entry->value;
744 return entry;751 return entry;
745 }752 }
746753
747 assertNoError(ensure_complete_type(g, child_type));754 assertNoError(ensure_complete_type(g, child_type));
748755
749 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArray);756 ZigType *entry = new_type_table_entry(ZigTypeIdArray);
750 entry->zero_bits = (array_size == 0) || child_type->zero_bits;757 entry->zero_bits = (array_size == 0) || child_type->zero_bits;
751 entry->is_copyable = false;758 entry->is_copyable = false;
752759
...@@ -773,7 +780,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t...@@ -773,7 +780,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
773 return entry;780 return entry;
774}781}
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) {
777 unsigned element_count = 2;784 unsigned element_count = 2;
778 Buf *ptr_field_name = buf_create_from_str("ptr");785 Buf *ptr_field_name = buf_create_from_str("ptr");
779 Buf *len_field_name = buf_create_from_str("len");786 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...@@ -804,16 +811,16 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ
804 }811 }
805}812}
806813
807TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {814ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
808 assert(ptr_type->id == TypeTableEntryIdPointer);815 assert(ptr_type->id == ZigTypeIdPointer);
809 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);816 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;
812 if (*parent_pointer) {819 if (*parent_pointer) {
813 return *parent_pointer;820 return *parent_pointer;
814 }821 }
815822
816 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct);823 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
817 entry->is_copyable = true;824 entry->is_copyable = true;
818825
819 // replace the & with [] to go from a ptr type name to a slice type name826 // 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) {...@@ -821,14 +828,14 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
821 size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3;828 size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3;
822 buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + name_offset);829 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;
825 uint32_t abi_alignment = get_abi_alignment(g, child_type);832 uint32_t abi_alignment = get_abi_alignment(g, child_type);
826 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||833 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
827 ptr_type->data.pointer.alignment != abi_alignment)834 ptr_type->data.pointer.alignment != abi_alignment)
828 {835 {
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,
830 PtrLenUnknown, abi_alignment, 0, 0);837 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
833 slice_type_common_init(g, ptr_type, entry);840 slice_type_common_init(g, ptr_type, entry);
834841
...@@ -845,18 +852,18 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {...@@ -845,18 +852,18 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
845 // If the child type is []const T then we need to make sure the type ref852 // If the child type is []const T then we need to make sure the type ref
846 // and debug info is the same as if the child type were []T.853 // and debug info is the same as if the child type were []T.
847 if (is_slice(child_type)) {854 if (is_slice(child_type)) {
848 TypeTableEntry *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;855 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
849 assert(child_ptr_type->id == TypeTableEntryIdPointer);856 assert(child_ptr_type->id == ZigTypeIdPointer);
850 TypeTableEntry *grand_child_type = child_ptr_type->data.pointer.child_type;857 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
851 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||858 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
852 child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))859 child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))
853 {860 {
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,
855 PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0);862 PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0);
856 TypeTableEntry *bland_child_slice = get_slice_type(g, bland_child_ptr_type);863 ZigType *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,864 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
858 PtrLenUnknown, get_abi_alignment(g, bland_child_slice), 0, 0);865 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
861 entry->type_ref = peer_slice_type->type_ref;868 entry->type_ref = peer_slice_type->type_ref;
862 entry->di_type = peer_slice_type->di_type;869 entry->di_type = peer_slice_type->di_type;
...@@ -882,7 +889,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {...@@ -882,7 +889,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
882 };889 };
883 LLVMStructSetBody(entry->type_ref, element_types, 1, false);890 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;
886 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);893 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
887 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);894 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
888 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);895 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) {...@@ -921,7 +928,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
921 uint64_t ptr_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->type_ref);928 uint64_t ptr_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->type_ref);
922 uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);929 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;
925 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);932 uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
926 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);933 uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
927 uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);934 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) {...@@ -964,8 +971,8 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
964 return entry;971 return entry;
965}972}
966973
967TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {974ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
968 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque);975 ZigType *entry = new_type_table_entry(ZigTypeIdOpaque);
969976
970 buf_init_from_str(&entry->name, name);977 buf_init_from_str(&entry->name, name);
971978
...@@ -984,13 +991,13 @@ TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node,...@@ -984,13 +991,13 @@ TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node,
984 return entry;991 return entry;
985}992}
986993
987TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {994ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
988 TypeTableEntry *fn_type = fn_entry->type_entry;995 ZigType *fn_type = fn_entry->type_entry;
989 assert(fn_type->id == TypeTableEntryIdFn);996 assert(fn_type->id == ZigTypeIdFn);
990 if (fn_type->data.fn.bound_fn_parent)997 if (fn_type->data.fn.bound_fn_parent)
991 return fn_type->data.fn.bound_fn_parent;998 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);
994 bound_fn_type->is_copyable = false;1001 bound_fn_type->is_copyable = false;
995 bound_fn_type->data.bound_fn.fn_type = fn_type;1002 bound_fn_type->data.bound_fn.fn_type = fn_type;
996 bound_fn_type->zero_bits = true;1003 bound_fn_type->zero_bits = true;
...@@ -1002,11 +1009,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {...@@ -1002,11 +1009,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {
1002 return bound_fn_type;1009 return bound_fn_type;
1003}1010}
10041011
1005bool calling_convention_does_first_arg_return(CallingConvention cc) {1012const char *calling_convention_name(CallingConvention cc) {
1006 return cc == CallingConventionUnspecified;
1007}
1008
1009static const char *calling_convention_name(CallingConvention cc) {
1010 switch (cc) {1013 switch (cc) {
1011 case CallingConventionUnspecified: return "undefined";1014 case CallingConventionUnspecified: return "undefined";
1012 case CallingConventionC: return "ccc";1015 case CallingConventionC: return "ccc";
...@@ -1030,7 +1033,7 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) {...@@ -1030,7 +1033,7 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) {
1030 zig_unreachable();1033 zig_unreachable();
1031}1034}
10321035
1033static bool calling_convention_allows_zig_types(CallingConvention cc) {1036bool calling_convention_allows_zig_types(CallingConvention cc) {
1034 switch (cc) {1037 switch (cc) {
1035 case CallingConventionUnspecified:1038 case CallingConventionUnspecified:
1036 case CallingConventionAsync:1039 case CallingConventionAsync:
...@@ -1044,17 +1047,38 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -1044,17 +1047,38 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {
1044 zig_unreachable();1047 zig_unreachable();
1045}1048}
10461049
1047TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) {1050ZigType *get_ptr_to_stack_trace_type(CodeGen *g) {
1048 if (g->stack_trace_type == nullptr) {1051 if (g->stack_trace_type == nullptr) {
1049 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");1052 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);
1051 g->stack_trace_type = stack_trace_type_val->data.x_type;1054 g->stack_trace_type = stack_trace_type_val->data.x_type;
1052 g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);1055 g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);
1053 }1056 }
1054 return g->ptr_to_stack_trace_type;1057 return g->ptr_to_stack_trace_type;
1055}1058}
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) {
1058 Error err;1082 Error err;
1059 auto table_entry = g->fn_type_table.maybe_get(fn_type_id);1083 auto table_entry = g->fn_type_table.maybe_get(fn_type_id);
1060 if (table_entry) {1084 if (table_entry) {
...@@ -1063,12 +1087,12 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1063,12 +1087,12 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1063 if (fn_type_id->return_type != nullptr) {1087 if (fn_type_id->return_type != nullptr) {
1064 if ((err = ensure_complete_type(g, fn_type_id->return_type)))1088 if ((err = ensure_complete_type(g, fn_type_id->return_type)))
1065 return g->builtin_types.entry_invalid;1089 return g->builtin_types.entry_invalid;
1066 assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);1090 assert(fn_type_id->return_type->id != ZigTypeIdOpaque);
1067 } else {1091 } else {
1068 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");1092 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
1069 }1093 }
10701094
1071 TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);1095 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1072 fn_type->is_copyable = true;1096 fn_type->is_copyable = true;
1073 fn_type->data.fn.fn_type_id = *fn_type_id;1097 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) {...@@ -1087,7 +1111,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1087 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {1111 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
1088 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];1112 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
10891113
1090 TypeTableEntry *param_type = param_info->type;1114 ZigType *param_type = param_info->type;
1091 const char *comma = (i == 0) ? "" : ", ";1115 const char *comma = (i == 0) ? "" : ", ";
1092 const char *noalias_str = param_info->is_noalias ? "noalias " : "";1116 const char *noalias_str = param_info->is_noalias ? "noalias " : "";
1093 buf_appendf(&fn_type->name, "%s%s%s", comma, noalias_str, buf_ptr(&param_type->name));1117 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) {...@@ -1109,32 +1133,29 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1109 // next, loop over the parameters again and compute debug information1133 // next, loop over the parameters again and compute debug information
1110 // and codegen information1134 // and codegen information
1111 if (!skip_debug_info) {1135 if (!skip_debug_info) {
1112 bool first_arg_return = calling_convention_does_first_arg_return(fn_type_id->cc) &&1136 bool first_arg_return = want_first_arg_sret(g, fn_type_id);
1113 handle_is_ptr(fn_type_id->return_type);
1114 bool is_async = fn_type_id->cc == CallingConventionAsync;1137 bool is_async = fn_type_id->cc == CallingConventionAsync;
1138 bool is_c_abi = fn_type_id->cc == CallingConventionC;
1115 bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id);1139 bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id);
1116 // +1 for maybe making the first argument the return value1140 // +1 for maybe making the first argument the return value
1117 // +1 for maybe first argument the error return trace1141 // +1 for maybe first argument the error return trace
1118 // +2 for maybe arguments async allocator and error code pointer1142 // +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 = {};
1120 // +1 because 0 is the return type and1144 // +1 because 0 is the return type and
1121 // +1 for maybe making first arg ret val and1145 // +1 for maybe making first arg ret val and
1122 // +1 for maybe first argument the error return trace1146 // +1 for maybe first argument the error return trace
1123 // +2 for maybe arguments async allocator and error code pointer1147 // +2 for maybe arguments async allocator and error code pointer
1124 ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(5 + fn_type_id->param_count);1148 ZigList<ZigLLVMDIType *> param_di_types = {};
1125 param_di_types[0] = fn_type_id->return_type->di_type;1149 param_di_types.append(fn_type_id->return_type->di_type);
1126 size_t gen_param_index = 0;1150 ZigType *gen_return_type;
1127 TypeTableEntry *gen_return_type;
1128 if (is_async) {1151 if (is_async) {
1129 gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);1152 gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
1130 } else if (!type_has_bits(fn_type_id->return_type)) {1153 } else if (!type_has_bits(fn_type_id->return_type)) {
1131 gen_return_type = g->builtin_types.entry_void;1154 gen_return_type = g->builtin_types.entry_void;
1132 } else if (first_arg_return) {1155 } else if (first_arg_return) {
1133 TypeTableEntry *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);1156 ZigType *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);
1134 gen_param_types[gen_param_index] = gen_type->type_ref;1157 gen_param_types.append(gen_type->type_ref);
1135 gen_param_index += 1;1158 param_di_types.append(gen_type->di_type);
1136 // after the gen_param_index += 1 because 0 is the return type
1137 param_di_types[gen_param_index] = gen_type->di_type;
1138 gen_return_type = g->builtin_types.entry_void;1159 gen_return_type = g->builtin_types.entry_void;
1139 } else {1160 } else {
1140 gen_return_type = fn_type_id->return_type;1161 gen_return_type = fn_type_id->return_type;
...@@ -1142,36 +1163,30 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1142,36 +1163,30 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1142 fn_type->data.fn.gen_return_type = gen_return_type;1163 fn_type->data.fn.gen_return_type = gen_return_type;
11431164
1144 if (prefix_arg_error_return_trace) {1165 if (prefix_arg_error_return_trace) {
1145 TypeTableEntry *gen_type = get_ptr_to_stack_trace_type(g);1166 ZigType *gen_type = get_ptr_to_stack_trace_type(g);
1146 gen_param_types[gen_param_index] = gen_type->type_ref;1167 gen_param_types.append(gen_type->type_ref);
1147 gen_param_index += 1;1168 param_di_types.append(gen_type->di_type);
1148 // after the gen_param_index += 1 because 0 is the return type
1149 param_di_types[gen_param_index] = gen_type->di_type;
1150 }1169 }
1151 if (is_async) {1170 if (is_async) {
1152 {1171 {
1153 // async allocator param1172 // async allocator param
1154 TypeTableEntry *gen_type = fn_type_id->async_allocator_type;1173 ZigType *gen_type = fn_type_id->async_allocator_type;
1155 gen_param_types[gen_param_index] = gen_type->type_ref;1174 gen_param_types.append(gen_type->type_ref);
1156 gen_param_index += 1;1175 param_di_types.append(gen_type->di_type);
1157 // after the gen_param_index += 1 because 0 is the return type
1158 param_di_types[gen_param_index] = gen_type->di_type;
1159 }1176 }
11601177
1161 {1178 {
1162 // error code pointer1179 // error code pointer
1163 TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);1180 ZigType *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;1181 gen_param_types.append(gen_type->type_ref);
1165 gen_param_index += 1;1182 param_di_types.append(gen_type->di_type);
1166 // after the gen_param_index += 1 because 0 is the return type
1167 param_di_types[gen_param_index] = gen_type->di_type;
1168 }1183 }
1169 }1184 }
11701185
1171 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);1186 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
1172 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {1187 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
1173 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];1188 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;
1175 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];1190 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
11761191
1177 gen_param_info->src_index = i;1192 gen_param_info->src_index = i;
...@@ -1180,31 +1195,39 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1180,31 +1195,39 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1180 if ((err = ensure_complete_type(g, type_entry)))1195 if ((err = ensure_complete_type(g, type_entry)))
1181 return g->builtin_types.entry_invalid;1196 return g->builtin_types.entry_invalid;
11821197
1198 if (is_c_abi)
1199 continue;
1200
1183 if (type_has_bits(type_entry)) {1201 if (type_has_bits(type_entry)) {
1184 TypeTableEntry *gen_type;1202 ZigType *gen_type;
1185 if (handle_is_ptr(type_entry)) {1203 if (handle_is_ptr(type_entry)) {
1186 gen_type = get_pointer_to_type(g, type_entry, true);1204 gen_type = get_pointer_to_type(g, type_entry, true);
1187 gen_param_info->is_byval = true;1205 gen_param_info->is_byval = true;
1188 } else {1206 } else {
1189 gen_type = type_entry;1207 gen_type = type_entry;
1190 }1208 }
1191 gen_param_types[gen_param_index] = gen_type->type_ref;1209 gen_param_info->gen_index = gen_param_types.length;
1192 gen_param_info->gen_index = gen_param_index;
1193 gen_param_info->type = gen_type;1210 gen_param_info->type = gen_type;
1211 gen_param_types.append(gen_type->type_ref);
11941212
1195 gen_param_index += 1;1213 param_di_types.append(gen_type->di_type);
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;
1199 }1214 }
1200 }1215 }
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
1204 fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref,1227 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);
1206 fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0);1229 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);
1208 }1231 }
12091232
1210 g->fn_type_table.put(&fn_type->data.fn.fn_type_id, fn_type);1233 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) {...@@ -1212,23 +1235,23 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1212 return fn_type;1235 return fn_type;
1213}1236}
12141237
1215static TypeTableEntryId container_to_type(ContainerKind kind) {1238static ZigTypeId container_to_type(ContainerKind kind) {
1216 switch (kind) {1239 switch (kind) {
1217 case ContainerKindStruct:1240 case ContainerKindStruct:
1218 return TypeTableEntryIdStruct;1241 return ZigTypeIdStruct;
1219 case ContainerKindEnum:1242 case ContainerKindEnum:
1220 return TypeTableEntryIdEnum;1243 return ZigTypeIdEnum;
1221 case ContainerKindUnion:1244 case ContainerKindUnion:
1222 return TypeTableEntryIdUnion;1245 return ZigTypeIdUnion;
1223 }1246 }
1224 zig_unreachable();1247 zig_unreachable();
1225}1248}
12261249
1227TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,1250ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
1228 AstNode *decl_node, const char *name, ContainerLayout layout)1251 AstNode *decl_node, const char *name, ContainerLayout layout)
1229{1252{
1230 TypeTableEntryId type_id = container_to_type(kind);1253 ZigTypeId type_id = container_to_type(kind);
1231 TypeTableEntry *entry = new_container_type_entry(type_id, decl_node, scope);1254 ZigType *entry = new_container_type_entry(type_id, decl_node, scope);
12321255
1233 switch (kind) {1256 switch (kind) {
1234 case ContainerKindStruct:1257 case ContainerKindStruct:
...@@ -1259,24 +1282,24 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi...@@ -1259,24 +1282,24 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
1259 return entry;1282 return entry;
1260}1283}
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) {
1263 size_t backward_branch_count = 0;1286 size_t backward_branch_count = 0;
1264 return ir_eval_const_value(g, scope, node, type_entry,1287 return ir_eval_const_value(g, scope, node, type_entry,
1265 &backward_branch_count, default_backward_branch_quota,1288 &backward_branch_count, default_backward_branch_quota,
1266 nullptr, nullptr, node, type_name, nullptr);1289 nullptr, nullptr, node, type_name, nullptr);
1267}1290}
12681291
1269TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {1292ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1270 IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);1293 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)
1272 return g->builtin_types.entry_invalid;1295 return g->builtin_types.entry_invalid;
12731296
1274 assert(result->value.special != ConstValSpecialRuntime);1297 assert(result->value.special != ConstValSpecialRuntime);
1275 return result->value.data.x_type;1298 return result->value.data.x_type;
1276}1299}
12771300
1278TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {1301ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1279 TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);1302 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1280 fn_type->is_copyable = false;1303 fn_type->is_copyable = false;
1281 buf_resize(&fn_type->name, 0);1304 buf_resize(&fn_type->name, 0);
1282 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {1305 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_...@@ -1343,9 +1366,9 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
1343}1366}
13441367
1345static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) {1368static 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,
1347 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);1370 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);
1349 IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);1372 IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);
1350 if (type_is_invalid(instr->value.type))1373 if (type_is_invalid(instr->value.type))
1351 return false;1374 return false;
...@@ -1375,71 +1398,71 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1375,71 +1398,71 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1375 return true;1398 return true;
1376}1399}
13771400
1378static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {1401static bool type_allowed_in_packed_struct(ZigType *type_entry) {
1379 switch (type_entry->id) {1402 switch (type_entry->id) {
1380 case TypeTableEntryIdInvalid:1403 case ZigTypeIdInvalid:
1381 zig_unreachable();1404 zig_unreachable();
1382 case TypeTableEntryIdMetaType:1405 case ZigTypeIdMetaType:
1383 case TypeTableEntryIdUnreachable:1406 case ZigTypeIdUnreachable:
1384 case TypeTableEntryIdComptimeFloat:1407 case ZigTypeIdComptimeFloat:
1385 case TypeTableEntryIdComptimeInt:1408 case ZigTypeIdComptimeInt:
1386 case TypeTableEntryIdUndefined:1409 case ZigTypeIdUndefined:
1387 case TypeTableEntryIdNull:1410 case ZigTypeIdNull:
1388 case TypeTableEntryIdErrorUnion:1411 case ZigTypeIdErrorUnion:
1389 case TypeTableEntryIdErrorSet:1412 case ZigTypeIdErrorSet:
1390 case TypeTableEntryIdNamespace:1413 case ZigTypeIdNamespace:
1391 case TypeTableEntryIdBlock:1414 case ZigTypeIdBlock:
1392 case TypeTableEntryIdBoundFn:1415 case ZigTypeIdBoundFn:
1393 case TypeTableEntryIdArgTuple:1416 case ZigTypeIdArgTuple:
1394 case TypeTableEntryIdOpaque:1417 case ZigTypeIdOpaque:
1395 case TypeTableEntryIdPromise:1418 case ZigTypeIdPromise:
1396 return false;1419 return false;
1397 case TypeTableEntryIdVoid:1420 case ZigTypeIdVoid:
1398 case TypeTableEntryIdBool:1421 case ZigTypeIdBool:
1399 case TypeTableEntryIdInt:1422 case ZigTypeIdInt:
1400 case TypeTableEntryIdFloat:1423 case ZigTypeIdFloat:
1401 case TypeTableEntryIdPointer:1424 case ZigTypeIdPointer:
1402 case TypeTableEntryIdArray:1425 case ZigTypeIdArray:
1403 case TypeTableEntryIdFn:1426 case ZigTypeIdFn:
1404 return true;1427 return true;
1405 case TypeTableEntryIdStruct:1428 case ZigTypeIdStruct:
1406 return type_entry->data.structure.layout == ContainerLayoutPacked;1429 return type_entry->data.structure.layout == ContainerLayoutPacked;
1407 case TypeTableEntryIdUnion:1430 case ZigTypeIdUnion:
1408 return type_entry->data.unionation.layout == ContainerLayoutPacked;1431 return type_entry->data.unionation.layout == ContainerLayoutPacked;
1409 case TypeTableEntryIdOptional:1432 case ZigTypeIdOptional:
1410 {1433 {
1411 TypeTableEntry *child_type = type_entry->data.maybe.child_type;1434 ZigType *child_type = type_entry->data.maybe.child_type;
1412 return type_is_codegen_pointer(child_type);1435 return type_is_codegen_pointer(child_type);
1413 }1436 }
1414 case TypeTableEntryIdEnum:1437 case ZigTypeIdEnum:
1415 return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;1438 return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;
1416 }1439 }
1417 zig_unreachable();1440 zig_unreachable();
1418}1441}
14191442
1420static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {1443static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
1421 switch (type_entry->id) {1444 switch (type_entry->id) {
1422 case TypeTableEntryIdInvalid:1445 case ZigTypeIdInvalid:
1423 zig_unreachable();1446 zig_unreachable();
1424 case TypeTableEntryIdMetaType:1447 case ZigTypeIdMetaType:
1425 case TypeTableEntryIdComptimeFloat:1448 case ZigTypeIdComptimeFloat:
1426 case TypeTableEntryIdComptimeInt:1449 case ZigTypeIdComptimeInt:
1427 case TypeTableEntryIdUndefined:1450 case ZigTypeIdUndefined:
1428 case TypeTableEntryIdNull:1451 case ZigTypeIdNull:
1429 case TypeTableEntryIdErrorUnion:1452 case ZigTypeIdErrorUnion:
1430 case TypeTableEntryIdErrorSet:1453 case ZigTypeIdErrorSet:
1431 case TypeTableEntryIdNamespace:1454 case ZigTypeIdNamespace:
1432 case TypeTableEntryIdBlock:1455 case ZigTypeIdBlock:
1433 case TypeTableEntryIdBoundFn:1456 case ZigTypeIdBoundFn:
1434 case TypeTableEntryIdArgTuple:1457 case ZigTypeIdArgTuple:
1435 case TypeTableEntryIdPromise:1458 case ZigTypeIdPromise:
1436 case TypeTableEntryIdVoid:1459 case ZigTypeIdVoid:
1437 return false;1460 return false;
1438 case TypeTableEntryIdOpaque:1461 case ZigTypeIdOpaque:
1439 case TypeTableEntryIdUnreachable:1462 case ZigTypeIdUnreachable:
1440 case TypeTableEntryIdBool:1463 case ZigTypeIdBool:
1441 return true;1464 return true;
1442 case TypeTableEntryIdInt:1465 case ZigTypeIdInt:
1443 switch (type_entry->data.integral.bit_count) {1466 switch (type_entry->data.integral.bit_count) {
1444 case 8:1467 case 8:
1445 case 16:1468 case 16:
...@@ -1450,36 +1473,36 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {...@@ -1450,36 +1473,36 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
1450 default:1473 default:
1451 return false;1474 return false;
1452 }1475 }
1453 case TypeTableEntryIdFloat:1476 case ZigTypeIdFloat:
1454 return true;1477 return true;
1455 case TypeTableEntryIdArray:1478 case ZigTypeIdArray:
1456 return type_allowed_in_extern(g, type_entry->data.array.child_type);1479 return type_allowed_in_extern(g, type_entry->data.array.child_type);
1457 case TypeTableEntryIdFn:1480 case ZigTypeIdFn:
1458 return type_entry->data.fn.fn_type_id.cc == CallingConventionC;1481 return type_entry->data.fn.fn_type_id.cc == CallingConventionC;
1459 case TypeTableEntryIdPointer:1482 case ZigTypeIdPointer:
1460 if (type_size(g, type_entry) == 0)1483 if (type_size(g, type_entry) == 0)
1461 return false;1484 return false;
1462 return true;1485 return true;
1463 case TypeTableEntryIdStruct:1486 case ZigTypeIdStruct:
1464 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;1487 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
1465 case TypeTableEntryIdOptional:1488 case ZigTypeIdOptional:
1466 {1489 {
1467 TypeTableEntry *child_type = type_entry->data.maybe.child_type;1490 ZigType *child_type = type_entry->data.maybe.child_type;
1468 if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) {1491 if (child_type->id != ZigTypeIdPointer && child_type->id != ZigTypeIdFn) {
1469 return false;1492 return false;
1470 }1493 }
1471 return type_allowed_in_extern(g, child_type);1494 return type_allowed_in_extern(g, child_type);
1472 }1495 }
1473 case TypeTableEntryIdEnum:1496 case ZigTypeIdEnum:
1474 return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;1497 return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;
1475 case TypeTableEntryIdUnion:1498 case ZigTypeIdUnion:
1476 return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;1499 return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;
1477 }1500 }
1478 zig_unreachable();1501 zig_unreachable();
1479}1502}
14801503
1481TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {1504ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1482 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);1505 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
1483 buf_resize(&err_set_type->name, 0);1506 buf_resize(&err_set_type->name, 0);
1484 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));1507 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
1485 err_set_type->is_copyable = true;1508 err_set_type->is_copyable = true;
...@@ -1494,7 +1517,7 @@ TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {...@@ -1494,7 +1517,7 @@ TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
1494 return err_set_type;1517 return err_set_type;
1495}1518}
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) {
1498 assert(proto_node->type == NodeTypeFnProto);1521 assert(proto_node->type == NodeTypeFnProto);
1499 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;1522 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
1500 Error err;1523 Error err;
...@@ -1517,7 +1540,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1517,7 +1540,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1517 return g->builtin_types.entry_invalid;1540 return g->builtin_types.entry_invalid;
1518 }1541 }
1519 if (param_node->data.param_decl.type != nullptr) {1542 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);
1521 if (type_is_invalid(type_entry)) {1544 if (type_is_invalid(type_entry)) {
1522 return g->builtin_types.entry_invalid;1545 return g->builtin_types.entry_invalid;
1523 }1546 }
...@@ -1550,7 +1573,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1550,7 +1573,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1550 return get_generic_fn_type(g, &fn_type_id);1573 return get_generic_fn_type(g, &fn_type_id);
1551 }1574 }
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);
1554 if (type_is_invalid(type_entry)) {1577 if (type_is_invalid(type_entry)) {
1555 return g->builtin_types.entry_invalid;1578 return g->builtin_types.entry_invalid;
1556 }1579 }
...@@ -1574,36 +1597,36 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1574,36 +1597,36 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1574 }1597 }
15751598
1576 switch (type_entry->id) {1599 switch (type_entry->id) {
1577 case TypeTableEntryIdInvalid:1600 case ZigTypeIdInvalid:
1578 zig_unreachable();1601 zig_unreachable();
1579 case TypeTableEntryIdUnreachable:1602 case ZigTypeIdUnreachable:
1580 case TypeTableEntryIdUndefined:1603 case ZigTypeIdUndefined:
1581 case TypeTableEntryIdNull:1604 case ZigTypeIdNull:
1582 case TypeTableEntryIdArgTuple:1605 case ZigTypeIdArgTuple:
1583 case TypeTableEntryIdOpaque:1606 case ZigTypeIdOpaque:
1584 add_node_error(g, param_node->data.param_decl.type,1607 add_node_error(g, param_node->data.param_decl.type,
1585 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));1608 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
1586 return g->builtin_types.entry_invalid;1609 return g->builtin_types.entry_invalid;
1587 case TypeTableEntryIdComptimeFloat:1610 case ZigTypeIdComptimeFloat:
1588 case TypeTableEntryIdComptimeInt:1611 case ZigTypeIdComptimeInt:
1589 case TypeTableEntryIdNamespace:1612 case ZigTypeIdNamespace:
1590 case TypeTableEntryIdBlock:1613 case ZigTypeIdBlock:
1591 case TypeTableEntryIdBoundFn:1614 case ZigTypeIdBoundFn:
1592 case TypeTableEntryIdMetaType:1615 case ZigTypeIdMetaType:
1593 case TypeTableEntryIdVoid:1616 case ZigTypeIdVoid:
1594 case TypeTableEntryIdBool:1617 case ZigTypeIdBool:
1595 case TypeTableEntryIdInt:1618 case ZigTypeIdInt:
1596 case TypeTableEntryIdFloat:1619 case ZigTypeIdFloat:
1597 case TypeTableEntryIdPointer:1620 case ZigTypeIdPointer:
1598 case TypeTableEntryIdArray:1621 case ZigTypeIdArray:
1599 case TypeTableEntryIdStruct:1622 case ZigTypeIdStruct:
1600 case TypeTableEntryIdOptional:1623 case ZigTypeIdOptional:
1601 case TypeTableEntryIdErrorUnion:1624 case ZigTypeIdErrorUnion:
1602 case TypeTableEntryIdErrorSet:1625 case ZigTypeIdErrorSet:
1603 case TypeTableEntryIdEnum:1626 case ZigTypeIdEnum:
1604 case TypeTableEntryIdUnion:1627 case ZigTypeIdUnion:
1605 case TypeTableEntryIdFn:1628 case ZigTypeIdFn:
1606 case TypeTableEntryIdPromise:1629 case ZigTypeIdPromise:
1607 if ((err = type_ensure_zero_bits_known(g, type_entry)))1630 if ((err = type_ensure_zero_bits_known(g, type_entry)))
1608 return g->builtin_types.entry_invalid;1631 return g->builtin_types.entry_invalid;
1609 if (type_requires_comptime(type_entry)) {1632 if (type_requires_comptime(type_entry)) {
...@@ -1638,21 +1661,21 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1638,21 +1661,21 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1638 //return get_generic_fn_type(g, &fn_type_id);1661 //return get_generic_fn_type(g, &fn_type_id);
1639 }1662 }
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);
1642 if (type_is_invalid(specified_return_type)) {1665 if (type_is_invalid(specified_return_type)) {
1643 fn_type_id.return_type = g->builtin_types.entry_invalid;1666 fn_type_id.return_type = g->builtin_types.entry_invalid;
1644 return g->builtin_types.entry_invalid;1667 return g->builtin_types.entry_invalid;
1645 }1668 }
16461669
1647 if (fn_proto->auto_err_set) {1670 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);
1649 fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type);1672 fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type);
1650 } else {1673 } else {
1651 fn_type_id.return_type = specified_return_type;1674 fn_type_id.return_type = specified_return_type;
1652 }1675 }
16531676
1654 if (!calling_convention_allows_zig_types(fn_type_id.cc) &&1677 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 &&
1656 !type_allowed_in_extern(g, fn_type_id.return_type))1679 !type_allowed_in_extern(g, fn_type_id.return_type))
1657 {1680 {
1658 add_node_error(g, fn_proto->return_type,1681 add_node_error(g, fn_proto->return_type,
...@@ -1663,38 +1686,38 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1663,38 +1686,38 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1663 }1686 }
16641687
1665 switch (fn_type_id.return_type->id) {1688 switch (fn_type_id.return_type->id) {
1666 case TypeTableEntryIdInvalid:1689 case ZigTypeIdInvalid:
1667 zig_unreachable();1690 zig_unreachable();
16681691
1669 case TypeTableEntryIdUndefined:1692 case ZigTypeIdUndefined:
1670 case TypeTableEntryIdNull:1693 case ZigTypeIdNull:
1671 case TypeTableEntryIdArgTuple:1694 case ZigTypeIdArgTuple:
1672 case TypeTableEntryIdOpaque:1695 case ZigTypeIdOpaque:
1673 add_node_error(g, fn_proto->return_type,1696 add_node_error(g, fn_proto->return_type,
1674 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));1697 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
1675 return g->builtin_types.entry_invalid;1698 return g->builtin_types.entry_invalid;
16761699
1677 case TypeTableEntryIdComptimeFloat:1700 case ZigTypeIdComptimeFloat:
1678 case TypeTableEntryIdComptimeInt:1701 case ZigTypeIdComptimeInt:
1679 case TypeTableEntryIdNamespace:1702 case ZigTypeIdNamespace:
1680 case TypeTableEntryIdBlock:1703 case ZigTypeIdBlock:
1681 case TypeTableEntryIdBoundFn:1704 case ZigTypeIdBoundFn:
1682 case TypeTableEntryIdMetaType:1705 case ZigTypeIdMetaType:
1683 case TypeTableEntryIdUnreachable:1706 case ZigTypeIdUnreachable:
1684 case TypeTableEntryIdVoid:1707 case ZigTypeIdVoid:
1685 case TypeTableEntryIdBool:1708 case ZigTypeIdBool:
1686 case TypeTableEntryIdInt:1709 case ZigTypeIdInt:
1687 case TypeTableEntryIdFloat:1710 case ZigTypeIdFloat:
1688 case TypeTableEntryIdPointer:1711 case ZigTypeIdPointer:
1689 case TypeTableEntryIdArray:1712 case ZigTypeIdArray:
1690 case TypeTableEntryIdStruct:1713 case ZigTypeIdStruct:
1691 case TypeTableEntryIdOptional:1714 case ZigTypeIdOptional:
1692 case TypeTableEntryIdErrorUnion:1715 case ZigTypeIdErrorUnion:
1693 case TypeTableEntryIdErrorSet:1716 case ZigTypeIdErrorSet:
1694 case TypeTableEntryIdEnum:1717 case ZigTypeIdEnum:
1695 case TypeTableEntryIdUnion:1718 case ZigTypeIdUnion:
1696 case TypeTableEntryIdFn:1719 case ZigTypeIdFn:
1697 case TypeTableEntryIdPromise:1720 case ZigTypeIdPromise:
1698 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))1721 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
1699 return g->builtin_types.entry_invalid;1722 return g->builtin_types.entry_invalid;
1700 if (type_requires_comptime(fn_type_id.return_type)) {1723 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...@@ -1716,15 +1739,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1716 return get_fn_type(g, &fn_type_id);1739 return get_fn_type(g, &fn_type_id);
1717}1740}
17181741
1719bool type_is_invalid(TypeTableEntry *type_entry) {1742bool type_is_invalid(ZigType *type_entry) {
1720 switch (type_entry->id) {1743 switch (type_entry->id) {
1721 case TypeTableEntryIdInvalid:1744 case ZigTypeIdInvalid:
1722 return true;1745 return true;
1723 case TypeTableEntryIdStruct:1746 case ZigTypeIdStruct:
1724 return type_entry->data.structure.is_invalid;1747 return type_entry->data.structure.is_invalid;
1725 case TypeTableEntryIdEnum:1748 case ZigTypeIdEnum:
1726 return type_entry->data.enumeration.is_invalid;1749 return type_entry->data.enumeration.is_invalid;
1727 case TypeTableEntryIdUnion:1750 case ZigTypeIdUnion:
1728 return type_entry->data.unionation.is_invalid;1751 return type_entry->data.unionation.is_invalid;
1729 default:1752 default:
1730 return false;1753 return false;
...@@ -1733,8 +1756,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {...@@ -1733,8 +1756,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
1733}1756}
17341757
17351758
1736static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {1759static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1737 assert(enum_type->id == TypeTableEntryIdEnum);1760 assert(enum_type->id == ZigTypeIdEnum);
17381761
1739 if (enum_type->data.enumeration.is_invalid)1762 if (enum_type->data.enumeration.is_invalid)
1740 return ErrorSemanticAnalyzeFail;1763 return ErrorSemanticAnalyzeFail;
...@@ -1808,7 +1831,7 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {...@@ -1808,7 +1831,7 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
1808 return ErrorNone;1831 return ErrorNone;
1809 }1832 }
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
1813 // create debug type for tag1836 // create debug type for tag
1814 uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);1837 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) {...@@ -1827,10 +1850,10 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
1827}1850}
18281851
18291852
1830TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],1853ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
1831 TypeTableEntry *field_types[], size_t field_count)1854 ZigType *field_types[], size_t field_count)
1832{1855{
1833 TypeTableEntry *struct_type = new_type_table_entry(TypeTableEntryIdStruct);1856 ZigType *struct_type = new_type_table_entry(ZigTypeIdStruct);
18341857
1835 buf_init_from_str(&struct_type->name, type_name);1858 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...@@ -1874,7 +1897,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
1874 if (type_struct_field->gen_index == SIZE_MAX) {1897 if (type_struct_field->gen_index == SIZE_MAX) {
1875 continue;1898 continue;
1876 }1899 }
1877 TypeTableEntry *field_type = type_struct_field->type_entry;1900 ZigType *field_type = type_struct_field->type_entry;
1878 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref);1901 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref);
1879 uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref);1902 uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref);
1880 uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, type_struct_field->gen_index);1903 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...@@ -1906,8 +1929,8 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
1906 return struct_type;1929 return struct_type;
1907}1930}
19081931
1909static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {1932static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1910 assert(struct_type->id == TypeTableEntryIdStruct);1933 assert(struct_type->id == ZigTypeIdStruct);
19111934
1912 if (struct_type->data.structure.complete)1935 if (struct_type->data.structure.complete)
1913 return ErrorNone;1936 return ErrorNone;
...@@ -1950,7 +1973,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {...@@ -1950,7 +1973,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
19501973
1951 for (size_t i = 0; i < field_count; i += 1) {1974 for (size_t i = 0; i < field_count; i += 1) {
1952 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];1975 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
1955 if ((err = ensure_complete_type(g, field_type))) {1978 if ((err = ensure_complete_type(g, field_type))) {
1956 struct_type->data.structure.is_invalid = true;1979 struct_type->data.structure.is_invalid = true;
...@@ -2081,12 +2104,12 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2081,12 +2104,12 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
2081 continue;2104 continue;
2082 }2105 }
20832106
2084 TypeTableEntry *field_type = type_struct_field->type_entry;2107 ZigType *field_type = type_struct_field->type_entry;
20852108
2086 // if the field is a function, actually the debug info should be a pointer.2109 // if the field is a function, actually the debug info should be a pointer.
2087 ZigLLVMDIType *field_di_type;2110 ZigLLVMDIType *field_di_type;
2088 if (field_type->id == TypeTableEntryIdFn) {2111 if (field_type->id == ZigTypeIdFn) {
2089 TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true);2112 ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true);
2090 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);2113 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);
2091 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);2114 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);
2092 field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type,2115 field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type,
...@@ -2140,8 +2163,8 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2140,8 +2163,8 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
2140 return ErrorNone;2163 return ErrorNone;
2141}2164}
21422165
2143static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {2166static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2144 assert(union_type->id == TypeTableEntryIdUnion);2167 assert(union_type->id == ZigTypeIdUnion);
21452168
2146 if (union_type->data.unionation.complete)2169 if (union_type->data.unionation.complete)
2147 return ErrorNone;2170 return ErrorNone;
...@@ -2172,7 +2195,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2172,7 +2195,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
2172 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;2195 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
2173 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);2196 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;
2176 uint64_t size_of_most_aligned_member_in_bits = 0;2199 uint64_t size_of_most_aligned_member_in_bits = 0;
2177 uint64_t biggest_align_in_bits = 0;2200 uint64_t biggest_align_in_bits = 0;
2178 uint64_t biggest_size_in_bits = 0;2201 uint64_t biggest_size_in_bits = 0;
...@@ -2187,7 +2210,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2187,7 +2210,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
2187 for (uint32_t i = 0; i < field_count; i += 1) {2210 for (uint32_t i = 0; i < field_count; i += 1) {
2188 AstNode *field_node = decl_node->data.container_decl.fields.at(i);2211 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
2189 TypeUnionField *union_field = &union_type->data.unionation.fields[i];2212 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
2192 if ((err = ensure_complete_type(g, field_type))) {2215 if ((err = ensure_complete_type(g, field_type))) {
2193 union_type->data.unionation.is_invalid = true;2216 union_type->data.unionation.is_invalid = true;
...@@ -2252,13 +2275,13 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2252,13 +2275,13 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
22522275
2253 uint64_t padding_in_bits = biggest_size_in_bits - size_of_most_aligned_member_in_bits;2276 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;
2256 if (tag_type == nullptr || tag_type->zero_bits) {2279 if (tag_type == nullptr || tag_type->zero_bits) {
2257 assert(most_aligned_union_member != nullptr);2280 assert(most_aligned_union_member != nullptr);
22582281
2259 if (padding_in_bits > 0) {2282 if (padding_in_bits > 0) {
2260 TypeTableEntry *u8_type = get_int_type(g, false, 8);2283 ZigType *u8_type = get_int_type(g, false, 8);
2261 TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);2284 ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
2262 LLVMTypeRef union_element_types[] = {2285 LLVMTypeRef union_element_types[] = {
2263 most_aligned_union_member->type_ref,2286 most_aligned_union_member->type_ref,
2264 padding_array->type_ref,2287 padding_array->type_ref,
...@@ -2288,8 +2311,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2288,8 +2311,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
22882311
2289 LLVMTypeRef union_type_ref;2312 LLVMTypeRef union_type_ref;
2290 if (padding_in_bits > 0) {2313 if (padding_in_bits > 0) {
2291 TypeTableEntry *u8_type = get_int_type(g, false, 8);2314 ZigType *u8_type = get_int_type(g, false, 8);
2292 TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);2315 ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
2293 LLVMTypeRef union_element_types[] = {2316 LLVMTypeRef union_element_types[] = {
2294 most_aligned_union_member->type_ref,2317 most_aligned_union_member->type_ref,
2295 padding_array->type_ref,2318 padding_array->type_ref,
...@@ -2312,7 +2335,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2312,7 +2335,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
2312 assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits);2335 assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits);
23132336
2314 // create llvm type for root struct2337 // 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;
2316 uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);2339 uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);
23172340
2318 if (align_of_tag_in_bits >= biggest_align_in_bits) {2341 if (align_of_tag_in_bits >= biggest_align_in_bits) {
...@@ -2380,8 +2403,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {...@@ -2380,8 +2403,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
2380 return ErrorNone;2403 return ErrorNone;
2381}2404}
23822405
2383static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {2406static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2384 assert(enum_type->id == TypeTableEntryIdEnum);2407 assert(enum_type->id == ZigTypeIdEnum);
23852408
2386 if (enum_type->data.enumeration.zero_bits_known)2409 if (enum_type->data.enumeration.zero_bits_known)
2387 return ErrorNone;2410 return ErrorNone;
...@@ -2421,7 +2444,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2421,7 +2444,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2421 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};2444 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
2422 occupied_tag_values.init(field_count);2445 occupied_tag_values.init(field_count);
24232446
2424 TypeTableEntry *tag_int_type;2447 ZigType *tag_int_type;
2425 if (enum_type->data.enumeration.layout == ContainerLayoutExtern) {2448 if (enum_type->data.enumeration.layout == ContainerLayoutExtern) {
2426 tag_int_type = get_c_int_type(g, CIntTypeInt);2449 tag_int_type = get_c_int_type(g, CIntTypeInt);
2427 } else {2450 } else {
...@@ -2430,10 +2453,10 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2430,10 +2453,10 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
24302453
2431 // TODO: Are extern enums allowed to have an init_arg_expr?2454 // TODO: Are extern enums allowed to have an init_arg_expr?
2432 if (decl_node->data.container_decl.init_arg_expr != nullptr) {2455 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);
2434 if (type_is_invalid(wanted_tag_int_type)) {2457 if (type_is_invalid(wanted_tag_int_type)) {
2435 enum_type->data.enumeration.is_invalid = true;2458 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) {
2437 enum_type->data.enumeration.is_invalid = true;2460 enum_type->data.enumeration.is_invalid = true;
2438 add_node_error(g, decl_node->data.container_decl.init_arg_expr,2461 add_node_error(g, decl_node->data.container_decl.init_arg_expr,
2439 buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name)));2462 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) {...@@ -2482,12 +2505,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2482 // In a second pass we will fill in the unspecified ones.2505 // In a second pass we will fill in the unspecified ones.
2483 if (tag_value != nullptr) {2506 if (tag_value != nullptr) {
2484 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2507 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) {
2486 enum_type->data.enumeration.is_invalid = true;2509 enum_type->data.enumeration.is_invalid = true;
2487 continue;2510 continue;
2488 }2511 }
2489 assert(result_inst->value.special != ConstValSpecialRuntime);2512 assert(result_inst->value.special != ConstValSpecialRuntime);
2490 assert(result_inst->value.type->id == TypeTableEntryIdInt);2513 assert(result_inst->value.type->id == ZigTypeIdInt);
2491 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);2514 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
2492 if (entry == nullptr) {2515 if (entry == nullptr) {
2493 bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint);2516 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) {...@@ -2543,8 +2566,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2543 return ErrorNone;2566 return ErrorNone;
2544}2567}
25452568
2546static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {2569static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2547 assert(struct_type->id == TypeTableEntryIdStruct);2570 assert(struct_type->id == ZigTypeIdStruct);
25482571
2549 Error err;2572 Error err;
25502573
...@@ -2607,7 +2630,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2607,7 +2630,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2607 continue;2630 continue;
2608 }2631 }
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);
2611 type_struct_field->type_entry = field_type;2634 type_struct_field->type_entry = field_type;
2612 type_struct_field->src_index = i;2635 type_struct_field->src_index = i;
2613 type_struct_field->gen_index = SIZE_MAX;2636 type_struct_field->gen_index = SIZE_MAX;
...@@ -2662,8 +2685,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2662,8 +2685,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2662 return ErrorNone;2685 return ErrorNone;
2663}2686}
26642687
2665static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {2688static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2666 assert(union_type->id == TypeTableEntryIdUnion);2689 assert(union_type->id == ZigTypeIdUnion);
26672690
2668 Error err;2691 Error err;
26692692
...@@ -2727,7 +2750,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2727,7 +2750,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2727 enum_type_node != nullptr;2750 enum_type_node != nullptr;
2728 bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto);2751 bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto);
2729 bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr);2752 bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr);
2730 TypeTableEntry *tag_type;2753 ZigType *tag_type;
2731 bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety);2754 bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety);
2732 bool *covered_enum_fields;2755 bool *covered_enum_fields;
2733 ZigLLVMDIEnumerator **di_enumerators;2756 ZigLLVMDIEnumerator **di_enumerators;
...@@ -2737,14 +2760,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2737,14 +2760,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
27372760
2738 di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);2761 di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
27392762
2740 TypeTableEntry *tag_int_type;2763 ZigType *tag_int_type;
2741 if (enum_type_node != nullptr) {2764 if (enum_type_node != nullptr) {
2742 tag_int_type = analyze_type_expr(g, scope, enum_type_node);2765 tag_int_type = analyze_type_expr(g, scope, enum_type_node);
2743 if (type_is_invalid(tag_int_type)) {2766 if (type_is_invalid(tag_int_type)) {
2744 union_type->data.unionation.is_invalid = true;2767 union_type->data.unionation.is_invalid = true;
2745 return ErrorSemanticAnalyzeFail;2768 return ErrorSemanticAnalyzeFail;
2746 }2769 }
2747 if (tag_int_type->id != TypeTableEntryIdInt) {2770 if (tag_int_type->id != ZigTypeIdInt) {
2748 add_node_error(g, enum_type_node,2771 add_node_error(g, enum_type_node,
2749 buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));2772 buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));
2750 union_type->data.unionation.is_invalid = true;2773 union_type->data.unionation.is_invalid = true;
...@@ -2755,7 +2778,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2755,7 +2778,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2755 }2778 }
2756 abi_alignment_so_far = get_abi_alignment(g, tag_int_type);2779 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);
2759 buf_resize(&tag_type->name, 0);2782 buf_resize(&tag_type->name, 0);
2760 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));2783 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));
2761 tag_type->is_copyable = true;2784 tag_type->is_copyable = true;
...@@ -2772,12 +2795,12 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2772,12 +2795,12 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2772 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;2795 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
2773 tag_type->data.enumeration.complete = true;2796 tag_type->data.enumeration.complete = true;
2774 } else if (enum_type_node != nullptr) {2797 } 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);
2776 if (type_is_invalid(enum_type)) {2799 if (type_is_invalid(enum_type)) {
2777 union_type->data.unionation.is_invalid = true;2800 union_type->data.unionation.is_invalid = true;
2778 return ErrorSemanticAnalyzeFail;2801 return ErrorSemanticAnalyzeFail;
2779 }2802 }
2780 if (enum_type->id != TypeTableEntryIdEnum) {2803 if (enum_type->id != ZigTypeIdEnum) {
2781 union_type->data.unionation.is_invalid = true;2804 union_type->data.unionation.is_invalid = true;
2782 add_node_error(g, enum_type_node,2805 add_node_error(g, enum_type_node,
2783 buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name)));2806 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) {...@@ -2809,7 +2832,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2809 continue;2832 continue;
2810 }2833 }
28112834
2812 TypeTableEntry *field_type;2835 ZigType *field_type;
2813 if (field_node->data.struct_field.type == nullptr) {2836 if (field_node->data.struct_field.type == nullptr) {
2814 if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) {2837 if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) {
2815 field_type = g->builtin_types.entry_void;2838 field_type = g->builtin_types.entry_void;
...@@ -2853,14 +2876,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2853,14 +2876,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2853 // In this first pass we resolve explicit tag values.2876 // In this first pass we resolve explicit tag values.
2854 // In a second pass we will fill in the unspecified ones.2877 // In a second pass we will fill in the unspecified ones.
2855 if (tag_value != nullptr) {2878 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;
2857 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2880 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) {
2859 union_type->data.unionation.is_invalid = true;2882 union_type->data.unionation.is_invalid = true;
2860 continue;2883 continue;
2861 }2884 }
2862 assert(result_inst->value.special != ConstValSpecialRuntime);2885 assert(result_inst->value.special != ConstValSpecialRuntime);
2863 assert(result_inst->value.type->id == TypeTableEntryIdInt);2886 assert(result_inst->value.type->id == ZigTypeIdInt);
2864 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);2887 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
2865 if (entry == nullptr) {2888 if (entry == nullptr) {
2866 bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint);2889 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) {...@@ -3031,8 +3054,8 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, uint8_t sep) {
3031 buf_append_buf(buf, tld->name);3054 buf_append_buf(buf, tld->name);
3032}3055}
30333056
3034FnTableEntry *create_fn_raw(FnInline inline_value) {3057ZigFn *create_fn_raw(FnInline inline_value) {
3035 FnTableEntry *fn_entry = allocate<FnTableEntry>(1);3058 ZigFn *fn_entry = allocate<ZigFn>(1);
30363059
3037 fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;3060 fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
3038 fn_entry->analyzed_executable.backward_branch_quota = default_backward_branch_quota;3061 fn_entry->analyzed_executable.backward_branch_quota = default_backward_branch_quota;
...@@ -3043,12 +3066,12 @@ FnTableEntry *create_fn_raw(FnInline inline_value) {...@@ -3043,12 +3066,12 @@ FnTableEntry *create_fn_raw(FnInline inline_value) {
3043 return fn_entry;3066 return fn_entry;
3044}3067}
30453068
3046FnTableEntry *create_fn(AstNode *proto_node) {3069ZigFn *create_fn(AstNode *proto_node) {
3047 assert(proto_node->type == NodeTypeFnProto);3070 assert(proto_node->type == NodeTypeFnProto);
3048 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;3071 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
30493072
3050 FnInline inline_value = fn_proto->is_inline ? FnInlineAlways : FnInlineAuto;3073 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
3053 fn_entry->proto_node = proto_node;3076 fn_entry->proto_node = proto_node;
3054 fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr :3077 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) {...@@ -3068,39 +3091,39 @@ static bool scope_is_root_decls(Scope *scope) {
3068 zig_unreachable();3091 zig_unreachable();
3069}3092}
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) {
3072 add_node_error(g, proto_node,3095 add_node_error(g, proto_node,
3073 buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'",3096 buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'",
3074 buf_ptr(&fn_type->name)));3097 buf_ptr(&fn_type->name)));
3075}3098}
30763099
3077static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {3100static void typecheck_panic_fn(CodeGen *g, ZigFn *panic_fn) {
3078 AstNode *proto_node = panic_fn->proto_node;3101 AstNode *proto_node = panic_fn->proto_node;
3079 assert(proto_node->type == NodeTypeFnProto);3102 assert(proto_node->type == NodeTypeFnProto);
3080 TypeTableEntry *fn_type = panic_fn->type_entry;3103 ZigType *fn_type = panic_fn->type_entry;
3081 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;3104 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
3082 if (fn_type_id->param_count != 2) {3105 if (fn_type_id->param_count != 2) {
3083 return wrong_panic_prototype(g, proto_node, fn_type);3106 return wrong_panic_prototype(g, proto_node, fn_type);
3084 }3107 }
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,
3086 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);3109 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);
3088 if (fn_type_id->param_info[0].type != const_u8_slice) {3111 if (fn_type_id->param_info[0].type != const_u8_slice) {
3089 return wrong_panic_prototype(g, proto_node, fn_type);3112 return wrong_panic_prototype(g, proto_node, fn_type);
3090 }3113 }
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));
3093 if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {3116 if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {
3094 return wrong_panic_prototype(g, proto_node, fn_type);3117 return wrong_panic_prototype(g, proto_node, fn_type);
3095 }3118 }
30963119
3097 TypeTableEntry *actual_return_type = fn_type_id->return_type;3120 ZigType *actual_return_type = fn_type_id->return_type;
3098 if (actual_return_type != g->builtin_types.entry_unreachable) {3121 if (actual_return_type != g->builtin_types.entry_unreachable) {
3099 return wrong_panic_prototype(g, proto_node, fn_type);3122 return wrong_panic_prototype(g, proto_node, fn_type);
3100 }3123 }
3101}3124}
31023125
3103TypeTableEntry *get_test_fn_type(CodeGen *g) {3126ZigType *get_test_fn_type(CodeGen *g) {
3104 if (g->test_fn_type)3127 if (g->test_fn_type)
3105 return g->test_fn_type;3128 return g->test_fn_type;
31063129
...@@ -3111,7 +3134,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {...@@ -3111,7 +3134,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
3111 return g->test_fn_type;3134 return g->test_fn_type;
3112}3135}
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) {
3115 if (ccc) {3138 if (ccc) {
3116 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {3139 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
3117 g->have_c_main = true;3140 g->have_c_main = true;
...@@ -3147,7 +3170,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3147,7 +3170,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
31473170
3148 AstNode *fn_def_node = fn_proto->fn_def_node;3171 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);
3151 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');3174 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
31523175
3153 if (fn_proto->is_export) {3176 if (fn_proto->is_export) {
...@@ -3185,7 +3208,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3185,7 +3208,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3185 }3208 }
3186 }3209 }
31873210
3188 if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {3211 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
3189 tld_fn->base.resolution = TldResolutionInvalid;3212 tld_fn->base.resolution = TldResolutionInvalid;
3190 return;3213 return;
3191 }3214 }
...@@ -3208,7 +3231,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3208,7 +3231,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3208 }3231 }
3209 }3232 }
3210 } else if (source_node->type == NodeTypeTestDecl) {3233 } 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
3213 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');3236 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) {...@@ -3273,7 +3296,7 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3273 }3296 }
32743297
3275 {3298 {
3276 TypeTableEntry *type = get_primitive_type(g, tld->name);3299 ZigType *type = get_primitive_type(g, tld->name);
3277 if (type != nullptr) {3300 if (type != nullptr) {
3278 add_node_error(g, tld->source_node,3301 add_node_error(g, tld->source_node,
3279 buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));3302 buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));
...@@ -3437,17 +3460,17 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3437,17 +3460,17 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3437}3460}
34383461
3439static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {3462static 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;
3441 assert(type_entry);3464 assert(type_entry);
34423465
3443 switch (type_entry->id) {3466 switch (type_entry->id) {
3444 case TypeTableEntryIdStruct:3467 case ZigTypeIdStruct:
3445 resolve_struct_type(g, tld_container->type_entry);3468 resolve_struct_type(g, tld_container->type_entry);
3446 return;3469 return;
3447 case TypeTableEntryIdEnum:3470 case ZigTypeIdEnum:
3448 resolve_enum_type(g, tld_container->type_entry);3471 resolve_enum_type(g, tld_container->type_entry);
3449 return;3472 return;
3450 case TypeTableEntryIdUnion:3473 case ZigTypeIdUnion:
3451 resolve_union_type(g, tld_container->type_entry);3474 resolve_union_type(g, tld_container->type_entry);
3452 return;3475 return;
3453 default:3476 default:
...@@ -3455,38 +3478,38 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {...@@ -3455,38 +3478,38 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
3455 }3478 }
3456}3479}
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) {
3459 switch (type_entry->id) {3482 switch (type_entry->id) {
3460 case TypeTableEntryIdInvalid:3483 case ZigTypeIdInvalid:
3461 return g->builtin_types.entry_invalid;3484 return g->builtin_types.entry_invalid;
3462 case TypeTableEntryIdUnreachable:3485 case ZigTypeIdUnreachable:
3463 case TypeTableEntryIdUndefined:3486 case ZigTypeIdUndefined:
3464 case TypeTableEntryIdNull:3487 case ZigTypeIdNull:
3465 case TypeTableEntryIdBlock:3488 case ZigTypeIdBlock:
3466 case TypeTableEntryIdArgTuple:3489 case ZigTypeIdArgTuple:
3467 case TypeTableEntryIdOpaque:3490 case ZigTypeIdOpaque:
3468 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",3491 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
3469 buf_ptr(&type_entry->name)));3492 buf_ptr(&type_entry->name)));
3470 return g->builtin_types.entry_invalid;3493 return g->builtin_types.entry_invalid;
3471 case TypeTableEntryIdComptimeFloat:3494 case ZigTypeIdComptimeFloat:
3472 case TypeTableEntryIdComptimeInt:3495 case ZigTypeIdComptimeInt:
3473 case TypeTableEntryIdNamespace:3496 case ZigTypeIdNamespace:
3474 case TypeTableEntryIdMetaType:3497 case ZigTypeIdMetaType:
3475 case TypeTableEntryIdVoid:3498 case ZigTypeIdVoid:
3476 case TypeTableEntryIdBool:3499 case ZigTypeIdBool:
3477 case TypeTableEntryIdInt:3500 case ZigTypeIdInt:
3478 case TypeTableEntryIdFloat:3501 case ZigTypeIdFloat:
3479 case TypeTableEntryIdPointer:3502 case ZigTypeIdPointer:
3480 case TypeTableEntryIdArray:3503 case ZigTypeIdArray:
3481 case TypeTableEntryIdStruct:3504 case ZigTypeIdStruct:
3482 case TypeTableEntryIdOptional:3505 case ZigTypeIdOptional:
3483 case TypeTableEntryIdErrorUnion:3506 case ZigTypeIdErrorUnion:
3484 case TypeTableEntryIdErrorSet:3507 case ZigTypeIdErrorSet:
3485 case TypeTableEntryIdEnum:3508 case ZigTypeIdEnum:
3486 case TypeTableEntryIdUnion:3509 case ZigTypeIdUnion:
3487 case TypeTableEntryIdFn:3510 case ZigTypeIdFn:
3488 case TypeTableEntryIdBoundFn:3511 case ZigTypeIdBoundFn:
3489 case TypeTableEntryIdPromise:3512 case ZigTypeIdPromise:
3490 return type_entry;3513 return type_entry;
3491 }3514 }
3492 zig_unreachable();3515 zig_unreachable();
...@@ -3494,12 +3517,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt...@@ -3494,12 +3517,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
34943517
3495// Set name to nullptr to make the variable anonymous (not visible to programmer).3518// Set name to nullptr to make the variable anonymous (not visible to programmer).
3496// TODO merge with definition of add_local_var in ir.cpp3519// 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,
3498 bool is_const, ConstExprValue *value, Tld *src_tld)3521 bool is_const, ConstExprValue *value, Tld *src_tld)
3499{3522{
3500 assert(value);3523 assert(value);
35013524
3502 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);3525 ZigVar *variable_entry = allocate<ZigVar>(1);
3503 variable_entry->value = value;3526 variable_entry->value = value;
3504 variable_entry->parent_scope = parent_scope;3527 variable_entry->parent_scope = parent_scope;
3505 variable_entry->shadowable = false;3528 variable_entry->shadowable = false;
...@@ -3512,14 +3535,14 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent...@@ -3512,14 +3535,14 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
3512 if (!type_is_invalid(value->type)) {3535 if (!type_is_invalid(value->type)) {
3513 variable_entry->align_bytes = get_abi_alignment(g, value->type);3536 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);
3516 if (existing_var && !existing_var->shadowable) {3539 if (existing_var && !existing_var->shadowable) {
3517 ErrorMsg *msg = add_node_error(g, source_node,3540 ErrorMsg *msg = add_node_error(g, source_node,
3518 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));3541 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
3519 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));3542 add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
3520 variable_entry->value->type = g->builtin_types.entry_invalid;3543 variable_entry->value->type = g->builtin_types.entry_invalid;
3521 } else {3544 } else {
3522 TypeTableEntry *type = get_primitive_type(g, name);3545 ZigType *type = get_primitive_type(g, name);
3523 if (type != nullptr) {3546 if (type != nullptr) {
3524 add_node_error(g, source_node,3547 add_node_error(g, source_node,
3525 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));3548 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
...@@ -3570,9 +3593,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {...@@ -3570,9 +3593,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
3570 bool is_extern = var_decl->is_extern;3593 bool is_extern = var_decl->is_extern;
3571 bool is_export = var_decl->is_export;3594 bool is_export = var_decl->is_export;
35723595
3573 TypeTableEntry *explicit_type = nullptr;3596 ZigType *explicit_type = nullptr;
3574 if (var_decl->type) {3597 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);
3576 explicit_type = validate_var_type(g, var_decl->type, proposed_type);3599 explicit_type = validate_var_type(g, var_decl->type, proposed_type);
3577 }3600 }
35783601
...@@ -3590,37 +3613,37 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {...@@ -3590,37 +3613,37 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
3590 IrInstruction *init_value = nullptr;3613 IrInstruction *init_value = nullptr;
35913614
3592 // TODO more validation for types that can't be used for export/extern variables3615 // TODO more validation for types that can't be used for export/extern variables
3593 TypeTableEntry *implicit_type = nullptr;3616 ZigType *implicit_type = nullptr;
3594 if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) {3617 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {
3595 implicit_type = explicit_type;3618 implicit_type = explicit_type;
3596 } else if (var_decl->expr) {3619 } else if (var_decl->expr) {
3597 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);3620 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);
3598 assert(init_value);3621 assert(init_value);
3599 implicit_type = init_value->value.type;3622 implicit_type = init_value->value.type;
36003623
3601 if (implicit_type->id == TypeTableEntryIdUnreachable) {3624 if (implicit_type->id == ZigTypeIdUnreachable) {
3602 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));3625 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
3603 implicit_type = g->builtin_types.entry_invalid;3626 implicit_type = g->builtin_types.entry_invalid;
3604 } else if ((!is_const || linkage == VarLinkageExternal) &&3627 } else if ((!is_const || linkage == VarLinkageExternal) &&
3605 (implicit_type->id == TypeTableEntryIdComptimeFloat ||3628 (implicit_type->id == ZigTypeIdComptimeFloat ||
3606 implicit_type->id == TypeTableEntryIdComptimeInt))3629 implicit_type->id == ZigTypeIdComptimeInt))
3607 {3630 {
3608 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));3631 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
3609 implicit_type = g->builtin_types.entry_invalid;3632 implicit_type = g->builtin_types.entry_invalid;
3610 } else if (implicit_type->id == TypeTableEntryIdNull) {3633 } else if (implicit_type->id == ZigTypeIdNull) {
3611 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));3634 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
3612 implicit_type = g->builtin_types.entry_invalid;3635 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) {
3614 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));3637 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));
3615 implicit_type = g->builtin_types.entry_invalid;3638 implicit_type = g->builtin_types.entry_invalid;
3616 }3639 }
3617 assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime);3640 assert(implicit_type->id == ZigTypeIdInvalid || init_value->value.special != ConstValSpecialRuntime);
3618 } else if (linkage != VarLinkageExternal) {3641 } else if (linkage != VarLinkageExternal) {
3619 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));3642 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
3620 implicit_type = g->builtin_types.entry_invalid;3643 implicit_type = g->builtin_types.entry_invalid;
3621 }3644 }
36223645
3623 TypeTableEntry *type = explicit_type ? explicit_type : implicit_type;3646 ZigType *type = explicit_type ? explicit_type : implicit_type;
3624 assert(type != nullptr); // should have been caught by the parser3647 assert(type != nullptr); // should have been caught by the parser
36253648
3626 ConstExprValue *init_val = init_value ? &init_value->value : create_const_runtime(type);3649 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) {...@@ -3719,12 +3742,16 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
3719 return nullptr;3742 return nullptr;
3720}3743}
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;
3723 while (scope) {3747 while (scope) {
3724 if (scope->id == ScopeIdVarDecl) {3748 if (scope->id == ScopeIdVarDecl) {
3725 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;3749 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;
3727 return var_scope->var;3753 return var_scope->var;
3754 }
3728 } else if (scope->id == ScopeIdDecls) {3755 } else if (scope->id == ScopeIdDecls) {
3729 ScopeDecls *decls_scope = (ScopeDecls *)scope;3756 ScopeDecls *decls_scope = (ScopeDecls *)scope;
3730 auto entry = decls_scope->decl_table.maybe_get(name);3757 auto entry = decls_scope->decl_table.maybe_get(name);
...@@ -3732,10 +3759,15 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {...@@ -3732,10 +3759,15 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
3732 Tld *tld = entry->value;3759 Tld *tld = entry->value;
3733 if (tld->id == TldIdVar) {3760 if (tld->id == TldIdVar) {
3734 TldVar *tld_var = (TldVar *)tld;3761 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;
3736 return tld_var->var;3765 return tld_var->var;
3766 }
3737 }3767 }
3738 }3768 }
3769 } else if (scope->id == ScopeIdFnDef) {
3770 my_crossed_fndef_scope = (ScopeFnDef *)scope;
3739 }3771 }
3740 scope = scope->parent;3772 scope = scope->parent;
3741 }3773 }
...@@ -3743,7 +3775,7 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {...@@ -3743,7 +3775,7 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
3743 return nullptr;3775 return nullptr;
3744}3776}
37453777
3746FnTableEntry *scope_fn_entry(Scope *scope) {3778ZigFn *scope_fn_entry(Scope *scope) {
3747 while (scope) {3779 while (scope) {
3748 if (scope->id == ScopeIdFnDef) {3780 if (scope->id == ScopeIdFnDef) {
3749 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;3781 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
...@@ -3754,7 +3786,7 @@ FnTableEntry *scope_fn_entry(Scope *scope) {...@@ -3754,7 +3786,7 @@ FnTableEntry *scope_fn_entry(Scope *scope) {
3754 return nullptr;3786 return nullptr;
3755}3787}
37563788
3757FnTableEntry *scope_get_fn_if_root(Scope *scope) {3789ZigFn *scope_get_fn_if_root(Scope *scope) {
3758 assert(scope);3790 assert(scope);
3759 scope = scope->parent;3791 scope = scope->parent;
3760 while (scope) {3792 while (scope) {
...@@ -3770,6 +3802,7 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {...@@ -3770,6 +3802,7 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
3770 case ScopeIdSuspend:3802 case ScopeIdSuspend:
3771 case ScopeIdCompTime:3803 case ScopeIdCompTime:
3772 case ScopeIdCoroPrelude:3804 case ScopeIdCoroPrelude:
3805 case ScopeIdRuntime:
3773 scope = scope->parent;3806 scope = scope->parent;
3774 continue;3807 continue;
3775 case ScopeIdFnDef:3808 case ScopeIdFnDef:
...@@ -3781,8 +3814,8 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {...@@ -3781,8 +3814,8 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
3781 return nullptr;3814 return nullptr;
3782}3815}
37833816
3784TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {3817TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
3785 assert(enum_type->id == TypeTableEntryIdEnum);3818 assert(enum_type->id == ZigTypeIdEnum);
3786 if (enum_type->data.enumeration.src_field_count == 0)3819 if (enum_type->data.enumeration.src_field_count == 0)
3787 return nullptr;3820 return nullptr;
3788 auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);3821 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) {...@@ -3791,8 +3824,8 @@ TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
3791 return entry->value;3824 return entry->value;
3792}3825}
37933826
3794TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {3827TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {
3795 assert(type_entry->id == TypeTableEntryIdStruct);3828 assert(type_entry->id == ZigTypeIdStruct);
3796 assert(type_entry->data.structure.complete);3829 assert(type_entry->data.structure.complete);
3797 if (type_entry->data.structure.src_field_count == 0)3830 if (type_entry->data.structure.src_field_count == 0)
3798 return nullptr;3831 return nullptr;
...@@ -3802,8 +3835,8 @@ TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {...@@ -3802,8 +3835,8 @@ TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
3802 return entry->value;3835 return entry->value;
3803}3836}
38043837
3805TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {3838TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {
3806 assert(type_entry->id == TypeTableEntryIdUnion);3839 assert(type_entry->id == ZigTypeIdUnion);
3807 assert(type_entry->data.unionation.zero_bits_known);3840 assert(type_entry->data.unionation.zero_bits_known);
3808 if (type_entry->data.unionation.src_field_count == 0)3841 if (type_entry->data.unionation.src_field_count == 0)
3809 return nullptr;3842 return nullptr;
...@@ -3813,8 +3846,8 @@ TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {...@@ -3813,8 +3846,8 @@ TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
3813 return entry->value;3846 return entry->value;
3814}3847}
38153848
3816TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) {3849TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) {
3817 assert(type_entry->id == TypeTableEntryIdUnion);3850 assert(type_entry->id == ZigTypeIdUnion);
3818 assert(type_entry->data.unionation.zero_bits_known);3851 assert(type_entry->data.unionation.zero_bits_known);
3819 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {3852 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
3820 TypeUnionField *field = &type_entry->data.unionation.fields[i];3853 TypeUnionField *field = &type_entry->data.unionation.fields[i];
...@@ -3825,7 +3858,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt...@@ -3825,7 +3858,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt
3825 return nullptr;3858 return nullptr;
3826}3859}
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) {
3829 assert(enum_type->data.enumeration.zero_bits_known);3862 assert(enum_type->data.enumeration.zero_bits_known);
3830 for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {3863 for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {
3831 TypeEnumField *field = &enum_type->data.enumeration.fields[i];3864 TypeEnumField *field = &enum_type->data.enumeration.fields[i];
...@@ -3837,143 +3870,143 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t...@@ -3837,143 +3870,143 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t
3837}3870}
38383871
38393872
3840static bool is_container(TypeTableEntry *type_entry) {3873static bool is_container(ZigType *type_entry) {
3841 switch (type_entry->id) {3874 switch (type_entry->id) {
3842 case TypeTableEntryIdInvalid:3875 case ZigTypeIdInvalid:
3843 zig_unreachable();3876 zig_unreachable();
3844 case TypeTableEntryIdStruct:3877 case ZigTypeIdStruct:
3845 case TypeTableEntryIdEnum:3878 case ZigTypeIdEnum:
3846 case TypeTableEntryIdUnion:3879 case ZigTypeIdUnion:
3847 return true;3880 return true;
3848 case TypeTableEntryIdPointer:3881 case ZigTypeIdPointer:
3849 case TypeTableEntryIdMetaType:3882 case ZigTypeIdMetaType:
3850 case TypeTableEntryIdVoid:3883 case ZigTypeIdVoid:
3851 case TypeTableEntryIdBool:3884 case ZigTypeIdBool:
3852 case TypeTableEntryIdUnreachable:3885 case ZigTypeIdUnreachable:
3853 case TypeTableEntryIdInt:3886 case ZigTypeIdInt:
3854 case TypeTableEntryIdFloat:3887 case ZigTypeIdFloat:
3855 case TypeTableEntryIdArray:3888 case ZigTypeIdArray:
3856 case TypeTableEntryIdComptimeFloat:3889 case ZigTypeIdComptimeFloat:
3857 case TypeTableEntryIdComptimeInt:3890 case ZigTypeIdComptimeInt:
3858 case TypeTableEntryIdUndefined:3891 case ZigTypeIdUndefined:
3859 case TypeTableEntryIdNull:3892 case ZigTypeIdNull:
3860 case TypeTableEntryIdOptional:3893 case ZigTypeIdOptional:
3861 case TypeTableEntryIdErrorUnion:3894 case ZigTypeIdErrorUnion:
3862 case TypeTableEntryIdErrorSet:3895 case ZigTypeIdErrorSet:
3863 case TypeTableEntryIdFn:3896 case ZigTypeIdFn:
3864 case TypeTableEntryIdNamespace:3897 case ZigTypeIdNamespace:
3865 case TypeTableEntryIdBlock:3898 case ZigTypeIdBlock:
3866 case TypeTableEntryIdBoundFn:3899 case ZigTypeIdBoundFn:
3867 case TypeTableEntryIdArgTuple:3900 case ZigTypeIdArgTuple:
3868 case TypeTableEntryIdOpaque:3901 case ZigTypeIdOpaque:
3869 case TypeTableEntryIdPromise:3902 case ZigTypeIdPromise:
3870 return false;3903 return false;
3871 }3904 }
3872 zig_unreachable();3905 zig_unreachable();
3873}3906}
38743907
3875bool is_ref(TypeTableEntry *type_entry) {3908bool is_ref(ZigType *type_entry) {
3876 return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;3909 return type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
3877}3910}
38783911
3879bool is_array_ref(TypeTableEntry *type_entry) {3912bool is_array_ref(ZigType *type_entry) {
3880 TypeTableEntry *array = is_ref(type_entry) ?3913 ZigType *array = is_ref(type_entry) ?
3881 type_entry->data.pointer.child_type : type_entry;3914 type_entry->data.pointer.child_type : type_entry;
3882 return array->id == TypeTableEntryIdArray;3915 return array->id == ZigTypeIdArray;
3883}3916}
38843917
3885bool is_container_ref(TypeTableEntry *type_entry) {3918bool is_container_ref(ZigType *type_entry) {
3886 return is_ref(type_entry) ?3919 return is_ref(type_entry) ?
3887 is_container(type_entry->data.pointer.child_type) : is_container(type_entry);3920 is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
3888}3921}
38893922
3890TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {3923ZigType *container_ref_type(ZigType *type_entry) {
3891 assert(is_container_ref(type_entry));3924 assert(is_container_ref(type_entry));
3892 return is_ref(type_entry) ?3925 return is_ref(type_entry) ?
3893 type_entry->data.pointer.child_type : type_entry;3926 type_entry->data.pointer.child_type : type_entry;
3894}3927}
38953928
3896void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {3929void resolve_container_type(CodeGen *g, ZigType *type_entry) {
3897 switch (type_entry->id) {3930 switch (type_entry->id) {
3898 case TypeTableEntryIdStruct:3931 case ZigTypeIdStruct:
3899 resolve_struct_type(g, type_entry);3932 resolve_struct_type(g, type_entry);
3900 break;3933 break;
3901 case TypeTableEntryIdEnum:3934 case ZigTypeIdEnum:
3902 resolve_enum_type(g, type_entry);3935 resolve_enum_type(g, type_entry);
3903 break;3936 break;
3904 case TypeTableEntryIdUnion:3937 case ZigTypeIdUnion:
3905 resolve_union_type(g, type_entry);3938 resolve_union_type(g, type_entry);
3906 break;3939 break;
3907 case TypeTableEntryIdPointer:3940 case ZigTypeIdPointer:
3908 case TypeTableEntryIdMetaType:3941 case ZigTypeIdMetaType:
3909 case TypeTableEntryIdVoid:3942 case ZigTypeIdVoid:
3910 case TypeTableEntryIdBool:3943 case ZigTypeIdBool:
3911 case TypeTableEntryIdUnreachable:3944 case ZigTypeIdUnreachable:
3912 case TypeTableEntryIdInt:3945 case ZigTypeIdInt:
3913 case TypeTableEntryIdFloat:3946 case ZigTypeIdFloat:
3914 case TypeTableEntryIdArray:3947 case ZigTypeIdArray:
3915 case TypeTableEntryIdComptimeFloat:3948 case ZigTypeIdComptimeFloat:
3916 case TypeTableEntryIdComptimeInt:3949 case ZigTypeIdComptimeInt:
3917 case TypeTableEntryIdUndefined:3950 case ZigTypeIdUndefined:
3918 case TypeTableEntryIdNull:3951 case ZigTypeIdNull:
3919 case TypeTableEntryIdOptional:3952 case ZigTypeIdOptional:
3920 case TypeTableEntryIdErrorUnion:3953 case ZigTypeIdErrorUnion:
3921 case TypeTableEntryIdErrorSet:3954 case ZigTypeIdErrorSet:
3922 case TypeTableEntryIdFn:3955 case ZigTypeIdFn:
3923 case TypeTableEntryIdNamespace:3956 case ZigTypeIdNamespace:
3924 case TypeTableEntryIdBlock:3957 case ZigTypeIdBlock:
3925 case TypeTableEntryIdBoundFn:3958 case ZigTypeIdBoundFn:
3926 case TypeTableEntryIdInvalid:3959 case ZigTypeIdInvalid:
3927 case TypeTableEntryIdArgTuple:3960 case ZigTypeIdArgTuple:
3928 case TypeTableEntryIdOpaque:3961 case ZigTypeIdOpaque:
3929 case TypeTableEntryIdPromise:3962 case ZigTypeIdPromise:
3930 zig_unreachable();3963 zig_unreachable();
3931 }3964 }
3932}3965}
39333966
3934TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {3967ZigType *get_codegen_ptr_type(ZigType *type) {
3935 if (type->id == TypeTableEntryIdPointer) return type;3968 if (type->id == ZigTypeIdPointer) return type;
3936 if (type->id == TypeTableEntryIdFn) return type;3969 if (type->id == ZigTypeIdFn) return type;
3937 if (type->id == TypeTableEntryIdPromise) return type;3970 if (type->id == ZigTypeIdPromise) return type;
3938 if (type->id == TypeTableEntryIdOptional) {3971 if (type->id == ZigTypeIdOptional) {
3939 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;3972 if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type;
3940 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;3973 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
3941 if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;3974 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
3942 }3975 }
3943 return nullptr;3976 return nullptr;
3944}3977}
39453978
3946bool type_is_codegen_pointer(TypeTableEntry *type) {3979bool type_is_codegen_pointer(ZigType *type) {
3947 return get_codegen_ptr_type(type) == type;3980 return get_codegen_ptr_type(type) == type;
3948}3981}
39493982
3950uint32_t get_ptr_align(TypeTableEntry *type) {3983uint32_t get_ptr_align(ZigType *type) {
3951 TypeTableEntry *ptr_type = get_codegen_ptr_type(type);3984 ZigType *ptr_type = get_codegen_ptr_type(type);
3952 if (ptr_type->id == TypeTableEntryIdPointer) {3985 if (ptr_type->id == ZigTypeIdPointer) {
3953 return ptr_type->data.pointer.alignment;3986 return ptr_type->data.pointer.alignment;
3954 } else if (ptr_type->id == TypeTableEntryIdFn) {3987 } else if (ptr_type->id == ZigTypeIdFn) {
3955 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;3988 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) {
3957 return 1;3990 return 1;
3958 } else {3991 } else {
3959 zig_unreachable();3992 zig_unreachable();
3960 }3993 }
3961}3994}
39623995
3963bool get_ptr_const(TypeTableEntry *type) {3996bool get_ptr_const(ZigType *type) {
3964 TypeTableEntry *ptr_type = get_codegen_ptr_type(type);3997 ZigType *ptr_type = get_codegen_ptr_type(type);
3965 if (ptr_type->id == TypeTableEntryIdPointer) {3998 if (ptr_type->id == ZigTypeIdPointer) {
3966 return ptr_type->data.pointer.is_const;3999 return ptr_type->data.pointer.is_const;
3967 } else if (ptr_type->id == TypeTableEntryIdFn) {4000 } else if (ptr_type->id == ZigTypeIdFn) {
3968 return true;4001 return true;
3969 } else if (ptr_type->id == TypeTableEntryIdPromise) {4002 } else if (ptr_type->id == ZigTypeIdPromise) {
3970 return true;4003 return true;
3971 } else {4004 } else {
3972 zig_unreachable();4005 zig_unreachable();
3973 }4006 }
3974}4007}
39754008
3976AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {4009AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) {
3977 if (fn_entry->param_source_nodes)4010 if (fn_entry->param_source_nodes)
3978 return fn_entry->param_source_nodes[index];4011 return fn_entry->param_source_nodes[index];
3979 else if (fn_entry->proto_node)4012 else if (fn_entry->proto_node)
...@@ -3982,8 +4015,8 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {...@@ -3982,8 +4015,8 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {
3982 return nullptr;4015 return nullptr;
3983}4016}
39844017
3985static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry) {4018static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
3986 TypeTableEntry *fn_type = fn_table_entry->type_entry;4019 ZigType *fn_type = fn_table_entry->type_entry;
3987 assert(!fn_type->data.fn.is_generic);4020 assert(!fn_type->data.fn.is_generic);
3988 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;4021 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
3989 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {4022 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...@@ -4000,14 +4033,14 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
4000 continue;4033 continue;
4001 }4034 }
40024035
4003 TypeTableEntry *param_type = param_info->type;4036 ZigType *param_type = param_info->type;
4004 bool is_noalias = param_info->is_noalias;4037 bool is_noalias = param_info->is_noalias;
40054038
4006 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {4039 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
4007 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));4040 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
4008 }4041 }
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,
4011 param_name, true, create_const_runtime(param_type), nullptr);4044 param_name, true, create_const_runtime(param_type), nullptr);
4012 var->src_arg_index = i;4045 var->src_arg_index = i;
4013 fn_table_entry->child_scope = var->child_scope;4046 fn_table_entry->child_scope = var->child_scope;
...@@ -4023,8 +4056,8 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr...@@ -4023,8 +4056,8 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
4023 }4056 }
4024}4057}
40254058
4026bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {4059bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
4027 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;4060 ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;
4028 if (infer_fn != nullptr) {4061 if (infer_fn != nullptr) {
4029 if (infer_fn->anal_state == FnAnalStateInvalid) {4062 if (infer_fn->anal_state == FnAnalStateInvalid) {
4030 return false;4063 return false;
...@@ -4044,12 +4077,12 @@ bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNod...@@ -4044,12 +4077,12 @@ bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNod
4044 return true;4077 return true;
4045}4078}
40464079
4047void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node) {4080void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) {
4048 TypeTableEntry *fn_type = fn_table_entry->type_entry;4081 ZigType *fn_type = fn_table_entry->type_entry;
4049 assert(!fn_type->data.fn.is_generic);4082 assert(!fn_type->data.fn.is_generic);
4050 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;4083 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,
4053 &fn_table_entry->analyzed_executable, fn_type_id->return_type, return_type_node);4086 &fn_table_entry->analyzed_executable, fn_type_id->return_type, return_type_node);
4054 fn_table_entry->src_implicit_return_type = block_return_type;4087 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...@@ -4059,13 +4092,13 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
4059 return;4092 return;
4060 }4093 }
40614094
4062 if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) {4095 if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {
4063 TypeTableEntry *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;4096 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
4064 if (return_err_set_type->data.error_set.infer_fn != nullptr) {4097 if (return_err_set_type->data.error_set.infer_fn != nullptr) {
4065 TypeTableEntry *inferred_err_set_type;4098 ZigType *inferred_err_set_type;
4066 if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) {4099 if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorSet) {
4067 inferred_err_set_type = fn_table_entry->src_implicit_return_type;4100 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) {
4069 inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;4102 inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;
4070 } else {4103 } else {
4071 add_node_error(g, return_type_node,4104 add_node_error(g, return_type_node,
...@@ -4105,7 +4138,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ...@@ -4105,7 +4138,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
4105 fn_table_entry->anal_state = FnAnalStateComplete;4138 fn_table_entry->anal_state = FnAnalStateComplete;
4106}4139}
41074140
4108static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {4141static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
4109 assert(fn_table_entry->anal_state != FnAnalStateProbing);4142 assert(fn_table_entry->anal_state != FnAnalStateProbing);
4110 if (fn_table_entry->anal_state != FnAnalStateReady)4143 if (fn_table_entry->anal_state != FnAnalStateReady)
4111 return;4144 return;
...@@ -4121,7 +4154,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -4121,7 +4154,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
41214154
4122 define_local_param_variables(g, fn_table_entry);4155 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;
4125 assert(!fn_type->data.fn.is_generic);4158 assert(!fn_type->data.fn.is_generic);
41264159
4127 ir_gen_fn(g, fn_table_entry);4160 ir_gen_fn(g, fn_table_entry);
...@@ -4146,7 +4179,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4146,7 +4179,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
4146 }4179 }
41474180
4148 IrInstruction *use_target_value = src_use_node->data.use.value;4181 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) {
4150 dst_use_node->owner->any_imports_failed = true;4183 dst_use_node->owner->any_imports_failed = true;
4151 return;4184 return;
4152 }4185 }
...@@ -4222,15 +4255,15 @@ void preview_use_decl(CodeGen *g, AstNode *node) {...@@ -4222,15 +4255,15 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
4222 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,4255 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
4223 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);4256 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)
4226 node->owner->any_imports_failed = true;4259 node->owner->any_imports_failed = true;
42274260
4228 node->data.use.value = result;4261 node->data.use.value = result;
4229}4262}
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) {
4232 if (g->verbose_tokenize) {4265 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));
4234 fprintf(stderr, "----------------\n");4267 fprintf(stderr, "----------------\n");
4235 fprintf(stderr, "%s\n", buf_ptr(source_code));4268 fprintf(stderr, "%s\n", buf_ptr(source_code));
42364269
...@@ -4242,7 +4275,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a...@@ -4242,7 +4275,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
4242 tokenize(source_code, &tokenization);4275 tokenize(source_code, &tokenization);
42434276
4244 if (tokenization.err) {4277 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,
4246 source_code, tokenization.line_offsets, tokenization.err);4279 source_code, tokenization.line_offsets, tokenization.err);
42474280
4248 print_err_msg(err, g->err_color);4281 print_err_msg(err, g->err_color);
...@@ -4260,7 +4293,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a...@@ -4260,7 +4293,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
4260 import_entry->package = package;4293 import_entry->package = package;
4261 import_entry->source_code = source_code;4294 import_entry->source_code = source_code;
4262 import_entry->line_offsets = tokenization.line_offsets;4295 import_entry->line_offsets = tokenization.line_offsets;
4263 import_entry->path = abs_full_path;4296 import_entry->path = resolved_path;
42644297
4265 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);4298 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
4266 assert(import_entry->root);4299 assert(import_entry->root);
...@@ -4270,10 +4303,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a...@@ -4270,10 +4303,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
42704303
4271 Buf *src_dirname = buf_alloc();4304 Buf *src_dirname = buf_alloc();
4272 Buf *src_basename = buf_alloc();4305 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
4275 import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));4308 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);
4277 g->import_queue.append(import_entry);4310 g->import_queue.append(import_entry);
42784311
4279 import_entry->decls_scope = create_decls_scope(import_entry->root, nullptr, nullptr, import_entry);4312 import_entry->decls_scope = create_decls_scope(import_entry->root, nullptr, nullptr, import_entry);
...@@ -4341,15 +4374,15 @@ void semantic_analyze(CodeGen *g) {...@@ -4341,15 +4374,15 @@ void semantic_analyze(CodeGen *g) {
4341 }4374 }
43424375
4343 for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {4376 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);
4345 analyze_fn_body(g, fn_entry);4378 analyze_fn_body(g, fn_entry);
4346 }4379 }
4347 }4380 }
4348}4381}
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) {
4351 TypeId type_id = {};4384 TypeId type_id = {};
4352 type_id.id = TypeTableEntryIdInt;4385 type_id.id = ZigTypeIdInt;
4353 type_id.data.integer.is_signed = is_signed;4386 type_id.data.integer.is_signed = is_signed;
4354 type_id.data.integer.bit_count = size_in_bits;4387 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)...@@ -4359,53 +4392,53 @@ TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
4359 return entry->value;4392 return entry->value;
4360 }4393 }
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);
4363 g->type_table.put(type_id, new_entry);4396 g->type_table.put(type_id, new_entry);
4364 return new_entry;4397 return new_entry;
4365}4398}
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) {
4368 return &g->builtin_types.entry_c_int[c_int_type];4401 return &g->builtin_types.entry_c_int[c_int_type];
4369}4402}
43704403
4371TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type) {4404ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
4372 return *get_c_int_type_ptr(g, c_int_type);4405 return *get_c_int_type_ptr(g, c_int_type);
4373}4406}
43744407
4375bool handle_is_ptr(TypeTableEntry *type_entry) {4408bool handle_is_ptr(ZigType *type_entry) {
4376 switch (type_entry->id) {4409 switch (type_entry->id) {
4377 case TypeTableEntryIdInvalid:4410 case ZigTypeIdInvalid:
4378 case TypeTableEntryIdMetaType:4411 case ZigTypeIdMetaType:
4379 case TypeTableEntryIdComptimeFloat:4412 case ZigTypeIdComptimeFloat:
4380 case TypeTableEntryIdComptimeInt:4413 case ZigTypeIdComptimeInt:
4381 case TypeTableEntryIdUndefined:4414 case ZigTypeIdUndefined:
4382 case TypeTableEntryIdNull:4415 case ZigTypeIdNull:
4383 case TypeTableEntryIdNamespace:4416 case ZigTypeIdNamespace:
4384 case TypeTableEntryIdBlock:4417 case ZigTypeIdBlock:
4385 case TypeTableEntryIdBoundFn:4418 case ZigTypeIdBoundFn:
4386 case TypeTableEntryIdArgTuple:4419 case ZigTypeIdArgTuple:
4387 case TypeTableEntryIdOpaque:4420 case ZigTypeIdOpaque:
4388 zig_unreachable();4421 zig_unreachable();
4389 case TypeTableEntryIdUnreachable:4422 case ZigTypeIdUnreachable:
4390 case TypeTableEntryIdVoid:4423 case ZigTypeIdVoid:
4391 case TypeTableEntryIdBool:4424 case ZigTypeIdBool:
4392 case TypeTableEntryIdInt:4425 case ZigTypeIdInt:
4393 case TypeTableEntryIdFloat:4426 case ZigTypeIdFloat:
4394 case TypeTableEntryIdPointer:4427 case ZigTypeIdPointer:
4395 case TypeTableEntryIdErrorSet:4428 case ZigTypeIdErrorSet:
4396 case TypeTableEntryIdFn:4429 case ZigTypeIdFn:
4397 case TypeTableEntryIdEnum:4430 case ZigTypeIdEnum:
4398 case TypeTableEntryIdPromise:4431 case ZigTypeIdPromise:
4399 return false;4432 return false;
4400 case TypeTableEntryIdArray:4433 case ZigTypeIdArray:
4401 case TypeTableEntryIdStruct:4434 case ZigTypeIdStruct:
4402 return type_has_bits(type_entry);4435 return type_has_bits(type_entry);
4403 case TypeTableEntryIdErrorUnion:4436 case ZigTypeIdErrorUnion:
4404 return type_has_bits(type_entry->data.error_union.payload_type);4437 return type_has_bits(type_entry->data.error_union.payload_type);
4405 case TypeTableEntryIdOptional:4438 case ZigTypeIdOptional:
4406 return type_has_bits(type_entry->data.maybe.child_type) &&4439 return type_has_bits(type_entry->data.maybe.child_type) &&
4407 !type_is_codegen_pointer(type_entry->data.maybe.child_type);4440 !type_is_codegen_pointer(type_entry->data.maybe.child_type);
4408 case TypeTableEntryIdUnion:4441 case ZigTypeIdUnion:
4409 assert(type_entry->data.unionation.complete);4442 assert(type_entry->data.unionation.complete);
4410 if (type_entry->data.unionation.gen_field_count == 0)4443 if (type_entry->data.unionation.gen_field_count == 0)
4411 return false;4444 return false;
...@@ -4594,11 +4627,11 @@ static uint32_t hash_size(size_t x) {...@@ -4594,11 +4627,11 @@ static uint32_t hash_size(size_t x) {
4594 return (uint32_t)(x % UINT32_MAX);4627 return (uint32_t)(x % UINT32_MAX);
4595}4628}
45964629
4597uint32_t fn_table_entry_hash(FnTableEntry* value) {4630uint32_t fn_table_entry_hash(ZigFn* value) {
4598 return ptr_hash(value);4631 return ptr_hash(value);
4599}4632}
46004633
4601bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b) {4634bool fn_table_entry_eql(ZigFn *a, ZigFn *b) {
4602 return ptr_eq(a, b);4635 return ptr_eq(a, b);
4603}4636}
46044637
...@@ -4689,16 +4722,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {...@@ -4689,16 +4722,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
4689static uint32_t hash_const_val(ConstExprValue *const_val) {4722static uint32_t hash_const_val(ConstExprValue *const_val) {
4690 assert(const_val->special == ConstValSpecialStatic);4723 assert(const_val->special == ConstValSpecialStatic);
4691 switch (const_val->type->id) {4724 switch (const_val->type->id) {
4692 case TypeTableEntryIdOpaque:4725 case ZigTypeIdOpaque:
4693 zig_unreachable();4726 zig_unreachable();
4694 case TypeTableEntryIdBool:4727 case ZigTypeIdBool:
4695 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;4728 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
4696 case TypeTableEntryIdMetaType:4729 case ZigTypeIdMetaType:
4697 return hash_ptr(const_val->data.x_type);4730 return hash_ptr(const_val->data.x_type);
4698 case TypeTableEntryIdVoid:4731 case ZigTypeIdVoid:
4699 return (uint32_t)4149439618;4732 return (uint32_t)4149439618;
4700 case TypeTableEntryIdInt:4733 case ZigTypeIdInt:
4701 case TypeTableEntryIdComptimeInt:4734 case ZigTypeIdComptimeInt:
4702 {4735 {
4703 uint32_t result = 1331471175;4736 uint32_t result = 1331471175;
4704 for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {4737 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) {...@@ -4707,7 +4740,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4707 }4740 }
4708 return result;4741 return result;
4709 }4742 }
4710 case TypeTableEntryIdEnum:4743 case ZigTypeIdEnum:
4711 {4744 {
4712 uint32_t result = 31643936;4745 uint32_t result = 31643936;
4713 for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) {4746 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) {...@@ -4716,7 +4749,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4716 }4749 }
4717 return result;4750 return result;
4718 }4751 }
4719 case TypeTableEntryIdFloat:4752 case ZigTypeIdFloat:
4720 switch (const_val->type->data.floating.bit_count) {4753 switch (const_val->type->data.floating.bit_count) {
4721 case 16:4754 case 16:
4722 {4755 {
...@@ -4746,39 +4779,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4746,39 +4779,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4746 default:4779 default:
4747 zig_unreachable();4780 zig_unreachable();
4748 }4781 }
4749 case TypeTableEntryIdComptimeFloat:4782 case ZigTypeIdComptimeFloat:
4750 {4783 {
4751 float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);4784 float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
4752 uint32_t ints[4];4785 uint32_t ints[4];
4753 memcpy(&ints[0], &f128, 16);4786 memcpy(&ints[0], &f128, 16);
4754 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;4787 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;
4755 }4788 }
4756 case TypeTableEntryIdArgTuple:4789 case ZigTypeIdArgTuple:
4757 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +4790 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
4758 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;4791 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
4759 case TypeTableEntryIdFn:4792 case ZigTypeIdFn:
4760 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);4793 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
4761 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);4794 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
4762 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);4795 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4763 case TypeTableEntryIdPointer:4796 case ZigTypeIdPointer:
4764 return hash_const_val_ptr(const_val);4797 return hash_const_val_ptr(const_val);
4765 case TypeTableEntryIdPromise:4798 case ZigTypeIdPromise:
4766 // TODO better hashing algorithm4799 // TODO better hashing algorithm
4767 return 223048345;4800 return 223048345;
4768 case TypeTableEntryIdUndefined:4801 case ZigTypeIdUndefined:
4769 return 162837799;4802 return 162837799;
4770 case TypeTableEntryIdNull:4803 case ZigTypeIdNull:
4771 return 844854567;4804 return 844854567;
4772 case TypeTableEntryIdArray:4805 case ZigTypeIdArray:
4773 // TODO better hashing algorithm4806 // TODO better hashing algorithm
4774 return 1166190605;4807 return 1166190605;
4775 case TypeTableEntryIdStruct:4808 case ZigTypeIdStruct:
4776 // TODO better hashing algorithm4809 // TODO better hashing algorithm
4777 return 1532530855;4810 return 1532530855;
4778 case TypeTableEntryIdUnion:4811 case ZigTypeIdUnion:
4779 // TODO better hashing algorithm4812 // TODO better hashing algorithm
4780 return 2709806591;4813 return 2709806591;
4781 case TypeTableEntryIdOptional:4814 case ZigTypeIdOptional:
4782 if (get_codegen_ptr_type(const_val->type) != nullptr) {4815 if (get_codegen_ptr_type(const_val->type) != nullptr) {
4783 return hash_const_val(const_val) * 1992916303;4816 return hash_const_val(const_val) * 1992916303;
4784 } else {4817 } else {
...@@ -4788,19 +4821,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4788,19 +4821,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4788 return 4016830364;4821 return 4016830364;
4789 }4822 }
4790 }4823 }
4791 case TypeTableEntryIdErrorUnion:4824 case ZigTypeIdErrorUnion:
4792 // TODO better hashing algorithm4825 // TODO better hashing algorithm
4793 return 3415065496;4826 return 3415065496;
4794 case TypeTableEntryIdErrorSet:4827 case ZigTypeIdErrorSet:
4795 assert(const_val->data.x_err_set != nullptr);4828 assert(const_val->data.x_err_set != nullptr);
4796 return const_val->data.x_err_set->value ^ 2630160122;4829 return const_val->data.x_err_set->value ^ 2630160122;
4797 case TypeTableEntryIdNamespace:4830 case ZigTypeIdNamespace:
4798 return hash_ptr(const_val->data.x_import);4831 return hash_ptr(const_val->data.x_import);
4799 case TypeTableEntryIdBlock:4832 case ZigTypeIdBlock:
4800 return hash_ptr(const_val->data.x_block);4833 return hash_ptr(const_val->data.x_block);
4801 case TypeTableEntryIdBoundFn:4834 case ZigTypeIdBoundFn:
4802 case TypeTableEntryIdInvalid:4835 case ZigTypeIdInvalid:
4803 case TypeTableEntryIdUnreachable:4836 case ZigTypeIdUnreachable:
4804 zig_unreachable();4837 zig_unreachable();
4805 }4838 }
4806 zig_unreachable();4839 zig_unreachable();
...@@ -4843,32 +4876,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -4843,32 +4876,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
4843static bool can_mutate_comptime_var_state(ConstExprValue *value) {4876static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4844 assert(value != nullptr);4877 assert(value != nullptr);
4845 switch (value->type->id) {4878 switch (value->type->id) {
4846 case TypeTableEntryIdInvalid:4879 case ZigTypeIdInvalid:
4847 zig_unreachable();4880 zig_unreachable();
4848 case TypeTableEntryIdMetaType:4881 case ZigTypeIdMetaType:
4849 case TypeTableEntryIdVoid:4882 case ZigTypeIdVoid:
4850 case TypeTableEntryIdBool:4883 case ZigTypeIdBool:
4851 case TypeTableEntryIdUnreachable:4884 case ZigTypeIdUnreachable:
4852 case TypeTableEntryIdInt:4885 case ZigTypeIdInt:
4853 case TypeTableEntryIdFloat:4886 case ZigTypeIdFloat:
4854 case TypeTableEntryIdComptimeFloat:4887 case ZigTypeIdComptimeFloat:
4855 case TypeTableEntryIdComptimeInt:4888 case ZigTypeIdComptimeInt:
4856 case TypeTableEntryIdUndefined:4889 case ZigTypeIdUndefined:
4857 case TypeTableEntryIdNull:4890 case ZigTypeIdNull:
4858 case TypeTableEntryIdNamespace:4891 case ZigTypeIdNamespace:
4859 case TypeTableEntryIdBoundFn:4892 case ZigTypeIdBoundFn:
4860 case TypeTableEntryIdFn:4893 case ZigTypeIdFn:
4861 case TypeTableEntryIdBlock:4894 case ZigTypeIdBlock:
4862 case TypeTableEntryIdOpaque:4895 case ZigTypeIdOpaque:
4863 case TypeTableEntryIdPromise:4896 case ZigTypeIdPromise:
4864 case TypeTableEntryIdErrorSet:4897 case ZigTypeIdErrorSet:
4865 case TypeTableEntryIdEnum:4898 case ZigTypeIdEnum:
4866 return false;4899 return false;
48674900
4868 case TypeTableEntryIdPointer:4901 case ZigTypeIdPointer:
4869 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;4902 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
48704903
4871 case TypeTableEntryIdArray:4904 case ZigTypeIdArray:
4872 if (value->type->data.array.len == 0)4905 if (value->type->data.array.len == 0)
4873 return false;4906 return false;
4874 if (value->data.x_array.special == ConstArraySpecialUndef)4907 if (value->data.x_array.special == ConstArraySpecialUndef)
...@@ -4879,78 +4912,78 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4879,78 +4912,78 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4879 }4912 }
4880 return false;4913 return false;
48814914
4882 case TypeTableEntryIdStruct:4915 case ZigTypeIdStruct:
4883 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {4916 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
4884 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))4917 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))
4885 return true;4918 return true;
4886 }4919 }
4887 return false;4920 return false;
48884921
4889 case TypeTableEntryIdOptional:4922 case ZigTypeIdOptional:
4890 if (get_codegen_ptr_type(value->type) != nullptr)4923 if (get_codegen_ptr_type(value->type) != nullptr)
4891 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;4924 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
4892 if (value->data.x_optional == nullptr)4925 if (value->data.x_optional == nullptr)
4893 return false;4926 return false;
4894 return can_mutate_comptime_var_state(value->data.x_optional);4927 return can_mutate_comptime_var_state(value->data.x_optional);
48954928
4896 case TypeTableEntryIdErrorUnion:4929 case ZigTypeIdErrorUnion:
4897 if (value->data.x_err_union.err != nullptr)4930 if (value->data.x_err_union.err != nullptr)
4898 return false;4931 return false;
4899 assert(value->data.x_err_union.payload != nullptr);4932 assert(value->data.x_err_union.payload != nullptr);
4900 return can_mutate_comptime_var_state(value->data.x_err_union.payload);4933 return can_mutate_comptime_var_state(value->data.x_err_union.payload);
49014934
4902 case TypeTableEntryIdUnion:4935 case ZigTypeIdUnion:
4903 return can_mutate_comptime_var_state(value->data.x_union.payload);4936 return can_mutate_comptime_var_state(value->data.x_union.payload);
49044937
4905 case TypeTableEntryIdArgTuple:4938 case ZigTypeIdArgTuple:
4906 zig_panic("TODO var args at comptime is currently not supported");4939 zig_panic("TODO var args at comptime is currently not supported");
4907 }4940 }
4908 zig_unreachable();4941 zig_unreachable();
4909}4942}
49104943
4911static bool return_type_is_cacheable(TypeTableEntry *return_type) {4944static bool return_type_is_cacheable(ZigType *return_type) {
4912 switch (return_type->id) {4945 switch (return_type->id) {
4913 case TypeTableEntryIdInvalid:4946 case ZigTypeIdInvalid:
4914 zig_unreachable();4947 zig_unreachable();
4915 case TypeTableEntryIdMetaType:4948 case ZigTypeIdMetaType:
4916 case TypeTableEntryIdVoid:4949 case ZigTypeIdVoid:
4917 case TypeTableEntryIdBool:4950 case ZigTypeIdBool:
4918 case TypeTableEntryIdUnreachable:4951 case ZigTypeIdUnreachable:
4919 case TypeTableEntryIdInt:4952 case ZigTypeIdInt:
4920 case TypeTableEntryIdFloat:4953 case ZigTypeIdFloat:
4921 case TypeTableEntryIdComptimeFloat:4954 case ZigTypeIdComptimeFloat:
4922 case TypeTableEntryIdComptimeInt:4955 case ZigTypeIdComptimeInt:
4923 case TypeTableEntryIdUndefined:4956 case ZigTypeIdUndefined:
4924 case TypeTableEntryIdNull:4957 case ZigTypeIdNull:
4925 case TypeTableEntryIdNamespace:4958 case ZigTypeIdNamespace:
4926 case TypeTableEntryIdBoundFn:4959 case ZigTypeIdBoundFn:
4927 case TypeTableEntryIdFn:4960 case ZigTypeIdFn:
4928 case TypeTableEntryIdBlock:4961 case ZigTypeIdBlock:
4929 case TypeTableEntryIdOpaque:4962 case ZigTypeIdOpaque:
4930 case TypeTableEntryIdPromise:4963 case ZigTypeIdPromise:
4931 case TypeTableEntryIdErrorSet:4964 case ZigTypeIdErrorSet:
4932 case TypeTableEntryIdEnum:4965 case ZigTypeIdEnum:
4933 case TypeTableEntryIdPointer:4966 case ZigTypeIdPointer:
4934 return true;4967 return true;
49354968
4936 case TypeTableEntryIdArray:4969 case ZigTypeIdArray:
4937 case TypeTableEntryIdStruct:4970 case ZigTypeIdStruct:
4938 case TypeTableEntryIdUnion:4971 case ZigTypeIdUnion:
4939 return false;4972 return false;
49404973
4941 case TypeTableEntryIdOptional:4974 case ZigTypeIdOptional:
4942 return return_type_is_cacheable(return_type->data.maybe.child_type);4975 return return_type_is_cacheable(return_type->data.maybe.child_type);
49434976
4944 case TypeTableEntryIdErrorUnion:4977 case ZigTypeIdErrorUnion:
4945 return return_type_is_cacheable(return_type->data.error_union.payload_type);4978 return return_type_is_cacheable(return_type->data.error_union.payload_type);
49464979
4947 case TypeTableEntryIdArgTuple:4980 case ZigTypeIdArgTuple:
4948 zig_panic("TODO var args at comptime is currently not supported");4981 zig_panic("TODO var args at comptime is currently not supported");
4949 }4982 }
4950 zig_unreachable();4983 zig_unreachable();
4951}4984}
49524985
4953bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) {4986bool fn_eval_cacheable(Scope *scope, ZigType *return_type) {
4954 if (!return_type_is_cacheable(return_type))4987 if (!return_type_is_cacheable(return_type))
4955 return false;4988 return false;
4956 while (scope) {4989 while (scope) {
...@@ -5019,56 +5052,56 @@ bool fn_eval_eql(Scope *a, Scope *b) {...@@ -5019,56 +5052,56 @@ bool fn_eval_eql(Scope *a, Scope *b) {
5019 return false;5052 return false;
5020}5053}
50215054
5022bool type_has_bits(TypeTableEntry *type_entry) {5055bool type_has_bits(ZigType *type_entry) {
5023 assert(type_entry);5056 assert(type_entry);
5024 assert(type_entry->id != TypeTableEntryIdInvalid);5057 assert(type_entry->id != ZigTypeIdInvalid);
5025 assert(type_has_zero_bits_known(type_entry));5058 assert(type_has_zero_bits_known(type_entry));
5026 return !type_entry->zero_bits;5059 return !type_entry->zero_bits;
5027}5060}
50285061
5029bool type_requires_comptime(TypeTableEntry *type_entry) {5062bool type_requires_comptime(ZigType *type_entry) {
5030 switch (type_entry->id) {5063 switch (type_entry->id) {
5031 case TypeTableEntryIdInvalid:5064 case ZigTypeIdInvalid:
5032 case TypeTableEntryIdOpaque:5065 case ZigTypeIdOpaque:
5033 zig_unreachable();5066 zig_unreachable();
5034 case TypeTableEntryIdComptimeFloat:5067 case ZigTypeIdComptimeFloat:
5035 case TypeTableEntryIdComptimeInt:5068 case ZigTypeIdComptimeInt:
5036 case TypeTableEntryIdUndefined:5069 case ZigTypeIdUndefined:
5037 case TypeTableEntryIdNull:5070 case ZigTypeIdNull:
5038 case TypeTableEntryIdMetaType:5071 case ZigTypeIdMetaType:
5039 case TypeTableEntryIdNamespace:5072 case ZigTypeIdNamespace:
5040 case TypeTableEntryIdBlock:5073 case ZigTypeIdBlock:
5041 case TypeTableEntryIdBoundFn:5074 case ZigTypeIdBoundFn:
5042 case TypeTableEntryIdArgTuple:5075 case ZigTypeIdArgTuple:
5043 return true;5076 return true;
5044 case TypeTableEntryIdArray:5077 case ZigTypeIdArray:
5045 return type_requires_comptime(type_entry->data.array.child_type);5078 return type_requires_comptime(type_entry->data.array.child_type);
5046 case TypeTableEntryIdStruct:5079 case ZigTypeIdStruct:
5047 assert(type_has_zero_bits_known(type_entry));5080 assert(type_has_zero_bits_known(type_entry));
5048 return type_entry->data.structure.requires_comptime;5081 return type_entry->data.structure.requires_comptime;
5049 case TypeTableEntryIdUnion:5082 case ZigTypeIdUnion:
5050 assert(type_has_zero_bits_known(type_entry));5083 assert(type_has_zero_bits_known(type_entry));
5051 return type_entry->data.unionation.requires_comptime;5084 return type_entry->data.unionation.requires_comptime;
5052 case TypeTableEntryIdOptional:5085 case ZigTypeIdOptional:
5053 return type_requires_comptime(type_entry->data.maybe.child_type);5086 return type_requires_comptime(type_entry->data.maybe.child_type);
5054 case TypeTableEntryIdErrorUnion:5087 case ZigTypeIdErrorUnion:
5055 return type_requires_comptime(type_entry->data.error_union.payload_type);5088 return type_requires_comptime(type_entry->data.error_union.payload_type);
5056 case TypeTableEntryIdPointer:5089 case ZigTypeIdPointer:
5057 if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) {5090 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
5058 return false;5091 return false;
5059 } else {5092 } else {
5060 return type_requires_comptime(type_entry->data.pointer.child_type);5093 return type_requires_comptime(type_entry->data.pointer.child_type);
5061 }5094 }
5062 case TypeTableEntryIdFn:5095 case ZigTypeIdFn:
5063 return type_entry->data.fn.is_generic;5096 return type_entry->data.fn.is_generic;
5064 case TypeTableEntryIdEnum:5097 case ZigTypeIdEnum:
5065 case TypeTableEntryIdErrorSet:5098 case ZigTypeIdErrorSet:
5066 case TypeTableEntryIdBool:5099 case ZigTypeIdBool:
5067 case TypeTableEntryIdInt:5100 case ZigTypeIdInt:
5068 case TypeTableEntryIdFloat:5101 case ZigTypeIdFloat:
5069 case TypeTableEntryIdVoid:5102 case ZigTypeIdVoid:
5070 case TypeTableEntryIdUnreachable:5103 case ZigTypeIdUnreachable:
5071 case TypeTableEntryIdPromise:5104 case ZigTypeIdPromise:
5072 return false;5105 return false;
5073 }5106 }
5074 zig_unreachable();5107 zig_unreachable();
...@@ -5135,27 +5168,27 @@ ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {...@@ -5135,27 +5168,27 @@ ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {
5135 return const_val;5168 return const_val;
5136}5169}
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) {
5139 const_val->special = ConstValSpecialStatic;5172 const_val->special = ConstValSpecialStatic;
5140 const_val->type = type;5173 const_val->type = type;
5141 bigint_init_bigint(&const_val->data.x_bigint, bigint);5174 bigint_init_bigint(&const_val->data.x_bigint, bigint);
5142}5175}
51435176
5144ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint) {5177ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5145 ConstExprValue *const_val = create_const_vals(1);5178 ConstExprValue *const_val = create_const_vals(1);
5146 init_const_bigint(const_val, type, bigint);5179 init_const_bigint(const_val, type, bigint);
5147 return const_val;5180 return const_val;
5148}5181}
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) {
5152 const_val->special = ConstValSpecialStatic;5185 const_val->special = ConstValSpecialStatic;
5153 const_val->type = type;5186 const_val->type = type;
5154 bigint_init_unsigned(&const_val->data.x_bigint, x);5187 bigint_init_unsigned(&const_val->data.x_bigint, x);
5155 const_val->data.x_bigint.is_negative = negative;5188 const_val->data.x_bigint.is_negative = negative;
5156}5189}
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) {
5159 ConstExprValue *const_val = create_const_vals(1);5192 ConstExprValue *const_val = create_const_vals(1);
5160 init_const_unsigned_negative(const_val, type, x, negative);5193 init_const_unsigned_negative(const_val, type, x, negative);
5161 return const_val;5194 return const_val;
...@@ -5169,24 +5202,24 @@ ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {...@@ -5169,24 +5202,24 @@ ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {
5169 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);5202 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
5170}5203}
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) {
5173 const_val->special = ConstValSpecialStatic;5206 const_val->special = ConstValSpecialStatic;
5174 const_val->type = type;5207 const_val->type = type;
5175 bigint_init_signed(&const_val->data.x_bigint, x);5208 bigint_init_signed(&const_val->data.x_bigint, x);
5176}5209}
51775210
5178ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) {5211ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
5179 ConstExprValue *const_val = create_const_vals(1);5212 ConstExprValue *const_val = create_const_vals(1);
5180 init_const_signed(const_val, type, x);5213 init_const_signed(const_val, type, x);
5181 return const_val;5214 return const_val;
5182}5215}
51835216
5184void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) {5217void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5185 const_val->special = ConstValSpecialStatic;5218 const_val->special = ConstValSpecialStatic;
5186 const_val->type = type;5219 const_val->type = type;
5187 if (type->id == TypeTableEntryIdComptimeFloat) {5220 if (type->id == ZigTypeIdComptimeFloat) {
5188 bigfloat_init_64(&const_val->data.x_bigfloat, value);5221 bigfloat_init_64(&const_val->data.x_bigfloat, value);
5189 } else if (type->id == TypeTableEntryIdFloat) {5222 } else if (type->id == ZigTypeIdFloat) {
5190 switch (type->data.floating.bit_count) {5223 switch (type->data.floating.bit_count) {
5191 case 16:5224 case 16:
5192 const_val->data.x_f16 = zig_double_to_f16(value);5225 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...@@ -5208,19 +5241,19 @@ void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double va
5208 }5241 }
5209}5242}
52105243
5211ConstExprValue *create_const_float(TypeTableEntry *type, double value) {5244ConstExprValue *create_const_float(ZigType *type, double value) {
5212 ConstExprValue *const_val = create_const_vals(1);5245 ConstExprValue *const_val = create_const_vals(1);
5213 init_const_float(const_val, type, value);5246 init_const_float(const_val, type, value);
5214 return const_val;5247 return const_val;
5215}5248}
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) {
5218 const_val->special = ConstValSpecialStatic;5251 const_val->special = ConstValSpecialStatic;
5219 const_val->type = type;5252 const_val->type = type;
5220 bigint_init_bigint(&const_val->data.x_enum_tag, tag);5253 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
5221}5254}
52225255
5223ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag) {5256ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {
5224 ConstExprValue *const_val = create_const_vals(1);5257 ConstExprValue *const_val = create_const_vals(1);
5225 init_const_enum(const_val, type, tag);5258 init_const_enum(const_val, type, tag);
5226 return const_val;5259 return const_val;
...@@ -5239,24 +5272,24 @@ ConstExprValue *create_const_bool(CodeGen *g, bool value) {...@@ -5239,24 +5272,24 @@ ConstExprValue *create_const_bool(CodeGen *g, bool value) {
5239 return const_val;5272 return const_val;
5240}5273}
52415274
5242void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type) {5275void init_const_runtime(ConstExprValue *const_val, ZigType *type) {
5243 const_val->special = ConstValSpecialRuntime;5276 const_val->special = ConstValSpecialRuntime;
5244 const_val->type = type;5277 const_val->type = type;
5245}5278}
52465279
5247ConstExprValue *create_const_runtime(TypeTableEntry *type) {5280ConstExprValue *create_const_runtime(ZigType *type) {
5248 ConstExprValue *const_val = create_const_vals(1);5281 ConstExprValue *const_val = create_const_vals(1);
5249 init_const_runtime(const_val, type);5282 init_const_runtime(const_val, type);
5250 return const_val;5283 return const_val;
5251}5284}
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) {
5254 const_val->special = ConstValSpecialStatic;5287 const_val->special = ConstValSpecialStatic;
5255 const_val->type = g->builtin_types.entry_type;5288 const_val->type = g->builtin_types.entry_type;
5256 const_val->data.x_type = type_value;5289 const_val->data.x_type = type_value;
5257}5290}
52585291
5259ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {5292ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {
5260 ConstExprValue *const_val = create_const_vals(1);5293 ConstExprValue *const_val = create_const_vals(1);
5261 init_const_type(g, const_val, type_value);5294 init_const_type(g, const_val, type_value);
5262 return const_val;5295 return const_val;
...@@ -5265,9 +5298,9 @@ ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {...@@ -5265,9 +5298,9 @@ ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
5265void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5298void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
5266 size_t start, size_t len, bool is_const)5299 size_t start, size_t len, bool is_const)
5267{5300{
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,
5271 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),5304 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),
5272 0, 0);5305 0, 0);
52735306
...@@ -5289,8 +5322,8 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t...@@ -5289,8 +5322,8 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
5289void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5322void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
5290 size_t elem_index, bool is_const, PtrLen ptr_len)5323 size_t elem_index, bool is_const, PtrLen ptr_len)
5291{5324{
5292 assert(array_val->type->id == TypeTableEntryIdArray);5325 assert(array_val->type->id == ZigTypeIdArray);
5293 TypeTableEntry *child_type = array_val->type->data.array.child_type;5326 ZigType *child_type = array_val->type->data.array.child_type;
52945327
5295 const_val->special = ConstValSpecialStatic;5328 const_val->special = ConstValSpecialStatic;
5296 const_val->type = get_pointer_to_type_extra(g, child_type, is_const, false,5329 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...@@ -5321,7 +5354,7 @@ ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bo
5321 return const_val;5354 return const_val;
5322}5355}
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,
5325 size_t addr, bool is_const)5358 size_t addr, bool is_const)
5326{5359{
5327 const_val->special = ConstValSpecialStatic;5360 const_val->special = ConstValSpecialStatic;
...@@ -5330,7 +5363,7 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeT...@@ -5330,7 +5363,7 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeT
5330 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;5363 const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
5331}5364}
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,
5334 size_t addr, bool is_const)5367 size_t addr, bool is_const)
5335{5368{
5336 ConstExprValue *const_val = create_const_vals(1);5369 ConstExprValue *const_val = create_const_vals(1);
...@@ -5354,11 +5387,11 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_...@@ -5354,11 +5387,11 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
53545387
5355void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {5388void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
5356 Error err;5389 Error err;
5357 TypeTableEntry *wanted_type = const_val->type;5390 ZigType *wanted_type = const_val->type;
5358 if (wanted_type->id == TypeTableEntryIdArray) {5391 if (wanted_type->id == ZigTypeIdArray) {
5359 const_val->special = ConstValSpecialStatic;5392 const_val->special = ConstValSpecialStatic;
5360 const_val->data.x_array.special = ConstArraySpecialUndef;5393 const_val->data.x_array.special = ConstArraySpecialUndef;
5361 } else if (wanted_type->id == TypeTableEntryIdStruct) {5394 } else if (wanted_type->id == ZigTypeIdStruct) {
5362 if ((err = ensure_complete_type(g, wanted_type))) {5395 if ((err = ensure_complete_type(g, wanted_type))) {
5363 return;5396 return;
5364 }5397 }
...@@ -5392,36 +5425,36 @@ ConstExprValue *create_const_vals(size_t count) {...@@ -5392,36 +5425,36 @@ ConstExprValue *create_const_vals(size_t count) {
5392 return vals;5425 return vals;
5393}5426}
53945427
5395Error ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry) {5428Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {
5396 if (type_is_invalid(type_entry))5429 if (type_is_invalid(type_entry))
5397 return ErrorSemanticAnalyzeFail;5430 return ErrorSemanticAnalyzeFail;
5398 if (type_entry->id == TypeTableEntryIdStruct) {5431 if (type_entry->id == ZigTypeIdStruct) {
5399 if (!type_entry->data.structure.complete)5432 if (!type_entry->data.structure.complete)
5400 return resolve_struct_type(g, type_entry);5433 return resolve_struct_type(g, type_entry);
5401 } else if (type_entry->id == TypeTableEntryIdEnum) {5434 } else if (type_entry->id == ZigTypeIdEnum) {
5402 if (!type_entry->data.enumeration.complete)5435 if (!type_entry->data.enumeration.complete)
5403 return resolve_enum_type(g, type_entry);5436 return resolve_enum_type(g, type_entry);
5404 } else if (type_entry->id == TypeTableEntryIdUnion) {5437 } else if (type_entry->id == ZigTypeIdUnion) {
5405 if (!type_entry->data.unionation.complete)5438 if (!type_entry->data.unionation.complete)
5406 return resolve_union_type(g, type_entry);5439 return resolve_union_type(g, type_entry);
5407 }5440 }
5408 return ErrorNone;5441 return ErrorNone;
5409}5442}
54105443
5411Error type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry) {5444Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {
5412 if (type_is_invalid(type_entry))5445 if (type_is_invalid(type_entry))
5413 return ErrorSemanticAnalyzeFail;5446 return ErrorSemanticAnalyzeFail;
5414 if (type_entry->id == TypeTableEntryIdStruct) {5447 if (type_entry->id == ZigTypeIdStruct) {
5415 return resolve_struct_zero_bits(g, type_entry);5448 return resolve_struct_zero_bits(g, type_entry);
5416 } else if (type_entry->id == TypeTableEntryIdEnum) {5449 } else if (type_entry->id == ZigTypeIdEnum) {
5417 return resolve_enum_zero_bits(g, type_entry);5450 return resolve_enum_zero_bits(g, type_entry);
5418 } else if (type_entry->id == TypeTableEntryIdUnion) {5451 } else if (type_entry->id == ZigTypeIdUnion) {
5419 return resolve_union_zero_bits(g, type_entry);5452 return resolve_union_zero_bits(g, type_entry);
5420 }5453 }
5421 return ErrorNone;5454 return ErrorNone;
5422}5455}
54235456
5424bool ir_get_var_is_comptime(VariableTableEntry *var) {5457bool ir_get_var_is_comptime(ZigVar *var) {
5425 if (!var->is_comptime)5458 if (!var->is_comptime)
5426 return false;5459 return false;
5427 if (var->is_comptime->other)5460 if (var->is_comptime->other)
...@@ -5480,11 +5513,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5480,11 +5513,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5480 assert(a->special == ConstValSpecialStatic);5513 assert(a->special == ConstValSpecialStatic);
5481 assert(b->special == ConstValSpecialStatic);5514 assert(b->special == ConstValSpecialStatic);
5482 switch (a->type->id) {5515 switch (a->type->id) {
5483 case TypeTableEntryIdOpaque:5516 case ZigTypeIdOpaque:
5484 zig_unreachable();5517 zig_unreachable();
5485 case TypeTableEntryIdEnum:5518 case ZigTypeIdEnum:
5486 return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;5519 return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;
5487 case TypeTableEntryIdUnion: {5520 case ZigTypeIdUnion: {
5488 ConstUnionValue *union1 = &a->data.x_union;5521 ConstUnionValue *union1 = &a->data.x_union;
5489 ConstUnionValue *union2 = &b->data.x_union;5522 ConstUnionValue *union2 = &b->data.x_union;
54905523
...@@ -5499,15 +5532,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5499,15 +5532,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5499 }5532 }
5500 return false;5533 return false;
5501 }5534 }
5502 case TypeTableEntryIdMetaType:5535 case ZigTypeIdMetaType:
5503 return a->data.x_type == b->data.x_type;5536 return a->data.x_type == b->data.x_type;
5504 case TypeTableEntryIdVoid:5537 case ZigTypeIdVoid:
5505 return true;5538 return true;
5506 case TypeTableEntryIdErrorSet:5539 case ZigTypeIdErrorSet:
5507 return a->data.x_err_set->value == b->data.x_err_set->value;5540 return a->data.x_err_set->value == b->data.x_err_set->value;
5508 case TypeTableEntryIdBool:5541 case ZigTypeIdBool:
5509 return a->data.x_bool == b->data.x_bool;5542 return a->data.x_bool == b->data.x_bool;
5510 case TypeTableEntryIdFloat:5543 case ZigTypeIdFloat:
5511 assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);5544 assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);
5512 switch (a->type->data.floating.bit_count) {5545 switch (a->type->data.floating.bit_count) {
5513 case 16:5546 case 16:
...@@ -5521,15 +5554,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5521,15 +5554,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5521 default:5554 default:
5522 zig_unreachable();5555 zig_unreachable();
5523 }5556 }
5524 case TypeTableEntryIdComptimeFloat:5557 case ZigTypeIdComptimeFloat:
5525 return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;5558 return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;
5526 case TypeTableEntryIdInt:5559 case ZigTypeIdInt:
5527 case TypeTableEntryIdComptimeInt:5560 case ZigTypeIdComptimeInt:
5528 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;5561 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
5529 case TypeTableEntryIdPointer:5562 case ZigTypeIdPointer:
5530 case TypeTableEntryIdFn:5563 case ZigTypeIdFn:
5531 return const_values_equal_ptr(a, b);5564 return const_values_equal_ptr(a, b);
5532 case TypeTableEntryIdArray: {5565 case ZigTypeIdArray: {
5533 assert(a->type->data.array.len == b->type->data.array.len);5566 assert(a->type->data.array.len == b->type->data.array.len);
5534 assert(a->data.x_array.special != ConstArraySpecialUndef);5567 assert(a->data.x_array.special != ConstArraySpecialUndef);
5535 assert(b->data.x_array.special != ConstArraySpecialUndef);5568 assert(b->data.x_array.special != ConstArraySpecialUndef);
...@@ -5545,7 +5578,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5545,7 +5578,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55455578
5546 return true;5579 return true;
5547 }5580 }
5548 case TypeTableEntryIdStruct:5581 case ZigTypeIdStruct:
5549 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {5582 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
5550 ConstExprValue *field_a = &a->data.x_struct.fields[i];5583 ConstExprValue *field_a = &a->data.x_struct.fields[i];
5551 ConstExprValue *field_b = &b->data.x_struct.fields[i];5584 ConstExprValue *field_b = &b->data.x_struct.fields[i];
...@@ -5553,11 +5586,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5553,11 +5586,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5553 return false;5586 return false;
5554 }5587 }
5555 return true;5588 return true;
5556 case TypeTableEntryIdUndefined:5589 case ZigTypeIdUndefined:
5557 zig_panic("TODO");5590 zig_panic("TODO");
5558 case TypeTableEntryIdNull:5591 case ZigTypeIdNull:
5559 zig_panic("TODO");5592 zig_panic("TODO");
5560 case TypeTableEntryIdOptional:5593 case ZigTypeIdOptional:
5561 if (get_codegen_ptr_type(a->type) != nullptr)5594 if (get_codegen_ptr_type(a->type) != nullptr)
5562 return const_values_equal_ptr(a, b);5595 return const_values_equal_ptr(a, b);
5563 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {5596 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
...@@ -5565,26 +5598,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5565,26 +5598,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5565 } else {5598 } else {
5566 return const_values_equal(a->data.x_optional, b->data.x_optional);5599 return const_values_equal(a->data.x_optional, b->data.x_optional);
5567 }5600 }
5568 case TypeTableEntryIdErrorUnion:5601 case ZigTypeIdErrorUnion:
5569 zig_panic("TODO");5602 zig_panic("TODO");
5570 case TypeTableEntryIdNamespace:5603 case ZigTypeIdNamespace:
5571 return a->data.x_import == b->data.x_import;5604 return a->data.x_import == b->data.x_import;
5572 case TypeTableEntryIdBlock:5605 case ZigTypeIdBlock:
5573 return a->data.x_block == b->data.x_block;5606 return a->data.x_block == b->data.x_block;
5574 case TypeTableEntryIdArgTuple:5607 case ZigTypeIdArgTuple:
5575 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&5608 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
5576 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;5609 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
5577 case TypeTableEntryIdBoundFn:5610 case ZigTypeIdBoundFn:
5578 case TypeTableEntryIdInvalid:5611 case ZigTypeIdInvalid:
5579 case TypeTableEntryIdUnreachable:5612 case ZigTypeIdUnreachable:
5580 case TypeTableEntryIdPromise:5613 case ZigTypeIdPromise:
5581 zig_unreachable();5614 zig_unreachable();
5582 }5615 }
5583 zig_unreachable();5616 zig_unreachable();
5584}5617}
55855618
5586void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max) {5619void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) {
5587 assert(int_type->id == TypeTableEntryIdInt);5620 assert(int_type->id == ZigTypeIdInt);
5588 if (int_type->data.integral.bit_count == 0) {5621 if (int_type->data.integral.bit_count == 0) {
5589 bigint_init_unsigned(bigint, 0);5622 bigint_init_unsigned(bigint, 0);
5590 return;5623 return;
...@@ -5620,21 +5653,21 @@ void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint...@@ -5620,21 +5653,21 @@ void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint
5620 }5653 }
5621}5654}
56225655
5623void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) {5656void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {
5624 if (type_entry->id == TypeTableEntryIdInt) {5657 if (type_entry->id == ZigTypeIdInt) {
5625 const_val->special = ConstValSpecialStatic;5658 const_val->special = ConstValSpecialStatic;
5626 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);5659 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) {
5628 const_val->special = ConstValSpecialStatic;5661 const_val->special = ConstValSpecialStatic;
5629 const_val->data.x_bool = is_max;5662 const_val->data.x_bool = is_max;
5630 } else if (type_entry->id == TypeTableEntryIdVoid) {5663 } else if (type_entry->id == ZigTypeIdVoid) {
5631 // nothing to do5664 // nothing to do
5632 } else {5665 } else {
5633 zig_unreachable();5666 zig_unreachable();
5634 }5667 }
5635}5668}
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) {
5638 switch (const_val->data.x_ptr.special) {5671 switch (const_val->data.x_ptr.special) {
5639 case ConstPtrSpecialInvalid:5672 case ConstPtrSpecialInvalid:
5640 zig_unreachable();5673 zig_unreachable();
...@@ -5661,7 +5694,7 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeT...@@ -5661,7 +5694,7 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeT
5661 return;5694 return;
5662 case ConstPtrSpecialFunction:5695 case ConstPtrSpecialFunction:
5663 {5696 {
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;
5665 buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name));5698 buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name));
5666 return;5699 return;
5667 }5700 }
...@@ -5682,20 +5715,20 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5682,20 +5715,20 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5682 }5715 }
5683 assert(const_val->type);5716 assert(const_val->type);
56845717
5685 TypeTableEntry *type_entry = const_val->type;5718 ZigType *type_entry = const_val->type;
5686 switch (type_entry->id) {5719 switch (type_entry->id) {
5687 case TypeTableEntryIdOpaque:5720 case ZigTypeIdOpaque:
5688 zig_unreachable();5721 zig_unreachable();
5689 case TypeTableEntryIdInvalid:5722 case ZigTypeIdInvalid:
5690 buf_appendf(buf, "(invalid)");5723 buf_appendf(buf, "(invalid)");
5691 return;5724 return;
5692 case TypeTableEntryIdVoid:5725 case ZigTypeIdVoid:
5693 buf_appendf(buf, "{}");5726 buf_appendf(buf, "{}");
5694 return;5727 return;
5695 case TypeTableEntryIdComptimeFloat:5728 case ZigTypeIdComptimeFloat:
5696 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);5729 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
5697 return;5730 return;
5698 case TypeTableEntryIdFloat:5731 case ZigTypeIdFloat:
5699 switch (type_entry->data.floating.bit_count) {5732 switch (type_entry->data.floating.bit_count) {
5700 case 16:5733 case 16:
5701 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));5734 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) {...@@ -5723,41 +5756,41 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5723 default:5756 default:
5724 zig_unreachable();5757 zig_unreachable();
5725 }5758 }
5726 case TypeTableEntryIdComptimeInt:5759 case ZigTypeIdComptimeInt:
5727 case TypeTableEntryIdInt:5760 case ZigTypeIdInt:
5728 bigint_append_buf(buf, &const_val->data.x_bigint, 10);5761 bigint_append_buf(buf, &const_val->data.x_bigint, 10);
5729 return;5762 return;
5730 case TypeTableEntryIdMetaType:5763 case ZigTypeIdMetaType:
5731 buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));5764 buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));
5732 return;5765 return;
5733 case TypeTableEntryIdUnreachable:5766 case ZigTypeIdUnreachable:
5734 buf_appendf(buf, "unreachable");5767 buf_appendf(buf, "unreachable");
5735 return;5768 return;
5736 case TypeTableEntryIdBool:5769 case ZigTypeIdBool:
5737 {5770 {
5738 const char *value = const_val->data.x_bool ? "true" : "false";5771 const char *value = const_val->data.x_bool ? "true" : "false";
5739 buf_appendf(buf, "%s", value);5772 buf_appendf(buf, "%s", value);
5740 return;5773 return;
5741 }5774 }
5742 case TypeTableEntryIdFn:5775 case ZigTypeIdFn:
5743 {5776 {
5744 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);5777 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
5745 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);5778 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;
5747 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));5780 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
5748 return;5781 return;
5749 }5782 }
5750 case TypeTableEntryIdPointer:5783 case ZigTypeIdPointer:
5751 return render_const_val_ptr(g, buf, const_val, type_entry);5784 return render_const_val_ptr(g, buf, const_val, type_entry);
5752 case TypeTableEntryIdBlock:5785 case ZigTypeIdBlock:
5753 {5786 {
5754 AstNode *node = const_val->data.x_block->source_node;5787 AstNode *node = const_val->data.x_block->source_node;
5755 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);5788 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
5756 return;5789 return;
5757 }5790 }
5758 case TypeTableEntryIdArray:5791 case ZigTypeIdArray:
5759 {5792 {
5760 TypeTableEntry *child_type = type_entry->data.array.child_type;5793 ZigType *child_type = type_entry->data.array.child_type;
5761 uint64_t len = type_entry->data.array.len;5794 uint64_t len = type_entry->data.array.len;
57625795
5763 if (const_val->data.x_array.special == ConstArraySpecialUndef) {5796 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
...@@ -5766,7 +5799,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5766,7 +5799,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5766 }5799 }
57675800
5768 // if it's []u8, assume UTF-8 and output a string5801 // if it's []u8, assume UTF-8 and output a string
5769 if (child_type->id == TypeTableEntryIdInt &&5802 if (child_type->id == ZigTypeIdInt &&
5770 child_type->data.integral.bit_count == 8 &&5803 child_type->data.integral.bit_count == 8 &&
5771 !child_type->data.integral.is_signed)5804 !child_type->data.integral.is_signed)
5772 {5805 {
...@@ -5796,17 +5829,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5796,17 +5829,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5796 buf_appendf(buf, "}");5829 buf_appendf(buf, "}");
5797 return;5830 return;
5798 }5831 }
5799 case TypeTableEntryIdNull:5832 case ZigTypeIdNull:
5800 {5833 {
5801 buf_appendf(buf, "null");5834 buf_appendf(buf, "null");
5802 return;5835 return;
5803 }5836 }
5804 case TypeTableEntryIdUndefined:5837 case ZigTypeIdUndefined:
5805 {5838 {
5806 buf_appendf(buf, "undefined");5839 buf_appendf(buf, "undefined");
5807 return;5840 return;
5808 }5841 }
5809 case TypeTableEntryIdOptional:5842 case ZigTypeIdOptional:
5810 {5843 {
5811 if (get_codegen_ptr_type(const_val->type) != nullptr)5844 if (get_codegen_ptr_type(const_val->type) != nullptr)
5812 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);5845 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) {...@@ -5817,7 +5850,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5817 }5850 }
5818 return;5851 return;
5819 }5852 }
5820 case TypeTableEntryIdNamespace:5853 case ZigTypeIdNamespace:
5821 {5854 {
5822 ImportTableEntry *import = const_val->data.x_import;5855 ImportTableEntry *import = const_val->data.x_import;
5823 if (import->c_import_node) {5856 if (import->c_import_node) {
...@@ -5827,51 +5860,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5827,51 +5860,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5827 }5860 }
5828 return;5861 return;
5829 }5862 }
5830 case TypeTableEntryIdBoundFn:5863 case ZigTypeIdBoundFn:
5831 {5864 {
5832 FnTableEntry *fn_entry = const_val->data.x_bound_fn.fn;5865 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
5833 buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));5866 buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));
5834 return;5867 return;
5835 }5868 }
5836 case TypeTableEntryIdStruct:5869 case ZigTypeIdStruct:
5837 {5870 {
5838 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));5871 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));
5839 return;5872 return;
5840 }5873 }
5841 case TypeTableEntryIdEnum:5874 case ZigTypeIdEnum:
5842 {5875 {
5843 TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);5876 TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);
5844 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));5877 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));
5845 return;5878 return;
5846 }5879 }
5847 case TypeTableEntryIdErrorUnion:5880 case ZigTypeIdErrorUnion:
5848 {5881 {
5849 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));5882 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));
5850 return;5883 return;
5851 }5884 }
5852 case TypeTableEntryIdUnion:5885 case ZigTypeIdUnion:
5853 {5886 {
5854 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));5887 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));
5855 return;5888 return;
5856 }5889 }
5857 case TypeTableEntryIdErrorSet:5890 case ZigTypeIdErrorSet:
5858 {5891 {
5859 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));5892 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));
5860 return;5893 return;
5861 }5894 }
5862 case TypeTableEntryIdArgTuple:5895 case ZigTypeIdArgTuple:
5863 {5896 {
5864 buf_appendf(buf, "(args value)");5897 buf_appendf(buf, "(args value)");
5865 return;5898 return;
5866 }5899 }
5867 case TypeTableEntryIdPromise:5900 case ZigTypeIdPromise:
5868 zig_unreachable();5901 zig_unreachable();
5869 }5902 }
5870 zig_unreachable();5903 zig_unreachable();
5871}5904}
58725905
5873TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {5906ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
5874 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);5907 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
5875 entry->is_copyable = true;5908 entry->is_copyable = true;
5876 entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);5909 entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);
5877 entry->zero_bits = (size_in_bits == 0);5910 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)...@@ -5905,32 +5938,32 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
59055938
5906uint32_t type_id_hash(TypeId x) {5939uint32_t type_id_hash(TypeId x) {
5907 switch (x.id) {5940 switch (x.id) {
5908 case TypeTableEntryIdInvalid:5941 case ZigTypeIdInvalid:
5909 case TypeTableEntryIdOpaque:5942 case ZigTypeIdOpaque:
5910 case TypeTableEntryIdMetaType:5943 case ZigTypeIdMetaType:
5911 case TypeTableEntryIdVoid:5944 case ZigTypeIdVoid:
5912 case TypeTableEntryIdBool:5945 case ZigTypeIdBool:
5913 case TypeTableEntryIdUnreachable:5946 case ZigTypeIdUnreachable:
5914 case TypeTableEntryIdFloat:5947 case ZigTypeIdFloat:
5915 case TypeTableEntryIdStruct:5948 case ZigTypeIdStruct:
5916 case TypeTableEntryIdComptimeFloat:5949 case ZigTypeIdComptimeFloat:
5917 case TypeTableEntryIdComptimeInt:5950 case ZigTypeIdComptimeInt:
5918 case TypeTableEntryIdUndefined:5951 case ZigTypeIdUndefined:
5919 case TypeTableEntryIdNull:5952 case ZigTypeIdNull:
5920 case TypeTableEntryIdOptional:5953 case ZigTypeIdOptional:
5921 case TypeTableEntryIdErrorSet:5954 case ZigTypeIdErrorSet:
5922 case TypeTableEntryIdEnum:5955 case ZigTypeIdEnum:
5923 case TypeTableEntryIdUnion:5956 case ZigTypeIdUnion:
5924 case TypeTableEntryIdFn:5957 case ZigTypeIdFn:
5925 case TypeTableEntryIdNamespace:5958 case ZigTypeIdNamespace:
5926 case TypeTableEntryIdBlock:5959 case ZigTypeIdBlock:
5927 case TypeTableEntryIdBoundFn:5960 case ZigTypeIdBoundFn:
5928 case TypeTableEntryIdArgTuple:5961 case ZigTypeIdArgTuple:
5929 case TypeTableEntryIdPromise:5962 case ZigTypeIdPromise:
5930 zig_unreachable();5963 zig_unreachable();
5931 case TypeTableEntryIdErrorUnion:5964 case ZigTypeIdErrorUnion:
5932 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);5965 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
5933 case TypeTableEntryIdPointer:5966 case ZigTypeIdPointer:
5934 return hash_ptr(x.data.pointer.child_type) +5967 return hash_ptr(x.data.pointer.child_type) +
5935 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +5968 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
5936 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +5969 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
...@@ -5938,10 +5971,10 @@ uint32_t type_id_hash(TypeId x) {...@@ -5938,10 +5971,10 @@ uint32_t type_id_hash(TypeId x) {
5938 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +5971 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
5939 (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +5972 (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +
5940 (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);5973 (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);
5941 case TypeTableEntryIdArray:5974 case ZigTypeIdArray:
5942 return hash_ptr(x.data.array.child_type) +5975 return hash_ptr(x.data.array.child_type) +
5943 ((uint32_t)x.data.array.size ^ (uint32_t)2122979968);5976 ((uint32_t)x.data.array.size ^ (uint32_t)2122979968);
5944 case TypeTableEntryIdInt:5977 case ZigTypeIdInt:
5945 return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +5978 return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +
5946 (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);5979 (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);
5947 }5980 }
...@@ -5952,34 +5985,34 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5952,34 +5985,34 @@ bool type_id_eql(TypeId a, TypeId b) {
5952 if (a.id != b.id)5985 if (a.id != b.id)
5953 return false;5986 return false;
5954 switch (a.id) {5987 switch (a.id) {
5955 case TypeTableEntryIdInvalid:5988 case ZigTypeIdInvalid:
5956 case TypeTableEntryIdMetaType:5989 case ZigTypeIdMetaType:
5957 case TypeTableEntryIdVoid:5990 case ZigTypeIdVoid:
5958 case TypeTableEntryIdBool:5991 case ZigTypeIdBool:
5959 case TypeTableEntryIdUnreachable:5992 case ZigTypeIdUnreachable:
5960 case TypeTableEntryIdFloat:5993 case ZigTypeIdFloat:
5961 case TypeTableEntryIdStruct:5994 case ZigTypeIdStruct:
5962 case TypeTableEntryIdComptimeFloat:5995 case ZigTypeIdComptimeFloat:
5963 case TypeTableEntryIdComptimeInt:5996 case ZigTypeIdComptimeInt:
5964 case TypeTableEntryIdUndefined:5997 case ZigTypeIdUndefined:
5965 case TypeTableEntryIdNull:5998 case ZigTypeIdNull:
5966 case TypeTableEntryIdOptional:5999 case ZigTypeIdOptional:
5967 case TypeTableEntryIdPromise:6000 case ZigTypeIdPromise:
5968 case TypeTableEntryIdErrorSet:6001 case ZigTypeIdErrorSet:
5969 case TypeTableEntryIdEnum:6002 case ZigTypeIdEnum:
5970 case TypeTableEntryIdUnion:6003 case ZigTypeIdUnion:
5971 case TypeTableEntryIdFn:6004 case ZigTypeIdFn:
5972 case TypeTableEntryIdNamespace:6005 case ZigTypeIdNamespace:
5973 case TypeTableEntryIdBlock:6006 case ZigTypeIdBlock:
5974 case TypeTableEntryIdBoundFn:6007 case ZigTypeIdBoundFn:
5975 case TypeTableEntryIdArgTuple:6008 case ZigTypeIdArgTuple:
5976 case TypeTableEntryIdOpaque:6009 case ZigTypeIdOpaque:
5977 zig_unreachable();6010 zig_unreachable();
5978 case TypeTableEntryIdErrorUnion:6011 case ZigTypeIdErrorUnion:
5979 return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&6012 return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&
5980 a.data.error_union.payload_type == b.data.error_union.payload_type;6013 a.data.error_union.payload_type == b.data.error_union.payload_type;
59816014
5982 case TypeTableEntryIdPointer:6015 case ZigTypeIdPointer:
5983 return a.data.pointer.child_type == b.data.pointer.child_type &&6016 return a.data.pointer.child_type == b.data.pointer.child_type &&
5984 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&6017 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
5985 a.data.pointer.is_const == b.data.pointer.is_const &&6018 a.data.pointer.is_const == b.data.pointer.is_const &&
...@@ -5987,10 +6020,10 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5987,10 +6020,10 @@ bool type_id_eql(TypeId a, TypeId b) {
5987 a.data.pointer.alignment == b.data.pointer.alignment &&6020 a.data.pointer.alignment == b.data.pointer.alignment &&
5988 a.data.pointer.bit_offset == b.data.pointer.bit_offset &&6021 a.data.pointer.bit_offset == b.data.pointer.bit_offset &&
5989 a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;6022 a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;
5990 case TypeTableEntryIdArray:6023 case ZigTypeIdArray:
5991 return a.data.array.child_type == b.data.array.child_type &&6024 return a.data.array.child_type == b.data.array.child_type &&
5992 a.data.array.size == b.data.array.size;6025 a.data.array.size == b.data.array.size;
5993 case TypeTableEntryIdInt:6026 case ZigTypeIdInt:
5994 return a.data.integer.is_signed == b.data.integer.is_signed &&6027 return a.data.integer.is_signed == b.data.integer.is_signed &&
5995 a.data.integer.bit_count == b.data.integer.bit_count;6028 a.data.integer.bit_count == b.data.integer.bit_count;
5996 }6029 }
...@@ -6042,7 +6075,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {...@@ -6042,7 +6075,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
6042}6075}
60436076
6044void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {6077void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
6045 assert(const_val->type->id == TypeTableEntryIdArray);6078 assert(const_val->type->id == ZigTypeIdArray);
6046 if (const_val->data.x_array.special == ConstArraySpecialUndef) {6079 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
6047 const_val->data.x_array.special = ConstArraySpecialNone;6080 const_val->data.x_array.special = ConstArraySpecialNone;
6048 size_t elem_count = const_val->type->data.array.len;6081 size_t elem_count = const_val->type->data.array.len;
...@@ -6063,47 +6096,47 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -6063,47 +6096,47 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
60636096
6064ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {6097ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {
6065 assert(value->type);6098 assert(value->type);
6066 TypeTableEntry *type_entry = value->type;6099 ZigType *type_entry = value->type;
6067 if (type_entry->id == TypeTableEntryIdArray) {6100 if (type_entry->id == ZigTypeIdArray) {
6068 expand_undef_array(g, value);6101 expand_undef_array(g, value);
6069 return &value->data.x_array.s_none.parent;6102 return &value->data.x_array.s_none.parent;
6070 } else if (type_entry->id == TypeTableEntryIdStruct) {6103 } else if (type_entry->id == ZigTypeIdStruct) {
6071 return &value->data.x_struct.parent;6104 return &value->data.x_struct.parent;
6072 } else if (type_entry->id == TypeTableEntryIdUnion) {6105 } else if (type_entry->id == ZigTypeIdUnion) {
6073 return &value->data.x_union.parent;6106 return &value->data.x_union.parent;
6074 }6107 }
6075 return nullptr;6108 return nullptr;
6076}6109}
60776110
6078static const TypeTableEntryId all_type_ids[] = {6111static const ZigTypeId all_type_ids[] = {
6079 TypeTableEntryIdMetaType,6112 ZigTypeIdMetaType,
6080 TypeTableEntryIdVoid,6113 ZigTypeIdVoid,
6081 TypeTableEntryIdBool,6114 ZigTypeIdBool,
6082 TypeTableEntryIdUnreachable,6115 ZigTypeIdUnreachable,
6083 TypeTableEntryIdInt,6116 ZigTypeIdInt,
6084 TypeTableEntryIdFloat,6117 ZigTypeIdFloat,
6085 TypeTableEntryIdPointer,6118 ZigTypeIdPointer,
6086 TypeTableEntryIdArray,6119 ZigTypeIdArray,
6087 TypeTableEntryIdStruct,6120 ZigTypeIdStruct,
6088 TypeTableEntryIdComptimeFloat,6121 ZigTypeIdComptimeFloat,
6089 TypeTableEntryIdComptimeInt,6122 ZigTypeIdComptimeInt,
6090 TypeTableEntryIdUndefined,6123 ZigTypeIdUndefined,
6091 TypeTableEntryIdNull,6124 ZigTypeIdNull,
6092 TypeTableEntryIdOptional,6125 ZigTypeIdOptional,
6093 TypeTableEntryIdErrorUnion,6126 ZigTypeIdErrorUnion,
6094 TypeTableEntryIdErrorSet,6127 ZigTypeIdErrorSet,
6095 TypeTableEntryIdEnum,6128 ZigTypeIdEnum,
6096 TypeTableEntryIdUnion,6129 ZigTypeIdUnion,
6097 TypeTableEntryIdFn,6130 ZigTypeIdFn,
6098 TypeTableEntryIdNamespace,6131 ZigTypeIdNamespace,
6099 TypeTableEntryIdBlock,6132 ZigTypeIdBlock,
6100 TypeTableEntryIdBoundFn,6133 ZigTypeIdBoundFn,
6101 TypeTableEntryIdArgTuple,6134 ZigTypeIdArgTuple,
6102 TypeTableEntryIdOpaque,6135 ZigTypeIdOpaque,
6103 TypeTableEntryIdPromise,6136 ZigTypeIdPromise,
6104};6137};
61056138
6106TypeTableEntryId type_id_at_index(size_t index) {6139ZigTypeId type_id_at_index(size_t index) {
6107 assert(index < array_length(all_type_ids));6140 assert(index < array_length(all_type_ids));
6108 return all_type_ids[index];6141 return all_type_ids[index];
6109}6142}
...@@ -6112,119 +6145,119 @@ size_t type_id_len() {...@@ -6112,119 +6145,119 @@ size_t type_id_len() {
6112 return array_length(all_type_ids);6145 return array_length(all_type_ids);
6113}6146}
61146147
6115size_t type_id_index(TypeTableEntry *entry) {6148size_t type_id_index(ZigType *entry) {
6116 switch (entry->id) {6149 switch (entry->id) {
6117 case TypeTableEntryIdInvalid:6150 case ZigTypeIdInvalid:
6118 zig_unreachable();6151 zig_unreachable();
6119 case TypeTableEntryIdMetaType:6152 case ZigTypeIdMetaType:
6120 return 0;6153 return 0;
6121 case TypeTableEntryIdVoid:6154 case ZigTypeIdVoid:
6122 return 1;6155 return 1;
6123 case TypeTableEntryIdBool:6156 case ZigTypeIdBool:
6124 return 2;6157 return 2;
6125 case TypeTableEntryIdUnreachable:6158 case ZigTypeIdUnreachable:
6126 return 3;6159 return 3;
6127 case TypeTableEntryIdInt:6160 case ZigTypeIdInt:
6128 return 4;6161 return 4;
6129 case TypeTableEntryIdFloat:6162 case ZigTypeIdFloat:
6130 return 5;6163 return 5;
6131 case TypeTableEntryIdPointer:6164 case ZigTypeIdPointer:
6132 return 6;6165 return 6;
6133 case TypeTableEntryIdArray:6166 case ZigTypeIdArray:
6134 return 7;6167 return 7;
6135 case TypeTableEntryIdStruct:6168 case ZigTypeIdStruct:
6136 if (entry->data.structure.is_slice)6169 if (entry->data.structure.is_slice)
6137 return 6;6170 return 6;
6138 return 8;6171 return 8;
6139 case TypeTableEntryIdComptimeFloat:6172 case ZigTypeIdComptimeFloat:
6140 return 9;6173 return 9;
6141 case TypeTableEntryIdComptimeInt:6174 case ZigTypeIdComptimeInt:
6142 return 10;6175 return 10;
6143 case TypeTableEntryIdUndefined:6176 case ZigTypeIdUndefined:
6144 return 11;6177 return 11;
6145 case TypeTableEntryIdNull:6178 case ZigTypeIdNull:
6146 return 12;6179 return 12;
6147 case TypeTableEntryIdOptional:6180 case ZigTypeIdOptional:
6148 return 13;6181 return 13;
6149 case TypeTableEntryIdErrorUnion:6182 case ZigTypeIdErrorUnion:
6150 return 14;6183 return 14;
6151 case TypeTableEntryIdErrorSet:6184 case ZigTypeIdErrorSet:
6152 return 15;6185 return 15;
6153 case TypeTableEntryIdEnum:6186 case ZigTypeIdEnum:
6154 return 16;6187 return 16;
6155 case TypeTableEntryIdUnion:6188 case ZigTypeIdUnion:
6156 return 17;6189 return 17;
6157 case TypeTableEntryIdFn:6190 case ZigTypeIdFn:
6158 return 18;6191 return 18;
6159 case TypeTableEntryIdNamespace:6192 case ZigTypeIdNamespace:
6160 return 19;6193 return 19;
6161 case TypeTableEntryIdBlock:6194 case ZigTypeIdBlock:
6162 return 20;6195 return 20;
6163 case TypeTableEntryIdBoundFn:6196 case ZigTypeIdBoundFn:
6164 return 21;6197 return 21;
6165 case TypeTableEntryIdArgTuple:6198 case ZigTypeIdArgTuple:
6166 return 22;6199 return 22;
6167 case TypeTableEntryIdOpaque:6200 case ZigTypeIdOpaque:
6168 return 23;6201 return 23;
6169 case TypeTableEntryIdPromise:6202 case ZigTypeIdPromise:
6170 return 24;6203 return 24;
6171 }6204 }
6172 zig_unreachable();6205 zig_unreachable();
6173}6206}
61746207
6175const char *type_id_name(TypeTableEntryId id) {6208const char *type_id_name(ZigTypeId id) {
6176 switch (id) {6209 switch (id) {
6177 case TypeTableEntryIdInvalid:6210 case ZigTypeIdInvalid:
6178 zig_unreachable();6211 zig_unreachable();
6179 case TypeTableEntryIdMetaType:6212 case ZigTypeIdMetaType:
6180 return "Type";6213 return "Type";
6181 case TypeTableEntryIdVoid:6214 case ZigTypeIdVoid:
6182 return "Void";6215 return "Void";
6183 case TypeTableEntryIdBool:6216 case ZigTypeIdBool:
6184 return "Bool";6217 return "Bool";
6185 case TypeTableEntryIdUnreachable:6218 case ZigTypeIdUnreachable:
6186 return "NoReturn";6219 return "NoReturn";
6187 case TypeTableEntryIdInt:6220 case ZigTypeIdInt:
6188 return "Int";6221 return "Int";
6189 case TypeTableEntryIdFloat:6222 case ZigTypeIdFloat:
6190 return "Float";6223 return "Float";
6191 case TypeTableEntryIdPointer:6224 case ZigTypeIdPointer:
6192 return "Pointer";6225 return "Pointer";
6193 case TypeTableEntryIdArray:6226 case ZigTypeIdArray:
6194 return "Array";6227 return "Array";
6195 case TypeTableEntryIdStruct:6228 case ZigTypeIdStruct:
6196 return "Struct";6229 return "Struct";
6197 case TypeTableEntryIdComptimeFloat:6230 case ZigTypeIdComptimeFloat:
6198 return "ComptimeFloat";6231 return "ComptimeFloat";
6199 case TypeTableEntryIdComptimeInt:6232 case ZigTypeIdComptimeInt:
6200 return "ComptimeInt";6233 return "ComptimeInt";
6201 case TypeTableEntryIdUndefined:6234 case ZigTypeIdUndefined:
6202 return "Undefined";6235 return "Undefined";
6203 case TypeTableEntryIdNull:6236 case ZigTypeIdNull:
6204 return "Null";6237 return "Null";
6205 case TypeTableEntryIdOptional:6238 case ZigTypeIdOptional:
6206 return "Optional";6239 return "Optional";
6207 case TypeTableEntryIdErrorUnion:6240 case ZigTypeIdErrorUnion:
6208 return "ErrorUnion";6241 return "ErrorUnion";
6209 case TypeTableEntryIdErrorSet:6242 case ZigTypeIdErrorSet:
6210 return "ErrorSet";6243 return "ErrorSet";
6211 case TypeTableEntryIdEnum:6244 case ZigTypeIdEnum:
6212 return "Enum";6245 return "Enum";
6213 case TypeTableEntryIdUnion:6246 case ZigTypeIdUnion:
6214 return "Union";6247 return "Union";
6215 case TypeTableEntryIdFn:6248 case ZigTypeIdFn:
6216 return "Fn";6249 return "Fn";
6217 case TypeTableEntryIdNamespace:6250 case ZigTypeIdNamespace:
6218 return "Namespace";6251 return "Namespace";
6219 case TypeTableEntryIdBlock:6252 case ZigTypeIdBlock:
6220 return "Block";6253 return "Block";
6221 case TypeTableEntryIdBoundFn:6254 case ZigTypeIdBoundFn:
6222 return "BoundFn";6255 return "BoundFn";
6223 case TypeTableEntryIdArgTuple:6256 case ZigTypeIdArgTuple:
6224 return "ArgTuple";6257 return "ArgTuple";
6225 case TypeTableEntryIdOpaque:6258 case ZigTypeIdOpaque:
6226 return "Opaque";6259 return "Opaque";
6227 case TypeTableEntryIdPromise:6260 case ZigTypeIdPromise:
6228 return "Promise";6261 return "Promise";
6229 }6262 }
6230 zig_unreachable();6263 zig_unreachable();
...@@ -6258,31 +6291,31 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {...@@ -6258,31 +6291,31 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
6258 return link_lib;6291 return link_lib;
6259}6292}
62606293
6261uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) {6294uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {
6262 assertNoError(type_ensure_zero_bits_known(g, type_entry));6295 assertNoError(type_ensure_zero_bits_known(g, type_entry));
6263 if (type_entry->zero_bits) return 0;6296 if (type_entry->zero_bits) return 0;
62646297
6265 // We need to make this function work without requiring ensure_complete_type6298 // We need to make this function work without requiring ensure_complete_type
6266 // so that we can have structs with fields that are pointers to their own type.6299 // 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) {
6268 assert(type_entry->data.structure.abi_alignment != 0);6301 assert(type_entry->data.structure.abi_alignment != 0);
6269 return type_entry->data.structure.abi_alignment;6302 return type_entry->data.structure.abi_alignment;
6270 } else if (type_entry->id == TypeTableEntryIdUnion) {6303 } else if (type_entry->id == ZigTypeIdUnion) {
6271 assert(type_entry->data.unionation.abi_alignment != 0);6304 assert(type_entry->data.unionation.abi_alignment != 0);
6272 return type_entry->data.unionation.abi_alignment;6305 return type_entry->data.unionation.abi_alignment;
6273 } else if (type_entry->id == TypeTableEntryIdOpaque) {6306 } else if (type_entry->id == ZigTypeIdOpaque) {
6274 return 1;6307 return 1;
6275 } else {6308 } else {
6276 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);6309 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
6277 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw6310 // 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) {
6279 return 8;6312 return 8;
6280 }6313 }
6281 return llvm_alignment;6314 return llvm_alignment;
6282 }6315 }
6283}6316}
62846317
6285TypeTableEntry *get_align_amt_type(CodeGen *g) {6318ZigType *get_align_amt_type(CodeGen *g) {
6286 if (g->align_amt_type == nullptr) {6319 if (g->align_amt_type == nullptr) {
6287 // according to LLVM the maximum alignment is 1 << 29.6320 // according to LLVM the maximum alignment is 1 << 29.
6288 g->align_amt_type = get_int_type(g, false, 29);6321 g->align_amt_type = get_int_type(g, false, 29);
...@@ -6290,11 +6323,11 @@ TypeTableEntry *get_align_amt_type(CodeGen *g) {...@@ -6290,11 +6323,11 @@ TypeTableEntry *get_align_amt_type(CodeGen *g) {
6290 return g->align_amt_type;6323 return g->align_amt_type;
6291}6324}
62926325
6293uint32_t type_ptr_hash(const TypeTableEntry *ptr) {6326uint32_t type_ptr_hash(const ZigType *ptr) {
6294 return hash_ptr((void*)ptr);6327 return hash_ptr((void*)ptr);
6295}6328}
62966329
6297bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b) {6330bool type_ptr_eql(const ZigType *a, const ZigType *b) {
6298 return a == b;6331 return a == b;
6299}6332}
63006333
...@@ -6308,8 +6341,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {...@@ -6308,8 +6341,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
6308 return var_value;6341 return var_value;
6309}6342}
63106343
6311bool type_is_global_error_set(TypeTableEntry *err_set_type) {6344bool type_is_global_error_set(ZigType *err_set_type) {
6312 assert(err_set_type->id == TypeTableEntryIdErrorSet);6345 assert(err_set_type->id == ZigTypeIdErrorSet);
6313 assert(err_set_type->data.error_set.infer_fn == nullptr);6346 assert(err_set_type->data.error_set.infer_fn == nullptr);
6314 return err_set_type->data.error_set.err_count == UINT32_MAX;6347 return err_set_type->data.error_set.err_count == UINT32_MAX;
6315}6348}
...@@ -6318,15 +6351,15 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {...@@ -6318,15 +6351,15 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {
6318 return g->pointer_size_bytes * 2;6351 return g->pointer_size_bytes * 2;
6319}6352}
63206353
6321bool type_can_fail(TypeTableEntry *type_entry) {6354bool type_can_fail(ZigType *type_entry) {
6322 return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet;6355 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
6323}6356}
63246357
6325bool fn_type_can_fail(FnTypeId *fn_type_id) {6358bool fn_type_can_fail(FnTypeId *fn_type_id) {
6326 return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;6359 return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;
6327}6360}
63286361
6329TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name) {6362ZigType *get_primitive_type(CodeGen *g, Buf *name) {
6330 if (buf_len(name) >= 2) {6363 if (buf_len(name) >= 2) {
6331 uint8_t first_c = buf_ptr(name)[0];6364 uint8_t first_c = buf_ptr(name)[0];
6332 if (first_c == 'i' || first_c == 'u') {6365 if (first_c == 'i' || first_c == 'u') {
...@@ -6350,3 +6383,85 @@ not_integer:...@@ -6350,3 +6383,85 @@ not_integer:
6350 }6383 }
6351 return nullptr;6384 return nullptr;
6352}6385}
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 @@...@@ -14,103 +14,104 @@
14void semantic_analyze(CodeGen *g);14void semantic_analyze(CodeGen *g);
15ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);15ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);16ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
17TypeTableEntry *new_type_table_entry(TypeTableEntryId id);17ZigType *new_type_table_entry(ZigTypeId id);
18TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);18ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
19TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,19ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
20 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);20 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);21uint64_t type_size(CodeGen *g, ZigType *type_entry);
22uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);22uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);23ZigType *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);24ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
25TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);25ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
26TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);26ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
27TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type);27ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
28TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);28ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
29TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type);29ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
30TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,30ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
31 AstNode *decl_node, const char *name, ContainerLayout layout);31 AstNode *decl_node, const char *name, ContainerLayout layout);
32TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);32ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
33TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type);33ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
34TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);34ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
35TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);35ZigType *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[],36ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
37 TypeTableEntry *field_types[], size_t field_count);37 ZigType *field_types[], size_t field_count);
38TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type);38ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
39TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type);39ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type);
40TypeTableEntry *get_test_fn_type(CodeGen *g);40ZigType *get_test_fn_type(CodeGen *g);
41bool handle_is_ptr(TypeTableEntry *type_entry);41bool handle_is_ptr(ZigType *type_entry);
42void find_libc_include_path(CodeGen *g);42void find_libc_include_path(CodeGen *g);
43void find_libc_lib_path(CodeGen *g);43void find_libc_lib_path(CodeGen *g);
4444
45bool type_has_bits(TypeTableEntry *type_entry);45bool type_has_bits(ZigType *type_entry);
4646
4747
48ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);48ImportTableEntry *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);
52Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);52Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
54bool type_is_codegen_pointer(TypeTableEntry *type);54bool type_is_codegen_pointer(ZigType *type);
5555
56TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type);56ZigType *get_codegen_ptr_type(ZigType *type);
57uint32_t get_ptr_align(TypeTableEntry *type);57uint32_t get_ptr_align(ZigType *type);
58bool get_ptr_const(TypeTableEntry *type);58bool get_ptr_const(ZigType *type);
59TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);59ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
60TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);60ZigType *container_ref_type(ZigType *type_entry);
61bool type_is_complete(TypeTableEntry *type_entry);61bool type_is_complete(ZigType *type_entry);
62bool type_is_invalid(TypeTableEntry *type_entry);62bool type_is_invalid(ZigType *type_entry);
63bool type_is_global_error_set(TypeTableEntry *err_set_type);63bool type_is_global_error_set(ZigType *err_set_type);
64bool type_has_zero_bits_known(TypeTableEntry *type_entry);64bool type_has_zero_bits_known(ZigType *type_entry);
65void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);65void resolve_container_type(CodeGen *g, ZigType *type_entry);
66ScopeDecls *get_container_scope(TypeTableEntry *type_entry);66ScopeDecls *get_container_scope(ZigType *type_entry);
67TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);67TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name);
68TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);68TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name);
69TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name);69TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name);
70TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag);70TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag);
71TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag);71TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);
7272
73bool is_ref(TypeTableEntry *type_entry);73bool is_ref(ZigType *type_entry);
74bool is_array_ref(TypeTableEntry *type_entry);74bool is_array_ref(ZigType *type_entry);
75bool is_container_ref(TypeTableEntry *type_entry);75bool is_container_ref(ZigType *type_entry);
76void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);76void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
77void scan_import(CodeGen *g, ImportTableEntry *import);77void scan_import(CodeGen *g, ImportTableEntry *import);
78void preview_use_decl(CodeGen *g, AstNode *node);78void preview_use_decl(CodeGen *g, AstNode *node);
79void resolve_use_decl(CodeGen *g, AstNode *node);79void resolve_use_decl(CodeGen *g, AstNode *node);
80FnTableEntry *scope_fn_entry(Scope *scope);80ZigFn *scope_fn_entry(Scope *scope);
81ImportTableEntry *get_scope_import(Scope *scope);81ImportTableEntry *get_scope_import(Scope *scope);
82void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);82void 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,
84 bool is_const, ConstExprValue *init_value, Tld *src_tld);84 bool is_const, ConstExprValue *init_value, Tld *src_tld);
85TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);85ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
86FnTableEntry *create_fn(AstNode *proto_node);86ZigFn *create_fn(AstNode *proto_node);
87FnTableEntry *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);87ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
88void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);88void 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);89AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
90FnTableEntry *scope_get_fn_if_root(Scope *scope);90ZigFn *scope_get_fn_if_root(Scope *scope);
91bool type_requires_comptime(TypeTableEntry *type_entry);91bool type_requires_comptime(ZigType *type_entry);
92Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, TypeTableEntry *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, TypeTableEntry *type_entry);93Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
94void complete_enum(CodeGen *g, TypeTableEntry *enum_type);94void complete_enum(CodeGen *g, ZigType *enum_type);
95bool ir_get_var_is_comptime(VariableTableEntry *var);95bool ir_get_var_is_comptime(ZigVar *var);
96bool const_values_equal(ConstExprValue *a, ConstExprValue *b);96bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
97void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, 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, TypeTableEntry *int_type, BigInt *bigint, bool is_max);98void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
9999
100void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);100void 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
103ScopeBlock *create_block_scope(AstNode *node, Scope *parent);103ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
104ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);104ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);
105ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);105ScopeDeferExpr *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);
107ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);107ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
108ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);108ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);
109ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);109ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);
110ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry);110ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry);
111ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import);111ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
112Scope *create_comptime_scope(AstNode *node, Scope *parent);112Scope *create_comptime_scope(AstNode *node, Scope *parent);
113Scope *create_coro_prelude_scope(AstNode *node, Scope *parent);113Scope *create_coro_prelude_scope(AstNode *node, Scope *parent);
114Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime);
114115
115void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);116void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
116ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);117ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
...@@ -118,39 +119,39 @@ ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);...@@ -118,39 +119,39 @@ ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
118void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);119void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
119ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);120ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
120121
121void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint);122void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
122ConstExprValue *create_const_bigint(TypeTableEntry *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);125void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);
125ConstExprValue *create_const_unsigned_negative(TypeTableEntry *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);128void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);
128ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x);129ConstExprValue *create_const_signed(ZigType *type, int64_t x);
129130
130void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);131void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);
131ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);132ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
132133
133void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value);134void init_const_float(ConstExprValue *const_val, ZigType *type, double value);
134ConstExprValue *create_const_float(TypeTableEntry *type, double value);135ConstExprValue *create_const_float(ZigType *type, double value);
135136
136void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag);137void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);
137ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag);138ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);
138139
139void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);140void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
140ConstExprValue *create_const_bool(CodeGen *g, bool value);141ConstExprValue *create_const_bool(CodeGen *g, bool value);
141142
142void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value);143void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);
143ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value);144ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);
144145
145void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type);146void init_const_runtime(ConstExprValue *const_val, ZigType *type);
146ConstExprValue *create_const_runtime(TypeTableEntry *type);147ConstExprValue *create_const_runtime(ZigType *type);
147148
148void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);149void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);
149ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);150ConstExprValue *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,
152 size_t addr, bool is_const);153 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,
154 size_t addr, bool is_const);155 size_t addr, bool is_const);
155156
156void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,157void 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);...@@ -169,41 +170,48 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val);
169170
170ConstExprValue *create_const_vals(size_t count);171ConstExprValue *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);
173ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value);174ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value);
174void expand_undef_array(CodeGen *g, ConstExprValue *const_val);175void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
175void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);176void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);
176177
177const char *type_id_name(TypeTableEntryId id);178const char *type_id_name(ZigTypeId id);
178TypeTableEntryId type_id_at_index(size_t index);179ZigTypeId type_id_at_index(size_t index);
179size_t type_id_len();180size_t type_id_len();
180size_t type_id_index(TypeTableEntry *entry);181size_t type_id_index(ZigType *entry);
181TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);182ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
182Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry);183Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry);
183LinkLib *create_link_lib(Buf *name);184LinkLib *create_link_lib(Buf *name);
184bool calling_convention_does_first_arg_return(CallingConvention cc);
185LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);185LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
186186
187uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry);187uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
188TypeTableEntry *get_align_amt_type(CodeGen *g);188ZigType *get_align_amt_type(CodeGen *g);
189PackageTableEntry *new_anonymous_package(void);189PackageTableEntry *new_anonymous_package(void);
190190
191Buf *const_value_to_buffer(ConstExprValue *const_val);191Buf *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
195ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);195ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
196TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);196ZigType *get_ptr_to_stack_trace_type(CodeGen *g);
197bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node);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
201uint32_t get_coro_frame_align_bytes(CodeGen *g);201uint32_t get_coro_frame_align_bytes(CodeGen *g);
202bool fn_type_can_fail(FnTypeId *fn_type_id);202bool fn_type_can_fail(FnTypeId *fn_type_id);
203bool type_can_fail(TypeTableEntry *type_entry);203bool type_can_fail(ZigType *type_entry);
204bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type);204bool fn_eval_cacheable(Scope *scope, ZigType *return_type);
205AstNode *type_decl_node(TypeTableEntry *type_entry);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
209#endif217#endif
src/buffer.hpp+5
...@@ -173,4 +173,9 @@ static inline void buf_upcase(Buf *buf) {...@@ -173,4 +173,9 @@ static inline void buf_upcase(Buf *buf) {
173 }173 }
174}174}
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
176#endif181#endif
src/codegen.cpp+906-603
...@@ -243,7 +243,7 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {...@@ -243,7 +243,7 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
243 g->root_out_name = out_name;243 g->root_out_name = out_name;
244}244}
245245
246void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir) {246void codegen_set_cache_dir(CodeGen *g, Buf cache_dir) {
247 g->cache_dir = cache_dir;247 g->cache_dir = cache_dir;
248}248}
249249
...@@ -358,6 +358,10 @@ static void addLLVMArgAttr(LLVMValueRef fn_val, unsigned param_index, const char...@@ -358,6 +358,10 @@ static void addLLVMArgAttr(LLVMValueRef fn_val, unsigned param_index, const char
358 return addLLVMAttr(fn_val, param_index + 1, attr_name);358 return addLLVMAttr(fn_val, param_index + 1, attr_name);
359}359}
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
361static bool is_symbol_available(CodeGen *g, Buf *name) {365static bool is_symbol_available(CodeGen *g, Buf *name) {
362 return g->exported_symbol_names.maybe_get(name) == nullptr && g->external_prototypes.maybe_get(name) == nullptr;366 return g->exported_symbol_names.maybe_get(name) == nullptr && g->external_prototypes.maybe_get(name) == nullptr;
363}367}
...@@ -430,23 +434,23 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) {...@@ -430,23 +434,23 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) {
430 zig_unreachable();434 zig_unreachable();
431}435}
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) {
434 if (!g->have_err_ret_tracing) {438 if (!g->have_err_ret_tracing) {
435 return UINT32_MAX;439 return UINT32_MAX;
436 }440 }
437 if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {441 if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {
438 return 0;442 return 0;
439 }443 }
440 TypeTableEntry *fn_type = fn_table_entry->type_entry;444 ZigType *fn_type = fn_table_entry->type_entry;
441 if (!fn_type_can_fail(&fn_type->data.fn.fn_type_id)) {445 if (!fn_type_can_fail(&fn_type->data.fn.fn_type_id)) {
442 return UINT32_MAX;446 return UINT32_MAX;
443 }447 }
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;
445 bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type);449 bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type);
446 return first_arg_ret ? 1 : 0;450 return first_arg_ret ? 1 : 0;
447}451}
448452
449static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {453static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
450 if (fn_table_entry->llvm_value)454 if (fn_table_entry->llvm_value)
451 return fn_table_entry->llvm_value;455 return fn_table_entry->llvm_value;
452456
...@@ -466,7 +470,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -466,7 +470,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
466 }470 }
467471
468 bool external_linkage = linkage != GlobalLinkageIdInternal;472 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 &&
470 g->zig_target.arch.arch == ZigLLVM_x86)475 g->zig_target.arch.arch == ZigLLVM_x86)
471 {476 {
472 // prevent llvm name mangling477 // prevent llvm name mangling
...@@ -474,7 +479,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -474,7 +479,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
474 }479 }
475480
476481
477 TypeTableEntry *fn_type = fn_table_entry->type_entry;482 ZigType *fn_type = fn_table_entry->type_entry;
478 LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref;483 LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref;
479 if (fn_table_entry->body_node == nullptr) {484 if (fn_table_entry->body_node == nullptr) {
480 LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name));485 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) {...@@ -510,17 +515,17 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
510 break;515 break;
511 }516 }
512517
513 if (fn_type->data.fn.fn_type_id.cc == CallingConventionNaked) {518 if (cc == CallingConventionNaked) {
514 addLLVMFnAttr(fn_table_entry->llvm_value, "naked");519 addLLVMFnAttr(fn_table_entry->llvm_value, "naked");
515 } else {520 } else {
516 LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));521 LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));
517 }522 }
518 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {523 if (cc == CallingConventionAsync) {
519 addLLVMFnAttr(fn_table_entry->llvm_value, "optnone");524 addLLVMFnAttr(fn_table_entry->llvm_value, "optnone");
520 addLLVMFnAttr(fn_table_entry->llvm_value, "noinline");525 addLLVMFnAttr(fn_table_entry->llvm_value, "noinline");
521 }526 }
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;
524 if (want_cold) {529 if (want_cold) {
525 ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);530 ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);
526 }531 }
...@@ -532,8 +537,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -532,8 +537,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
532 LLVMSetUnnamedAddr(fn_table_entry->llvm_value, true);537 LLVMSetUnnamedAddr(fn_table_entry->llvm_value, true);
533 }538 }
534539
535 TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;540 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
536 if (return_type->id == TypeTableEntryIdUnreachable) {541 if (return_type->id == ZigTypeIdUnreachable) {
537 addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");542 addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");
538 }543 }
539544
...@@ -572,41 +577,26 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -572,41 +577,26 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
572 // use the ABI alignment, which is fine.577 // use the ABI alignment, which is fine.
573 }578 }
574579
580 unsigned init_gen_i = 0;
575 if (!type_has_bits(return_type)) {581 if (!type_has_bits(return_type)) {
576 // nothing to do582 // nothing to do
577 } else if (type_is_codegen_pointer(return_type)) {583 } else if (type_is_codegen_pointer(return_type)) {
578 addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull");584 addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull");
579 } else if (handle_is_ptr(return_type) &&585 } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
580 calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc))
581 {
582 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");586 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");
583 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull");587 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;
584 }592 }
585593
586
587 // set parameter attributes594 // set parameter attributes
588 for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) {595 FnWalk fn_walk = {};
589 FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];596 fn_walk.id = FnWalkIdAttrs;
590 size_t gen_index = gen_info->gen_index;597 fn_walk.data.attrs.fn = fn_table_entry;
591 bool is_byval = gen_info->is_byval;598 fn_walk.data.attrs.gen_i = init_gen_i;
592599 walk_function_params(g, fn_type, &fn_walk);
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 }
610600
611 uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry);601 uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry);
612 if (err_ret_trace_arg_index != UINT32_MAX) {602 if (err_ret_trace_arg_index != UINT32_MAX) {
...@@ -628,7 +618,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -628,7 +618,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
628 {618 {
629 assert(scope->parent);619 assert(scope->parent);
630 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;620 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
631 FnTableEntry *fn_table_entry = fn_scope->fn_entry;621 ZigFn *fn_table_entry = fn_scope->fn_entry;
632 if (!fn_table_entry->proto_node)622 if (!fn_table_entry->proto_node)
633 return get_di_scope(g, scope->parent);623 return get_di_scope(g, scope->parent);
634 unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ?624 unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ?
...@@ -678,6 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -678,6 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
678 case ScopeIdSuspend:668 case ScopeIdSuspend:
679 case ScopeIdCompTime:669 case ScopeIdCompTime:
680 case ScopeIdCoroPrelude:670 case ScopeIdCoroPrelude:
671 case ScopeIdRuntime:
681 return get_di_scope(g, scope->parent);672 return get_di_scope(g, scope->parent);
682 }673 }
683 zig_unreachable();674 zig_unreachable();
...@@ -687,12 +678,12 @@ static void clear_debug_source_node(CodeGen *g) {...@@ -687,12 +678,12 @@ static void clear_debug_source_node(CodeGen *g) {
687 ZigLLVMClearCurrentDebugLocation(g->builder);678 ZigLLVMClearCurrentDebugLocation(g->builder);
688}679}
689680
690static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,681static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,
691 const char *signed_name, const char *unsigned_name)682 const char *signed_name, const char *unsigned_name)
692{683{
693 char fn_name[64];684 char fn_name[64];
694685
695 assert(type_entry->id == TypeTableEntryIdInt);686 assert(type_entry->id == ZigTypeIdInt);
696 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;687 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
697 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);688 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_...@@ -711,8 +702,8 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
711 return fn_val;702 return fn_val;
712}703}
713704
714static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {705static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {
715 assert(type_entry->id == TypeTableEntryIdInt);706 assert(type_entry->id == ZigTypeIdInt);
716707
717 ZigLLVMFnKey key = {};708 ZigLLVMFnKey key = {};
718 key.id = ZigLLVMFnIdOverflowArithmetic;709 key.id = ZigLLVMFnIdOverflowArithmetic;
...@@ -741,8 +732,8 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,...@@ -741,8 +732,8 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
741 return fn_val;732 return fn_val;
742}733}
743734
744static LLVMValueRef get_float_fn(CodeGen *g, TypeTableEntry *type_entry, ZigLLVMFnId fn_id) {735static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) {
745 assert(type_entry->id == TypeTableEntryIdFloat);736 assert(type_entry->id == ZigTypeIdFloat);
746737
747 ZigLLVMFnKey key = {};738 ZigLLVMFnKey key = {};
748 key.id = fn_id;739 key.id = fn_id;
...@@ -786,8 +777,8 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR...@@ -786,8 +777,8 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR
786 return instruction;777 return instruction;
787}778}
788779
789static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, TypeTableEntry *ptr_type) {780static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) {
790 assert(ptr_type->id == TypeTableEntryIdPointer);781 assert(ptr_type->id == ZigTypeIdPointer);
791 return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);782 return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
792}783}
793784
...@@ -804,17 +795,17 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig...@@ -804,17 +795,17 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
804 return result;795 return result;
805}796}
806797
807static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, const char *name) {798static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
808 assert(ptr_type->id == TypeTableEntryIdPointer);799 assert(ptr_type->id == ZigTypeIdPointer);
809 return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);800 return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);
810}801}
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) {
813 if (type_has_bits(type)) {804 if (type_has_bits(type)) {
814 if (handle_is_ptr(type)) {805 if (handle_is_ptr(type)) {
815 return ptr;806 return ptr;
816 } else {807 } else {
817 assert(ptr_type->id == TypeTableEntryIdPointer);808 assert(ptr_type->id == ZigTypeIdPointer);
818 return gen_load(g, ptr, ptr_type, "");809 return gen_load(g, ptr, ptr_type, "");
819 }810 }
820 } else {811 } else {
...@@ -917,9 +908,9 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {...@@ -917,9 +908,9 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
917 assert(val->global_refs->llvm_global);908 assert(val->global_refs->llvm_global);
918 }909 }
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,
921 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);912 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);
923 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));914 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));
924}915}
925916
...@@ -928,7 +919,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace...@@ -928,7 +919,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
928 LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);919 LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);
929 LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);920 LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);
930 if (stack_trace_arg == nullptr) {921 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);
932 stack_trace_arg = LLVMConstNull(ptr_to_stack_trace_type->type_ref);923 stack_trace_arg = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
933 }924 }
934 LLVMValueRef args[] = {925 LLVMValueRef args[] = {
...@@ -1166,7 +1157,7 @@ static LLVMValueRef get_return_address_fn_val(CodeGen *g) {...@@ -1166,7 +1157,7 @@ static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
1166 if (g->return_address_fn_val)1157 if (g->return_address_fn_val)
1167 return g->return_address_fn_val;1158 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
1171 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,1162 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
1172 &g->builtin_types.entry_i32->type_ref, 1, false);1163 &g->builtin_types.entry_i32->type_ref, 1, false);
...@@ -1217,7 +1208,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1217,7 +1208,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
1217 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;1208 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
1218 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, "");1209 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;
1221 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;1212 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
1222 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");1213 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
1223 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;1214 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) {...@@ -1317,7 +1308,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
1317 (unsigned)src_index_field_index, "");1308 (unsigned)src_index_field_index, "");
1318 LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,1309 LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
1319 (unsigned)src_addresses_field_index, "");1310 (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;
1321 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;1312 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
1322 LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");1313 LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");
1323 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;1314 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) {...@@ -1459,7 +1450,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1459 LLVMSetUnnamedAddr(global_array, true);1450 LLVMSetUnnamedAddr(global_array, true);
1460 LLVMSetAlignment(global_array, u8_align_bytes);1451 LLVMSetAlignment(global_array, u8_align_bytes);
14611452
1462 TypeTableEntry *usize = g->builtin_types.entry_usize;1453 ZigType *usize = g->builtin_types.entry_usize;
1463 LLVMValueRef full_buf_ptr_indices[] = {1454 LLVMValueRef full_buf_ptr_indices[] = {
1464 LLVMConstNull(usize->type_ref),1455 LLVMConstNull(usize->type_ref),
1465 LLVMConstNull(usize->type_ref),1456 LLVMConstNull(usize->type_ref),
...@@ -1467,9 +1458,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1467,9 +1458,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1467 LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2);1458 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,
1471 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);1462 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);
1473 LLVMValueRef global_slice_fields[] = {1464 LLVMValueRef global_slice_fields[] = {
1474 full_buf_ptr,1465 full_buf_ptr,
1475 LLVMConstNull(usize->type_ref),1466 LLVMConstNull(usize->type_ref),
...@@ -1575,7 +1566,7 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc...@@ -1575,7 +1566,7 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc
1575 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);1566 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
1576 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, scope);1567 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, scope);
1577 if (err_ret_trace_val == nullptr) {1568 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);
1579 err_ret_trace_val = LLVMConstNull(ptr_to_stack_trace_type->type_ref);1570 err_ret_trace_val = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
1580 }1571 }
1581 LLVMValueRef args[] = {1572 LLVMValueRef args[] = {
...@@ -1621,24 +1612,24 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,...@@ -1621,24 +1612,24 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
1621 LLVMPositionBuilderAtEnd(g->builder, ok_block);1612 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1622}1613}
16231614
1624static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type,1615static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type,
1625 TypeTableEntry *wanted_type, LLVMValueRef expr_val)1616 ZigType *wanted_type, LLVMValueRef expr_val)
1626{1617{
1627 assert(actual_type->id == wanted_type->id);1618 assert(actual_type->id == wanted_type->id);
16281619
1629 uint64_t actual_bits;1620 uint64_t actual_bits;
1630 uint64_t wanted_bits;1621 uint64_t wanted_bits;
1631 if (actual_type->id == TypeTableEntryIdFloat) {1622 if (actual_type->id == ZigTypeIdFloat) {
1632 actual_bits = actual_type->data.floating.bit_count;1623 actual_bits = actual_type->data.floating.bit_count;
1633 wanted_bits = wanted_type->data.floating.bit_count;1624 wanted_bits = wanted_type->data.floating.bit_count;
1634 } else if (actual_type->id == TypeTableEntryIdInt) {1625 } else if (actual_type->id == ZigTypeIdInt) {
1635 actual_bits = actual_type->data.integral.bit_count;1626 actual_bits = actual_type->data.integral.bit_count;
1636 wanted_bits = wanted_type->data.integral.bit_count;1627 wanted_bits = wanted_type->data.integral.bit_count;
1637 } else {1628 } else {
1638 zig_unreachable();1629 zig_unreachable();
1639 }1630 }
16401631
1641 if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&1632 if (actual_bits >= wanted_bits && actual_type->id == ZigTypeIdInt &&
1642 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&1633 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
1643 want_runtime_safety)1634 want_runtime_safety)
1644 {1635 {
...@@ -1658,9 +1649,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T...@@ -1658,9 +1649,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
1658 if (actual_bits == wanted_bits) {1649 if (actual_bits == wanted_bits) {
1659 return expr_val;1650 return expr_val;
1660 } else if (actual_bits < wanted_bits) {1651 } else if (actual_bits < wanted_bits) {
1661 if (actual_type->id == TypeTableEntryIdFloat) {1652 if (actual_type->id == ZigTypeIdFloat) {
1662 return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");1653 return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");
1663 } else if (actual_type->id == TypeTableEntryIdInt) {1654 } else if (actual_type->id == ZigTypeIdInt) {
1664 if (actual_type->data.integral.is_signed) {1655 if (actual_type->data.integral.is_signed) {
1665 return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");1656 return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");
1666 } else {1657 } else {
...@@ -1670,9 +1661,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T...@@ -1670,9 +1661,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
1670 zig_unreachable();1661 zig_unreachable();
1671 }1662 }
1672 } else if (actual_bits > wanted_bits) {1663 } else if (actual_bits > wanted_bits) {
1673 if (actual_type->id == TypeTableEntryIdFloat) {1664 if (actual_type->id == ZigTypeIdFloat) {
1674 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");1665 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1675 } else if (actual_type->id == TypeTableEntryIdInt) {1666 } else if (actual_type->id == ZigTypeIdInt) {
1676 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");1667 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1677 if (!want_runtime_safety) {1668 if (!want_runtime_safety) {
1678 return trunc_val;1669 return trunc_val;
...@@ -1701,7 +1692,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T...@@ -1701,7 +1692,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
1701 }1692 }
1702}1693}
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,
1705 LLVMValueRef val1, LLVMValueRef val2)1696 LLVMValueRef val1, LLVMValueRef val2)
1706{1697{
1707 LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op);1698 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) {...@@ -1761,11 +1752,11 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) {
1761 }1752 }
1762}1753}
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,
1765 LLVMValueRef value)1756 LLVMValueRef value)
1766{1757{
1767 assert(ptr_type->id == TypeTableEntryIdPointer);1758 assert(ptr_type->id == ZigTypeIdPointer);
1768 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;1759 ZigType *child_type = ptr_type->data.pointer.child_type;
17691760
1770 if (!type_has_bits(child_type))1761 if (!type_has_bits(child_type))
1771 return nullptr;1762 return nullptr;
...@@ -1779,7 +1770,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry...@@ -1779,7 +1770,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
1779 LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, value, ptr_u8, "");1770 LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, value, ptr_u8, "");
1780 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, ptr, ptr_u8, "");1771 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;
1783 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, child_type->type_ref);1774 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, child_type->type_ref);
1784 uint64_t align_bytes = ptr_type->data.pointer.alignment;1775 uint64_t align_bytes = ptr_type->data.pointer.alignment;
1785 assert(size_bytes > 0);1776 assert(size_bytes > 0);
...@@ -1819,7 +1810,8 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry...@@ -1819,7 +1810,8 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
1819 return nullptr;1810 return nullptr;
1820}1811}
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);
1823 AstNode *source_node = var->decl_node;1815 AstNode *source_node = var->decl_node;
1824 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,1816 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
1825 (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));1817 (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) {...@@ -1838,9 +1830,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1838 // values are rendered with a type other than the one we expect1830 // values are rendered with a type other than the one we expect
1839 if (handle_is_ptr(instruction->value.type)) {1831 if (handle_is_ptr(instruction->value.type)) {
1840 render_const_val_global(g, &instruction->value, "");1832 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);
1842 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, "");1834 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) {
1844 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");1836 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");
1845 } else {1837 } else {
1846 instruction->llvm_value = instruction->value.global_refs->llvm_value;1838 instruction->llvm_value = instruction->value.global_refs->llvm_value;
...@@ -1850,6 +1842,353 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -1850,6 +1842,353 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1850 return instruction->llvm_value;1842 return instruction->llvm_value;
1851}1843}
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
1853static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,2192static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
1854 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)2193 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
1855{2194{
...@@ -1866,24 +2205,22 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut...@@ -1866,24 +2205,22 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
18662205
1867static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {2206static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {
1868 LLVMValueRef value = ir_llvm_value(g, return_instruction->value);2207 LLVMValueRef value = ir_llvm_value(g, return_instruction->value);
1869 TypeTableEntry *return_type = return_instruction->value->value.type;2208 ZigType *return_type = return_instruction->value->value.type;
18702209
1871 if (handle_is_ptr(return_type)) {2210 if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) {
1872 if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {2211 assert(g->cur_ret_ptr);
1873 assert(g->cur_ret_ptr);2212 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
1874 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);2213 LLVMBuildRetVoid(g->builder);
1875 LLVMBuildRetVoid(g->builder);2214 } else if (handle_is_ptr(return_type)) {
1876 } else {2215 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
1877 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");2216 LLVMBuildRet(g->builder, by_val_value);
1878 LLVMBuildRet(g->builder, by_val_value);
1879 }
1880 } else {2217 } else {
1881 LLVMBuildRet(g->builder, value);2218 LLVMBuildRet(g->builder, value);
1882 }2219 }
1883 return nullptr;2220 return nullptr;
1884}2221}
18852222
1886static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,2223static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,
1887 LLVMValueRef val1, LLVMValueRef val2)2224 LLVMValueRef val1, LLVMValueRef val2)
1888{2225{
1889 // for unsigned left shifting, we do the lossy shift, then logically shift2226 // 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,...@@ -1891,7 +2228,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
1891 // if the values don't match, we have an overflow2228 // if the values don't match, we have an overflow
1892 // for signed left shifting we do the same except arithmetic shift right2229 // 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
1896 LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");2233 LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");
1897 LLVMValueRef orig_val;2234 LLVMValueRef orig_val;
...@@ -1913,10 +2250,10 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,...@@ -1913,10 +2250,10 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
1913 return result;2250 return result;
1914}2251}
19152252
1916static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,2253static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,
1917 LLVMValueRef val1, LLVMValueRef val2)2254 LLVMValueRef val1, LLVMValueRef val2)
1918{2255{
1919 assert(type_entry->id == TypeTableEntryIdInt);2256 assert(type_entry->id == ZigTypeIdInt);
19202257
1921 LLVMValueRef result;2258 LLVMValueRef result;
1922 if (type_entry->data.integral.is_signed) {2259 if (type_entry->data.integral.is_signed) {
...@@ -1938,16 +2275,16 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,...@@ -1938,16 +2275,16 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
1938 return result;2275 return result;
1939}2276}
19402277
1941static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {2278static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
1942 if (type_entry->id == TypeTableEntryIdInt)2279 if (type_entry->id == ZigTypeIdInt)
1943 return val;2280 return val;
19442281
1945 LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);2282 LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);
1946 return LLVMBuildCall(g->builder, floor_fn, &val, 1, "");2283 return LLVMBuildCall(g->builder, floor_fn, &val, 1, "");
1947}2284}
19482285
1949static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {2286static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
1950 if (type_entry->id == TypeTableEntryIdInt)2287 if (type_entry->id == ZigTypeIdInt)
1951 return val;2288 return val;
19522289
1953 LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil);2290 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) {...@@ -1980,16 +2317,16 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {
19802317
1981static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,2318static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
1982 LLVMValueRef val1, LLVMValueRef val2,2319 LLVMValueRef val1, LLVMValueRef val2,
1983 TypeTableEntry *type_entry, DivKind div_kind)2320 ZigType *type_entry, DivKind div_kind)
1984{2321{
1985 ZigLLVMSetFastMath(g->builder, want_fast_math);2322 ZigLLVMSetFastMath(g->builder, want_fast_math);
19862323
1987 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);2324 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)) {
1989 LLVMValueRef is_zero_bit;2326 LLVMValueRef is_zero_bit;
1990 if (type_entry->id == TypeTableEntryIdInt) {2327 if (type_entry->id == ZigTypeIdInt) {
1991 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");2328 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");
1992 } else if (type_entry->id == TypeTableEntryIdFloat) {2329 } else if (type_entry->id == ZigTypeIdFloat) {
1993 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");2330 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
1994 } else {2331 } else {
1995 zig_unreachable();2332 zig_unreachable();
...@@ -2003,7 +2340,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2003,7 +2340,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
20032340
2004 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);2341 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) {
2007 LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);2344 LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);
2008 BigInt int_min_bi = {0};2345 BigInt int_min_bi = {0};
2009 eval_min_max_value_int(g, type_entry, &int_min_bi, false);2346 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...@@ -2022,7 +2359,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
2022 }2359 }
2023 }2360 }
20242361
2025 if (type_entry->id == TypeTableEntryIdFloat) {2362 if (type_entry->id == ZigTypeIdFloat) {
2026 LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");2363 LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");
2027 switch (div_kind) {2364 switch (div_kind) {
2028 case DivKindFloat:2365 case DivKindFloat:
...@@ -2073,7 +2410,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2073,7 +2410,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
2073 zig_unreachable();2410 zig_unreachable();
2074 }2411 }
20752412
2076 assert(type_entry->id == TypeTableEntryIdInt);2413 assert(type_entry->id == ZigTypeIdInt);
20772414
2078 switch (div_kind) {2415 switch (div_kind) {
2079 case DivKindFloat:2416 case DivKindFloat:
...@@ -2139,17 +2476,17 @@ enum RemKind {...@@ -2139,17 +2476,17 @@ enum RemKind {
21392476
2140static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,2477static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
2141 LLVMValueRef val1, LLVMValueRef val2,2478 LLVMValueRef val1, LLVMValueRef val2,
2142 TypeTableEntry *type_entry, RemKind rem_kind)2479 ZigType *type_entry, RemKind rem_kind)
2143{2480{
2144 ZigLLVMSetFastMath(g->builder, want_fast_math);2481 ZigLLVMSetFastMath(g->builder, want_fast_math);
21452482
2146 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);2483 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
2147 if (want_runtime_safety) {2484 if (want_runtime_safety) {
2148 LLVMValueRef is_zero_bit;2485 LLVMValueRef is_zero_bit;
2149 if (type_entry->id == TypeTableEntryIdInt) {2486 if (type_entry->id == ZigTypeIdInt) {
2150 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;2487 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;
2151 is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");2488 is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");
2152 } else if (type_entry->id == TypeTableEntryIdFloat) {2489 } else if (type_entry->id == ZigTypeIdFloat) {
2153 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");2490 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
2154 } else {2491 } else {
2155 zig_unreachable();2492 zig_unreachable();
...@@ -2164,7 +2501,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2164,7 +2501,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
2164 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);2501 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
2165 }2502 }
21662503
2167 if (type_entry->id == TypeTableEntryIdFloat) {2504 if (type_entry->id == ZigTypeIdFloat) {
2168 if (rem_kind == RemKindRem) {2505 if (rem_kind == RemKindRem) {
2169 return LLVMBuildFRem(g->builder, val1, val2, "");2506 return LLVMBuildFRem(g->builder, val1, val2, "");
2170 } else {2507 } else {
...@@ -2175,7 +2512,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2175,7 +2512,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
2175 return LLVMBuildSelect(g->builder, ltz, c, a, "");2512 return LLVMBuildSelect(g->builder, ltz, c, a, "");
2176 }2513 }
2177 } else {2514 } else {
2178 assert(type_entry->id == TypeTableEntryIdInt);2515 assert(type_entry->id == ZigTypeIdInt);
2179 if (type_entry->data.integral.is_signed) {2516 if (type_entry->data.integral.is_signed) {
2180 if (rem_kind == RemKindRem) {2517 if (rem_kind == RemKindRem) {
2181 return LLVMBuildSRem(g->builder, val1, val2, "");2518 return LLVMBuildSRem(g->builder, val1, val2, "");
...@@ -2203,12 +2540,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2203,12 +2540,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2203 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||2540 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
2204 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||2541 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2205 op_id == IrBinOpBitShiftRightExact ||2542 op_id == IrBinOpBitShiftRightExact ||
2206 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||2543 (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) ||
2207 (op1->value.type->id == TypeTableEntryIdPointer &&2544 (op1->value.type->id == ZigTypeIdPointer &&
2208 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&2545 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2209 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)2546 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
2210 );2547 );
2211 TypeTableEntry *type_entry = op1->value.type;2548 ZigType *type_entry = op1->value.type;
22122549
2213 bool want_runtime_safety = bin_op_instruction->safety_check_on &&2550 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
2214 ir_want_runtime_safety(g, &bin_op_instruction->base);2551 ir_want_runtime_safety(g, &bin_op_instruction->base);
...@@ -2234,16 +2571,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2234,16 +2571,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2234 case IrBinOpCmpGreaterThan:2571 case IrBinOpCmpGreaterThan:
2235 case IrBinOpCmpLessOrEq:2572 case IrBinOpCmpLessOrEq:
2236 case IrBinOpCmpGreaterOrEq:2573 case IrBinOpCmpGreaterOrEq:
2237 if (type_entry->id == TypeTableEntryIdFloat) {2574 if (type_entry->id == ZigTypeIdFloat) {
2238 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2575 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2239 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);2576 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
2240 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");2577 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
2241 } else if (type_entry->id == TypeTableEntryIdInt) {2578 } else if (type_entry->id == ZigTypeIdInt) {
2242 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);2579 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);
2243 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");2580 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
2244 } else if (type_entry->id == TypeTableEntryIdEnum ||2581 } else if (type_entry->id == ZigTypeIdEnum ||
2245 type_entry->id == TypeTableEntryIdErrorSet ||2582 type_entry->id == ZigTypeIdErrorSet ||
2246 type_entry->id == TypeTableEntryIdBool ||2583 type_entry->id == ZigTypeIdBool ||
2247 get_codegen_ptr_type(type_entry) != nullptr)2584 get_codegen_ptr_type(type_entry) != nullptr)
2248 {2585 {
2249 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);2586 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
...@@ -2253,14 +2590,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2253,14 +2590,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2253 }2590 }
2254 case IrBinOpAdd:2591 case IrBinOpAdd:
2255 case IrBinOpAddWrap:2592 case IrBinOpAddWrap:
2256 if (type_entry->id == TypeTableEntryIdPointer) {2593 if (type_entry->id == ZigTypeIdPointer) {
2257 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);2594 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2258 // TODO runtime safety2595 // TODO runtime safety
2259 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");2596 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
2260 } else if (type_entry->id == TypeTableEntryIdFloat) {2597 } else if (type_entry->id == ZigTypeIdFloat) {
2261 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2598 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2262 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");2599 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
2263 } else if (type_entry->id == TypeTableEntryIdInt) {2600 } else if (type_entry->id == ZigTypeIdInt) {
2264 bool is_wrapping = (op_id == IrBinOpAddWrap);2601 bool is_wrapping = (op_id == IrBinOpAddWrap);
2265 if (is_wrapping) {2602 if (is_wrapping) {
2266 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");2603 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
...@@ -2283,7 +2620,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2283,7 +2620,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2283 case IrBinOpBitShiftLeftLossy:2620 case IrBinOpBitShiftLeftLossy:
2284 case IrBinOpBitShiftLeftExact:2621 case IrBinOpBitShiftLeftExact:
2285 {2622 {
2286 assert(type_entry->id == TypeTableEntryIdInt);2623 assert(type_entry->id == ZigTypeIdInt);
2287 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2624 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
2288 type_entry, op2_value);2625 type_entry, op2_value);
2289 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);2626 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
...@@ -2300,7 +2637,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2300,7 +2637,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2300 case IrBinOpBitShiftRightLossy:2637 case IrBinOpBitShiftRightLossy:
2301 case IrBinOpBitShiftRightExact:2638 case IrBinOpBitShiftRightExact:
2302 {2639 {
2303 assert(type_entry->id == TypeTableEntryIdInt);2640 assert(type_entry->id == ZigTypeIdInt);
2304 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2641 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
2305 type_entry, op2_value);2642 type_entry, op2_value);
2306 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);2643 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
...@@ -2320,15 +2657,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2320,15 +2657,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2320 }2657 }
2321 case IrBinOpSub:2658 case IrBinOpSub:
2322 case IrBinOpSubWrap:2659 case IrBinOpSubWrap:
2323 if (type_entry->id == TypeTableEntryIdPointer) {2660 if (type_entry->id == ZigTypeIdPointer) {
2324 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);2661 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2325 // TODO runtime safety2662 // TODO runtime safety
2326 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");2663 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
2327 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");2664 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2328 } else if (type_entry->id == TypeTableEntryIdFloat) {2665 } else if (type_entry->id == ZigTypeIdFloat) {
2329 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2666 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2330 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");2667 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
2331 } else if (type_entry->id == TypeTableEntryIdInt) {2668 } else if (type_entry->id == ZigTypeIdInt) {
2332 bool is_wrapping = (op_id == IrBinOpSubWrap);2669 bool is_wrapping = (op_id == IrBinOpSubWrap);
2333 if (is_wrapping) {2670 if (is_wrapping) {
2334 return LLVMBuildSub(g->builder, op1_value, op2_value, "");2671 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
...@@ -2344,10 +2681,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2344,10 +2681,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2344 }2681 }
2345 case IrBinOpMult:2682 case IrBinOpMult:
2346 case IrBinOpMultWrap:2683 case IrBinOpMultWrap:
2347 if (type_entry->id == TypeTableEntryIdFloat) {2684 if (type_entry->id == ZigTypeIdFloat) {
2348 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2685 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2349 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");2686 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
2350 } else if (type_entry->id == TypeTableEntryIdInt) {2687 } else if (type_entry->id == ZigTypeIdInt) {
2351 bool is_wrapping = (op_id == IrBinOpMultWrap);2688 bool is_wrapping = (op_id == IrBinOpMultWrap);
2352 if (is_wrapping) {2689 if (is_wrapping) {
2353 return LLVMBuildMul(g->builder, op1_value, op2_value, "");2690 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
...@@ -2383,8 +2720,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2383,8 +2720,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2383 zig_unreachable();2720 zig_unreachable();
2384}2721}
23852722
2386static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *int_type, LLVMValueRef target_val) {2723static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) {
2387 assert(err_set_type->id == TypeTableEntryIdErrorSet);2724 assert(err_set_type->id == ZigTypeIdErrorSet);
23882725
2389 if (type_is_global_error_set(err_set_type)) {2726 if (type_is_global_error_set(err_set_type)) {
2390 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);2727 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);
...@@ -2434,8 +2771,8 @@ static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, Type...@@ -2434,8 +2771,8 @@ static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, Type
2434static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,2771static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2435 IrInstructionCast *cast_instruction)2772 IrInstructionCast *cast_instruction)
2436{2773{
2437 TypeTableEntry *actual_type = cast_instruction->value->value.type;2774 ZigType *actual_type = cast_instruction->value->value.type;
2438 TypeTableEntry *wanted_type = cast_instruction->base.value.type;2775 ZigType *wanted_type = cast_instruction->base.value.type;
2439 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);2776 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
2440 assert(expr_val);2777 assert(expr_val);
24412778
...@@ -2448,15 +2785,15 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2448,15 +2785,15 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2448 case CastOpResizeSlice:2785 case CastOpResizeSlice:
2449 {2786 {
2450 assert(cast_instruction->tmp_ptr);2787 assert(cast_instruction->tmp_ptr);
2451 assert(wanted_type->id == TypeTableEntryIdStruct);2788 assert(wanted_type->id == ZigTypeIdStruct);
2452 assert(wanted_type->data.structure.is_slice);2789 assert(wanted_type->data.structure.is_slice);
2453 assert(actual_type->id == TypeTableEntryIdStruct);2790 assert(actual_type->id == ZigTypeIdStruct);
2454 assert(actual_type->data.structure.is_slice);2791 assert(actual_type->data.structure.is_slice);
24552792
2456 TypeTableEntry *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;2793 ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
2457 TypeTableEntry *actual_child_type = actual_pointer_type->data.pointer.child_type;2794 ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type;
2458 TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;2795 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
2459 TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;2796 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
24602797
24612798
2462 size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index;2799 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,...@@ -2511,12 +2848,12 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2511 case CastOpBytesToSlice:2848 case CastOpBytesToSlice:
2512 {2849 {
2513 assert(cast_instruction->tmp_ptr);2850 assert(cast_instruction->tmp_ptr);
2514 assert(wanted_type->id == TypeTableEntryIdStruct);2851 assert(wanted_type->id == ZigTypeIdStruct);
2515 assert(wanted_type->data.structure.is_slice);2852 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;2855 ZigType *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;2856 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
25202857
25212858
2522 size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;2859 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,...@@ -2535,14 +2872,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2535 return cast_instruction->tmp_ptr;2872 return cast_instruction->tmp_ptr;
2536 }2873 }
2537 case CastOpIntToFloat:2874 case CastOpIntToFloat:
2538 assert(actual_type->id == TypeTableEntryIdInt);2875 assert(actual_type->id == ZigTypeIdInt);
2539 if (actual_type->data.integral.is_signed) {2876 if (actual_type->data.integral.is_signed) {
2540 return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");2877 return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");
2541 } else {2878 } else {
2542 return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");2879 return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");
2543 }2880 }
2544 case CastOpFloatToInt: {2881 case CastOpFloatToInt: {
2545 assert(wanted_type->id == TypeTableEntryIdInt);2882 assert(wanted_type->id == ZigTypeIdInt);
2546 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));2883 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));
25472884
2548 bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);2885 bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);
...@@ -2577,8 +2914,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2577,8 +2914,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2577 return result;2914 return result;
2578 }2915 }
2579 case CastOpBoolToInt:2916 case CastOpBoolToInt:
2580 assert(wanted_type->id == TypeTableEntryIdInt);2917 assert(wanted_type->id == ZigTypeIdInt);
2581 assert(actual_type->id == TypeTableEntryIdBool);2918 assert(actual_type->id == ZigTypeIdBool);
2582 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");2919 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
2583 case CastOpErrSet:2920 case CastOpErrSet:
2584 if (ir_want_runtime_safety(g, &cast_instruction->base)) {2921 if (ir_want_runtime_safety(g, &cast_instruction->base)) {
...@@ -2589,9 +2926,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2589,9 +2926,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2589 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");2926 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");
2590 case CastOpPtrOfArrayToSlice: {2927 case CastOpPtrOfArrayToSlice: {
2591 assert(cast_instruction->tmp_ptr);2928 assert(cast_instruction->tmp_ptr);
2592 assert(actual_type->id == TypeTableEntryIdPointer);2929 assert(actual_type->id == ZigTypeIdPointer);
2593 TypeTableEntry *array_type = actual_type->data.pointer.child_type;2930 ZigType *array_type = actual_type->data.pointer.child_type;
2594 assert(array_type->id == TypeTableEntryIdArray);2931 assert(array_type->id == ZigTypeIdArray);
25952932
2596 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,2933 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
2597 slice_ptr_index, "");2934 slice_ptr_index, "");
...@@ -2617,7 +2954,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2617,7 +2954,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2617static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,2954static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
2618 IrInstructionPtrCast *instruction)2955 IrInstructionPtrCast *instruction)
2619{2956{
2620 TypeTableEntry *wanted_type = instruction->base.value.type;2957 ZigType *wanted_type = instruction->base.value.type;
2621 if (!type_has_bits(wanted_type)) {2958 if (!type_has_bits(wanted_type)) {
2622 return nullptr;2959 return nullptr;
2623 }2960 }
...@@ -2628,7 +2965,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,...@@ -2628,7 +2965,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
2628static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,2965static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
2629 IrInstructionBitCast *instruction)2966 IrInstructionBitCast *instruction)
2630{2967{
2631 TypeTableEntry *wanted_type = instruction->base.value.type;2968 ZigType *wanted_type = instruction->base.value.type;
2632 LLVMValueRef value = ir_llvm_value(g, instruction->value);2969 LLVMValueRef value = ir_llvm_value(g, instruction->value);
2633 return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, "");2970 return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, "");
2634}2971}
...@@ -2636,11 +2973,11 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,...@@ -2636,11 +2973,11 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
2636static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,2973static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
2637 IrInstructionWidenOrShorten *instruction)2974 IrInstructionWidenOrShorten *instruction)
2638{2975{
2639 TypeTableEntry *actual_type = instruction->target->value.type;2976 ZigType *actual_type = instruction->target->value.type;
2640 // TODO instead of this logic, use the Noop instruction to change the type from2977 // TODO instead of this logic, use the Noop instruction to change the type from
2641 // enum_tag to the underlying int type2978 // enum_tag to the underlying int type
2642 TypeTableEntry *int_type;2979 ZigType *int_type;
2643 if (actual_type->id == TypeTableEntryIdEnum) {2980 if (actual_type->id == ZigTypeIdEnum) {
2644 int_type = actual_type->data.enumeration.tag_int_type;2981 int_type = actual_type->data.enumeration.tag_int_type;
2645 } else {2982 } else {
2646 int_type = actual_type;2983 int_type = actual_type;
...@@ -2651,21 +2988,21 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa...@@ -2651,21 +2988,21 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
2651}2988}
26522989
2653static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {2990static 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;
2655 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2992 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2656 return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, "");2993 return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, "");
2657}2994}
26582995
2659static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {2996static 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;
2661 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2998 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2662 return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, "");2999 return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, "");
2663}3000}
26643001
2665static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {3002static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
2666 TypeTableEntry *wanted_type = instruction->base.value.type;3003 ZigType *wanted_type = instruction->base.value.type;
2667 assert(wanted_type->id == TypeTableEntryIdEnum);3004 assert(wanted_type->id == ZigTypeIdEnum);
2668 TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;3005 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
26693006
2670 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3007 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2671 LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),3008 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,...@@ -2690,11 +3027,11 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
2690}3027}
26913028
2692static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {3029static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
2693 TypeTableEntry *wanted_type = instruction->base.value.type;3030 ZigType *wanted_type = instruction->base.value.type;
2694 assert(wanted_type->id == TypeTableEntryIdErrorSet);3031 assert(wanted_type->id == ZigTypeIdErrorSet);
26953032
2696 TypeTableEntry *actual_type = instruction->target->value.type;3033 ZigType *actual_type = instruction->target->value.type;
2697 assert(actual_type->id == TypeTableEntryIdInt);3034 assert(actual_type->id == ZigTypeIdInt);
2698 assert(!actual_type->data.integral.is_signed);3035 assert(!actual_type->data.integral.is_signed);
26993036
2700 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3037 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...@@ -2707,17 +3044,17 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
2707}3044}
27083045
2709static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {3046static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
2710 TypeTableEntry *wanted_type = instruction->base.value.type;3047 ZigType *wanted_type = instruction->base.value.type;
2711 assert(wanted_type->id == TypeTableEntryIdInt);3048 assert(wanted_type->id == ZigTypeIdInt);
2712 assert(!wanted_type->data.integral.is_signed);3049 assert(!wanted_type->data.integral.is_signed);
27133050
2714 TypeTableEntry *actual_type = instruction->target->value.type;3051 ZigType *actual_type = instruction->target->value.type;
2715 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3052 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
27163053
2717 if (actual_type->id == TypeTableEntryIdErrorSet) {3054 if (actual_type->id == ZigTypeIdErrorSet) {
2718 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),3055 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
2719 g->err_tag_type, wanted_type, target_val);3056 g->err_tag_type, wanted_type, target_val);
2720 } else if (actual_type->id == TypeTableEntryIdErrorUnion) {3057 } else if (actual_type->id == ZigTypeIdErrorUnion) {
2721 // this should have been a compile time constant3058 // this should have been a compile time constant
2722 assert(type_has_bits(actual_type->data.error_union.err_set_type));3059 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...@@ -2761,7 +3098,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
2761static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {3098static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
2762 IrUnOp op_id = un_op_instruction->op_id;3099 IrUnOp op_id = un_op_instruction->op_id;
2763 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);3100 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
2766 switch (op_id) {3103 switch (op_id) {
2767 case IrUnOpInvalid:3104 case IrUnOpInvalid:
...@@ -2771,10 +3108,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst...@@ -2771,10 +3108,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
2771 case IrUnOpNegation:3108 case IrUnOpNegation:
2772 case IrUnOpNegationWrap:3109 case IrUnOpNegationWrap:
2773 {3110 {
2774 if (expr_type->id == TypeTableEntryIdFloat) {3111 if (expr_type->id == ZigTypeIdFloat) {
2775 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));3112 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
2776 return LLVMBuildFNeg(g->builder, expr, "");3113 return LLVMBuildFNeg(g->builder, expr, "");
2777 } else if (expr_type->id == TypeTableEntryIdInt) {3114 } else if (expr_type->id == ZigTypeIdInt) {
2778 if (op_id == IrUnOpNegationWrap) {3115 if (op_id == IrUnOpNegationWrap) {
2779 return LLVMBuildNeg(g->builder, expr, "");3116 return LLVMBuildNeg(g->builder, expr, "");
2780 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {3117 } 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...@@ -2805,7 +3142,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrI
2805static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,3142static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
2806 IrInstructionDeclVar *decl_var_instruction)3143 IrInstructionDeclVar *decl_var_instruction)
2807{3144{
2808 VariableTableEntry *var = decl_var_instruction->var;3145 ZigVar *var = decl_var_instruction->var;
28093146
2810 if (!type_has_bits(var->value->type))3147 if (!type_has_bits(var->value->type))
2811 return nullptr;3148 return nullptr;
...@@ -2823,13 +3160,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -2823,13 +3160,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
28233160
2824 if (have_init_expr) {3161 if (have_init_expr) {
2825 assert(var->value->type == init_value->value.type);3162 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,
2827 PtrLenSingle, var->align_bytes, 0, 0);3164 PtrLenSingle, var->align_bytes, 0, 0);
2828 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));3165 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
2829 } else {3166 } else {
2830 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);3167 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
2831 if (want_safe) {3168 if (want_safe) {
2832 TypeTableEntry *usize = g->builtin_types.entry_usize;3169 ZigType *usize = g->builtin_types.entry_usize;
2833 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);3170 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);
2834 assert(size_bytes > 0);3171 assert(size_bytes > 0);
28353172
...@@ -2849,13 +3186,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -2849,13 +3186,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
2849}3186}
28503187
2851static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) {3188static 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;
2853 if (!type_has_bits(child_type))3190 if (!type_has_bits(child_type))
2854 return nullptr;3191 return nullptr;
28553192
2856 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3193 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
2857 TypeTableEntry *ptr_type = instruction->ptr->value.type;3194 ZigType *ptr_type = instruction->ptr->value.type;
2858 assert(ptr_type->id == TypeTableEntryIdPointer);3195 assert(ptr_type->id == ZigTypeIdPointer);
28593196
2860 uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;3197 uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;
2861 if (unaligned_bit_count == 0)3198 if (unaligned_bit_count == 0)
...@@ -2880,8 +3217,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -2880,8 +3217,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
2880 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3217 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
2881 LLVMValueRef value = ir_llvm_value(g, instruction->value);3218 LLVMValueRef value = ir_llvm_value(g, instruction->value);
28823219
2883 assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);3220 assert(instruction->ptr->value.type->id == ZigTypeIdPointer);
2884 TypeTableEntry *ptr_type = instruction->ptr->value.type;3221 ZigType *ptr_type = instruction->ptr->value.type;
28853222
2886 gen_assign_raw(g, ptr, ptr_type, value);3223 gen_assign_raw(g, ptr, ptr_type, value);
28873224
...@@ -2889,7 +3226,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -2889,7 +3226,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
2889}3226}
28903227
2891static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {3228static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
2892 VariableTableEntry *var = instruction->var;3229 ZigVar *var = instruction->var;
2893 if (type_has_bits(var->value->type)) {3230 if (type_has_bits(var->value->type)) {
2894 assert(var->value_ref);3231 assert(var->value_ref);
2895 return var->value_ref;3232 return var->value_ref;
...@@ -2900,9 +3237,9 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -2900,9 +3237,9 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
29003237
2901static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {3238static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
2902 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);3239 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
2903 TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type;3240 ZigType *array_ptr_type = instruction->array_ptr->value.type;
2904 assert(array_ptr_type->id == TypeTableEntryIdPointer);3241 assert(array_ptr_type->id == ZigTypeIdPointer);
2905 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;3242 ZigType *array_type = array_ptr_type->data.pointer.child_type;
2906 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);3243 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
2907 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);3244 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
2908 assert(subscript_value);3245 assert(subscript_value);
...@@ -2912,11 +3249,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2912,11 +3249,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29123249
2913 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;3250 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
29143251
2915 if (array_type->id == TypeTableEntryIdArray ||3252 if (array_type->id == ZigTypeIdArray ||
2916 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))3253 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
2917 {3254 {
2918 if (array_type->id == TypeTableEntryIdPointer) {3255 if (array_type->id == ZigTypeIdPointer) {
2919 assert(array_type->data.pointer.child_type->id == TypeTableEntryIdArray);3256 assert(array_type->data.pointer.child_type->id == ZigTypeIdArray);
2920 array_type = array_type->data.pointer.child_type;3257 array_type = array_type->data.pointer.child_type;
2921 }3258 }
2922 if (safety_check_on) {3259 if (safety_check_on) {
...@@ -2927,8 +3264,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2927,8 +3264,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
2927 if (array_ptr_type->data.pointer.unaligned_bit_count != 0) {3264 if (array_ptr_type->data.pointer.unaligned_bit_count != 0) {
2928 return array_ptr_ptr;3265 return array_ptr_ptr;
2929 }3266 }
2930 TypeTableEntry *child_type = array_type->data.array.child_type;3267 ZigType *child_type = array_type->data.array.child_type;
2931 if (child_type->id == TypeTableEntryIdStruct &&3268 if (child_type->id == ZigTypeIdStruct &&
2932 child_type->data.structure.layout == ContainerLayoutPacked)3269 child_type->data.structure.layout == ContainerLayoutPacked)
2933 {3270 {
2934 size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;3271 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...@@ -2951,13 +3288,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
2951 subscript_value3288 subscript_value
2952 };3289 };
2953 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");3290 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");
2954 } else if (array_type->id == TypeTableEntryIdPointer) {3291 } else if (array_type->id == ZigTypeIdPointer) {
2955 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);3292 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
2956 LLVMValueRef indices[] = {3293 LLVMValueRef indices[] = {
2957 subscript_value3294 subscript_value
2958 };3295 };
2959 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");3296 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
2960 } else if (array_type->id == TypeTableEntryIdStruct) {3297 } else if (array_type->id == ZigTypeIdStruct) {
2961 assert(array_type->data.structure.is_slice);3298 assert(array_type->data.structure.is_slice);
2962 if (!type_has_bits(instruction->base.value.type)) {3299 if (!type_has_bits(instruction->base.value.type)) {
2963 if (safety_check_on) {3300 if (safety_check_on) {
...@@ -2990,8 +3327,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2990,8 +3327,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29903327
2991static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {3328static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {
2992 return g->have_err_ret_tracing &&3329 return g->have_err_ret_tracing &&
2993 (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion ||3330 (fn_type_id->return_type->id == ZigTypeIdErrorUnion ||
2994 fn_type_id->return_type->id == TypeTableEntryIdErrorSet ||3331 fn_type_id->return_type->id == ZigTypeIdErrorSet ||
2995 fn_type_id->cc == CallingConventionAsync);3332 fn_type_id->cc == CallingConventionAsync);
2996}3333}
29973334
...@@ -3047,7 +3384,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {...@@ -3047,7 +3384,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {
30473384
3048static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {3385static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
3049 LLVMValueRef fn_val;3386 LLVMValueRef fn_val;
3050 TypeTableEntry *fn_type;3387 ZigType *fn_type;
3051 if (instruction->fn_entry) {3388 if (instruction->fn_entry) {
3052 fn_val = fn_llvm_value(g, instruction->fn_entry);3389 fn_val = fn_llvm_value(g, instruction->fn_entry);
3053 fn_type = instruction->fn_entry->type_entry;3390 fn_type = instruction->fn_entry->type_entry;
...@@ -3059,43 +3396,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3059,43 +3396,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
30593396
3060 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;3397 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;
3063 bool ret_has_bits = type_has_bits(src_return_type);3400 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) &&3402 CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
3066 calling_convention_does_first_arg_return(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);
3067 bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id);3405 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;
3070 bool is_var_args = fn_type_id->is_var_args;3406 bool is_var_args = fn_type_id->is_var_args;
3071 LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);3407 ZigList<LLVMValueRef> gen_param_values = {};
3072 size_t gen_param_index = 0;
3073 if (first_arg_ret) {3408 if (first_arg_ret) {
3074 gen_param_values[gen_param_index] = instruction->tmp_ptr;3409 gen_param_values.append(instruction->tmp_ptr);
3075 gen_param_index += 1;
3076 }3410 }
3077 if (prefix_arg_err_ret_stack) {3411 if (prefix_arg_err_ret_stack) {
3078 gen_param_values[gen_param_index] = get_cur_err_ret_trace_val(g, instruction->base.scope);3412 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
3079 gen_param_index += 1;
3080 }3413 }
3081 if (instruction->is_async) {3414 if (instruction->is_async) {
3082 gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->async_allocator);3415 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));
3083 gen_param_index += 1;
30843416
3085 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");3417 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");
3086 gen_param_values[gen_param_index] = err_val_ptr;3418 gen_param_values.append(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 }
3098 }3419 }
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
3100 ZigLLVM_FnInline fn_inline;3427 ZigLLVM_FnInline fn_inline;
3101 switch (instruction->fn_inline) {3428 switch (instruction->fn_inline) {
...@@ -3110,12 +3437,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3110,12 +3437,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3110 break;3437 break;
3111 }3438 }
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);
3114 LLVMValueRef result;3441 LLVMValueRef result;
3115 3442
3116 if (instruction->new_stack == nullptr) {3443 if (instruction->new_stack == nullptr) {
3117 result = ZigLLVMBuildCall(g->builder, fn_val,3444 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, "");
3119 } else {3446 } else {
3120 LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g);3447 LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g);
3121 LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g);3448 LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g);
...@@ -3124,7 +3451,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3124,7 +3451,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3124 LLVMValueRef old_stack_ref = LLVMBuildCall(g->builder, stacksave_fn_val, nullptr, 0, "");3451 LLVMValueRef old_stack_ref = LLVMBuildCall(g->builder, stacksave_fn_val, nullptr, 0, "");
3125 gen_set_stack_pointer(g, new_stack_addr);3452 gen_set_stack_pointer(g, new_stack_addr);
3126 result = ZigLLVMBuildCall(g->builder, fn_val,3453 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, "");
3128 LLVMBuildCall(g->builder, stackrestore_fn_val, &old_stack_ref, 1, "");3455 LLVMBuildCall(g->builder, stackrestore_fn_val, &old_stack_ref, 1, "");
3129 }3456 }
31303457
...@@ -3135,7 +3462,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3135,7 +3462,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3135 return instruction->tmp_ptr;3462 return instruction->tmp_ptr;
3136 }3463 }
31373464
3138 if (src_return_type->id == TypeTableEntryIdUnreachable) {3465 if (src_return_type->id == ZigTypeIdUnreachable) {
3139 return LLVMBuildUnreachable(g->builder);3466 return LLVMBuildUnreachable(g->builder);
3140 } else if (!ret_has_bits) {3467 } else if (!ret_has_bits) {
3141 return nullptr;3468 return nullptr;
...@@ -3155,14 +3482,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -3155,14 +3482,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
3155 IrInstructionStructFieldPtr *instruction)3482 IrInstructionStructFieldPtr *instruction)
3156{3483{
3157 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);3484 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
3158 // not necessarily a pointer. could be TypeTableEntryIdStruct3485 // not necessarily a pointer. could be ZigTypeIdStruct
3159 TypeTableEntry *struct_ptr_type = instruction->struct_ptr->value.type;3486 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;
3160 TypeStructField *field = instruction->field;3487 TypeStructField *field = instruction->field;
31613488
3162 if (!type_has_bits(field->type_entry))3489 if (!type_has_bits(field->type_entry))
3163 return nullptr;3490 return nullptr;
31643491
3165 if (struct_ptr_type->id == TypeTableEntryIdPointer &&3492 if (struct_ptr_type->id == ZigTypeIdPointer &&
3166 struct_ptr_type->data.pointer.unaligned_bit_count != 0)3493 struct_ptr_type->data.pointer.unaligned_bit_count != 0)
3167 {3494 {
3168 return struct_ptr;3495 return struct_ptr;
...@@ -3175,10 +3502,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -3175,10 +3502,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
3175static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,3502static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
3176 IrInstructionUnionFieldPtr *instruction)3503 IrInstructionUnionFieldPtr *instruction)
3177{3504{
3178 TypeTableEntry *union_ptr_type = instruction->union_ptr->value.type;3505 ZigType *union_ptr_type = instruction->union_ptr->value.type;
3179 assert(union_ptr_type->id == TypeTableEntryIdPointer);3506 assert(union_ptr_type->id == ZigTypeIdPointer);
3180 TypeTableEntry *union_type = union_ptr_type->data.pointer.child_type;3507 ZigType *union_type = union_ptr_type->data.pointer.child_type;
3181 assert(union_type->id == TypeTableEntryIdUnion);3508 assert(union_type->id == ZigTypeIdUnion);
31823509
3183 TypeUnionField *field = instruction->field;3510 TypeUnionField *field = instruction->field;
31843511
...@@ -3304,7 +3631,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3304,7 +3631,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3304 }3631 }
33053632
3306 if (!is_return) {3633 if (!is_return) {
3307 VariableTableEntry *variable = instruction->output_vars[i];3634 ZigVar *variable = instruction->output_vars[i];
3308 assert(variable);3635 assert(variable);
3309 param_types[param_index] = LLVMTypeOf(variable->value_ref);3636 param_types[param_index] = LLVMTypeOf(variable->value_ref);
3310 param_values[param_index] = variable->value_ref;3637 param_values[param_index] = variable->value_ref;
...@@ -3345,9 +3672,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3345,9 +3672,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3345 return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");3672 return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
3346}3673}
33473674
3348static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {3675static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
3349 assert(maybe_type->id == TypeTableEntryIdOptional);3676 assert(maybe_type->id == ZigTypeIdOptional);
3350 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;3677 ZigType *child_type = maybe_type->data.maybe.child_type;
3351 if (child_type->zero_bits) {3678 if (child_type->zero_bits) {
3352 return maybe_handle;3679 return maybe_handle;
3353 } else {3680 } else {
...@@ -3370,11 +3697,11 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable...@@ -3370,11 +3697,11 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable
3370static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,3697static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
3371 IrInstructionUnwrapOptional *instruction)3698 IrInstructionUnwrapOptional *instruction)
3372{3699{
3373 TypeTableEntry *ptr_type = instruction->value->value.type;3700 ZigType *ptr_type = instruction->value->value.type;
3374 assert(ptr_type->id == TypeTableEntryIdPointer);3701 assert(ptr_type->id == ZigTypeIdPointer);
3375 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;3702 ZigType *maybe_type = ptr_type->data.pointer.child_type;
3376 assert(maybe_type->id == TypeTableEntryIdOptional);3703 assert(maybe_type->id == ZigTypeIdOptional);
3377 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;3704 ZigType *child_type = maybe_type->data.maybe.child_type;
3378 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);3705 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
3379 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);3706 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
3380 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {3707 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,...@@ -3401,7 +3728,7 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
3401 }3728 }
3402}3729}
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) {
3405 ZigLLVMFnKey key = {};3732 ZigLLVMFnKey key = {};
3406 const char *fn_name;3733 const char *fn_name;
3407 uint32_t n_args;3734 uint32_t n_args;
...@@ -3444,7 +3771,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui...@@ -3444,7 +3771,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
3444}3771}
34453772
3446static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {3773static 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;
3448 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);3775 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
3449 LLVMValueRef operand = ir_llvm_value(g, instruction->value);3776 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
3450 LLVMValueRef params[] {3777 LLVMValueRef params[] {
...@@ -3456,7 +3783,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3456,7 +3783,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
3456}3783}
34573784
3458static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {3785static 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;
3460 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);3787 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
3461 LLVMValueRef operand = ir_llvm_value(g, instruction->value);3788 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
3462 LLVMValueRef params[] {3789 LLVMValueRef params[] {
...@@ -3468,7 +3795,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3468,7 +3795,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
3468}3795}
34693796
3470static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {3797static 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;
3472 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);3799 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
3473 LLVMValueRef operand = ir_llvm_value(g, instruction->value);3800 LLVMValueRef operand = ir_llvm_value(g, instruction->value);
3474 LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, "");3801 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...@@ -3545,15 +3872,15 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
3545 return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, "");3872 return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, "");
3546}3873}
35473874
3548static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_type) {3875static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
3549 assert(enum_type->id == TypeTableEntryIdEnum);3876 assert(enum_type->id == ZigTypeIdEnum);
3550 if (enum_type->data.enumeration.name_function)3877 if (enum_type->data.enumeration.name_function)
3551 return enum_type->data.enumeration.name_function;3878 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,
3554 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);3881 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
3555 TypeTableEntry *u8_slice_type = get_slice_type(g, u8_ptr_type);3882 ZigType *u8_slice_type = get_slice_type(g, u8_ptr_type);
3556 TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;3883 ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
35573884
3558 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0),3885 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0),
3559 &tag_int_type->type_ref, 1, false);3886 &tag_int_type->type_ref, 1, false);
...@@ -3571,7 +3898,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_...@@ -3571,7 +3898,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
35713898
3572 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);3899 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
3573 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);3900 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
3574 FnTableEntry *prev_cur_fn = g->cur_fn;3901 ZigFn *prev_cur_fn = g->cur_fn;
3575 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;3902 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
35763903
3577 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");3904 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
...@@ -3586,7 +3913,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_...@@ -3586,7 +3913,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
3586 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, tag_int_value, bad_value_block, field_count);3913 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;
3590 LLVMValueRef array_ptr_indices[] = {3917 LLVMValueRef array_ptr_indices[] = {
3591 LLVMConstNull(usize->type_ref),3918 LLVMConstNull(usize->type_ref),
3592 LLVMConstNull(usize->type_ref),3919 LLVMConstNull(usize->type_ref),
...@@ -3643,8 +3970,8 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_...@@ -3643,8 +3970,8 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
3643static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,3970static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
3644 IrInstructionTagName *instruction)3971 IrInstructionTagName *instruction)
3645{3972{
3646 TypeTableEntry *enum_type = instruction->target->value.type;3973 ZigType *enum_type = instruction->target->value.type;
3647 assert(enum_type->id == TypeTableEntryIdEnum);3974 assert(enum_type->id == ZigTypeIdEnum);
36483975
3649 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);3976 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...@@ -3656,10 +3983,10 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
3656static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,3983static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
3657 IrInstructionFieldParentPtr *instruction)3984 IrInstructionFieldParentPtr *instruction)
3658{3985{
3659 TypeTableEntry *container_ptr_type = instruction->base.value.type;3986 ZigType *container_ptr_type = instruction->base.value.type;
3660 assert(container_ptr_type->id == TypeTableEntryIdPointer);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
3664 size_t byte_offset = LLVMOffsetOfElement(g->target_data_ref,3991 size_t byte_offset = LLVMOffsetOfElement(g->target_data_ref,
3665 container_type->type_ref, instruction->field->gen_index);3992 container_type->type_ref, instruction->field->gen_index);
...@@ -3669,7 +3996,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa...@@ -3669,7 +3996,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
3669 if (byte_offset == 0) {3996 if (byte_offset == 0) {
3670 return LLVMBuildBitCast(g->builder, field_ptr_val, container_ptr_type->type_ref, "");3997 return LLVMBuildBitCast(g->builder, field_ptr_val, container_ptr_type->type_ref, "");
3671 } else {3998 } else {
3672 TypeTableEntry *usize = g->builtin_types.entry_usize;3999 ZigType *usize = g->builtin_types.entry_usize;
36734000
3674 LLVMValueRef field_ptr_int = LLVMBuildPtrToInt(g->builder, field_ptr_val,4001 LLVMValueRef field_ptr_int = LLVMBuildPtrToInt(g->builder, field_ptr_val,
3675 usize->type_ref, "");4002 usize->type_ref, "");
...@@ -3690,32 +4017,32 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -3690,32 +4017,32 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
3690 return target_val;4017 return target_val;
3691 }4018 }
36924019
3693 TypeTableEntry *target_type = instruction->base.value.type;4020 ZigType *target_type = instruction->base.value.type;
3694 uint32_t align_bytes;4021 uint32_t align_bytes;
3695 LLVMValueRef ptr_val;4022 LLVMValueRef ptr_val;
36964023
3697 if (target_type->id == TypeTableEntryIdPointer) {4024 if (target_type->id == ZigTypeIdPointer) {
3698 align_bytes = target_type->data.pointer.alignment;4025 align_bytes = target_type->data.pointer.alignment;
3699 ptr_val = target_val;4026 ptr_val = target_val;
3700 } else if (target_type->id == TypeTableEntryIdFn) {4027 } else if (target_type->id == ZigTypeIdFn) {
3701 align_bytes = target_type->data.fn.fn_type_id.alignment;4028 align_bytes = target_type->data.fn.fn_type_id.alignment;
3702 ptr_val = target_val;4029 ptr_val = target_val;
3703 } else if (target_type->id == TypeTableEntryIdOptional &&4030 } else if (target_type->id == ZigTypeIdOptional &&
3704 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)4031 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
3705 {4032 {
3706 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;4033 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
3707 ptr_val = target_val;4034 ptr_val = target_val;
3708 } else if (target_type->id == TypeTableEntryIdOptional &&4035 } else if (target_type->id == ZigTypeIdOptional &&
3709 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)4036 target_type->data.maybe.child_type->id == ZigTypeIdFn)
3710 {4037 {
3711 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;4038 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
3712 ptr_val = target_val;4039 ptr_val = target_val;
3713 } else if (target_type->id == TypeTableEntryIdOptional &&4040 } else if (target_type->id == ZigTypeIdOptional &&
3714 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)4041 target_type->data.maybe.child_type->id == ZigTypeIdPromise)
3715 {4042 {
3716 zig_panic("TODO audit this function");4043 zig_panic("TODO audit this function");
3717 } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) {4044 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
3718 TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;4045 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
3719 align_bytes = slice_ptr_type->data.pointer.alignment;4046 align_bytes = slice_ptr_type->data.pointer.alignment;
37204047
3721 size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index;4048 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...@@ -3727,7 +4054,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
37274054
3728 assert(align_bytes != 1);4055 assert(align_bytes != 1);
37294056
3730 TypeTableEntry *usize = g->builtin_types.entry_usize;4057 ZigType *usize = g->builtin_types.entry_usize;
3731 LLVMValueRef ptr_as_int_val = LLVMBuildPtrToInt(g->builder, ptr_val, usize->type_ref, "");4058 LLVMValueRef ptr_as_int_val = LLVMBuildPtrToInt(g->builder, ptr_val, usize->type_ref, "");
3732 LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->type_ref, align_bytes - 1, false);4059 LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->type_ref, align_bytes - 1, false);
3733 LLVMValueRef anded_val = LLVMBuildAnd(g->builder, ptr_as_int_val, alignment_minus_1, "");4060 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...@@ -3751,7 +4078,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
3751{4078{
3752 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope);4079 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope);
3753 if (cur_err_ret_trace_val == nullptr) {4080 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);
3755 return LLVMConstNull(ptr_to_stack_trace_type->type_ref);4082 return LLVMConstNull(ptr_to_stack_trace_type->type_ref);
3756 }4083 }
3757 return cur_err_ret_trace_val;4084 return cur_err_ret_trace_val;
...@@ -3811,9 +4138,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -3811,9 +4138,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
3811 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,4138 LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
3812 success_order, failure_order, instruction->is_weak);4139 success_order, failure_order, instruction->is_weak);
38134140
3814 TypeTableEntry *maybe_type = instruction->base.value.type;4141 ZigType *maybe_type = instruction->base.value.type;
3815 assert(maybe_type->id == TypeTableEntryIdOptional);4142 assert(maybe_type->id == ZigTypeIdOptional);
3816 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;4143 ZigType *child_type = maybe_type->data.maybe.child_type;
38174144
3818 if (type_is_codegen_pointer(child_type)) {4145 if (type_is_codegen_pointer(child_type)) {
3819 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");4146 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
...@@ -3843,8 +4170,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst...@@ -3843,8 +4170,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst
38434170
3844static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {4171static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
3845 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);4172 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3846 TypeTableEntry *dest_type = instruction->base.value.type;4173 ZigType *dest_type = instruction->base.value.type;
3847 TypeTableEntry *src_type = instruction->target->value.type;4174 ZigType *src_type = instruction->target->value.type;
3848 if (dest_type == src_type) {4175 if (dest_type == src_type) {
3849 // no-op4176 // no-op
3850 return target_val;4177 return target_val;
...@@ -3865,8 +4192,8 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -3865,8 +4192,8 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
38654192
3866 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");4193 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
38674194
3868 TypeTableEntry *ptr_type = instruction->dest_ptr->value.type;4195 ZigType *ptr_type = instruction->dest_ptr->value.type;
3869 assert(ptr_type->id == TypeTableEntryIdPointer);4196 assert(ptr_type->id == ZigTypeIdPointer);
38704197
3871 ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, char_val, len_val, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);4198 ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, char_val, len_val, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
3872 return nullptr;4199 return nullptr;
...@@ -3882,11 +4209,11 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -3882,11 +4209,11 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
3882 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");4209 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
3883 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");4210 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
38844211
3885 TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type;4212 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;
3886 TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type;4213 ZigType *src_ptr_type = instruction->src_ptr->value.type;
38874214
3888 assert(dest_ptr_type->id == TypeTableEntryIdPointer);4215 assert(dest_ptr_type->id == ZigTypeIdPointer);
3889 assert(src_ptr_type->id == TypeTableEntryIdPointer);4216 assert(src_ptr_type->id == ZigTypeIdPointer);
38904217
3891 bool is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile);4218 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...@@ -3899,19 +4226,19 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3899 assert(instruction->tmp_ptr);4226 assert(instruction->tmp_ptr);
39004227
3901 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);4228 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
3902 TypeTableEntry *array_ptr_type = instruction->ptr->value.type;4229 ZigType *array_ptr_type = instruction->ptr->value.type;
3903 assert(array_ptr_type->id == TypeTableEntryIdPointer);4230 assert(array_ptr_type->id == ZigTypeIdPointer);
3904 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;4231 ZigType *array_type = array_ptr_type->data.pointer.child_type;
3905 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);4232 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
39064233
3907 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;4234 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
39084235
3909 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);4236 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
39104237
3911 if (array_type->id == TypeTableEntryIdArray ||4238 if (array_type->id == ZigTypeIdArray ||
3912 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))4239 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
3913 {4240 {
3914 if (array_type->id == TypeTableEntryIdPointer) {4241 if (array_type->id == ZigTypeIdPointer) {
3915 array_type = array_type->data.pointer.child_type;4242 array_type = array_type->data.pointer.child_type;
3916 }4243 }
3917 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);4244 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
...@@ -3952,7 +4279,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3952,7 +4279,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3952 gen_store_untyped(g, len_value, len_field_ptr, 0, false);4279 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
39534280
3954 return tmp_struct_ptr;4281 return tmp_struct_ptr;
3955 } else if (array_type->id == TypeTableEntryIdPointer) {4282 } else if (array_type->id == ZigTypeIdPointer) {
3956 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);4283 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
3957 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);4284 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
3958 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);4285 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
...@@ -3974,7 +4301,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3974,7 +4301,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3974 gen_store_untyped(g, len_value, len_field_ptr, 0, false);4301 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
39754302
3976 return tmp_struct_ptr;4303 return tmp_struct_ptr;
3977 } else if (array_type->id == TypeTableEntryIdStruct) {4304 } else if (array_type->id == ZigTypeIdStruct) {
3978 assert(array_type->data.structure.is_slice);4305 assert(array_type->data.structure.is_slice);
3979 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);4306 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
3980 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);4307 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
...@@ -4050,7 +4377,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {...@@ -4050,7 +4377,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
4050 if (g->frame_address_fn_val)4377 if (g->frame_address_fn_val)
4051 return g->frame_address_fn_val;4378 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
4055 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,4382 LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
4056 &g->builtin_types.entry_i32->type_ref, 1, false);4383 &g->builtin_types.entry_i32->type_ref, 1, false);
...@@ -4088,8 +4415,8 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,...@@ -4088,8 +4415,8 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
4088}4415}
40894416
4090static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {4417static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
4091 TypeTableEntry *int_type = instruction->result_ptr_type;4418 ZigType *int_type = instruction->result_ptr_type;
4092 assert(int_type->id == TypeTableEntryIdInt);4419 assert(int_type->id == ZigTypeIdInt);
40934420
4094 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);4421 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
4095 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);4422 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
...@@ -4128,8 +4455,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -4128,8 +4455,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
4128 return render_shl_with_overflow(g, instruction);4455 return render_shl_with_overflow(g, instruction);
4129 }4456 }
41304457
4131 TypeTableEntry *int_type = instruction->result_ptr_type;4458 ZigType *int_type = instruction->result_ptr_type;
4132 assert(int_type->id == TypeTableEntryIdInt);4459 assert(int_type->id == ZigTypeIdInt);
41334460
4134 LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);4461 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,...@@ -4151,8 +4478,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
4151}4478}
41524479
4153static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {4480static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {
4154 TypeTableEntry *err_union_type = instruction->value->value.type;4481 ZigType *err_union_type = instruction->value->value.type;
4155 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;4482 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4156 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);4483 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);
41574484
4158 LLVMValueRef err_val;4485 LLVMValueRef err_val;
...@@ -4168,10 +4495,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI...@@ -4168,10 +4495,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
4168}4495}
41694496
4170static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {4497static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
4171 TypeTableEntry *ptr_type = instruction->value->value.type;4498 ZigType *ptr_type = instruction->value->value.type;
4172 assert(ptr_type->id == TypeTableEntryIdPointer);4499 assert(ptr_type->id == ZigTypeIdPointer);
4173 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;4500 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4174 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;4501 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4175 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);4502 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
4176 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);4503 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...@@ -4184,10 +4511,10 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
4184}4511}
41854512
4186static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {4513static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
4187 TypeTableEntry *ptr_type = instruction->value->value.type;4514 ZigType *ptr_type = instruction->value->value.type;
4188 assert(ptr_type->id == TypeTableEntryIdPointer);4515 assert(ptr_type->id == ZigTypeIdPointer);
4189 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;4516 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4190 TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;4517 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4191 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);4518 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
4192 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);4519 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...@@ -4223,11 +4550,11 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
4223}4550}
42244551
4225static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {4552static 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
4232 if (child_type->zero_bits) {4559 if (child_type->zero_bits) {
4233 return LLVMConstInt(LLVMInt1Type(), 1, false);4560 return LLVMConstInt(LLVMInt1Type(), 1, false);
...@@ -4250,12 +4577,12 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I...@@ -4250,12 +4577,12 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
4250}4577}
42514578
4252static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {4579static 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;4584 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4258 TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;4585 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
42594586
4260 LLVMValueRef err_val = ir_llvm_value(g, instruction->value);4587 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...@@ -4271,12 +4598,12 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
4271}4598}
42724599
4273static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {4600static 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;4605 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4279 TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;4606 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
42804607
4281 if (!type_has_bits(err_set_type)) {4608 if (!type_has_bits(err_set_type)) {
4282 return ir_llvm_value(g, instruction->value);4609 return ir_llvm_value(g, instruction->value);
...@@ -4301,10 +4628,10 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa...@@ -4301,10 +4628,10 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
4301}4628}
43024629
4303static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {4630static 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;
4305 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);4632 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;
4308 if (!type_has_bits(tag_type))4635 if (!type_has_bits(tag_type))
4309 return nullptr;4636 return nullptr;
43104637
...@@ -4314,7 +4641,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir...@@ -4314,7 +4641,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
43144641
4315 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,4642 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
4316 union_type->data.unionation.gen_tag_index, "");4643 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);
4318 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);4645 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
4319}4646}
43204647
...@@ -4331,7 +4658,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,...@@ -4331,7 +4658,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
43314658
4332 uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry);4659 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,
4335 false, false, PtrLenSingle, field_align_bytes,4662 false, false, PtrLenSingle, field_align_bytes,
4336 (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);4663 (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...@@ -4347,14 +4674,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
4347 return nullptr;4674 return nullptr;
43484675
4349 uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);4676 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,
4351 false, false, PtrLenSingle, field_align_bytes,4678 false, false, PtrLenSingle, field_align_bytes,
4352 0, 0);4679 0, 0);
43534680
4354 LLVMValueRef uncasted_union_ptr;4681 LLVMValueRef uncasted_union_ptr;
4355 // Even if safety is off in this block, if the union type has the safety field, we have to populate it4682 // Even if safety is off in this block, if the union type has the safety field, we have to populate it
4356 // correctly. Otherwise safety code somewhere other than here could fail.4683 // correctly. Otherwise safety code somewhere other than here could fail.
4357 TypeTableEntry *union_type = instruction->union_type;4684 ZigType *union_type = instruction->union_type;
4358 if (union_type->data.unionation.gen_tag_index != SIZE_MAX) {4685 if (union_type->data.unionation.gen_tag_index != SIZE_MAX) {
4359 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,4686 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
4360 union_type->data.unionation.gen_tag_index, "");4687 union_type->data.unionation.gen_tag_index, "");
...@@ -4380,14 +4707,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I...@@ -4380,14 +4707,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
4380static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable,4707static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable,
4381 IrInstructionContainerInitList *instruction)4708 IrInstructionContainerInitList *instruction)
4382{4709{
4383 TypeTableEntry *array_type = instruction->base.value.type;4710 ZigType *array_type = instruction->base.value.type;
4384 assert(array_type->id == TypeTableEntryIdArray);4711 assert(array_type->id == ZigTypeIdArray);
4385 LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;4712 LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;
4386 assert(tmp_array_ptr);4713 assert(tmp_array_ptr);
43874714
4388 size_t field_count = instruction->item_count;4715 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;
4391 for (size_t i = 0; i < field_count; i += 1) {4718 for (size_t i = 0; i < field_count; i += 1) {
4392 LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]);4719 LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]);
4393 LLVMValueRef indices[] = {4720 LLVMValueRef indices[] = {
...@@ -4511,13 +4838,13 @@ static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable,...@@ -4511,13 +4838,13 @@ static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable,
4511 return LLVMBuildBitCast(g->builder, uncasted_result, instruction->base.value.type->type_ref, "");4838 return LLVMBuildBitCast(g->builder, uncasted_result, instruction->base.value.type->type_ref, "");
4512}4839}
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) {
4515 if (g->coro_alloc_helper_fn_val != nullptr)4842 if (g->coro_alloc_helper_fn_val != nullptr)
4516 return g->coro_alloc_helper_fn_val;4843 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
4522 LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref);4849 LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref);
4523 LLVMTypeRef *alloc_fn_arg_types = allocate<LLVMTypeRef>(LLVMCountParamTypes(alloc_raw_fn_type_ref));4850 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...@@ -4545,7 +4872,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
45454872
4546 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);4873 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
4547 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);4874 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
4548 FnTableEntry *prev_cur_fn = g->cur_fn;4875 ZigFn *prev_cur_fn = g->cur_fn;
4549 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;4876 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
45504877
4551 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");4878 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
...@@ -4596,9 +4923,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f...@@ -4596,9 +4923,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
45964923
4597 LLVMPositionBuilderAtEnd(g->builder, ok_block);4924 LLVMPositionBuilderAtEnd(g->builder, ok_block);
4598 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");4925 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,
4600 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);4927 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);
4602 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;4929 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
4603 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");4930 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
4604 LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, "");4931 LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, "");
...@@ -4643,8 +4970,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -4643,8 +4970,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
4643 IrInstructionAtomicRmw *instruction)4970 IrInstructionAtomicRmw *instruction)
4644{4971{
4645 bool is_signed;4972 bool is_signed;
4646 TypeTableEntry *operand_type = instruction->operand->value.type;4973 ZigType *operand_type = instruction->operand->value.type;
4647 if (operand_type->id == TypeTableEntryIdInt) {4974 if (operand_type->id == ZigTypeIdInt) {
4648 is_signed = operand_type->data.integral.is_signed;4975 is_signed = operand_type->data.integral.is_signed;
4649 } else {4976 } else {
4650 is_signed = false;4977 is_signed = false;
...@@ -4699,7 +5026,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e...@@ -4699,7 +5026,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e
46995026
4700static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {5027static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {
4701 LLVMValueRef op = ir_llvm_value(g, instruction->op);5028 LLVMValueRef op = ir_llvm_value(g, instruction->op);
4702 assert(instruction->base.value.type->id == TypeTableEntryIdFloat);5029 assert(instruction->base.value.type->id == ZigTypeIdFloat);
4703 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);5030 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);
4704 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");5031 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
4705}5032}
...@@ -4780,6 +5107,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4780,6 +5107,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4780 case IrInstructionIdFromBytes:5107 case IrInstructionIdFromBytes:
4781 case IrInstructionIdToBytes:5108 case IrInstructionIdToBytes:
4782 case IrInstructionIdEnumToInt:5109 case IrInstructionIdEnumToInt:
5110 case IrInstructionIdCheckRuntimeScope:
4783 zig_unreachable();5111 zig_unreachable();
47845112
4785 case IrInstructionIdReturn:5113 case IrInstructionIdReturn:
...@@ -4946,7 +5274,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4946,7 +5274,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4946 zig_unreachable();5274 zig_unreachable();
4947}5275}
49485276
4949static void ir_render(CodeGen *g, FnTableEntry *fn_entry) {5277static void ir_render(CodeGen *g, ZigFn *fn_entry) {
4950 assert(fn_entry);5278 assert(fn_entry);
49515279
4952 IrExecutable *executable = &fn_entry->analyzed_executable;5280 IrExecutable *executable = &fn_entry->analyzed_executable;
...@@ -4999,14 +5327,14 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar...@@ -4999,14 +5327,14 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
49995327
5000 LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr)));5328 LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr)));
5001 if (el_type == LLVMArrayTypeKind) {5329 if (el_type == LLVMArrayTypeKind) {
5002 TypeTableEntry *usize = g->builtin_types.entry_usize;5330 ZigType *usize = g->builtin_types.entry_usize;
5003 LLVMValueRef indices[] = {5331 LLVMValueRef indices[] = {
5004 LLVMConstNull(usize->type_ref),5332 LLVMConstNull(usize->type_ref),
5005 LLVMConstInt(usize->type_ref, index, false),5333 LLVMConstInt(usize->type_ref, index, false),
5006 };5334 };
5007 return LLVMConstInBoundsGEP(base_ptr, indices, 2);5335 return LLVMConstInBoundsGEP(base_ptr, indices, 2);
5008 } else if (el_type == LLVMStructTypeKind) {5336 } else if (el_type == LLVMStructTypeKind) {
5009 TypeTableEntry *u32 = g->builtin_types.entry_u32;5337 ZigType *u32 = g->builtin_types.entry_u32;
5010 LLVMValueRef indices[] = {5338 LLVMValueRef indices[] = {
5011 LLVMConstNull(u32->type_ref),5339 LLVMConstNull(u32->type_ref),
5012 LLVMConstInt(u32->type_ref, index, false),5340 LLVMConstInt(u32->type_ref, index, false),
...@@ -5022,7 +5350,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s...@@ -5022,7 +5350,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s
5022 ConstParent *parent = &struct_const_val->data.x_struct.parent;5350 ConstParent *parent = &struct_const_val->data.x_struct.parent;
5023 LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);5351 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;
5026 LLVMValueRef indices[] = {5354 LLVMValueRef indices[] = {
5027 LLVMConstNull(u32->type_ref),5355 LLVMConstNull(u32->type_ref),
5028 LLVMConstInt(u32->type_ref, field_index, false),5356 LLVMConstInt(u32->type_ref, field_index, false),
...@@ -5034,7 +5362,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un...@@ -5034,7 +5362,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
5034 ConstParent *parent = &union_const_val->data.x_union.parent;5362 ConstParent *parent = &union_const_val->data.x_union.parent;
5035 LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);5363 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;
5038 LLVMValueRef indices[] = {5366 LLVMValueRef indices[] = {
5039 LLVMConstNull(u32->type_ref),5367 LLVMConstNull(u32->type_ref),
5040 LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload5368 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...@@ -5052,59 +5380,59 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
5052 break;5380 break;
5053 }5381 }
50545382
5055 TypeTableEntry *type_entry = const_val->type;5383 ZigType *type_entry = const_val->type;
5056 assert(!type_entry->zero_bits);5384 assert(!type_entry->zero_bits);
5057 switch (type_entry->id) {5385 switch (type_entry->id) {
5058 case TypeTableEntryIdInvalid:5386 case ZigTypeIdInvalid:
5059 case TypeTableEntryIdMetaType:5387 case ZigTypeIdMetaType:
5060 case TypeTableEntryIdUnreachable:5388 case ZigTypeIdUnreachable:
5061 case TypeTableEntryIdComptimeFloat:5389 case ZigTypeIdComptimeFloat:
5062 case TypeTableEntryIdComptimeInt:5390 case ZigTypeIdComptimeInt:
5063 case TypeTableEntryIdUndefined:5391 case ZigTypeIdUndefined:
5064 case TypeTableEntryIdNull:5392 case ZigTypeIdNull:
5065 case TypeTableEntryIdErrorUnion:5393 case ZigTypeIdErrorUnion:
5066 case TypeTableEntryIdErrorSet:5394 case ZigTypeIdErrorSet:
5067 case TypeTableEntryIdNamespace:5395 case ZigTypeIdNamespace:
5068 case TypeTableEntryIdBlock:5396 case ZigTypeIdBlock:
5069 case TypeTableEntryIdBoundFn:5397 case ZigTypeIdBoundFn:
5070 case TypeTableEntryIdArgTuple:5398 case ZigTypeIdArgTuple:
5071 case TypeTableEntryIdVoid:5399 case ZigTypeIdVoid:
5072 case TypeTableEntryIdOpaque:5400 case ZigTypeIdOpaque:
5073 zig_unreachable();5401 zig_unreachable();
5074 case TypeTableEntryIdBool:5402 case ZigTypeIdBool:
5075 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);5403 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);
5076 case TypeTableEntryIdEnum:5404 case ZigTypeIdEnum:
5077 {5405 {
5078 assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);5406 assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);
5079 LLVMValueRef int_val = gen_const_val(g, const_val, "");5407 LLVMValueRef int_val = gen_const_val(g, const_val, "");
5080 return LLVMConstZExt(int_val, big_int_type_ref);5408 return LLVMConstZExt(int_val, big_int_type_ref);
5081 }5409 }
5082 case TypeTableEntryIdInt:5410 case ZigTypeIdInt:
5083 {5411 {
5084 LLVMValueRef int_val = gen_const_val(g, const_val, "");5412 LLVMValueRef int_val = gen_const_val(g, const_val, "");
5085 return LLVMConstZExt(int_val, big_int_type_ref);5413 return LLVMConstZExt(int_val, big_int_type_ref);
5086 }5414 }
5087 case TypeTableEntryIdFloat:5415 case ZigTypeIdFloat:
5088 {5416 {
5089 LLVMValueRef float_val = gen_const_val(g, const_val, "");5417 LLVMValueRef float_val = gen_const_val(g, const_val, "");
5090 LLVMValueRef int_val = LLVMConstFPToUI(float_val,5418 LLVMValueRef int_val = LLVMConstFPToUI(float_val,
5091 LLVMIntType((unsigned)type_entry->data.floating.bit_count));5419 LLVMIntType((unsigned)type_entry->data.floating.bit_count));
5092 return LLVMConstZExt(int_val, big_int_type_ref);5420 return LLVMConstZExt(int_val, big_int_type_ref);
5093 }5421 }
5094 case TypeTableEntryIdPointer:5422 case ZigTypeIdPointer:
5095 case TypeTableEntryIdFn:5423 case ZigTypeIdFn:
5096 case TypeTableEntryIdOptional:5424 case ZigTypeIdOptional:
5097 case TypeTableEntryIdPromise:5425 case ZigTypeIdPromise:
5098 {5426 {
5099 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");5427 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
5100 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);5428 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);
5101 return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);5429 return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);
5102 }5430 }
5103 case TypeTableEntryIdArray:5431 case ZigTypeIdArray:
5104 zig_panic("TODO bit pack an array");5432 zig_panic("TODO bit pack an array");
5105 case TypeTableEntryIdUnion:5433 case ZigTypeIdUnion:
5106 zig_panic("TODO bit pack a union");5434 zig_panic("TODO bit pack a union");
5107 case TypeTableEntryIdStruct:5435 case ZigTypeIdStruct:
5108 {5436 {
5109 assert(type_entry->data.structure.layout == ContainerLayoutPacked);5437 assert(type_entry->data.structure.layout == ContainerLayoutPacked);
5110 bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type5438 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...@@ -5137,7 +5465,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
51375465
5138// We have this because union constants can't be represented by the official union type,5466// We have this because union constants can't be represented by the official union type,
5139// and this property bubbles up in whatever aggregate type contains a union constant5467// 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) {
5141 return LLVMTypeOf(val) != type_entry->type_ref;5469 return LLVMTypeOf(val) != type_entry->type_ref;
5142}5470}
51435471
...@@ -5162,10 +5490,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5162,10 +5490,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5162 render_const_val_global(g, const_val, name);5490 render_const_val_global(g, const_val, name);
5163 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;5491 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
5164 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;5492 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);
5166 if (array_const_val->type->zero_bits) {5494 if (array_const_val->type->zero_bits) {
5167 // make this a null pointer5495 // make this a null pointer
5168 TypeTableEntry *usize = g->builtin_types.entry_usize;5496 ZigType *usize = g->builtin_types.entry_usize;
5169 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),5497 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
5170 const_val->type->type_ref);5498 const_val->type->type_ref);
5171 render_const_val_global(g, const_val, "");5499 render_const_val_global(g, const_val, "");
...@@ -5182,10 +5510,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5182,10 +5510,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5182 {5510 {
5183 render_const_val_global(g, const_val, name);5511 render_const_val_global(g, const_val, name);
5184 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;5512 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);
5186 if (struct_const_val->type->zero_bits) {5514 if (struct_const_val->type->zero_bits) {
5187 // make this a null pointer5515 // make this a null pointer
5188 TypeTableEntry *usize = g->builtin_types.entry_usize;5516 ZigType *usize = g->builtin_types.entry_usize;
5189 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),5517 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
5190 const_val->type->type_ref);5518 const_val->type->type_ref);
5191 render_const_val_global(g, const_val, "");5519 render_const_val_global(g, const_val, "");
...@@ -5205,7 +5533,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5205,7 +5533,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5205 {5533 {
5206 render_const_val_global(g, const_val, name);5534 render_const_val_global(g, const_val, name);
5207 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;5535 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;
5209 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, addr_value, false),5537 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, addr_value, false),
5210 const_val->type->type_ref);5538 const_val->type->type_ref);
5211 render_const_val_global(g, const_val, "");5539 render_const_val_global(g, const_val, "");
...@@ -5218,7 +5546,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5218,7 +5546,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5218}5546}
52195547
5220static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {5548static 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;
5222 assert(!type_entry->zero_bits);5550 assert(!type_entry->zero_bits);
52235551
5224 switch (const_val->special) {5552 switch (const_val->special) {
...@@ -5231,13 +5559,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5231,13 +5559,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5231 }5559 }
52325560
5233 switch (type_entry->id) {5561 switch (type_entry->id) {
5234 case TypeTableEntryIdInt:5562 case ZigTypeIdInt:
5235 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);5563 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);
5236 case TypeTableEntryIdErrorSet:5564 case ZigTypeIdErrorSet:
5237 assert(const_val->data.x_err_set != nullptr);5565 assert(const_val->data.x_err_set != nullptr);
5238 return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,5566 return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,
5239 const_val->data.x_err_set->value, false);5567 const_val->data.x_err_set->value, false);
5240 case TypeTableEntryIdFloat:5568 case ZigTypeIdFloat:
5241 switch (type_entry->data.floating.bit_count) {5569 switch (type_entry->data.floating.bit_count) {
5242 case 16:5570 case 16:
5243 return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16));5571 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...@@ -5257,15 +5585,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5257 default:5585 default:
5258 zig_unreachable();5586 zig_unreachable();
5259 }5587 }
5260 case TypeTableEntryIdBool:5588 case ZigTypeIdBool:
5261 if (const_val->data.x_bool) {5589 if (const_val->data.x_bool) {
5262 return LLVMConstAllOnes(LLVMInt1Type());5590 return LLVMConstAllOnes(LLVMInt1Type());
5263 } else {5591 } else {
5264 return LLVMConstNull(LLVMInt1Type());5592 return LLVMConstNull(LLVMInt1Type());
5265 }5593 }
5266 case TypeTableEntryIdOptional:5594 case ZigTypeIdOptional:
5267 {5595 {
5268 TypeTableEntry *child_type = type_entry->data.maybe.child_type;5596 ZigType *child_type = type_entry->data.maybe.child_type;
5269 if (child_type->zero_bits) {5597 if (child_type->zero_bits) {
5270 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);5598 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
5271 } else if (type_is_codegen_pointer(child_type)) {5599 } else if (type_is_codegen_pointer(child_type)) {
...@@ -5296,7 +5624,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5296,7 +5624,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5296 }5624 }
5297 }5625 }
5298 }5626 }
5299 case TypeTableEntryIdStruct:5627 case ZigTypeIdStruct:
5300 {5628 {
5301 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);5629 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
5302 size_t src_field_count = type_entry->data.structure.src_field_count;5630 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...@@ -5372,7 +5700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5372 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);5700 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);
5373 }5701 }
5374 }5702 }
5375 case TypeTableEntryIdArray:5703 case ZigTypeIdArray:
5376 {5704 {
5377 uint64_t len = type_entry->data.array.len;5705 uint64_t len = type_entry->data.array.len;
5378 if (const_val->data.x_array.special == ConstArraySpecialUndef) {5706 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
...@@ -5394,12 +5722,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5394,12 +5722,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5394 return LLVMConstArray(element_type_ref, values, (unsigned)len);5722 return LLVMConstArray(element_type_ref, values, (unsigned)len);
5395 }5723 }
5396 }5724 }
5397 case TypeTableEntryIdUnion:5725 case ZigTypeIdUnion:
5398 {5726 {
5399 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;5727 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
54005728
5401 if (type_entry->data.unionation.gen_field_count == 0) {5729 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) {
5403 return nullptr;5731 return nullptr;
5404 } else {5732 } else {
5405 return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref,5733 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...@@ -5458,18 +5786,18 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
54585786
5459 }5787 }
54605788
5461 case TypeTableEntryIdEnum:5789 case ZigTypeIdEnum:
5462 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);5790 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);
5463 case TypeTableEntryIdFn:5791 case ZigTypeIdFn:
5464 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);5792 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
5465 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);5793 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
5466 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);5794 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
5467 case TypeTableEntryIdPointer:5795 case ZigTypeIdPointer:
5468 return gen_const_val_ptr(g, const_val, name);5796 return gen_const_val_ptr(g, const_val, name);
5469 case TypeTableEntryIdErrorUnion:5797 case ZigTypeIdErrorUnion:
5470 {5798 {
5471 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;5799 ZigType *payload_type = type_entry->data.error_union.payload_type;
5472 TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;5800 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
5473 if (!type_has_bits(payload_type)) {5801 if (!type_has_bits(payload_type)) {
5474 assert(type_has_bits(err_set_type));5802 assert(type_has_bits(err_set_type));
5475 uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0;5803 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...@@ -5502,21 +5830,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5502 }5830 }
5503 }5831 }
5504 }5832 }
5505 case TypeTableEntryIdVoid:5833 case ZigTypeIdVoid:
5506 return nullptr;5834 return nullptr;
5507 case TypeTableEntryIdInvalid:5835 case ZigTypeIdInvalid:
5508 case TypeTableEntryIdMetaType:5836 case ZigTypeIdMetaType:
5509 case TypeTableEntryIdUnreachable:5837 case ZigTypeIdUnreachable:
5510 case TypeTableEntryIdComptimeFloat:5838 case ZigTypeIdComptimeFloat:
5511 case TypeTableEntryIdComptimeInt:5839 case ZigTypeIdComptimeInt:
5512 case TypeTableEntryIdUndefined:5840 case ZigTypeIdUndefined:
5513 case TypeTableEntryIdNull:5841 case ZigTypeIdNull:
5514 case TypeTableEntryIdNamespace:5842 case ZigTypeIdNamespace:
5515 case TypeTableEntryIdBlock:5843 case ZigTypeIdBlock:
5516 case TypeTableEntryIdBoundFn:5844 case ZigTypeIdBoundFn:
5517 case TypeTableEntryIdArgTuple:5845 case ZigTypeIdArgTuple:
5518 case TypeTableEntryIdOpaque:5846 case ZigTypeIdOpaque:
5519 case TypeTableEntryIdPromise:5847 case ZigTypeIdPromise:
5520 zig_unreachable();5848 zig_unreachable();
55215849
5522 }5850 }
...@@ -5559,9 +5887,9 @@ static void generate_error_name_table(CodeGen *g) {...@@ -5559,9 +5887,9 @@ static void generate_error_name_table(CodeGen *g) {
55595887
5560 assert(g->errors_by_index.length > 0);5888 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,
5563 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);5891 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
5566 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);5894 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
5567 values[0] = LLVMGetUndef(str_type->type_ref);5895 values[0] = LLVMGetUndef(str_type->type_ref);
...@@ -5597,7 +5925,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -5597,7 +5925,7 @@ static void generate_error_name_table(CodeGen *g) {
5597 LLVMSetAlignment(g->err_name_table, LLVMABIAlignmentOfType(g->target_data_ref, LLVMTypeOf(err_name_table_init)));5925 LLVMSetAlignment(g->err_name_table, LLVMABIAlignmentOfType(g->target_data_ref, LLVMTypeOf(err_name_table_init)));
5598}5926}
55995927
5600static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {5928static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
5601 IrExecutable *executable = &fn->analyzed_executable;5929 IrExecutable *executable = &fn->analyzed_executable;
5602 assert(executable->basic_block_list.length > 0);5930 assert(executable->basic_block_list.length > 0);
5603 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {5931 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) {...@@ -5608,8 +5936,8 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
5608 LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);5936 LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);
5609}5937}
56105938
5611static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,5939static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
5612 TypeTableEntry *type_entry)5940 ZigType *type_entry)
5613{5941{
5614 if (g->strip_debug_symbols) {5942 if (g->strip_debug_symbols) {
5615 return;5943 return;
...@@ -5630,33 +5958,16 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini...@@ -5630,33 +5958,16 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
5630 // TODO ^^ make an actual global variable5958 // TODO ^^ make an actual global variable
5631}5959}
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
5640static void ensure_cache_dir(CodeGen *g) {5961static void ensure_cache_dir(CodeGen *g) {
5641 int err;5962 int err;
5642 if ((err = os_make_path(g->cache_dir))) {5963 if ((err = os_make_path(&g->cache_dir))) {
5643 zig_panic("unable to make cache dir: %s", err_str(err));5964 zig_panic("unable to make cache dir: %s", err_str(err));
5644 }5965 }
5645}5966}
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
5657static void validate_inline_fns(CodeGen *g) {5968static void validate_inline_fns(CodeGen *g) {
5658 for (size_t i = 0; i < g->inline_fns.length; i += 1) {5969 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);
5660 LLVMValueRef fn_val = LLVMGetNamedFunction(g->module, fn_entry->llvm_name);5971 LLVMValueRef fn_val = LLVMGetNamedFunction(g->module, fn_entry->llvm_name);
5661 if (fn_val != nullptr) {5972 if (fn_val != nullptr) {
5662 add_node_error(g, fn_entry->proto_node, buf_sprintf("unable to inline function"));5973 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) {...@@ -5697,13 +6008,13 @@ static void do_code_gen(CodeGen *g) {
5697 // Generate module level variables6008 // Generate module level variables
5698 for (size_t i = 0; i < g->global_vars.length; i += 1) {6009 for (size_t i = 0; i < g->global_vars.length; i += 1) {
5699 TldVar *tld_var = g->global_vars.at(i);6010 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) {
5703 // Generate debug info for it but that's it.6014 // Generate debug info for it but that's it.
5704 ConstExprValue *const_val = var->value;6015 ConstExprValue *const_val = var->value;
5705 assert(const_val->special != ConstValSpecialRuntime);6016 assert(const_val->special != ConstValSpecialRuntime);
5706 TypeTableEntry *var_type = g->builtin_types.entry_f128;6017 ZigType *var_type = g->builtin_types.entry_f128;
5707 ConstExprValue coerced_value;6018 ConstExprValue coerced_value;
5708 coerced_value.special = ConstValSpecialStatic;6019 coerced_value.special = ConstValSpecialStatic;
5709 coerced_value.type = var_type;6020 coerced_value.type = var_type;
...@@ -5713,7 +6024,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5713,7 +6024,7 @@ static void do_code_gen(CodeGen *g) {
5713 continue;6024 continue;
5714 }6025 }
57156026
5716 if (var->value->type->id == TypeTableEntryIdComptimeInt) {6027 if (var->value->type->id == ZigTypeIdComptimeInt) {
5717 // Generate debug info for it but that's it.6028 // Generate debug info for it but that's it.
5718 ConstExprValue *const_val = var->value;6029 ConstExprValue *const_val = var->value;
5719 assert(const_val->special != ConstValSpecialRuntime);6030 assert(const_val->special != ConstValSpecialRuntime);
...@@ -5721,7 +6032,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5721,7 +6032,7 @@ static void do_code_gen(CodeGen *g) {
5721 if (bits_needed < 8) {6032 if (bits_needed < 8) {
5722 bits_needed = 8;6033 bits_needed = 8;
5723 }6034 }
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);
5725 LLVMValueRef init_val = bigint_to_llvm_const(var_type->type_ref, &const_val->data.x_bigint);6036 LLVMValueRef init_val = bigint_to_llvm_const(var_type->type_ref, &const_val->data.x_bigint);
5726 gen_global_var(g, var, init_val, var_type);6037 gen_global_var(g, var, init_val, var_type);
5727 continue;6038 continue;
...@@ -5761,7 +6072,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5761,7 +6072,7 @@ static void do_code_gen(CodeGen *g) {
5761 LLVMSetAlignment(global_value, var->align_bytes);6072 LLVMSetAlignment(global_value, var->align_bytes);
57626073
5763 // TODO debug info for function pointers6074 // 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) {
5765 gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);6076 gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);
5766 }6077 }
57676078
...@@ -5773,12 +6084,15 @@ static void do_code_gen(CodeGen *g) {...@@ -5773,12 +6084,15 @@ static void do_code_gen(CodeGen *g) {
57736084
5774 // Generate function definitions.6085 // Generate function definitions.
5775 for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {6086 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
5778 LLVMValueRef fn = fn_llvm_value(g, fn_table_entry);6092 LLVMValueRef fn = fn_llvm_value(g, fn_table_entry);
5779 g->cur_fn = fn_table_entry;6093 g->cur_fn = fn_table_entry;
5780 g->cur_fn_val = fn;6094 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;
5782 if (handle_is_ptr(return_type)) {6096 if (handle_is_ptr(return_type)) {
5783 g->cur_ret_ptr = LLVMGetParam(fn, 0);6097 g->cur_ret_ptr = LLVMGetParam(fn, 0);
5784 } else {6098 } else {
...@@ -5797,11 +6111,11 @@ static void do_code_gen(CodeGen *g) {...@@ -5797,11 +6111,11 @@ static void do_code_gen(CodeGen *g) {
5797 }6111 }
57986112
5799 // error return tracing setup6113 // 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;
5801 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;6115 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;
5802 LLVMValueRef err_ret_array_val = nullptr;6116 LLVMValueRef err_ret_array_val = nullptr;
5803 if (have_err_ret_trace_stack) {6117 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);
5805 err_ret_array_val = build_alloca(g, array_type, "error_return_trace_addresses", get_abi_alignment(g, array_type));6119 err_ret_array_val = build_alloca(g, array_type, "error_return_trace_addresses", get_abi_alignment(g, array_type));
5806 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));6120 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));
5807 } else {6121 } else {
...@@ -5812,14 +6126,14 @@ static void do_code_gen(CodeGen *g) {...@@ -5812,14 +6126,14 @@ static void do_code_gen(CodeGen *g) {
5812 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {6126 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
5813 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);6127 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
5814 LLVMValueRef *slot;6128 LLVMValueRef *slot;
5815 TypeTableEntry *slot_type = instruction->value.type;6129 ZigType *slot_type = instruction->value.type;
5816 if (instruction->id == IrInstructionIdCast) {6130 if (instruction->id == IrInstructionIdCast) {
5817 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;6131 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
5818 slot = &cast_instruction->tmp_ptr;6132 slot = &cast_instruction->tmp_ptr;
5819 } else if (instruction->id == IrInstructionIdRef) {6133 } else if (instruction->id == IrInstructionIdRef) {
5820 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;6134 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;
5821 slot = &ref_instruction->tmp_ptr;6135 slot = &ref_instruction->tmp_ptr;
5822 assert(instruction->value.type->id == TypeTableEntryIdPointer);6136 assert(instruction->value.type->id == ZigTypeIdPointer);
5823 slot_type = instruction->value.type->data.pointer.child_type;6137 slot_type = instruction->value.type->data.pointer.child_type;
5824 } else if (instruction->id == IrInstructionIdContainerInitList) {6138 } else if (instruction->id == IrInstructionIdContainerInitList) {
5825 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;6139 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
...@@ -5856,9 +6170,17 @@ static void do_code_gen(CodeGen *g) {...@@ -5856,9 +6170,17 @@ static void do_code_gen(CodeGen *g) {
58566170
5857 ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);6171 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
5859 // create debug variable declarations for variables and allocate all local variables6175 // 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;
5860 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {6182 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
5863 if (!type_has_bits(var->value->type)) {6185 if (!type_has_bits(var->value->type)) {
5864 continue;6186 continue;
...@@ -5875,9 +6197,12 @@ static void do_code_gen(CodeGen *g) {...@@ -5875,9 +6197,12 @@ static void do_code_gen(CodeGen *g) {
5875 buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),6197 buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
5876 var->value->type->di_type, !g->strip_debug_symbols, 0);6198 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);
5878 } else {6203 } else {
5879 assert(var->gen_arg_index != SIZE_MAX);6204 assert(var->gen_arg_index != SIZE_MAX);
5880 TypeTableEntry *gen_type;6205 ZigType *gen_type;
5881 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];6206 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];
58826207
5883 if (handle_is_ptr(var->value->type)) {6208 if (handle_is_ptr(var->value->type)) {
...@@ -5903,7 +6228,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5903,7 +6228,7 @@ static void do_code_gen(CodeGen *g) {
59036228
5904 // finishing error return trace setup. we have to do this after all the allocas.6229 // finishing error return trace setup. we have to do this after all the allocas.
5905 if (have_err_ret_trace_stack) {6230 if (have_err_ret_trace_stack) {
5906 TypeTableEntry *usize = g->builtin_types.entry_usize;6231 ZigType *usize = g->builtin_types.entry_usize;
5907 size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;6232 size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
5908 LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, "");6233 LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, "");
5909 gen_store_untyped(g, LLVMConstNull(usize->type_ref), index_field_ptr, 0, false);6234 gen_store_untyped(g, LLVMConstNull(usize->type_ref), index_field_ptr, 0, false);
...@@ -5911,14 +6236,14 @@ static void do_code_gen(CodeGen *g) {...@@ -5911,14 +6236,14 @@ static void do_code_gen(CodeGen *g) {
5911 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;6236 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
5912 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, "");6237 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;
5915 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;6240 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
5916 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");6241 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
5917 LLVMValueRef zero = LLVMConstNull(usize->type_ref);6242 LLVMValueRef zero = LLVMConstNull(usize->type_ref);
5918 LLVMValueRef indices[] = {zero, zero};6243 LLVMValueRef indices[] = {zero, zero};
5919 LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP(g->builder, err_ret_array_val,6244 LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP(g->builder, err_ret_array_val,
5920 indices, 2, "");6245 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);
5922 gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type);6247 gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type);
59236248
5924 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;6249 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) {...@@ -5926,33 +6251,14 @@ static void do_code_gen(CodeGen *g) {
5926 gen_store(g, LLVMConstInt(usize->type_ref, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false));6251 gen_store(g, LLVMConstInt(usize->type_ref, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false));
5927 }6252 }
59286253
5929 FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
5930
5931 // create debug variable declarations for parameters6254 // create debug variable declarations for parameters
5932 // rely on the first variables in the variable_list being parameters.6255 // rely on the first variables in the variable_list being parameters.
5933 size_t next_var_i = 0;6256 FnWalk fn_walk_init = {};
5934 for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) {6257 fn_walk_init.id = FnWalkIdInits;
5935 FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];6258 fn_walk_init.data.inits.fn = fn_table_entry;
5936 if (info->gen_index == SIZE_MAX)6259 fn_walk_init.data.inits.llvm_fn = fn;
5937 continue;6260 fn_walk_init.data.inits.gen_i = gen_i_init;
59386261 walk_function_params(g, fn_table_entry->type_entry, &fn_walk_init);
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 }
59566262
5957 ir_render(g, fn_table_entry);6263 ir_render(g, fn_table_entry);
59586264
...@@ -6007,7 +6313,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6007,7 +6313,7 @@ static void do_code_gen(CodeGen *g) {
6007 }6313 }
60086314
6009 Buf *output_path = buf_alloc();6315 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);
6011 ensure_cache_dir(g);6317 ensure_cache_dir(g);
60126318
6013 bool is_small = g->build_mode == BuildModeSmallRelease;6319 bool is_small = g->build_mode == BuildModeSmallRelease;
...@@ -6030,6 +6336,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6030,6 +6336,7 @@ static void do_code_gen(CodeGen *g) {
6030 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);6336 zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
6031 }6337 }
6032 validate_inline_fns(g);6338 validate_inline_fns(g);
6339 g->link_objects.append(output_path);
6033 break;6340 break;
60346341
6035 case EmitFileTypeLLVMIr:6342 case EmitFileTypeLLVMIr:
...@@ -6039,6 +6346,7 @@ static void do_code_gen(CodeGen *g) {...@@ -6039,6 +6346,7 @@ static void do_code_gen(CodeGen *g) {
6039 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);6346 zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
6040 }6347 }
6041 validate_inline_fns(g);6348 validate_inline_fns(g);
6349 g->link_objects.append(output_path);
6042 break;6350 break;
60436351
6044 default:6352 default:
...@@ -6080,51 +6388,51 @@ static const GlobalLinkageValue global_linkage_values[] = {...@@ -6080,51 +6388,51 @@ static const GlobalLinkageValue global_linkage_values[] = {
6080static void define_builtin_types(CodeGen *g) {6388static void define_builtin_types(CodeGen *g) {
6081 {6389 {
6082 // if this type is anywhere in the AST, we should never hit codegen.6390 // 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);
6084 buf_init_from_str(&entry->name, "(invalid)");6392 buf_init_from_str(&entry->name, "(invalid)");
6085 entry->zero_bits = true;6393 entry->zero_bits = true;
6086 g->builtin_types.entry_invalid = entry;6394 g->builtin_types.entry_invalid = entry;
6087 }6395 }
6088 {6396 {
6089 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNamespace);6397 ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
6090 buf_init_from_str(&entry->name, "(namespace)");6398 buf_init_from_str(&entry->name, "(namespace)");
6091 entry->zero_bits = true;6399 entry->zero_bits = true;
6092 g->builtin_types.entry_namespace = entry;6400 g->builtin_types.entry_namespace = entry;
6093 }6401 }
6094 {6402 {
6095 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBlock);6403 ZigType *entry = new_type_table_entry(ZigTypeIdBlock);
6096 buf_init_from_str(&entry->name, "(block)");6404 buf_init_from_str(&entry->name, "(block)");
6097 entry->zero_bits = true;6405 entry->zero_bits = true;
6098 g->builtin_types.entry_block = entry;6406 g->builtin_types.entry_block = entry;
6099 }6407 }
6100 {6408 {
6101 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat);6409 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
6102 buf_init_from_str(&entry->name, "comptime_float");6410 buf_init_from_str(&entry->name, "comptime_float");
6103 entry->zero_bits = true;6411 entry->zero_bits = true;
6104 g->builtin_types.entry_num_lit_float = entry;6412 g->builtin_types.entry_num_lit_float = entry;
6105 g->primitive_type_table.put(&entry->name, entry);6413 g->primitive_type_table.put(&entry->name, entry);
6106 }6414 }
6107 {6415 {
6108 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeInt);6416 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeInt);
6109 buf_init_from_str(&entry->name, "comptime_int");6417 buf_init_from_str(&entry->name, "comptime_int");
6110 entry->zero_bits = true;6418 entry->zero_bits = true;
6111 g->builtin_types.entry_num_lit_int = entry;6419 g->builtin_types.entry_num_lit_int = entry;
6112 g->primitive_type_table.put(&entry->name, entry);6420 g->primitive_type_table.put(&entry->name, entry);
6113 }6421 }
6114 {6422 {
6115 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefined);6423 ZigType *entry = new_type_table_entry(ZigTypeIdUndefined);
6116 buf_init_from_str(&entry->name, "(undefined)");6424 buf_init_from_str(&entry->name, "(undefined)");
6117 entry->zero_bits = true;6425 entry->zero_bits = true;
6118 g->builtin_types.entry_undef = entry;6426 g->builtin_types.entry_undef = entry;
6119 }6427 }
6120 {6428 {
6121 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNull);6429 ZigType *entry = new_type_table_entry(ZigTypeIdNull);
6122 buf_init_from_str(&entry->name, "(null)");6430 buf_init_from_str(&entry->name, "(null)");
6123 entry->zero_bits = true;6431 entry->zero_bits = true;
6124 g->builtin_types.entry_null = entry;6432 g->builtin_types.entry_null = entry;
6125 }6433 }
6126 {6434 {
6127 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple);6435 ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
6128 buf_init_from_str(&entry->name, "(args)");6436 buf_init_from_str(&entry->name, "(args)");
6129 entry->zero_bits = true;6437 entry->zero_bits = true;
6130 g->builtin_types.entry_arg_tuple = entry;6438 g->builtin_types.entry_arg_tuple = entry;
...@@ -6135,7 +6443,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6135,7 +6443,7 @@ static void define_builtin_types(CodeGen *g) {
6135 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);6443 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
6136 bool is_signed = info->is_signed;6444 bool is_signed = info->is_signed;
61376445
6138 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);6446 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
6139 entry->type_ref = LLVMIntType(size_in_bits);6447 entry->type_ref = LLVMIntType(size_in_bits);
61406448
6141 buf_init_from_str(&entry->name, info->name);6449 buf_init_from_str(&entry->name, info->name);
...@@ -6152,7 +6460,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6152,7 +6460,7 @@ static void define_builtin_types(CodeGen *g) {
6152 }6460 }
61536461
6154 {6462 {
6155 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBool);6463 ZigType *entry = new_type_table_entry(ZigTypeIdBool);
6156 entry->type_ref = LLVMInt1Type();6464 entry->type_ref = LLVMInt1Type();
6157 buf_init_from_str(&entry->name, "bool");6465 buf_init_from_str(&entry->name, "bool");
6158 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);6466 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) {...@@ -6166,7 +6474,7 @@ static void define_builtin_types(CodeGen *g) {
6166 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {6474 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
6167 bool is_signed = is_signed_list[sign_i];6475 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);
6170 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);6478 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
61716479
6172 const char u_or_i = is_signed ? 'i' : 'u';6480 const char u_or_i = is_signed ? 'i' : 'u';
...@@ -6193,8 +6501,8 @@ static void define_builtin_types(CodeGen *g) {...@@ -6193,8 +6501,8 @@ static void define_builtin_types(CodeGen *g) {
6193 const char *name,6501 const char *name,
6194 uint32_t bit_count,6502 uint32_t bit_count,
6195 LLVMTypeRef type_ref,6503 LLVMTypeRef type_ref,
6196 TypeTableEntry **field) {6504 ZigType **field) {
6197 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);6505 ZigType *entry = new_type_table_entry(ZigTypeIdFloat);
6198 entry->type_ref = type_ref;6506 entry->type_ref = type_ref;
6199 buf_init_from_str(&entry->name, name);6507 buf_init_from_str(&entry->name, name);
6200 entry->data.floating.bit_count = bit_count;6508 entry->data.floating.bit_count = bit_count;
...@@ -6213,7 +6521,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6213,7 +6521,7 @@ static void define_builtin_types(CodeGen *g) {
6213 add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);6521 add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);
62146522
6215 {6523 {
6216 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVoid);6524 ZigType *entry = new_type_table_entry(ZigTypeIdVoid);
6217 entry->type_ref = LLVMVoidType();6525 entry->type_ref = LLVMVoidType();
6218 entry->zero_bits = true;6526 entry->zero_bits = true;
6219 buf_init_from_str(&entry->name, "void");6527 buf_init_from_str(&entry->name, "void");
...@@ -6224,7 +6532,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6224,7 +6532,7 @@ static void define_builtin_types(CodeGen *g) {
6224 g->primitive_type_table.put(&entry->name, entry);6532 g->primitive_type_table.put(&entry->name, entry);
6225 }6533 }
6226 {6534 {
6227 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);6535 ZigType *entry = new_type_table_entry(ZigTypeIdUnreachable);
6228 entry->type_ref = LLVMVoidType();6536 entry->type_ref = LLVMVoidType();
6229 entry->zero_bits = true;6537 entry->zero_bits = true;
6230 buf_init_from_str(&entry->name, "noreturn");6538 buf_init_from_str(&entry->name, "noreturn");
...@@ -6233,7 +6541,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6233,7 +6541,7 @@ static void define_builtin_types(CodeGen *g) {
6233 g->primitive_type_table.put(&entry->name, entry);6541 g->primitive_type_table.put(&entry->name, entry);
6234 }6542 }
6235 {6543 {
6236 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMetaType);6544 ZigType *entry = new_type_table_entry(ZigTypeIdMetaType);
6237 buf_init_from_str(&entry->name, "type");6545 buf_init_from_str(&entry->name, "type");
6238 entry->zero_bits = true;6546 entry->zero_bits = true;
6239 g->builtin_types.entry_type = entry;6547 g->builtin_types.entry_type = entry;
...@@ -6255,7 +6563,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6255,7 +6563,7 @@ static void define_builtin_types(CodeGen *g) {
6255 }6563 }
62566564
6257 {6565 {
6258 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);6566 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
6259 buf_init_from_str(&entry->name, "error");6567 buf_init_from_str(&entry->name, "error");
6260 entry->data.error_set.err_count = UINT32_MAX;6568 entry->data.error_set.err_count = UINT32_MAX;
62616569
...@@ -6277,7 +6585,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6277,7 +6585,7 @@ static void define_builtin_types(CodeGen *g) {
6277 g->primitive_type_table.put(&entry->name, entry);6585 g->primitive_type_table.put(&entry->name, entry);
6278 }6586 }
6279 {6587 {
6280 TypeTableEntry *entry = get_promise_type(g, nullptr);6588 ZigType *entry = get_promise_type(g, nullptr);
6281 g->primitive_type_table.put(&entry->name, entry);6589 g->primitive_type_table.put(&entry->name, entry);
6282 }6590 }
62836591
...@@ -6530,7 +6838,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -6530,7 +6838,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
6530 buf_appendf(contents, "pub const TypeId = enum {\n");6838 buf_appendf(contents, "pub const TypeId = enum {\n");
6531 size_t field_count = type_id_len();6839 size_t field_count = type_id_len();
6532 for (size_t i = 0; i < field_count; i += 1) {6840 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);
6534 buf_appendf(contents, " %s,\n", type_id_name(id));6842 buf_appendf(contents, " %s,\n", type_id_name(id));
6535 }6843 }
6536 buf_appendf(contents, "};\n\n");6844 buf_appendf(contents, "};\n\n");
...@@ -6769,25 +7077,22 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6769,25 +7077,22 @@ static void define_builtin_compile_vars(CodeGen *g) {
67697077
6770 const char *builtin_zig_basename = "builtin.zig";7078 const char *builtin_zig_basename = "builtin.zig";
6771 Buf *builtin_zig_path = buf_alloc();7079 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
6774 Buf *contents = codegen_generate_builtin_source(g);7082 Buf *contents = codegen_generate_builtin_source(g);
6775 ensure_cache_dir(g);7083 ensure_cache_dir(g);
6776 os_write_file(builtin_zig_path, contents);7084 os_write_file(builtin_zig_path, contents);
67777085
6778 int err;7086 Buf *resolved_path = buf_alloc();
6779 Buf *abs_full_path = buf_alloc();7087 Buf *resolve_paths[] = {builtin_zig_path};
6780 if ((err = os_path_real(builtin_zig_path, abs_full_path))) {7088 *resolved_path = os_path_resolve(resolve_paths, 1);
6781 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));
6782 exit(1);
6783 }
67847089
6785 assert(g->root_package);7090 assert(g->root_package);
6786 assert(g->std_package);7091 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);
6788 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);7093 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
6789 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);7094 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);
6791 scan_import(g, g->compile_var_import);7096 scan_import(g, g->compile_var_import);
6792}7097}
67937098
...@@ -6943,17 +7248,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package...@@ -6943,17 +7248,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
6943 Buf *code_basename = buf_create_from_str(basename);7248 Buf *code_basename = buf_create_from_str(basename);
6944 Buf path_to_code_src = BUF_INIT;7249 Buf path_to_code_src = BUF_INIT;
6945 os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);7250 os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);
6946 Buf *abs_full_path = buf_alloc();7251
6947 int err;7252 Buf *resolve_paths[] = {&path_to_code_src};
6948 if ((err = os_path_real(&path_to_code_src, abs_full_path))) {7253 Buf *resolved_path = buf_alloc();
6949 zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));7254 *resolved_path = os_path_resolve(resolve_paths, 1);
6950 }
6951 Buf *import_code = buf_alloc();7255 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))) {
6953 zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));7258 zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
6954 }7259 }
69557260
6956 return add_source_file(g, package, abs_full_path, import_code);7261 return add_source_file(g, package, resolved_path, import_code);
6957}7262}
69587263
6959static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {7264static 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) {...@@ -6978,14 +7283,14 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
6978 exit(0);7283 exit(0);
6979 }7284 }
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,
6982 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);7287 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
6983 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);7288 ZigType *str_type = get_slice_type(g, u8_ptr_type);
6984 TypeTableEntry *fn_type = get_test_fn_type(g);7289 ZigType *fn_type = get_test_fn_type(g);
69857290
6986 const char *field_names[] = { "name", "func", };7291 const char *field_names[] = { "name", "func", };
6987 TypeTableEntry *field_types[] = { str_type, fn_type, };7292 ZigType *field_types[] = { str_type, fn_type, };
6988 TypeTableEntry *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);7293 ZigType *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);
69897294
6990 ConstExprValue *test_fn_array = create_const_vals(1);7295 ConstExprValue *test_fn_array = create_const_vals(1);
6991 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length);7296 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) {...@@ -6993,7 +7298,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
6993 test_fn_array->data.x_array.s_none.elements = create_const_vals(g->test_fns.length);7298 test_fn_array->data.x_array.s_none.elements = create_const_vals(g->test_fns.length);
69947299
6995 for (size_t i = 0; i < g->test_fns.length; i += 1) {7300 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
6998 ConstExprValue *this_val = &test_fn_array->data.x_array.s_none.elements[i];7303 ConstExprValue *this_val = &test_fn_array->data.x_array.s_none.elements[i];
6999 this_val->special = ConstValSpecialStatic;7304 this_val->special = ConstValSpecialStatic;
...@@ -7031,20 +7336,18 @@ static void gen_root_source(CodeGen *g) {...@@ -7031,20 +7336,18 @@ static void gen_root_source(CodeGen *g) {
7031 Buf *rel_full_path = buf_alloc();7336 Buf *rel_full_path = buf_alloc();
7032 os_path_join(&g->root_package->root_src_dir, &g->root_package->root_src_path, rel_full_path);7337 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();7339 Buf *resolved_path = buf_alloc();
7035 int err;7340 Buf *resolve_paths[] = {rel_full_path};
7036 if ((err = os_path_real(rel_full_path, abs_full_path))) {7341 *resolved_path = os_path_resolve(resolve_paths, 1);
7037 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
7038 exit(1);
7039 }
70407342
7041 Buf *source_code = buf_alloc();7343 Buf *source_code = buf_alloc();
7344 int err;
7042 if ((err = os_fetch_file_path(rel_full_path, source_code, true))) {7345 if ((err = os_fetch_file_path(rel_full_path, source_code, true))) {
7043 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));7346 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
7044 exit(1);7347 exit(1);
7045 }7348 }
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
7049 assert(g->root_out_name);7352 assert(g->root_out_name);
7050 assert(g->out_type != OutTypeUnknown);7353 assert(g->out_type != OutTypeUnknown);
...@@ -7129,66 +7432,66 @@ static const char *c_int_type_names[] = {...@@ -7129,66 +7432,66 @@ static const char *c_int_type_names[] = {
7129};7432};
71307433
7131struct GenH {7434struct GenH {
7132 ZigList<TypeTableEntry *> types_to_declare;7435 ZigList<ZigType *> types_to_declare;
7133};7436};
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) {
7136 if (type_entry->gen_h_loop_flag)7439 if (type_entry->gen_h_loop_flag)
7137 return;7440 return;
7138 type_entry->gen_h_loop_flag = true;7441 type_entry->gen_h_loop_flag = true;
71397442
7140 switch (type_entry->id) {7443 switch (type_entry->id) {
7141 case TypeTableEntryIdInvalid:7444 case ZigTypeIdInvalid:
7142 case TypeTableEntryIdMetaType:7445 case ZigTypeIdMetaType:
7143 case TypeTableEntryIdComptimeFloat:7446 case ZigTypeIdComptimeFloat:
7144 case TypeTableEntryIdComptimeInt:7447 case ZigTypeIdComptimeInt:
7145 case TypeTableEntryIdUndefined:7448 case ZigTypeIdUndefined:
7146 case TypeTableEntryIdNull:7449 case ZigTypeIdNull:
7147 case TypeTableEntryIdNamespace:7450 case ZigTypeIdNamespace:
7148 case TypeTableEntryIdBlock:7451 case ZigTypeIdBlock:
7149 case TypeTableEntryIdBoundFn:7452 case ZigTypeIdBoundFn:
7150 case TypeTableEntryIdArgTuple:7453 case ZigTypeIdArgTuple:
7151 case TypeTableEntryIdErrorUnion:7454 case ZigTypeIdErrorUnion:
7152 case TypeTableEntryIdErrorSet:7455 case ZigTypeIdErrorSet:
7153 case TypeTableEntryIdPromise:7456 case ZigTypeIdPromise:
7154 zig_unreachable();7457 zig_unreachable();
7155 case TypeTableEntryIdVoid:7458 case ZigTypeIdVoid:
7156 case TypeTableEntryIdUnreachable:7459 case ZigTypeIdUnreachable:
7157 case TypeTableEntryIdBool:7460 case ZigTypeIdBool:
7158 case TypeTableEntryIdInt:7461 case ZigTypeIdInt:
7159 case TypeTableEntryIdFloat:7462 case ZigTypeIdFloat:
7160 return;7463 return;
7161 case TypeTableEntryIdOpaque:7464 case ZigTypeIdOpaque:
7162 gen_h->types_to_declare.append(type_entry);7465 gen_h->types_to_declare.append(type_entry);
7163 return;7466 return;
7164 case TypeTableEntryIdStruct:7467 case ZigTypeIdStruct:
7165 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {7468 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
7166 TypeStructField *field = &type_entry->data.structure.fields[i];7469 TypeStructField *field = &type_entry->data.structure.fields[i];
7167 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);7470 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
7168 }7471 }
7169 gen_h->types_to_declare.append(type_entry);7472 gen_h->types_to_declare.append(type_entry);
7170 return;7473 return;
7171 case TypeTableEntryIdUnion:7474 case ZigTypeIdUnion:
7172 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {7475 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
7173 TypeUnionField *field = &type_entry->data.unionation.fields[i];7476 TypeUnionField *field = &type_entry->data.unionation.fields[i];
7174 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);7477 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
7175 }7478 }
7176 gen_h->types_to_declare.append(type_entry);7479 gen_h->types_to_declare.append(type_entry);
7177 return;7480 return;
7178 case TypeTableEntryIdEnum:7481 case ZigTypeIdEnum:
7179 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);7482 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
7180 gen_h->types_to_declare.append(type_entry);7483 gen_h->types_to_declare.append(type_entry);
7181 return;7484 return;
7182 case TypeTableEntryIdPointer:7485 case ZigTypeIdPointer:
7183 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);7486 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
7184 return;7487 return;
7185 case TypeTableEntryIdArray:7488 case ZigTypeIdArray:
7186 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);7489 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
7187 return;7490 return;
7188 case TypeTableEntryIdOptional:7491 case ZigTypeIdOptional:
7189 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);7492 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
7190 return;7493 return;
7191 case TypeTableEntryIdFn:7494 case ZigTypeIdFn:
7192 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {7495 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
7193 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);7496 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
7194 }7497 }
...@@ -7197,7 +7500,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry...@@ -7197,7 +7500,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
7197 }7500 }
7198}7501}
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) {
7201 assert(type_entry);7504 assert(type_entry);
72027505
7203 for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {7506 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...@@ -7228,17 +7531,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7228 prepend_c_type_to_decl_list(g, gen_h, type_entry);7531 prepend_c_type_to_decl_list(g, gen_h, type_entry);
72297532
7230 switch (type_entry->id) {7533 switch (type_entry->id) {
7231 case TypeTableEntryIdVoid:7534 case ZigTypeIdVoid:
7232 buf_init_from_str(out_buf, "void");7535 buf_init_from_str(out_buf, "void");
7233 break;7536 break;
7234 case TypeTableEntryIdBool:7537 case ZigTypeIdBool:
7235 buf_init_from_str(out_buf, "bool");7538 buf_init_from_str(out_buf, "bool");
7236 g->c_want_stdbool = true;7539 g->c_want_stdbool = true;
7237 break;7540 break;
7238 case TypeTableEntryIdUnreachable:7541 case ZigTypeIdUnreachable:
7239 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");7542 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");
7240 break;7543 break;
7241 case TypeTableEntryIdFloat:7544 case ZigTypeIdFloat:
7242 switch (type_entry->data.floating.bit_count) {7545 switch (type_entry->data.floating.bit_count) {
7243 case 32:7546 case 32:
7244 buf_init_from_str(out_buf, "float");7547 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...@@ -7256,17 +7559,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7256 zig_unreachable();7559 zig_unreachable();
7257 }7560 }
7258 break;7561 break;
7259 case TypeTableEntryIdInt:7562 case ZigTypeIdInt:
7260 g->c_want_stdint = true;7563 g->c_want_stdint = true;
7261 buf_resize(out_buf, 0);7564 buf_resize(out_buf, 0);
7262 buf_appendf(out_buf, "%sint%" PRIu32 "_t",7565 buf_appendf(out_buf, "%sint%" PRIu32 "_t",
7263 type_entry->data.integral.is_signed ? "" : "u",7566 type_entry->data.integral.is_signed ? "" : "u",
7264 type_entry->data.integral.bit_count);7567 type_entry->data.integral.bit_count);
7265 break;7568 break;
7266 case TypeTableEntryIdPointer:7569 case ZigTypeIdPointer:
7267 {7570 {
7268 Buf child_buf = BUF_INIT;7571 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;
7270 get_c_type(g, gen_h, child_type, &child_buf);7573 get_c_type(g, gen_h, child_type, &child_buf);
72717574
7272 const char *const_str = type_entry->data.pointer.is_const ? "const " : "";7575 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...@@ -7274,9 +7577,9 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7274 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));7577 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
7275 break;7578 break;
7276 }7579 }
7277 case TypeTableEntryIdOptional:7580 case ZigTypeIdOptional:
7278 {7581 {
7279 TypeTableEntry *child_type = type_entry->data.maybe.child_type;7582 ZigType *child_type = type_entry->data.maybe.child_type;
7280 if (child_type->zero_bits) {7583 if (child_type->zero_bits) {
7281 buf_init_from_str(out_buf, "bool");7584 buf_init_from_str(out_buf, "bool");
7282 return;7585 return;
...@@ -7286,28 +7589,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf...@@ -7286,28 +7589,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7286 zig_unreachable();7589 zig_unreachable();
7287 }7590 }
7288 }7591 }
7289 case TypeTableEntryIdStruct:7592 case ZigTypeIdStruct:
7290 case TypeTableEntryIdOpaque:7593 case ZigTypeIdOpaque:
7291 {7594 {
7292 buf_init_from_str(out_buf, "struct ");7595 buf_init_from_str(out_buf, "struct ");
7293 buf_append_buf(out_buf, &type_entry->name);7596 buf_append_buf(out_buf, &type_entry->name);
7294 return;7597 return;
7295 }7598 }
7296 case TypeTableEntryIdUnion:7599 case ZigTypeIdUnion:
7297 {7600 {
7298 buf_init_from_str(out_buf, "union ");7601 buf_init_from_str(out_buf, "union ");
7299 buf_append_buf(out_buf, &type_entry->name);7602 buf_append_buf(out_buf, &type_entry->name);
7300 return;7603 return;
7301 }7604 }
7302 case TypeTableEntryIdEnum:7605 case ZigTypeIdEnum:
7303 {7606 {
7304 buf_init_from_str(out_buf, "enum ");7607 buf_init_from_str(out_buf, "enum ");
7305 buf_append_buf(out_buf, &type_entry->name);7608 buf_append_buf(out_buf, &type_entry->name);
7306 return;7609 return;
7307 }7610 }
7308 case TypeTableEntryIdArray:7611 case ZigTypeIdArray:
7309 {7612 {
7310 TypeTableEntryArray *array_data = &type_entry->data.array;7613 ZigTypeArray *array_data = &type_entry->data.array;
73117614
7312 Buf *child_buf = buf_alloc();7615 Buf *child_buf = buf_alloc();
7313 get_c_type(g, gen_h, array_data->child_type, child_buf);7616 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...@@ -7316,21 +7619,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7316 buf_appendf(out_buf, "%s", buf_ptr(child_buf));7619 buf_appendf(out_buf, "%s", buf_ptr(child_buf));
7317 return;7620 return;
7318 }7621 }
7319 case TypeTableEntryIdErrorUnion:7622 case ZigTypeIdErrorUnion:
7320 case TypeTableEntryIdErrorSet:7623 case ZigTypeIdErrorSet:
7321 case TypeTableEntryIdFn:7624 case ZigTypeIdFn:
7322 zig_panic("TODO implement get_c_type for more types");7625 zig_panic("TODO implement get_c_type for more types");
7323 case TypeTableEntryIdInvalid:7626 case ZigTypeIdInvalid:
7324 case TypeTableEntryIdMetaType:7627 case ZigTypeIdMetaType:
7325 case TypeTableEntryIdBoundFn:7628 case ZigTypeIdBoundFn:
7326 case TypeTableEntryIdNamespace:7629 case ZigTypeIdNamespace:
7327 case TypeTableEntryIdBlock:7630 case ZigTypeIdBlock:
7328 case TypeTableEntryIdComptimeFloat:7631 case ZigTypeIdComptimeFloat:
7329 case TypeTableEntryIdComptimeInt:7632 case ZigTypeIdComptimeInt:
7330 case TypeTableEntryIdUndefined:7633 case ZigTypeIdUndefined:
7331 case TypeTableEntryIdNull:7634 case ZigTypeIdNull:
7332 case TypeTableEntryIdArgTuple:7635 case ZigTypeIdArgTuple:
7333 case TypeTableEntryIdPromise:7636 case ZigTypeIdPromise:
7334 zig_unreachable();7637 zig_unreachable();
7335 }7638 }
7336}7639}
...@@ -7395,7 +7698,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7395,7 +7698,7 @@ static void gen_h_file(CodeGen *g) {
7395 Buf h_buf = BUF_INIT;7698 Buf h_buf = BUF_INIT;
7396 buf_resize(&h_buf, 0);7699 buf_resize(&h_buf, 0);
7397 for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {7700 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
7400 if (fn_table_entry->export_list.length == 0)7703 if (fn_table_entry->export_list.length == 0)
7401 continue;7704 continue;
...@@ -7421,7 +7724,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7421,7 +7724,7 @@ static void gen_h_file(CodeGen *g) {
7421 const char *restrict_str = param_info->is_noalias ? "restrict" : "";7724 const char *restrict_str = param_info->is_noalias ? "restrict" : "";
7422 get_c_type(g, gen_h, param_info->type, &param_type_c);7725 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) {
7425 // Arrays decay to pointers7728 // Arrays decay to pointers
7426 buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),7729 buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),
7427 restrict_str, buf_ptr(param_name));7730 restrict_str, buf_ptr(param_name));
...@@ -7467,32 +7770,32 @@ static void gen_h_file(CodeGen *g) {...@@ -7467,32 +7770,32 @@ static void gen_h_file(CodeGen *g) {
7467 fprintf(out_h, "\n");7770 fprintf(out_h, "\n");
74687771
7469 for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {7772 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);
7471 switch (type_entry->id) {7774 switch (type_entry->id) {
7472 case TypeTableEntryIdInvalid:7775 case ZigTypeIdInvalid:
7473 case TypeTableEntryIdMetaType:7776 case ZigTypeIdMetaType:
7474 case TypeTableEntryIdVoid:7777 case ZigTypeIdVoid:
7475 case TypeTableEntryIdBool:7778 case ZigTypeIdBool:
7476 case TypeTableEntryIdUnreachable:7779 case ZigTypeIdUnreachable:
7477 case TypeTableEntryIdInt:7780 case ZigTypeIdInt:
7478 case TypeTableEntryIdFloat:7781 case ZigTypeIdFloat:
7479 case TypeTableEntryIdPointer:7782 case ZigTypeIdPointer:
7480 case TypeTableEntryIdComptimeFloat:7783 case ZigTypeIdComptimeFloat:
7481 case TypeTableEntryIdComptimeInt:7784 case ZigTypeIdComptimeInt:
7482 case TypeTableEntryIdArray:7785 case ZigTypeIdArray:
7483 case TypeTableEntryIdUndefined:7786 case ZigTypeIdUndefined:
7484 case TypeTableEntryIdNull:7787 case ZigTypeIdNull:
7485 case TypeTableEntryIdErrorUnion:7788 case ZigTypeIdErrorUnion:
7486 case TypeTableEntryIdErrorSet:7789 case ZigTypeIdErrorSet:
7487 case TypeTableEntryIdNamespace:7790 case ZigTypeIdNamespace:
7488 case TypeTableEntryIdBlock:7791 case ZigTypeIdBlock:
7489 case TypeTableEntryIdBoundFn:7792 case ZigTypeIdBoundFn:
7490 case TypeTableEntryIdArgTuple:7793 case ZigTypeIdArgTuple:
7491 case TypeTableEntryIdOptional:7794 case ZigTypeIdOptional:
7492 case TypeTableEntryIdFn:7795 case ZigTypeIdFn:
7493 case TypeTableEntryIdPromise:7796 case ZigTypeIdPromise:
7494 zig_unreachable();7797 zig_unreachable();
7495 case TypeTableEntryIdEnum:7798 case ZigTypeIdEnum:
7496 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {7799 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
7497 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));7800 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
7498 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {7801 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) {...@@ -7510,7 +7813,7 @@ static void gen_h_file(CodeGen *g) {
7510 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));7813 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
7511 }7814 }
7512 break;7815 break;
7513 case TypeTableEntryIdStruct:7816 case ZigTypeIdStruct:
7514 if (type_entry->data.structure.layout == ContainerLayoutExtern) {7817 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
7515 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));7818 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
7516 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {7819 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) {...@@ -7519,7 +7822,7 @@ static void gen_h_file(CodeGen *g) {
7519 Buf *type_name_buf = buf_alloc();7822 Buf *type_name_buf = buf_alloc();
7520 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);7823 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) {
7523 fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),7826 fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
7524 buf_ptr(struct_field->name),7827 buf_ptr(struct_field->name),
7525 struct_field->type_entry->data.array.len);7828 struct_field->type_entry->data.array.len);
...@@ -7533,7 +7836,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7533,7 +7836,7 @@ static void gen_h_file(CodeGen *g) {
7533 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));7836 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
7534 }7837 }
7535 break;7838 break;
7536 case TypeTableEntryIdUnion:7839 case ZigTypeIdUnion:
7537 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {7840 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
7538 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));7841 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
7539 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {7842 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) {...@@ -7548,7 +7851,7 @@ static void gen_h_file(CodeGen *g) {
7548 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));7851 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
7549 }7852 }
7550 break;7853 break;
7551 case TypeTableEntryIdOpaque:7854 case ZigTypeIdOpaque:
7552 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));7855 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
7553 break;7856 break;
7554 }7857 }
src/codegen.hpp+1-2
...@@ -47,7 +47,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script);...@@ -47,7 +47,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script);
47void codegen_set_test_filter(CodeGen *g, Buf *filter);47void codegen_set_test_filter(CodeGen *g, Buf *filter);
48void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);48void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);
49void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch);49void 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);
51void codegen_set_output_h_path(CodeGen *g, Buf *h_path);51void codegen_set_output_h_path(CodeGen *g, Buf *h_path);
52void codegen_add_time_event(CodeGen *g, const char *name);52void codegen_add_time_event(CodeGen *g, const char *name);
53void codegen_print_timing_report(CodeGen *g, FILE *f);53void codegen_print_timing_report(CodeGen *g, FILE *f);
...@@ -61,5 +61,4 @@ void codegen_translate_c(CodeGen *g, Buf *path);...@@ -61,5 +61,4 @@ void codegen_translate_c(CodeGen *g, Buf *path);
6161
62Buf *codegen_generate_builtin_source(CodeGen *g);62Buf *codegen_generate_builtin_source(CodeGen *g);
6363
64
65#endif64#endif
src/ir.cpp+1985-1726
...@@ -33,7 +33,7 @@ struct IrAnalyze {...@@ -33,7 +33,7 @@ struct IrAnalyze {
33 IrExecContext exec_context;33 IrExecContext exec_context;
34 size_t old_bb_index;34 size_t old_bb_index;
35 size_t instruction_index;35 size_t instruction_index;
36 TypeTableEntry *explicit_return_type;36 ZigType *explicit_return_type;
37 ZigList<IrInstruction *> src_implicit_return_type_list;37 ZigList<IrInstruction *> src_implicit_return_type_list;
38 IrBasicBlock *const_predecessor_bb;38 IrBasicBlock *const_predecessor_bb;
39};39};
...@@ -99,38 +99,38 @@ struct ConstCastOnly {...@@ -99,38 +99,38 @@ struct ConstCastOnly {
99};99};
100100
101struct ConstCastTypeMismatch {101struct ConstCastTypeMismatch {
102 TypeTableEntry *wanted_type;102 ZigType *wanted_type;
103 TypeTableEntry *actual_type;103 ZigType *actual_type;
104};104};
105105
106struct ConstCastOptionalMismatch {106struct ConstCastOptionalMismatch {
107 ConstCastOnly child;107 ConstCastOnly child;
108 TypeTableEntry *wanted_child;108 ZigType *wanted_child;
109 TypeTableEntry *actual_child;109 ZigType *actual_child;
110};110};
111111
112struct ConstCastPointerMismatch {112struct ConstCastPointerMismatch {
113 ConstCastOnly child;113 ConstCastOnly child;
114 TypeTableEntry *wanted_child;114 ZigType *wanted_child;
115 TypeTableEntry *actual_child;115 ZigType *actual_child;
116};116};
117117
118struct ConstCastSliceMismatch {118struct ConstCastSliceMismatch {
119 ConstCastOnly child;119 ConstCastOnly child;
120 TypeTableEntry *wanted_child;120 ZigType *wanted_child;
121 TypeTableEntry *actual_child;121 ZigType *actual_child;
122};122};
123123
124struct ConstCastErrUnionErrSetMismatch {124struct ConstCastErrUnionErrSetMismatch {
125 ConstCastOnly child;125 ConstCastOnly child;
126 TypeTableEntry *wanted_err_set;126 ZigType *wanted_err_set;
127 TypeTableEntry *actual_err_set;127 ZigType *actual_err_set;
128};128};
129129
130struct ConstCastErrUnionPayloadMismatch {130struct ConstCastErrUnionPayloadMismatch {
131 ConstCastOnly child;131 ConstCastOnly child;
132 TypeTableEntry *wanted_payload;132 ZigType *wanted_payload;
133 TypeTableEntry *actual_payload;133 ZigType *actual_payload;
134};134};
135135
136struct ConstCastErrSetMismatch {136struct ConstCastErrSetMismatch {
...@@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch {...@@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch {
139139
140static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);140static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
141static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);141static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);
142static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);142static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
143static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);143static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
144static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);144static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);
145static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);145static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
146static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,146static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
147 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);147 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
149static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);149static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
150static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);150static 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);151static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
152static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_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) {
155 assert(get_codegen_ptr_type(const_val->type) != nullptr);157 assert(get_codegen_ptr_type(const_val->type) != nullptr);
156 assert(const_val->special == ConstValSpecialStatic);158 assert(const_val->special == ConstValSpecialStatic);
157 ConstExprValue *result;159 ConstExprValue *result;
...@@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {...@@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
181 return result;183 return result;
182}184}
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
184static bool ir_should_inline(IrExecutable *exec, Scope *scope) {207static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
185 if (exec->is_inline)208 if (exec->is_inline)
186 return true;209 return true;
...@@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) {...@@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) {
213 return result;236 return result;
214}237}
215238
216static FnTableEntry *exec_fn_entry(IrExecutable *exec) {239static ZigFn *exec_fn_entry(IrExecutable *exec) {
217 return exec->fn_entry;240 return exec->fn_entry;
218}241}
219242
...@@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {...@@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {
230}253}
231254
232static bool instr_is_unreachable(IrInstruction *instruction) {255static 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;
234}257}
235258
236static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {259static 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)...@@ -254,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb)
254 ir_ref_bb(instruction->owner_bb);277 ir_ref_bb(instruction->owner_bb);
255}278}
256279
257static void ir_ref_var(VariableTableEntry *var) {280static void ir_ref_var(ZigVar *var) {
258 var->ref_count += 1;281 var->ref_count += 1;
259}282}
260283
...@@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) {...@@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) {
832 return IrInstructionIdSqrt;855 return IrInstructionIdSqrt;
833}856}
834857
858static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {
859 return IrInstructionIdCheckRuntimeScope;
860}
861
835template<typename T>862template<typename T>
836static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {863static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
837 T *special_instruction = allocate<T>(1);864 T *special_instruction = allocate<T>(1);
...@@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod...@@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod
851 return special_instruction;878 return special_instruction;
852}879}
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,
855 IrInstruction *value, CastOp cast_op)882 IrInstruction *value, CastOp cast_op)
856{883{
857 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);884 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...@@ -904,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
904}931}
905932
906static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,933static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,
907 TypeTableEntry *type_entry)934 ZigType *type_entry)
908{935{
909 assert(type_entry);936 assert(type_entry);
910 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);937 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...@@ -975,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s
975}1002}
9761003
977static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,1004static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
978 TypeTableEntry *type_entry)1005 ZigType *type_entry)
979{1006{
980 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);1007 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
981 const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;1008 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...@@ -985,14 +1012,14 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
985}1012}
9861013
987static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,1014static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
988 TypeTableEntry *type_entry)1015 ZigType *type_entry)
989{1016{
990 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);1017 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
991 ir_instruction_append(irb->current_basic_block, instruction);1018 ir_instruction_append(irb->current_basic_block, instruction);
992 return instruction;1019 return instruction;
993}1020}
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) {
996 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);1023 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
997 const_instruction->base.value.type = fn_entry->type_entry;1024 const_instruction->base.value.type = fn_entry->type_entry;
998 const_instruction->base.value.special = ConstValSpecialStatic;1025 const_instruction->base.value.special = ConstValSpecialStatic;
...@@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *...@@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
1002 return &const_instruction->base;1029 return &const_instruction->base;
1003}1030}
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) {
1006 IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry);1033 IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry);
1007 ir_instruction_append(irb->current_basic_block, instruction);1034 ir_instruction_append(irb->current_basic_block, instruction);
1008 return instruction;1035 return instruction;
...@@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode...@@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode
1035}1062}
10361063
1037static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,1064static 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)
1039{1066{
1040 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);1067 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1041 const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);1068 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...@@ -1087,15 +1114,22 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1087 return new_instruction;1114 return new_instruction;
1088}1115}
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{
1091 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);1120 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
1092 instruction->var = var;1121 instruction->var = var;
1122 instruction->crossed_fndef_scope = crossed_fndef_scope;
10931123
1094 ir_ref_var(var);1124 ir_ref_var(var);
10951125
1096 return &instruction->base;1126 return &instruction->base;
1097}1127}
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
1099static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,1133static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
1100 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)1134 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
1101{1135{
...@@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio...@@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio
1172}1206}
11731207
1174static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node,1208static 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,
1176 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,1210 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
1177 IrInstruction *new_stack)1211 IrInstruction *new_stack)
1178{1212{
...@@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc...@@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
1200}1234}
12011235
1202static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction,1236static 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,
1204 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,1238 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
1205 IrInstruction *new_stack)1239 IrInstruction *new_stack)
1206{1240{
...@@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop...@@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
1349}1383}
13501384
1351static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node,1385static 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)
1353{1387{
1354 IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node);1388 IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node);
1355 struct_init_instruction->struct_type = struct_type;1389 struct_init_instruction->struct_type = struct_type;
...@@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode...@@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode
1363}1397}
13641398
1365static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction,1399static 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)
1367{1401{
1368 IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope,1402 IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope,
1369 old_instruction->source_node, struct_type, field_count, fields);1403 old_instruction->source_node, struct_type, field_count, fields);
...@@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o...@@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o
1372}1406}
13731407
1374static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node,1408static 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)
1376{1410{
1377 IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node);1411 IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node);
1378 union_init_instruction->union_type = union_type;1412 union_init_instruction->union_type = union_type;
...@@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode...@@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode
1385}1419}
13861420
1387static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction,1421static 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)
1389{1423{
1390 IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope,1424 IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope,
1391 old_instruction->source_node, union_type, field, init_value);1425 old_instruction->source_node, union_type, field, init_value);
...@@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old...@@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old
1432}1466}
14331467
1434static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,1468static 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)
1436{1470{
1437 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);1471 IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);
1438 decl_var_instruction->base.value.special = ConstValSpecialStatic;1472 decl_var_instruction->base.value.special = ConstValSpecialStatic;
...@@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
1450}1484}
14511485
1452static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction,1486static 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)
1454{1488{
1455 IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,1489 IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,
1456 old_instruction->source_node, var, var_type, align_value, init_value);1490 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...@@ -1595,7 +1629,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
1595}1629}
15961630
1597static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list,1631static 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)
1599{1633{
1600 IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);1634 IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);
1601 instruction->input_list = input_list;1635 instruction->input_list = input_list;
...@@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source...@@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source
1619}1653}
16201654
1621static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list,1655static 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)
1623{1657{
1624 IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,1658 IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,
1625 old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects);1659 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...@@ -1946,7 +1980,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so
1946 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,1980 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
1947 IrInstruction *success_order_value, IrInstruction *failure_order_value,1981 IrInstruction *success_order_value, IrInstruction *failure_order_value,
1948 bool is_weak,1982 bool is_weak,
1949 TypeTableEntry *type, AtomicOrder success_order, AtomicOrder failure_order)1983 ZigType *type, AtomicOrder success_order, AtomicOrder failure_order)
1950{1984{
1951 IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node);1985 IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node);
1952 instruction->type_value = type_value;1986 instruction->type_value = type_value;
...@@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in...@@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in
22592293
2260static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,2294static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,
2261 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,2295 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)
2263{2297{
2264 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);2298 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);
2265 instruction->op = op;2299 instruction->op = op;
...@@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode...@@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
22792313
2280static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction,2314static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction,
2281 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,2315 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)
2283{2317{
2284 IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node,2318 IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node,
2285 op, type_value, op1, op2, result_ptr, result_ptr_type);2319 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...@@ -2974,6 +3008,17 @@ static IrInstruction *ir_build_sqrt(IrBuilder *irb, Scope *scope, AstNode *sourc
2974 return &instruction->base;3008 return &instruction->base;
2975}3009}
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
2977static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {3022static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
2978 results[ReturnKindUnconditional] = 0;3023 results[ReturnKindUnconditional] = 0;
2979 results[ReturnKindError] = 0;3024 results[ReturnKindError] = 0;
...@@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco...@@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
2999 case ScopeIdLoop:3044 case ScopeIdLoop:
3000 case ScopeIdSuspend:3045 case ScopeIdSuspend:
3001 case ScopeIdCompTime:3046 case ScopeIdCompTime:
3047 case ScopeIdRuntime:
3002 scope = scope->parent;3048 scope = scope->parent;
3003 continue;3049 continue;
3004 case ScopeIdDeferExpr:3050 case ScopeIdDeferExpr:
...@@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
3033 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;3079 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
3034 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);3080 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
3035 if (defer_expr_value != irb->codegen->invalid_instruction) {3081 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) {
3037 is_noreturn = true;3083 is_noreturn = true;
3038 } else {3084 } else {
3039 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));3085 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...@@ -3051,6 +3097,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
3051 case ScopeIdLoop:3097 case ScopeIdLoop:
3052 case ScopeIdSuspend:3098 case ScopeIdSuspend:
3053 case ScopeIdCompTime:3099 case ScopeIdCompTime:
3100 case ScopeIdRuntime:
3054 scope = scope->parent;3101 scope = scope->parent;
3055 continue;3102 continue;
3056 case ScopeIdDeferExpr:3103 case ScopeIdDeferExpr:
...@@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {...@@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
3098}3145}
30993146
3100static bool exec_is_async(IrExecutable *exec) {3147static bool exec_is_async(IrExecutable *exec) {
3101 FnTableEntry *fn_entry = exec_fn_entry(exec);3148 ZigFn *fn_entry = exec_fn_entry(exec);
3102 return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;3149 return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
3103}3150}
31043151
...@@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode...@@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode
3160static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {3207static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {
3161 assert(node->type == NodeTypeReturnExpr);3208 assert(node->type == NodeTypeReturnExpr);
31623209
3163 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);3210 ZigFn *fn_entry = exec_fn_entry(irb->exec);
3164 if (!fn_entry) {3211 if (!fn_entry) {
3165 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));3212 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
3166 return irb->codegen->invalid_instruction;3213 return irb->codegen->invalid_instruction;
...@@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3184 IrInstruction *return_value;3231 IrInstruction *return_value;
3185 if (expr_node) {3232 if (expr_node) {
3186 // Temporarily set this so that if we return a type it gets the name of the function3233 // 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;
3188 irb->exec->name_fn = exec_fn_entry(irb->exec);3235 irb->exec->name_fn = exec_fn_entry(irb->exec);
3189 return_value = ir_gen_node(irb, expr_node, scope);3236 return_value = ir_gen_node(irb, expr_node, scope);
3190 irb->exec->name_fn = prev_name_fn;3237 irb->exec->name_fn = prev_name_fn;
...@@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3280 zig_unreachable();3327 zig_unreachable();
3281}3328}
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,
3284 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,3331 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
3285 bool skip_name_check)3332 bool skip_name_check)
3286{3333{
3287 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);3334 ZigVar *variable_entry = allocate<ZigVar>(1);
3288 variable_entry->parent_scope = parent_scope;3335 variable_entry->parent_scope = parent_scope;
3289 variable_entry->shadowable = is_shadowable;3336 variable_entry->shadowable = is_shadowable;
3290 variable_entry->mem_slot_index = SIZE_MAX;3337 variable_entry->mem_slot_index = SIZE_MAX;
...@@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
3296 buf_init_from_buf(&variable_entry->name, name);3343 buf_init_from_buf(&variable_entry->name, name);
32973344
3298 if (!skip_name_check) {3345 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);
3300 if (existing_var && !existing_var->shadowable) {3347 if (existing_var && !existing_var->shadowable) {
3301 ErrorMsg *msg = add_node_error(codegen, node,3348 ErrorMsg *msg = add_node_error(codegen, node,
3302 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));3349 buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
3303 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));3350 add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
3304 variable_entry->value->type = codegen->builtin_types.entry_invalid;3351 variable_entry->value->type = codegen->builtin_types.entry_invalid;
3305 } else {3352 } else {
3306 TypeTableEntry *type = get_primitive_type(codegen, name);3353 ZigType *type = get_primitive_type(codegen, name);
3307 if (type != nullptr) {3354 if (type != nullptr) {
3308 add_node_error(codegen, node,3355 add_node_error(codegen, node,
3309 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));3356 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
...@@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
33373384
3338// Set name to nullptr to make the variable anonymous (not visible to programmer).3385// Set name to nullptr to make the variable anonymous (not visible to programmer).
3339// After you call this function var->child_scope has the variable in scope3386// 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,
3341 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)3388 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
3342{3389{
3343 bool is_underscored = name ? buf_eql_str(name, "_") : false;3390 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,
3345 (is_underscored ? nullptr : name), src_is_const, gen_is_const,3392 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
3346 (is_underscored ? true : is_shadowable), is_comptime, false);3393 (is_underscored ? true : is_shadowable), is_comptime, false);
3347 if (is_comptime != nullptr || gen_is_const) {3394 if (is_comptime != nullptr || gen_is_const) {
...@@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
3363 Scope *outer_block_scope = &scope_block->base;3410 Scope *outer_block_scope = &scope_block->base;
3364 Scope *child_scope = outer_block_scope;3411 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);
3367 if (fn_entry && fn_entry->child_scope == parent_scope) {3414 if (fn_entry && fn_entry->child_scope == parent_scope) {
3368 fn_entry->def_scope = scope_block;3415 fn_entry->def_scope = scope_block;
3369 }3416 }
...@@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3749 return &const_instruction->base;3796 return &const_instruction->base;
3750 }3797 }
37513798
3752 TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name);3799 ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name);
3753 if (primitive_type != nullptr) {3800 if (primitive_type != nullptr) {
3754 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);3801 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
3755 if (lval == LValPtr) {3802 if (lval == LValPtr) {
...@@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3759 }3806 }
3760 }3807 }
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);
3763 if (var) {3811 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);
3765 if (lval == LValPtr)3813 if (lval == LValPtr)
3766 return var_ptr;3814 return var_ptr;
3767 else3815 else
...@@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
49805028
4981 ir_set_cursor_at_end_and_append_block(irb, then_block);5029 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);
4984 if (then_expr_result == irb->codegen->invalid_instruction)5033 if (then_expr_result == irb->codegen->invalid_instruction)
4985 return then_expr_result;5034 return then_expr_result;
4986 IrBasicBlock *after_then_block = irb->current_basic_block;5035 IrBasicBlock *after_then_block = irb->current_basic_block;
...@@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
4990 ir_set_cursor_at_end_and_append_block(irb, else_block);5039 ir_set_cursor_at_end_and_append_block(irb, else_block);
4991 IrInstruction *else_expr_result;5040 IrInstruction *else_expr_result;
4992 if (else_node) {5041 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);
4994 if (else_expr_result == irb->codegen->invalid_instruction)5043 if (else_expr_result == irb->codegen->invalid_instruction)
4995 return else_expr_result;5044 return else_expr_result;
4996 } else {5045 } else {
...@@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
52175266
5218 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,5267 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
5219 ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);5268 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,
5221 is_const, is_const, is_shadowable, is_comptime);5270 is_const, is_const, is_shadowable, is_comptime);
5222 // we detect IrInstructionIdDeclVar in gen_block to make sure the next node5271 // we detect IrInstructionIdDeclVar in gen_block to make sure the next node
5223 // is inside var->child_scope5272 // is inside var->child_scope
...@@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5271 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);5320 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
5272 ir_build_br(irb, scope, node, cond_block, is_comptime);5321 ir_build_br(irb, scope, node, cond_block, is_comptime);
52735322
5323 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5274 Buf *var_symbol = node->data.while_expr.var_symbol;5324 Buf *var_symbol = node->data.while_expr.var_symbol;
5275 Buf *err_symbol = node->data.while_expr.err_symbol;5325 Buf *err_symbol = node->data.while_expr.err_symbol;
5276 if (err_symbol != nullptr) {5326 if (err_symbol != nullptr) {
...@@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
52785328
5279 Scope *payload_scope;5329 Scope *payload_scope;
5280 AstNode *symbol_node = node; // TODO make more accurate5330 AstNode *symbol_node = node; // TODO make more accurate
5281 VariableTableEntry *payload_var;5331 ZigVar *payload_var;
5282 if (var_symbol) {5332 if (var_symbol) {
5283 // TODO make it an error to write to payload variable5333 // 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,
5285 true, false, false, is_comptime);5335 true, false, false, is_comptime);
5286 payload_scope = payload_var->child_scope;5336 payload_scope = payload_var->child_scope;
5287 } else {5337 } else {
5288 payload_scope = scope;5338 payload_scope = subexpr_scope;
5289 }5339 }
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);
5291 if (err_val_ptr == irb->codegen->invalid_instruction)5341 if (err_val_ptr == irb->codegen->invalid_instruction)
5292 return err_val_ptr;5342 return err_val_ptr;
5293 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);5343 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...@@ -5342,7 +5392,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
53425392
5343 // TODO make it an error to write to error variable5393 // TODO make it an error to write to error variable
5344 AstNode *err_symbol_node = else_node; // TODO make more accurate5394 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,
5346 true, false, false, is_comptime);5396 true, false, false, is_comptime);
5347 Scope *err_scope = err_var->child_scope;5397 Scope *err_scope = err_var->child_scope;
5348 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);5398 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...@@ -5367,12 +5417,14 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5367 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);5417 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
5368 } else if (var_symbol != nullptr) {5418 } else if (var_symbol != nullptr) {
5369 ir_set_cursor_at_end_and_append_block(irb, cond_block);5419 ir_set_cursor_at_end_and_append_block(irb, cond_block);
5420 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5370 // TODO make it an error to write to payload variable5421 // TODO make it an error to write to payload variable
5371 AstNode *symbol_node = node; // TODO make more accurate5422 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,
5373 true, false, false, is_comptime);5425 true, false, false, is_comptime);
5374 Scope *child_scope = payload_var->child_scope;5426 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);
5376 if (maybe_val_ptr == irb->codegen->invalid_instruction)5428 if (maybe_val_ptr == irb->codegen->invalid_instruction)
5377 return maybe_val_ptr;5429 return maybe_val_ptr;
5378 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);5430 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...@@ -5456,7 +5508,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5456 ZigList<IrInstruction *> incoming_values = {0};5508 ZigList<IrInstruction *> incoming_values = {0};
5457 ZigList<IrBasicBlock *> incoming_blocks = {0};5509 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);
5460 loop_scope->break_block = end_block;5514 loop_scope->break_block = end_block;
5461 loop_scope->continue_block = continue_block;5515 loop_scope->continue_block = continue_block;
5462 loop_scope->is_comptime = is_comptime;5516 loop_scope->is_comptime = is_comptime;
...@@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
54745528
5475 if (continue_expr_node) {5529 if (continue_expr_node) {
5476 ir_set_cursor_at_end_and_append_block(irb, continue_block);5530 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);
5478 if (expr_result == irb->codegen->invalid_instruction)5532 if (expr_result == irb->codegen->invalid_instruction)
5479 return expr_result;5533 return expr_result;
5480 if (!instr_is_unreachable(expr_result))5534 if (!instr_is_unreachable(expr_result))
...@@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5485 if (else_node) {5539 if (else_node) {
5486 ir_set_cursor_at_end_and_append_block(irb, else_block);5540 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);
5489 if (else_result == irb->codegen->invalid_instruction)5543 if (else_result == irb->codegen->invalid_instruction)
5490 return else_result;5544 return else_result;
5491 if (!instr_is_unreachable(else_result))5545 if (!instr_is_unreachable(else_result))
...@@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
55395593
5540 // TODO make it an error to write to element variable or i variable.5594 // TODO make it an error to write to element variable or i variable.
5541 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;5595 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);
5543 Scope *child_scope = elem_var->child_scope;5597 Scope *child_scope = elem_var->child_scope;
55445598
5545 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);5599 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...@@ -5547,7 +5601,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5547 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);5601 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
55485602
5549 AstNode *index_var_source_node;5603 AstNode *index_var_source_node;
5550 VariableTableEntry *index_var;5604 ZigVar *index_var;
5551 if (index_node) {5605 if (index_node) {
5552 index_var_source_node = index_node;5606 index_var_source_node = index_node;
5553 Buf *index_var_name = index_node->data.symbol_expr.symbol;5607 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...@@ -5640,7 +5694,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
5640 if (!scope->parent)5694 if (!scope->parent)
5641 return ir_build_const_import(irb, scope, node, node->owner);5695 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);
5644 if (fn_entry)5698 if (fn_entry)
5645 return ir_build_const_fn(irb, scope, node, fn_entry);5699 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...@@ -5650,7 +5704,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
56505704
5651 if (scope->id == ScopeIdDecls) {5705 if (scope->id == ScopeIdDecls) {
5652 ScopeDecls *decls_scope = (ScopeDecls *)scope;5706 ScopeDecls *decls_scope = (ScopeDecls *)scope;
5653 TypeTableEntry *container_type = decls_scope->container_type;5707 ZigType *container_type = decls_scope->container_type;
5654 assert(container_type);5708 assert(container_type);
5655 return ir_build_const_type(irb, scope, node, container_type);5709 return ir_build_const_type(irb, scope, node, container_type);
5656 }5710 }
...@@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
57525806
5753 IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);5807 IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);
5754 IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length);5808 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);
5756 size_t return_count = 0;5810 size_t return_count = 0;
5757 bool is_volatile = node->data.asm_expr.is_volatile;5811 bool is_volatile = node->data.asm_expr.is_volatile;
5758 if (!is_volatile && node->data.asm_expr.output_list.length == 0) {5812 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...@@ -5776,7 +5830,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
5776 output_types[i] = return_type;5830 output_types[i] = return_type;
5777 } else {5831 } else {
5778 Buf *variable_name = asm_output->variable_name;5832 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);
5780 if (var) {5836 if (var) {
5781 output_vars[i] = var;5837 output_vars[i] = var;
5782 } else {5838 } else {
...@@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no...@@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
58285884
5829 ir_set_cursor_at_end_and_append_block(irb, then_block);5885 ir_set_cursor_at_end_and_append_block(irb, then_block);
58305886
5887 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5831 Scope *var_scope;5888 Scope *var_scope;
5832 if (var_symbol) {5889 if (var_symbol) {
5833 IrInstruction *var_type = nullptr;5890 IrInstruction *var_type = nullptr;
5834 bool is_shadowable = false;5891 bool is_shadowable = false;
5835 bool is_const = true;5892 bool is_const = true;
5836 VariableTableEntry *var = ir_create_var(irb, node, scope,5893 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5837 var_symbol, is_const, is_const, is_shadowable, is_comptime);5894 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);5896 IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_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);5897 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
5841 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);5898 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
5842 var_scope = var->child_scope;5899 var_scope = var->child_scope;
5843 } else {5900 } else {
5844 var_scope = scope;5901 var_scope = subexpr_scope;
5845 }5902 }
5846 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);5903 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
5847 if (then_expr_result == irb->codegen->invalid_instruction)5904 if (then_expr_result == irb->codegen->invalid_instruction)
...@@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no...@@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
5853 ir_set_cursor_at_end_and_append_block(irb, else_block);5910 ir_set_cursor_at_end_and_append_block(irb, else_block);
5854 IrInstruction *else_expr_result;5911 IrInstruction *else_expr_result;
5855 if (else_node) {5912 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);
5857 if (else_expr_result == irb->codegen->invalid_instruction)5914 if (else_expr_result == irb->codegen->invalid_instruction)
5858 return else_expr_result;5915 return else_expr_result;
5859 } else {5916 } else {
...@@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
59025959
5903 ir_set_cursor_at_end_and_append_block(irb, ok_block);5960 ir_set_cursor_at_end_and_append_block(irb, ok_block);
59045961
5962 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
5905 Scope *var_scope;5963 Scope *var_scope;
5906 if (var_symbol) {5964 if (var_symbol) {
5907 IrInstruction *var_type = nullptr;5965 IrInstruction *var_type = nullptr;
5908 bool is_shadowable = false;5966 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);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);
5910 VariableTableEntry *var = ir_create_var(irb, node, scope,5968 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5911 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);5969 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);5971 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_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);5972 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
5915 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);5973 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
5916 var_scope = var->child_scope;5974 var_scope = var->child_scope;
5917 } else {5975 } else {
5918 var_scope = scope;5976 var_scope = subexpr_scope;
5919 }5977 }
5920 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);5978 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
5921 if (then_expr_result == irb->codegen->invalid_instruction)5979 if (then_expr_result == irb->codegen->invalid_instruction)
...@@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
5933 IrInstruction *var_type = nullptr;5991 IrInstruction *var_type = nullptr;
5934 bool is_shadowable = false;5992 bool is_shadowable = false;
5935 bool is_const = true;5993 bool is_const = true;
5936 VariableTableEntry *var = ir_create_var(irb, node, scope,5994 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
5937 err_symbol, is_const, is_const, is_shadowable, is_comptime);5995 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);5997 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
5940 ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);5998 ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
5941 err_var_scope = var->child_scope;5999 err_var_scope = var->child_scope;
5942 } else {6000 } else {
5943 err_var_scope = scope;6001 err_var_scope = subexpr_scope;
5944 }6002 }
5945 else_expr_result = ir_gen_node(irb, else_node, err_var_scope);6003 else_expr_result = ir_gen_node(irb, else_node, err_var_scope);
5946 if (else_expr_result == irb->codegen->invalid_instruction)6004 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...@@ -5981,7 +6039,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
59816039
5982 bool is_shadowable = false;6040 bool is_shadowable = false;
5983 bool is_const = true;6041 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,
5985 var_name, is_const, is_const, is_shadowable, var_is_comptime);6043 var_name, is_const, is_const, is_shadowable, var_is_comptime);
5986 child_scope = var->child_scope;6044 child_scope = var->child_scope;
5987 IrInstruction *var_value;6045 IrInstruction *var_value;
...@@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
6037 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};6095 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
60386096
6039 // First do the else and the ranges6097 // First do the else and the ranges
6098 Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
6040 Scope *comptime_scope = create_comptime_scope(node, scope);6099 Scope *comptime_scope = create_comptime_scope(node, scope);
6041 AstNode *else_prong = nullptr;6100 AstNode *else_prong = nullptr;
6042 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {6101 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 *...@@ -6054,7 +6113,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
60546113
6055 IrBasicBlock *prev_block = irb->current_basic_block;6114 IrBasicBlock *prev_block = irb->current_basic_block;
6056 ir_set_cursor_at_end_and_append_block(irb, else_block);6115 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,
6058 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))6117 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
6059 {6118 {
6060 return irb->codegen->invalid_instruction;6119 return irb->codegen->invalid_instruction;
...@@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
6121 range_block_no, is_comptime));6180 range_block_no, is_comptime));
61226181
6123 ir_set_cursor_at_end_and_append_block(irb, range_block_yes);6182 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,
6125 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))6184 is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
6126 {6185 {
6127 return irb->codegen->invalid_instruction;6186 return irb->codegen->invalid_instruction;
...@@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
61656224
6166 IrBasicBlock *prev_block = irb->current_basic_block;6225 IrBasicBlock *prev_block = irb->current_basic_block;
6167 ir_set_cursor_at_end_and_append_block(irb, prong_block);6226 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,
6169 is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values))6228 is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values))
6170 {6229 {
6171 return irb->codegen->invalid_instruction;6230 return irb->codegen->invalid_instruction;
...@@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
6308 // * defer expression scope => error, cannot break out of defer expression6367 // * defer expression scope => error, cannot break out of defer expression
6309 // * loop scope => OK6368 // * loop scope => OK
63106369
6370 ZigList<ScopeRuntime *> runtime_scopes = {};
6371
6311 Scope *search_scope = continue_scope;6372 Scope *search_scope = continue_scope;
6312 ScopeLoop *loop_scope;6373 ScopeLoop *loop_scope;
6313 for (;;) {6374 for (;;) {
...@@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
6330 loop_scope = this_loop_scope;6391 loop_scope = this_loop_scope;
6331 break;6392 break;
6332 }6393 }
6394 } else if (search_scope->id == ScopeIdRuntime) {
6395 ScopeRuntime *scope_runtime = (ScopeRuntime *)search_scope;
6396 runtime_scopes.append(scope_runtime);
6333 }6397 }
6334 search_scope = search_scope->parent;6398 search_scope = search_scope->parent;
6335 }6399 }
...@@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
6341 is_comptime = loop_scope->is_comptime;6405 is_comptime = loop_scope->is_comptime;
6342 }6406 }
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
6344 IrBasicBlock *dest_block = loop_scope->continue_block;6413 IrBasicBlock *dest_block = loop_scope->continue_block;
6345 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);6414 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
6346 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));6415 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...@@ -6435,7 +6504,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
6435 Buf *var_name = var_node->data.symbol_expr.symbol;6504 Buf *var_name = var_node->data.symbol_expr.symbol;
6436 bool is_const = true;6505 bool is_const = true;
6437 bool is_shadowable = false;6506 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,
6439 is_const, is_const, is_shadowable, is_comptime);6508 is_const, is_const, is_shadowable, is_comptime);
6440 err_scope = var->child_scope;6509 err_scope = var->child_scope;
6441 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);6510 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,...@@ -6507,7 +6576,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
6507 init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope);6576 init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope);
65086577
6509 ContainerLayout layout = node->data.container_decl.layout;6578 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,
6511 kind, node, buf_ptr(name), layout);6580 kind, node, buf_ptr(name), layout);
6512 ScopeDecls *child_scope = get_container_scope(container_type);6581 ScopeDecls *child_scope = get_container_scope(container_type);
65136582
...@@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,...@@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
6527}6596}
65286597
6529// errors should be populated with set1's values6598// errors should be populated with set1's values
6530static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) {6599static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {
6531 assert(set1->id == TypeTableEntryIdErrorSet);6600 assert(set1->id == ZigTypeIdErrorSet);
6532 assert(set2->id == TypeTableEntryIdErrorSet);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);
6535 buf_resize(&err_set_type->name, 0);6604 buf_resize(&err_set_type->name, 0);
6536 buf_appendf(&err_set_type->name, "error{");6605 buf_appendf(&err_set_type->name, "error{");
65376606
...@@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors,...@@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors,
65806649
6581}6650}
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,
6584 ErrorTableEntry *err_entry)6653 ErrorTableEntry *err_entry)
6585{6654{
6586 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);6655 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
6587 buf_resize(&err_set_type->name, 0);6656 buf_resize(&err_set_type->name, 0);
6588 buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));6657 buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));
6589 err_set_type->is_copyable = true;6658 err_set_type->is_copyable = true;
...@@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A...@@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
6605 uint32_t err_count = node->data.err_set_decl.decls.length;6674 uint32_t err_count = node->data.err_set_decl.decls.length;
66066675
6607 Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);6676 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);
6609 buf_init_from_buf(&err_set_type->name, type_name);6678 buf_init_from_buf(&err_set_type->name, type_name);
6610 err_set_type->is_copyable = true;6679 err_set_type->is_copyable = true;
6611 err_set_type->data.error_set.err_count = err_count;6680 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...@@ -6854,7 +6923,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
6854 if (target_inst == irb->codegen->invalid_instruction)6923 if (target_inst == irb->codegen->invalid_instruction)
6855 return irb->codegen->invalid_instruction;6924 return irb->codegen->invalid_instruction;
68566925
6857 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);6926 ZigFn *fn_entry = exec_fn_entry(irb->exec);
6858 if (!fn_entry) {6927 if (!fn_entry) {
6859 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));6928 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
6860 return irb->codegen->invalid_instruction;6929 return irb->codegen->invalid_instruction;
...@@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
6917 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b0016986 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
6918 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b0106987 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,
6921 false, false, true, const_bool_false);6990 false, false, true, const_bool_false);
6922 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);6991 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
6923 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);6992 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...@@ -7031,7 +7100,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
7031static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {7100static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
7032 assert(node->type == NodeTypeSuspend);7101 assert(node->type == NodeTypeSuspend);
70337102
7034 FnTableEntry *fn_entry = exec_fn_entry(irb->exec);7103 ZigFn *fn_entry = exec_fn_entry(irb->exec);
7035 if (!fn_entry) {7104 if (!fn_entry) {
7036 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));7105 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
7037 return irb->codegen->invalid_instruction;7106 return irb->codegen->invalid_instruction;
...@@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7320 // Entry block gets a reference because we enter it to begin.7389 // Entry block gets a reference because we enter it to begin.
7321 ir_ref_bb(irb->current_basic_block);7390 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);
7324 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;7393 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
7325 IrInstruction *coro_id;7394 IrInstruction *coro_id;
7326 IrInstruction *u8_ptr_type;7395 IrInstruction *u8_ptr_type;
7327 IrInstruction *const_bool_false;7396 IrInstruction *const_bool_false;
7328 IrInstruction *coro_promise_ptr;7397 IrInstruction *coro_promise_ptr;
7329 IrInstruction *err_ret_trace_ptr;7398 IrInstruction *err_ret_trace_ptr;
7330 TypeTableEntry *return_type;7399 ZigType *return_type;
7331 Buf *result_ptr_field_name;7400 Buf *result_ptr_field_name;
7332 VariableTableEntry *coro_size_var;7401 ZigVar *coro_size_var;
7333 if (is_async) {7402 if (is_async) {
7334 // create the coro promise7403 // create the coro promise
7335 Scope *coro_scope = create_coro_prelude_scope(node, scope);7404 Scope *coro_scope = create_coro_prelude_scope(node, scope);
7336 const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);7405 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
7339 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;7408 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
7340 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);7409 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);
7342 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);7411 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
7343 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa7412 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
7344 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);7413 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
7345 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);7414 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);
7348 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);7417 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
7349 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,7418 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
7350 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));7419 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...@@ -7531,7 +7600,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7531 return true;7600 return true;
7532}7601}
75337602
7534bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {7603bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
7535 assert(fn_entry);7604 assert(fn_entry);
75367605
7537 IrExecutable *ir_executable = &fn_entry->ir_executable;7606 IrExecutable *ir_executable = &fn_entry->ir_executable;
...@@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,...@@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
7566 return ir_add_error_node(ira, source_instruction->source_node, msg);7635 return ir_add_error_node(ira, source_instruction->source_node, msg);
7567}7636}
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
7569static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {7651static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
7570 IrBasicBlock *bb = exec->basic_block_list.at(0);7652 IrBasicBlock *bb = exec->basic_block_list.at(0);
7571 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {7653 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...@@ -7596,17 +7678,17 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
7596 return true;7678 return true;
7597}7679}
75987680
7599static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) {7681static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {
7600 return ((num_lit_type->id == TypeTableEntryIdComptimeFloat &&7682 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
7601 (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) ||7683 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
7602 (num_lit_type->id == TypeTableEntryIdComptimeInt &&7684 (num_lit_type->id == ZigTypeIdComptimeInt &&
7603 (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt)));7685 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
7604}7686}
76057687
7606static bool float_has_fraction(ConstExprValue *const_val) {7688static bool float_has_fraction(ConstExprValue *const_val) {
7607 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7689 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7608 return bigfloat_has_fraction(&const_val->data.x_bigfloat);7690 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) {
7610 switch (const_val->type->data.floating.bit_count) {7692 switch (const_val->type->data.floating.bit_count) {
7611 case 16:7693 case 16:
7612 {7694 {
...@@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {...@@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {
7632}7714}
76337715
7634static void float_append_buf(Buf *buf, ConstExprValue *const_val) {7716static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
7635 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7717 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7636 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);7718 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) {
7638 switch (const_val->type->data.floating.bit_count) {7720 switch (const_val->type->data.floating.bit_count) {
7639 case 16:7721 case 16:
7640 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));7722 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) {...@@ -7670,9 +7752,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
7670}7752}
76717753
7672static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {7754static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
7673 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7755 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7674 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);7756 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) {
7676 switch (const_val->type->data.floating.bit_count) {7758 switch (const_val->type->data.floating.bit_count) {
7677 case 16:7759 case 16:
7678 {7760 {
...@@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {...@@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
7717}7799}
77187800
7719static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {7801static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
7720 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7802 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7721 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);7803 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) {
7723 switch (dest_val->type->data.floating.bit_count) {7805 switch (dest_val->type->data.floating.bit_count) {
7724 case 16:7806 case 16:
7725 dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);7807 dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);
...@@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {...@@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
7742}7824}
77437825
7744static void float_init_f16(ConstExprValue *dest_val, float16_t x) {7826static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
7745 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7827 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7746 bigfloat_init_16(&dest_val->data.x_bigfloat, x);7828 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) {
7748 switch (dest_val->type->data.floating.bit_count) {7830 switch (dest_val->type->data.floating.bit_count) {
7749 case 16:7831 case 16:
7750 dest_val->data.x_f16 = x;7832 dest_val->data.x_f16 = x;
...@@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {...@@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
7767}7849}
77687850
7769static void float_init_f32(ConstExprValue *dest_val, float x) {7851static void float_init_f32(ConstExprValue *dest_val, float x) {
7770 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7852 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7771 bigfloat_init_32(&dest_val->data.x_bigfloat, x);7853 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) {
7773 switch (dest_val->type->data.floating.bit_count) {7855 switch (dest_val->type->data.floating.bit_count) {
7774 case 16:7856 case 16:
7775 dest_val->data.x_f16 = zig_double_to_f16(x);7857 dest_val->data.x_f16 = zig_double_to_f16(x);
...@@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {...@@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
7796}7878}
77977879
7798static void float_init_f64(ConstExprValue *dest_val, double x) {7880static void float_init_f64(ConstExprValue *dest_val, double x) {
7799 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7881 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7800 bigfloat_init_64(&dest_val->data.x_bigfloat, x);7882 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) {
7802 switch (dest_val->type->data.floating.bit_count) {7884 switch (dest_val->type->data.floating.bit_count) {
7803 case 16:7885 case 16:
7804 dest_val->data.x_f16 = zig_double_to_f16(x);7886 dest_val->data.x_f16 = zig_double_to_f16(x);
...@@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {...@@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
7825}7907}
78267908
7827static void float_init_f128(ConstExprValue *dest_val, float128_t x) {7909static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
7828 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7910 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7829 bigfloat_init_128(&dest_val->data.x_bigfloat, x);7911 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) {
7831 switch (dest_val->type->data.floating.bit_count) {7913 switch (dest_val->type->data.floating.bit_count) {
7832 case 16:7914 case 16:
7833 dest_val->data.x_f16 = f128M_to_f16(&x);7915 dest_val->data.x_f16 = f128M_to_f16(&x);
...@@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {...@@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
7858}7940}
78597941
7860static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {7942static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
7861 if (src_val->type->id == TypeTableEntryIdComptimeFloat) {7943 if (src_val->type->id == ZigTypeIdComptimeFloat) {
7862 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);7944 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) {
7864 switch (src_val->type->data.floating.bit_count) {7946 switch (src_val->type->data.floating.bit_count) {
7865 case 16:7947 case 16:
7866 float_init_f16(dest_val, src_val->data.x_f16);7948 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)...@@ -7884,9 +7966,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
78847966
7885static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {7967static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
7886 assert(op1->type == op2->type);7968 assert(op1->type == op2->type);
7887 if (op1->type->id == TypeTableEntryIdComptimeFloat) {7969 if (op1->type->id == ZigTypeIdComptimeFloat) {
7888 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);7970 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) {
7890 switch (op1->type->data.floating.bit_count) {7972 switch (op1->type->data.floating.bit_count) {
7891 case 16:7973 case 16:
7892 if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {7974 if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {
...@@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {...@@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
7929}8011}
79308012
7931static Cmp float_cmp_zero(ConstExprValue *op) {8013static Cmp float_cmp_zero(ConstExprValue *op) {
7932 if (op->type->id == TypeTableEntryIdComptimeFloat) {8014 if (op->type->id == ZigTypeIdComptimeFloat) {
7933 return bigfloat_cmp_zero(&op->data.x_bigfloat);8015 return bigfloat_cmp_zero(&op->data.x_bigfloat);
7934 } else if (op->type->id == TypeTableEntryIdFloat) {8016 } else if (op->type->id == ZigTypeIdFloat) {
7935 switch (op->type->data.floating.bit_count) {8017 switch (op->type->data.floating.bit_count) {
7936 case 16:8018 case 16:
7937 {8019 {
...@@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {...@@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
7981static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8063static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
7982 assert(op1->type == op2->type);8064 assert(op1->type == op2->type);
7983 out_val->type = op1->type;8065 out_val->type = op1->type;
7984 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8066 if (op1->type->id == ZigTypeIdComptimeFloat) {
7985 bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8067 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) {
7987 switch (op1->type->data.floating.bit_count) {8069 switch (op1->type->data.floating.bit_count) {
7988 case 16:8070 case 16:
7989 out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16);8071 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...@@ -8008,9 +8090,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8008static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8090static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8009 assert(op1->type == op2->type);8091 assert(op1->type == op2->type);
8010 out_val->type = op1->type;8092 out_val->type = op1->type;
8011 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8093 if (op1->type->id == ZigTypeIdComptimeFloat) {
8012 bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8094 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) {
8014 switch (op1->type->data.floating.bit_count) {8096 switch (op1->type->data.floating.bit_count) {
8015 case 16:8097 case 16:
8016 out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16);8098 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...@@ -8035,9 +8117,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8035static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8117static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8036 assert(op1->type == op2->type);8118 assert(op1->type == op2->type);
8037 out_val->type = op1->type;8119 out_val->type = op1->type;
8038 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8120 if (op1->type->id == ZigTypeIdComptimeFloat) {
8039 bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8121 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) {
8041 switch (op1->type->data.floating.bit_count) {8123 switch (op1->type->data.floating.bit_count) {
8042 case 16:8124 case 16:
8043 out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16);8125 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...@@ -8062,9 +8144,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8062static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8144static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8063 assert(op1->type == op2->type);8145 assert(op1->type == op2->type);
8064 out_val->type = op1->type;8146 out_val->type = op1->type;
8065 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8147 if (op1->type->id == ZigTypeIdComptimeFloat) {
8066 bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8148 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) {
8068 switch (op1->type->data.floating.bit_count) {8150 switch (op1->type->data.floating.bit_count) {
8069 case 16:8151 case 16:
8070 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8152 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...@@ -8089,9 +8171,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8089static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8171static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8090 assert(op1->type == op2->type);8172 assert(op1->type == op2->type);
8091 out_val->type = op1->type;8173 out_val->type = op1->type;
8092 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8174 if (op1->type->id == ZigTypeIdComptimeFloat) {
8093 bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8175 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) {
8095 switch (op1->type->data.floating.bit_count) {8177 switch (op1->type->data.floating.bit_count) {
8096 case 16:8178 case 16:
8097 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8179 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...@@ -8118,9 +8200,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
8118static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8200static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8119 assert(op1->type == op2->type);8201 assert(op1->type == op2->type);
8120 out_val->type = op1->type;8202 out_val->type = op1->type;
8121 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8203 if (op1->type->id == ZigTypeIdComptimeFloat) {
8122 bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8204 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) {
8124 switch (op1->type->data.floating.bit_count) {8206 switch (op1->type->data.floating.bit_count) {
8125 case 16:8207 case 16:
8126 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8208 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...@@ -8147,9 +8229,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
8147static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8229static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8148 assert(op1->type == op2->type);8230 assert(op1->type == op2->type);
8149 out_val->type = op1->type;8231 out_val->type = op1->type;
8150 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8232 if (op1->type->id == ZigTypeIdComptimeFloat) {
8151 bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8233 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) {
8153 switch (op1->type->data.floating.bit_count) {8235 switch (op1->type->data.floating.bit_count) {
8154 case 16:8236 case 16:
8155 out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16);8237 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*...@@ -8192,9 +8274,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
8192static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8274static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8193 assert(op1->type == op2->type);8275 assert(op1->type == op2->type);
8194 out_val->type = op1->type;8276 out_val->type = op1->type;
8195 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8277 if (op1->type->id == ZigTypeIdComptimeFloat) {
8196 bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8278 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) {
8198 switch (op1->type->data.floating.bit_count) {8280 switch (op1->type->data.floating.bit_count) {
8199 case 16:8281 case 16:
8200 out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16);8282 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...@@ -8218,9 +8300,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
82188300
8219static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {8301static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
8220 out_val->type = op->type;8302 out_val->type = op->type;
8221 if (op->type->id == TypeTableEntryIdComptimeFloat) {8303 if (op->type->id == ZigTypeIdComptimeFloat) {
8222 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);8304 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) {
8224 switch (op->type->data.floating.bit_count) {8306 switch (op->type->data.floating.bit_count) {
8225 case 16:8307 case 16:
8226 {8308 {
...@@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {...@@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
8248}8330}
82498331
8250void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {8332void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
8251 if (op->type->id == TypeTableEntryIdFloat) {8333 if (op->type->id == ZigTypeIdFloat) {
8252 switch (op->type->data.floating.bit_count) {8334 switch (op->type->data.floating.bit_count) {
8253 case 16:8335 case 16:
8254 memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian8336 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) {...@@ -8271,7 +8353,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
8271}8353}
82728354
8273void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {8355void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
8274 if (val->type->id == TypeTableEntryIdFloat) {8356 if (val->type->id == ZigTypeIdFloat) {
8275 switch (val->type->data.floating.bit_count) {8357 switch (val->type->data.floating.bit_count) {
8276 case 16:8358 case 16:
8277 memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian8359 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) {...@@ -8293,7 +8375,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
8293 }8375 }
8294}8376}
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,
8297 bool explicit_cast)8379 bool explicit_cast)
8298{8380{
8299 if (type_is_invalid(other_type)) {8381 if (type_is_invalid(other_type)) {
...@@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8303 ConstExprValue *const_val = &instruction->value;8385 ConstExprValue *const_val = &instruction->value;
8304 assert(const_val->special != ConstValSpecialRuntime);8386 assert(const_val->special != ConstValSpecialRuntime);
83058387
8306 bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt ||8388 bool const_val_is_int = (const_val->type->id == ZigTypeIdInt ||
8307 const_val->type->id == TypeTableEntryIdComptimeInt);8389 const_val->type->id == ZigTypeIdComptimeInt);
8308 bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat ||8390 bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat ||
8309 const_val->type->id == TypeTableEntryIdComptimeFloat);8391 const_val->type->id == ZigTypeIdComptimeFloat);
8310 if (other_type->id == TypeTableEntryIdFloat) {8392 if (other_type->id == ZigTypeIdFloat) {
8311 return true;8393 return true;
8312 } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) {8394 } else if (other_type->id == ZigTypeIdInt && const_val_is_int) {
8313 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {8395 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
8314 Buf *val_buf = buf_alloc();8396 Buf *val_buf = buf_alloc();
8315 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);8397 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...@@ -8326,11 +8408,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8326 }8408 }
8327 } else if (const_val_fits_in_num_lit(const_val, other_type)) {8409 } else if (const_val_fits_in_num_lit(const_val, other_type)) {
8328 return true;8410 return true;
8329 } else if (other_type->id == TypeTableEntryIdOptional) {8411 } else if (other_type->id == ZigTypeIdOptional) {
8330 TypeTableEntry *child_type = other_type->data.maybe.child_type;8412 ZigType *child_type = other_type->data.maybe.child_type;
8331 if (const_val_fits_in_num_lit(const_val, child_type)) {8413 if (const_val_fits_in_num_lit(const_val, child_type)) {
8332 return true;8414 return true;
8333 } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) {8415 } else if (child_type->id == ZigTypeIdInt && const_val_is_int) {
8334 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {8416 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
8335 Buf *val_buf = buf_alloc();8417 Buf *val_buf = buf_alloc();
8336 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);8418 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...@@ -8346,11 +8428,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8346 {8428 {
8347 return true;8429 return true;
8348 }8430 }
8349 } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) {8431 } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) {
8350 return true;8432 return true;
8351 }8433 }
8352 }8434 }
8353 if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) &&8435 if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) &&
8354 const_val_is_float)8436 const_val_is_float)
8355 {8437 {
8356 if (float_has_fraction(const_val)) {8438 if (float_has_fraction(const_val)) {
...@@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8363 buf_ptr(&other_type->name)));8445 buf_ptr(&other_type->name)));
8364 return false;8446 return false;
8365 } else {8447 } else {
8366 if (other_type->id == TypeTableEntryIdComptimeInt) {8448 if (other_type->id == ZigTypeIdComptimeInt) {
8367 return true;8449 return true;
8368 } else {8450 } else {
8369 BigInt bigint;8451 BigInt bigint;
...@@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8395 return false;8477 return false;
8396}8478}
83978479
8398static bool is_slice(TypeTableEntry *type) {8480static bool is_slice(ZigType *type) {
8399 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;8481 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
8400}8482}
84018483
8402static bool slice_is_const(TypeTableEntry *type) {8484static bool slice_is_const(ZigType *type) {
8403 assert(is_slice(type));8485 assert(is_slice(type));
8404 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;8486 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
8405}8487}
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,
8408 AstNode *source_node)8490 AstNode *source_node)
8409{8491{
8410 assert(set1->id == TypeTableEntryIdErrorSet);8492 assert(set1->id == ZigTypeIdErrorSet);
8411 assert(set2->id == TypeTableEntryIdErrorSet);8493 assert(set2->id == ZigTypeIdErrorSet);
84128494
8413 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {8495 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
8414 return ira->codegen->builtin_types.entry_invalid;8496 return ira->codegen->builtin_types.entry_invalid;
...@@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry...@@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
8430 }8512 }
8431 ZigList<ErrorTableEntry *> intersection_list = {};8513 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);
8434 buf_resize(&err_set_type->name, 0);8516 buf_resize(&err_set_type->name, 0);
8435 buf_appendf(&err_set_type->name, "error{");8517 buf_appendf(&err_set_type->name, "error{");
84368518
...@@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry...@@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
8459}8541}
84608542
84618543
8462static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *wanted_type,8544static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,
8463 TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable)8545 ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable)
8464{8546{
8465 CodeGen *g = ira->codegen;8547 CodeGen *g = ira->codegen;
8466 ConstCastOnly result = {};8548 ConstCastOnly result = {};
...@@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8472 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively8554 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively
8473 // but not if we want a mutable pointer8555 // but not if we want a mutable pointer
8474 // and not if the actual pointer has zero bits8556 // and not if the actual pointer has zero bits
8475 if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional &&8557 if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&
8476 wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&8558 wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&
8477 actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type))8559 actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))
8478 {8560 {
8479 ConstCastOnly child = types_match_const_cast_only(ira,8561 ConstCastOnly child = types_match_const_cast_only(ira,
8480 wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);8562 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...@@ -8487,10 +8569,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8487 }8569 }
84888570
8489 // *T and [*]T can always cast to *c_void8571 // *T and [*]T can always cast to *c_void
8490 if (wanted_type->id == TypeTableEntryIdPointer &&8572 if (wanted_type->id == ZigTypeIdPointer &&
8491 wanted_type->data.pointer.ptr_len == PtrLenSingle &&8573 wanted_type->data.pointer.ptr_len == PtrLenSingle &&
8492 wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&8574 wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&
8493 actual_type->id == TypeTableEntryIdPointer &&8575 actual_type->id == ZigTypeIdPointer &&
8494 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&8576 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
8495 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))8577 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
8496 {8578 {
...@@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8499 }8581 }
85008582
8501 // pointer const8583 // pointer const
8502 if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) {8584 if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) {
8503 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,8585 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
8504 actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);8586 actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);
8505 if (child.id != ConstCastResultIdOk) {8587 if (child.id != ConstCastResultIdOk) {
...@@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
85238605
8524 // slice const8606 // slice const
8525 if (is_slice(wanted_type) && is_slice(actual_type)) {8607 if (is_slice(wanted_type) && is_slice(actual_type)) {
8526 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;8608 ZigType *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;8609 ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
8528 if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&8610 if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
8529 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&8611 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&
8530 actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset &&8612 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...@@ -8545,7 +8627,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8545 }8627 }
85468628
8547 // maybe8629 // maybe
8548 if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {8630 if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) {
8549 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,8631 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,
8550 actual_type->data.maybe.child_type, source_node, wanted_is_mutable);8632 actual_type->data.maybe.child_type, source_node, wanted_is_mutable);
8551 if (child.id != ConstCastResultIdOk) {8633 if (child.id != ConstCastResultIdOk) {
...@@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8559 }8641 }
85608642
8561 // error union8643 // error union
8562 if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {8644 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) {
8563 ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,8645 ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,
8564 actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);8646 actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);
8565 if (payload_child.id != ConstCastResultIdOk) {8647 if (payload_child.id != ConstCastResultIdOk) {
...@@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8584 }8666 }
85858667
8586 // error set8668 // error set
8587 if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {8669 if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) {
8588 TypeTableEntry *contained_set = actual_type;8670 ZigType *contained_set = actual_type;
8589 TypeTableEntry *container_set = wanted_type;8671 ZigType *container_set = wanted_type;
85908672
8591 // if the container set is inferred, then this will always work.8673 // if the container set is inferred, then this will always work.
8592 if (container_set->data.error_set.infer_fn != nullptr) {8674 if (container_set->data.error_set.infer_fn != nullptr) {
...@@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8629 }8711 }
86308712
8631 if (wanted_type == ira->codegen->builtin_types.entry_promise &&8713 if (wanted_type == ira->codegen->builtin_types.entry_promise &&
8632 actual_type->id == TypeTableEntryIdPromise)8714 actual_type->id == ZigTypeIdPromise)
8633 {8715 {
8634 return result;8716 return result;
8635 }8717 }
86368718
8637 // fn8719 // fn
8638 if (wanted_type->id == TypeTableEntryIdFn &&8720 if (wanted_type->id == ZigTypeIdFn &&
8639 actual_type->id == TypeTableEntryIdFn)8721 actual_type->id == ZigTypeIdFn)
8640 {8722 {
8641 if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {8723 if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
8642 result.id = ConstCastResultIdFnAlign;8724 result.id = ConstCastResultIdFnAlign;
...@@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
8655 return result;8737 return result;
8656 }8738 }
8657 if (!wanted_type->data.fn.is_generic &&8739 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)
8659 {8741 {
8660 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,8742 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,
8661 actual_type->data.fn.fn_type_id.return_type, source_node, false);8743 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 *...@@ -8725,7 +8807,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
8725 *errors = reallocate(*errors, old_errors_count, *errors_count);8807 *errors = reallocate(*errors, old_errors_count, *errors_count);
8726}8808}
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) {
8729 Error err;8811 Error err;
8730 assert(instruction_count >= 1);8812 assert(instruction_count >= 1);
8731 IrInstruction *prev_inst = instructions[0];8813 IrInstruction *prev_inst = instructions[0];
...@@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8734 }8816 }
8735 ErrorTableEntry **errors = nullptr;8817 ErrorTableEntry **errors = nullptr;
8736 size_t errors_count = 0;8818 size_t errors_count = 0;
8737 TypeTableEntry *err_set_type = nullptr;8819 ZigType *err_set_type = nullptr;
8738 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {8820 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
8739 if (type_is_global_error_set(prev_inst->value.type)) {8821 if (type_is_global_error_set(prev_inst->value.type)) {
8740 err_set_type = ira->codegen->builtin_types.entry_global_error_set;8822 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
8741 } else {8823 } else {
...@@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8753 }8835 }
8754 }8836 }
87558837
8756 bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull);8838 bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
8757 bool convert_to_const_slice = false;8839 bool convert_to_const_slice = false;
8758 for (size_t i = 1; i < instruction_count; i += 1) {8840 for (size_t i = 1; i < instruction_count; i += 1) {
8759 IrInstruction *cur_inst = instructions[i];8841 IrInstruction *cur_inst = instructions[i];
8760 TypeTableEntry *cur_type = cur_inst->value.type;8842 ZigType *cur_type = cur_inst->value.type;
8761 TypeTableEntry *prev_type = prev_inst->value.type;8843 ZigType *prev_type = prev_inst->value.type;
87628844
8763 if (type_is_invalid(cur_type)) {8845 if (type_is_invalid(cur_type)) {
8764 return cur_type;8846 return cur_type;
8765 }8847 }
87668848
8767 if (prev_type->id == TypeTableEntryIdUnreachable) {8849 if (prev_type->id == ZigTypeIdUnreachable) {
8768 prev_inst = cur_inst;8850 prev_inst = cur_inst;
8769 continue;8851 continue;
8770 }8852 }
87718853
8772 if (cur_type->id == TypeTableEntryIdUnreachable) {8854 if (cur_type->id == ZigTypeIdUnreachable) {
8773 continue;8855 continue;
8774 }8856 }
87758857
8776 if (prev_type->id == TypeTableEntryIdErrorSet) {8858 if (prev_type->id == ZigTypeIdErrorSet) {
8777 assert(err_set_type != nullptr);8859 assert(err_set_type != nullptr);
8778 if (cur_type->id == TypeTableEntryIdErrorSet) {8860 if (cur_type->id == ZigTypeIdErrorSet) {
8779 if (type_is_global_error_set(err_set_type)) {8861 if (type_is_global_error_set(err_set_type)) {
8780 continue;8862 continue;
8781 }8863 }
...@@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8839 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);8921 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);
8840 assert(errors != nullptr);8922 assert(errors != nullptr);
8841 continue;8923 continue;
8842 } else if (cur_type->id == TypeTableEntryIdErrorUnion) {8924 } else if (cur_type->id == ZigTypeIdErrorUnion) {
8843 if (type_is_global_error_set(err_set_type)) {8925 if (type_is_global_error_set(err_set_type)) {
8844 prev_inst = cur_inst;8926 prev_inst = cur_inst;
8845 continue;8927 continue;
8846 }8928 }
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;
8848 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {8930 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
8849 return ira->codegen->builtin_types.entry_invalid;8931 return ira->codegen->builtin_types.entry_invalid;
8850 }8932 }
...@@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8897 }8979 }
8898 }8980 }
88998981
8900 if (cur_type->id == TypeTableEntryIdErrorSet) {8982 if (cur_type->id == ZigTypeIdErrorSet) {
8901 if (prev_type->id == TypeTableEntryIdArray) {8983 if (prev_type->id == ZigTypeIdArray) {
8902 convert_to_const_slice = true;8984 convert_to_const_slice = true;
8903 }8985 }
8904 if (type_is_global_error_set(cur_type)) {8986 if (type_is_global_error_set(cur_type)) {
...@@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8915 update_errors_helper(ira->codegen, &errors, &errors_count);8997 update_errors_helper(ira->codegen, &errors, &errors_count);
89168998
8917 if (err_set_type == nullptr) {8999 if (err_set_type == nullptr) {
8918 if (prev_type->id == TypeTableEntryIdErrorUnion) {9000 if (prev_type->id == ZigTypeIdErrorUnion) {
8919 err_set_type = prev_type->data.error_union.err_set_type;9001 err_set_type = prev_type->data.error_union.err_set_type;
8920 } else {9002 } else {
8921 err_set_type = cur_type;9003 err_set_type = cur_type;
...@@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8948 continue;9030 continue;
8949 }9031 }
89509032
8951 if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) {9033 if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) {
8952 TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type;9034 ZigType *prev_payload_type = prev_type->data.error_union.payload_type;
8953 TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type;9035 ZigType *cur_payload_type = cur_type->data.error_union.payload_type;
89549036
8955 bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type,9037 bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type,
8956 source_node, false).id == ConstCastResultIdOk;9038 source_node, false).id == ConstCastResultIdOk;
...@@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8962 prev_inst = cur_inst;9044 prev_inst = cur_inst;
8963 }9045 }
89649046
8965 TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;9047 ZigType *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;9048 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
89679049
8968 if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {9050 if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
8969 return ira->codegen->builtin_types.entry_invalid;9051 return ira->codegen->builtin_types.entry_invalid;
...@@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9032 }9114 }
9033 }9115 }
90349116
9035 if (prev_type->id == TypeTableEntryIdNull) {9117 if (prev_type->id == ZigTypeIdNull) {
9036 prev_inst = cur_inst;9118 prev_inst = cur_inst;
9037 continue;9119 continue;
9038 }9120 }
90399121
9040 if (cur_type->id == TypeTableEntryIdNull) {9122 if (cur_type->id == ZigTypeIdNull) {
9041 any_are_null = true;9123 any_are_null = true;
9042 continue;9124 continue;
9043 }9125 }
...@@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9051 continue;9133 continue;
9052 }9134 }
90539135
9054 if (prev_type->id == TypeTableEntryIdInt &&9136 if (prev_type->id == ZigTypeIdInt &&
9055 cur_type->id == TypeTableEntryIdInt &&9137 cur_type->id == ZigTypeIdInt &&
9056 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)9138 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)
9057 {9139 {
9058 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {9140 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...@@ -9061,26 +9143,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9061 continue;9143 continue;
9062 }9144 }
90639145
9064 if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) {9146 if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) {
9065 if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {9147 if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {
9066 prev_inst = cur_inst;9148 prev_inst = cur_inst;
9067 }9149 }
9068 continue;9150 continue;
9069 }9151 }
90709152
9071 if (prev_type->id == TypeTableEntryIdErrorUnion &&9153 if (prev_type->id == ZigTypeIdErrorUnion &&
9072 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,9154 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,
9073 source_node, false).id == ConstCastResultIdOk)9155 source_node, false).id == ConstCastResultIdOk)
9074 {9156 {
9075 continue;9157 continue;
9076 }9158 }
90779159
9078 if (cur_type->id == TypeTableEntryIdErrorUnion &&9160 if (cur_type->id == ZigTypeIdErrorUnion &&
9079 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,9161 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,
9080 source_node, false).id == ConstCastResultIdOk)9162 source_node, false).id == ConstCastResultIdOk)
9081 {9163 {
9082 if (err_set_type != nullptr) {9164 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;
9084 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {9166 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
9085 return ira->codegen->builtin_types.entry_invalid;9167 return ira->codegen->builtin_types.entry_invalid;
9086 }9168 }
...@@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9098 continue;9180 continue;
9099 }9181 }
91009182
9101 if (prev_type->id == TypeTableEntryIdOptional &&9183 if (prev_type->id == ZigTypeIdOptional &&
9102 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,9184 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,
9103 source_node, false).id == ConstCastResultIdOk)9185 source_node, false).id == ConstCastResultIdOk)
9104 {9186 {
9105 continue;9187 continue;
9106 }9188 }
91079189
9108 if (cur_type->id == TypeTableEntryIdOptional &&9190 if (cur_type->id == ZigTypeIdOptional &&
9109 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,9191 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,
9110 source_node, false).id == ConstCastResultIdOk)9192 source_node, false).id == ConstCastResultIdOk)
9111 {9193 {
...@@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9113 continue;9195 continue;
9114 }9196 }
91159197
9116 if (cur_type->id == TypeTableEntryIdUndefined) {9198 if (cur_type->id == ZigTypeIdUndefined) {
9117 continue;9199 continue;
9118 }9200 }
91199201
9120 if (prev_type->id == TypeTableEntryIdUndefined) {9202 if (prev_type->id == ZigTypeIdUndefined) {
9121 prev_inst = cur_inst;9203 prev_inst = cur_inst;
9122 continue;9204 continue;
9123 }9205 }
91249206
9125 if (prev_type->id == TypeTableEntryIdComptimeInt ||9207 if (prev_type->id == ZigTypeIdComptimeInt ||
9126 prev_type->id == TypeTableEntryIdComptimeFloat)9208 prev_type->id == ZigTypeIdComptimeFloat)
9127 {9209 {
9128 if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {9210 if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {
9129 prev_inst = cur_inst;9211 prev_inst = cur_inst;
...@@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9133 }9215 }
9134 }9216 }
91359217
9136 if (cur_type->id == TypeTableEntryIdComptimeInt ||9218 if (cur_type->id == ZigTypeIdComptimeInt ||
9137 cur_type->id == TypeTableEntryIdComptimeFloat)9219 cur_type->id == ZigTypeIdComptimeFloat)
9138 {9220 {
9139 if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {9221 if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {
9140 continue;9222 continue;
...@@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9143 }9225 }
9144 }9226 }
91459227
9146 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&9228 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
9147 cur_type->data.array.len != prev_type->data.array.len &&9229 cur_type->data.array.len != prev_type->data.array.len &&
9148 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,9230 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
9149 source_node, false).id == ConstCastResultIdOk)9231 source_node, false).id == ConstCastResultIdOk)
...@@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9153 continue;9235 continue;
9154 }9236 }
91559237
9156 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&9238 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
9157 cur_type->data.array.len != prev_type->data.array.len &&9239 cur_type->data.array.len != prev_type->data.array.len &&
9158 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,9240 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
9159 source_node, false).id == ConstCastResultIdOk)9241 source_node, false).id == ConstCastResultIdOk)
...@@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9162 continue;9244 continue;
9163 }9245 }
91649246
9165 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&9247 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
9166 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||9248 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
9167 cur_type->data.array.len == 0) &&9249 cur_type->data.array.len == 0) &&
9168 types_match_const_cast_only(ira,9250 types_match_const_cast_only(ira,
...@@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9173 continue;9255 continue;
9174 }9256 }
91759257
9176 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&9258 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
9177 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||9259 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
9178 prev_type->data.array.len == 0) &&9260 prev_type->data.array.len == 0) &&
9179 types_match_const_cast_only(ira,9261 types_match_const_cast_only(ira,
...@@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9185 continue;9267 continue;
9186 }9268 }
91879269
9188 if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion &&9270 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
9189 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))9271 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
9190 {9272 {
9191 if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type)))9273 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...@@ -9195,7 +9277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9195 }9277 }
9196 }9278 }
91979279
9198 if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion &&9280 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion &&
9199 (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))9281 (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
9200 {9282 {
9201 if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type)))9283 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...@@ -9220,33 +9302,33 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9220 free(errors);9302 free(errors);
92219303
9222 if (convert_to_const_slice) {9304 if (convert_to_const_slice) {
9223 assert(prev_inst->value.type->id == TypeTableEntryIdArray);9305 assert(prev_inst->value.type->id == ZigTypeIdArray);
9224 TypeTableEntry *ptr_type = get_pointer_to_type_extra(9306 ZigType *ptr_type = get_pointer_to_type_extra(
9225 ira->codegen, prev_inst->value.type->data.array.child_type,9307 ira->codegen, prev_inst->value.type->data.array.child_type,
9226 true, false, PtrLenUnknown,9308 true, false, PtrLenUnknown,
9227 get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),9309 get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),
9228 0, 0);9310 0, 0);
9229 TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type);9311 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
9230 if (err_set_type != nullptr) {9312 if (err_set_type != nullptr) {
9231 return get_error_union_type(ira->codegen, err_set_type, slice_type);9313 return get_error_union_type(ira->codegen, err_set_type, slice_type);
9232 } else {9314 } else {
9233 return slice_type;9315 return slice_type;
9234 }9316 }
9235 } else if (err_set_type != nullptr) {9317 } else if (err_set_type != nullptr) {
9236 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {9318 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
9237 return err_set_type;9319 return err_set_type;
9238 } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) {9320 } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {
9239 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type);9321 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) {
9241 return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);9323 return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);
9242 } else {9324 } else {
9243 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||9325 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9244 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)9326 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
9245 {9327 {
9246 ir_add_error_node(ira, source_node,9328 ir_add_error_node(ira, source_node,
9247 buf_sprintf("unable to make error union out of number literal"));9329 buf_sprintf("unable to make error union out of number literal"));
9248 return ira->codegen->builtin_types.entry_invalid;9330 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) {
9250 ir_add_error_node(ira, source_node,9332 ir_add_error_node(ira, source_node,
9251 buf_sprintf("unable to make error union out of null literal"));9333 buf_sprintf("unable to make error union out of null literal"));
9252 return ira->codegen->builtin_types.entry_invalid;9334 return ira->codegen->builtin_types.entry_invalid;
...@@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9254 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);9336 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);
9255 }9337 }
9256 }9338 }
9257 } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) {9339 } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {
9258 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||9340 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9259 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)9341 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
9260 {9342 {
9261 ir_add_error_node(ira, source_node,9343 ir_add_error_node(ira, source_node,
9262 buf_sprintf("unable to make maybe out of number literal"));9344 buf_sprintf("unable to make maybe out of number literal"));
9263 return ira->codegen->builtin_types.entry_invalid;9345 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) {
9265 return prev_inst->value.type;9347 return prev_inst->value.type;
9266 } else {9348 } else {
9267 return get_optional_type(ira->codegen, prev_inst->value.type);9349 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...@@ -9271,9 +9353,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
9271 }9353 }
9272}9354}
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) {
9275 if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) {9357 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);
9277 if (fn_entry != nullptr) {9359 if (fn_entry != nullptr) {
9278 fn_entry->alloca_list.append(instruction);9360 fn_entry->alloca_list.append(instruction);
9279 }9361 }
...@@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
9285 *dest = *src;9367 *dest = *src;
9286 if (!same_global_refs) {9368 if (!same_global_refs) {
9287 dest->global_refs = global_refs;9369 dest->global_refs = global_refs;
9288 if (dest->type->id == TypeTableEntryIdStruct) {9370 if (dest->type->id == ZigTypeIdStruct) {
9289 dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);9371 dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);
9290 memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);9372 memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);
9291 }9373 }
...@@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
92949376
9295static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,9377static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
9296 CastOp cast_op,9378 CastOp cast_op,
9297 ConstExprValue *other_val, TypeTableEntry *other_type,9379 ConstExprValue *other_val, ZigType *other_type,
9298 ConstExprValue *const_val, TypeTableEntry *new_type)9380 ConstExprValue *const_val, ZigType *new_type)
9299{9381{
9300 const_val->special = other_val->special;9382 const_val->special = other_val->special;
93019383
...@@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9315 break;9397 break;
9316 }9398 }
9317 case CastOpNumLitToConcrete:9399 case CastOpNumLitToConcrete:
9318 if (other_val->type->id == TypeTableEntryIdComptimeFloat) {9400 if (other_val->type->id == ZigTypeIdComptimeFloat) {
9319 assert(new_type->id == TypeTableEntryIdFloat);9401 assert(new_type->id == ZigTypeIdFloat);
9320 switch (new_type->data.floating.bit_count) {9402 switch (new_type->data.floating.bit_count) {
9321 case 16:9403 case 16:
9322 const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat);9404 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_...@@ -9333,7 +9415,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9333 default:9415 default:
9334 zig_unreachable();9416 zig_unreachable();
9335 }9417 }
9336 } else if (other_val->type->id == TypeTableEntryIdComptimeInt) {9418 } else if (other_val->type->id == ZigTypeIdComptimeInt) {
9337 bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);9419 bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);
9338 } else {9420 } else {
9339 zig_unreachable();9421 zig_unreachable();
...@@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9346 zig_unreachable();9428 zig_unreachable();
9347 case CastOpIntToFloat:9429 case CastOpIntToFloat:
9348 {9430 {
9349 assert(new_type->id == TypeTableEntryIdFloat);9431 assert(new_type->id == ZigTypeIdFloat);
93509432
9351 BigFloat bigfloat;9433 BigFloat bigfloat;
9352 bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);9434 bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);
...@@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9371 }9453 }
9372 case CastOpFloatToInt:9454 case CastOpFloatToInt:
9373 float_init_bigint(&const_val->data.x_bigint, other_val);9455 float_init_bigint(&const_val->data.x_bigint, other_val);
9374 if (new_type->id == TypeTableEntryIdInt) {9456 if (new_type->id == ZigTypeIdInt) {
9375 if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,9457 if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,
9376 new_type->data.integral.is_signed))9458 new_type->data.integral.is_signed))
9377 {9459 {
...@@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9395 return true;9477 return true;
9396}9478}
9397static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,9479static 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)
9399{9481{
9400 if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) &&9482 if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) &&
9401 cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice)9483 cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice)
...@@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
9419}9501}
94209502
9421static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,9503static 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)
9423{9505{
9424 assert(value->value.type->id == TypeTableEntryIdPointer);9506 assert(value->value.type->id == ZigTypeIdPointer);
9425 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);9507 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
94269508
9427 if (instr_is_comptime(value)) {9509 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;
9429 if (pointee->special != ConstValSpecialRuntime) {9513 if (pointee->special != ConstValSpecialRuntime) {
9430 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,9514 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
9431 source_instr->source_node, wanted_type);9515 source_instr->source_node, wanted_type);
...@@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
9446}9530}
94479531
9448static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,9532static 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)
9450{9534{
9451 wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);9535 wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
94529536
9453 if (instr_is_comptime(value)) {9537 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;
9455 if (pointee->special != ConstValSpecialRuntime) {9541 if (pointee->special != ConstValSpecialRuntime) {
9456 assert(value->value.type->id == TypeTableEntryIdPointer);9542 assert(value->value.type->id == ZigTypeIdPointer);
9457 TypeTableEntry *array_type = value->value.type->data.pointer.child_type;9543 ZigType *array_type = value->value.type->data.pointer.child_type;
9458 assert(is_slice(wanted_type));9544 assert(is_slice(wanted_type));
9459 bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;9545 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...@@ -9475,10 +9561,10 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
9475 return result;9561 return result;
9476}9562}
94779563
9478static bool is_container(TypeTableEntry *type) {9564static bool is_container(ZigType *type) {
9479 return type->id == TypeTableEntryIdStruct ||9565 return type->id == ZigTypeIdStruct ||
9480 type->id == TypeTableEntryIdEnum ||9566 type->id == ZigTypeIdEnum ||
9481 type->id == TypeTableEntryIdUnion;9567 type->id == ZigTypeIdUnion;
9482}9568}
94839569
9484static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {9570static 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...@@ -9496,6 +9582,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr
9496 return new_bb;9582 return new_bb;
9497}9583}
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
9499static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {9598static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
9500 ira->instruction_index = 0;9599 ira->instruction_index = 0;
9501 ira->old_irb.current_basic_block = old_bb;9600 ira->old_irb.current_basic_block = old_bb;
...@@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) {...@@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
9541 }9640 }
9542}9641}
95439642
9544static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) {9643static ZigType *ir_unreach_error(IrAnalyze *ira) {
9545 ira->old_bb_index = SIZE_MAX;9644 ira->old_bb_index = SIZE_MAX;
9546 ira->new_irb.exec->invalid = true;9645 ira->new_irb.exec->invalid = true;
9547 return ira->codegen->builtin_types.entry_unreachable;9646 return ira->codegen->builtin_types.entry_unreachable;
...@@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru...@@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
9564 return true;9663 return true;
9565}9664}
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) {
9568 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {9667 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
9569 if (!ir_emit_backward_branch(ira, source_instruction))9668 if (!ir_emit_backward_branch(ira, source_instruction))
9570 return ir_unreach_error(ira);9669 return ir_unreach_error(ira);
...@@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru...@@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru
9575 return ira->codegen->builtin_types.entry_unreachable;9674 return ira->codegen->builtin_types.entry_unreachable;
9576}9675}
95779676
9578static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) {9677static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) {
9579 if (result_type->id == TypeTableEntryIdUnreachable)9678 if (result_type->id == ZigTypeIdUnreachable)
9580 ir_finish_bb(ira);9679 ir_finish_bb(ira);
9581 return result_type;9680 return result_type;
9582}9681}
...@@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in...@@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in
9595 return &new_instruction->value;9694 return &new_instruction->value;
9596}9695}
95979696
9598static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {9697static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
9599 ir_build_const_from(ira, instruction);9698 ir_build_const_from(ira, instruction);
9600 return ira->codegen->builtin_types.entry_void;9699 return ira->codegen->builtin_types.entry_void;
9601}9700}
96029701
9603static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,9702static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
9604 ConstExprValue *pointee, TypeTableEntry *pointee_type,9703 ConstExprValue *pointee, ZigType *pointee_type,
9605 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)9704 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
9606{9705{
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,
9608 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);9707 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);
9609 IrInstruction *const_instr = ir_get_const(ira, instruction);9708 IrInstruction *const_instr = ir_get_const(ira, instruction);
9610 ConstExprValue *const_val = &const_instr->value;9709 ConstExprValue *const_val = &const_instr->value;
...@@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
9615 return const_instr;9714 return const_instr;
9616}9715}
96179716
9618static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,9717static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
9619 ConstExprValue *pointee, TypeTableEntry *pointee_type,9718 ConstExprValue *pointee, ZigType *pointee_type,
9620 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile)9719 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile)
9621{9720{
9622 IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee,9721 IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee,
...@@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr...@@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
9626 return const_instr->value.type;9725 return const_instr->value.type;
9627}9726}
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) {
9630 ConstExprValue *const_val = ir_build_const_from(ira, instruction);9729 ConstExprValue *const_val = ir_build_const_from(ira, instruction);
9631 bigint_init_unsigned(&const_val->data.x_bigint, value);9730 bigint_init_unsigned(&const_val->data.x_bigint, value);
9632 return ira->codegen->builtin_types.entry_usize;9731 return ira->codegen->builtin_types.entry_usize;
...@@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un...@@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
9659}9758}
96609759
9661IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,9760IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
9662 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,9761 ZigType *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,9762 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
9664 IrExecutable *parent_exec)9763 IrExecutable *parent_exec)
9665{9764{
9666 if (expected_type != nullptr && type_is_invalid(expected_type))9765 if (expected_type != nullptr && type_is_invalid(expected_type))
...@@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
9697 analyzed_executable->backward_branch_count = backward_branch_count;9796 analyzed_executable->backward_branch_count = backward_branch_count;
9698 analyzed_executable->backward_branch_quota = backward_branch_quota;9797 analyzed_executable->backward_branch_quota = backward_branch_quota;
9699 analyzed_executable->begin_scope = scope;9798 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);
9701 if (type_is_invalid(result_type))9800 if (type_is_invalid(result_type))
9702 return codegen->invalid_instruction;9801 return codegen->invalid_instruction;
97039802
...@@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
9710 return ir_exec_const_result(codegen, analyzed_executable);9809 return ir_exec_const_result(codegen, analyzed_executable);
9711}9810}
97129811
9713static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {9812static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
9714 if (type_is_invalid(type_value->value.type))9813 if (type_is_invalid(type_value->value.type))
9715 return ira->codegen->builtin_types.entry_invalid;9814 return ira->codegen->builtin_types.entry_invalid;
97169815
9717 if (type_value->value.type->id != TypeTableEntryIdMetaType) {9816 if (type_value->value.type->id != ZigTypeIdMetaType) {
9718 ir_add_error(ira, type_value,9817 ir_add_error(ira, type_value,
9719 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));9818 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
9720 return ira->codegen->builtin_types.entry_invalid;9819 return ira->codegen->builtin_types.entry_invalid;
...@@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value...@@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value
9727 return const_val->data.x_type;9826 return const_val->data.x_type;
9728}9827}
97299828
9730static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {9829static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9731 if (fn_value == ira->codegen->invalid_instruction)9830 if (fn_value == ira->codegen->invalid_instruction)
9732 return nullptr;9831 return nullptr;
97339832
9734 if (type_is_invalid(fn_value->value.type))9833 if (type_is_invalid(fn_value->value.type))
9735 return nullptr;9834 return nullptr;
97369835
9737 if (fn_value->value.type->id != TypeTableEntryIdFn) {9836 if (fn_value->value.type->id != ZigTypeIdFn) {
9738 ir_add_error_node(ira, fn_value->source_node,9837 ir_add_error_node(ira, fn_value->source_node,
9739 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));9838 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));
9740 return nullptr;9839 return nullptr;
...@@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9748 return const_val->data.x_ptr.data.fn.fn_entry;9847 return const_val->data.x_ptr.data.fn.fn_entry;
9749}9848}
97509849
9751static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {9850static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9752 assert(wanted_type->id == TypeTableEntryIdOptional);9851 assert(wanted_type->id == ZigTypeIdOptional);
97539852
9754 if (instr_is_comptime(value)) {9853 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;
9756 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);9855 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
9757 if (type_is_invalid(casted_payload->value.type))9856 if (type_is_invalid(casted_payload->value.type))
9758 return ira->codegen->invalid_instruction;9857 return ira->codegen->invalid_instruction;
...@@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
9781}9880}
97829881
9783static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,9882static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
9784 IrInstruction *value, TypeTableEntry *wanted_type)9883 IrInstruction *value, ZigType *wanted_type)
9785{9884{
9786 assert(wanted_type->id == TypeTableEntryIdErrorUnion);9885 assert(wanted_type->id == ZigTypeIdErrorUnion);
97879886
9788 if (instr_is_comptime(value)) {9887 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;
9790 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);9889 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
9791 if (type_is_invalid(casted_payload->value.type))9890 if (type_is_invalid(casted_payload->value.type))
9792 return ira->codegen->invalid_instruction;9891 return ira->codegen->invalid_instruction;
...@@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
9812}9911}
98139912
9814static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,9913static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
9815 TypeTableEntry *wanted_type)9914 ZigType *wanted_type)
9816{9915{
9817 assert(value->value.type->id == TypeTableEntryIdErrorSet);9916 assert(value->value.type->id == ZigTypeIdErrorSet);
9818 assert(wanted_type->id == TypeTableEntryIdErrorSet);9917 assert(wanted_type->id == ZigTypeIdErrorSet);
98199918
9820 if (instr_is_comptime(value)) {9919 if (instr_is_comptime(value)) {
9821 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);9920 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
9854 return result;9953 return result;
9855}9954}
98569955
9857static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {9956static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9858 assert(wanted_type->id == TypeTableEntryIdErrorUnion);9957 assert(wanted_type->id == ZigTypeIdErrorUnion);
98599958
9860 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);9959 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...@@ -9881,7 +9980,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
9881}9980}
98829981
9883static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr,9982static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr,
9884 IrInstruction *value, TypeTableEntry *wanted_type)9983 IrInstruction *value, ZigType *wanted_type)
9885{9984{
9886 if (instr_is_comptime(value)) {9985 if (instr_is_comptime(value)) {
9887 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);9986 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_...@@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
9905 source_instr->source_node, value, true, false);10004 source_instr->source_node, value, true, false);
9906 new_instruction->value.type = wanted_type;10005 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;
9909 if (type_has_bits(child_type)) {10008 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);
9911 assert(fn_entry);10010 assert(fn_entry);
9912 fn_entry->alloca_list.append(new_instruction);10011 fn_entry->alloca_list.append(new_instruction);
9913 }10012 }
...@@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_...@@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
9916 }10015 }
9917}10016}
991810017
9919static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {10018static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9920 assert(wanted_type->id == TypeTableEntryIdOptional);10019 assert(wanted_type->id == ZigTypeIdOptional);
9921 assert(instr_is_comptime(value));10020 assert(instr_is_comptime(value));
992210021
9923 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);10022 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
9950 get_abi_alignment(ira->codegen, value->value.type));10049 get_abi_alignment(ira->codegen, value->value.type));
9951 }10050 }
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,
9954 is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);10053 is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
9955 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,10054 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
9956 source_instruction->source_node, value, is_const, is_volatile);10055 source_instruction->source_node, value, is_const, is_volatile);
9957 new_instruction->value.type = ptr_type;10056 new_instruction->value.type = ptr_type;
9958 new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;10057 new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;
9959 if (type_has_bits(ptr_type)) {10058 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);
9961 assert(fn_entry);10060 assert(fn_entry);
9962 fn_entry->alloca_list.append(new_instruction);10061 fn_entry->alloca_list.append(new_instruction);
9963 }10062 }
...@@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
9965}10064}
996610065
9967static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,10066static 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)
9969{10068{
9970 assert(is_slice(wanted_type));10069 assert(is_slice(wanted_type));
9971 // In this function we honor the const-ness of wanted_type, because10070 // 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...@@ -9973,14 +10072,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
997310072
9974 IrInstruction *array_ptr = nullptr;10073 IrInstruction *array_ptr = nullptr;
9975 IrInstruction *array;10074 IrInstruction *array;
9976 if (array_arg->value.type->id == TypeTableEntryIdPointer) {10075 if (array_arg->value.type->id == ZigTypeIdPointer) {
9977 array = ir_get_deref(ira, source_instr, array_arg);10076 array = ir_get_deref(ira, source_instr, array_arg);
9978 array_ptr = array_arg;10077 array_ptr = array_arg;
9979 } else {10078 } else {
9980 array = array_arg;10079 array = array_arg;
9981 }10080 }
9982 TypeTableEntry *array_type = array->value.type;10081 ZigType *array_type = array->value.type;
9983 assert(array_type->id == TypeTableEntryIdArray);10082 assert(array_type->id == ZigTypeIdArray);
998410083
9985 if (instr_is_comptime(array)) {10084 if (instr_is_comptime(array)) {
9986 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10085 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...@@ -10011,12 +10110,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
10011}10110}
1001210111
10013static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr,10112static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr,
10014 IrInstruction *target, TypeTableEntry *wanted_type)10113 IrInstruction *target, ZigType *wanted_type)
10015{10114{
10016 Error err;10115 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;
10020 if ((err = ensure_complete_type(ira->codegen, actual_type)))10119 if ((err = ensure_complete_type(ira->codegen, actual_type)))
10021 return ira->codegen->invalid_instruction;10120 return ira->codegen->invalid_instruction;
1002210121
...@@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
10028 return ira->codegen->invalid_instruction;10127 return ira->codegen->invalid_instruction;
10029 }10128 }
1003010129
10031 assert(actual_type->id == TypeTableEntryIdEnum);10130 assert(actual_type->id == ZigTypeIdEnum);
1003210131
10033 if (instr_is_comptime(target)) {10132 if (instr_is_comptime(target)) {
10034 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10133 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
10047}10146}
1004810147
10049static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,10148static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
10050 IrInstruction *target, TypeTableEntry *wanted_type)10149 IrInstruction *target, ZigType *wanted_type)
10051{10150{
10052 assert(target->value.type->id == TypeTableEntryIdUnion);10151 assert(target->value.type->id == ZigTypeIdUnion);
10053 assert(wanted_type->id == TypeTableEntryIdEnum);10152 assert(wanted_type->id == ZigTypeIdEnum);
10054 assert(wanted_type == target->value.type->data.unionation.tag_type);10153 assert(wanted_type == target->value.type->data.unionation.tag_type);
1005510154
10056 if (instr_is_comptime(target)) {10155 if (instr_is_comptime(target)) {
...@@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
10072}10171}
1007310172
10074static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,10173static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,
10075 IrInstruction *target, TypeTableEntry *wanted_type)10174 IrInstruction *target, ZigType *wanted_type)
10076{10175{
10077 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10176 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
10078 source_instr->source_node, wanted_type);10177 source_instr->source_node, wanted_type);
...@@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc...@@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
10081}10180}
1008210181
10083static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,10182static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,
10084 IrInstruction *target, TypeTableEntry *wanted_type)10183 IrInstruction *target, ZigType *wanted_type)
10085{10184{
10086 Error err;10185 Error err;
10087 assert(wanted_type->id == TypeTableEntryIdUnion);10186 assert(wanted_type->id == ZigTypeIdUnion);
10088 assert(target->value.type->id == TypeTableEntryIdEnum);10187 assert(target->value.type->id == ZigTypeIdEnum);
1008910188
10090 if (instr_is_comptime(target)) {10189 if (instr_is_comptime(target)) {
10091 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10190 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
10140}10239}
1014110240
10142static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,10241static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
10143 IrInstruction *target, TypeTableEntry *wanted_type)10242 IrInstruction *target, ZigType *wanted_type)
10144{10243{
10145 assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat);10244 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1014610245
10147 if (instr_is_comptime(target)) {10246 if (instr_is_comptime(target)) {
10148 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10247 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
10149 if (!val)10248 if (!val)
10150 return ira->codegen->invalid_instruction;10249 return ira->codegen->invalid_instruction;
10151 if (wanted_type->id == TypeTableEntryIdInt) {10250 if (wanted_type->id == ZigTypeIdInt) {
10152 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {10251 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
10153 ir_add_error(ira, source_instr,10252 ir_add_error(ira, source_instr,
10154 buf_sprintf("attempt to cast negative value to unsigned integer"));10253 buf_sprintf("attempt to cast negative value to unsigned integer"));
...@@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
10166 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10265 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
10167 source_instr->source_node, wanted_type);10266 source_instr->source_node, wanted_type);
10168 result->value.type = wanted_type;10267 result->value.type = wanted_type;
10169 if (wanted_type->id == TypeTableEntryIdInt) {10268 if (wanted_type->id == ZigTypeIdInt) {
10170 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);10269 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
10171 } else {10270 } else {
10172 float_init_float(&result->value, val);10271 float_init_float(&result->value, val);
...@@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
10181}10280}
1018210281
10183static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,10282static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,
10184 IrInstruction *target, TypeTableEntry *wanted_type)10283 IrInstruction *target, ZigType *wanted_type)
10185{10284{
10186 Error err;10285 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
10191 if ((err = ensure_complete_type(ira->codegen, wanted_type)))10290 if ((err = ensure_complete_type(ira->codegen, wanted_type)))
10192 return ira->codegen->invalid_instruction;10291 return ira->codegen->invalid_instruction;
...@@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
10199 return ira->codegen->invalid_instruction;10298 return ira->codegen->invalid_instruction;
10200 }10299 }
1020110300
10202 assert(actual_type->id == TypeTableEntryIdInt);10301 assert(actual_type->id == ZigTypeIdInt);
1020310302
10204 if (instr_is_comptime(target)) {10303 if (instr_is_comptime(target)) {
10205 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10304 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
10231}10330}
1023210331
10233static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,10332static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
10234 IrInstruction *target, TypeTableEntry *wanted_type)10333 IrInstruction *target, ZigType *wanted_type)
10235{10334{
10236 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10335 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
10237 if (!val)10336 if (!val)
...@@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1023910338
10240 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10339 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
10241 source_instr->source_node, wanted_type);10340 source_instr->source_node, wanted_type);
10242 if (wanted_type->id == TypeTableEntryIdComptimeFloat) {10341 if (wanted_type->id == ZigTypeIdComptimeFloat) {
10243 float_init_float(&result->value, val);10342 float_init_float(&result->value, val);
10244 } else if (wanted_type->id == TypeTableEntryIdComptimeInt) {10343 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
10245 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);10344 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
10246 } else {10345 } else {
10247 zig_unreachable();10346 zig_unreachable();
...@@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
10250}10349}
1025110350
10252static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10351static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10253 TypeTableEntry *wanted_type)10352 ZigType *wanted_type)
10254{10353{
10255 assert(target->value.type->id == TypeTableEntryIdInt);10354 assert(target->value.type->id == ZigTypeIdInt);
10256 assert(!target->value.type->data.integral.is_signed);10355 assert(!target->value.type->data.integral.is_signed);
10257 assert(wanted_type->id == TypeTableEntryIdErrorSet);10356 assert(wanted_type->id == ZigTypeIdErrorSet);
1025810357
10259 if (instr_is_comptime(target)) {10358 if (instr_is_comptime(target)) {
10260 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10359 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
10315}10414}
1031610415
10317static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10416static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10318 TypeTableEntry *wanted_type)10417 ZigType *wanted_type)
10319{10418{
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
10324 if (instr_is_comptime(target)) {10423 if (instr_is_comptime(target)) {
10325 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10424 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10330 source_instr->source_node, wanted_type);10429 source_instr->source_node, wanted_type);
1033110430
10332 ErrorTableEntry *err;10431 ErrorTableEntry *err;
10333 if (err_type->id == TypeTableEntryIdErrorUnion) {10432 if (err_type->id == ZigTypeIdErrorUnion) {
10334 err = val->data.x_err_union.err;10433 err = val->data.x_err_union.err;
10335 } else if (err_type->id == TypeTableEntryIdErrorSet) {10434 } else if (err_type->id == ZigTypeIdErrorSet) {
10336 err = val->data.x_err_set;10435 err = val->data.x_err_set;
10337 } else {10436 } else {
10338 zig_unreachable();10437 zig_unreachable();
...@@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10353 return result;10452 return result;
10354 }10453 }
1035510454
10356 TypeTableEntry *err_set_type;10455 ZigType *err_set_type;
10357 if (err_type->id == TypeTableEntryIdErrorUnion) {10456 if (err_type->id == ZigTypeIdErrorUnion) {
10358 err_set_type = err_type->data.error_union.err_set_type;10457 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) {
10360 err_set_type = err_type;10459 err_set_type = err_type;
10361 } else {10460 } else {
10362 zig_unreachable();10461 zig_unreachable();
...@@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10395}10494}
1039610495
10397static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10496static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10398 TypeTableEntry *wanted_type)10497 ZigType *wanted_type)
10399{10498{
10400 assert(wanted_type->id == TypeTableEntryIdPointer);10499 assert(wanted_type->id == ZigTypeIdPointer);
10401 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment);10500 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;10501 ZigType *array_type = wanted_type->data.pointer.child_type;
10403 assert(array_type->id == TypeTableEntryIdArray);10502 assert(array_type->id == ZigTypeIdArray);
10404 assert(array_type->data.array.len == 1);10503 assert(array_type->data.array.len == 1);
1040510504
10406 if (instr_is_comptime(target)) {10505 if (instr_is_comptime(target)) {
...@@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
10408 if (!val)10507 if (!val)
10409 return ira->codegen->invalid_instruction;10508 return ira->codegen->invalid_instruction;
1041010509
10411 assert(val->type->id == TypeTableEntryIdPointer);10510 assert(val->type->id == ZigTypeIdPointer);
10412 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, val);10511 ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);
10512 if (pointee == nullptr)
10513 return ira->codegen->invalid_instruction;
10413 if (pointee->special != ConstValSpecialRuntime) {10514 if (pointee->special != ConstValSpecialRuntime) {
10414 ConstExprValue *array_val = create_const_vals(1);10515 ConstExprValue *array_val = create_const_vals(1);
10415 array_val->special = ConstValSpecialStatic;10516 array_val->special = ConstValSpecialStatic;
...@@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa...@@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
10529}10630}
1053010631
10531static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,10632static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
10532 TypeTableEntry *wanted_type, IrInstruction *value)10633 ZigType *wanted_type, IrInstruction *value)
10533{10634{
10534 Error err;10635 Error err;
10535 TypeTableEntry *actual_type = value->value.type;10636 ZigType *actual_type = value->value.type;
10536 AstNode *source_node = source_instr->source_node;10637 AstNode *source_node = source_instr->source_node;
1053710638
10538 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {10639 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...@@ -10547,8 +10648,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10547 }10648 }
1054810649
10549 // widening conversion10650 // widening conversion
10550 if (wanted_type->id == TypeTableEntryIdInt &&10651 if (wanted_type->id == ZigTypeIdInt &&
10551 actual_type->id == TypeTableEntryIdInt &&10652 actual_type->id == ZigTypeIdInt &&
10552 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&10653 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
10553 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)10654 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
10554 {10655 {
...@@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10556 }10657 }
1055710658
10558 // small enough unsigned ints can get casted to large enough signed ints10659 // small enough unsigned ints can get casted to large enough signed ints
10559 if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed &&10660 if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed &&
10560 actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed &&10661 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
10561 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)10662 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
10562 {10663 {
10563 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);10664 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
10564 }10665 }
1056510666
10566 // float widening conversion10667 // float widening conversion
10567 if (wanted_type->id == TypeTableEntryIdFloat &&10668 if (wanted_type->id == ZigTypeIdFloat &&
10568 actual_type->id == TypeTableEntryIdFloat &&10669 actual_type->id == ZigTypeIdFloat &&
10569 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)10670 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
10570 {10671 {
10571 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);10672 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...@@ -10573,9 +10674,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1057310674
1057410675
10575 // cast from [N]T to []const T10676 // cast from [N]T to []const T
10576 if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) {10677 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
10577 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10678 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10578 assert(ptr_type->id == TypeTableEntryIdPointer);10679 assert(ptr_type->id == ZigTypeIdPointer);
10579 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10680 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10580 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10681 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10581 source_node, false).id == ConstCastResultIdOk)10682 source_node, false).id == ConstCastResultIdOk)
...@@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1058610687
10587 // cast from *const [N]T to []const T10688 // cast from *const [N]T to []const T
10588 if (is_slice(wanted_type) &&10689 if (is_slice(wanted_type) &&
10589 actual_type->id == TypeTableEntryIdPointer &&10690 actual_type->id == ZigTypeIdPointer &&
10590 actual_type->data.pointer.is_const &&10691 actual_type->data.pointer.is_const &&
10591 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)10692 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
10592 {10693 {
10593 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10694 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10594 assert(ptr_type->id == TypeTableEntryIdPointer);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
10598 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&10699 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
10599 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type,10700 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...@@ -10604,14 +10705,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10604 }10705 }
1060510706
10606 // cast from [N]T to *const []const T10707 // cast from [N]T to *const []const T
10607 if (wanted_type->id == TypeTableEntryIdPointer &&10708 if (wanted_type->id == ZigTypeIdPointer &&
10608 wanted_type->data.pointer.is_const &&10709 wanted_type->data.pointer.is_const &&
10609 is_slice(wanted_type->data.pointer.child_type) &&10710 is_slice(wanted_type->data.pointer.child_type) &&
10610 actual_type->id == TypeTableEntryIdArray)10711 actual_type->id == ZigTypeIdArray)
10611 {10712 {
10612 TypeTableEntry *ptr_type =10713 ZigType *ptr_type =
10613 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;10714 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);
10615 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10716 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10616 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10717 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10617 source_node, false).id == ConstCastResultIdOk)10718 source_node, false).id == ConstCastResultIdOk)
...@@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10629 }10730 }
1063010731
10631 // cast from [N]T to ?[]const T10732 // cast from [N]T to ?[]const T
10632 if (wanted_type->id == TypeTableEntryIdOptional &&10733 if (wanted_type->id == ZigTypeIdOptional &&
10633 is_slice(wanted_type->data.maybe.child_type) &&10734 is_slice(wanted_type->data.maybe.child_type) &&
10634 actual_type->id == TypeTableEntryIdArray)10735 actual_type->id == ZigTypeIdArray)
10635 {10736 {
10636 TypeTableEntry *ptr_type =10737 ZigType *ptr_type =
10637 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;10738 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);
10639 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10740 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10640 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10741 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10641 source_node, false).id == ConstCastResultIdOk)10742 source_node, false).id == ConstCastResultIdOk)
...@@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10653 }10754 }
1065410755
10655 // *[N]T to [*]T10756 // *[N]T to [*]T
10656 if (wanted_type->id == TypeTableEntryIdPointer &&10757 if (wanted_type->id == ZigTypeIdPointer &&
10657 wanted_type->data.pointer.ptr_len == PtrLenUnknown &&10758 wanted_type->data.pointer.ptr_len == PtrLenUnknown &&
10658 actual_type->id == TypeTableEntryIdPointer &&10759 actual_type->id == ZigTypeIdPointer &&
10659 actual_type->data.pointer.ptr_len == PtrLenSingle &&10760 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 &&
10661 actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&10762 actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&
10662 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,10763 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
10663 actual_type->data.pointer.child_type->data.array.child_type, source_node,10764 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...@@ -10668,12 +10769,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1066810769
10669 // *[N]T to []T10770 // *[N]T to []T
10670 if (is_slice(wanted_type) &&10771 if (is_slice(wanted_type) &&
10671 actual_type->id == TypeTableEntryIdPointer &&10772 actual_type->id == ZigTypeIdPointer &&
10672 actual_type->data.pointer.ptr_len == PtrLenSingle &&10773 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)
10674 {10775 {
10675 TypeTableEntry *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10776 ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10676 assert(slice_ptr_type->id == TypeTableEntryIdPointer);10777 assert(slice_ptr_type->id == ZigTypeIdPointer);
10677 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,10778 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
10678 actual_type->data.pointer.child_type->data.array.child_type, source_node,10779 actual_type->data.pointer.child_type->data.array.child_type, source_node,
10679 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)10780 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)
...@@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1068510786
10686 // cast from T to ?T10787 // cast from T to ?T
10687 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism10788 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism
10688 if (wanted_type->id == TypeTableEntryIdOptional) {10789 if (wanted_type->id == ZigTypeIdOptional) {
10689 TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;10790 ZigType *wanted_child_type = wanted_type->data.maybe.child_type;
10690 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,10791 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
10691 false).id == ConstCastResultIdOk)10792 false).id == ConstCastResultIdOk)
10692 {10793 {
10693 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);10794 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
10694 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||10795 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10695 actual_type->id == TypeTableEntryIdComptimeFloat)10796 actual_type->id == ZigTypeIdComptimeFloat)
10696 {10797 {
10697 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {10798 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
10698 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);10799 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
10699 } else {10800 } else {
10700 return ira->codegen->invalid_instruction;10801 return ira->codegen->invalid_instruction;
10701 }10802 }
10702 } else if (wanted_child_type->id == TypeTableEntryIdPointer &&10803 } else if (wanted_child_type->id == ZigTypeIdPointer &&
10703 wanted_child_type->data.pointer.is_const &&10804 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)))
10705 {10806 {
10706 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);10807 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);
10707 if (type_is_invalid(cast1->value.type))10808 if (type_is_invalid(cast1->value.type))
...@@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1071310814
10714 return cast2;10815 return cast2;
10715 } else if (10816 } else if (
10716 wanted_child_type->id == TypeTableEntryIdPointer &&10817 wanted_child_type->id == ZigTypeIdPointer &&
10717 wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&10818 wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&
10718 actual_type->id == TypeTableEntryIdPointer &&10819 actual_type->id == ZigTypeIdPointer &&
10719 actual_type->data.pointer.ptr_len == PtrLenSingle &&10820 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 &&
10721 actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&10822 actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&
10722 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,10823 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
10723 actual_type->data.pointer.child_type->data.array.child_type, source_node,10824 actual_type->data.pointer.child_type->data.array.child_type, source_node,
10724 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)10825 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
10725 {10826 {
10726 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type);10827 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;
10727 return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type);10830 return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type);
10728 }10831 }
10729 }10832 }
1073010833
10731 // cast from null literal to maybe type10834 // cast from null literal to maybe type
10732 if (wanted_type->id == TypeTableEntryIdOptional &&10835 if (wanted_type->id == ZigTypeIdOptional &&
10733 actual_type->id == TypeTableEntryIdNull)10836 actual_type->id == ZigTypeIdNull)
10734 {10837 {
10735 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);10838 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
10736 }10839 }
1073710840
10738 // cast from child type of error type to error type10841 // cast from child type of error type to error type
10739 if (wanted_type->id == TypeTableEntryIdErrorUnion) {10842 if (wanted_type->id == ZigTypeIdErrorUnion) {
10740 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,10843 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
10741 source_node, false).id == ConstCastResultIdOk)10844 source_node, false).id == ConstCastResultIdOk)
10742 {10845 {
10743 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);10846 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
10744 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||10847 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10745 actual_type->id == TypeTableEntryIdComptimeFloat)10848 actual_type->id == ZigTypeIdComptimeFloat)
10746 {10849 {
10747 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {10850 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
10748 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);10851 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...@@ -10753,13 +10856,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10753 }10856 }
1075410857
10755 // cast from [N]T to E![]const T10858 // cast from [N]T to E![]const T
10756 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10859 if (wanted_type->id == ZigTypeIdErrorUnion &&
10757 is_slice(wanted_type->data.error_union.payload_type) &&10860 is_slice(wanted_type->data.error_union.payload_type) &&
10758 actual_type->id == TypeTableEntryIdArray)10861 actual_type->id == ZigTypeIdArray)
10759 {10862 {
10760 TypeTableEntry *ptr_type =10863 ZigType *ptr_type =
10761 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;10864 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);
10763 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10866 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10764 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10867 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10765 source_node, false).id == ConstCastResultIdOk)10868 source_node, false).id == ConstCastResultIdOk)
...@@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10777 }10880 }
1077810881
10779 // cast from error set to error union type10882 // cast from error set to error union type
10780 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10883 if (wanted_type->id == ZigTypeIdErrorUnion &&
10781 actual_type->id == TypeTableEntryIdErrorSet)10884 actual_type->id == ZigTypeIdErrorSet)
10782 {10885 {
10783 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);10886 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);
10784 }10887 }
1078510888
10786 // cast from T to E!?T10889 // cast from T to E!?T
10787 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10890 if (wanted_type->id == ZigTypeIdErrorUnion &&
10788 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&10891 wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional &&
10789 actual_type->id != TypeTableEntryIdOptional)10892 actual_type->id != ZigTypeIdOptional)
10790 {10893 {
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;
10792 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||10895 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||
10793 actual_type->id == TypeTableEntryIdNull ||10896 actual_type->id == ZigTypeIdNull ||
10794 actual_type->id == TypeTableEntryIdComptimeInt ||10897 actual_type->id == ZigTypeIdComptimeInt ||
10795 actual_type->id == TypeTableEntryIdComptimeFloat)10898 actual_type->id == ZigTypeIdComptimeFloat)
10796 {10899 {
10797 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);10900 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
10798 if (type_is_invalid(cast1->value.type))10901 if (type_is_invalid(cast1->value.type))
...@@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1080810911
10809 // cast from number literal to another type10912 // cast from number literal to another type
10810 // cast from number literal to *const integer10913 // cast from number literal to *const integer
10811 if (actual_type->id == TypeTableEntryIdComptimeFloat ||10914 if (actual_type->id == ZigTypeIdComptimeFloat ||
10812 actual_type->id == TypeTableEntryIdComptimeInt)10915 actual_type->id == ZigTypeIdComptimeInt)
10813 {10916 {
10814 if ((err = ensure_complete_type(ira->codegen, wanted_type)))10917 if ((err = ensure_complete_type(ira->codegen, wanted_type)))
10815 return ira->codegen->invalid_instruction;10918 return ira->codegen->invalid_instruction;
10816 if (wanted_type->id == TypeTableEntryIdEnum) {10919 if (wanted_type->id == ZigTypeIdEnum) {
10817 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);10920 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
10818 if (type_is_invalid(cast1->value.type))10921 if (type_is_invalid(cast1->value.type))
10819 return ira->codegen->invalid_instruction;10922 return ira->codegen->invalid_instruction;
...@@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10823 return ira->codegen->invalid_instruction;10926 return ira->codegen->invalid_instruction;
1082410927
10825 return cast2;10928 return cast2;
10826 } else if (wanted_type->id == TypeTableEntryIdPointer &&10929 } else if (wanted_type->id == ZigTypeIdPointer &&
10827 wanted_type->data.pointer.is_const)10930 wanted_type->data.pointer.is_const)
10828 {10931 {
10829 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);10932 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...@@ -10837,15 +10940,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10837 return cast2;10940 return cast2;
10838 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {10941 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
10839 CastOp op;10942 CastOp op;
10840 if ((actual_type->id == TypeTableEntryIdComptimeFloat &&10943 if ((actual_type->id == ZigTypeIdComptimeFloat &&
10841 wanted_type->id == TypeTableEntryIdFloat) ||10944 wanted_type->id == ZigTypeIdFloat) ||
10842 (actual_type->id == TypeTableEntryIdComptimeInt &&10945 (actual_type->id == ZigTypeIdComptimeInt &&
10843 wanted_type->id == TypeTableEntryIdInt))10946 wanted_type->id == ZigTypeIdInt))
10844 {10947 {
10845 op = CastOpNumLitToConcrete;10948 op = CastOpNumLitToConcrete;
10846 } else if (wanted_type->id == TypeTableEntryIdInt) {10949 } else if (wanted_type->id == ZigTypeIdInt) {
10847 op = CastOpFloatToInt;10950 op = CastOpFloatToInt;
10848 } else if (wanted_type->id == TypeTableEntryIdFloat) {10951 } else if (wanted_type->id == ZigTypeIdFloat) {
10849 op = CastOpIntToFloat;10952 op = CastOpIntToFloat;
10850 } else {10953 } else {
10851 zig_unreachable();10954 zig_unreachable();
...@@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10859 // cast from typed number to integer or float literal.10962 // cast from typed number to integer or float literal.
10860 // works when the number is known at compile time10963 // works when the number is known at compile time
10861 if (instr_is_comptime(value) &&10964 if (instr_is_comptime(value) &&
10862 ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) ||10965 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
10863 (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat)))10966 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
10864 {10967 {
10865 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);10968 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
10866 }10969 }
1086710970
10868 // cast from union to the enum type of the union10971 // 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) {
10870 if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))10973 if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))
10871 return ira->codegen->invalid_instruction;10974 return ira->codegen->invalid_instruction;
1087210975
...@@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10876 }10979 }
1087710980
10878 // enum to union which has the enum as the tag type10981 // 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 &&
10880 (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||10983 (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||
10881 wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))10984 wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
10882 {10985 {
...@@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10889 }10992 }
1089010993
10891 // enum to &const union which has the enum as the tag type10994 // enum to &const union which has the enum as the tag type
10892 if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) {10995 if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) {
10893 TypeTableEntry *union_type = wanted_type->data.pointer.child_type;10996 ZigType *union_type = wanted_type->data.pointer.child_type;
10894 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||10997 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
10895 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)10998 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
10896 {10999 {
...@@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10912 }11015 }
1091311016
10914 // cast from *T to *[1]T11017 // cast from *T to *[1]T
10915 if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&11018 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
10916 actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)11019 actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
10917 {11020 {
10918 TypeTableEntry *array_type = wanted_type->data.pointer.child_type;11021 ZigType *array_type = wanted_type->data.pointer.child_type;
10919 if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 &&11022 if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 &&
10920 types_match_const_cast_only(ira, array_type->data.array.child_type,11023 types_match_const_cast_only(ira, array_type->data.array.child_type,
10921 actual_type->data.pointer.child_type, source_node,11024 actual_type->data.pointer.child_type, source_node,
10922 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)11025 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
...@@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10936 }11039 }
1093711040
10938 // cast from T to *T where T is zero bits11041 // 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 &&
10940 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,11043 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
10941 actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)11044 actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
10942 {11045 {
...@@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1095011053
1095111054
10952 // cast from undefined to anything11055 // cast from undefined to anything
10953 if (actual_type->id == TypeTableEntryIdUndefined) {11056 if (actual_type->id == ZigTypeIdUndefined) {
10954 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);11057 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
10955 }11058 }
1095611059
10957 // cast from something to const pointer of it11060 // cast from something to const pointer of it
10958 if (!type_requires_comptime(actual_type)) {11061 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);
10960 if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) {11063 if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) {
10961 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);11064 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
10962 }11065 }
...@@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10970 return ira->codegen->invalid_instruction;11073 return ira->codegen->invalid_instruction;
10971}11074}
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) {
10974 assert(value);11077 assert(value);
10975 assert(value != ira->codegen->invalid_instruction);11078 assert(value != ira->codegen->invalid_instruction);
10976 assert(!expected_type || !type_is_invalid(expected_type));11079 assert(!expected_type || !type_is_invalid(expected_type));
...@@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ...@@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
10980 return value; // anything will do11083 return value; // anything will do
10981 if (expected_type == value->value.type)11084 if (expected_type == value->value.type)
10982 return value; // match11085 return value; // match
10983 if (value->value.type->id == TypeTableEntryIdUnreachable)11086 if (value->value.type->id == ZigTypeIdUnreachable)
10984 return value;11087 return value;
1098511088
10986 return ir_analyze_cast(ira, value, expected_type, value);11089 return ir_analyze_cast(ira, value, expected_type, value);
10987}11090}
1098811091
10989static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {11092static 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;
10991 if (type_is_invalid(type_entry)) {11094 if (type_is_invalid(type_entry)) {
10992 return ira->codegen->invalid_instruction;11095 return ira->codegen->invalid_instruction;
10993 } else if (type_entry->id == TypeTableEntryIdPointer) {11096 } else if (type_entry->id == ZigTypeIdPointer) {
10994 TypeTableEntry *child_type = type_entry->data.pointer.child_type;11097 ZigType *child_type = type_entry->data.pointer.child_type;
10995 if (instr_is_comptime(ptr)) {11098 if (instr_is_comptime(ptr)) {
10996 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||11099 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||
10997 ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)11100 ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)
10998 {11101 {
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;
11000 if (pointee->special != ConstValSpecialRuntime) {11105 if (pointee->special != ConstValSpecialRuntime) {
11001 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,11106 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
11002 source_instruction->source_node, child_type);11107 source_instruction->source_node, child_type);
...@@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
11019 }11124 }
11020}11125}
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,
11023 bool is_const, bool is_volatile)11128 bool is_const, bool is_volatile)
11024{11129{
11025 IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile);11130 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...@@ -11054,7 +11159,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out
11054 return true;11159 return true;
11055}11160}
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) {
11058 if (type_is_invalid(value->value.type))11163 if (type_is_invalid(value->value.type))
11059 return false;11164 return false;
1106011165
...@@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
11103 return false;11208 return false;
1110411209
11105 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");11210 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
11106 assert(atomic_order_val->type->id == TypeTableEntryIdMetaType);11211 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
11107 TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type;11212 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1110811213
11109 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);11214 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
11110 if (type_is_invalid(casted_value->value.type))11215 if (type_is_invalid(casted_value->value.type))
...@@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
11123 return false;11228 return false;
1112411229
11125 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");11230 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
11126 assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType);11231 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
11127 TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;11232 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1112811233
11129 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);11234 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
11130 if (type_is_invalid(casted_value->value.type))11235 if (type_is_invalid(casted_value->value.type))
...@@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
11143 return false;11248 return false;
1114411249
11145 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");11250 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
11146 assert(global_linkage_val->type->id == TypeTableEntryIdMetaType);11251 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
11147 TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type;11252 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1114811253
11149 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);11254 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
11150 if (type_is_invalid(casted_value->value.type))11255 if (type_is_invalid(casted_value->value.type))
...@@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
11163 return false;11268 return false;
1116411269
11165 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");11270 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
11166 assert(float_mode_val->type->id == TypeTableEntryIdMetaType);11271 assert(float_mode_val->type->id == ZigTypeIdMetaType);
11167 TypeTableEntry *float_mode_type = float_mode_val->data.x_type;11272 ZigType *float_mode_type = float_mode_val->data.x_type;
1116811273
11169 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);11274 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
11170 if (type_is_invalid(casted_value->value.type))11275 if (type_is_invalid(casted_value->value.type))
...@@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
11183 if (type_is_invalid(value->value.type))11288 if (type_is_invalid(value->value.type))
11184 return nullptr;11289 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,
11187 true, false, PtrLenUnknown,11292 true, false, PtrLenUnknown,
11188 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);11293 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);
11190 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);11295 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
11191 if (type_is_invalid(casted_value->value.type))11296 if (type_is_invalid(casted_value->value.type))
11192 return nullptr;11297 return nullptr;
...@@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
11219 return result;11324 return result;
11220}11325}
1122111326
11222static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,11327static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
11223 IrInstructionAddImplicitReturnType *instruction)11328 IrInstructionAddImplicitReturnType *instruction)
11224{11329{
11225 IrInstruction *value = instruction->value->other;11330 IrInstruction *value = instruction->value->other;
...@@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze...@@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
11233 return out_val->type;11338 return out_val->type;
11234}11339}
1123511340
11236static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,11341static ZigType *ir_analyze_instruction_return(IrAnalyze *ira,
11237 IrInstructionReturn *return_instruction)11342 IrInstructionReturn *return_instruction)
11238{11343{
11239 IrInstruction *value = return_instruction->value->other;11344 IrInstruction *value = return_instruction->value->other;
...@@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,...@@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
11245 return ir_unreach_error(ira);11350 return ir_unreach_error(ira);
1124611351
11247 if (casted_value->value.special == ConstValSpecialRuntime &&11352 if (casted_value->value.special == ConstValSpecialRuntime &&
11248 casted_value->value.type->id == TypeTableEntryIdPointer &&11353 casted_value->value.type->id == ZigTypeIdPointer &&
11249 casted_value->value.data.rh_ptr == RuntimeHintPtrStack)11354 casted_value->value.data.rh_ptr == RuntimeHintPtrStack)
11250 {11355 {
11251 ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable"));11356 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,...@@ -11258,13 +11363,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
11258 return ir_finish_anal(ira, result->value.type);11363 return ir_finish_anal(ira, result->value.type);
11259}11364}
1126011365
11261static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {11366static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
11262 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base);11367 ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base);
11263 *out_val = const_instruction->base.value;11368 *out_val = const_instruction->base.value;
11264 return const_instruction->base.value.type;11369 return const_instruction->base.value.type;
11265}11370}
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) {
11268 IrInstruction *op1 = bin_op_instruction->op1->other;11373 IrInstruction *op1 = bin_op_instruction->op1->other;
11269 if (type_is_invalid(op1->value.type))11374 if (type_is_invalid(op1->value.type))
11270 return ira->codegen->builtin_types.entry_invalid;11375 return ira->codegen->builtin_types.entry_invalid;
...@@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
11273 if (type_is_invalid(op2->value.type))11378 if (type_is_invalid(op2->value.type))
11274 return ira->codegen->builtin_types.entry_invalid;11379 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
11278 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);11383 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
11279 if (casted_op1 == ira->codegen->invalid_instruction)11384 if (casted_op1 == ira->codegen->invalid_instruction)
...@@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
11293 if (op2_val == nullptr)11398 if (op2_val == nullptr)
11294 return ira->codegen->builtin_types.entry_invalid;11399 return ira->codegen->builtin_types.entry_invalid;
1129511400
11296 assert(casted_op1->value.type->id == TypeTableEntryIdBool);11401 assert(casted_op1->value.type->id == ZigTypeIdBool);
11297 assert(casted_op2->value.type->id == TypeTableEntryIdBool);11402 assert(casted_op2->value.type->id == ZigTypeIdBool);
11298 if (bin_op_instruction->op_id == IrBinOpBoolOr) {11403 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
11299 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;11404 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;
11300 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {11405 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {
...@@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) {...@@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
11338 }11443 }
11339}11444}
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) {
11342 Error err;11447 Error err;
11343 IrInstruction *op1 = bin_op_instruction->op1->other;11448 IrInstruction *op1 = bin_op_instruction->op1->other;
11344 IrInstruction *op2 = bin_op_instruction->op2->other;11449 IrInstruction *op2 = bin_op_instruction->op2->other;
...@@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11347 IrBinOp op_id = bin_op_instruction->op_id;11452 IrBinOp op_id = bin_op_instruction->op_id;
11348 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);11453 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
11349 if (is_equality_cmp &&11454 if (is_equality_cmp &&
11350 ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) ||11455 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||
11351 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||11456 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) ||
11352 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))11457 (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull)))
11353 {11458 {
11354 if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {11459 if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) {
11355 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);11460 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
11356 out_val->data.x_bool = (op_id == IrBinOpCmpEq);11461 out_val->data.x_bool = (op_id == IrBinOpCmpEq);
11357 return ira->codegen->builtin_types.entry_bool;11462 return ira->codegen->builtin_types.entry_bool;
11358 }11463 }
11359 IrInstruction *maybe_op;11464 IrInstruction *maybe_op;
11360 if (op1->value.type->id == TypeTableEntryIdNull) {11465 if (op1->value.type->id == ZigTypeIdNull) {
11361 maybe_op = op2;11466 maybe_op = op2;
11362 } else if (op2->value.type->id == TypeTableEntryIdNull) {11467 } else if (op2->value.type->id == ZigTypeIdNull) {
11363 maybe_op = op1;11468 maybe_op = op1;
11364 } else {11469 } else {
11365 zig_unreachable();11470 zig_unreachable();
...@@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11386 return ira->codegen->builtin_types.entry_bool;11491 return ira->codegen->builtin_types.entry_bool;
11387 }11492 }
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) {
11390 if (!is_equality_cmp) {11495 if (!is_equality_cmp) {
11391 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));11496 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
11392 return ira->codegen->builtin_types.entry_invalid;11497 return ira->codegen->builtin_types.entry_invalid;
11393 }11498 }
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);
11395 if (type_is_invalid(intersect_type)) {11500 if (type_is_invalid(intersect_type)) {
11396 return ira->codegen->builtin_types.entry_invalid;11501 return ira->codegen->builtin_types.entry_invalid;
11397 }11502 }
...@@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11472 }11577 }
1147311578
11474 IrInstruction *instructions[] = {op1, op2};11579 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);
11476 if (type_is_invalid(resolved_type))11581 if (type_is_invalid(resolved_type))
11477 return resolved_type;11582 return resolved_type;
11478 if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type)))11583 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...@@ -11480,42 +11585,42 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1148011585
11481 bool operator_allowed;11586 bool operator_allowed;
11482 switch (resolved_type->id) {11587 switch (resolved_type->id) {
11483 case TypeTableEntryIdInvalid:11588 case ZigTypeIdInvalid:
11484 zig_unreachable(); // handled above11589 zig_unreachable(); // handled above
1148511590
11486 case TypeTableEntryIdComptimeFloat:11591 case ZigTypeIdComptimeFloat:
11487 case TypeTableEntryIdComptimeInt:11592 case ZigTypeIdComptimeInt:
11488 case TypeTableEntryIdInt:11593 case ZigTypeIdInt:
11489 case TypeTableEntryIdFloat:11594 case ZigTypeIdFloat:
11490 operator_allowed = true;11595 operator_allowed = true;
11491 break;11596 break;
1149211597
11493 case TypeTableEntryIdBool:11598 case ZigTypeIdBool:
11494 case TypeTableEntryIdMetaType:11599 case ZigTypeIdMetaType:
11495 case TypeTableEntryIdVoid:11600 case ZigTypeIdVoid:
11496 case TypeTableEntryIdPointer:11601 case ZigTypeIdPointer:
11497 case TypeTableEntryIdErrorSet:11602 case ZigTypeIdErrorSet:
11498 case TypeTableEntryIdFn:11603 case ZigTypeIdFn:
11499 case TypeTableEntryIdOpaque:11604 case ZigTypeIdOpaque:
11500 case TypeTableEntryIdNamespace:11605 case ZigTypeIdNamespace:
11501 case TypeTableEntryIdBlock:11606 case ZigTypeIdBlock:
11502 case TypeTableEntryIdBoundFn:11607 case ZigTypeIdBoundFn:
11503 case TypeTableEntryIdArgTuple:11608 case ZigTypeIdArgTuple:
11504 case TypeTableEntryIdPromise:11609 case ZigTypeIdPromise:
11505 case TypeTableEntryIdEnum:11610 case ZigTypeIdEnum:
11506 operator_allowed = is_equality_cmp;11611 operator_allowed = is_equality_cmp;
11507 break;11612 break;
1150811613
11509 case TypeTableEntryIdUnreachable:11614 case ZigTypeIdUnreachable:
11510 case TypeTableEntryIdArray:11615 case ZigTypeIdArray:
11511 case TypeTableEntryIdStruct:11616 case ZigTypeIdStruct:
11512 case TypeTableEntryIdUndefined:11617 case ZigTypeIdUndefined:
11513 case TypeTableEntryIdNull:11618 case ZigTypeIdNull:
11514 case TypeTableEntryIdErrorUnion:11619 case ZigTypeIdErrorUnion:
11515 case TypeTableEntryIdUnion:11620 case ZigTypeIdUnion:
11516 operator_allowed = false;11621 operator_allowed = false;
11517 break;11622 break;
11518 case TypeTableEntryIdOptional:11623 case ZigTypeIdOptional:
11519 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;11624 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
11520 break;11625 break;
11521 }11626 }
...@@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11543 return ira->codegen->builtin_types.entry_invalid;11648 return ira->codegen->builtin_types.entry_invalid;
1154411649
11545 bool answer;11650 bool answer;
11546 if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {11651 if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) {
11547 Cmp cmp_result = float_cmp(op1_val, op2_val);11652 Cmp cmp_result = float_cmp(op1_val, op2_val);
11548 answer = resolve_cmp_op_id(op_id, cmp_result);11653 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) {
11550 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);11655 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
11551 answer = resolve_cmp_op_id(op_id, cmp_result);11656 answer = resolve_cmp_op_id(op_id, cmp_result);
11552 } else {11657 } else {
...@@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11566 }11671 }
1156711672
11568 // some comparisons with unsigned numbers can be evaluated11673 // 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) {
11570 ConstExprValue *known_left_val;11675 ConstExprValue *known_left_val;
11571 IrBinOp flipped_op_id;11676 IrBinOp flipped_op_id;
11572 if (instr_is_comptime(casted_op1)) {11677 if (instr_is_comptime(casted_op1)) {
...@@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11610 return ira->codegen->builtin_types.entry_bool;11715 return ira->codegen->builtin_types.entry_bool;
11611}11716}
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,
11614 IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val)11719 IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val)
11615{11720{
11616 bool is_int;11721 bool is_int;
11617 bool is_float;11722 bool is_float;
11618 Cmp op2_zcmp;11723 Cmp op2_zcmp;
11619 if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) {11724 if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) {
11620 is_int = true;11725 is_int = true;
11621 is_float = false;11726 is_float = false;
11622 op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);11727 op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);
11623 } else if (type_entry->id == TypeTableEntryIdFloat ||11728 } else if (type_entry->id == ZigTypeIdFloat ||
11624 type_entry->id == TypeTableEntryIdComptimeFloat)11729 type_entry->id == ZigTypeIdComptimeFloat)
11625 {11730 {
11626 is_int = false;11731 is_int = false;
11627 is_float = true;11732 is_float = true;
...@@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11671 bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);11776 bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
11672 break;11777 break;
11673 case IrBinOpBitShiftLeftLossy:11778 case IrBinOpBitShiftLeftLossy:
11674 assert(type_entry->id == TypeTableEntryIdInt);11779 assert(type_entry->id == ZigTypeIdInt);
11675 bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11780 bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11676 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11781 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11677 break;11782 break;
...@@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11698 }11803 }
11699 break;11804 break;
11700 case IrBinOpAddWrap:11805 case IrBinOpAddWrap:
11701 assert(type_entry->id == TypeTableEntryIdInt);11806 assert(type_entry->id == ZigTypeIdInt);
11702 bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11807 bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11703 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11808 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11704 break;11809 break;
...@@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11710 }11815 }
11711 break;11816 break;
11712 case IrBinOpSubWrap:11817 case IrBinOpSubWrap:
11713 assert(type_entry->id == TypeTableEntryIdInt);11818 assert(type_entry->id == ZigTypeIdInt);
11714 bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11819 bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11715 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11820 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11716 break;11821 break;
...@@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11722 }11827 }
11723 break;11828 break;
11724 case IrBinOpMultWrap:11829 case IrBinOpMultWrap:
11725 assert(type_entry->id == TypeTableEntryIdInt);11830 assert(type_entry->id == ZigTypeIdInt);
11726 bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11831 bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11727 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11832 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11728 break;11833 break;
...@@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11777 break;11882 break;
11778 }11883 }
1177911884
11780 if (type_entry->id == TypeTableEntryIdInt) {11885 if (type_entry->id == ZigTypeIdInt) {
11781 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,11886 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
11782 type_entry->data.integral.is_signed))11887 type_entry->data.integral.is_signed))
11783 {11888 {
...@@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,...@@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
11790 return 0;11895 return 0;
11791}11896}
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) {
11794 IrInstruction *op1 = bin_op_instruction->op1->other;11899 IrInstruction *op1 = bin_op_instruction->op1->other;
11795 if (type_is_invalid(op1->value.type))11900 if (type_is_invalid(op1->value.type))
11796 return ira->codegen->builtin_types.entry_invalid;11901 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) {
11799 ir_add_error(ira, &bin_op_instruction->base,11904 ir_add_error(ira, &bin_op_instruction->base,
11800 buf_sprintf("bit shifting operation expected integer type, found '%s'",11905 buf_sprintf("bit shifting operation expected integer type, found '%s'",
11801 buf_ptr(&op1->value.type->name)));11906 buf_ptr(&op1->value.type->name)));
...@@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *...@@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1180811913
11809 IrInstruction *casted_op2;11914 IrInstruction *casted_op2;
11810 IrBinOp op_id = bin_op_instruction->op_id;11915 IrBinOp op_id = bin_op_instruction->op_id;
11811 if (op1->value.type->id == TypeTableEntryIdComptimeInt) {11916 if (op1->value.type->id == ZigTypeIdComptimeInt) {
11812 casted_op2 = op2;11917 casted_op2 = op2;
1181311918
11814 if (op_id == IrBinOpBitShiftLeftLossy) {11919 if (op_id == IrBinOpBitShiftLeftLossy) {
...@@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *...@@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
11822 return ira->codegen->builtin_types.entry_invalid;11927 return ira->codegen->builtin_types.entry_invalid;
11823 }11928 }
11824 } else {11929 } 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,
11826 op1->value.type->data.integral.bit_count - 1);11931 op1->value.type->data.integral.bit_count - 1);
11827 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&11932 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
11828 op2->value.type->id == TypeTableEntryIdComptimeInt) {11933 op2->value.type->id == ZigTypeIdComptimeInt) {
11829 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,11934 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,
11830 shift_amt_type->data.integral.bit_count,11935 shift_amt_type->data.integral.bit_count,
11831 op2->value.data.x_bigint.is_negative)) {11936 op2->value.data.x_bigint.is_negative)) {
...@@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *...@@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1187911984
11880 ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);11985 ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);
11881 return op1->value.type;11986 return op1->value.type;
11882 } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) {11987 } else if (op1->value.type->id == ZigTypeIdComptimeInt) {
11883 ir_add_error(ira, &bin_op_instruction->base,11988 ir_add_error(ira, &bin_op_instruction->base,
11884 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));11989 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
11885 return ira->codegen->builtin_types.entry_invalid;11990 return ira->codegen->builtin_types.entry_invalid;
...@@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *...@@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
11890 return op1->value.type;11995 return op1->value.type;
11891}11996}
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) {
11894 IrInstruction *op1 = bin_op_instruction->op1->other;11999 IrInstruction *op1 = bin_op_instruction->op1->other;
11895 if (type_is_invalid(op1->value.type))12000 if (type_is_invalid(op1->value.type))
11896 return ira->codegen->builtin_types.entry_invalid;12001 return ira->codegen->builtin_types.entry_invalid;
...@@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
11902 IrBinOp op_id = bin_op_instruction->op_id;12007 IrBinOp op_id = bin_op_instruction->op_id;
1190312008
11904 // look for pointer math12009 // 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 &&
11906 (op_id == IrBinOpAdd || op_id == IrBinOpSub))12011 (op_id == IrBinOpAdd || op_id == IrBinOpSub))
11907 {12012 {
11908 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);12013 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...@@ -11917,19 +12022,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
11917 }12022 }
1191812023
11919 IrInstruction *instructions[] = {op1, op2};12024 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);
11921 if (type_is_invalid(resolved_type))12026 if (type_is_invalid(resolved_type))
11922 return resolved_type;12027 return resolved_type;
1192312028
11924 bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt;12029 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
11925 bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat;12030 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
11926 bool is_signed_div = (12031 bool is_signed_div = (
11927 (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) ||12032 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
11928 resolved_type->id == TypeTableEntryIdFloat ||12033 resolved_type->id == ZigTypeIdFloat ||
11929 (resolved_type->id == TypeTableEntryIdComptimeFloat &&12034 (resolved_type->id == ZigTypeIdComptimeFloat &&
11930 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=12035 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
11931 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||12036 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
11932 (resolved_type->id == TypeTableEntryIdComptimeInt &&12037 (resolved_type->id == ZigTypeIdComptimeInt &&
11933 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=12038 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
11934 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))12039 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
11935 );12040 );
...@@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
12051 return ira->codegen->builtin_types.entry_invalid;12156 return ira->codegen->builtin_types.entry_invalid;
12052 }12157 }
1205312158
12054 if (resolved_type->id == TypeTableEntryIdComptimeInt) {12159 if (resolved_type->id == ZigTypeIdComptimeInt) {
12055 if (op_id == IrBinOpAddWrap) {12160 if (op_id == IrBinOpAddWrap) {
12056 op_id = IrBinOpAdd;12161 op_id = IrBinOpAdd;
12057 } else if (op_id == IrBinOpSubWrap) {12162 } else if (op_id == IrBinOpSubWrap) {
...@@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
12111}12216}
1211212217
1211312218
12114static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {12219static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12115 IrInstruction *op1 = instruction->op1->other;12220 IrInstruction *op1 = instruction->op1->other;
12116 TypeTableEntry *op1_type = op1->value.type;12221 ZigType *op1_type = op1->value.type;
12117 if (type_is_invalid(op1_type))12222 if (type_is_invalid(op1_type))
12118 return ira->codegen->builtin_types.entry_invalid;12223 return ira->codegen->builtin_types.entry_invalid;
1211912224
12120 IrInstruction *op2 = instruction->op2->other;12225 IrInstruction *op2 = instruction->op2->other;
12121 TypeTableEntry *op2_type = op2->value.type;12226 ZigType *op2_type = op2->value.type;
12122 if (type_is_invalid(op2_type))12227 if (type_is_invalid(op2_type))
12123 return ira->codegen->builtin_types.entry_invalid;12228 return ira->codegen->builtin_types.entry_invalid;
1212412229
...@@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12133 ConstExprValue *op1_array_val;12238 ConstExprValue *op1_array_val;
12134 size_t op1_array_index;12239 size_t op1_array_index;
12135 size_t op1_array_end;12240 size_t op1_array_end;
12136 TypeTableEntry *child_type;12241 ZigType *child_type;
12137 if (op1_type->id == TypeTableEntryIdArray) {12242 if (op1_type->id == ZigTypeIdArray) {
12138 child_type = op1_type->data.array.child_type;12243 child_type = op1_type->data.array.child_type;
12139 op1_array_val = op1_val;12244 op1_array_val = op1_val;
12140 op1_array_index = 0;12245 op1_array_index = 0;
12141 op1_array_end = op1_type->data.array.len;12246 op1_array_end = op1_type->data.array.len;
12142 } else if (op1_type->id == TypeTableEntryIdPointer &&12247 } else if (op1_type->id == ZigTypeIdPointer &&
12143 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&12248 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
12144 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&12249 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
12145 op1_val->data.x_ptr.data.base_array.is_cstr)12250 op1_val->data.x_ptr.data.base_array.is_cstr)
...@@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12149 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;12254 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
12150 op1_array_end = op1_array_val->type->data.array.len - 1;12255 op1_array_end = op1_array_val->type->data.array.len - 1;
12151 } else if (is_slice(op1_type)) {12256 } 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;
12153 child_type = ptr_type->data.pointer.child_type;12258 child_type = ptr_type->data.pointer.child_type;
12154 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];12259 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];
12155 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);12260 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
...@@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12165 ConstExprValue *op2_array_val;12270 ConstExprValue *op2_array_val;
12166 size_t op2_array_index;12271 size_t op2_array_index;
12167 size_t op2_array_end;12272 size_t op2_array_end;
12168 if (op2_type->id == TypeTableEntryIdArray) {12273 if (op2_type->id == ZigTypeIdArray) {
12169 if (op2_type->data.array.child_type != child_type) {12274 if (op2_type->data.array.child_type != child_type) {
12170 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12275 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
12171 buf_ptr(&child_type->name),12276 buf_ptr(&child_type->name),
...@@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12175 op2_array_val = op2_val;12280 op2_array_val = op2_val;
12176 op2_array_index = 0;12281 op2_array_index = 0;
12177 op2_array_end = op2_array_val->type->data.array.len;12282 op2_array_end = op2_array_val->type->data.array.len;
12178 } else if (op2_type->id == TypeTableEntryIdPointer &&12283 } else if (op2_type->id == ZigTypeIdPointer &&
12179 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&12284 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
12180 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&12285 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
12181 op2_val->data.x_ptr.data.base_array.is_cstr)12286 op2_val->data.x_ptr.data.base_array.is_cstr)
...@@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12190 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;12295 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
12191 op2_array_end = op2_array_val->type->data.array.len - 1;12296 op2_array_end = op2_array_val->type->data.array.len - 1;
12192 } else if (is_slice(op2_type)) {12297 } 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;
12194 if (ptr_type->data.pointer.child_type != child_type) {12299 if (ptr_type->data.pointer.child_type != child_type) {
12195 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12300 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
12196 buf_ptr(&child_type->name),12301 buf_ptr(&child_type->name),
...@@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1221012315
12211 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12316 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1221212317
12213 TypeTableEntry *result_type;12318 ZigType *result_type;
12214 ConstExprValue *out_array_val;12319 ConstExprValue *out_array_val;
12215 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);12320 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) {
12217 result_type = get_array_type(ira->codegen, child_type, new_len);12322 result_type = get_array_type(ira->codegen, child_type, new_len);
1221812323
12219 out_array_val = out_val;12324 out_array_val = out_val;
12220 } else if (is_slice(op1_type) || is_slice(op2_type)) {12325 } 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,
12222 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);12327 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
12223 result_type = get_slice_type(ira->codegen, ptr_type);12328 result_type = get_slice_type(ira->codegen, ptr_type);
12224 out_array_val = create_const_vals(1);12329 out_array_val = create_const_vals(1);
...@@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
12279 return result_type;12384 return result_type;
12280}12385}
1228112386
12282static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {12387static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12283 IrInstruction *op1 = instruction->op1->other;12388 IrInstruction *op1 = instruction->op1->other;
12284 if (type_is_invalid(op1->value.type))12389 if (type_is_invalid(op1->value.type))
12285 return ira->codegen->builtin_types.entry_invalid;12390 return ira->codegen->builtin_types.entry_invalid;
...@@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp...@@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
12296 if (!ir_resolve_usize(ira, op2, &mult_amt))12401 if (!ir_resolve_usize(ira, op2, &mult_amt))
12297 return ira->codegen->builtin_types.entry_invalid;12402 return ira->codegen->builtin_types.entry_invalid;
1229812403
12299 TypeTableEntry *array_type = op1->value.type;12404 ZigType *array_type = op1->value.type;
12300 if (array_type->id != TypeTableEntryIdArray) {12405 if (array_type->id != ZigTypeIdArray) {
12301 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));12406 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
12302 return ira->codegen->builtin_types.entry_invalid;12407 return ira->codegen->builtin_types.entry_invalid;
12303 }12408 }
...@@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp...@@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
12315 if (array_val->data.x_array.special == ConstArraySpecialUndef) {12420 if (array_val->data.x_array.special == ConstArraySpecialUndef) {
12316 out_val->data.x_array.special = ConstArraySpecialUndef;12421 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;
12319 return get_array_type(ira->codegen, child_type, new_array_len);12424 return get_array_type(ira->codegen, child_type, new_array_len);
12320 }12425 }
1232112426
...@@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp...@@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
12330 }12435 }
12331 assert(i == new_array_len);12436 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;
12334 return get_array_type(ira->codegen, child_type, new_array_len);12439 return get_array_type(ira->codegen, child_type, new_array_len);
12335}12440}
1233612441
12337static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {12442static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
12338 TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other);12443 ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other);
12339 if (type_is_invalid(op1_type))12444 if (type_is_invalid(op1_type))
12340 return ira->codegen->builtin_types.entry_invalid;12445 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);
12343 if (type_is_invalid(op2_type))12448 if (type_is_invalid(op2_type))
12344 return ira->codegen->builtin_types.entry_invalid;12449 return ira->codegen->builtin_types.entry_invalid;
1234512450
...@@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction...@@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
12365 assert(errors[error_entry->value] == nullptr);12470 assert(errors[error_entry->value] == nullptr);
12366 errors[error_entry->value] = error_entry;12471 errors[error_entry->value] = error_entry;
12367 }12472 }
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);
12369 free(errors);12474 free(errors);
1237012475
1237112476
...@@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction...@@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
12374 return ira->codegen->builtin_types.entry_type;12479 return ira->codegen->builtin_types.entry_type;
12375}12480}
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) {
12378 IrBinOp op_id = bin_op_instruction->op_id;12483 IrBinOp op_id = bin_op_instruction->op_id;
12379 switch (op_id) {12484 switch (op_id) {
12380 case IrBinOpInvalid:12485 case IrBinOpInvalid:
...@@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi...@@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi
12421 zig_unreachable();12526 zig_unreachable();
12422}12527}
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) {
12425 Error err;12530 Error err;
12426 VariableTableEntry *var = decl_var_instruction->var;12531 ZigVar *var = decl_var_instruction->var;
1242712532
12428 IrInstruction *init_value = decl_var_instruction->init_value->other;12533 IrInstruction *init_value = decl_var_instruction->init_value->other;
12429 if (type_is_invalid(init_value->value.type)) {12534 if (type_is_invalid(init_value->value.type)) {
...@@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
12431 return var->value->type;12536 return var->value->type;
12432 }12537 }
1243312538
12434 TypeTableEntry *explicit_type = nullptr;12539 ZigType *explicit_type = nullptr;
12435 IrInstruction *var_type = nullptr;12540 IrInstruction *var_type = nullptr;
12436 if (decl_var_instruction->var_type != nullptr) {12541 if (decl_var_instruction->var_type != nullptr) {
12437 var_type = decl_var_instruction->var_type->other;12542 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);
12439 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);12544 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
12440 if (type_is_invalid(explicit_type)) {12545 if (type_is_invalid(explicit_type)) {
12441 var->value->type = ira->codegen->builtin_types.entry_invalid;12546 var->value->type = ira->codegen->builtin_types.entry_invalid;
...@@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1245012555
12451 bool var_class_requires_const = false;12556 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;
12454 if (type_is_invalid(result_type)) {12559 if (type_is_invalid(result_type)) {
12455 result_type = ira->codegen->builtin_types.entry_invalid;12560 result_type = ira->codegen->builtin_types.entry_invalid;
12456 } else {12561 } else {
...@@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
12460 }12565 }
1246112566
12462 if (!type_is_invalid(result_type)) {12567 if (!type_is_invalid(result_type)) {
12463 if (result_type->id == TypeTableEntryIdUnreachable ||12568 if (result_type->id == ZigTypeIdUnreachable ||
12464 result_type->id == TypeTableEntryIdOpaque)12569 result_type->id == ZigTypeIdOpaque)
12465 {12570 {
12466 ir_add_error_node(ira, source_node,12571 ir_add_error_node(ira, source_node,
12467 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));12572 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...@@ -12476,7 +12581,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
12476 }12581 }
12477 } else {12582 } else {
12478 if (casted_init_value->value.special == ConstValSpecialStatic &&12583 if (casted_init_value->value.special == ConstValSpecialStatic &&
12479 casted_init_value->value.type->id == TypeTableEntryIdFn &&12584 casted_init_value->value.type->id == ZigTypeIdFn &&
12480 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)12585 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
12481 {12586 {
12482 var_class_requires_const = true;12587 var_class_requires_const = true;
...@@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
12496 // This means that this is actually a different variable due to, e.g. an inline while loop.12601 // This means that this is actually a different variable due to, e.g. an inline while loop.
12497 // We make a new variable so that it can hold a different type, and so the debug info can12602 // We make a new variable so that it can hold a different type, and so the debug info can
12498 // be distinct.12603 // 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,
12500 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);12605 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);
12501 new_var->owner_exec = var->owner_exec;12606 new_var->owner_exec = var->owner_exec;
12502 new_var->align_bytes = var->align_bytes;12607 new_var->align_bytes = var->align_bytes;
...@@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1254912654
12550 ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value);12655 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);
12553 if (fn_entry)12658 if (fn_entry)
12554 fn_entry->variable_list.append(var);12659 fn_entry->variable_list.append(var);
1255512660
12556 return ira->codegen->builtin_types.entry_void;12661 return ira->codegen->builtin_types.entry_void;
12557}12662}
1255812663
12559static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {12664static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
12560 IrInstruction *name = instruction->name->other;12665 IrInstruction *name = instruction->name->other;
12561 Buf *symbol_name = ir_resolve_str(ira, name);12666 Buf *symbol_name = ir_resolve_str(ira, name);
12562 if (symbol_name == nullptr) {12667 if (symbol_name == nullptr) {
...@@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12585 }12690 }
1258612691
12587 switch (target->value.type->id) {12692 switch (target->value.type->id) {
12588 case TypeTableEntryIdInvalid:12693 case ZigTypeIdInvalid:
12589 case TypeTableEntryIdUnreachable:12694 case ZigTypeIdUnreachable:
12590 zig_unreachable();12695 zig_unreachable();
12591 case TypeTableEntryIdFn: {12696 case ZigTypeIdFn: {
12592 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);12697 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;
12594 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;12699 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
12595 switch (cc) {12700 switch (cc) {
12596 case CallingConventionUnspecified: {12701 case CallingConventionUnspecified: {
...@@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12611 break;12716 break;
12612 }12717 }
12613 } break;12718 } break;
12614 case TypeTableEntryIdStruct:12719 case ZigTypeIdStruct:
12615 if (is_slice(target->value.type)) {12720 if (is_slice(target->value.type)) {
12616 ir_add_error(ira, target,12721 ir_add_error(ira, target,
12617 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));12722 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...@@ -12621,26 +12726,26 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12621 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));12726 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));
12622 }12727 }
12623 break;12728 break;
12624 case TypeTableEntryIdUnion:12729 case ZigTypeIdUnion:
12625 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {12730 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {
12626 ErrorMsg *msg = ir_add_error(ira, target,12731 ErrorMsg *msg = ir_add_error(ira, target,
12627 buf_sprintf("exported union value must be declared extern"));12732 buf_sprintf("exported union value must be declared extern"));
12628 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));12733 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));
12629 }12734 }
12630 break;12735 break;
12631 case TypeTableEntryIdEnum:12736 case ZigTypeIdEnum:
12632 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {12737 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {
12633 ErrorMsg *msg = ir_add_error(ira, target,12738 ErrorMsg *msg = ir_add_error(ira, target,
12634 buf_sprintf("exported enum value must be declared extern"));12739 buf_sprintf("exported enum value must be declared extern"));
12635 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));12740 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));
12636 }12741 }
12637 break;12742 break;
12638 case TypeTableEntryIdMetaType: {12743 case ZigTypeIdMetaType: {
12639 TypeTableEntry *type_value = target->value.data.x_type;12744 ZigType *type_value = target->value.data.x_type;
12640 switch (type_value->id) {12745 switch (type_value->id) {
12641 case TypeTableEntryIdInvalid:12746 case ZigTypeIdInvalid:
12642 zig_unreachable();12747 zig_unreachable();
12643 case TypeTableEntryIdStruct:12748 case ZigTypeIdStruct:
12644 if (is_slice(type_value)) {12749 if (is_slice(type_value)) {
12645 ir_add_error(ira, target,12750 ir_add_error(ira, target,
12646 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));12751 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...@@ -12650,73 +12755,73 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12650 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));12755 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
12651 }12756 }
12652 break;12757 break;
12653 case TypeTableEntryIdUnion:12758 case ZigTypeIdUnion:
12654 if (type_value->data.unionation.layout != ContainerLayoutExtern) {12759 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
12655 ErrorMsg *msg = ir_add_error(ira, target,12760 ErrorMsg *msg = ir_add_error(ira, target,
12656 buf_sprintf("exported union must be declared extern"));12761 buf_sprintf("exported union must be declared extern"));
12657 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));12762 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
12658 }12763 }
12659 break;12764 break;
12660 case TypeTableEntryIdEnum:12765 case ZigTypeIdEnum:
12661 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {12766 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
12662 ErrorMsg *msg = ir_add_error(ira, target,12767 ErrorMsg *msg = ir_add_error(ira, target,
12663 buf_sprintf("exported enum must be declared extern"));12768 buf_sprintf("exported enum must be declared extern"));
12664 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));12769 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
12665 }12770 }
12666 break;12771 break;
12667 case TypeTableEntryIdFn: {12772 case ZigTypeIdFn: {
12668 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {12773 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
12669 ir_add_error(ira, target,12774 ir_add_error(ira, target,
12670 buf_sprintf("exported function type must specify calling convention"));12775 buf_sprintf("exported function type must specify calling convention"));
12671 }12776 }
12672 } break;12777 } break;
12673 case TypeTableEntryIdInt:12778 case ZigTypeIdInt:
12674 case TypeTableEntryIdFloat:12779 case ZigTypeIdFloat:
12675 case TypeTableEntryIdPointer:12780 case ZigTypeIdPointer:
12676 case TypeTableEntryIdArray:12781 case ZigTypeIdArray:
12677 case TypeTableEntryIdBool:12782 case ZigTypeIdBool:
12678 break;12783 break;
12679 case TypeTableEntryIdMetaType:12784 case ZigTypeIdMetaType:
12680 case TypeTableEntryIdVoid:12785 case ZigTypeIdVoid:
12681 case TypeTableEntryIdUnreachable:12786 case ZigTypeIdUnreachable:
12682 case TypeTableEntryIdComptimeFloat:12787 case ZigTypeIdComptimeFloat:
12683 case TypeTableEntryIdComptimeInt:12788 case ZigTypeIdComptimeInt:
12684 case TypeTableEntryIdUndefined:12789 case ZigTypeIdUndefined:
12685 case TypeTableEntryIdNull:12790 case ZigTypeIdNull:
12686 case TypeTableEntryIdOptional:12791 case ZigTypeIdOptional:
12687 case TypeTableEntryIdErrorUnion:12792 case ZigTypeIdErrorUnion:
12688 case TypeTableEntryIdErrorSet:12793 case ZigTypeIdErrorSet:
12689 case TypeTableEntryIdNamespace:12794 case ZigTypeIdNamespace:
12690 case TypeTableEntryIdBlock:12795 case ZigTypeIdBlock:
12691 case TypeTableEntryIdBoundFn:12796 case ZigTypeIdBoundFn:
12692 case TypeTableEntryIdArgTuple:12797 case ZigTypeIdArgTuple:
12693 case TypeTableEntryIdOpaque:12798 case ZigTypeIdOpaque:
12694 case TypeTableEntryIdPromise:12799 case ZigTypeIdPromise:
12695 ir_add_error(ira, target,12800 ir_add_error(ira, target,
12696 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));12801 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
12697 break;12802 break;
12698 }12803 }
12699 } break;12804 } break;
12700 case TypeTableEntryIdVoid:12805 case ZigTypeIdVoid:
12701 case TypeTableEntryIdBool:12806 case ZigTypeIdBool:
12702 case TypeTableEntryIdInt:12807 case ZigTypeIdInt:
12703 case TypeTableEntryIdFloat:12808 case ZigTypeIdFloat:
12704 case TypeTableEntryIdPointer:12809 case ZigTypeIdPointer:
12705 case TypeTableEntryIdArray:12810 case ZigTypeIdArray:
12706 case TypeTableEntryIdComptimeFloat:12811 case ZigTypeIdComptimeFloat:
12707 case TypeTableEntryIdComptimeInt:12812 case ZigTypeIdComptimeInt:
12708 case TypeTableEntryIdUndefined:12813 case ZigTypeIdUndefined:
12709 case TypeTableEntryIdNull:12814 case ZigTypeIdNull:
12710 case TypeTableEntryIdOptional:12815 case ZigTypeIdOptional:
12711 case TypeTableEntryIdErrorUnion:12816 case ZigTypeIdErrorUnion:
12712 case TypeTableEntryIdErrorSet:12817 case ZigTypeIdErrorSet:
12713 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));12818 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
12714 case TypeTableEntryIdNamespace:12819 case ZigTypeIdNamespace:
12715 case TypeTableEntryIdBlock:12820 case ZigTypeIdBlock:
12716 case TypeTableEntryIdBoundFn:12821 case ZigTypeIdBoundFn:
12717 case TypeTableEntryIdArgTuple:12822 case ZigTypeIdArgTuple:
12718 case TypeTableEntryIdOpaque:12823 case ZigTypeIdOpaque:
12719 case TypeTableEntryIdPromise:12824 case ZigTypeIdPromise:
12720 ir_add_error(ira, target,12825 ir_add_error(ira, target,
12721 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));12826 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
12722 break;12827 break;
...@@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12727}12832}
1272812833
12729static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {12834static 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);
12731 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;12836 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
12732}12837}
1273312838
12734static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,12839static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
12735 IrInstructionErrorReturnTrace *instruction)12840 IrInstructionErrorReturnTrace *instruction)
12736{12841{
12737 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {12842 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
12738 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);12843 ZigType *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);12844 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
12740 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {12845 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
12741 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12846 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
12742 assert(get_codegen_ptr_type(optional_type) != nullptr);12847 assert(get_codegen_ptr_type(optional_type) != nullptr);
...@@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
12757 }12862 }
12758}12863}
1275912864
12760static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,12865static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira,
12761 IrInstructionErrorUnion *instruction)12866 IrInstructionErrorUnion *instruction)
12762{12867{
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);
12764 if (type_is_invalid(err_set_type))12869 if (type_is_invalid(err_set_type))
12765 return ira->codegen->builtin_types.entry_invalid;12870 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);
12768 if (type_is_invalid(payload_type))12873 if (type_is_invalid(payload_type))
12769 return ira->codegen->builtin_types.entry_invalid;12874 return ira->codegen->builtin_types.entry_invalid;
1277012875
12771 if (err_set_type->id != TypeTableEntryIdErrorSet) {12876 if (err_set_type->id != ZigTypeIdErrorSet) {
12772 ir_add_error(ira, instruction->err_set->other,12877 ir_add_error(ira, instruction->err_set->other,
12773 buf_sprintf("expected error set type, found type '%s'",12878 buf_sprintf("expected error set type, found type '%s'",
12774 buf_ptr(&err_set_type->name)));12879 buf_ptr(&err_set_type->name)));
12775 return ira->codegen->builtin_types.entry_invalid;12880 return ira->codegen->builtin_types.entry_invalid;
12776 }12881 }
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
12780 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12885 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
12781 out_val->data.x_type = result_type;12886 out_val->data.x_type = result_type;
...@@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
12783}12888}
1278412889
12785IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) {12890IrInstruction *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);
12787 if (parent_fn_entry == nullptr) {12892 if (parent_fn_entry == nullptr) {
12788 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));12893 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
12789 return ira->codegen->invalid_instruction;12894 return ira->codegen->invalid_instruction;
...@@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i...@@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
12807 }12912 }
12808 case ImplicitAllocatorIdLocalVar:12913 case ImplicitAllocatorIdLocalVar:
12809 {12914 {
12810 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;12915 ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
12811 assert(coro_allocator_var != nullptr);12916 assert(coro_allocator_var != nullptr);
12812 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);12917 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
12813 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);12918 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...@@ -12818,38 +12923,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
12818 zig_unreachable();12923 zig_unreachable();
12819}12924}
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,
12822 IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst)12927 IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst)
12823{12928{
12824 Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);12929 Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);
12825 //Buf *free_field_name = buf_create_from_str("freeFn");12930 //Buf *free_field_name = buf_create_from_str("freeFn");
12826 assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer);12931 assert(async_allocator_inst->value.type->id == ZigTypeIdPointer);
12827 TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type;12932 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
12828 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,12933 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,
12829 async_allocator_inst, container_type);12934 async_allocator_inst, container_type);
12830 if (type_is_invalid(field_ptr_inst->value.type)) {12935 if (type_is_invalid(field_ptr_inst->value.type)) {
12831 return ira->codegen->invalid_instruction;12936 return ira->codegen->invalid_instruction;
12832 }12937 }
12833 TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type;12938 ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
12834 assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer);12939 assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer);
1283512940
12836 TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;12941 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
12837 if (alloc_fn_type->id != TypeTableEntryIdFn) {12942 if (alloc_fn_type->id != ZigTypeIdFn) {
12838 ir_add_error(ira, &call_instruction->base,12943 ir_add_error(ira, &call_instruction->base,
12839 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));12944 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));
12840 return ira->codegen->invalid_instruction;12945 return ira->codegen->invalid_instruction;
12841 }12946 }
1284212947
12843 TypeTableEntry *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;12948 ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
12844 if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) {12949 if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) {
12845 ir_add_error(ira, fn_ref,12950 ir_add_error(ira, fn_ref,
12846 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));12951 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));
12847 return ira->codegen->invalid_instruction;12952 return ira->codegen->invalid_instruction;
12848 }12953 }
12849 TypeTableEntry *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type;12954 ZigType *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;12955 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
12851 TypeTableEntry *promise_type = get_promise_type(ira->codegen, return_type);12956 ZigType *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);12957 ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
1285312958
12854 IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node,12959 IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node,
12855 fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr);12960 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...@@ -12866,7 +12971,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
12866 IrInstruction *casted_arg;12971 IrInstruction *casted_arg;
12867 if (param_decl_node->data.param_decl.var_token == nullptr) {12972 if (param_decl_node->data.param_decl.var_token == nullptr) {
12868 AstNode *param_type_node = param_decl_node->data.param_decl.type;12973 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);
12870 if (type_is_invalid(param_type))12975 if (type_is_invalid(param_type))
12871 return false;12976 return false;
1287212977
...@@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
12882 return false;12987 return false;
1288312988
12884 Buf *param_name = param_decl_node->data.param_decl.name;12989 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,
12886 *exec_scope, param_name, true, arg_val, nullptr);12991 *exec_scope, param_name, true, arg_val, nullptr);
12887 *exec_scope = var->child_scope;12992 *exec_scope = var->child_scope;
12888 *next_proto_i += 1;12993 *next_proto_i += 1;
...@@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
12893static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,12998static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
12894 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,12999 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,
12895 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,13000 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,
12896 FnTableEntry *impl_fn)13001 ZigFn *impl_fn)
12897{13002{
12898 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);13003 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
12899 assert(param_decl_node->type == NodeTypeParamDecl);13004 assert(param_decl_node->type == NodeTypeParamDecl);
...@@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12906 } else {13011 } else {
12907 if (param_decl_node->data.param_decl.var_token == nullptr) {13012 if (param_decl_node->data.param_decl.var_token == nullptr) {
12908 AstNode *param_type_node = param_decl_node->data.param_decl.type;13013 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);
12910 if (type_is_invalid(param_type))13015 if (type_is_invalid(param_type))
12911 return false;13016 return false;
1291213017
...@@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12920 }13025 }
1292113026
12922 bool comptime_arg = param_decl_node->data.param_decl.is_inline ||13027 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
12925 ConstExprValue *arg_val;13030 ConstExprValue *arg_val;
1292613031
...@@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12940 Buf *param_name = param_decl_node->data.param_decl.name;13045 Buf *param_name = param_decl_node->data.param_decl.name;
12941 if (!param_name) return false;13046 if (!param_name) return false;
12942 if (!is_var_args) {13047 if (!is_var_args) {
12943 VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,13048 ZigVar *var = add_variable(ira->codegen, param_decl_node,
12944 *child_scope, param_name, true, arg_val, nullptr);13049 *child_scope, param_name, true, arg_val, nullptr);
12945 *child_scope = var->child_scope;13050 *child_scope = var->child_scope;
12946 var->shadowable = !comptime_arg;13051 var->shadowable = !comptime_arg;
1294713052
12948 *next_proto_i += 1;13053 *next_proto_i += 1;
12949 } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt ||13054 } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||
12950 casted_arg->value.type->id == TypeTableEntryIdComptimeFloat)13055 casted_arg->value.type->id == ZigTypeIdComptimeFloat)
12951 {13056 {
12952 ir_add_error(ira, casted_arg,13057 ir_add_error(ira, casted_arg,
12953 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));13058 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...@@ -12972,7 +13077,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12972 return true;13077 return true;
12973}13078}
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) {
12976 size_t next_var_i = 0;13081 size_t next_var_i = 0;
12977 FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;13082 FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;
12978 assert(gen_param_info != nullptr);13083 assert(gen_param_info != nullptr);
...@@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in...@@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
12991}13096}
1299213097
12993static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,13098static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12994 VariableTableEntry *var)13099 ZigVar *var)
12995{13100{
12996 Error err;13101 Error err;
12997 while (var->next_var != nullptr) {13102 while (var->next_var != nullptr) {
...@@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13002 assert(ira->codegen->errors.length != 0);13107 assert(ira->codegen->errors.length != 0);
13003 return ira->codegen->invalid_instruction;13108 return ira->codegen->invalid_instruction;
13004 }13109 }
13005 assert(var->value->type);13110 if (var->value->type == nullptr || type_is_invalid(var->value->type))
13006 if (type_is_invalid(var->value->type))
13007 return ira->codegen->invalid_instruction;13111 return ira->codegen->invalid_instruction;
1300813112
13009 bool comptime_var_mem = ir_get_var_is_comptime(var);13113 bool comptime_var_mem = ir_get_var_is_comptime(var);
...@@ -13061,8 +13165,8 @@ no_mem_slot:...@@ -13061,8 +13165,8 @@ no_mem_slot:
13061 return var_ptr_instruction;13165 return var_ptr_instruction;
13062}13166}
1306313167
13064static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,13168static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,
13065 FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref,13169 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
13066 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)13170 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)
13067{13171{
13068 Error err;13172 Error err;
...@@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13082 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;13186 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
13083 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {13187 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
13084 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value;13188 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) {
13086 call_param_count -= 1;13190 call_param_count -= 1;
13087 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -13191 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
13088 arg_tuple_value->data.x_arg_tuple.start_index;13192 arg_tuple_value->data.x_arg_tuple.start_index;
...@@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1315013254
13151 size_t next_proto_i = 0;13255 size_t next_proto_i = 0;
13152 if (first_arg_ptr) {13256 if (first_arg_ptr) {
13153 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);13257 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1315413258
13155 bool first_arg_known_bare = false;13259 bool first_arg_known_bare = false;
13156 if (fn_type_id->next_param_index >= 1) {13260 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;
13158 if (type_is_invalid(param_type))13262 if (type_is_invalid(param_type))
13159 return ira->codegen->builtin_types.entry_invalid;13263 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;
13161 }13265 }
1316213266
13163 IrInstruction *first_arg;13267 IrInstruction *first_arg;
...@@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13190 }13294 }
1319113295
13192 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;13296 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);
13194 if (type_is_invalid(specified_return_type))13298 if (type_is_invalid(specified_return_type))
13195 return ira->codegen->builtin_types.entry_invalid;13299 return ira->codegen->builtin_types.entry_invalid;
13196 TypeTableEntry *return_type;13300 ZigType *return_type;
13197 TypeTableEntry *inferred_err_set_type = nullptr;13301 ZigType *inferred_err_set_type = nullptr;
13198 if (fn_proto_node->data.fn_proto.auto_err_set) {13302 if (fn_proto_node->data.fn_proto.auto_err_set) {
13199 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);13303 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
13200 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);13304 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...@@ -13219,16 +13323,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1321913323
13220 if (inferred_err_set_type != nullptr) {13324 if (inferred_err_set_type != nullptr) {
13221 inferred_err_set_type->data.error_set.infer_fn = nullptr;13325 inferred_err_set_type->data.error_set.infer_fn = nullptr;
13222 if (result->value.type->id == TypeTableEntryIdErrorUnion) {13326 if (result->value.type->id == ZigTypeIdErrorUnion) {
13223 if (result->value.data.x_err_union.err != nullptr) {13327 if (result->value.data.x_err_union.err != nullptr) {
13224 inferred_err_set_type->data.error_set.err_count = 1;13328 inferred_err_set_type->data.error_set.err_count = 1;
13225 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);13329 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
13226 inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err;13330 inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err;
13227 }13331 }
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;
13229 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;13333 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;
13230 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;13334 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) {
13232 inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;13336 inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;
13233 inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;13337 inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;
13234 }13338 }
...@@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1324913353
13250 IrInstruction *casted_new_stack = nullptr;13354 IrInstruction *casted_new_stack = nullptr;
13251 if (call_instruction->new_stack != nullptr) {13355 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,
13253 false, false, PtrLenUnknown,13357 false, false, PtrLenUnknown,
13254 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);13358 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);
13256 IrInstruction *new_stack = call_instruction->new_stack->other;13360 IrInstruction *new_stack = call_instruction->new_stack->other;
13257 if (type_is_invalid(new_stack->value.type))13361 if (type_is_invalid(new_stack->value.type))
13258 return ira->codegen->builtin_types.entry_invalid;13362 return ira->codegen->builtin_types.entry_invalid;
...@@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13276 if (type_is_invalid(arg->value.type))13380 if (type_is_invalid(arg->value.type))
13277 return ira->codegen->builtin_types.entry_invalid;13381 return ira->codegen->builtin_types.entry_invalid;
1327813382
13279 if (arg->value.type->id == TypeTableEntryIdArgTuple) {13383 if (arg->value.type->id == ZigTypeIdArgTuple) {
13280 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;13384 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;
13281 } else {13385 } else {
13282 new_fn_arg_count += 1;13386 new_fn_arg_count += 1;
...@@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1328713391
13288 // Fork a scope of the function with known values for the parameters.13392 // Fork a scope of the function with known values for the parameters.
13289 Scope *parent_scope = fn_entry->fndef_scope->base.parent;13393 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);
13291 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);13395 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
13292 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);13396 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
13293 impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn);13397 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...@@ -13306,14 +13410,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13306 size_t next_proto_i = 0;13410 size_t next_proto_i = 0;
1330713411
13308 if (first_arg_ptr) {13412 if (first_arg_ptr) {
13309 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);13413 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1331013414
13311 bool first_arg_known_bare = false;13415 bool first_arg_known_bare = false;
13312 if (fn_type_id->next_param_index >= 1) {13416 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;
13314 if (type_is_invalid(param_type))13418 if (type_is_invalid(param_type))
13315 return ira->codegen->builtin_types.entry_invalid;13419 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;
13317 }13421 }
1331813422
13319 IrInstruction *first_arg;13423 IrInstruction *first_arg;
...@@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13335 bool found_first_var_arg = false;13439 bool found_first_var_arg = false;
13336 size_t first_var_arg;13440 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);
13339 assert(parent_fn_entry);13443 assert(parent_fn_entry);
13340 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {13444 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
13341 IrInstruction *arg = call_instruction->args[call_i]->other;13445 IrInstruction *arg = call_instruction->args[call_i]->other;
13342 if (type_is_invalid(arg->value.type))13446 if (type_is_invalid(arg->value.type))
13343 return ira->codegen->builtin_types.entry_invalid;13447 return ira->codegen->builtin_types.entry_invalid;
1334413448
13345 if (arg->value.type->id == TypeTableEntryIdArgTuple) {13449 if (arg->value.type->id == ZigTypeIdArgTuple) {
13346 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;13450 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;
13347 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)13451 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
13348 {13452 {
...@@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13354 found_first_var_arg = true;13458 found_first_var_arg = true;
13355 }13459 }
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);
13358 if (arg_var == nullptr) {13462 if (arg_var == nullptr) {
13359 ir_add_error(ira, arg,13463 ir_add_error(ira, arg,
13360 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));13464 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...@@ -13401,7 +13505,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1340113505
13402 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,13506 ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,
13403 first_var_arg, inst_fn_type_id.param_count);13507 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,
13405 impl_fn->child_scope, param_name, true, var_args_val, nullptr);13509 impl_fn->child_scope, param_name, true, var_args_val, nullptr);
13406 impl_fn->child_scope = var->child_scope;13510 impl_fn->child_scope = var->child_scope;
13407 }13511 }
...@@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1342013524
13421 if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {13525 if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
13422 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;13526 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);
13424 if (type_is_invalid(specified_return_type))13528 if (type_is_invalid(specified_return_type))
13425 return ira->codegen->builtin_types.entry_invalid;13529 return ira->codegen->builtin_types.entry_invalid;
13426 if (fn_proto_node->data.fn_proto.auto_err_set) {13530 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);
13428 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);13532 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
13429 } else {13533 } else {
13430 inst_fn_type_id.return_type = specified_return_type;13534 inst_fn_type_id.return_type = specified_return_type;
...@@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13442 if (call_instruction->is_async) {13546 if (call_instruction->is_async) {
13443 AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;13547 AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;
13444 if (async_allocator_type_node != nullptr) {13548 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);
13446 if (type_is_invalid(async_allocator_type))13550 if (type_is_invalid(async_allocator_type))
13447 return ira->codegen->builtin_types.entry_invalid;13551 return ira->codegen->builtin_types.entry_invalid;
13448 inst_fn_type_id.async_allocator_type = async_allocator_type;13552 inst_fn_type_id.async_allocator_type = async_allocator_type;
...@@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13486 ira->codegen->fn_defs.append(impl_fn);13590 ira->codegen->fn_defs.append(impl_fn);
13487 }13591 }
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;
13490 if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) {13594 if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) {
13491 parent_fn_entry->calls_or_awaits_errorable_fn = true;13595 parent_fn_entry->calls_or_awaits_errorable_fn = true;
13492 }13596 }
...@@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13510 return ir_finish_anal(ira, return_type);13614 return ir_finish_anal(ira, return_type);
13511 }13615 }
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);
13514 assert(fn_type_id->return_type != nullptr);13618 assert(fn_type_id->return_type != nullptr);
13515 assert(parent_fn_entry != nullptr);13619 assert(parent_fn_entry != nullptr);
13516 if (fn_type_can_fail(fn_type_id)) {13620 if (fn_type_can_fail(fn_type_id)) {
...@@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13521 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);13625 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
13522 size_t next_arg_index = 0;13626 size_t next_arg_index = 0;
13523 if (first_arg_ptr) {13627 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;
13527 if (type_is_invalid(param_type))13631 if (type_is_invalid(param_type))
13528 return ira->codegen->builtin_types.entry_invalid;13632 return ira->codegen->builtin_types.entry_invalid;
1352913633
13530 IrInstruction *first_arg;13634 IrInstruction *first_arg;
13531 if (param_type->id == TypeTableEntryIdPointer &&13635 if (param_type->id == ZigTypeIdPointer &&
13532 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))13636 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
13533 {13637 {
13534 first_arg = first_arg_ptr;13638 first_arg = first_arg_ptr;
...@@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13551 return ira->codegen->builtin_types.entry_invalid;13655 return ira->codegen->builtin_types.entry_invalid;
13552 IrInstruction *casted_arg;13656 IrInstruction *casted_arg;
13553 if (next_arg_index < src_param_count) {13657 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;
13555 if (type_is_invalid(param_type))13659 if (type_is_invalid(param_type))
13556 return ira->codegen->builtin_types.entry_invalid;13660 return ira->codegen->builtin_types.entry_invalid;
13557 casted_arg = ir_implicit_cast(ira, old_arg, param_type);13661 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
...@@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1356713671
13568 assert(next_arg_index == call_param_count);13672 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;
13571 if (type_is_invalid(return_type))13675 if (type_is_invalid(return_type))
13572 return ira->codegen->builtin_types.entry_invalid;13676 return ira->codegen->builtin_types.entry_invalid;
1357313677
...@@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13595 return ir_finish_anal(ira, result->value.type);13699 return ir_finish_anal(ira, result->value.type);
13596 }13700 }
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
13599 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,13708 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
13600 fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack);13709 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...@@ -13603,7 +13712,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
13603 return ir_finish_anal(ira, return_type);13712 return ir_finish_anal(ira, return_type);
13604}13713}
1360513714
13606static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {13715static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
13607 IrInstruction *fn_ref = call_instruction->fn_ref->other;13716 IrInstruction *fn_ref = call_instruction->fn_ref->other;
13608 if (type_is_invalid(fn_ref->value.type))13717 if (type_is_invalid(fn_ref->value.type))
13609 return ira->codegen->builtin_types.entry_invalid;13718 return ira->codegen->builtin_types.entry_invalid;
...@@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
13612 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);13721 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
1361313722
13614 if (is_comptime || instr_is_comptime(fn_ref)) {13723 if (is_comptime || instr_is_comptime(fn_ref)) {
13615 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {13724 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
13616 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);13725 ZigType *dest_type = ir_resolve_type(ira, fn_ref);
13617 if (type_is_invalid(dest_type))13726 if (type_is_invalid(dest_type))
13618 return ira->codegen->builtin_types.entry_invalid;13727 return ira->codegen->builtin_types.entry_invalid;
1361913728
...@@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1363313742
13634 ir_link_new_instruction(cast_instruction, &call_instruction->base);13743 ir_link_new_instruction(cast_instruction, &call_instruction->base);
13635 return ir_finish_anal(ira, cast_instruction->value.type);13744 return ir_finish_anal(ira, cast_instruction->value.type);
13636 } else if (fn_ref->value.type->id == TypeTableEntryIdFn) {13745 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
13637 FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);13746 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
13638 if (fn_table_entry == nullptr)13747 if (fn_table_entry == nullptr)
13639 return ira->codegen->builtin_types.entry_invalid;13748 return ira->codegen->builtin_types.entry_invalid;
13640 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,13749 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
13641 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);13750 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) {
13643 assert(fn_ref->value.special == ConstValSpecialStatic);13752 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;
13645 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;13754 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;
13646 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,13755 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
13647 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);13756 fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);
...@@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
13652 }13761 }
13653 }13762 }
1365413763
13655 if (fn_ref->value.type->id == TypeTableEntryIdFn) {13764 if (fn_ref->value.type->id == ZigTypeIdFn) {
13656 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,13765 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
13657 fn_ref, nullptr, false, FnInlineAuto);13766 fn_ref, nullptr, false, FnInlineAuto);
13658 } else {13767 } else {
...@@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
13662 }13771 }
13663}13772}
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;
13666 IrInstruction *value = un_op_instruction->value->other;13807 IrInstruction *value = un_op_instruction->value->other;
1366713808
13668 TypeTableEntry *ptr_type = value->value.type;13809 ZigType *ptr_type = value->value.type;
13669 TypeTableEntry *child_type;13810 ZigType *child_type;
13670 if (type_is_invalid(ptr_type)) {13811 if (type_is_invalid(ptr_type)) {
13671 return ira->codegen->builtin_types.entry_invalid;13812 return ira->codegen->builtin_types.entry_invalid;
13672 } else if (ptr_type->id == TypeTableEntryIdPointer) {13813 } else if (ptr_type->id == ZigTypeIdPointer) {
13673 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {13814 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
13674 ir_add_error_node(ira, un_op_instruction->base.source_node,13815 ir_add_error_node(ira, un_op_instruction->base.source_node,
13675 buf_sprintf("index syntax required for unknown-length pointer type '%s'",13816 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
...@@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp...@@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
13692 if (comptime_value == nullptr)13833 if (comptime_value == nullptr)
13693 return ira->codegen->builtin_types.entry_invalid;13834 return ira->codegen->builtin_types.entry_invalid;
1369413835
13695 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value);13836 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
13696 if (pointee->type == child_type) {13837 out_val->type = child_type;
13697 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);13838 if ((err = ir_read_const_ptr(ira, un_op_instruction->base.source_node, out_val, comptime_value)))
13698 copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst);13839 return ira->codegen->builtin_types.entry_invalid;
13699 return child_type;13840 return child_type;
13700 }
13701 }13841 }
1370213842
13703 ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);13843 ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);
13704 return child_type;13844 return child_type;
13705}13845}
1370613846
13707static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {13847static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13708 Error err;13848 Error err;
13709 IrInstruction *value = un_op_instruction->value->other;13849 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);
13711 if (type_is_invalid(type_entry))13851 if (type_is_invalid(type_entry))
13712 return ira->codegen->builtin_types.entry_invalid;13852 return ira->codegen->builtin_types.entry_invalid;
13713 if ((err = ensure_complete_type(ira->codegen, type_entry)))13853 if ((err = ensure_complete_type(ira->codegen, type_entry)))
13714 return ira->codegen->builtin_types.entry_invalid;13854 return ira->codegen->builtin_types.entry_invalid;
1371513855
13716 switch (type_entry->id) {13856 switch (type_entry->id) {
13717 case TypeTableEntryIdInvalid:13857 case ZigTypeIdInvalid:
13718 zig_unreachable();13858 zig_unreachable();
13719 case TypeTableEntryIdMetaType:13859 case ZigTypeIdMetaType:
13720 case TypeTableEntryIdVoid:13860 case ZigTypeIdVoid:
13721 case TypeTableEntryIdBool:13861 case ZigTypeIdBool:
13722 case TypeTableEntryIdInt:13862 case ZigTypeIdInt:
13723 case TypeTableEntryIdFloat:13863 case ZigTypeIdFloat:
13724 case TypeTableEntryIdPointer:13864 case ZigTypeIdPointer:
13725 case TypeTableEntryIdArray:13865 case ZigTypeIdArray:
13726 case TypeTableEntryIdStruct:13866 case ZigTypeIdStruct:
13727 case TypeTableEntryIdComptimeFloat:13867 case ZigTypeIdComptimeFloat:
13728 case TypeTableEntryIdComptimeInt:13868 case ZigTypeIdComptimeInt:
13729 case TypeTableEntryIdUndefined:13869 case ZigTypeIdUndefined:
13730 case TypeTableEntryIdNull:13870 case ZigTypeIdNull:
13731 case TypeTableEntryIdOptional:13871 case ZigTypeIdOptional:
13732 case TypeTableEntryIdErrorUnion:13872 case ZigTypeIdErrorUnion:
13733 case TypeTableEntryIdErrorSet:13873 case ZigTypeIdErrorSet:
13734 case TypeTableEntryIdEnum:13874 case ZigTypeIdEnum:
13735 case TypeTableEntryIdUnion:13875 case ZigTypeIdUnion:
13736 case TypeTableEntryIdFn:13876 case ZigTypeIdFn:
13737 case TypeTableEntryIdNamespace:13877 case ZigTypeIdNamespace:
13738 case TypeTableEntryIdBlock:13878 case ZigTypeIdBlock:
13739 case TypeTableEntryIdBoundFn:13879 case ZigTypeIdBoundFn:
13740 case TypeTableEntryIdArgTuple:13880 case ZigTypeIdArgTuple:
13741 case TypeTableEntryIdPromise:13881 case ZigTypeIdPromise:
13742 {13882 {
13743 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);13883 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
13744 out_val->data.x_type = get_optional_type(ira->codegen, type_entry);13884 out_val->data.x_type = get_optional_type(ira->codegen, type_entry);
13745 return ira->codegen->builtin_types.entry_type;13885 return ira->codegen->builtin_types.entry_type;
13746 }13886 }
13747 case TypeTableEntryIdUnreachable:13887 case ZigTypeIdUnreachable:
13748 case TypeTableEntryIdOpaque:13888 case ZigTypeIdOpaque:
13749 ir_add_error_node(ira, un_op_instruction->base.source_node,13889 ir_add_error_node(ira, un_op_instruction->base.source_node,
13750 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));13890 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));
13751 return ira->codegen->builtin_types.entry_invalid;13891 return ira->codegen->builtin_types.entry_invalid;
...@@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
13753 zig_unreachable();13893 zig_unreachable();
13754}13894}
1375513895
13756static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {13896static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
13757 IrInstruction *value = un_op_instruction->value->other;13897 IrInstruction *value = un_op_instruction->value->other;
13758 TypeTableEntry *expr_type = value->value.type;13898 ZigType *expr_type = value->value.type;
13759 if (type_is_invalid(expr_type))13899 if (type_is_invalid(expr_type))
13760 return ira->codegen->builtin_types.entry_invalid;13900 return ira->codegen->builtin_types.entry_invalid;
1376113901
13762 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);13902 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) ||13906 if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) ||
13767 expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op))13907 expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op))
13768 {13908 {
13769 if (instr_is_comptime(value)) {13909 if (instr_is_comptime(value)) {
13770 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);13910 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
...@@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
13780 } else {13920 } else {
13781 bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);13921 bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);
13782 }13922 }
13783 if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) {13923 if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) {
13784 return expr_type;13924 return expr_type;
13785 }13925 }
1378613926
...@@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
13800 return ira->codegen->builtin_types.entry_invalid;13940 return ira->codegen->builtin_types.entry_invalid;
13801}13941}
1380213942
13803static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {13943static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
13804 IrInstruction *value = instruction->value->other;13944 IrInstruction *value = instruction->value->other;
13805 TypeTableEntry *expr_type = value->value.type;13945 ZigType *expr_type = value->value.type;
13806 if (type_is_invalid(expr_type))13946 if (type_is_invalid(expr_type))
13807 return ira->codegen->builtin_types.entry_invalid;13947 return ira->codegen->builtin_types.entry_invalid;
1380813948
13809 if (expr_type->id == TypeTableEntryIdInt) {13949 if (expr_type->id == ZigTypeIdInt) {
13810 if (instr_is_comptime(value)) {13950 if (instr_is_comptime(value)) {
13811 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);13951 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
13812 if (target_const_val == nullptr)13952 if (target_const_val == nullptr)
...@@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins
13827 return ira->codegen->builtin_types.entry_invalid;13967 return ira->codegen->builtin_types.entry_invalid;
13828}13968}
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) {
13831 IrUnOp op_id = un_op_instruction->op_id;13971 IrUnOp op_id = un_op_instruction->op_id;
13832 switch (op_id) {13972 switch (op_id) {
13833 case IrUnOpInvalid:13973 case IrUnOpInvalid:
...@@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio...@@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio
13845 zig_unreachable();13985 zig_unreachable();
13846}13986}
1384713987
13848static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {13988static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
13849 IrBasicBlock *old_dest_block = br_instruction->dest_block;13989 IrBasicBlock *old_dest_block = br_instruction->dest_block;
1385013990
13851 bool is_comptime;13991 bool is_comptime;
...@@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr...@@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
13855 if (is_comptime || old_dest_block->ref_count == 1)13995 if (is_comptime || old_dest_block->ref_count == 1)
13856 return ir_inline_bb(ira, &br_instruction->base, old_dest_block);13996 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);13998 IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
1385913999 if (new_bb == nullptr)
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"));
13865 return ir_unreach_error(ira);14000 return ir_unreach_error(ira);
13866 }
1386714001
13868 ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb);14002 ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb);
13869 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);14003 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
13870}14004}
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) {
13873 IrInstruction *condition = cond_br_instruction->condition->other;14007 IrInstruction *condition = cond_br_instruction->condition->other;
13874 if (type_is_invalid(condition->value.type))14008 if (type_is_invalid(condition->value.type))
13875 return ir_unreach_error(ira);14009 return ir_unreach_error(ira);
...@@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct...@@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct
13889 if (is_comptime || old_dest_block->ref_count == 1)14023 if (is_comptime || old_dest_block->ref_count == 1)
13890 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);14024 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
13893 ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block);14030 ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block);
13894 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);14031 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
13895 }14032 }
1389614033
13897 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;14034 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
13898 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);14035 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
13899 if (casted_condition == ira->codegen->invalid_instruction)14036 if (casted_condition == ira->codegen->invalid_instruction)
13900 return ir_unreach_error(ira);14037 return ir_unreach_error(ira);
1390114038
13902 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);14039 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);14040 IrBasicBlock *new_then_block = ir_get_new_bb_runtime(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);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
13905 ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base,14048 ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base,
13906 casted_condition, new_then_block, new_else_block, nullptr);14049 casted_condition, new_then_block, new_else_block, nullptr);
13907 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);14050 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
13908}14051}
1390914052
13910static TypeTableEntry *ir_analyze_instruction_unreachable(IrAnalyze *ira,14053static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira,
13911 IrInstructionUnreachable *unreachable_instruction)14054 IrInstructionUnreachable *unreachable_instruction)
13912{14055{
13913 ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base);14056 ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base);
13914 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);14057 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
13915}14058}
1391614059
13917static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {14060static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
13918 if (ira->const_predecessor_bb) {14061 if (ira->const_predecessor_bb) {
13919 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {14062 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
13920 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];14063 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
...@@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
13948 IrInstruction *old_value = phi_instruction->incoming_values[i];14091 IrInstruction *old_value = phi_instruction->incoming_values[i];
13949 assert(old_value);14092 assert(old_value);
13950 IrInstruction *new_value = old_value->other;14093 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)
13952 continue;14095 continue;
1395314096
13954 if (type_is_invalid(new_value->value.type))14097 if (type_is_invalid(new_value->value.type))
...@@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
13971 return first_value->value.type;14114 return first_value->value.type;
13972 }14115 }
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,
13975 new_incoming_values.items, new_incoming_values.length);14118 new_incoming_values.items, new_incoming_values.length);
13976 if (type_is_invalid(resolved_type))14119 if (type_is_invalid(resolved_type))
13977 return resolved_type;14120 return resolved_type;
1397814121
13979 if (resolved_type->id == TypeTableEntryIdComptimeFloat ||14122 if (resolved_type->id == ZigTypeIdComptimeFloat ||
13980 resolved_type->id == TypeTableEntryIdComptimeInt ||14123 resolved_type->id == ZigTypeIdComptimeInt ||
13981 resolved_type->id == TypeTableEntryIdNull ||14124 resolved_type->id == ZigTypeIdNull ||
13982 resolved_type->id == TypeTableEntryIdUndefined)14125 resolved_type->id == ZigTypeIdUndefined)
13983 {14126 {
13984 ir_add_error_node(ira, phi_instruction->base.source_node,14127 ir_add_error_node(ira, phi_instruction->base.source_node,
13985 buf_sprintf("unable to infer expression type"));14128 buf_sprintf("unable to infer expression type"));
13986 return ira->codegen->builtin_types.entry_invalid;14129 return ira->codegen->builtin_types.entry_invalid;
13987 }14130 }
1398814131
13989 bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer);14132 bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer);
1399014133
13991 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.14134 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
13992 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and14135 // 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...@@ -14023,21 +14166,30 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
14023 return resolved_type;14166 return resolved_type;
14024}14167}
1402514168
14026static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,14169static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
14027 VariableTableEntry *var)
14028{
14029 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);14170 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
14030 ir_link_new_instruction(result, instruction);14171 ir_link_new_instruction(result, instruction);
14031 return result->value.type;14172 return result->value.type;
14032}14173}
1403314174
14034static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {14175static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {
14035 VariableTableEntry *var = var_ptr_instruction->var;14176 ZigVar *var = instruction->var;
14036 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, 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;
14037}14189}
1403814190
14039static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {14191static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) {
14040 assert(ptr_type->id == TypeTableEntryIdPointer);14192 assert(ptr_type->id == ZigTypeIdPointer);
14041 return get_pointer_to_type_extra(g,14193 return get_pointer_to_type_extra(g,
14042 ptr_type->data.pointer.child_type,14194 ptr_type->data.pointer.child_type,
14043 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,14195 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...@@ -14046,15 +14198,15 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui
14046 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);14198 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
14047}14199}
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) {
14050 assert(is_slice(slice_type));14202 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,
14052 new_align);14204 new_align);
14053 return get_slice_type(g, ptr_type);14205 return get_slice_type(g, ptr_type);
14054}14206}
1405514207
14056static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) {14208static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
14057 assert(ptr_type->id == TypeTableEntryIdPointer);14209 assert(ptr_type->id == ZigTypeIdPointer);
14058 return get_pointer_to_type_extra(g,14210 return get_pointer_to_type_extra(g,
14059 ptr_type->data.pointer.child_type,14211 ptr_type->data.pointer.child_type,
14060 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,14212 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...@@ -14063,7 +14215,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL
14063 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);14215 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
14064}14216}
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) {
14067 Error err;14219 Error err;
14068 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;14220 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
14069 if (type_is_invalid(array_ptr->value.type))14221 if (type_is_invalid(array_ptr->value.type))
...@@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14075 if (type_is_invalid(elem_index->value.type))14227 if (type_is_invalid(elem_index->value.type))
14076 return ira->codegen->builtin_types.entry_invalid;14228 return ira->codegen->builtin_types.entry_invalid;
1407714229
14078 TypeTableEntry *ptr_type = orig_array_ptr_val->type;14230 ZigType *ptr_type = orig_array_ptr_val->type;
14079 assert(ptr_type->id == TypeTableEntryIdPointer);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
14083 // At first return_type will be the pointer type we want to return, except with an optimistic alignment.14235 // At first return_type will be the pointer type we want to return, except with an optimistic alignment.
14084 // We will adjust return_type's alignment before returning it.14236 // We will adjust return_type's alignment before returning it.
14085 TypeTableEntry *return_type;14237 ZigType *return_type;
1408614238
14087 if (type_is_invalid(array_type)) {14239 if (type_is_invalid(array_type)) {
14088 return array_type;14240 return array_type;
14089 } else if (array_type->id == TypeTableEntryIdArray ||14241 } else if (array_type->id == ZigTypeIdArray ||
14090 (array_type->id == TypeTableEntryIdPointer &&14242 (array_type->id == ZigTypeIdPointer &&
14091 array_type->data.pointer.ptr_len == PtrLenSingle &&14243 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))
14093 {14245 {
14094 if (array_type->id == TypeTableEntryIdPointer) {14246 if (array_type->id == ZigTypeIdPointer) {
14095 array_type = array_type->data.pointer.child_type;14247 array_type = array_type->data.pointer.child_type;
14096 ptr_type = ptr_type->data.pointer.child_type;14248 ptr_type = ptr_type->data.pointer.child_type;
14097 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {14249 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;
14099 }14254 }
14100 }14255 }
14101 if (array_type->data.array.len == 0) {14256 if (array_type->data.array.len == 0) {
...@@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14103 buf_sprintf("index 0 outside array of size 0"));14258 buf_sprintf("index 0 outside array of size 0"));
14104 return ira->codegen->builtin_types.entry_invalid;14259 return ira->codegen->builtin_types.entry_invalid;
14105 }14260 }
14106 TypeTableEntry *child_type = array_type->data.array.child_type;14261 ZigType *child_type = array_type->data.array.child_type;
14107 if (ptr_type->data.pointer.unaligned_bit_count == 0) {14262 if (ptr_type->data.pointer.unaligned_bit_count == 0) {
14108 return_type = get_pointer_to_type_extra(ira->codegen, child_type,14263 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
14109 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,14264 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...@@ -14122,7 +14277,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14122 elem_ptr_instruction->ptr_len,14277 elem_ptr_instruction->ptr_len,
14123 1, (uint32_t)bit_offset, (uint32_t)bit_width);14278 1, (uint32_t)bit_offset, (uint32_t)bit_width);
14124 }14279 }
14125 } else if (array_type->id == TypeTableEntryIdPointer) {14280 } else if (array_type->id == ZigTypeIdPointer) {
14126 if (array_type->data.pointer.ptr_len == PtrLenSingle) {14281 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
14127 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14282 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14128 buf_sprintf("index of single-item pointer"));14283 buf_sprintf("index of single-item pointer"));
...@@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14132 } else if (is_slice(array_type)) {14287 } else if (is_slice(array_type)) {
14133 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,14288 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
14134 elem_ptr_instruction->ptr_len);14289 elem_ptr_instruction->ptr_len);
14135 } else if (array_type->id == TypeTableEntryIdArgTuple) {14290 } else if (array_type->id == ZigTypeIdArgTuple) {
14136 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);14291 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
14137 if (!ptr_val)14292 if (!ptr_val)
14138 return ira->codegen->builtin_types.entry_invalid;14293 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;
14140 size_t start = args_val->data.x_arg_tuple.start_index;14297 size_t start = args_val->data.x_arg_tuple.start_index;
14141 size_t end = args_val->data.x_arg_tuple.end_index;14298 size_t end = args_val->data.x_arg_tuple.end_index;
14142 uint64_t elem_index_val;14299 uint64_t elem_index_val;
...@@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14150 return ira->codegen->builtin_types.entry_invalid;14307 return ira->codegen->builtin_types.entry_invalid;
14151 }14308 }
14152 size_t abs_index = start + index;14309 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);
14154 assert(fn_entry);14311 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);
14156 bool is_const = true;14313 bool is_const = true;
14157 bool is_volatile = false;14314 bool is_volatile = false;
14158 if (var) {14315 if (var) {
...@@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14167 return ira->codegen->builtin_types.entry_invalid;14324 return ira->codegen->builtin_types.entry_invalid;
14168 }14325 }
1416914326
14170 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;14327 ZigType *usize = ira->codegen->builtin_types.entry_usize;
14171 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);14328 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
14172 if (casted_elem_index == ira->codegen->invalid_instruction)14329 if (casted_elem_index == ira->codegen->invalid_instruction)
14173 return ira->codegen->builtin_types.entry_invalid;14330 return ira->codegen->builtin_types.entry_invalid;
...@@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14181 uint64_t ptr_align = return_type->data.pointer.alignment;14338 uint64_t ptr_align = return_type->data.pointer.alignment;
14182 if (instr_is_comptime(casted_elem_index)) {14339 if (instr_is_comptime(casted_elem_index)) {
14183 uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);14340 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) {
14185 uint64_t array_len = array_type->data.array.len;14342 uint64_t array_len = array_type->data.array.len;
14186 if (index >= array_len) {14343 if (index >= array_len) {
14187 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14344 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...@@ -14212,120 +14369,126 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14212 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);14369 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
14213 }14370 }
1421414371
14215 ConstExprValue *array_ptr_val;
14216 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&14372 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
14217 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == TypeTableEntryIdArray) &&14373 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
14218 (array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val)) &&14374 array_type->id == ZigTypeIdArray))
14219 array_ptr_val->special != ConstValSpecialRuntime &&
14220 (array_type->id != TypeTableEntryIdPointer ||
14221 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
14222 {14375 {
14223 if (array_type->id == TypeTableEntryIdPointer) {14376 ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
14224 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);14377 elem_ptr_instruction->base.source_node);
14225 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;14378 if (array_ptr_val == nullptr)
14226 size_t new_index;14379 return ira->codegen->builtin_types.entry_invalid;
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;
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;
14257 break;14402 break;
14258 }14403 case ConstPtrSpecialBaseArray:
14259 case ConstPtrSpecialBaseStruct:14404 {
14260 zig_panic("TODO elem ptr on a const inner struct");14405 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
14261 case ConstPtrSpecialHardCodedAddr:14406 new_index = offset + index;
14262 zig_unreachable();14407 mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
14263 case ConstPtrSpecialFunction:14408 old_size = mem_size - offset;
14264 zig_panic("TODO element ptr of a function casted to a ptr");14409
14265 }14410 assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
14266 if (new_index >= mem_size) {14411
14267 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14412 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14268 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));14413 out_val->data.x_ptr.data.base_array.array_val =
14269 return ira->codegen->builtin_types.entry_invalid;14414 array_ptr_val->data.x_ptr.data.base_array.array_val;
14270 }14415 out_val->data.x_ptr.data.base_array.elem_index = new_index;
14271 return return_type;14416 out_val->data.x_ptr.data.base_array.is_cstr =
14272 } else if (is_slice(array_type)) {14417 array_ptr_val->data.x_ptr.data.base_array.is_cstr;
14273 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];14418
14274 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {14419 break;
14275 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,14420 }
14276 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);14421 case ConstPtrSpecialBaseStruct:
14277 result->value.type = return_type;14422 zig_panic("TODO elem ptr on a const inner struct");
14278 ir_link_new_instruction(result, &elem_ptr_instruction->base);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 }
14279 return return_type;14433 return return_type;
14280 }14434 } else if (is_slice(array_type)) {
14281 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];14435 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
14282 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);14436 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
14283 uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);14437 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
14284 if (index >= slice_len) {14438 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
14285 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14439 result->value.type = return_type;
14286 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,14440 ir_link_new_instruction(result, &elem_ptr_instruction->base);
14287 index, slice_len));14441 return return_type;
14288 return ira->codegen->builtin_types.entry_invalid;14442 }
14289 }14443 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
14290 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;14444 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14291 switch (ptr_field->data.x_ptr.special) {14445 uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
14292 case ConstPtrSpecialInvalid:14446 if (index >= slice_len) {
14293 case ConstPtrSpecialDiscard:14447 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14294 zig_unreachable();14448 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
14295 case ConstPtrSpecialRef:14449 index, slice_len));
14296 out_val->data.x_ptr.special = ConstPtrSpecialRef;14450 return ira->codegen->builtin_types.entry_invalid;
14297 out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;14451 }
14298 break;14452 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
14299 case ConstPtrSpecialBaseArray:14453 switch (ptr_field->data.x_ptr.special) {
14300 {14454 case ConstPtrSpecialInvalid:
14301 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;14455 case ConstPtrSpecialDiscard:
14302 uint64_t new_index = offset + index;14456 zig_unreachable();
14303 assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);14457 case ConstPtrSpecialRef:
14304 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;14458 out_val->data.x_ptr.special = ConstPtrSpecialRef;
14305 out_val->data.x_ptr.data.base_array.array_val =14459 out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;
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;
14310 break;14460 break;
14311 }14461 case ConstPtrSpecialBaseArray:
14312 case ConstPtrSpecialBaseStruct:14462 {
14313 zig_panic("TODO elem ptr on a slice backed by const inner struct");14463 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
14314 case ConstPtrSpecialHardCodedAddr:14464 uint64_t new_index = offset + index;
14315 zig_unreachable();14465 assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);
14316 case ConstPtrSpecialFunction:14466 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14317 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");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();
14318 }14491 }
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();
14329 }14492 }
14330 }14493 }
1433114494
...@@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
14351}14514}
1435214515
14353static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,14516static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14354 TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr,14517 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
14355 IrInstruction *container_ptr, TypeTableEntry *container_type)14518 IrInstruction *container_ptr, ZigType *container_type)
14356{14519{
14357 if (!is_slice(bare_struct_type)) {14520 if (!is_slice(bare_struct_type)) {
14358 ScopeDecls *container_scope = get_container_scope(bare_struct_type);14521 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
...@@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14364 if (tld->resolution == TldResolutionInvalid)14527 if (tld->resolution == TldResolutionInvalid)
14365 return ira->codegen->invalid_instruction;14528 return ira->codegen->invalid_instruction;
14366 TldFn *tld_fn = (TldFn *)tld;14529 TldFn *tld_fn = (TldFn *)tld;
14367 FnTableEntry *fn_entry = tld_fn->fn_entry;14530 ZigFn *fn_entry = tld_fn->fn_entry;
14368 if (type_is_invalid(fn_entry->type_entry))14531 if (type_is_invalid(fn_entry->type_entry))
14369 return ira->codegen->invalid_instruction;14532 return ira->codegen->invalid_instruction;
1437014533
...@@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14376 const char *prefix_name;14539 const char *prefix_name;
14377 if (is_slice(bare_struct_type)) {14540 if (is_slice(bare_struct_type)) {
14378 prefix_name = "";14541 prefix_name = "";
14379 } else if (bare_struct_type->id == TypeTableEntryIdStruct) {14542 } else if (bare_struct_type->id == ZigTypeIdStruct) {
14380 prefix_name = "struct ";14543 prefix_name = "struct ";
14381 } else if (bare_struct_type->id == TypeTableEntryIdEnum) {14544 } else if (bare_struct_type->id == ZigTypeIdEnum) {
14382 prefix_name = "enum ";14545 prefix_name = "enum ";
14383 } else if (bare_struct_type->id == TypeTableEntryIdUnion) {14546 } else if (bare_struct_type->id == ZigTypeIdUnion) {
14384 prefix_name = "union ";14547 prefix_name = "union ";
14385 } else {14548 } else {
14386 prefix_name = "";14549 prefix_name = "";
...@@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14391}14554}
1439214555
14393static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,14556static 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)
14395{14558{
14396 Error err;14559 Error err;
1439714560
14398 TypeTableEntry *bare_type = container_ref_type(container_type);14561 ZigType *bare_type = container_ref_type(container_type);
14399 if ((err = ensure_complete_type(ira->codegen, bare_type)))14562 if ((err = ensure_complete_type(ira->codegen, bare_type)))
14400 return ira->codegen->invalid_instruction;14563 return ira->codegen->invalid_instruction;
1440114564
14402 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14565 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14403 bool is_const = container_ptr->value.type->data.pointer.is_const;14566 bool is_const = container_ptr->value.type->data.pointer.is_const;
14404 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;14567 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;
14405 if (bare_type->id == TypeTableEntryIdStruct) {14568 if (bare_type->id == ZigTypeIdStruct) {
14406 TypeStructField *field = find_struct_type_field(bare_type, field_name);14569 TypeStructField *field = find_struct_type_field(bare_type, field_name);
14407 if (field) {14570 if (field) {
14408 bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);14571 bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);
...@@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14417 return ira->codegen->invalid_instruction;14580 return ira->codegen->invalid_instruction;
1441814581
14419 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {14582 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;
14421 if (type_is_invalid(struct_val->type))14586 if (type_is_invalid(struct_val->type))
14422 return ira->codegen->invalid_instruction;14587 return ira->codegen->invalid_instruction;
14423 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];14588 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,
14425 is_const, is_volatile, PtrLenSingle, align_bytes,14590 is_const, is_volatile, PtrLenSingle, align_bytes,
14426 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),14591 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
14427 (uint32_t)unaligned_bit_count_for_result_type);14592 (uint32_t)unaligned_bit_count_for_result_type);
...@@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14447 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14612 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14448 source_instr, container_ptr, container_type);14613 source_instr, container_ptr, container_type);
14449 }14614 }
14450 } else if (bare_type->id == TypeTableEntryIdEnum) {14615 } else if (bare_type->id == ZigTypeIdEnum) {
14451 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14616 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14452 source_instr, container_ptr, container_type);14617 source_instr, container_ptr, container_type);
14453 } else if (bare_type->id == TypeTableEntryIdUnion) {14618 } else if (bare_type->id == ZigTypeIdUnion) {
14454 TypeUnionField *field = find_union_type_field(bare_type, field_name);14619 TypeUnionField *field = find_union_type_field(bare_type, field_name);
14455 if (field) {14620 if (field) {
14456 if (instr_is_comptime(container_ptr)) {14621 if (instr_is_comptime(container_ptr)) {
...@@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14459 return ira->codegen->invalid_instruction;14624 return ira->codegen->invalid_instruction;
1446014625
14461 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {14626 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;
14463 if (type_is_invalid(union_val->type))14630 if (type_is_invalid(union_val->type))
14464 return ira->codegen->invalid_instruction;14631 return ira->codegen->invalid_instruction;
1446514632
...@@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1447614643
14477 ConstExprValue *payload_val = union_val->data.x_union.payload;14644 ConstExprValue *payload_val = union_val->data.x_union.payload;
1447814645
14479 TypeTableEntry *field_type = field->type_entry;14646 ZigType *field_type = field->type_entry;
14480 if (field_type->id == TypeTableEntryIdVoid) {14647 if (field_type->id == ZigTypeIdVoid) {
14481 assert(payload_val == nullptr);14648 assert(payload_val == nullptr);
14482 payload_val = create_const_vals(1);14649 payload_val = create_const_vals(1);
14483 payload_val->special = ConstValSpecialStatic;14650 payload_val->special = ConstValSpecialStatic;
14484 payload_val->type = field_type;14651 payload_val->type = field_type;
14485 }14652 }
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,
14488 is_const, is_volatile,14655 is_const, is_volatile,
14489 PtrLenSingle,14656 PtrLenSingle,
14490 get_abi_alignment(ira->codegen, field_type), 0, 0);14657 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,...@@ -14531,7 +14698,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
14531}14698}
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) {
14535 bool pointer_only = false;14702 bool pointer_only = false;
14536 resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);14703 resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
14537 if (tld->resolution == TldResolutionInvalid)14704 if (tld->resolution == TldResolutionInvalid)
...@@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
14544 case TldIdVar:14711 case TldIdVar:
14545 {14712 {
14546 TldVar *tld_var = (TldVar *)tld;14713 TldVar *tld_var = (TldVar *)tld;
14547 VariableTableEntry *var = tld_var->var;14714 ZigVar *var = tld_var->var;
14548 if (tld_var->extern_lib_name != nullptr) {14715 if (tld_var->extern_lib_name != nullptr) {
14549 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);14716 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
14550 }14717 }
...@@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
14554 case TldIdFn:14721 case TldIdFn:
14555 {14722 {
14556 TldFn *tld_fn = (TldFn *)tld;14723 TldFn *tld_fn = (TldFn *)tld;
14557 FnTableEntry *fn_entry = tld_fn->fn_entry;14724 ZigFn *fn_entry = tld_fn->fn_entry;
14558 assert(fn_entry->type_entry);14725 assert(fn_entry->type_entry);
1455914726
14560 if (type_is_invalid(fn_entry->type_entry))14727 if (type_is_invalid(fn_entry->type_entry))
...@@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
14582 zig_unreachable();14749 zig_unreachable();
14583}14750}
1458414751
14585static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) {14752static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) {
14586 assert(err_set_type->id == TypeTableEntryIdErrorSet);14753 assert(err_set_type->id == ZigTypeIdErrorSet);
14587 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {14754 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
14588 ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];14755 ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];
14589 if (buf_eql_buf(&err_table_entry->name, field_name)) {14756 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 *...@@ -14593,14 +14760,14 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *
14593 return nullptr;14760 return nullptr;
14594}14761}
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) {
14597 Error err;14764 Error err;
14598 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;14765 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
14599 if (type_is_invalid(container_ptr->value.type))14766 if (type_is_invalid(container_ptr->value.type))
14600 return ira->codegen->builtin_types.entry_invalid;14767 return ira->codegen->builtin_types.entry_invalid;
1460114768
14602 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;14769 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
14603 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14770 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1460414771
14605 Buf *field_name = field_ptr_instruction->field_name_buffer;14772 Buf *field_name = field_ptr_instruction->field_name_buffer;
14606 if (!field_name) {14773 if (!field_name) {
...@@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14616 if (type_is_invalid(container_type)) {14783 if (type_is_invalid(container_type)) {
14617 return container_type;14784 return container_type;
14618 } else if (is_container_ref(container_type)) {14785 } else if (is_container_ref(container_type)) {
14619 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14786 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14620 if (container_type->id == TypeTableEntryIdPointer) {14787 if (container_type->id == ZigTypeIdPointer) {
14621 TypeTableEntry *bare_type = container_ref_type(container_type);14788 ZigType *bare_type = container_ref_type(container_type);
14622 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);14789 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
14623 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);14790 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);
14624 ir_link_new_instruction(result, &field_ptr_instruction->base);14791 ir_link_new_instruction(result, &field_ptr_instruction->base);
...@@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14631 } else if (is_array_ref(container_type)) {14798 } else if (is_array_ref(container_type)) {
14632 if (buf_eql_str(field_name, "len")) {14799 if (buf_eql_str(field_name, "len")) {
14633 ConstExprValue *len_val = create_const_vals(1);14800 ConstExprValue *len_val = create_const_vals(1);
14634 if (container_type->id == TypeTableEntryIdPointer) {14801 if (container_type->id == ZigTypeIdPointer) {
14635 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);14802 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
14636 } else {14803 } else {
14637 init_const_usize(ira->codegen, len_val, container_type->data.array.len);14804 init_const_usize(ira->codegen, len_val, container_type->data.array.len);
14638 }14805 }
1463914806
14640 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;14807 ZigType *usize = ira->codegen->builtin_types.entry_usize;
14641 bool ptr_is_const = true;14808 bool ptr_is_const = true;
14642 bool ptr_is_volatile = false;14809 bool ptr_is_volatile = false;
14643 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,14810 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...@@ -14648,20 +14815,22 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14648 buf_ptr(&container_type->name)));14815 buf_ptr(&container_type->name)));
14649 return ira->codegen->builtin_types.entry_invalid;14816 return ira->codegen->builtin_types.entry_invalid;
14650 }14817 }
14651 } else if (container_type->id == TypeTableEntryIdArgTuple) {14818 } else if (container_type->id == ZigTypeIdArgTuple) {
14652 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);14819 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
14653 if (!container_ptr_val)14820 if (!container_ptr_val)
14654 return ira->codegen->builtin_types.entry_invalid;14821 return ira->codegen->builtin_types.entry_invalid;
1465514822
14656 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14823 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14657 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);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
14659 if (buf_eql_str(field_name, "len")) {14828 if (buf_eql_str(field_name, "len")) {
14660 ConstExprValue *len_val = create_const_vals(1);14829 ConstExprValue *len_val = create_const_vals(1);
14661 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;14830 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
14662 init_const_usize(ira->codegen, len_val, len);14831 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;
14665 bool ptr_is_const = true;14834 bool ptr_is_const = true;
14666 bool ptr_is_volatile = false;14835 bool ptr_is_volatile = false;
14667 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,14836 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...@@ -14672,14 +14841,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14672 buf_ptr(&container_type->name)));14841 buf_ptr(&container_type->name)));
14673 return ira->codegen->builtin_types.entry_invalid;14842 return ira->codegen->builtin_types.entry_invalid;
14674 }14843 }
14675 } else if (container_type->id == TypeTableEntryIdMetaType) {14844 } else if (container_type->id == ZigTypeIdMetaType) {
14676 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);14845 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
14677 if (!container_ptr_val)14846 if (!container_ptr_val)
14678 return ira->codegen->builtin_types.entry_invalid;14847 return ira->codegen->builtin_types.entry_invalid;
1467914848
14680 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14849 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14681 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);14850 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
14682 TypeTableEntry *child_type = child_val->data.x_type;14851 if (child_val == nullptr)
14852 return ira->codegen->builtin_types.entry_invalid;
14853 ZigType *child_type = child_val->data.x_type;
1468314854
14684 if (type_is_invalid(child_type)) {14855 if (type_is_invalid(child_type)) {
14685 return ira->codegen->builtin_types.entry_invalid;14856 return ira->codegen->builtin_types.entry_invalid;
...@@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14688 bool ptr_is_const = true;14859 bool ptr_is_const = true;
14689 bool ptr_is_volatile = false;14860 bool ptr_is_volatile = false;
14690 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];14861 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
14691 assert(ptr_field->type_entry->id == TypeTableEntryIdPointer);14862 assert(ptr_field->type_entry->id == ZigTypeIdPointer);
14692 TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type;14863 ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;
14693 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,14864 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
14694 create_const_type(ira->codegen, child_type),14865 create_const_type(ira->codegen, child_type),
14695 ira->codegen->builtin_types.entry_type,14866 ira->codegen->builtin_types.entry_type,
14696 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);14867 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
14697 }14868 }
14698 if (child_type->id == TypeTableEntryIdEnum) {14869 if (child_type->id == ZigTypeIdEnum) {
14699 if ((err = ensure_complete_type(ira->codegen, child_type)))14870 if ((err = ensure_complete_type(ira->codegen, child_type)))
14700 return ira->codegen->builtin_types.entry_invalid;14871 return ira->codegen->builtin_types.entry_invalid;
1470114872
...@@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14716 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);14887 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
14717 }14888 }
14718 }14889 }
14719 if (child_type->id == TypeTableEntryIdUnion &&14890 if (child_type->id == ZigTypeIdUnion &&
14720 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||14891 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
14721 child_type->data.unionation.decl_node->data.container_decl.auto_enum))14892 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
14722 {14893 {
...@@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14724 return ira->codegen->builtin_types.entry_invalid;14895 return ira->codegen->builtin_types.entry_invalid;
14725 TypeUnionField *field = find_union_type_field(child_type, field_name);14896 TypeUnionField *field = find_union_type_field(child_type, field_name);
14726 if (field) {14897 if (field) {
14727 TypeTableEntry *enum_type = child_type->data.unionation.tag_type;14898 ZigType *enum_type = child_type->data.unionation.tag_type;
14728 bool ptr_is_const = true;14899 bool ptr_is_const = true;
14729 bool ptr_is_volatile = false;14900 bool ptr_is_volatile = false;
14730 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,14901 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
...@@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14736 buf_sprintf("container '%s' has no member called '%s'",14907 buf_sprintf("container '%s' has no member called '%s'",
14737 buf_ptr(&child_type->name), buf_ptr(field_name)));14908 buf_ptr(&child_type->name), buf_ptr(field_name)));
14738 return ira->codegen->builtin_types.entry_invalid;14909 return ira->codegen->builtin_types.entry_invalid;
14739 } else if (child_type->id == TypeTableEntryIdErrorSet) {14910 } else if (child_type->id == ZigTypeIdErrorSet) {
14740 ErrorTableEntry *err_entry;14911 ErrorTableEntry *err_entry;
14741 TypeTableEntry *err_set_type;14912 ZigType *err_set_type;
14742 if (type_is_global_error_set(child_type)) {14913 if (type_is_global_error_set(child_type)) {
14743 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);14914 auto existing_entry = ira->codegen->error_table.maybe_get(field_name);
14744 if (existing_entry) {14915 if (existing_entry) {
...@@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14782 bool ptr_is_volatile = false;14953 bool ptr_is_volatile = false;
14783 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,14954 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,
14784 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);14955 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
14785 } else if (child_type->id == TypeTableEntryIdInt) {14956 } else if (child_type->id == ZigTypeIdInt) {
14786 if (buf_eql_str(field_name, "bit_count")) {14957 if (buf_eql_str(field_name, "bit_count")) {
14787 bool ptr_is_const = true;14958 bool ptr_is_const = true;
14788 bool ptr_is_volatile = false;14959 bool ptr_is_volatile = false;
...@@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14804 buf_ptr(&child_type->name), buf_ptr(field_name)));14975 buf_ptr(&child_type->name), buf_ptr(field_name)));
14805 return ira->codegen->builtin_types.entry_invalid;14976 return ira->codegen->builtin_types.entry_invalid;
14806 }14977 }
14807 } else if (child_type->id == TypeTableEntryIdFloat) {14978 } else if (child_type->id == ZigTypeIdFloat) {
14808 if (buf_eql_str(field_name, "bit_count")) {14979 if (buf_eql_str(field_name, "bit_count")) {
14809 bool ptr_is_const = true;14980 bool ptr_is_const = true;
14810 bool ptr_is_volatile = false;14981 bool ptr_is_volatile = false;
...@@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14819 buf_ptr(&child_type->name), buf_ptr(field_name)));14990 buf_ptr(&child_type->name), buf_ptr(field_name)));
14820 return ira->codegen->builtin_types.entry_invalid;14991 return ira->codegen->builtin_types.entry_invalid;
14821 }14992 }
14822 } else if (child_type->id == TypeTableEntryIdPointer) {14993 } else if (child_type->id == ZigTypeIdPointer) {
14823 if (buf_eql_str(field_name, "Child")) {14994 if (buf_eql_str(field_name, "Child")) {
14824 bool ptr_is_const = true;14995 bool ptr_is_const = true;
14825 bool ptr_is_volatile = false;14996 bool ptr_is_volatile = false;
...@@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14841 buf_ptr(&child_type->name), buf_ptr(field_name)));15012 buf_ptr(&child_type->name), buf_ptr(field_name)));
14842 return ira->codegen->builtin_types.entry_invalid;15013 return ira->codegen->builtin_types.entry_invalid;
14843 }15014 }
14844 } else if (child_type->id == TypeTableEntryIdArray) {15015 } else if (child_type->id == ZigTypeIdArray) {
14845 if (buf_eql_str(field_name, "Child")) {15016 if (buf_eql_str(field_name, "Child")) {
14846 bool ptr_is_const = true;15017 bool ptr_is_const = true;
14847 bool ptr_is_volatile = false;15018 bool ptr_is_volatile = false;
...@@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14863 buf_ptr(&child_type->name), buf_ptr(field_name)));15034 buf_ptr(&child_type->name), buf_ptr(field_name)));
14864 return ira->codegen->builtin_types.entry_invalid;15035 return ira->codegen->builtin_types.entry_invalid;
14865 }15036 }
14866 } else if (child_type->id == TypeTableEntryIdErrorUnion) {15037 } else if (child_type->id == ZigTypeIdErrorUnion) {
14867 if (buf_eql_str(field_name, "Payload")) {15038 if (buf_eql_str(field_name, "Payload")) {
14868 bool ptr_is_const = true;15039 bool ptr_is_const = true;
14869 bool ptr_is_volatile = false;15040 bool ptr_is_volatile = false;
...@@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14884 buf_ptr(&child_type->name), buf_ptr(field_name)));15055 buf_ptr(&child_type->name), buf_ptr(field_name)));
14885 return ira->codegen->builtin_types.entry_invalid;15056 return ira->codegen->builtin_types.entry_invalid;
14886 }15057 }
14887 } else if (child_type->id == TypeTableEntryIdOptional) {15058 } else if (child_type->id == ZigTypeIdOptional) {
14888 if (buf_eql_str(field_name, "Child")) {15059 if (buf_eql_str(field_name, "Child")) {
14889 bool ptr_is_const = true;15060 bool ptr_is_const = true;
14890 bool ptr_is_volatile = false;15061 bool ptr_is_volatile = false;
...@@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14898 buf_ptr(&child_type->name), buf_ptr(field_name)));15069 buf_ptr(&child_type->name), buf_ptr(field_name)));
14899 return ira->codegen->builtin_types.entry_invalid;15070 return ira->codegen->builtin_types.entry_invalid;
14900 }15071 }
14901 } else if (child_type->id == TypeTableEntryIdFn) {15072 } else if (child_type->id == ZigTypeIdFn) {
14902 if (buf_eql_str(field_name, "ReturnType")) {15073 if (buf_eql_str(field_name, "ReturnType")) {
14903 if (child_type->data.fn.fn_type_id.return_type == nullptr) {15074 if (child_type->data.fn.fn_type_id.return_type == nullptr) {
14904 // Return type can only ever be null, if the function is generic15075 // 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...@@ -14940,13 +15111,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14940 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));15111 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
14941 return ira->codegen->builtin_types.entry_invalid;15112 return ira->codegen->builtin_types.entry_invalid;
14942 }15113 }
14943 } else if (container_type->id == TypeTableEntryIdNamespace) {15114 } else if (container_type->id == ZigTypeIdNamespace) {
14944 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);15115 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14945 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);15116 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
14946 if (!container_ptr_val)15117 if (!container_ptr_val)
14947 return ira->codegen->builtin_types.entry_invalid;15118 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;
14950 assert(namespace_val->special == ConstValSpecialStatic);15124 assert(namespace_val->special == ConstValSpecialStatic);
1495115125
14952 ImportTableEntry *namespace_import = namespace_val->data.x_import;15126 ImportTableEntry *namespace_import = namespace_val->data.x_import;
...@@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14975 }15149 }
14976}15150}
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) {
14979 IrInstruction *ptr = load_ptr_instruction->ptr->other;15153 IrInstruction *ptr = load_ptr_instruction->ptr->other;
14980 if (type_is_invalid(ptr->value.type))15154 if (type_is_invalid(ptr->value.type))
14981 return ira->codegen->builtin_types.entry_invalid;15155 return ira->codegen->builtin_types.entry_invalid;
...@@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc...@@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
14986 return result->value.type;15160 return result->value.type;
14987}15161}
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) {
14990 IrInstruction *ptr = store_ptr_instruction->ptr->other;15164 IrInstruction *ptr = store_ptr_instruction->ptr->other;
14991 if (type_is_invalid(ptr->value.type))15165 if (type_is_invalid(ptr->value.type))
14992 return ptr->value.type;15166 return ptr->value.type;
...@@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
14995 if (type_is_invalid(value->value.type))15169 if (type_is_invalid(value->value.type))
14996 return value->value.type;15170 return value->value.type;
1499715171
14998 if (ptr->value.type->id != TypeTableEntryIdPointer) {15172 if (ptr->value.type->id != ZigTypeIdPointer) {
14999 ir_add_error(ira, ptr,15173 ir_add_error(ira, ptr,
15000 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));15174 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
15001 return ira->codegen->builtin_types.entry_invalid;15175 return ira->codegen->builtin_types.entry_invalid;
...@@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
15010 return ira->codegen->builtin_types.entry_invalid;15184 return ira->codegen->builtin_types.entry_invalid;
15011 }15185 }
1501215186
15013 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;15187 ZigType *child_type = ptr->value.type->data.pointer.child_type;
15014 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);15188 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
15015 if (casted_value == ira->codegen->invalid_instruction)15189 if (casted_value == ira->codegen->invalid_instruction)
15016 return ira->codegen->builtin_types.entry_invalid;15190 return ira->codegen->builtin_types.entry_invalid;
...@@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
15022 }15196 }
15023 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {15197 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {
15024 if (instr_is_comptime(casted_value)) {15198 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;
15026 if (dest_val->special != ConstValSpecialRuntime) {15202 if (dest_val->special != ConstValSpecialRuntime) {
15027 *dest_val = casted_value->value;15203 *dest_val = casted_value->value;
15028 if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {15204 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...@@ -15033,7 +15209,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
15033 }15209 }
15034 ir_add_error(ira, &store_ptr_instruction->base,15210 ir_add_error(ira, &store_ptr_instruction->base,
15035 buf_sprintf("cannot store runtime value in compile time variable"));15211 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);
15037 dest_val->type = ira->codegen->builtin_types.entry_invalid;15213 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1503815214
15039 return ira->codegen->builtin_types.entry_invalid;15215 return ira->codegen->builtin_types.entry_invalid;
...@@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
15044 return ira->codegen->builtin_types.entry_void;15220 return ira->codegen->builtin_types.entry_void;
15045}15221}
1504615222
15047static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {15223static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
15048 IrInstruction *expr_value = typeof_instruction->value->other;15224 IrInstruction *expr_value = typeof_instruction->value->other;
15049 TypeTableEntry *type_entry = expr_value->value.type;15225 ZigType *type_entry = expr_value->value.type;
15050 if (type_is_invalid(type_entry))15226 if (type_is_invalid(type_entry))
15051 return ira->codegen->builtin_types.entry_invalid;15227 return ira->codegen->builtin_types.entry_invalid;
15052 switch (type_entry->id) {15228 switch (type_entry->id) {
15053 case TypeTableEntryIdInvalid:15229 case ZigTypeIdInvalid:
15054 zig_unreachable(); // handled above15230 zig_unreachable(); // handled above
15055 case TypeTableEntryIdComptimeFloat:15231 case ZigTypeIdComptimeFloat:
15056 case TypeTableEntryIdComptimeInt:15232 case ZigTypeIdComptimeInt:
15057 case TypeTableEntryIdUndefined:15233 case ZigTypeIdUndefined:
15058 case TypeTableEntryIdNull:15234 case ZigTypeIdNull:
15059 case TypeTableEntryIdNamespace:15235 case ZigTypeIdNamespace:
15060 case TypeTableEntryIdBlock:15236 case ZigTypeIdBlock:
15061 case TypeTableEntryIdBoundFn:15237 case ZigTypeIdBoundFn:
15062 case TypeTableEntryIdMetaType:15238 case ZigTypeIdMetaType:
15063 case TypeTableEntryIdVoid:15239 case ZigTypeIdVoid:
15064 case TypeTableEntryIdBool:15240 case ZigTypeIdBool:
15065 case TypeTableEntryIdUnreachable:15241 case ZigTypeIdUnreachable:
15066 case TypeTableEntryIdInt:15242 case ZigTypeIdInt:
15067 case TypeTableEntryIdFloat:15243 case ZigTypeIdFloat:
15068 case TypeTableEntryIdPointer:15244 case ZigTypeIdPointer:
15069 case TypeTableEntryIdArray:15245 case ZigTypeIdArray:
15070 case TypeTableEntryIdStruct:15246 case ZigTypeIdStruct:
15071 case TypeTableEntryIdOptional:15247 case ZigTypeIdOptional:
15072 case TypeTableEntryIdErrorUnion:15248 case ZigTypeIdErrorUnion:
15073 case TypeTableEntryIdErrorSet:15249 case ZigTypeIdErrorSet:
15074 case TypeTableEntryIdEnum:15250 case ZigTypeIdEnum:
15075 case TypeTableEntryIdUnion:15251 case ZigTypeIdUnion:
15076 case TypeTableEntryIdFn:15252 case ZigTypeIdFn:
15077 case TypeTableEntryIdArgTuple:15253 case ZigTypeIdArgTuple:
15078 case TypeTableEntryIdOpaque:15254 case ZigTypeIdOpaque:
15079 case TypeTableEntryIdPromise:15255 case ZigTypeIdPromise:
15080 {15256 {
15081 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);15257 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
15082 out_val->data.x_type = type_entry;15258 out_val->data.x_type = type_entry;
...@@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi...@@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
15088 zig_unreachable();15264 zig_unreachable();
15089}15265}
1509015266
15091static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,15267static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
15092 IrInstructionToPtrType *to_ptr_type_instruction)15268 IrInstructionToPtrType *to_ptr_type_instruction)
15093{15269{
15094 IrInstruction *value = to_ptr_type_instruction->value->other;15270 IrInstruction *value = to_ptr_type_instruction->value->other;
15095 TypeTableEntry *type_entry = value->value.type;15271 ZigType *type_entry = value->value.type;
15096 if (type_is_invalid(type_entry))15272 if (type_is_invalid(type_entry))
15097 return type_entry;15273 return type_entry;
1509815274
15099 TypeTableEntry *ptr_type;15275 ZigType *ptr_type;
15100 if (type_entry->id == TypeTableEntryIdArray) {15276 if (type_entry->id == ZigTypeIdArray) {
15101 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);15277 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
15102 } else if (is_slice(type_entry)) {15278 } else if (is_slice(type_entry)) {
15103 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);15279 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) {
15105 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);15281 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
15106 if (!arg_tuple_val)15282 if (!arg_tuple_val)
15107 return ira->codegen->builtin_types.entry_invalid;15283 return ira->codegen->builtin_types.entry_invalid;
...@@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,...@@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
15117 return ira->codegen->builtin_types.entry_type;15293 return ira->codegen->builtin_types.entry_type;
15118}15294}
1511915295
15120static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,15296static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
15121 IrInstructionPtrTypeChild *ptr_type_child_instruction)15297 IrInstructionPtrTypeChild *ptr_type_child_instruction)
15122{15298{
15123 IrInstruction *type_value = ptr_type_child_instruction->value->other;15299 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);
15125 if (type_is_invalid(type_entry))15301 if (type_is_invalid(type_entry))
15126 return type_entry;15302 return type_entry;
1512715303
15128 if (type_entry->id != TypeTableEntryIdPointer) {15304 if (type_entry->id != ZigTypeIdPointer) {
15129 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,15305 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
15130 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));15306 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
15131 return ira->codegen->builtin_types.entry_invalid;15307 return ira->codegen->builtin_types.entry_invalid;
...@@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
15136 return ira->codegen->builtin_types.entry_type;15312 return ira->codegen->builtin_types.entry_type;
15137}15313}
1513815314
15139static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {15315static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
15140 if (ira->new_irb.exec->is_inline) {15316 if (ira->new_irb.exec->is_inline) {
15141 // ignore setCold when running functions at compile time15317 // ignore setCold when running functions at compile time
15142 ir_build_const_from(ira, &instruction->base);15318 ir_build_const_from(ira, &instruction->base);
...@@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc...@@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
15148 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))15324 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
15149 return ira->codegen->builtin_types.entry_invalid;15325 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);
15152 if (fn_entry == nullptr) {15328 if (fn_entry == nullptr) {
15153 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));15329 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));
15154 return ira->codegen->builtin_types.entry_invalid;15330 return ira->codegen->builtin_types.entry_invalid;
...@@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc...@@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
15166 ir_build_const_from(ira, &instruction->base);15342 ir_build_const_from(ira, &instruction->base);
15167 return ira->codegen->builtin_types.entry_void;15343 return ira->codegen->builtin_types.entry_void;
15168}15344}
15169static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,15345static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15170 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)15346 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
15171{15347{
15172 if (ira->new_irb.exec->is_inline) {15348 if (ira->new_irb.exec->is_inline) {
...@@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15187 break;15363 break;
15188 } else if (scope->id == ScopeIdFnDef) {15364 } else if (scope->id == ScopeIdFnDef) {
15189 ScopeFnDef *def_scope = (ScopeFnDef *)scope;15365 ScopeFnDef *def_scope = (ScopeFnDef *)scope;
15190 FnTableEntry *target_fn = def_scope->fn_entry;15366 ZigFn *target_fn = def_scope->fn_entry;
15191 assert(target_fn->def_scope != nullptr);15367 assert(target_fn->def_scope != nullptr);
15192 safety_off_ptr = &target_fn->def_scope->safety_off;15368 safety_off_ptr = &target_fn->def_scope->safety_off;
15193 safety_set_node_ptr = &target_fn->def_scope->safety_set_node;15369 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,...@@ -15223,11 +15399,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15223 return ira->codegen->builtin_types.entry_void;15399 return ira->codegen->builtin_types.entry_void;
15224}15400}
1522515401
15226static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,15402static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15227 IrInstructionSetFloatMode *instruction)15403 IrInstructionSetFloatMode *instruction)
15228{15404{
15229 IrInstruction *target_instruction = instruction->scope_value->other;15405 IrInstruction *target_instruction = instruction->scope_value->other;
15230 TypeTableEntry *target_type = target_instruction->value.type;15406 ZigType *target_type = target_instruction->value.type;
15231 if (type_is_invalid(target_type))15407 if (type_is_invalid(target_type))
15232 return ira->codegen->builtin_types.entry_invalid;15408 return ira->codegen->builtin_types.entry_invalid;
15233 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);15409 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
...@@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1524215418
15243 bool *fast_math_on_ptr;15419 bool *fast_math_on_ptr;
15244 AstNode **fast_math_set_node_ptr;15420 AstNode **fast_math_set_node_ptr;
15245 if (target_type->id == TypeTableEntryIdBlock) {15421 if (target_type->id == ZigTypeIdBlock) {
15246 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;15422 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
15247 fast_math_on_ptr = &block_scope->fast_math_on;15423 fast_math_on_ptr = &block_scope->fast_math_on;
15248 fast_math_set_node_ptr = &block_scope->fast_math_set_node;15424 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) {
15250 assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);15426 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;
15252 assert(target_fn->def_scope);15428 assert(target_fn->def_scope);
15253 fast_math_on_ptr = &target_fn->def_scope->fast_math_on;15429 fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
15254 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;15430 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) {
15256 ScopeDecls *decls_scope;15432 ScopeDecls *decls_scope;
15257 TypeTableEntry *type_arg = target_val->data.x_type;15433 ZigType *type_arg = target_val->data.x_type;
15258 if (type_arg->id == TypeTableEntryIdStruct) {15434 if (type_arg->id == ZigTypeIdStruct) {
15259 decls_scope = type_arg->data.structure.decls_scope;15435 decls_scope = type_arg->data.structure.decls_scope;
15260 } else if (type_arg->id == TypeTableEntryIdEnum) {15436 } else if (type_arg->id == ZigTypeIdEnum) {
15261 decls_scope = type_arg->data.enumeration.decls_scope;15437 decls_scope = type_arg->data.enumeration.decls_scope;
15262 } else if (type_arg->id == TypeTableEntryIdUnion) {15438 } else if (type_arg->id == ZigTypeIdUnion) {
15263 decls_scope = type_arg->data.unionation.decls_scope;15439 decls_scope = type_arg->data.unionation.decls_scope;
15264 } else {15440 } else {
15265 ir_add_error_node(ira, target_instruction->source_node,15441 ir_add_error_node(ira, target_instruction->source_node,
...@@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15294 return ira->codegen->builtin_types.entry_void;15470 return ira->codegen->builtin_types.entry_void;
15295}15471}
1529615472
15297static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,15473static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15298 IrInstructionSliceType *slice_type_instruction)15474 IrInstructionSliceType *slice_type_instruction)
15299{15475{
15300 Error err;15476 Error err;
...@@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15304 return ira->codegen->builtin_types.entry_invalid;15480 return ira->codegen->builtin_types.entry_invalid;
15305 }15481 }
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);
15308 if (type_is_invalid(child_type))15484 if (type_is_invalid(child_type))
15309 return ira->codegen->builtin_types.entry_invalid;15485 return ira->codegen->builtin_types.entry_invalid;
1531015486
...@@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15318 bool is_volatile = slice_type_instruction->is_volatile;15494 bool is_volatile = slice_type_instruction->is_volatile;
1531915495
15320 switch (child_type->id) {15496 switch (child_type->id) {
15321 case TypeTableEntryIdInvalid: // handled above15497 case ZigTypeIdInvalid: // handled above
15322 zig_unreachable();15498 zig_unreachable();
15323 case TypeTableEntryIdUnreachable:15499 case ZigTypeIdUnreachable:
15324 case TypeTableEntryIdUndefined:15500 case ZigTypeIdUndefined:
15325 case TypeTableEntryIdNull:15501 case ZigTypeIdNull:
15326 case TypeTableEntryIdBlock:15502 case ZigTypeIdBlock:
15327 case TypeTableEntryIdArgTuple:15503 case ZigTypeIdArgTuple:
15328 case TypeTableEntryIdOpaque:15504 case ZigTypeIdOpaque:
15329 ir_add_error_node(ira, slice_type_instruction->base.source_node,15505 ir_add_error_node(ira, slice_type_instruction->base.source_node,
15330 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));15506 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));
15331 return ira->codegen->builtin_types.entry_invalid;15507 return ira->codegen->builtin_types.entry_invalid;
15332 case TypeTableEntryIdMetaType:15508 case ZigTypeIdMetaType:
15333 case TypeTableEntryIdVoid:15509 case ZigTypeIdVoid:
15334 case TypeTableEntryIdBool:15510 case ZigTypeIdBool:
15335 case TypeTableEntryIdInt:15511 case ZigTypeIdInt:
15336 case TypeTableEntryIdFloat:15512 case ZigTypeIdFloat:
15337 case TypeTableEntryIdPointer:15513 case ZigTypeIdPointer:
15338 case TypeTableEntryIdArray:15514 case ZigTypeIdArray:
15339 case TypeTableEntryIdStruct:15515 case ZigTypeIdStruct:
15340 case TypeTableEntryIdComptimeFloat:15516 case ZigTypeIdComptimeFloat:
15341 case TypeTableEntryIdComptimeInt:15517 case ZigTypeIdComptimeInt:
15342 case TypeTableEntryIdOptional:15518 case ZigTypeIdOptional:
15343 case TypeTableEntryIdErrorUnion:15519 case ZigTypeIdErrorUnion:
15344 case TypeTableEntryIdErrorSet:15520 case ZigTypeIdErrorSet:
15345 case TypeTableEntryIdEnum:15521 case ZigTypeIdEnum:
15346 case TypeTableEntryIdUnion:15522 case ZigTypeIdUnion:
15347 case TypeTableEntryIdFn:15523 case ZigTypeIdFn:
15348 case TypeTableEntryIdNamespace:15524 case ZigTypeIdNamespace:
15349 case TypeTableEntryIdBoundFn:15525 case ZigTypeIdBoundFn:
15350 case TypeTableEntryIdPromise:15526 case ZigTypeIdPromise:
15351 {15527 {
15352 if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))15528 if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))
15353 return ira->codegen->builtin_types.entry_invalid;15529 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,
15355 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0);15531 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);
15357 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);15533 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
15358 out_val->data.x_type = result_type;15534 out_val->data.x_type = result_type;
15359 return ira->codegen->builtin_types.entry_type;15535 return ira->codegen->builtin_types.entry_type;
...@@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15362 zig_unreachable();15538 zig_unreachable();
15363}15539}
1536415540
15365static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {15541static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {
15366 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);15542 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
1536715543
15368 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;15544 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
...@@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA...@@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
15392 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);15568 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
15393 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);15569 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;
15396 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {15572 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
15397 AsmOutput *asm_output = asm_expr->output_list.at(i);15573 AsmOutput *asm_output = asm_expr->output_list.at(i);
15398 if (asm_output->return_type) {15574 if (asm_output->return_type) {
...@@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA...@@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
15414 return return_type;15590 return return_type;
15415}15591}
1541615592
15417static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,15593static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,
15418 IrInstructionArrayType *array_type_instruction)15594 IrInstructionArrayType *array_type_instruction)
15419{15595{
15596 Error err;
15597
15420 IrInstruction *size_value = array_type_instruction->size->other;15598 IrInstruction *size_value = array_type_instruction->size->other;
15421 uint64_t size;15599 uint64_t size;
15422 if (!ir_resolve_usize(ira, size_value, &size))15600 if (!ir_resolve_usize(ira, size_value, &size))
15423 return ira->codegen->builtin_types.entry_invalid;15601 return ira->codegen->builtin_types.entry_invalid;
1542415602
15425 IrInstruction *child_type_value = array_type_instruction->child_type->other;15603 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);
15427 if (type_is_invalid(child_type))15605 if (type_is_invalid(child_type))
15428 return ira->codegen->builtin_types.entry_invalid;15606 return ira->codegen->builtin_types.entry_invalid;
15429 switch (child_type->id) {15607 switch (child_type->id) {
15430 case TypeTableEntryIdInvalid: // handled above15608 case ZigTypeIdInvalid: // handled above
15431 zig_unreachable();15609 zig_unreachable();
15432 case TypeTableEntryIdUnreachable:15610 case ZigTypeIdUnreachable:
15433 case TypeTableEntryIdUndefined:15611 case ZigTypeIdUndefined:
15434 case TypeTableEntryIdNull:15612 case ZigTypeIdNull:
15435 case TypeTableEntryIdBlock:15613 case ZigTypeIdBlock:
15436 case TypeTableEntryIdArgTuple:15614 case ZigTypeIdArgTuple:
15437 case TypeTableEntryIdOpaque:15615 case ZigTypeIdOpaque:
15438 ir_add_error_node(ira, array_type_instruction->base.source_node,15616 ir_add_error_node(ira, array_type_instruction->base.source_node,
15439 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));15617 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
15440 return ira->codegen->builtin_types.entry_invalid;15618 return ira->codegen->builtin_types.entry_invalid;
15441 case TypeTableEntryIdMetaType:15619 case ZigTypeIdMetaType:
15442 case TypeTableEntryIdVoid:15620 case ZigTypeIdVoid:
15443 case TypeTableEntryIdBool:15621 case ZigTypeIdBool:
15444 case TypeTableEntryIdInt:15622 case ZigTypeIdInt:
15445 case TypeTableEntryIdFloat:15623 case ZigTypeIdFloat:
15446 case TypeTableEntryIdPointer:15624 case ZigTypeIdPointer:
15447 case TypeTableEntryIdArray:15625 case ZigTypeIdArray:
15448 case TypeTableEntryIdStruct:15626 case ZigTypeIdStruct:
15449 case TypeTableEntryIdComptimeFloat:15627 case ZigTypeIdComptimeFloat:
15450 case TypeTableEntryIdComptimeInt:15628 case ZigTypeIdComptimeInt:
15451 case TypeTableEntryIdOptional:15629 case ZigTypeIdOptional:
15452 case TypeTableEntryIdErrorUnion:15630 case ZigTypeIdErrorUnion:
15453 case TypeTableEntryIdErrorSet:15631 case ZigTypeIdErrorSet:
15454 case TypeTableEntryIdEnum:15632 case ZigTypeIdEnum:
15455 case TypeTableEntryIdUnion:15633 case ZigTypeIdUnion:
15456 case TypeTableEntryIdFn:15634 case ZigTypeIdFn:
15457 case TypeTableEntryIdNamespace:15635 case ZigTypeIdNamespace:
15458 case TypeTableEntryIdBoundFn:15636 case ZigTypeIdBoundFn:
15459 case TypeTableEntryIdPromise:15637 case ZigTypeIdPromise:
15460 {15638 {
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);
15462 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);15642 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
15463 out_val->data.x_type = result_type;15643 out_val->data.x_type = result_type;
15464 return ira->codegen->builtin_types.entry_type;15644 return ira->codegen->builtin_types.entry_type;
...@@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
15467 zig_unreachable();15647 zig_unreachable();
15468}15648}
1546915649
15470static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {15650static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
15471 TypeTableEntry *promise_type;15651 ZigType *promise_type;
1547215652
15473 if (instruction->payload_type == nullptr) {15653 if (instruction->payload_type == nullptr) {
15474 promise_type = ira->codegen->builtin_types.entry_promise;15654 promise_type = ira->codegen->builtin_types.entry_promise;
15475 } else {15655 } 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);
15477 if (type_is_invalid(payload_type))15657 if (type_is_invalid(payload_type))
15478 return ira->codegen->builtin_types.entry_invalid;15658 return ira->codegen->builtin_types.entry_invalid;
1547915659
...@@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns...@@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns
15485 return ira->codegen->builtin_types.entry_type;15665 return ira->codegen->builtin_types.entry_type;
15486}15666}
1548715667
15488static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,15668static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,
15489 IrInstructionSizeOf *size_of_instruction)15669 IrInstructionSizeOf *size_of_instruction)
15490{15670{
15491 Error err;15671 Error err;
15492 IrInstruction *type_value = size_of_instruction->type_value->other;15672 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
15495 if ((err = ensure_complete_type(ira->codegen, type_entry)))15675 if ((err = ensure_complete_type(ira->codegen, type_entry)))
15496 return ira->codegen->builtin_types.entry_invalid;15676 return ira->codegen->builtin_types.entry_invalid;
1549715677
15498 switch (type_entry->id) {15678 switch (type_entry->id) {
15499 case TypeTableEntryIdInvalid: // handled above15679 case ZigTypeIdInvalid: // handled above
15500 zig_unreachable();15680 zig_unreachable();
15501 case TypeTableEntryIdUnreachable:15681 case ZigTypeIdUnreachable:
15502 case TypeTableEntryIdUndefined:15682 case ZigTypeIdUndefined:
15503 case TypeTableEntryIdNull:15683 case ZigTypeIdNull:
15504 case TypeTableEntryIdBlock:15684 case ZigTypeIdBlock:
15505 case TypeTableEntryIdComptimeFloat:15685 case ZigTypeIdComptimeFloat:
15506 case TypeTableEntryIdComptimeInt:15686 case ZigTypeIdComptimeInt:
15507 case TypeTableEntryIdBoundFn:15687 case ZigTypeIdBoundFn:
15508 case TypeTableEntryIdMetaType:15688 case ZigTypeIdMetaType:
15509 case TypeTableEntryIdNamespace:15689 case ZigTypeIdNamespace:
15510 case TypeTableEntryIdArgTuple:15690 case ZigTypeIdArgTuple:
15511 case TypeTableEntryIdOpaque:15691 case ZigTypeIdOpaque:
15512 ir_add_error_node(ira, size_of_instruction->base.source_node,15692 ir_add_error_node(ira, size_of_instruction->base.source_node,
15513 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));15693 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
15514 return ira->codegen->builtin_types.entry_invalid;15694 return ira->codegen->builtin_types.entry_invalid;
15515 case TypeTableEntryIdVoid:15695 case ZigTypeIdVoid:
15516 case TypeTableEntryIdBool:15696 case ZigTypeIdBool:
15517 case TypeTableEntryIdInt:15697 case ZigTypeIdInt:
15518 case TypeTableEntryIdFloat:15698 case ZigTypeIdFloat:
15519 case TypeTableEntryIdPointer:15699 case ZigTypeIdPointer:
15520 case TypeTableEntryIdArray:15700 case ZigTypeIdArray:
15521 case TypeTableEntryIdStruct:15701 case ZigTypeIdStruct:
15522 case TypeTableEntryIdOptional:15702 case ZigTypeIdOptional:
15523 case TypeTableEntryIdErrorUnion:15703 case ZigTypeIdErrorUnion:
15524 case TypeTableEntryIdErrorSet:15704 case ZigTypeIdErrorSet:
15525 case TypeTableEntryIdEnum:15705 case ZigTypeIdEnum:
15526 case TypeTableEntryIdUnion:15706 case ZigTypeIdUnion:
15527 case TypeTableEntryIdFn:15707 case ZigTypeIdFn:
15528 case TypeTableEntryIdPromise:15708 case ZigTypeIdPromise:
15529 {15709 {
15530 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);15710 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
15531 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);15711 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,...@@ -15536,14 +15716,14 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
15536 zig_unreachable();15716 zig_unreachable();
15537}15717}
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) {
15540 IrInstruction *value = instruction->value->other;15720 IrInstruction *value = instruction->value->other;
15541 if (type_is_invalid(value->value.type))15721 if (type_is_invalid(value->value.type))
15542 return ira->codegen->builtin_types.entry_invalid;15722 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) {
15547 if (instr_is_comptime(value)) {15727 if (instr_is_comptime(value)) {
15548 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);15728 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
15549 if (!maybe_val)15729 if (!maybe_val)
...@@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1555615736
15557 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);15737 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
15558 return ira->codegen->builtin_types.entry_bool;15738 return ira->codegen->builtin_types.entry_bool;
15559 } else if (type_entry->id == TypeTableEntryIdNull) {15739 } else if (type_entry->id == ZigTypeIdNull) {
15560 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);15740 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
15561 out_val->data.x_bool = false;15741 out_val->data.x_bool = false;
15562 return ira->codegen->builtin_types.entry_bool;15742 return ira->codegen->builtin_types.entry_bool;
...@@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
15567 }15747 }
15568}15748}
1556915749
15570static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,15750static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15571 IrInstructionUnwrapOptional *unwrap_maybe_instruction)15751 IrInstructionUnwrapOptional *unwrap_maybe_instruction)
15572{15752{
15573 IrInstruction *value = unwrap_maybe_instruction->value->other;15753 IrInstruction *value = unwrap_maybe_instruction->value->other;
15574 if (type_is_invalid(value->value.type))15754 if (type_is_invalid(value->value.type))
15575 return ira->codegen->builtin_types.entry_invalid;15755 return ira->codegen->builtin_types.entry_invalid;
1557615756
15577 TypeTableEntry *ptr_type = value->value.type;15757 ZigType *ptr_type = value->value.type;
15578 assert(ptr_type->id == TypeTableEntryIdPointer);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;
15581 if (type_is_invalid(type_entry)) {15761 if (type_is_invalid(type_entry)) {
15582 return ira->codegen->builtin_types.entry_invalid;15762 return ira->codegen->builtin_types.entry_invalid;
15583 } else if (type_entry->id != TypeTableEntryIdOptional) {15763 } else if (type_entry->id != ZigTypeIdOptional) {
15584 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,15764 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
15585 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));15765 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
15586 return ira->codegen->builtin_types.entry_invalid;15766 return ira->codegen->builtin_types.entry_invalid;
15587 }15767 }
15588 TypeTableEntry *child_type = type_entry->data.maybe.child_type;15768 ZigType *child_type = type_entry->data.maybe.child_type;
15589 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,15769 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
15590 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,15770 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
15591 PtrLenSingle,15771 PtrLenSingle,
15592 get_abi_alignment(ira->codegen, child_type), 0, 0);15772 get_abi_alignment(ira->codegen, child_type), 0, 0);
...@@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15595 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);15775 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
15596 if (!val)15776 if (!val)
15597 return ira->codegen->builtin_types.entry_invalid;15777 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
15600 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {15782 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15601 if (optional_value_is_null(maybe_val)) {15783 if (optional_value_is_null(maybe_val)) {
...@@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15619 return result_type;15801 return result_type;
15620}15802}
1562115803
15622static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {15804static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
15623 IrInstruction *value = ctz_instruction->value->other;15805 IrInstruction *value = ctz_instruction->value->other;
15624 if (type_is_invalid(value->value.type)) {15806 if (type_is_invalid(value->value.type)) {
15625 return ira->codegen->builtin_types.entry_invalid;15807 return ira->codegen->builtin_types.entry_invalid;
15626 } else if (value->value.type->id == TypeTableEntryIdInt) {15808 } else if (value->value.type->id == ZigTypeIdInt) {
15627 TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,15809 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
15628 value->value.type->data.integral.bit_count);15810 value->value.type->data.integral.bit_count);
15629 if (value->value.special != ConstValSpecialRuntime) {15811 if (value->value.special != ConstValSpecialRuntime) {
15630 size_t result = bigint_ctz(&value->value.data.x_bigint,15812 size_t result = bigint_ctz(&value->value.data.x_bigint,
...@@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC...@@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
15643 }15825 }
15644}15826}
1564515827
15646static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {15828static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
15647 IrInstruction *value = clz_instruction->value->other;15829 IrInstruction *value = clz_instruction->value->other;
15648 if (type_is_invalid(value->value.type)) {15830 if (type_is_invalid(value->value.type)) {
15649 return ira->codegen->builtin_types.entry_invalid;15831 return ira->codegen->builtin_types.entry_invalid;
15650 } else if (value->value.type->id == TypeTableEntryIdInt) {15832 } else if (value->value.type->id == ZigTypeIdInt) {
15651 TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,15833 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
15652 value->value.type->data.integral.bit_count);15834 value->value.type->data.integral.bit_count);
15653 if (value->value.special != ConstValSpecialRuntime) {15835 if (value->value.special != ConstValSpecialRuntime) {
15654 size_t result = bigint_clz(&value->value.data.x_bigint,15836 size_t result = bigint_clz(&value->value.data.x_bigint,
...@@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC...@@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
15667 }15849 }
15668}15850}
1566915851
15670static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {15852static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
15671 IrInstruction *value = instruction->value->other;15853 IrInstruction *value = instruction->value->other;
15672 if (type_is_invalid(value->value.type))15854 if (type_is_invalid(value->value.type))
15673 return ira->codegen->builtin_types.entry_invalid;15855 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) {
15676 ir_add_error(ira, value,15858 ir_add_error(ira, value,
15677 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));15859 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
15678 return ira->codegen->builtin_types.entry_invalid;15860 return ira->codegen->builtin_types.entry_invalid;
...@@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru...@@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru
15688 bigint_init_unsigned(&out_val->data.x_bigint, result);15870 bigint_init_unsigned(&out_val->data.x_bigint, result);
15689 return ira->codegen->builtin_types.entry_num_lit_int;15871 return ira->codegen->builtin_types.entry_num_lit_int;
15690 }15872 }
15691 if (value->value.type->id == TypeTableEntryIdComptimeInt) {15873 if (value->value.type->id == ZigTypeIdComptimeInt) {
15692 Buf *val_buf = buf_alloc();15874 Buf *val_buf = buf_alloc();
15693 bigint_append_buf(val_buf, &val->data.x_bigint, 10);15875 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
15694 ir_add_error(ira, &instruction->base,15876 ir_add_error(ira, &instruction->base,
...@@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
15713 if (type_is_invalid(value->value.type))15895 if (type_is_invalid(value->value.type))
15714 return ira->codegen->invalid_instruction;15896 return ira->codegen->invalid_instruction;
1571515897
15716 if (value->value.type->id == TypeTableEntryIdEnum) {15898 if (value->value.type->id == ZigTypeIdEnum) {
15717 return value;15899 return value;
15718 }15900 }
1571915901
15720 if (value->value.type->id != TypeTableEntryIdUnion) {15902 if (value->value.type->id != ZigTypeIdUnion) {
15721 ir_add_error(ira, value,15903 ir_add_error(ira, value,
15722 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));15904 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));
15723 return ira->codegen->invalid_instruction;15905 return ira->codegen->invalid_instruction;
...@@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
15731 return ira->codegen->invalid_instruction;15913 return ira->codegen->invalid_instruction;
15732 }15914 }
1573315915
15734 TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type;15916 ZigType *tag_type = value->value.type->data.unionation.tag_type;
15735 assert(tag_type->id == TypeTableEntryIdEnum);15917 assert(tag_type->id == ZigTypeIdEnum);
1573615918
15737 if (instr_is_comptime(value)) {15919 if (instr_is_comptime(value)) {
15738 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);15920 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
15752 return result;15934 return result;
15753}15935}
1575415936
15755static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,15937static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15756 IrInstructionSwitchBr *switch_br_instruction)15938 IrInstructionSwitchBr *switch_br_instruction)
15757{15939{
15758 IrInstruction *target_value = switch_br_instruction->target_value->other;15940 IrInstruction *target_value = switch_br_instruction->target_value->other;
...@@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15784 if (type_is_invalid(case_value->value.type))15966 if (type_is_invalid(case_value->value.type))
15785 return ir_unreach_error(ira);15967 return ir_unreach_error(ira);
1578615968
15787 if (case_value->value.type->id == TypeTableEntryIdEnum) {15969 if (case_value->value.type->id == ZigTypeIdEnum) {
15788 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);15970 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);
15789 if (type_is_invalid(case_value->value.type))15971 if (type_is_invalid(case_value->value.type))
15790 return ir_unreach_error(ira);15972 return ir_unreach_error(ira);
...@@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15831 if (type_is_invalid(new_value->value.type))16013 if (type_is_invalid(new_value->value.type))
15832 continue;16014 continue;
1583316015
15834 if (new_value->value.type->id == TypeTableEntryIdEnum) {16016 if (new_value->value.type->id == ZigTypeIdEnum) {
15835 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);16017 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);
15836 if (type_is_invalid(new_value->value.type))16018 if (type_is_invalid(new_value->value.type))
15837 continue;16019 continue;
...@@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15860 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);16042 return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
15861}16043}
1586216044
15863static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,16045static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15864 IrInstructionSwitchTarget *switch_target_instruction)16046 IrInstructionSwitchTarget *switch_target_instruction)
15865{16047{
15866 Error err;16048 Error err;
...@@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15868 if (type_is_invalid(target_value_ptr->value.type))16050 if (type_is_invalid(target_value_ptr->value.type))
15869 return ira->codegen->builtin_types.entry_invalid;16051 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) {
15872 assert(instr_is_comptime(target_value_ptr));16054 assert(instr_is_comptime(target_value_ptr));
15873 TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;16055 ZigType *ptr_type = target_value_ptr->value.data.x_type;
15874 assert(ptr_type->id == TypeTableEntryIdPointer);16056 assert(ptr_type->id == ZigTypeIdPointer);
15875 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16057 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
15876 out_val->type = ira->codegen->builtin_types.entry_type;16058 out_val->type = ira->codegen->builtin_types.entry_type;
15877 out_val->data.x_type = ptr_type->data.pointer.child_type;16059 out_val->data.x_type = ptr_type->data.pointer.child_type;
15878 return out_val->type;16060 return out_val->type;
15879 }16061 }
1588016062
15881 if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {16063 if (target_value_ptr->value.type->id != ZigTypeIdPointer) {
15882 ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));16064 ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
15883 return ira->codegen->builtin_types.entry_invalid;16065 return ira->codegen->builtin_types.entry_invalid;
15884 }16066 }
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;
15887 ConstExprValue *pointee_val = nullptr;16069 ConstExprValue *pointee_val = nullptr;
15888 if (instr_is_comptime(target_value_ptr)) {16070 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
15890 if (pointee_val->special == ConstValSpecialRuntime)16075 if (pointee_val->special == ConstValSpecialRuntime)
15891 pointee_val = nullptr;16076 pointee_val = nullptr;
15892 }16077 }
...@@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15894 return ira->codegen->builtin_types.entry_invalid;16079 return ira->codegen->builtin_types.entry_invalid;
1589516080
15896 switch (target_type->id) {16081 switch (target_type->id) {
15897 case TypeTableEntryIdInvalid:16082 case ZigTypeIdInvalid:
15898 zig_unreachable();16083 zig_unreachable();
15899 case TypeTableEntryIdMetaType:16084 case ZigTypeIdMetaType:
15900 case TypeTableEntryIdVoid:16085 case ZigTypeIdVoid:
15901 case TypeTableEntryIdBool:16086 case ZigTypeIdBool:
15902 case TypeTableEntryIdInt:16087 case ZigTypeIdInt:
15903 case TypeTableEntryIdFloat:16088 case ZigTypeIdFloat:
15904 case TypeTableEntryIdComptimeFloat:16089 case ZigTypeIdComptimeFloat:
15905 case TypeTableEntryIdComptimeInt:16090 case ZigTypeIdComptimeInt:
15906 case TypeTableEntryIdPointer:16091 case ZigTypeIdPointer:
15907 case TypeTableEntryIdPromise:16092 case ZigTypeIdPromise:
15908 case TypeTableEntryIdFn:16093 case ZigTypeIdFn:
15909 case TypeTableEntryIdNamespace:16094 case ZigTypeIdNamespace:
15910 case TypeTableEntryIdErrorSet:16095 case ZigTypeIdErrorSet:
15911 if (pointee_val) {16096 if (pointee_val) {
15912 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16097 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
15913 copy_const_val(out_val, pointee_val, true);16098 copy_const_val(out_val, pointee_val, true);
...@@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1591716102
15918 ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);16103 ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);
15919 return target_type;16104 return target_type;
15920 case TypeTableEntryIdUnion: {16105 case ZigTypeIdUnion: {
15921 AstNode *decl_node = target_type->data.unionation.decl_node;16106 AstNode *decl_node = target_type->data.unionation.decl_node;
15922 if (!decl_node->data.container_decl.auto_enum &&16107 if (!decl_node->data.container_decl.auto_enum &&
15923 decl_node->data.container_decl.init_arg_expr == nullptr)16108 decl_node->data.container_decl.init_arg_expr == nullptr)
...@@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15928 buf_sprintf("consider 'union(enum)' here"));16113 buf_sprintf("consider 'union(enum)' here"));
15929 return ira->codegen->builtin_types.entry_invalid;16114 return ira->codegen->builtin_types.entry_invalid;
15930 }16115 }
15931 TypeTableEntry *tag_type = target_type->data.unionation.tag_type;16116 ZigType *tag_type = target_type->data.unionation.tag_type;
15932 assert(tag_type != nullptr);16117 assert(tag_type != nullptr);
15933 assert(tag_type->id == TypeTableEntryIdEnum);16118 assert(tag_type->id == ZigTypeIdEnum);
15934 if (pointee_val) {16119 if (pointee_val) {
15935 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16120 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
15936 bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag);16121 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,...@@ -15953,7 +16138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15953 ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);16138 ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);
15954 return tag_type;16139 return tag_type;
15955 }16140 }
15956 case TypeTableEntryIdEnum: {16141 case ZigTypeIdEnum: {
15957 if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))16142 if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))
15958 return ira->codegen->builtin_types.entry_invalid;16143 return ira->codegen->builtin_types.entry_invalid;
15959 if (target_type->data.enumeration.src_field_count < 2) {16144 if (target_type->data.enumeration.src_field_count < 2) {
...@@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15975 ir_link_new_instruction(enum_value, &switch_target_instruction->base);16160 ir_link_new_instruction(enum_value, &switch_target_instruction->base);
15976 return target_type;16161 return target_type;
15977 }16162 }
15978 case TypeTableEntryIdErrorUnion:16163 case ZigTypeIdErrorUnion:
15979 case TypeTableEntryIdUnreachable:16164 case ZigTypeIdUnreachable:
15980 case TypeTableEntryIdArray:16165 case ZigTypeIdArray:
15981 case TypeTableEntryIdStruct:16166 case ZigTypeIdStruct:
15982 case TypeTableEntryIdUndefined:16167 case ZigTypeIdUndefined:
15983 case TypeTableEntryIdNull:16168 case ZigTypeIdNull:
15984 case TypeTableEntryIdOptional:16169 case ZigTypeIdOptional:
15985 case TypeTableEntryIdBlock:16170 case ZigTypeIdBlock:
15986 case TypeTableEntryIdBoundFn:16171 case ZigTypeIdBoundFn:
15987 case TypeTableEntryIdArgTuple:16172 case ZigTypeIdArgTuple:
15988 case TypeTableEntryIdOpaque:16173 case ZigTypeIdOpaque:
15989 ir_add_error(ira, &switch_target_instruction->base,16174 ir_add_error(ira, &switch_target_instruction->base,
15990 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));16175 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
15991 return ira->codegen->builtin_types.entry_invalid;16176 return ira->codegen->builtin_types.entry_invalid;
...@@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15993 zig_unreachable();16178 zig_unreachable();
15994}16179}
1599516180
15996static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {16181static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
15997 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;16182 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
15998 if (type_is_invalid(target_value_ptr->value.type))16183 if (type_is_invalid(target_value_ptr->value.type))
15999 return ira->codegen->builtin_types.entry_invalid;16184 return ira->codegen->builtin_types.entry_invalid;
...@@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr...@@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
16002 if (type_is_invalid(prong_value->value.type))16187 if (type_is_invalid(prong_value->value.type))
16003 return ira->codegen->builtin_types.entry_invalid;16188 return ira->codegen->builtin_types.entry_invalid;
1600416189
16005 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);16190 assert(target_value_ptr->value.type->id == ZigTypeIdPointer);
16006 TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;16191 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
16007 if (target_type->id == TypeTableEntryIdUnion) {16192 if (target_type->id == ZigTypeIdUnion) {
16008 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);16193 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);
16009 if (!prong_val)16194 if (!prong_val)
16010 return ira->codegen->builtin_types.entry_invalid;16195 return ira->codegen->builtin_types.entry_invalid;
1601116196
16012 assert(prong_value->value.type->id == TypeTableEntryIdEnum);16197 assert(prong_value->value.type->id == ZigTypeIdEnum);
16013 TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);16198 TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);
1601416199
16015 if (instr_is_comptime(target_value_ptr)) {16200 if (instr_is_comptime(target_value_ptr)) {
...@@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr...@@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
16017 if (!target_value_ptr)16202 if (!target_value_ptr)
16018 return ira->codegen->builtin_types.entry_invalid;16203 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
16021 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);16209 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
16022 out_val->data.x_ptr.special = ConstPtrSpecialRef;16210 out_val->data.x_ptr.special = ConstPtrSpecialRef;
16023 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;16211 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...@@ -16035,14 +16223,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
16035 }16223 }
16036}16224}
1603716225
16038static TypeTableEntry *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {16226static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
16039 IrInstruction *value = instruction->value->other;16227 IrInstruction *value = instruction->value->other;
16040 IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value);16228 IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value);
16041 ir_link_new_instruction(new_instruction, &instruction->base);16229 ir_link_new_instruction(new_instruction, &instruction->base);
16042 return new_instruction->value.type;16230 return new_instruction->value.type;
16043}16231}
1604416232
16045static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {16233static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
16046 IrInstruction *name_value = import_instruction->name->other;16234 IrInstruction *name_value = import_instruction->name->other;
16047 Buf *import_target_str = ir_resolve_str(ira, name_value);16235 Buf *import_target_str = ir_resolve_str(ira, name_value);
16048 if (!import_target_str)16236 if (!import_target_str)
...@@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
16074 os_path_join(search_dir, import_target_path, &full_path);16262 os_path_join(search_dir, import_target_path, &full_path);
1607516263
16076 Buf *import_code = buf_alloc();16264 Buf *import_code = buf_alloc();
16077 Buf *abs_full_path = buf_alloc();16265 Buf *resolved_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 }
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);
16093 if (import_entry) {16271 if (import_entry) {
16094 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);16272 ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);
16095 out_val->data.x_import = import_entry->value;16273 out_val->data.x_import = import_entry->value;
16096 return ira->codegen->builtin_types.entry_namespace;16274 return ira->codegen->builtin_types.entry_namespace;
16097 }16275 }
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))) {
16100 if (err == ErrorFileNotFound) {16279 if (err == ErrorFileNotFound) {
16101 ir_add_error_node(ira, source_node,16280 ir_add_error_node(ira, source_node,
16102 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));16281 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
...@@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
16107 return ira->codegen->builtin_types.entry_invalid;16286 return ira->codegen->builtin_types.entry_invalid;
16108 }16287 }
16109 }16288 }
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
16112 scan_import(ira->codegen, target_import);16291 scan_import(ira->codegen, target_import);
1611316292
...@@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1611716296
16118}16297}
1611916298
16120static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,16299static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira,
16121 IrInstructionArrayLen *array_len_instruction)16300 IrInstructionArrayLen *array_len_instruction)
16122{16301{
16123 IrInstruction *array_value = array_len_instruction->array_value->other;16302 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;
16125 if (type_is_invalid(type_entry)) {16304 if (type_is_invalid(type_entry)) {
16126 return ira->codegen->builtin_types.entry_invalid;16305 return ira->codegen->builtin_types.entry_invalid;
16127 } else if (type_entry->id == TypeTableEntryIdArray) {16306 } else if (type_entry->id == ZigTypeIdArray) {
16128 return ir_analyze_const_usize(ira, &array_len_instruction->base,16307 return ir_analyze_const_usize(ira, &array_len_instruction->base,
16129 type_entry->data.array.len);16308 type_entry->data.array.len);
16130 } else if (is_slice(type_entry)) {16309 } else if (is_slice(type_entry)) {
...@@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,...@@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
16148 }16327 }
16149}16328}
1615016329
16151static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {16330static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
16152 IrInstruction *value = ref_instruction->value->other;16331 IrInstruction *value = ref_instruction->value->other;
16153 return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);16332 return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
16154}16333}
1615516334
16156static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,16335static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,
16157 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)16336 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16158{16337{
16159 Error err;16338 Error err;
16160 assert(container_type->id == TypeTableEntryIdUnion);16339 assert(container_type->id == ZigTypeIdUnion);
1616116340
16162 if ((err = ensure_complete_type(ira->codegen, container_type)))16341 if ((err = ensure_complete_type(ira->codegen, container_type)))
16163 return ira->codegen->builtin_types.entry_invalid;16342 return ira->codegen->builtin_types.entry_invalid;
...@@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir...@@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
16219 return container_type;16398 return container_type;
16220}16399}
1622116400
16222static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,16401static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
16223 TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)16402 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16224{16403{
16225 Error err;16404 Error err;
16226 if (container_type->id == TypeTableEntryIdUnion) {16405 if (container_type->id == ZigTypeIdUnion) {
16227 return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);16406 return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);
16228 }16407 }
16229 if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {16408 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
16230 ir_add_error(ira, instruction,16409 ir_add_error(ira, instruction,
16231 buf_sprintf("type '%s' does not support struct initialization syntax",16410 buf_sprintf("type '%s' does not support struct initialization syntax",
16232 buf_ptr(&container_type->name)));16411 buf_ptr(&container_type->name)));
...@@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
16339 return container_type;16518 return container_type;
16340}16519}
1634116520
16342static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira,16521static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16343 IrInstructionContainerInitList *instruction)16522 IrInstructionContainerInitList *instruction)
16344{16523{
16345 IrInstruction *container_type_value = instruction->container_type->other;16524 IrInstruction *container_type_value = instruction->container_type->other;
...@@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
16347 return ira->codegen->builtin_types.entry_invalid;16526 return ira->codegen->builtin_types.entry_invalid;
1634816527
16349 size_t elem_count = instruction->item_count;16528 size_t elem_count = instruction->item_count;
16350 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {16529 if (container_type_value->value.type->id == ZigTypeIdMetaType) {
16351 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);16530 ZigType *container_type = ir_resolve_type(ira, container_type_value);
16352 if (type_is_invalid(container_type))16531 if (type_is_invalid(container_type))
16353 return ira->codegen->builtin_types.entry_invalid;16532 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) {
16356 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,16535 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
16357 0, nullptr);16536 0, nullptr);
16358 } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) {16537 } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
16359 // array is same as slice init but we make a compile error if the length is wrong16538 // array is same as slice init but we make a compile error if the length is wrong
16360 TypeTableEntry *child_type;16539 ZigType *child_type;
16361 if (container_type->id == TypeTableEntryIdArray) {16540 if (container_type->id == ZigTypeIdArray) {
16362 child_type = container_type->data.array.child_type;16541 child_type = container_type->data.array.child_type;
16363 if (container_type->data.array.len != elem_count) {16542 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
16366 ir_add_error(ira, &instruction->base,16545 ir_add_error(ira, &instruction->base,
16367 buf_sprintf("expected %s literal, found %s literal",16546 buf_sprintf("expected %s literal, found %s literal",
...@@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
16369 return ira->codegen->builtin_types.entry_invalid;16548 return ira->codegen->builtin_types.entry_invalid;
16370 }16549 }
16371 } else {16550 } else {
16372 TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;16551 ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
16373 assert(pointer_type->id == TypeTableEntryIdPointer);16552 assert(pointer_type->id == ZigTypeIdPointer);
16374 child_type = pointer_type->data.pointer.child_type;16553 child_type = pointer_type->data.pointer.child_type;
16375 }16554 }
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
16379 ConstExprValue const_val = {};16558 ConstExprValue const_val = {};
16380 const_val.special = ConstValSpecialStatic;16559 const_val.special = ConstValSpecialStatic;
...@@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
16437 container_type_value, elem_count, new_items);16616 container_type_value, elem_count, new_items);
16438 ir_add_alloca(ira, new_instruction, fixed_size_array_type);16617 ir_add_alloca(ira, new_instruction, fixed_size_array_type);
16439 return fixed_size_array_type;16618 return fixed_size_array_type;
16440 } else if (container_type->id == TypeTableEntryIdVoid) {16619 } else if (container_type->id == ZigTypeIdVoid) {
16441 if (elem_count != 0) {16620 if (elem_count != 0) {
16442 ir_add_error_node(ira, instruction->base.source_node,16621 ir_add_error_node(ira, instruction->base.source_node,
16443 buf_sprintf("void expression expects no arguments"));16622 buf_sprintf("void expression expects no arguments"));
...@@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
16457 }16636 }
16458}16637}
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) {
16461 IrInstruction *container_type_value = instruction->container_type->other;16640 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);
16463 if (type_is_invalid(container_type))16642 if (type_is_invalid(container_type))
16464 return ira->codegen->builtin_types.entry_invalid;16643 return ira->codegen->builtin_types.entry_invalid;
1646516644
...@@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i...@@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i
16467 instruction->field_count, instruction->fields);16646 instruction->field_count, instruction->fields);
16468}16647}
1646916648
16470static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,16649static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
16471 IrInstruction *target_type_value, bool is_max)16650 IrInstruction *target_type_value, bool is_max)
16472{16651{
16473 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);16652 ZigType *target_type = ir_resolve_type(ira, target_type_value);
16474 if (type_is_invalid(target_type))16653 if (type_is_invalid(target_type))
16475 return ira->codegen->builtin_types.entry_invalid;16654 return ira->codegen->builtin_types.entry_invalid;
16476 switch (target_type->id) {16655 switch (target_type->id) {
16477 case TypeTableEntryIdInvalid:16656 case ZigTypeIdInvalid:
16478 zig_unreachable();16657 zig_unreachable();
16479 case TypeTableEntryIdInt:16658 case ZigTypeIdInt:
16480 {16659 {
16481 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);16660 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
16482 eval_min_max_value(ira->codegen, target_type, out_val, is_max);16661 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
16483 return ira->codegen->builtin_types.entry_num_lit_int;16662 return ira->codegen->builtin_types.entry_num_lit_int;
16484 }16663 }
16485 case TypeTableEntryIdBool:16664 case ZigTypeIdBool:
16486 case TypeTableEntryIdVoid:16665 case ZigTypeIdVoid:
16487 {16666 {
16488 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);16667 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
16489 eval_min_max_value(ira->codegen, target_type, out_val, is_max);16668 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
16490 return target_type;16669 return target_type;
16491 }16670 }
16492 case TypeTableEntryIdEnum:16671 case ZigTypeIdEnum:
16493 case TypeTableEntryIdFloat:16672 case ZigTypeIdFloat:
16494 case TypeTableEntryIdMetaType:16673 case ZigTypeIdMetaType:
16495 case TypeTableEntryIdUnreachable:16674 case ZigTypeIdUnreachable:
16496 case TypeTableEntryIdPointer:16675 case ZigTypeIdPointer:
16497 case TypeTableEntryIdPromise:16676 case ZigTypeIdPromise:
16498 case TypeTableEntryIdArray:16677 case ZigTypeIdArray:
16499 case TypeTableEntryIdStruct:16678 case ZigTypeIdStruct:
16500 case TypeTableEntryIdComptimeFloat:16679 case ZigTypeIdComptimeFloat:
16501 case TypeTableEntryIdComptimeInt:16680 case ZigTypeIdComptimeInt:
16502 case TypeTableEntryIdUndefined:16681 case ZigTypeIdUndefined:
16503 case TypeTableEntryIdNull:16682 case ZigTypeIdNull:
16504 case TypeTableEntryIdOptional:16683 case ZigTypeIdOptional:
16505 case TypeTableEntryIdErrorUnion:16684 case ZigTypeIdErrorUnion:
16506 case TypeTableEntryIdErrorSet:16685 case ZigTypeIdErrorSet:
16507 case TypeTableEntryIdUnion:16686 case ZigTypeIdUnion:
16508 case TypeTableEntryIdFn:16687 case ZigTypeIdFn:
16509 case TypeTableEntryIdNamespace:16688 case ZigTypeIdNamespace:
16510 case TypeTableEntryIdBlock:16689 case ZigTypeIdBlock:
16511 case TypeTableEntryIdBoundFn:16690 case ZigTypeIdBoundFn:
16512 case TypeTableEntryIdArgTuple:16691 case ZigTypeIdArgTuple:
16513 case TypeTableEntryIdOpaque:16692 case ZigTypeIdOpaque:
16514 {16693 {
16515 const char *err_format = is_max ?16694 const char *err_format = is_max ?
16516 "no max value available for type '%s'" :16695 "no max value available for type '%s'" :
...@@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_...@@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
16523 zig_unreachable();16702 zig_unreachable();
16524}16703}
1652516704
16526static TypeTableEntry *ir_analyze_instruction_min_value(IrAnalyze *ira,16705static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira,
16527 IrInstructionMinValue *instruction)16706 IrInstructionMinValue *instruction)
16528{16707{
16529 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false);16708 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false);
16530}16709}
1653116710
16532static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira,16711static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira,
16533 IrInstructionMaxValue *instruction)16712 IrInstructionMaxValue *instruction)
16534{16713{
16535 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true);16714 return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true);
16536}16715}
1653716716
16538static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,16717static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira,
16539 IrInstructionCompileErr *instruction)16718 IrInstructionCompileErr *instruction)
16540{16719{
16541 IrInstruction *msg_value = instruction->msg->other;16720 IrInstruction *msg_value = instruction->msg->other;
...@@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,...@@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
16559 return ira->codegen->builtin_types.entry_invalid;16738 return ira->codegen->builtin_types.entry_invalid;
16560}16739}
1656116740
16562static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {16741static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
16563 Buf buf = BUF_INIT;16742 Buf buf = BUF_INIT;
16564 fprintf(stderr, "| ");16743 fprintf(stderr, "| ");
16565 for (size_t i = 0; i < instruction->msg_count; i += 1) {16744 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...@@ -16579,7 +16758,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
16579 return ira->codegen->builtin_types.entry_void;16758 return ira->codegen->builtin_types.entry_void;
16580}16759}
1658116760
16582static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {16761static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
16583 IrInstruction *value = instruction->value->other;16762 IrInstruction *value = instruction->value->other;
16584 if (type_is_invalid(value->value.type))16763 if (type_is_invalid(value->value.type))
16585 return ira->codegen->builtin_types.entry_invalid;16764 return ira->codegen->builtin_types.entry_invalid;
...@@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc...@@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
16588 if (type_is_invalid(casted_value->value.type))16767 if (type_is_invalid(casted_value->value.type))
16589 return ira->codegen->builtin_types.entry_invalid;16768 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,
16592 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);16771 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);
16594 if (casted_value->value.special == ConstValSpecialStatic) {16773 if (casted_value->value.special == ConstValSpecialStatic) {
16595 ErrorTableEntry *err = casted_value->value.data.x_err_set;16774 ErrorTableEntry *err = casted_value->value.data.x_err_set;
16596 if (!err->cached_error_name_val) {16775 if (!err->cached_error_name_val) {
...@@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc...@@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
16607 return str_type;16786 return str_type;
16608}16787}
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) {
16611 Error err;16790 Error err;
16612 IrInstruction *target = instruction->target->other;16791 IrInstruction *target = instruction->target->other;
16613 if (type_is_invalid(target->value.type))16792 if (type_is_invalid(target->value.type))
16614 return ira->codegen->builtin_types.entry_invalid;16793 return ira->codegen->builtin_types.entry_invalid;
1661516794
16616 assert(target->value.type->id == TypeTableEntryIdEnum);16795 assert(target->value.type->id == ZigTypeIdEnum);
1661716796
16618 if (instr_is_comptime(target)) {16797 if (instr_is_comptime(target)) {
16619 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))16798 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...@@ -16628,7 +16807,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
16628 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,16807 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
16629 instruction->base.source_node, target);16808 instruction->base.source_node, target);
16630 ir_link_new_instruction(result, &instruction->base);16809 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(
16632 ira->codegen, ira->codegen->builtin_types.entry_u8,16811 ira->codegen, ira->codegen->builtin_types.entry_u8,
16633 true, false, PtrLenUnknown,16812 true, false, PtrLenUnknown,
16634 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),16813 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...@@ -16637,12 +16816,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
16637 return result->value.type;16816 return result->value.type;
16638}16817}
1663916818
16640static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,16819static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16641 IrInstructionFieldParentPtr *instruction)16820 IrInstructionFieldParentPtr *instruction)
16642{16821{
16643 Error err;16822 Error err;
16644 IrInstruction *type_value = instruction->type_value->other;16823 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);
16646 if (type_is_invalid(container_type))16825 if (type_is_invalid(container_type))
16647 return ira->codegen->builtin_types.entry_invalid;16826 return ira->codegen->builtin_types.entry_invalid;
1664816827
...@@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16655 if (type_is_invalid(field_ptr->value.type))16834 if (type_is_invalid(field_ptr->value.type))
16656 return ira->codegen->builtin_types.entry_invalid;16835 return ira->codegen->builtin_types.entry_invalid;
1665716836
16658 if (container_type->id != TypeTableEntryIdStruct) {16837 if (container_type->id != ZigTypeIdStruct) {
16659 ir_add_error(ira, type_value,16838 ir_add_error(ira, type_value,
16660 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));16839 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16661 return ira->codegen->builtin_types.entry_invalid;16840 return ira->codegen->builtin_types.entry_invalid;
...@@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16672 return ira->codegen->builtin_types.entry_invalid;16851 return ira->codegen->builtin_types.entry_invalid;
16673 }16852 }
1667416853
16675 if (field_ptr->value.type->id != TypeTableEntryIdPointer) {16854 if (field_ptr->value.type->id != ZigTypeIdPointer) {
16676 ir_add_error(ira, field_ptr,16855 ir_add_error(ira, field_ptr,
16677 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));16856 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));
16678 return ira->codegen->builtin_types.entry_invalid;16857 return ira->codegen->builtin_types.entry_invalid;
...@@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16682 uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry);16861 uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry);
16683 uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);16862 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,
16686 field_ptr->value.type->data.pointer.is_const,16865 field_ptr->value.type->data.pointer.is_const,
16687 field_ptr->value.type->data.pointer.is_volatile,16866 field_ptr->value.type->data.pointer.is_volatile,
16688 PtrLenSingle,16867 PtrLenSingle,
...@@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16691 if (type_is_invalid(casted_field_ptr->value.type))16870 if (type_is_invalid(casted_field_ptr->value.type))
16692 return ira->codegen->builtin_types.entry_invalid;16871 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,
16695 casted_field_ptr->value.type->data.pointer.is_const,16874 casted_field_ptr->value.type->data.pointer.is_const,
16696 casted_field_ptr->value.type->data.pointer.is_volatile,16875 casted_field_ptr->value.type->data.pointer.is_volatile,
16697 PtrLenSingle,16876 PtrLenSingle,
...@@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16730 return result_type;16909 return result_type;
16731}16910}
1673216911
16733static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,16912static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira,
16734 IrInstructionOffsetOf *instruction)16913 IrInstructionOffsetOf *instruction)
16735{16914{
16736 Error err;16915 Error err;
16737 IrInstruction *type_value = instruction->type_value->other;16916 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);
16739 if (type_is_invalid(container_type))16918 if (type_is_invalid(container_type))
16740 return ira->codegen->builtin_types.entry_invalid;16919 return ira->codegen->builtin_types.entry_invalid;
1674116920
...@@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,...@@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
16747 if (!field_name)16926 if (!field_name)
16748 return ira->codegen->builtin_types.entry_invalid;16927 return ira->codegen->builtin_types.entry_invalid;
1674916928
16750 if (container_type->id != TypeTableEntryIdStruct) {16929 if (container_type->id != ZigTypeIdStruct) {
16751 ir_add_error(ira, type_value,16930 ir_add_error(ira, type_value,
16752 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));16931 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16753 return ira->codegen->builtin_types.entry_invalid;16932 return ira->codegen->builtin_types.entry_invalid;
...@@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,...@@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
16773 return ira->codegen->builtin_types.entry_num_lit_int;16952 return ira->codegen->builtin_types.entry_num_lit_int;
16774}16953}
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)
16777{16956{
16778 Buf *field_name_buf;16957 Buf *field_name_buf;
1677916958
...@@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz...@@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz
16784 (buf_deinit(field_name_buf), true));16963 (buf_deinit(field_name_buf), true));
16785}16964}
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) {
16788 Error err;16967 Error err;
16789 static ConstExprValue *type_info_var = nullptr;16968 static ConstExprValue *type_info_var = nullptr;
16790 static TypeTableEntry *type_info_type = nullptr;16969 static ZigType *type_info_type = nullptr;
16791 if (type_info_var == nullptr) {16970 if (type_info_var == nullptr) {
16792 type_info_var = get_builtin_value(ira->codegen, "TypeInfo");16971 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
16795 assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));16974 assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));
16796 type_info_type = type_info_var->data.x_type;16975 type_info_type = type_info_var->data.x_type;
16797 assert(type_info_type->id == TypeTableEntryIdUnion);16976 assert(type_info_type->id == ZigTypeIdUnion);
16798 }16977 }
1679916978
16800 if (type_name == nullptr && root == nullptr)16979 if (type_name == nullptr && root == nullptr)
...@@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
16802 else if (type_name == nullptr)16981 else if (type_name == nullptr)
16803 return root;16982 return root;
1680416983
16805 TypeTableEntry *root_type = (root == nullptr) ? type_info_type : root;16984 ZigType *root_type = (root == nullptr) ? type_info_type : root;
1680616985
16807 ScopeDecls *type_info_scope = get_container_scope(root_type);16986 ScopeDecls *type_info_scope = get_container_scope(root_type);
16808 assert(type_info_scope != nullptr);16987 assert(type_info_scope != nullptr);
...@@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
16815 TldVar *tld = (TldVar *)entry;16994 TldVar *tld = (TldVar *)entry;
16816 assert(tld->base.id == TldIdVar);16995 assert(tld->base.id == TldIdVar);
1681716996
16818 VariableTableEntry *var = tld->var;16997 ZigVar *var = tld->var;
1681916998
16820 if ((err = ensure_complete_type(ira->codegen, var->value->type)))16999 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
16821 return ira->codegen->builtin_types.entry_invalid;17000 return ira->codegen->builtin_types.entry_invalid;
16822 assert(var->value->type->id == TypeTableEntryIdMetaType);17001 assert(var->value->type->id == ZigTypeIdMetaType);
16823 return var->value->data.x_type;17002 return var->value->data.x_type;
16824}17003}
1682517004
16826static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {17005static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
16827 Error err;17006 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);
16829 if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))17008 if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
16830 return err;17009 return err;
1683117010
...@@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16833 ensure_field_index(type_info_definition_type, "is_pub", 1);17012 ensure_field_index(type_info_definition_type, "is_pub", 1);
16834 ensure_field_index(type_info_definition_type, "data", 2);17013 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);
16837 if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))17016 if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))
16838 return err;17017 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);
16841 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))17020 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))
16842 return err;17021 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);
16845 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))17024 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))
16846 return err;17025 return err;
1684717026
...@@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16862 // Skip comptime blocks and test functions.17041 // Skip comptime blocks and test functions.
16863 if (curr_entry->value->id != TldIdCompTime) {17042 if (curr_entry->value->id != TldIdCompTime) {
16864 if (curr_entry->value->id == TldIdFn) {17043 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;
16866 if (fn_entry->is_test)17045 if (fn_entry->is_test)
16867 continue;17046 continue;
16868 }17047 }
...@@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16888 if (curr_entry->value->id == TldIdCompTime) {17067 if (curr_entry->value->id == TldIdCompTime) {
16889 continue;17068 continue;
16890 } else if (curr_entry->value->id == TldIdFn) {17069 } 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;
16892 if (fn_entry->is_test)17071 if (fn_entry->is_test)
16893 continue;17072 continue;
16894 }17073 }
...@@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16913 switch (curr_entry->value->id) {17092 switch (curr_entry->value->id) {
16914 case TldIdVar:17093 case TldIdVar:
16915 {17094 {
16916 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;17095 ZigVar *var = ((TldVar *)curr_entry->value)->var;
16917 if ((err = ensure_complete_type(ira->codegen, var->value->type)))17096 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
16918 return ErrorSemanticAnalyzeFail;17097 return ErrorSemanticAnalyzeFail;
1691917098
16920 if (var->value->type->id == TypeTableEntryIdMetaType)17099 if (var->value->type->id == ZigTypeIdMetaType)
16921 {17100 {
16922 // We have a variable of type 'type', so it's actually a type definition.17101 // We have a variable of type 'type', so it's actually a type definition.
16923 // 0: Data.Type: type17102 // 0: Data.Type: type
...@@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16944 // 2: Data.Fn: Data.FnDef17123 // 2: Data.Fn: Data.FnDef
16945 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2);17124 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;
16948 assert(!fn_entry->is_test);17127 assert(!fn_entry->is_test);
1694917128
16950 AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);17129 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...@@ -16992,7 +17171,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
16992 // lib_name: ?[]const u817171 // lib_name: ?[]const u8
16993 ensure_field_index(fn_def_val->type, "lib_name", 6);17172 ensure_field_index(fn_def_val->type, "lib_name", 6);
16994 fn_def_fields[6].special = ConstValSpecialStatic;17173 fn_def_fields[6].special = ConstValSpecialStatic;
16995 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(17174 ZigType *u8_ptr = get_pointer_to_type_extra(
16996 ira->codegen, ira->codegen->builtin_types.entry_u8,17175 ira->codegen, ira->codegen->builtin_types.entry_u8,
16997 true, false, PtrLenUnknown,17176 true, false, PtrLenUnknown,
16998 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),17177 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...@@ -17030,7 +17209,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
1703017209
17031 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)17210 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)
17032 {17211 {
17033 VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index);17212 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
17034 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];17213 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];
17035 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);17214 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);
17036 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);17215 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...@@ -17044,7 +17223,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
17044 }17223 }
17045 case TldIdContainer:17224 case TldIdContainer:
17046 {17225 {
17047 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;17226 ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
17048 if ((err = ensure_complete_type(ira->codegen, type_entry)))17227 if ((err = ensure_complete_type(ira->codegen, type_entry)))
17049 return ErrorSemanticAnalyzeFail;17228 return ErrorSemanticAnalyzeFail;
1705017229
...@@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
17071 return ErrorNone;17250 return ErrorNone;
17072}17251}
1707317252
17074static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) {17253static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
17075 TypeTableEntry *attrs_type;17254 ZigType *attrs_type;
17076 uint32_t size_enum_index;17255 uint32_t size_enum_index;
17077 if (is_slice(ptr_type_entry)) {17256 if (is_slice(ptr_type_entry)) {
17078 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;17257 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
17079 size_enum_index = 2;17258 size_enum_index = 2;
17080 } else if (ptr_type_entry->id == TypeTableEntryIdPointer) {17259 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
17081 attrs_type = ptr_type_entry;17260 attrs_type = ptr_type_entry;
17082 size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;17261 size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;
17083 } else {17262 } else {
17084 zig_unreachable();17263 zig_unreachable();
17085 }17264 }
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);
17088 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type));17267 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type));
1708917268
17090 ConstExprValue *result = create_const_vals(1);17269 ConstExprValue *result = create_const_vals(1);
...@@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry...@@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
1709617275
17097 // size: Size17276 // size: Size
17098 ensure_field_index(result->type, "size", 0);17277 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);
17100 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type));17279 assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type));
17101 fields[0].special = ConstValSpecialStatic;17280 fields[0].special = ConstValSpecialStatic;
17102 fields[0].type = type_info_pointer_size_type;17281 fields[0].type = type_info_pointer_size_type;
...@@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry...@@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
17127};17306};
1712817307
17129static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,17308static 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)
17131{17310{
17132 enum_field_val->special = ConstValSpecialStatic;17311 enum_field_val->special = ConstValSpecialStatic;
17133 enum_field_val->type = type_info_enum_field_type;17312 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,...@@ -17144,7 +17323,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
17144 enum_field_val->data.x_struct.fields = inner_fields;17323 enum_field_val->data.x_struct.fields = inner_fields;
17145}17324}
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) {
17148 Error err;17327 Error err;
17149 assert(type_entry != nullptr);17328 assert(type_entry != nullptr);
17150 assert(!type_is_invalid(type_entry));17329 assert(!type_is_invalid(type_entry));
...@@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17159 ConstExprValue *result = nullptr;17338 ConstExprValue *result = nullptr;
17160 switch (type_entry->id)17339 switch (type_entry->id)
17161 {17340 {
17162 case TypeTableEntryIdInvalid:17341 case ZigTypeIdInvalid:
17163 zig_unreachable();17342 zig_unreachable();
17164 case TypeTableEntryIdMetaType:17343 case ZigTypeIdMetaType:
17165 case TypeTableEntryIdVoid:17344 case ZigTypeIdVoid:
17166 case TypeTableEntryIdBool:17345 case ZigTypeIdBool:
17167 case TypeTableEntryIdUnreachable:17346 case ZigTypeIdUnreachable:
17168 case TypeTableEntryIdComptimeFloat:17347 case ZigTypeIdComptimeFloat:
17169 case TypeTableEntryIdComptimeInt:17348 case ZigTypeIdComptimeInt:
17170 case TypeTableEntryIdUndefined:17349 case ZigTypeIdUndefined:
17171 case TypeTableEntryIdNull:17350 case ZigTypeIdNull:
17172 case TypeTableEntryIdNamespace:17351 case ZigTypeIdNamespace:
17173 case TypeTableEntryIdBlock:17352 case ZigTypeIdBlock:
17174 case TypeTableEntryIdArgTuple:17353 case ZigTypeIdArgTuple:
17175 case TypeTableEntryIdOpaque:17354 case ZigTypeIdOpaque:
17176 *out = nullptr;17355 *out = nullptr;
17177 return ErrorNone;17356 return ErrorNone;
17178 default:17357 default:
...@@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1718617365
17187 // Fallthrough if we don't find one.17366 // Fallthrough if we don't find one.
17188 }17367 }
17189 case TypeTableEntryIdInt:17368 case ZigTypeIdInt:
17190 {17369 {
17191 result = create_const_vals(1);17370 result = create_const_vals(1);
17192 result->special = ConstValSpecialStatic;17371 result->special = ConstValSpecialStatic;
...@@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1720817387
17209 break;17388 break;
17210 }17389 }
17211 case TypeTableEntryIdFloat:17390 case ZigTypeIdFloat:
17212 {17391 {
17213 result = create_const_vals(1);17392 result = create_const_vals(1);
17214 result->special = ConstValSpecialStatic;17393 result->special = ConstValSpecialStatic;
...@@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1722517404
17226 break;17405 break;
17227 }17406 }
17228 case TypeTableEntryIdPointer:17407 case ZigTypeIdPointer:
17229 {17408 {
17230 result = create_ptr_like_type_info(ira, type_entry);17409 result = create_ptr_like_type_info(ira, type_entry);
17231 break;17410 break;
17232 }17411 }
17233 case TypeTableEntryIdArray:17412 case ZigTypeIdArray:
17234 {17413 {
17235 result = create_const_vals(1);17414 result = create_const_vals(1);
17236 result->special = ConstValSpecialStatic;17415 result->special = ConstValSpecialStatic;
...@@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1725217431
17253 break;17432 break;
17254 }17433 }
17255 case TypeTableEntryIdOptional:17434 case ZigTypeIdOptional:
17256 {17435 {
17257 result = create_const_vals(1);17436 result = create_const_vals(1);
17258 result->special = ConstValSpecialStatic;17437 result->special = ConstValSpecialStatic;
...@@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1726917448
17270 break;17449 break;
17271 }17450 }
17272 case TypeTableEntryIdPromise:17451 case ZigTypeIdPromise:
17273 {17452 {
17274 result = create_const_vals(1);17453 result = create_const_vals(1);
17275 result->special = ConstValSpecialStatic;17454 result->special = ConstValSpecialStatic;
...@@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1729517474
17296 break;17475 break;
17297 }17476 }
17298 case TypeTableEntryIdEnum:17477 case ZigTypeIdEnum:
17299 {17478 {
17300 result = create_const_vals(1);17479 result = create_const_vals(1);
17301 result->special = ConstValSpecialStatic;17480 result->special = ConstValSpecialStatic;
...@@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17317 // fields: []TypeInfo.EnumField17496 // fields: []TypeInfo.EnumField
17318 ensure_field_index(result->type, "fields", 2);17497 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);
17321 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;17500 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
1732217501
17323 ConstExprValue *enum_field_array = create_const_vals(1);17502 ConstExprValue *enum_field_array = create_const_vals(1);
...@@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1734517524
17346 break;17525 break;
17347 }17526 }
17348 case TypeTableEntryIdErrorSet:17527 case ZigTypeIdErrorSet:
17349 {17528 {
17350 result = create_const_vals(1);17529 result = create_const_vals(1);
17351 result->special = ConstValSpecialStatic;17530 result->special = ConstValSpecialStatic;
...@@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17357 // errors: []TypeInfo.Error17536 // errors: []TypeInfo.Error
17358 ensure_field_index(result->type, "errors", 0);17537 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);
17361 uint32_t error_count = type_entry->data.error_set.err_count;17540 uint32_t error_count = type_entry->data.error_set.err_count;
17362 ConstExprValue *error_array = create_const_vals(1);17541 ConstExprValue *error_array = create_const_vals(1);
17363 error_array->special = ConstValSpecialStatic;17542 error_array->special = ConstValSpecialStatic;
...@@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1739417573
17395 break;17574 break;
17396 }17575 }
17397 case TypeTableEntryIdErrorUnion:17576 case ZigTypeIdErrorUnion:
17398 {17577 {
17399 result = create_const_vals(1);17578 result = create_const_vals(1);
17400 result->special = ConstValSpecialStatic;17579 result->special = ConstValSpecialStatic;
...@@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1741717596
17418 break;17597 break;
17419 }17598 }
17420 case TypeTableEntryIdUnion:17599 case ZigTypeIdUnion:
17421 {17600 {
17422 result = create_const_vals(1);17601 result = create_const_vals(1);
17423 result->special = ConstValSpecialStatic;17602 result->special = ConstValSpecialStatic;
...@@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17451 // fields: []TypeInfo.UnionField17630 // fields: []TypeInfo.UnionField
17452 ensure_field_index(result->type, "fields", 2);17631 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);
17455 uint32_t union_field_count = type_entry->data.unionation.src_field_count;17634 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
1745617635
17457 ConstExprValue *union_field_array = create_const_vals(1);17636 ConstExprValue *union_field_array = create_const_vals(1);
...@@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1746317642
17464 init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false);17643 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
17468 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {17647 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
17469 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];17648 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,...@@ -17502,7 +17681,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1750217681
17503 break;17682 break;
17504 }17683 }
17505 case TypeTableEntryIdStruct:17684 case ZigTypeIdStruct:
17506 {17685 {
17507 if (type_entry->data.structure.is_slice) {17686 if (type_entry->data.structure.is_slice) {
17508 result = create_ptr_like_type_info(ira, type_entry);17687 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,...@@ -17524,7 +17703,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17524 // fields: []TypeInfo.StructField17703 // fields: []TypeInfo.StructField
17525 ensure_field_index(result->type, "fields", 1);17704 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);
17528 uint32_t struct_field_count = type_entry->data.structure.src_field_count;17707 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
1752917708
17530 ConstExprValue *struct_field_array = create_const_vals(1);17709 ConstExprValue *struct_field_array = create_const_vals(1);
...@@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1757617755
17577 break;17756 break;
17578 }17757 }
17579 case TypeTableEntryIdFn:17758 case ZigTypeIdFn:
17580 {17759 {
17581 result = create_const_vals(1);17760 result = create_const_vals(1);
17582 result->special = ConstValSpecialStatic;17761 result->special = ConstValSpecialStatic;
...@@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17629 fields[4].data.x_optional = async_alloc_type;17808 fields[4].data.x_optional = async_alloc_type;
17630 }17809 }
17631 // args: []TypeInfo.FnArg17810 // 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);
17633 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -17812 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
17634 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);17813 (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,...@@ -17681,10 +17860,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
1768117860
17682 break;17861 break;
17683 }17862 }
17684 case TypeTableEntryIdBoundFn:17863 case ZigTypeIdBoundFn:
17685 {17864 {
17686 TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type;17865 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
17687 assert(fn_type->id == TypeTableEntryIdFn);17866 assert(fn_type->id == ZigTypeIdFn);
17688 if ((err = ir_make_type_info_value(ira, fn_type, &result)))17867 if ((err = ir_make_type_info_value(ira, fn_type, &result)))
17689 return err;17868 return err;
1769017869
...@@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,...@@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
17698 return ErrorNone;17877 return ErrorNone;
17699}17878}
1770017879
17701static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,17880static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira,
17702 IrInstructionTypeInfo *instruction)17881 IrInstructionTypeInfo *instruction)
17703{17882{
17704 Error err;17883 Error err;
17705 IrInstruction *type_value = instruction->type_value->other;17884 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);
17707 if (type_is_invalid(type_entry))17886 if (type_is_invalid(type_entry))
17708 return ira->codegen->builtin_types.entry_invalid;17887 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
17712 ConstExprValue *payload;17891 ConstExprValue *payload;
17713 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))17892 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))
...@@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
17719 out_val->data.x_union.payload = payload;17898 out_val->data.x_union.payload = payload;
1772017899
17721 if (payload != nullptr) {17900 if (payload != nullptr) {
17722 assert(payload->type->id == TypeTableEntryIdStruct);17901 assert(payload->type->id == ZigTypeIdStruct);
17723 payload->data.x_struct.parent.id = ConstParentIdUnion;17902 payload->data.x_struct.parent.id = ConstParentIdUnion;
17724 payload->data.x_struct.parent.data.p_union.union_val = out_val;17903 payload->data.x_struct.parent.data.p_union.union_val = out_val;
17725 }17904 }
...@@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
17727 return result_type;17906 return result_type;
17728}17907}
1772917908
17730static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,17909static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira,
17731 IrInstructionTypeId *instruction)17910 IrInstructionTypeId *instruction)
17732{17911{
17733 IrInstruction *type_value = instruction->type_value->other;17912 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);
17735 if (type_is_invalid(type_entry))17914 if (type_is_invalid(type_entry))
17736 return ira->codegen->builtin_types.entry_invalid;17915 return ira->codegen->builtin_types.entry_invalid;
1773717916
17738 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");17917 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");
17739 assert(var_value->type->id == TypeTableEntryIdMetaType);17918 assert(var_value->type->id == ZigTypeIdMetaType);
17740 TypeTableEntry *result_type = var_value->data.x_type;17919 ZigType *result_type = var_value->data.x_type;
1774117920
17742 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);17921 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
17743 bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry));17922 bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry));
17744 return result_type;17923 return result_type;
17745}17924}
1774617925
17747static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,17926static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
17748 IrInstructionSetEvalBranchQuota *instruction)17927 IrInstructionSetEvalBranchQuota *instruction)
17749{17928{
17750 if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) {17929 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...@@ -17765,9 +17944,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i
17765 return ira->codegen->builtin_types.entry_void;17944 return ira->codegen->builtin_types.entry_void;
17766}17945}
1776717946
17768static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {17947static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
17769 IrInstruction *type_value = instruction->type_value->other;17948 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);
17771 if (type_is_invalid(type_entry))17950 if (type_is_invalid(type_entry))
17772 return ira->codegen->builtin_types.entry_invalid;17951 return ira->codegen->builtin_types.entry_invalid;
1777317952
...@@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru...@@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru
17779 return out_val->type;17958 return out_val->type;
17780}17959}
1778117960
17782static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {17961static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
17783 AstNode *node = instruction->base.source_node;17962 AstNode *node = instruction->base.source_node;
17784 assert(node->type == NodeTypeFnCallExpr);17963 assert(node->type == NodeTypeFnCallExpr);
17785 AstNode *block_node = node->data.fn_call_expr.params.at(0);17964 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...@@ -17787,7 +17966,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
17787 ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope);17966 ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope);
1778817967
17789 // Execute the C import block like an inline function17968 // 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;
17791 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,17970 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
17792 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,17971 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
17793 &cimport_scope->buf, block_node, nullptr, nullptr);17972 &cimport_scope->buf, block_node, nullptr, nullptr);
...@@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
17838 return ira->codegen->builtin_types.entry_namespace;18017 return ira->codegen->builtin_types.entry_namespace;
17839}18018}
1784018019
17841static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {18020static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
17842 IrInstruction *name_value = instruction->name->other;18021 IrInstruction *name_value = instruction->name->other;
17843 if (type_is_invalid(name_value->value.type))18022 if (type_is_invalid(name_value->value.type))
17844 return ira->codegen->builtin_types.entry_invalid;18023 return ira->codegen->builtin_types.entry_invalid;
...@@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru...@@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
17857 return ira->codegen->builtin_types.entry_void;18036 return ira->codegen->builtin_types.entry_void;
17858}18037}
1785918038
17860static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {18039static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
17861 IrInstruction *name = instruction->name->other;18040 IrInstruction *name = instruction->name->other;
17862 if (type_is_invalid(name->value.type))18041 if (type_is_invalid(name->value.type))
17863 return ira->codegen->builtin_types.entry_invalid;18042 return ira->codegen->builtin_types.entry_invalid;
...@@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc...@@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
17884 return ira->codegen->builtin_types.entry_void;18063 return ira->codegen->builtin_types.entry_void;
17885}18064}
1788618065
17887static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {18066static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
17888 IrInstruction *name = instruction->name->other;18067 IrInstruction *name = instruction->name->other;
17889 if (type_is_invalid(name->value.type))18068 if (type_is_invalid(name->value.type))
17890 return ira->codegen->builtin_types.entry_invalid;18069 return ira->codegen->builtin_types.entry_invalid;
...@@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct...@@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
17903 return ira->codegen->builtin_types.entry_void;18082 return ira->codegen->builtin_types.entry_void;
17904}18083}
1790518084
17906static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {18085static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
17907 IrInstruction *name = instruction->name->other;18086 IrInstruction *name = instruction->name->other;
17908 if (type_is_invalid(name->value.type))18087 if (type_is_invalid(name->value.type))
17909 return ira->codegen->builtin_types.entry_invalid;18088 return ira->codegen->builtin_types.entry_invalid;
...@@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr...@@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
17917 Buf source_dir_path = BUF_INIT;18096 Buf source_dir_path = BUF_INIT;
17918 os_path_dirname(import->path, &source_dir_path);18097 os_path_dirname(import->path, &source_dir_path);
1791918098
17920 Buf file_path = BUF_INIT;18099 Buf *resolve_paths[] = {
17921 os_path_resolve(&source_dir_path, rel_file_path, &file_path);18100 &source_dir_path,
18101 rel_file_path,
18102 };
18103 Buf file_path = os_path_resolve(resolve_paths, 2);
1792218104
17923 // load from file system into const expr18105 // load from file system into const expr
17924 Buf *file_contents = buf_alloc();18106 Buf *file_contents = buf_alloc();
...@@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr...@@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
17942 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents));18124 return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents));
17943}18125}
1794418126
17945static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {18127static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
17946 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);18128 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);
17947 if (type_is_invalid(operand_type))18129 if (type_is_invalid(operand_type))
17948 return ira->codegen->builtin_types.entry_invalid;18130 return ira->codegen->builtin_types.entry_invalid;
1794918131
...@@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct...@@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
17952 return ira->codegen->builtin_types.entry_invalid;18134 return ira->codegen->builtin_types.entry_invalid;
1795318135
17954 // TODO let this be volatile18136 // 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);
17956 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);18138 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
17957 if (type_is_invalid(casted_ptr->value.type))18139 if (type_is_invalid(casted_ptr->value.type))
17958 return ira->codegen->builtin_types.entry_invalid;18140 return ira->codegen->builtin_types.entry_invalid;
...@@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct...@@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
18023 return result->value.type;18205 return result->value.type;
18024}18206}
1802518207
18026static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {18208static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
18027 IrInstruction *order_value = instruction->order_value->other;18209 IrInstruction *order_value = instruction->order_value->other;
18028 if (type_is_invalid(order_value->value.type))18210 if (type_is_invalid(order_value->value.type))
18029 return ira->codegen->builtin_types.entry_invalid;18211 return ira->codegen->builtin_types.entry_invalid;
...@@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio...@@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
18036 return ira->codegen->builtin_types.entry_void;18218 return ira->codegen->builtin_types.entry_void;
18037}18219}
1803818220
18039static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {18221static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
18040 IrInstruction *dest_type_value = instruction->dest_type->other;18222 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);
18042 if (type_is_invalid(dest_type))18224 if (type_is_invalid(dest_type))
18043 return ira->codegen->builtin_types.entry_invalid;18225 return ira->codegen->builtin_types.entry_invalid;
1804418226
18045 if (dest_type->id != TypeTableEntryIdInt &&18227 if (dest_type->id != ZigTypeIdInt &&
18046 dest_type->id != TypeTableEntryIdComptimeInt)18228 dest_type->id != ZigTypeIdComptimeInt)
18047 {18229 {
18048 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));18230 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
18049 return ira->codegen->builtin_types.entry_invalid;18231 return ira->codegen->builtin_types.entry_invalid;
18050 }18232 }
1805118233
18052 IrInstruction *target = instruction->target->other;18234 IrInstruction *target = instruction->target->other;
18053 TypeTableEntry *src_type = target->value.type;18235 ZigType *src_type = target->value.type;
18054 if (type_is_invalid(src_type))18236 if (type_is_invalid(src_type))
18055 return ira->codegen->builtin_types.entry_invalid;18237 return ira->codegen->builtin_types.entry_invalid;
1805618238
18057 if (src_type->id != TypeTableEntryIdInt &&18239 if (src_type->id != ZigTypeIdInt &&
18058 src_type->id != TypeTableEntryIdComptimeInt)18240 src_type->id != ZigTypeIdComptimeInt)
18059 {18241 {
18060 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));18242 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
18061 return ira->codegen->builtin_types.entry_invalid;18243 return ira->codegen->builtin_types.entry_invalid;
...@@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc...@@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
18084 return dest_type;18266 return dest_type;
18085}18267}
1808618268
18087static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {18269static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
18088 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);18270 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18089 if (type_is_invalid(dest_type))18271 if (type_is_invalid(dest_type))
18090 return ira->codegen->builtin_types.entry_invalid;18272 return ira->codegen->builtin_types.entry_invalid;
1809118273
18092 if (dest_type->id != TypeTableEntryIdInt) {18274 if (dest_type->id != ZigTypeIdInt) {
18093 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));18275 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
18094 return ira->codegen->builtin_types.entry_invalid;18276 return ira->codegen->builtin_types.entry_invalid;
18095 }18277 }
...@@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc...@@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
18098 if (type_is_invalid(target->value.type))18280 if (type_is_invalid(target->value.type))
18099 return ira->codegen->builtin_types.entry_invalid;18281 return ira->codegen->builtin_types.entry_invalid;
1810018282
18101 if (target->value.type->id == TypeTableEntryIdComptimeInt) {18283 if (target->value.type->id == ZigTypeIdComptimeInt) {
18102 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {18284 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
18103 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,18285 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,
18104 CastOpNumLitToConcrete, false);18286 CastOpNumLitToConcrete, false);
...@@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc...@@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
18111 }18293 }
18112 }18294 }
1811318295
18114 if (target->value.type->id != TypeTableEntryIdInt) {18296 if (target->value.type->id != ZigTypeIdInt) {
18115 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",18297 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
18116 buf_ptr(&target->value.type->name)));18298 buf_ptr(&target->value.type->name)));
18117 return ira->codegen->builtin_types.entry_invalid;18299 return ira->codegen->builtin_types.entry_invalid;
...@@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc...@@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
18125 return dest_type;18307 return dest_type;
18126}18308}
1812718309
18128static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {18310static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
18129 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);18311 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18130 if (type_is_invalid(dest_type))18312 if (type_is_invalid(dest_type))
18131 return ira->codegen->builtin_types.entry_invalid;18313 return ira->codegen->builtin_types.entry_invalid;
1813218314
18133 if (dest_type->id != TypeTableEntryIdFloat) {18315 if (dest_type->id != ZigTypeIdFloat) {
18134 ir_add_error(ira, instruction->dest_type,18316 ir_add_error(ira, instruction->dest_type,
18135 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));18317 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
18136 return ira->codegen->builtin_types.entry_invalid;18318 return ira->codegen->builtin_types.entry_invalid;
...@@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr...@@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
18140 if (type_is_invalid(target->value.type))18322 if (type_is_invalid(target->value.type))
18141 return ira->codegen->builtin_types.entry_invalid;18323 return ira->codegen->builtin_types.entry_invalid;
1814218324
18143 if (target->value.type->id == TypeTableEntryIdComptimeInt ||18325 if (target->value.type->id == ZigTypeIdComptimeInt ||
18144 target->value.type->id == TypeTableEntryIdComptimeFloat)18326 target->value.type->id == ZigTypeIdComptimeFloat)
18145 {18327 {
18146 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {18328 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
18147 CastOp op;18329 CastOp op;
18148 if (target->value.type->id == TypeTableEntryIdComptimeInt) {18330 if (target->value.type->id == ZigTypeIdComptimeInt) {
18149 op = CastOpIntToFloat;18331 op = CastOpIntToFloat;
18150 } else {18332 } else {
18151 op = CastOpNumLitToConcrete;18333 op = CastOpNumLitToConcrete;
...@@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr...@@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
18160 }18342 }
18161 }18343 }
1816218344
18163 if (target->value.type->id != TypeTableEntryIdFloat) {18345 if (target->value.type->id != ZigTypeIdFloat) {
18164 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",18346 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
18165 buf_ptr(&target->value.type->name)));18347 buf_ptr(&target->value.type->name)));
18166 return ira->codegen->builtin_types.entry_invalid;18348 return ira->codegen->builtin_types.entry_invalid;
...@@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr...@@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
18173 return dest_type;18355 return dest_type;
18174}18356}
1817518357
18176static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {18358static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
18177 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);18359 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18178 if (type_is_invalid(dest_type))18360 if (type_is_invalid(dest_type))
18179 return ira->codegen->builtin_types.entry_invalid;18361 return ira->codegen->builtin_types.entry_invalid;
1818018362
18181 if (dest_type->id != TypeTableEntryIdErrorSet) {18363 if (dest_type->id != ZigTypeIdErrorSet) {
18182 ir_add_error(ira, instruction->dest_type,18364 ir_add_error(ira, instruction->dest_type,
18183 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));18365 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
18184 return ira->codegen->builtin_types.entry_invalid;18366 return ira->codegen->builtin_types.entry_invalid;
...@@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns...@@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
18188 if (type_is_invalid(target->value.type))18370 if (type_is_invalid(target->value.type))
18189 return ira->codegen->builtin_types.entry_invalid;18371 return ira->codegen->builtin_types.entry_invalid;
1819018372
18191 if (target->value.type->id != TypeTableEntryIdErrorSet) {18373 if (target->value.type->id != ZigTypeIdErrorSet) {
18192 ir_add_error(ira, instruction->target,18374 ir_add_error(ira, instruction->target,
18193 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));18375 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));
18194 return ira->codegen->builtin_types.entry_invalid;18376 return ira->codegen->builtin_types.entry_invalid;
...@@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns...@@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
18201 return dest_type;18383 return dest_type;
18202}18384}
1820318385
18204static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {18386static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
18205 TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);18387 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);
18206 if (type_is_invalid(dest_child_type))18388 if (type_is_invalid(dest_child_type))
18207 return ira->codegen->builtin_types.entry_invalid;18389 return ira->codegen->builtin_types.entry_invalid;
1820818390
...@@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr...@@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
18213 bool src_ptr_const;18395 bool src_ptr_const;
18214 bool src_ptr_volatile;18396 bool src_ptr_volatile;
18215 uint32_t src_ptr_align;18397 uint32_t src_ptr_align;
18216 if (target->value.type->id == TypeTableEntryIdPointer) {18398 if (target->value.type->id == ZigTypeIdPointer) {
18217 src_ptr_const = target->value.type->data.pointer.is_const;18399 src_ptr_const = target->value.type->data.pointer.is_const;
18218 src_ptr_volatile = target->value.type->data.pointer.is_volatile;18400 src_ptr_volatile = target->value.type->data.pointer.is_volatile;
18219 src_ptr_align = target->value.type->data.pointer.alignment;18401 src_ptr_align = target->value.type->data.pointer.alignment;
18220 } else if (is_slice(target->value.type)) {18402 } 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;
18222 src_ptr_const = src_ptr_type->data.pointer.is_const;18404 src_ptr_const = src_ptr_type->data.pointer.is_const;
18223 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;18405 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
18224 src_ptr_align = src_ptr_type->data.pointer.alignment;18406 src_ptr_align = src_ptr_type->data.pointer.alignment;
...@@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr...@@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
18228 src_ptr_align = get_abi_alignment(ira->codegen, target->value.type);18410 src_ptr_align = get_abi_alignment(ira->codegen, target->value.type);
18229 }18411 }
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,
18232 src_ptr_const, src_ptr_volatile, PtrLenUnknown,18414 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
18233 src_ptr_align, 0, 0);18415 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,
18237 src_ptr_const, src_ptr_volatile, PtrLenUnknown,18419 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
18238 src_ptr_align, 0, 0);18420 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
18241 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);18423 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
18242 if (type_is_invalid(casted_value->value.type))18424 if (type_is_invalid(casted_value->value.type))
...@@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr...@@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
18281 return dest_slice_type;18463 return dest_slice_type;
18282}18464}
1828318465
18284static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {18466static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
18285 IrInstruction *target = instruction->target->other;18467 IrInstruction *target = instruction->target->other;
18286 if (type_is_invalid(target->value.type))18468 if (type_is_invalid(target->value.type))
18287 return ira->codegen->builtin_types.entry_invalid;18469 return ira->codegen->builtin_types.entry_invalid;
...@@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc...@@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc
18292 return ira->codegen->builtin_types.entry_invalid;18474 return ira->codegen->builtin_types.entry_invalid;
18293 }18475 }
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,
18298 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,18480 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
18299 src_ptr_type->data.pointer.alignment, 0, 0);18481 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
18302 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true);18484 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true);
18303 ir_link_new_instruction(result, &instruction->base);18485 ir_link_new_instruction(result, &instruction->base);
18304 return dest_slice_type;18486 return dest_slice_type;
18305}18487}
1830618488
18307static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {18489static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
18308 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);18490 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18309 if (type_is_invalid(dest_type))18491 if (type_is_invalid(dest_type))
18310 return ira->codegen->builtin_types.entry_invalid;18492 return ira->codegen->builtin_types.entry_invalid;
1831118493
...@@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns...@@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
18313 if (type_is_invalid(target->value.type))18495 if (type_is_invalid(target->value.type))
18314 return ira->codegen->builtin_types.entry_invalid;18496 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) {
18317 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",18499 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
18318 buf_ptr(&target->value.type->name)));18500 buf_ptr(&target->value.type->name)));
18319 return ira->codegen->builtin_types.entry_invalid;18501 return ira->codegen->builtin_types.entry_invalid;
...@@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns...@@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
18324 return dest_type;18506 return dest_type;
18325}18507}
1832618508
18327static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {18509static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
18328 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);18510 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
18329 if (type_is_invalid(dest_type))18511 if (type_is_invalid(dest_type))
18330 return ira->codegen->builtin_types.entry_invalid;18512 return ira->codegen->builtin_types.entry_invalid;
1833118513
...@@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns...@@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns
18333 if (type_is_invalid(target->value.type))18515 if (type_is_invalid(target->value.type))
18334 return ira->codegen->builtin_types.entry_invalid;18516 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
18336 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);18532 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
18337 ir_link_new_instruction(result, &instruction->base);18533 ir_link_new_instruction(result, &instruction->base);
18338 return dest_type;18534 return dest_type;
18339}18535}
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) {
18342 IrInstruction *target = instruction->target->other;18538 IrInstruction *target = instruction->target->other;
18343 if (type_is_invalid(target->value.type))18539 if (type_is_invalid(target->value.type))
18344 return ira->codegen->builtin_types.entry_invalid;18540 return ira->codegen->builtin_types.entry_invalid;
1834518541
18346 IrInstruction *casted_target;18542 IrInstruction *casted_target;
18347 if (target->value.type->id == TypeTableEntryIdErrorSet) {18543 if (target->value.type->id == ZigTypeIdErrorSet) {
18348 casted_target = target;18544 casted_target = target;
18349 } else {18545 } else {
18350 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);18546 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...@@ -18357,7 +18553,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr
18357 return result->value.type;18553 return result->value.type;
18358}18554}
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) {
18361 IrInstruction *target = instruction->target->other;18557 IrInstruction *target = instruction->target->other;
18362 if (type_is_invalid(target->value.type))18558 if (type_is_invalid(target->value.type))
18363 return ira->codegen->builtin_types.entry_invalid;18559 return ira->codegen->builtin_types.entry_invalid;
...@@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr...@@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr
18371 return result->value.type;18567 return result->value.type;
18372}18568}
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) {
18375 IrInstruction *target = instruction->target->other;18571 IrInstruction *target = instruction->target->other;
18376 if (type_is_invalid(target->value.type))18572 if (type_is_invalid(target->value.type))
18377 return ira->codegen->builtin_types.entry_invalid;18573 return ira->codegen->builtin_types.entry_invalid;
1837818574
18379 if (target->value.type->id != TypeTableEntryIdBool) {18575 if (target->value.type->id != ZigTypeIdBool) {
18380 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",18576 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
18381 buf_ptr(&target->value.type->name)));18577 buf_ptr(&target->value.type->name)));
18382 return ira->codegen->builtin_types.entry_invalid;18578 return ira->codegen->builtin_types.entry_invalid;
...@@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst...@@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst
18392 return ira->codegen->builtin_types.entry_num_lit_int;18588 return ira->codegen->builtin_types.entry_num_lit_int;
18393 }18589 }
1839418590
18395 TypeTableEntry *u1_type = get_int_type(ira->codegen, false, 1);18591 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
18396 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);18592 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);
18397 ir_link_new_instruction(result, &instruction->base);18593 ir_link_new_instruction(result, &instruction->base);
18398 return u1_type;18594 return u1_type;
18399}18595}
1840018596
18401static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {18597static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
18402 IrInstruction *is_signed_value = instruction->is_signed->other;18598 IrInstruction *is_signed_value = instruction->is_signed->other;
18403 bool is_signed;18599 bool is_signed;
18404 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))18600 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
...@@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc...@@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
18414 return ira->codegen->builtin_types.entry_type;18610 return ira->codegen->builtin_types.entry_type;
18415}18611}
1841618612
18417static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {18613static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
18418 IrInstruction *value = instruction->value->other;18614 IrInstruction *value = instruction->value->other;
18419 if (type_is_invalid(value->value.type))18615 if (type_is_invalid(value->value.type))
18420 return ira->codegen->builtin_types.entry_invalid;18616 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
18424 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);18620 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
18425 if (type_is_invalid(casted_value->value.type))18621 if (type_is_invalid(casted_value->value.type))
...@@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc...@@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
18439 return bool_type;18635 return bool_type;
18440}18636}
1844118637
18442static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {18638static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
18443 IrInstruction *dest_ptr = instruction->dest_ptr->other;18639 IrInstruction *dest_ptr = instruction->dest_ptr->other;
18444 if (type_is_invalid(dest_ptr->value.type))18640 if (type_is_invalid(dest_ptr->value.type))
18445 return ira->codegen->builtin_types.entry_invalid;18641 return ira->codegen->builtin_types.entry_invalid;
...@@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi...@@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
18452 if (type_is_invalid(count_value->value.type))18648 if (type_is_invalid(count_value->value.type))
18453 return ira->codegen->builtin_types.entry_invalid;18649 return ira->codegen->builtin_types.entry_invalid;
1845418650
18455 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;18651 ZigType *dest_uncasted_type = dest_ptr->value.type;
18456 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&18652 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
18457 dest_uncasted_type->data.pointer.is_volatile;18653 dest_uncasted_type->data.pointer.is_volatile;
1845818654
18459 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;18655 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18460 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;18656 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18461 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?18657 uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
18462 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18658 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,
18464 PtrLenUnknown, dest_align, 0, 0);18660 PtrLenUnknown, dest_align, 0, 0);
1846518661
18466 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);18662 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...@@ -18531,7 +18727,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
18531 return ira->codegen->builtin_types.entry_void;18727 return ira->codegen->builtin_types.entry_void;
18532}18728}
1853318729
18534static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {18730static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
18535 IrInstruction *dest_ptr = instruction->dest_ptr->other;18731 IrInstruction *dest_ptr = instruction->dest_ptr->other;
18536 if (type_is_invalid(dest_ptr->value.type))18732 if (type_is_invalid(dest_ptr->value.type))
18537 return ira->codegen->builtin_types.entry_invalid;18733 return ira->codegen->builtin_types.entry_invalid;
...@@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
18544 if (type_is_invalid(count_value->value.type))18740 if (type_is_invalid(count_value->value.type))
18545 return ira->codegen->builtin_types.entry_invalid;18741 return ira->codegen->builtin_types.entry_invalid;
1854618742
18547 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;18743 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18548 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;18744 ZigType *dest_uncasted_type = dest_ptr->value.type;
18549 TypeTableEntry *src_uncasted_type = src_ptr->value.type;18745 ZigType *src_uncasted_type = src_ptr->value.type;
18550 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&18746 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
18551 dest_uncasted_type->data.pointer.is_volatile;18747 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) &&
18553 src_uncasted_type->data.pointer.is_volatile;18749 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) ?
18555 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18751 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) ?
18557 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18753 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
1855818754
18559 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;18755 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18560 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,18756 ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
18561 PtrLenUnknown, dest_align, 0, 0);18757 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,
18563 PtrLenUnknown, src_align, 0, 0);18759 PtrLenUnknown, src_align, 0, 0);
1856418760
18565 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);18761 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...@@ -18666,20 +18862,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
18666 return ira->codegen->builtin_types.entry_void;18862 return ira->codegen->builtin_types.entry_void;
18667}18863}
1866818864
18669static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {18865static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
18670 IrInstruction *ptr_ptr = instruction->ptr->other;18866 IrInstruction *ptr_ptr = instruction->ptr->other;
18671 if (type_is_invalid(ptr_ptr->value.type))18867 if (type_is_invalid(ptr_ptr->value.type))
18672 return ira->codegen->builtin_types.entry_invalid;18868 return ira->codegen->builtin_types.entry_invalid;
1867318869
18674 TypeTableEntry *ptr_type = ptr_ptr->value.type;18870 ZigType *ptr_type = ptr_ptr->value.type;
18675 assert(ptr_type->id == TypeTableEntryIdPointer);18871 assert(ptr_type->id == ZigTypeIdPointer);
18676 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;18872 ZigType *array_type = ptr_type->data.pointer.child_type;
1867718873
18678 IrInstruction *start = instruction->start->other;18874 IrInstruction *start = instruction->start->other;
18679 if (type_is_invalid(start->value.type))18875 if (type_is_invalid(start->value.type))
18680 return ira->codegen->builtin_types.entry_invalid;18876 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;
18683 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);18879 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
18684 if (type_is_invalid(casted_start->value.type))18880 if (type_is_invalid(casted_start->value.type))
18685 return ira->codegen->builtin_types.entry_invalid;18881 return ira->codegen->builtin_types.entry_invalid;
...@@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18696 end = nullptr;18892 end = nullptr;
18697 }18893 }
1869818894
18699 TypeTableEntry *return_type;18895 ZigType *return_type;
1870018896
18701 if (array_type->id == TypeTableEntryIdArray) {18897 if (array_type->id == ZigTypeIdArray) {
18702 uint32_t byte_alignment = ptr_type->data.pointer.alignment;18898 uint32_t byte_alignment = ptr_type->data.pointer.alignment;
18703 if (array_type->data.array.len == 0 && byte_alignment == 0) {18899 if (array_type->data.array.len == 0 && byte_alignment == 0) {
18704 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);18900 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
18705 }18901 }
18706 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&18902 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
18707 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;18903 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,
18709 ptr_type->data.pointer.is_const || is_comptime_const,18905 ptr_type->data.pointer.is_const || is_comptime_const,
18710 ptr_type->data.pointer.is_volatile,18906 ptr_type->data.pointer.is_volatile,
18711 PtrLenUnknown,18907 PtrLenUnknown,
18712 byte_alignment, 0, 0);18908 byte_alignment, 0, 0);
18713 return_type = get_slice_type(ira->codegen, slice_ptr_type);18909 return_type = get_slice_type(ira->codegen, slice_ptr_type);
18714 } else if (array_type->id == TypeTableEntryIdPointer) {18910 } else if (array_type->id == ZigTypeIdPointer) {
18715 if (array_type->data.pointer.ptr_len == PtrLenSingle) {18911 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
18716 TypeTableEntry *main_type = array_type->data.pointer.child_type;18912 ZigType *main_type = array_type->data.pointer.child_type;
18717 if (main_type->id == TypeTableEntryIdArray) {18913 if (main_type->id == ZigTypeIdArray) {
18718 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,18914 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
18719 main_type->data.pointer.child_type,18915 main_type->data.pointer.child_type,
18720 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,18916 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
18721 PtrLenUnknown,18917 PtrLenUnknown,
...@@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18726 return ira->codegen->builtin_types.entry_invalid;18922 return ira->codegen->builtin_types.entry_invalid;
18727 }18923 }
18728 } else {18924 } 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,
18730 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,18926 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
18731 PtrLenUnknown,18927 PtrLenUnknown,
18732 array_type->data.pointer.alignment, 0, 0);18928 array_type->data.pointer.alignment, 0, 0);
...@@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18737 }18933 }
18738 }18934 }
18739 } else if (is_slice(array_type)) {18935 } 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;
18741 return_type = get_slice_type(ira->codegen, ptr_type);18937 return_type = get_slice_type(ira->codegen, ptr_type);
18742 } else {18938 } else {
18743 ir_add_error(ira, &instruction->base,18939 ir_add_error(ira, &instruction->base,
...@@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18754 size_t abs_offset;18950 size_t abs_offset;
18755 size_t rel_end;18951 size_t rel_end;
18756 bool ptr_is_undef = false;18952 bool ptr_is_undef = false;
18757 if (array_type->id == TypeTableEntryIdArray ||18953 if (array_type->id == ZigTypeIdArray ||
18758 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))18954 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
18759 {18955 {
18760 if (array_type->id == TypeTableEntryIdPointer) {18956 if (array_type->id == ZigTypeIdPointer) {
18761 TypeTableEntry *child_array_type = array_type->data.pointer.child_type;18957 ZigType *child_array_type = array_type->data.pointer.child_type;
18762 assert(child_array_type->id == TypeTableEntryIdArray);18958 assert(child_array_type->id == ZigTypeIdArray);
18763 parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);18959 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18764 array_val = const_ptr_pointee(ira->codegen, parent_ptr);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
18765 rel_end = child_array_type->data.array.len;18967 rel_end = child_array_type->data.array.len;
18766 abs_offset = 0;18968 abs_offset = 0;
18767 } else {18969 } 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;
18769 rel_end = array_type->data.array.len;18973 rel_end = array_type->data.array.len;
18770 parent_ptr = nullptr;18974 parent_ptr = nullptr;
18771 abs_offset = 0;18975 abs_offset = 0;
18772 }18976 }
18773 } else if (array_type->id == TypeTableEntryIdPointer) {18977 } else if (array_type->id == ZigTypeIdPointer) {
18774 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);18978 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
18776 if (parent_ptr->special == ConstValSpecialUndef) {18983 if (parent_ptr->special == ConstValSpecialUndef) {
18777 array_val = nullptr;18984 array_val = nullptr;
18778 abs_offset = 0;18985 abs_offset = 0;
...@@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18803 zig_panic("TODO slice of ptr cast from function");19010 zig_panic("TODO slice of ptr cast from function");
18804 }19011 }
18805 } else if (is_slice(array_type)) {19012 } 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
18807 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];19017 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
18808 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];19018 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...@@ -18871,11 +19081,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18871 size_t index = abs_offset + start_scalar;19081 size_t index = abs_offset + start_scalar;
18872 bool is_const = slice_is_const(return_type);19082 bool is_const = slice_is_const(return_type);
18873 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);19083 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) {
18875 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;19085 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
18876 } else if (is_slice(array_type)) {19086 } else if (is_slice(array_type)) {
18877 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;19087 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) {
18879 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;19089 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
18880 }19090 }
18881 } else if (ptr_is_undef) {19091 } else if (ptr_is_undef) {
...@@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
18917 return return_type;19127 return return_type;
18918}19128}
1891919129
18920static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {19130static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
18921 Error err;19131 Error err;
18922 IrInstruction *container = instruction->container->other;19132 IrInstruction *container = instruction->container->other;
18923 if (type_is_invalid(container->value.type))19133 if (type_is_invalid(container->value.type))
18924 return ira->codegen->builtin_types.entry_invalid;19134 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
18927 if ((err = ensure_complete_type(ira->codegen, container_type)))19137 if ((err = ensure_complete_type(ira->codegen, container_type)))
18928 return ira->codegen->builtin_types.entry_invalid;19138 return ira->codegen->builtin_types.entry_invalid;
...@@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
18930 uint64_t result;19140 uint64_t result;
18931 if (type_is_invalid(container_type)) {19141 if (type_is_invalid(container_type)) {
18932 return ira->codegen->builtin_types.entry_invalid;19142 return ira->codegen->builtin_types.entry_invalid;
18933 } else if (container_type->id == TypeTableEntryIdEnum) {19143 } else if (container_type->id == ZigTypeIdEnum) {
18934 result = container_type->data.enumeration.src_field_count;19144 result = container_type->data.enumeration.src_field_count;
18935 } else if (container_type->id == TypeTableEntryIdStruct) {19145 } else if (container_type->id == ZigTypeIdStruct) {
18936 result = container_type->data.structure.src_field_count;19146 result = container_type->data.structure.src_field_count;
18937 } else if (container_type->id == TypeTableEntryIdUnion) {19147 } else if (container_type->id == ZigTypeIdUnion) {
18938 result = container_type->data.unionation.src_field_count;19148 result = container_type->data.unionation.src_field_count;
18939 } else if (container_type->id == TypeTableEntryIdErrorSet) {19149 } else if (container_type->id == ZigTypeIdErrorSet) {
18940 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {19150 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
18941 return ira->codegen->builtin_types.entry_invalid;19151 return ira->codegen->builtin_types.entry_invalid;
18942 }19152 }
...@@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
18955 return ira->codegen->builtin_types.entry_num_lit_int;19165 return ira->codegen->builtin_types.entry_num_lit_int;
18956}19166}
1895719167
18958static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {19168static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
18959 Error err;19169 Error err;
18960 IrInstruction *container_type_value = instruction->container_type->other;19170 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);
18962 if (type_is_invalid(container_type))19172 if (type_is_invalid(container_type))
18963 return ira->codegen->builtin_types.entry_invalid;19173 return ira->codegen->builtin_types.entry_invalid;
1896419174
...@@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst...@@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
18971 if (!ir_resolve_usize(ira, index_value, &member_index))19181 if (!ir_resolve_usize(ira, index_value, &member_index))
18972 return ira->codegen->builtin_types.entry_invalid;19182 return ira->codegen->builtin_types.entry_invalid;
1897319183
18974 if (container_type->id == TypeTableEntryIdStruct) {19184 if (container_type->id == ZigTypeIdStruct) {
18975 if (member_index >= container_type->data.structure.src_field_count) {19185 if (member_index >= container_type->data.structure.src_field_count) {
18976 ir_add_error(ira, index_value,19186 ir_add_error(ira, index_value,
18977 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19187 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...@@ -18983,7 +19193,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
18983 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19193 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
18984 out_val->data.x_type = field->type_entry;19194 out_val->data.x_type = field->type_entry;
18985 return ira->codegen->builtin_types.entry_type;19195 return ira->codegen->builtin_types.entry_type;
18986 } else if (container_type->id == TypeTableEntryIdUnion) {19196 } else if (container_type->id == ZigTypeIdUnion) {
18987 if (member_index >= container_type->data.unionation.src_field_count) {19197 if (member_index >= container_type->data.unionation.src_field_count) {
18988 ir_add_error(ira, index_value,19198 ir_add_error(ira, index_value,
18989 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19199 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...@@ -19002,10 +19212,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
19002 }19212 }
19003}19213}
1900419214
19005static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {19215static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
19006 Error err;19216 Error err;
19007 IrInstruction *container_type_value = instruction->container_type->other;19217 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);
19009 if (type_is_invalid(container_type))19219 if (type_is_invalid(container_type))
19010 return ira->codegen->builtin_types.entry_invalid;19220 return ira->codegen->builtin_types.entry_invalid;
1901119221
...@@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst...@@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
19017 if (!ir_resolve_usize(ira, index_value, &member_index))19227 if (!ir_resolve_usize(ira, index_value, &member_index))
19018 return ira->codegen->builtin_types.entry_invalid;19228 return ira->codegen->builtin_types.entry_invalid;
1901919229
19020 if (container_type->id == TypeTableEntryIdStruct) {19230 if (container_type->id == ZigTypeIdStruct) {
19021 if (member_index >= container_type->data.structure.src_field_count) {19231 if (member_index >= container_type->data.structure.src_field_count) {
19022 ir_add_error(ira, index_value,19232 ir_add_error(ira, index_value,
19023 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19233 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...@@ -19029,7 +19239,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
19029 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19239 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19030 init_const_str_lit(ira->codegen, out_val, field->name);19240 init_const_str_lit(ira->codegen, out_val, field->name);
19031 return out_val->type;19241 return out_val->type;
19032 } else if (container_type->id == TypeTableEntryIdEnum) {19242 } else if (container_type->id == ZigTypeIdEnum) {
19033 if (member_index >= container_type->data.enumeration.src_field_count) {19243 if (member_index >= container_type->data.enumeration.src_field_count) {
19034 ir_add_error(ira, index_value,19244 ir_add_error(ira, index_value,
19035 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19245 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...@@ -19041,7 +19251,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
19041 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19251 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19042 init_const_str_lit(ira->codegen, out_val, field->name);19252 init_const_str_lit(ira->codegen, out_val, field->name);
19043 return out_val->type;19253 return out_val->type;
19044 } else if (container_type->id == TypeTableEntryIdUnion) {19254 } else if (container_type->id == ZigTypeIdUnion) {
19045 if (member_index >= container_type->data.unionation.src_field_count) {19255 if (member_index >= container_type->data.unionation.src_field_count) {
19046 ir_add_error(ira, index_value,19256 ir_add_error(ira, index_value,
19047 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19257 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...@@ -19060,76 +19270,76 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
19060 }19270 }
19061}19271}
1906219272
19063static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {19273static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
19064 ir_build_breakpoint_from(&ira->new_irb, &instruction->base);19274 ir_build_breakpoint_from(&ira->new_irb, &instruction->base);
19065 return ira->codegen->builtin_types.entry_void;19275 return ira->codegen->builtin_types.entry_void;
19066}19276}
1906719277
19068static TypeTableEntry *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {19278static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
19069 ir_build_return_address_from(&ira->new_irb, &instruction->base);19279 ir_build_return_address_from(&ira->new_irb, &instruction->base);
1907019280
19071 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;19281 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
19072 TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);19282 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
19073 return u8_ptr_const;19283 return u8_ptr_const;
19074}19284}
1907519285
19076static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {19286static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
19077 ir_build_frame_address_from(&ira->new_irb, &instruction->base);19287 ir_build_frame_address_from(&ira->new_irb, &instruction->base);
1907819288
19079 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;19289 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
19080 TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);19290 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
19081 return u8_ptr_const;19291 return u8_ptr_const;
19082}19292}
1908319293
19084static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {19294static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
19085 ir_build_handle_from(&ira->new_irb, &instruction->base);19295 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);
19088 assert(fn_entry != nullptr);19298 assert(fn_entry != nullptr);
19089 return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);19299 return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
19090}19300}
1909119301
19092static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {19302static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
19093 Error err;19303 Error err;
19094 IrInstruction *type_value = instruction->type_value->other;19304 IrInstruction *type_value = instruction->type_value->other;
19095 if (type_is_invalid(type_value->value.type))19305 if (type_is_invalid(type_value->value.type))
19096 return ira->codegen->builtin_types.entry_invalid;19306 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
19099 if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry)))19309 if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry)))
19100 return ira->codegen->builtin_types.entry_invalid;19310 return ira->codegen->builtin_types.entry_invalid;
1910119311
19102 switch (type_entry->id) {19312 switch (type_entry->id) {
19103 case TypeTableEntryIdInvalid:19313 case ZigTypeIdInvalid:
19104 zig_unreachable();19314 zig_unreachable();
19105 case TypeTableEntryIdMetaType:19315 case ZigTypeIdMetaType:
19106 case TypeTableEntryIdUnreachable:19316 case ZigTypeIdUnreachable:
19107 case TypeTableEntryIdComptimeFloat:19317 case ZigTypeIdComptimeFloat:
19108 case TypeTableEntryIdComptimeInt:19318 case ZigTypeIdComptimeInt:
19109 case TypeTableEntryIdUndefined:19319 case ZigTypeIdUndefined:
19110 case TypeTableEntryIdNull:19320 case ZigTypeIdNull:
19111 case TypeTableEntryIdNamespace:19321 case ZigTypeIdNamespace:
19112 case TypeTableEntryIdBlock:19322 case ZigTypeIdBlock:
19113 case TypeTableEntryIdBoundFn:19323 case ZigTypeIdBoundFn:
19114 case TypeTableEntryIdArgTuple:19324 case ZigTypeIdArgTuple:
19115 case TypeTableEntryIdVoid:19325 case ZigTypeIdVoid:
19116 case TypeTableEntryIdOpaque:19326 case ZigTypeIdOpaque:
19117 ir_add_error(ira, instruction->type_value,19327 ir_add_error(ira, instruction->type_value,
19118 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));19328 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
19119 return ira->codegen->builtin_types.entry_invalid;19329 return ira->codegen->builtin_types.entry_invalid;
19120 case TypeTableEntryIdBool:19330 case ZigTypeIdBool:
19121 case TypeTableEntryIdInt:19331 case ZigTypeIdInt:
19122 case TypeTableEntryIdFloat:19332 case ZigTypeIdFloat:
19123 case TypeTableEntryIdPointer:19333 case ZigTypeIdPointer:
19124 case TypeTableEntryIdPromise:19334 case ZigTypeIdPromise:
19125 case TypeTableEntryIdArray:19335 case ZigTypeIdArray:
19126 case TypeTableEntryIdStruct:19336 case ZigTypeIdStruct:
19127 case TypeTableEntryIdOptional:19337 case ZigTypeIdOptional:
19128 case TypeTableEntryIdErrorUnion:19338 case ZigTypeIdErrorUnion:
19129 case TypeTableEntryIdErrorSet:19339 case ZigTypeIdErrorSet:
19130 case TypeTableEntryIdEnum:19340 case ZigTypeIdEnum:
19131 case TypeTableEntryIdUnion:19341 case ZigTypeIdUnion:
19132 case TypeTableEntryIdFn:19342 case ZigTypeIdFn:
19133 {19343 {
19134 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);19344 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);
19135 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19345 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc...@@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
19140 zig_unreachable();19350 zig_unreachable();
19141}19351}
1914219352
19143static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {19353static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
19144 IrInstruction *type_value = instruction->type_value->other;19354 IrInstruction *type_value = instruction->type_value->other;
19145 if (type_is_invalid(type_value->value.type))19355 if (type_is_invalid(type_value->value.type))
19146 return ira->codegen->builtin_types.entry_invalid;19356 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);
19149 if (type_is_invalid(dest_type))19359 if (type_is_invalid(dest_type))
19150 return ira->codegen->builtin_types.entry_invalid;19360 return ira->codegen->builtin_types.entry_invalid;
1915119361
19152 if (dest_type->id != TypeTableEntryIdInt) {19362 if (dest_type->id != ZigTypeIdInt) {
19153 ir_add_error(ira, type_value,19363 ir_add_error(ira, type_value,
19154 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));19364 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19155 return ira->codegen->builtin_types.entry_invalid;19365 return ira->codegen->builtin_types.entry_invalid;
...@@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1916919379
19170 IrInstruction *casted_op2;19380 IrInstruction *casted_op2;
19171 if (instruction->op == IrOverflowOpShl) {19381 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,
19173 dest_type->data.integral.bit_count - 1);19383 dest_type->data.integral.bit_count - 1);
19174 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);19384 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
19175 } else {19385 } else {
...@@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
19182 if (type_is_invalid(result_ptr->value.type))19392 if (type_is_invalid(result_ptr->value.type))
19183 return ira->codegen->builtin_types.entry_invalid;19393 return ira->codegen->builtin_types.entry_invalid;
1918419394
19185 TypeTableEntry *expected_ptr_type;19395 ZigType *expected_ptr_type;
19186 if (result_ptr->value.type->id == TypeTableEntryIdPointer) {19396 if (result_ptr->value.type->id == ZigTypeIdPointer) {
19187 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,19397 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
19188 false, result_ptr->value.type->data.pointer.is_volatile,19398 false, result_ptr->value.type->data.pointer.is_volatile,
19189 PtrLenSingle,19399 PtrLenSingle,
...@@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
19203 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19413 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19204 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;19414 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;
19205 BigInt *op2_bigint = &casted_op2->value.data.x_bigint;19415 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;
19207 BigInt *dest_bigint = &pointee_val->data.x_bigint;19419 BigInt *dest_bigint = &pointee_val->data.x_bigint;
19208 switch (instruction->op) {19420 switch (instruction->op) {
19209 case IrOverflowOpAdd:19421 case IrOverflowOpAdd:
...@@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
19237 return ira->codegen->builtin_types.entry_bool;19449 return ira->codegen->builtin_types.entry_bool;
19238}19450}
1923919451
19240static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {19452static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
19241 IrInstruction *value = instruction->value->other;19453 IrInstruction *value = instruction->value->other;
19242 if (type_is_invalid(value->value.type))19454 if (type_is_invalid(value->value.type))
19243 return ira->codegen->builtin_types.entry_invalid;19455 return ira->codegen->builtin_types.entry_invalid;
1924419456
19245 TypeTableEntry *type_entry = value->value.type;19457 ZigType *type_entry = value->value.type;
19246 if (type_is_invalid(type_entry)) {19458 if (type_is_invalid(type_entry)) {
19247 return ira->codegen->builtin_types.entry_invalid;19459 return ira->codegen->builtin_types.entry_invalid;
19248 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19460 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19249 if (instr_is_comptime(value)) {19461 if (instr_is_comptime(value)) {
19250 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);19462 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
19251 if (!err_union_val)19463 if (!err_union_val)
...@@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
19258 }19470 }
19259 }19471 }
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;
19262 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {19474 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
19263 return ira->codegen->builtin_types.entry_invalid;19475 return ira->codegen->builtin_types.entry_invalid;
19264 }19476 }
...@@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1927319485
19274 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);19486 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
19275 return ira->codegen->builtin_types.entry_bool;19487 return ira->codegen->builtin_types.entry_bool;
19276 } else if (type_entry->id == TypeTableEntryIdErrorSet) {19488 } else if (type_entry->id == ZigTypeIdErrorSet) {
19277 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19489 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19278 out_val->data.x_bool = true;19490 out_val->data.x_bool = true;
19279 return ira->codegen->builtin_types.entry_bool;19491 return ira->codegen->builtin_types.entry_bool;
...@@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
19284 }19496 }
19285}19497}
1928619498
19287static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,19499static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
19288 IrInstructionUnwrapErrCode *instruction)19500 IrInstructionUnwrapErrCode *instruction)
19289{19501{
19290 IrInstruction *value = instruction->value->other;19502 IrInstruction *value = instruction->value->other;
19291 if (type_is_invalid(value->value.type))19503 if (type_is_invalid(value->value.type))
19292 return ira->codegen->builtin_types.entry_invalid;19504 return ira->codegen->builtin_types.entry_invalid;
19293 TypeTableEntry *ptr_type = value->value.type;19505 ZigType *ptr_type = value->value.type;
1929419506
19295 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.19507 // 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;
19299 if (type_is_invalid(type_entry)) {19511 if (type_is_invalid(type_entry)) {
19300 return ira->codegen->builtin_types.entry_invalid;19512 return ira->codegen->builtin_types.entry_invalid;
19301 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19513 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19302 if (instr_is_comptime(value)) {19514 if (instr_is_comptime(value)) {
19303 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);19515 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
19304 if (!ptr_val)19516 if (!ptr_val)
19305 return ira->codegen->builtin_types.entry_invalid;19517 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;
19307 if (err_union_val->special != ConstValSpecialRuntime) {19521 if (err_union_val->special != ConstValSpecialRuntime) {
19308 ErrorTableEntry *err = err_union_val->data.x_err_union.err;19522 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
19309 assert(err);19523 assert(err);
...@@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
19323 }19537 }
19324}19538}
1932519539
19326static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,19540static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
19327 IrInstructionUnwrapErrPayload *instruction)19541 IrInstructionUnwrapErrPayload *instruction)
19328{19542{
19329 assert(instruction->value->other);19543 assert(instruction->value->other);
19330 IrInstruction *value = instruction->value->other;19544 IrInstruction *value = instruction->value->other;
19331 if (type_is_invalid(value->value.type))19545 if (type_is_invalid(value->value.type))
19332 return ira->codegen->builtin_types.entry_invalid;19546 return ira->codegen->builtin_types.entry_invalid;
19333 TypeTableEntry *ptr_type = value->value.type;19547 ZigType *ptr_type = value->value.type;
1933419548
19335 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.19549 // 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;
19339 if (type_is_invalid(type_entry)) {19553 if (type_is_invalid(type_entry)) {
19340 return ira->codegen->builtin_types.entry_invalid;19554 return ira->codegen->builtin_types.entry_invalid;
19341 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19555 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19342 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;19556 ZigType *payload_type = type_entry->data.error_union.payload_type;
19343 if (type_is_invalid(payload_type)) {19557 if (type_is_invalid(payload_type)) {
19344 return ira->codegen->builtin_types.entry_invalid;19558 return ira->codegen->builtin_types.entry_invalid;
19345 }19559 }
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,
19347 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,19561 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
19348 PtrLenSingle,19562 PtrLenSingle,
19349 get_abi_alignment(ira->codegen, payload_type), 0, 0);19563 get_abi_alignment(ira->codegen, payload_type), 0, 0);
...@@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
19351 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);19565 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
19352 if (!ptr_val)19566 if (!ptr_val)
19353 return ira->codegen->builtin_types.entry_invalid;19567 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;
19355 if (err_union_val->special != ConstValSpecialRuntime) {19571 if (err_union_val->special != ConstValSpecialRuntime) {
19356 ErrorTableEntry *err = err_union_val->data.x_err_union.err;19572 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
19357 if (err != nullptr) {19573 if (err != nullptr) {
...@@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1937719593
19378}19594}
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;
19381 AstNode *proto_node = instruction->base.source_node;19598 AstNode *proto_node = instruction->base.source_node;
19382 assert(proto_node->type == NodeTypeFnProto);19599 assert(proto_node->type == NodeTypeFnProto);
1938319600
...@@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
19419 IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other;19636 IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other;
19420 if (type_is_invalid(param_type_value->value.type))19637 if (type_is_invalid(param_type_value->value.type))
19421 return ira->codegen->builtin_types.entry_invalid;19638 return ira->codegen->builtin_types.entry_invalid;
19422 param_info->type = ir_resolve_type(ira, param_type_value);19639 ZigType *param_type = ir_resolve_type(ira, param_type_value);
19423 if (type_is_invalid(param_info->type))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)))
19424 return ira->codegen->builtin_types.entry_invalid;19643 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;
19425 }19658 }
1942619659
19427 }19660 }
...@@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
19435 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);19668 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
19436 if (type_is_invalid(fn_type_id.return_type))19669 if (type_is_invalid(fn_type_id.return_type))
19437 return ira->codegen->builtin_types.entry_invalid;19670 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) {
19439 ir_add_error(ira, instruction->return_type,19672 ir_add_error(ira, instruction->return_type,
19440 buf_sprintf("return type cannot be opaque"));19673 buf_sprintf("return type cannot be opaque"));
19441 return ira->codegen->builtin_types.entry_invalid;19674 return ira->codegen->builtin_types.entry_invalid;
...@@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
19458 return ira->codegen->builtin_types.entry_type;19691 return ira->codegen->builtin_types.entry_type;
19459}19692}
1946019693
19461static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {19694static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
19462 IrInstruction *value = instruction->value->other;19695 IrInstruction *value = instruction->value->other;
19463 if (type_is_invalid(value->value.type))19696 if (type_is_invalid(value->value.type))
19464 return ira->codegen->builtin_types.entry_invalid;19697 return ira->codegen->builtin_types.entry_invalid;
...@@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn...@@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn
19468 return ira->codegen->builtin_types.entry_bool;19701 return ira->codegen->builtin_types.entry_bool;
19469}19702}
1947019703
19471static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,19704static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19472 IrInstructionCheckSwitchProngs *instruction)19705 IrInstructionCheckSwitchProngs *instruction)
19473{19706{
19474 IrInstruction *target_value = instruction->target_value->other;19707 IrInstruction *target_value = instruction->target_value->other;
19475 TypeTableEntry *switch_type = target_value->value.type;19708 ZigType *switch_type = target_value->value.type;
19476 if (type_is_invalid(switch_type))19709 if (type_is_invalid(switch_type))
19477 return ira->codegen->builtin_types.entry_invalid;19710 return ira->codegen->builtin_types.entry_invalid;
1947819711
19479 if (switch_type->id == TypeTableEntryIdEnum) {19712 if (switch_type->id == ZigTypeIdEnum) {
19480 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};19713 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
19481 field_prev_uses.init(switch_type->data.enumeration.src_field_count);19714 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...@@ -19491,7 +19724,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19491 if (type_is_invalid(end_value->value.type))19724 if (type_is_invalid(end_value->value.type))
19492 return ira->codegen->builtin_types.entry_invalid;19725 return ira->codegen->builtin_types.entry_invalid;
1949319726
19494 if (start_value->value.type->id != TypeTableEntryIdEnum) {19727 if (start_value->value.type->id != ZigTypeIdEnum) {
19495 ir_add_error(ira, range->start, buf_sprintf("not an enum type"));19728 ir_add_error(ira, range->start, buf_sprintf("not an enum type"));
19496 return ira->codegen->builtin_types.entry_invalid;19729 return ira->codegen->builtin_types.entry_invalid;
19497 }19730 }
...@@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19499 BigInt start_index;19732 BigInt start_index;
19500 bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);19733 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);
19503 BigInt end_index;19736 BigInt end_index;
19504 bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);19737 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...@@ -19535,7 +19768,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19535 }19768 }
19536 }19769 }
19537 }19770 }
19538 } else if (switch_type->id == TypeTableEntryIdErrorSet) {19771 } else if (switch_type->id == ZigTypeIdErrorSet) {
19539 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {19772 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
19540 return ira->codegen->builtin_types.entry_invalid;19773 return ira->codegen->builtin_types.entry_invalid;
19541 }19774 }
...@@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19553 if (type_is_invalid(end_value->value.type))19786 if (type_is_invalid(end_value->value.type))
19554 return ira->codegen->builtin_types.entry_invalid;19787 return ira->codegen->builtin_types.entry_invalid;
1955519788
19556 assert(start_value->value.type->id == TypeTableEntryIdErrorSet);19789 assert(start_value->value.type->id == ZigTypeIdErrorSet);
19557 uint32_t start_index = start_value->value.data.x_err_set->value;19790 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);
19560 uint32_t end_index = end_value->value.data.x_err_set->value;19793 uint32_t end_index = end_value->value.data.x_err_set->value;
1956119794
19562 if (start_index != end_index) {19795 if (start_index != end_index) {
...@@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19592 }19825 }
1959319826
19594 free(field_prev_uses);19827 free(field_prev_uses);
19595 } else if (switch_type->id == TypeTableEntryIdInt) {19828 } else if (switch_type->id == ZigTypeIdInt) {
19596 RangeSet rs = {0};19829 RangeSet rs = {0};
19597 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {19830 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
19598 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];19831 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
...@@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19619 if (!end_val)19852 if (!end_val)
19620 return ira->codegen->builtin_types.entry_invalid;19853 return ira->codegen->builtin_types.entry_invalid;
1962119854
19622 assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);19855 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
19623 assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);19856 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
19624 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,19857 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
19625 start_value->source_node);19858 start_value->source_node);
19626 if (prev_node != nullptr) {19859 if (prev_node != nullptr) {
...@@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
19648 return ira->codegen->builtin_types.entry_void;19881 return ira->codegen->builtin_types.entry_void;
19649}19882}
1965019883
19651static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,19884static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
19652 IrInstructionCheckStatementIsVoid *instruction)19885 IrInstructionCheckStatementIsVoid *instruction)
19653{19886{
19654 IrInstruction *statement_value = instruction->statement_value->other;19887 IrInstruction *statement_value = instruction->statement_value->other;
19655 TypeTableEntry *statement_type = statement_value->value.type;19888 ZigType *statement_type = statement_value->value.type;
19656 if (type_is_invalid(statement_type))19889 if (type_is_invalid(statement_type))
19657 return ira->codegen->builtin_types.entry_invalid;19890 return ira->codegen->builtin_types.entry_invalid;
1965819891
19659 if (statement_type->id != TypeTableEntryIdVoid) {19892 if (statement_type->id != ZigTypeIdVoid) {
19660 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));19893 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
19661 }19894 }
1966219895
...@@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze...@@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze
19664 return ira->codegen->builtin_types.entry_void;19897 return ira->codegen->builtin_types.entry_void;
19665}19898}
1966619899
19667static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {19900static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
19668 IrInstruction *msg = instruction->msg->other;19901 IrInstruction *msg = instruction->msg->other;
19669 if (type_is_invalid(msg->value.type))19902 if (type_is_invalid(msg->value.type))
19670 return ir_unreach_error(ira);19903 return ir_unreach_error(ira);
...@@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio...@@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
19674 return ir_unreach_error(ira);19907 return ir_unreach_error(ira);
19675 }19908 }
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,
19678 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);19911 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);
19680 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);19913 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
19681 if (type_is_invalid(casted_msg->value.type))19914 if (type_is_invalid(casted_msg->value.type))
19682 return ir_unreach_error(ira);19915 return ir_unreach_error(ira);
...@@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio...@@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
19688}19921}
1968919922
19690static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {19923static 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;
19692 assert(!type_is_invalid(target_type));19925 assert(!type_is_invalid(target_type));
1969319926
19694 TypeTableEntry *result_type;19927 ZigType *result_type;
19695 uint32_t old_align_bytes;19928 uint32_t old_align_bytes;
1969619929
19697 if (target_type->id == TypeTableEntryIdPointer) {19930 if (target_type->id == ZigTypeIdPointer) {
19698 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);19931 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
19699 old_align_bytes = target_type->data.pointer.alignment;19932 old_align_bytes = target_type->data.pointer.alignment;
19700 } else if (target_type->id == TypeTableEntryIdFn) {19933 } else if (target_type->id == ZigTypeIdFn) {
19701 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;19934 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
19702 old_align_bytes = fn_type_id.alignment;19935 old_align_bytes = fn_type_id.alignment;
19703 fn_type_id.alignment = align_bytes;19936 fn_type_id.alignment = align_bytes;
19704 result_type = get_fn_type(ira->codegen, &fn_type_id);19937 result_type = get_fn_type(ira->codegen, &fn_type_id);
19705 } else if (target_type->id == TypeTableEntryIdOptional &&19938 } else if (target_type->id == ZigTypeIdOptional &&
19706 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)19939 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
19707 {19940 {
19708 TypeTableEntry *ptr_type = target_type->data.maybe.child_type;19941 ZigType *ptr_type = target_type->data.maybe.child_type;
19709 old_align_bytes = ptr_type->data.pointer.alignment;19942 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
19712 result_type = get_optional_type(ira->codegen, better_ptr_type);19945 result_type = get_optional_type(ira->codegen, better_ptr_type);
19713 } else if (target_type->id == TypeTableEntryIdOptional &&19946 } else if (target_type->id == ZigTypeIdOptional &&
19714 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)19947 target_type->data.maybe.child_type->id == ZigTypeIdFn)
19715 {19948 {
19716 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;19949 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;
19717 old_align_bytes = fn_type_id.alignment;19950 old_align_bytes = fn_type_id.alignment;
19718 fn_type_id.alignment = align_bytes;19951 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);
19720 result_type = get_optional_type(ira->codegen, fn_type);19953 result_type = get_optional_type(ira->codegen, fn_type);
19721 } else if (is_slice(target_type)) {19954 } 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;
19723 old_align_bytes = slice_ptr_type->data.pointer.alignment;19956 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);
19725 result_type = get_slice_type(ira->codegen, result_ptr_type);19958 result_type = get_slice_type(ira->codegen, result_ptr_type);
19726 } else {19959 } else {
19727 ir_add_error(ira, target,19960 ir_add_error(ira, target,
...@@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
19759 return result;19992 return result;
19760}19993}
1976119994
19762static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {19995static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
19763 Error err;19996 Error err;
1976419997
19765 IrInstruction *dest_type_value = instruction->dest_type->other;19998 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);
19767 if (type_is_invalid(dest_type))20000 if (type_is_invalid(dest_type))
19768 return ira->codegen->builtin_types.entry_invalid;20001 return ira->codegen->builtin_types.entry_invalid;
1976920002
19770 IrInstruction *ptr = instruction->ptr->other;20003 IrInstruction *ptr = instruction->ptr->other;
19771 TypeTableEntry *src_type = ptr->value.type;20004 ZigType *src_type = ptr->value.type;
19772 if (type_is_invalid(src_type))20005 if (type_is_invalid(src_type))
19773 return ira->codegen->builtin_types.entry_invalid;20006 return ira->codegen->builtin_types.entry_invalid;
1977420007
...@@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc...@@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
19835static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {20068static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
19836 assert(val->special == ConstValSpecialStatic);20069 assert(val->special == ConstValSpecialStatic);
19837 switch (val->type->id) {20070 switch (val->type->id) {
19838 case TypeTableEntryIdInvalid:20071 case ZigTypeIdInvalid:
19839 case TypeTableEntryIdMetaType:20072 case ZigTypeIdMetaType:
19840 case TypeTableEntryIdOpaque:20073 case ZigTypeIdOpaque:
19841 case TypeTableEntryIdBoundFn:20074 case ZigTypeIdBoundFn:
19842 case TypeTableEntryIdArgTuple:20075 case ZigTypeIdArgTuple:
19843 case TypeTableEntryIdNamespace:20076 case ZigTypeIdNamespace:
19844 case TypeTableEntryIdBlock:20077 case ZigTypeIdBlock:
19845 case TypeTableEntryIdUnreachable:20078 case ZigTypeIdUnreachable:
19846 case TypeTableEntryIdComptimeFloat:20079 case ZigTypeIdComptimeFloat:
19847 case TypeTableEntryIdComptimeInt:20080 case ZigTypeIdComptimeInt:
19848 case TypeTableEntryIdUndefined:20081 case ZigTypeIdUndefined:
19849 case TypeTableEntryIdNull:20082 case ZigTypeIdNull:
19850 case TypeTableEntryIdPromise:20083 case ZigTypeIdPromise:
19851 zig_unreachable();20084 zig_unreachable();
19852 case TypeTableEntryIdVoid:20085 case ZigTypeIdVoid:
19853 return;20086 return;
19854 case TypeTableEntryIdBool:20087 case ZigTypeIdBool:
19855 buf[0] = val->data.x_bool ? 1 : 0;20088 buf[0] = val->data.x_bool ? 1 : 0;
19856 return;20089 return;
19857 case TypeTableEntryIdInt:20090 case ZigTypeIdInt:
19858 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20091 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
19859 codegen->is_big_endian);20092 codegen->is_big_endian);
19860 return;20093 return;
19861 case TypeTableEntryIdFloat:20094 case ZigTypeIdFloat:
19862 float_write_ieee597(val, buf, codegen->is_big_endian);20095 float_write_ieee597(val, buf, codegen->is_big_endian);
19863 return;20096 return;
19864 case TypeTableEntryIdPointer:20097 case ZigTypeIdPointer:
19865 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {20098 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
19866 BigInt bn;20099 BigInt bn;
19867 bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr);20100 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...@@ -19870,7 +20103,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
19870 } else {20103 } else {
19871 zig_unreachable();20104 zig_unreachable();
19872 }20105 }
19873 case TypeTableEntryIdArray:20106 case ZigTypeIdArray:
19874 {20107 {
19875 size_t buf_i = 0;20108 size_t buf_i = 0;
19876 expand_undef_array(codegen, val);20109 expand_undef_array(codegen, val);
...@@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
19881 }20114 }
19882 }20115 }
19883 return;20116 return;
19884 case TypeTableEntryIdStruct:20117 case ZigTypeIdStruct:
19885 zig_panic("TODO buf_write_value_bytes struct type");20118 zig_panic("TODO buf_write_value_bytes struct type");
19886 case TypeTableEntryIdOptional:20119 case ZigTypeIdOptional:
19887 zig_panic("TODO buf_write_value_bytes maybe type");20120 zig_panic("TODO buf_write_value_bytes maybe type");
19888 case TypeTableEntryIdErrorUnion:20121 case ZigTypeIdErrorUnion:
19889 zig_panic("TODO buf_write_value_bytes error union");20122 zig_panic("TODO buf_write_value_bytes error union");
19890 case TypeTableEntryIdErrorSet:20123 case ZigTypeIdErrorSet:
19891 zig_panic("TODO buf_write_value_bytes pure error type");20124 zig_panic("TODO buf_write_value_bytes pure error type");
19892 case TypeTableEntryIdEnum:20125 case ZigTypeIdEnum:
19893 zig_panic("TODO buf_write_value_bytes enum type");20126 zig_panic("TODO buf_write_value_bytes enum type");
19894 case TypeTableEntryIdFn:20127 case ZigTypeIdFn:
19895 zig_panic("TODO buf_write_value_bytes fn type");20128 zig_panic("TODO buf_write_value_bytes fn type");
19896 case TypeTableEntryIdUnion:20129 case ZigTypeIdUnion:
19897 zig_panic("TODO buf_write_value_bytes union type");20130 zig_panic("TODO buf_write_value_bytes union type");
19898 }20131 }
19899 zig_unreachable();20132 zig_unreachable();
...@@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
19902static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {20135static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
19903 assert(val->special == ConstValSpecialStatic);20136 assert(val->special == ConstValSpecialStatic);
19904 switch (val->type->id) {20137 switch (val->type->id) {
19905 case TypeTableEntryIdInvalid:20138 case ZigTypeIdInvalid:
19906 case TypeTableEntryIdMetaType:20139 case ZigTypeIdMetaType:
19907 case TypeTableEntryIdOpaque:20140 case ZigTypeIdOpaque:
19908 case TypeTableEntryIdBoundFn:20141 case ZigTypeIdBoundFn:
19909 case TypeTableEntryIdArgTuple:20142 case ZigTypeIdArgTuple:
19910 case TypeTableEntryIdNamespace:20143 case ZigTypeIdNamespace:
19911 case TypeTableEntryIdBlock:20144 case ZigTypeIdBlock:
19912 case TypeTableEntryIdUnreachable:20145 case ZigTypeIdUnreachable:
19913 case TypeTableEntryIdComptimeFloat:20146 case ZigTypeIdComptimeFloat:
19914 case TypeTableEntryIdComptimeInt:20147 case ZigTypeIdComptimeInt:
19915 case TypeTableEntryIdUndefined:20148 case ZigTypeIdUndefined:
19916 case TypeTableEntryIdNull:20149 case ZigTypeIdNull:
19917 case TypeTableEntryIdPromise:20150 case ZigTypeIdPromise:
19918 zig_unreachable();20151 zig_unreachable();
19919 case TypeTableEntryIdVoid:20152 case ZigTypeIdVoid:
19920 return;20153 return;
19921 case TypeTableEntryIdBool:20154 case ZigTypeIdBool:
19922 val->data.x_bool = (buf[0] != 0);20155 val->data.x_bool = (buf[0] != 0);
19923 return;20156 return;
19924 case TypeTableEntryIdInt:20157 case ZigTypeIdInt:
19925 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20158 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
19926 codegen->is_big_endian, val->type->data.integral.is_signed);20159 codegen->is_big_endian, val->type->data.integral.is_signed);
19927 return;20160 return;
19928 case TypeTableEntryIdFloat:20161 case ZigTypeIdFloat:
19929 float_read_ieee597(val, buf, codegen->is_big_endian);20162 float_read_ieee597(val, buf, codegen->is_big_endian);
19930 return;20163 return;
19931 case TypeTableEntryIdPointer:20164 case ZigTypeIdPointer:
19932 {20165 {
19933 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;20166 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
19934 BigInt bn;20167 BigInt bn;
...@@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
19937 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);20170 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
19938 return;20171 return;
19939 }20172 }
19940 case TypeTableEntryIdArray:20173 case ZigTypeIdArray:
19941 zig_panic("TODO buf_read_value_bytes array type");20174 zig_panic("TODO buf_read_value_bytes array type");
19942 case TypeTableEntryIdStruct:20175 case ZigTypeIdStruct:
19943 zig_panic("TODO buf_read_value_bytes struct type");20176 zig_panic("TODO buf_read_value_bytes struct type");
19944 case TypeTableEntryIdOptional:20177 case ZigTypeIdOptional:
19945 zig_panic("TODO buf_read_value_bytes maybe type");20178 zig_panic("TODO buf_read_value_bytes maybe type");
19946 case TypeTableEntryIdErrorUnion:20179 case ZigTypeIdErrorUnion:
19947 zig_panic("TODO buf_read_value_bytes error union");20180 zig_panic("TODO buf_read_value_bytes error union");
19948 case TypeTableEntryIdErrorSet:20181 case ZigTypeIdErrorSet:
19949 zig_panic("TODO buf_read_value_bytes pure error type");20182 zig_panic("TODO buf_read_value_bytes pure error type");
19950 case TypeTableEntryIdEnum:20183 case ZigTypeIdEnum:
19951 zig_panic("TODO buf_read_value_bytes enum type");20184 zig_panic("TODO buf_read_value_bytes enum type");
19952 case TypeTableEntryIdFn:20185 case ZigTypeIdFn:
19953 zig_panic("TODO buf_read_value_bytes fn type");20186 zig_panic("TODO buf_read_value_bytes fn type");
19954 case TypeTableEntryIdUnion:20187 case ZigTypeIdUnion:
19955 zig_panic("TODO buf_read_value_bytes union type");20188 zig_panic("TODO buf_read_value_bytes union type");
19956 }20189 }
19957 zig_unreachable();20190 zig_unreachable();
19958}20191}
1995920192
19960static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {20193static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
19961 Error err;20194 Error err;
19962 IrInstruction *dest_type_value = instruction->dest_type->other;20195 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);
19964 if (type_is_invalid(dest_type))20197 if (type_is_invalid(dest_type))
19965 return ira->codegen->builtin_types.entry_invalid;20198 return ira->codegen->builtin_types.entry_invalid;
1996620199
19967 IrInstruction *value = instruction->value->other;20200 IrInstruction *value = instruction->value->other;
19968 TypeTableEntry *src_type = value->value.type;20201 ZigType *src_type = value->value.type;
19969 if (type_is_invalid(src_type))20202 if (type_is_invalid(src_type))
19970 return ira->codegen->builtin_types.entry_invalid;20203 return ira->codegen->builtin_types.entry_invalid;
1997120204
...@@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
19982 }20215 }
1998320216
19984 switch (src_type->id) {20217 switch (src_type->id) {
19985 case TypeTableEntryIdInvalid:20218 case ZigTypeIdInvalid:
19986 case TypeTableEntryIdMetaType:20219 case ZigTypeIdMetaType:
19987 case TypeTableEntryIdOpaque:20220 case ZigTypeIdOpaque:
19988 case TypeTableEntryIdBoundFn:20221 case ZigTypeIdBoundFn:
19989 case TypeTableEntryIdArgTuple:20222 case ZigTypeIdArgTuple:
19990 case TypeTableEntryIdNamespace:20223 case ZigTypeIdNamespace:
19991 case TypeTableEntryIdBlock:20224 case ZigTypeIdBlock:
19992 case TypeTableEntryIdUnreachable:20225 case ZigTypeIdUnreachable:
19993 case TypeTableEntryIdComptimeFloat:20226 case ZigTypeIdComptimeFloat:
19994 case TypeTableEntryIdComptimeInt:20227 case ZigTypeIdComptimeInt:
19995 case TypeTableEntryIdUndefined:20228 case ZigTypeIdUndefined:
19996 case TypeTableEntryIdNull:20229 case ZigTypeIdNull:
19997 ir_add_error(ira, dest_type_value,20230 ir_add_error(ira, dest_type_value,
19998 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));20231 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
19999 return ira->codegen->builtin_types.entry_invalid;20232 return ira->codegen->builtin_types.entry_invalid;
...@@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
20008 }20241 }
2000920242
20010 switch (dest_type->id) {20243 switch (dest_type->id) {
20011 case TypeTableEntryIdInvalid:20244 case ZigTypeIdInvalid:
20012 case TypeTableEntryIdMetaType:20245 case ZigTypeIdMetaType:
20013 case TypeTableEntryIdOpaque:20246 case ZigTypeIdOpaque:
20014 case TypeTableEntryIdBoundFn:20247 case ZigTypeIdBoundFn:
20015 case TypeTableEntryIdArgTuple:20248 case ZigTypeIdArgTuple:
20016 case TypeTableEntryIdNamespace:20249 case ZigTypeIdNamespace:
20017 case TypeTableEntryIdBlock:20250 case ZigTypeIdBlock:
20018 case TypeTableEntryIdUnreachable:20251 case ZigTypeIdUnreachable:
20019 case TypeTableEntryIdComptimeFloat:20252 case ZigTypeIdComptimeFloat:
20020 case TypeTableEntryIdComptimeInt:20253 case ZigTypeIdComptimeInt:
20021 case TypeTableEntryIdUndefined:20254 case ZigTypeIdUndefined:
20022 case TypeTableEntryIdNull:20255 case ZigTypeIdNull:
20023 ir_add_error(ira, dest_type_value,20256 ir_add_error(ira, dest_type_value,
20024 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));20257 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
20025 return ira->codegen->builtin_types.entry_invalid;20258 return ira->codegen->builtin_types.entry_invalid;
...@@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
20057 return dest_type;20290 return dest_type;
20058}20291}
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) {
20061 Error err;20294 Error err;
20062 IrInstruction *dest_type_value = instruction->dest_type->other;20295 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);
20064 if (type_is_invalid(dest_type))20297 if (type_is_invalid(dest_type))
20065 return ira->codegen->builtin_types.entry_invalid;20298 return ira->codegen->builtin_types.entry_invalid;
2006620299
...@@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr...@@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
20102 return dest_type;20335 return dest_type;
20103}20336}
2010420337
20105static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,20338static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20106 IrInstructionDeclRef *instruction)20339 IrInstructionDeclRef *instruction)
20107{20340{
20108 Tld *tld = instruction->tld;20341 Tld *tld = instruction->tld;
...@@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20119 case TldIdVar:20352 case TldIdVar:
20120 {20353 {
20121 TldVar *tld_var = (TldVar *)tld;20354 TldVar *tld_var = (TldVar *)tld;
20122 VariableTableEntry *var = tld_var->var;20355 ZigVar *var = tld_var->var;
2012320356
20124 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);20357 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
20125 if (type_is_invalid(var_ptr->value.type))20358 if (type_is_invalid(var_ptr->value.type))
...@@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20141 case TldIdFn:20374 case TldIdFn:
20142 {20375 {
20143 TldFn *tld_fn = (TldFn *)tld;20376 TldFn *tld_fn = (TldFn *)tld;
20144 FnTableEntry *fn_entry = tld_fn->fn_entry;20377 ZigFn *fn_entry = tld_fn->fn_entry;
20145 assert(fn_entry->type_entry);20378 assert(fn_entry->type_entry);
2014620379
20147 if (tld_fn->extern_lib_name != nullptr) {20380 if (tld_fn->extern_lib_name != nullptr) {
...@@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
20163 zig_unreachable();20396 zig_unreachable();
20164}20397}
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) {
20167 IrInstruction *target = instruction->target->other;20400 IrInstruction *target = instruction->target->other;
20168 if (type_is_invalid(target->value.type))20401 if (type_is_invalid(target->value.type))
20169 return ira->codegen->builtin_types.entry_invalid;20402 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
20173 if (get_codegen_ptr_type(target->value.type) == nullptr) {20406 if (get_codegen_ptr_type(target->value.type) == nullptr) {
20174 ir_add_error(ira, target,20407 ir_add_error(ira, target,
...@@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr...@@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
20186 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);20419 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
20187 if (!val)20420 if (!val)
20188 return ira->codegen->builtin_types.entry_invalid;20421 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) {
20190 IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,20423 IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,
20191 instruction->base.source_node, usize);20424 instruction->base.source_node, usize);
20192 bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);20425 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...@@ -20202,16 +20435,16 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
20202 return usize;20435 return usize;
20203}20436}
2020420437
20205static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {20438static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
20206 Error err;20439 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);
20208 if (type_is_invalid(child_type))20441 if (type_is_invalid(child_type))
20209 return ira->codegen->builtin_types.entry_invalid;20442 return ira->codegen->builtin_types.entry_invalid;
2021020443
20211 if (child_type->id == TypeTableEntryIdUnreachable) {20444 if (child_type->id == ZigTypeIdUnreachable) {
20212 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));20445 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
20213 return ira->codegen->builtin_types.entry_invalid;20446 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) {
20215 ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));20448 ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));
20216 return ira->codegen->builtin_types.entry_invalid;20449 return ira->codegen->builtin_types.entry_invalid;
20217 }20450 }
...@@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc...@@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
20235 return ira->codegen->builtin_types.entry_type;20468 return ira->codegen->builtin_types.entry_type;
20236}20469}
2023720470
20238static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {20471static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
20239 uint32_t align_bytes;20472 uint32_t align_bytes;
20240 IrInstruction *align_bytes_inst = instruction->align_bytes->other;20473 IrInstruction *align_bytes_inst = instruction->align_bytes->other;
20241 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))20474 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
...@@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr...@@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr
20253 return result->value.type;20486 return result->value.type;
20254}20487}
2025520488
20256static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {20489static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
20257 Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node);20490 Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node);
20258 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);20491 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
20259 out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,20492 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...@@ -20261,7 +20494,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst
20261 return ira->codegen->builtin_types.entry_type;20494 return ira->codegen->builtin_types.entry_type;
20262}20495}
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) {
20265 uint32_t align_bytes;20498 uint32_t align_bytes;
20266 IrInstruction *align_bytes_inst = instruction->align_bytes->other;20499 IrInstruction *align_bytes_inst = instruction->align_bytes->other;
20267 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))20500 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...@@ -20272,7 +20505,7 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
20272 return ira->codegen->builtin_types.entry_invalid;20505 return ira->codegen->builtin_types.entry_invalid;
20273 }20506 }
2027420507
20275 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);20508 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
20276 if (fn_entry == nullptr) {20509 if (fn_entry == nullptr) {
20277 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));20510 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
20278 return ira->codegen->builtin_types.entry_invalid;20511 return ira->codegen->builtin_types.entry_invalid;
...@@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir...@@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
20301 return ira->codegen->builtin_types.entry_void;20534 return ira->codegen->builtin_types.entry_void;
20302}20535}
2030320536
20304static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {20537static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
20305 IrInstruction *fn_type_inst = instruction->fn_type->other;20538 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);
20307 if (type_is_invalid(fn_type))20540 if (type_is_invalid(fn_type))
20308 return ira->codegen->builtin_types.entry_invalid;20541 return ira->codegen->builtin_types.entry_invalid;
2030920542
...@@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc...@@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
20312 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))20545 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
20313 return ira->codegen->builtin_types.entry_invalid;20546 return ira->codegen->builtin_types.entry_invalid;
2031420547
20315 if (fn_type->id != TypeTableEntryIdFn) {20548 if (fn_type->id != ZigTypeIdFn) {
20316 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));20549 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
20317 return ira->codegen->builtin_types.entry_invalid;20550 return ira->codegen->builtin_types.entry_invalid;
20318 }20551 }
...@@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc...@@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
20340 return ira->codegen->builtin_types.entry_type;20573 return ira->codegen->builtin_types.entry_type;
20341}20574}
2034220575
20343static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {20576static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
20344 Error err;20577 Error err;
20345 IrInstruction *target_inst = instruction->target->other;20578 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);
20347 if (type_is_invalid(enum_type))20580 if (type_is_invalid(enum_type))
20348 return ira->codegen->builtin_types.entry_invalid;20581 return ira->codegen->builtin_types.entry_invalid;
2034920582
20350 if (enum_type->id == TypeTableEntryIdEnum) {20583 if (enum_type->id == ZigTypeIdEnum) {
20351 if ((err = ensure_complete_type(ira->codegen, enum_type)))20584 if ((err = ensure_complete_type(ira->codegen, enum_type)))
20352 return ira->codegen->builtin_types.entry_invalid;20585 return ira->codegen->builtin_types.entry_invalid;
2035320586
20354 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);20587 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
20355 out_val->data.x_type = enum_type->data.enumeration.tag_int_type;20588 out_val->data.x_type = enum_type->data.enumeration.tag_int_type;
20356 return ira->codegen->builtin_types.entry_type;20589 return ira->codegen->builtin_types.entry_type;
20357 } else if (enum_type->id == TypeTableEntryIdUnion) {20590 } else if (enum_type->id == ZigTypeIdUnion) {
20358 if ((err = ensure_complete_type(ira->codegen, enum_type)))20591 if ((err = ensure_complete_type(ira->codegen, enum_type)))
20359 return ira->codegen->builtin_types.entry_invalid;20592 return ira->codegen->builtin_types.entry_invalid;
2036020593
...@@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc...@@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc
20378 }20611 }
20379}20612}
2038020613
20381static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {20614static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
20382 IrInstruction *target_inst = instruction->target->other;20615 IrInstruction *target_inst = instruction->target->other;
20383 if (type_is_invalid(target_inst->value.type))20616 if (type_is_invalid(target_inst->value.type))
20384 return ira->codegen->builtin_types.entry_invalid;20617 return ira->codegen->builtin_types.entry_invalid;
...@@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi...@@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi
20393 return result->value.type;20626 return result->value.type;
20394}20627}
2039520628
20396static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {20629static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
20397 IrInstruction *promise_ptr = instruction->promise_ptr->other;20630 IrInstruction *promise_ptr = instruction->promise_ptr->other;
20398 if (type_is_invalid(promise_ptr->value.type))20631 if (type_is_invalid(promise_ptr->value.type))
20399 return ira->codegen->builtin_types.entry_invalid;20632 return ira->codegen->builtin_types.entry_invalid;
...@@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct...@@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct
20405 return result->value.type;20638 return result->value.type;
20406}20639}
2040720640
20408static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {20641static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
20409 IrInstruction *coro_id = instruction->coro_id->other;20642 IrInstruction *coro_id = instruction->coro_id->other;
20410 if (type_is_invalid(coro_id->value.type))20643 if (type_is_invalid(coro_id->value.type))
20411 return ira->codegen->builtin_types.entry_invalid;20644 return ira->codegen->builtin_types.entry_invalid;
...@@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr...@@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr
20417 return result->value.type;20650 return result->value.type;
20418}20651}
2041920652
20420static TypeTableEntry *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {20653static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
20421 IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node);20654 IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
20422 ir_link_new_instruction(result, &instruction->base);20655 ir_link_new_instruction(result, &instruction->base);
20423 result->value.type = ira->codegen->builtin_types.entry_usize;20656 result->value.type = ira->codegen->builtin_types.entry_usize;
20424 return result->value.type;20657 return result->value.type;
20425}20658}
2042620659
20427static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {20660static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
20428 IrInstruction *coro_id = instruction->coro_id->other;20661 IrInstruction *coro_id = instruction->coro_id->other;
20429 if (type_is_invalid(coro_id->value.type))20662 if (type_is_invalid(coro_id->value.type))
20430 return ira->codegen->builtin_types.entry_invalid;20663 return ira->codegen->builtin_types.entry_invalid;
...@@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr...@@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
20433 if (type_is_invalid(coro_mem_ptr->value.type))20666 if (type_is_invalid(coro_mem_ptr->value.type))
20434 return ira->codegen->builtin_types.entry_invalid;20667 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);
20437 assert(fn_entry != nullptr);20670 assert(fn_entry != nullptr);
20438 IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,20671 IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
20439 coro_id, coro_mem_ptr);20672 coro_id, coro_mem_ptr);
...@@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr...@@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
20442 return result->value.type;20675 return result->value.type;
20443}20676}
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) {
20446 IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id);20679 IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id);
20447 ir_link_new_instruction(result, &instruction->base);20680 ir_link_new_instruction(result, &instruction->base);
20448 return result->value.type;20681 return result->value.type;
20449}20682}
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) {
20452 IrInstruction *err_val = instruction->err_val->other;20685 IrInstruction *err_val = instruction->err_val->other;
20453 if (type_is_invalid(err_val->value.type))20686 if (type_is_invalid(err_val->value.type))
20454 return ir_unreach_error(ira);20687 return ir_unreach_error(ira);
...@@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir...@@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir
20459 return ir_finish_anal(ira, result->value.type);20692 return ir_finish_anal(ira, result->value.type);
20460}20693}
2046120694
20462static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {20695static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
20463 IrInstruction *save_point = nullptr;20696 IrInstruction *save_point = nullptr;
20464 if (instruction->save_point != nullptr) {20697 if (instruction->save_point != nullptr) {
20465 save_point = instruction->save_point->other;20698 save_point = instruction->save_point->other;
...@@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns...@@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns
20478 return result->value.type;20711 return result->value.type;
20479}20712}
2048020713
20481static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {20714static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
20482 IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope,20715 IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope,
20483 instruction->base.source_node);20716 instruction->base.source_node);
20484 ir_link_new_instruction(result, &instruction->base);20717 ir_link_new_instruction(result, &instruction->base);
...@@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc...@@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc
20486 return result->value.type;20719 return result->value.type;
20487}20720}
2048820721
20489static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {20722static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
20490 IrInstruction *coro_id = instruction->coro_id->other;20723 IrInstruction *coro_id = instruction->coro_id->other;
20491 if (type_is_invalid(coro_id->value.type))20724 if (type_is_invalid(coro_id->value.type))
20492 return ira->codegen->builtin_types.entry_invalid;20725 return ira->codegen->builtin_types.entry_invalid;
...@@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru...@@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru
20498 IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope,20731 IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope,
20499 instruction->base.source_node, coro_id, coro_handle);20732 instruction->base.source_node, coro_id, coro_handle);
20500 ir_link_new_instruction(result, &instruction->base);20733 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);
20502 result->value.type = get_optional_type(ira->codegen, ptr_type);20735 result->value.type = get_optional_type(ira->codegen, ptr_type);
20503 return result->value.type;20736 return result->value.type;
20504}20737}
2050520738
20506static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {20739static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
20507 IrInstruction *awaiter_handle = instruction->awaiter_handle->other;20740 IrInstruction *awaiter_handle = instruction->awaiter_handle->other;
20508 if (type_is_invalid(awaiter_handle->value.type))20741 if (type_is_invalid(awaiter_handle->value.type))
20509 return ira->codegen->builtin_types.entry_invalid;20742 return ira->codegen->builtin_types.entry_invalid;
...@@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst...@@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst
20519 return result->value.type;20752 return result->value.type;
20520}20753}
2052120754
20522static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {20755static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
20523 IrInstruction *coro_handle = instruction->coro_handle->other;20756 IrInstruction *coro_handle = instruction->coro_handle->other;
20524 if (type_is_invalid(coro_handle->value.type))20757 if (type_is_invalid(coro_handle->value.type))
20525 return ira->codegen->builtin_types.entry_invalid;20758 return ira->codegen->builtin_types.entry_invalid;
...@@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru...@@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru
20531 return result->value.type;20764 return result->value.type;
20532}20765}
2053320766
20534static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {20767static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
20535 IrInstruction *coro_handle = instruction->coro_handle->other;20768 IrInstruction *coro_handle = instruction->coro_handle->other;
20536 if (type_is_invalid(coro_handle->value.type))20769 if (type_is_invalid(coro_handle->value.type))
20537 return ira->codegen->builtin_types.entry_invalid;20770 return ira->codegen->builtin_types.entry_invalid;
2053820771
20539 if (coro_handle->value.type->id != TypeTableEntryIdPromise ||20772 if (coro_handle->value.type->id != ZigTypeIdPromise ||
20540 coro_handle->value.type->data.promise.result_type == nullptr)20773 coro_handle->value.type->data.promise.result_type == nullptr)
20541 {20774 {
20542 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20775 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...@@ -20544,7 +20777,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
20544 return ira->codegen->builtin_types.entry_invalid;20777 return ira->codegen->builtin_types.entry_invalid;
20545 }20778 }
2054620779
20547 TypeTableEntry *coro_frame_type = get_promise_frame_type(ira->codegen,20780 ZigType *coro_frame_type = get_promise_frame_type(ira->codegen,
20548 coro_handle->value.type->data.promise.result_type);20781 coro_handle->value.type->data.promise.result_type);
2054920782
20550 IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope,20783 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...@@ -20554,7 +20787,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
20554 return result->value.type;20787 return result->value.type;
20555}20788}
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) {
20558 IrInstruction *alloc_fn = instruction->alloc_fn->other;20791 IrInstruction *alloc_fn = instruction->alloc_fn->other;
20559 if (type_is_invalid(alloc_fn->value.type))20792 if (type_is_invalid(alloc_fn->value.type))
20560 return ira->codegen->builtin_types.entry_invalid;20793 return ira->codegen->builtin_types.entry_invalid;
...@@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira,...@@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira,
20566 IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope,20799 IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope,
20567 instruction->base.source_node, alloc_fn, coro_size);20800 instruction->base.source_node, alloc_fn, coro_size);
20568 ir_link_new_instruction(result, &instruction->base);20801 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);
20570 result->value.type = get_optional_type(ira->codegen, u8_ptr_type);20803 result->value.type = get_optional_type(ira->codegen, u8_ptr_type);
20571 return result->value.type;20804 return result->value.type;
20572}20805}
2057320806
20574static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {20807static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
20575 TypeTableEntry *operand_type = ir_resolve_type(ira, op);20808 ZigType *operand_type = ir_resolve_type(ira, op);
20576 if (type_is_invalid(operand_type))20809 if (type_is_invalid(operand_type))
20577 return ira->codegen->builtin_types.entry_invalid;20810 return ira->codegen->builtin_types.entry_invalid;
2057820811
20579 if (operand_type->id == TypeTableEntryIdInt) {20812 if (operand_type->id == ZigTypeIdInt) {
20580 if (operand_type->data.integral.bit_count < 8) {20813 if (operand_type->data.integral.bit_count < 8) {
20581 ir_add_error(ira, op,20814 ir_add_error(ira, op,
20582 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",20815 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...@@ -20603,8 +20836,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct
20603 return operand_type;20836 return operand_type;
20604}20837}
2060520838
20606static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {20839static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
20607 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);20840 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
20608 if (type_is_invalid(operand_type))20841 if (type_is_invalid(operand_type))
20609 return ira->codegen->builtin_types.entry_invalid;20842 return ira->codegen->builtin_types.entry_invalid;
2061020843
...@@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr...@@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
20613 return ira->codegen->builtin_types.entry_invalid;20846 return ira->codegen->builtin_types.entry_invalid;
2061420847
20615 // TODO let this be volatile20848 // 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);
20617 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);20850 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
20618 if (type_is_invalid(casted_ptr->value.type))20851 if (type_is_invalid(casted_ptr->value.type))
20619 return ira->codegen->builtin_types.entry_invalid;20852 return ira->codegen->builtin_types.entry_invalid;
...@@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr...@@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
20661 return result->value.type;20894 return result->value.type;
20662}20895}
2066320896
20664static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {20897static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
20665 TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);20898 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
20666 if (type_is_invalid(operand_type))20899 if (type_is_invalid(operand_type))
20667 return ira->codegen->builtin_types.entry_invalid;20900 return ira->codegen->builtin_types.entry_invalid;
2066820901
...@@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst...@@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
20670 if (type_is_invalid(ptr_inst->value.type))20903 if (type_is_invalid(ptr_inst->value.type))
20671 return ira->codegen->builtin_types.entry_invalid;20904 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);
20674 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);20907 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
20675 if (type_is_invalid(casted_ptr->value.type))20908 if (type_is_invalid(casted_ptr->value.type))
20676 return ira->codegen->builtin_types.entry_invalid;20909 return ira->codegen->builtin_types.entry_invalid;
...@@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst...@@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
20704 return result->value.type;20937 return result->value.type;
20705}20938}
2070620939
20707static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {20940static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
20708 TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other);20941 ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other);
20709 if (type_is_invalid(promise_type))20942 if (type_is_invalid(promise_type))
20710 return ira->codegen->builtin_types.entry_invalid;20943 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) {
20713 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20946 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
20714 buf_ptr(&promise_type->name)));20947 buf_ptr(&promise_type->name)));
20715 return ira->codegen->builtin_types.entry_invalid;20948 return ira->codegen->builtin_types.entry_invalid;
...@@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira...@@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira
20720 return ira->codegen->builtin_types.entry_type;20953 return ira->codegen->builtin_types.entry_type;
20721}20954}
2072220955
20723static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {20956static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
20724 TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);20957 ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);
20725 if (type_is_invalid(promise_result_type))20958 if (type_is_invalid(promise_result_type))
20726 return ira->codegen->builtin_types.entry_invalid;20959 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);
20729 assert(fn_entry != nullptr);20962 assert(fn_entry != nullptr);
2073020963
20731 if (type_can_fail(promise_result_type)) {20964 if (type_can_fail(promise_result_type)) {
...@@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira,...@@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira,
20737 return out_val->type;20970 return out_val->type;
20738}20971}
2073920972
20740static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,20973static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
20741 IrInstructionMergeErrRetTraces *instruction)20974 IrInstructionMergeErrRetTraces *instruction)
20742{20975{
20743 IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other;20976 IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other;
20744 if (type_is_invalid(coro_promise_ptr->value.type))20977 if (type_is_invalid(coro_promise_ptr->value.type))
20745 return ira->codegen->builtin_types.entry_invalid;20978 return ira->codegen->builtin_types.entry_invalid;
2074620979
20747 assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer);20980 assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer);
20748 TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;20981 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
20749 assert(promise_frame_type->id == TypeTableEntryIdStruct);20982 assert(promise_frame_type->id == ZigTypeIdStruct);
20750 TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;20983 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
2075120984
20752 if (!type_can_fail(promise_result_type)) {20985 if (!type_can_fail(promise_result_type)) {
20753 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);20986 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...@@ -20770,7 +21003,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir
20770 return result->value.type;21003 return result->value.type;
20771}21004}
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) {
20774 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,21007 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
20775 instruction->base.source_node);21008 instruction->base.source_node);
20776 ir_link_new_instruction(result, &instruction->base);21009 ir_link_new_instruction(result, &instruction->base);
...@@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira,...@@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira,
20778 return result->value.type;21011 return result->value.type;
20779}21012}
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) {
20782 IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other;21015 IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other;
20783 if (type_is_invalid(err_ret_trace_ptr->value.type))21016 if (type_is_invalid(err_ret_trace_ptr->value.type))
20784 return ira->codegen->builtin_types.entry_invalid;21017 return ira->codegen->builtin_types.entry_invalid;
...@@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *...@@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *
20790 return result->value.type;21023 return result->value.type;
20791}21024}
2079221025
20793static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {21026static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
20794 TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other);21027 ZigType *float_type = ir_resolve_type(ira, instruction->type->other);
20795 if (type_is_invalid(float_type))21028 if (type_is_invalid(float_type))
20796 return ira->codegen->builtin_types.entry_invalid;21029 return ira->codegen->builtin_types.entry_invalid;
2079721030
...@@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction...@@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
20799 if (type_is_invalid(op->value.type))21032 if (type_is_invalid(op->value.type))
20800 return ira->codegen->builtin_types.entry_invalid;21033 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;
20803 if (!ok_type) {21036 if (!ok_type) {
20804 ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));21037 ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));
20805 return ira->codegen->builtin_types.entry_invalid;21038 return ira->codegen->builtin_types.entry_invalid;
...@@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction...@@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
2081621049
20817 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);21050 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
2081821051
20819 if (float_type->id == TypeTableEntryIdComptimeFloat) {21052 if (float_type->id == ZigTypeIdComptimeFloat) {
20820 bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);21053 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) {
20822 switch (float_type->data.floating.bit_count) {21055 switch (float_type->data.floating.bit_count) {
20823 case 16:21056 case 16:
20824 out_val->data.x_f16 = f16_sqrt(val->data.x_f16);21057 out_val->data.x_f16 = f16_sqrt(val->data.x_f16);
...@@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction...@@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
20842 return float_type;21075 return float_type;
20843 }21076 }
2084421077
20845 assert(float_type->id == TypeTableEntryIdFloat);21078 assert(float_type->id == ZigTypeIdFloat);
20846 if (float_type->data.floating.bit_count != 16 &&21079 if (float_type->data.floating.bit_count != 16 &&
20847 float_type->data.floating.bit_count != 32 &&21080 float_type->data.floating.bit_count != 32 &&
20848 float_type->data.floating.bit_count != 64) {21081 float_type->data.floating.bit_count != 64) {
...@@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction...@@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
20857 return result->value.type;21090 return result->value.type;
20858}21091}
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) {
20861 Error err;21094 Error err;
20862 IrInstruction *target = instruction->target->other;21095 IrInstruction *target = instruction->target->other;
20863 if (type_is_invalid(target->value.type))21096 if (type_is_invalid(target->value.type))
20864 return ira->codegen->builtin_types.entry_invalid;21097 return ira->codegen->builtin_types.entry_invalid;
2086521098
20866 if (target->value.type->id != TypeTableEntryIdEnum) {21099 if (target->value.type->id != ZigTypeIdEnum) {
20867 ir_add_error(ira, instruction->target,21100 ir_add_error(ira, instruction->target,
20868 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));21101 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
20869 return ira->codegen->builtin_types.entry_invalid;21102 return ira->codegen->builtin_types.entry_invalid;
...@@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst...@@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst
20872 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))21105 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
20873 return ira->codegen->builtin_types.entry_invalid;21106 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
20877 IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type);21110 IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type);
20878 ir_link_new_instruction(result, &instruction->base);21111 ir_link_new_instruction(result, &instruction->base);
20879 return result->value.type;21112 return result->value.type;
20880}21113}
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) {
20883 Error err;21116 Error err;
20884 IrInstruction *dest_type_value = instruction->dest_type->other;21117 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);
20886 if (type_is_invalid(dest_type))21119 if (type_is_invalid(dest_type))
20887 return ira->codegen->builtin_types.entry_invalid;21120 return ira->codegen->builtin_types.entry_invalid;
2088821121
20889 if (dest_type->id != TypeTableEntryIdEnum) {21122 if (dest_type->id != ZigTypeIdEnum) {
20890 ir_add_error(ira, instruction->dest_type,21123 ir_add_error(ira, instruction->dest_type,
20891 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));21124 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
20892 return ira->codegen->builtin_types.entry_invalid;21125 return ira->codegen->builtin_types.entry_invalid;
...@@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst...@@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
20895 if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type)))21128 if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type)))
20896 return ira->codegen->builtin_types.entry_invalid;21129 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
20900 IrInstruction *target = instruction->target->other;21133 IrInstruction *target = instruction->target->other;
20901 if (type_is_invalid(target->value.type))21134 if (type_is_invalid(target->value.type))
...@@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst...@@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
20910 return result->value.type;21143 return result->value.type;
20911}21144}
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) {
20914 switch (instruction->id) {21170 switch (instruction->id) {
20915 case IrInstructionIdInvalid:21171 case IrInstructionIdInvalid:
20916 case IrInstructionIdWidenOrShorten:21172 case IrInstructionIdWidenOrShorten:
...@@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
21186 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);21442 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
21187 case IrInstructionIdEnumToInt:21443 case IrInstructionIdEnumToInt:
21188 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);21444 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
21445 case IrInstructionIdCheckRuntimeScope:
21446 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);
21189 }21447 }
21190 zig_unreachable();21448 zig_unreachable();
21191}21449}
2119221450
21193static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {21451static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
21194 TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction);21452 ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
21195 instruction->value.type = instruction_type;21453 instruction->value.type = instruction_type;
2119621454
21197 if (instruction->other) {21455 if (instruction->other) {
21198 instruction->other->value.type = instruction_type;21456 instruction->other->value.type = instruction_type;
21199 } else {21457 } else {
21200 assert(instruction_type->id == TypeTableEntryIdInvalid ||21458 assert(instruction_type->id == ZigTypeIdInvalid ||
21201 instruction_type->id == TypeTableEntryIdUnreachable);21459 instruction_type->id == ZigTypeIdUnreachable);
21202 instruction->other = instruction;21460 instruction->other = instruction;
21203 }21461 }
2120421462
...@@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins...@@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
2120721465
21208// This function attempts to evaluate IR code while doing type checking and other analysis.21466// This function attempts to evaluate IR code while doing type checking and other analysis.
21209// It emits a new IrExecutable which is partially evaluated IR code.21467// It emits a new IrExecutable which is partially evaluated IR code.
21210TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,21468ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
21211 TypeTableEntry *expected_type, AstNode *expected_type_source_node)21469 ZigType *expected_type, AstNode *expected_type_source_node)
21212{21470{
21213 assert(!old_exec->invalid);21471 assert(!old_exec->invalid);
21214 assert(expected_type == nullptr || !type_is_invalid(expected_type));21472 assert(expected_type == nullptr || !type_is_invalid(expected_type));
...@@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl...@@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
21217 old_exec->analysis = ira;21475 old_exec->analysis = ira;
21218 ira->codegen = codegen;21476 ira->codegen = codegen;
2121921477
21220 FnTableEntry *fn_entry = exec_fn_entry(old_exec);21478 ZigFn *fn_entry = exec_fn_entry(old_exec);
21221 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;21479 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
21222 ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type;21480 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...@@ -21249,13 +21507,13 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
21249 continue;21507 continue;
21250 }21508 }
2125121509
21252 TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction);21510 ZigType *return_type = ir_analyze_instruction(ira, old_instruction);
21253 if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) {21511 if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) {
21254 return ira->codegen->builtin_types.entry_invalid;21512 return ira->codegen->builtin_types.entry_invalid;
21255 }21513 }
2125621514
21257 // unreachable instructions do their own control flow.21515 // unreachable instructions do their own control flow.
21258 if (return_type->id == TypeTableEntryIdUnreachable)21516 if (return_type->id == ZigTypeIdUnreachable)
21259 continue;21517 continue;
2126021518
21261 ira->instruction_index += 1;21519 ira->instruction_index += 1;
...@@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
21301 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free21559 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free
21302 case IrInstructionIdCheckSwitchProngs:21560 case IrInstructionIdCheckSwitchProngs:
21303 case IrInstructionIdCheckStatementIsVoid:21561 case IrInstructionIdCheckStatementIsVoid:
21562 case IrInstructionIdCheckRuntimeScope:
21304 case IrInstructionIdPanic:21563 case IrInstructionIdPanic:
21305 case IrInstructionIdSetEvalBranchQuota:21564 case IrInstructionIdSetEvalBranchQuota:
21306 case IrInstructionIdPtrType:21565 case IrInstructionIdPtrType:
src/ir.hpp+5-5
...@@ -11,15 +11,15 @@...@@ -11,15 +11,15 @@
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);13bool 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
16IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,16IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
17 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,17 ZigType *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,18 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
19 IrExecutable *parent_exec);19 IrExecutable *parent_exec);
2020
21TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,21ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
22 TypeTableEntry *expected_type, AstNode *expected_type_source_node);22 ZigType *expected_type, AstNode *expected_type_source_node);
2323
24bool ir_has_side_effects(IrInstruction *instruction);24bool ir_has_side_effects(IrInstruction *instruction);
25ConstExprValue *const_ptr_pointee(CodeGen *codegen, ConstExprValue *const_val);25ConstExprValue *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...@@ -957,6 +957,14 @@ static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instructi
957 fprintf(irp->f, ")");957 fprintf(irp->f, ")");
958}958}
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
960static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {968static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
961 fprintf(irp->f, "inttoerr ");969 fprintf(irp->f, "inttoerr ");
962 ir_print_other_instruction(irp, instruction->target);970 ir_print_other_instruction(irp, instruction->target);
...@@ -1749,6 +1757,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1749,6 +1757,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1749 case IrInstructionIdEnumToInt:1757 case IrInstructionIdEnumToInt:
1750 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);1758 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
1751 break;1759 break;
1760 case IrInstructionIdCheckRuntimeScope:
1761 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
1762 break;
1752 }1763 }
1753 fprintf(irp->f, "\n");1764 fprintf(irp->f, "\n");
1754}1765}
src/link.cpp+3-3
...@@ -66,7 +66,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)...@@ -66,7 +66,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
66 const char *o_ext = target_o_file_ext(&child_gen->zig_target);66 const char *o_ext = target_o_file_ext(&child_gen->zig_target);
67 Buf *o_out_name = buf_sprintf("%s%s", oname, o_ext);67 Buf *o_out_name = buf_sprintf("%s%s", oname, o_ext);
68 Buf *output_path = buf_alloc();68 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);
70 codegen_link(child_gen, buf_ptr(output_path));70 codegen_link(child_gen, buf_ptr(output_path));
7171
72 codegen_destroy(child_gen);72 codegen_destroy(child_gen);
...@@ -587,11 +587,11 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -587,11 +587,11 @@ static void construct_linker_job_coff(LinkJob *lj) {
587 buf_appendf(def_contents, "\n");587 buf_appendf(def_contents, "\n");
588588
589 Buf *def_path = buf_alloc();589 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);
591 os_write_file(def_path, def_contents);591 os_write_file(def_path, def_contents);
592592
593 Buf *generated_lib_path = buf_alloc();593 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
596 gen_lib_args.resize(0);596 gen_lib_args.resize(0);
597 gen_lib_args.append("link");597 gen_lib_args.append("link");
src/main.cpp+13-13
...@@ -374,25 +374,26 @@ int main(int argc, char **argv) {...@@ -374,25 +374,26 @@ int main(int argc, char **argv) {
374 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);374 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
375 codegen_set_out_name(g, buf_create_from_str("build"));375 codegen_set_out_name(g, buf_create_from_str("build"));
376376
377 Buf build_file_abs = BUF_INIT;377 Buf *build_file_buf = buf_create_from_str(build_file);
378 os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs);378 Buf build_file_abs = os_path_resolve(&build_file_buf, 1);
379 Buf build_file_basename = BUF_INIT;379 Buf build_file_basename = BUF_INIT;
380 Buf build_file_dirname = BUF_INIT;380 Buf build_file_dirname = BUF_INIT;
381 os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename);381 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;
384 if (cache_dir == nullptr) {384 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);
386 } else {386 } 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);
388 }389 }
389390
390 Buf *path_to_build_exe = buf_alloc();391 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);
392 codegen_set_cache_dir(g, full_cache_dir);393 codegen_set_cache_dir(g, full_cache_dir);
393394
394 args.items[1] = buf_ptr(&build_file_dirname);395 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
397 bool build_file_exists;398 bool build_file_exists;
398 if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {399 if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {
...@@ -789,7 +790,7 @@ int main(int argc, char **argv) {...@@ -789,7 +790,7 @@ int main(int argc, char **argv) {
789790
790 Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;791 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;
793 Buf *run_exec_path = buf_alloc();794 Buf *run_exec_path = buf_alloc();
794 if (cmd == CmdRun) {795 if (cmd == CmdRun) {
795 if (buf_out_name == nullptr) {796 if (buf_out_name == nullptr) {
...@@ -799,13 +800,12 @@ int main(int argc, char **argv) {...@@ -799,13 +800,12 @@ int main(int argc, char **argv) {
799 Buf *global_cache_dir = buf_alloc();800 Buf *global_cache_dir = buf_alloc();
800 os_get_global_cache_directory(global_cache_dir);801 os_get_global_cache_directory(global_cache_dir);
801 os_path_join(global_cache_dir, buf_out_name, run_exec_path);802 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
804 out_file = buf_ptr(run_exec_path);805 out_file = buf_ptr(run_exec_path);
805 } else {806 } else {
806 os_path_resolve(buf_create_from_str("."),807 Buf *resolve_paths = buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir);
807 buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir),808 full_cache_dir = os_path_resolve(&resolve_paths, 1);
808 full_cache_dir);
809 }809 }
810810
811 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();811 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
...@@ -937,7 +937,7 @@ int main(int argc, char **argv) {...@@ -937,7 +937,7 @@ int main(int argc, char **argv) {
937937
938 Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target));938 Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target));
939 Buf *test_exe_path = buf_alloc();939 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
942 for (size_t i = 0; i < test_exec_args.length; i += 1) {942 for (size_t i = 0; i < test_exec_args.length; i += 1) {
943 if (test_exec_args.items[i] == nullptr) {943 if (test_exec_args.items[i] == nullptr) {
src/os.cpp+499-29
...@@ -57,6 +57,54 @@ static clock_serv_t cclock;...@@ -57,6 +57,54 @@ static clock_serv_t cclock;
57#include <errno.h>57#include <errno.h>
58#include <time.h>58#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
60#if defined(ZIG_OS_POSIX)108#if defined(ZIG_OS_POSIX)
61static void populate_termination(Termination *term, int status) {109static void populate_termination(Termination *term, int status) {
62 if (WIFEXITED(status)) {110 if (WIFEXITED(status)) {
...@@ -266,15 +314,31 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {...@@ -266,15 +314,31 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {
266#endif314#endif
267}315}
268316
269bool os_path_is_absolute(Buf *path) {
270#if defined(ZIG_OS_WINDOWS)317#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] == '/')
272 return true;321 return true;
273322
274 if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':')323 if (path.ptr[0] == '\\') {
275 return true;324 return true;
276325 }
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 }
277 return false;335 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));
278#elif defined(ZIG_OS_POSIX)342#elif defined(ZIG_OS_POSIX)
279 return buf_ptr(path)[0] == '/';343 return buf_ptr(path)[0] == '/';
280#else344#else
...@@ -282,14 +346,423 @@ bool os_path_is_absolute(Buf *path) {...@@ -282,14 +346,423 @@ bool os_path_is_absolute(Buf *path) {
282#endif346#endif
283}347}
284348
285void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path) {349#if defined(ZIG_OS_WINDOWS)
286 if (os_path_is_absolute(target_path)) {350
287 buf_init_from_buf(out_abs_path, target_path);351enum WindowsPathKind {
288 return;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;
289 }389 }
290390
291 os_path_join(ref_path, target_path, out_abs_path);391 {
292 return;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
293}766}
294767
295int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {768int 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,...@@ -558,7 +1031,7 @@ int os_exec_process(const char *exe, ZigList<const char *> &args,
558void os_write_file(Buf *full_path, Buf *contents) {1031void os_write_file(Buf *full_path, Buf *contents) {
559 FILE *f = fopen(buf_ptr(full_path), "wb");1032 FILE *f = fopen(buf_ptr(full_path), "wb");
560 if (!f) {1033 if (!f) {
561 zig_panic("open failed");1034 zig_panic("os_write_file failed for %s", buf_ptr(full_path));
562 }1035 }
563 size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f);1036 size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f);
564 if (amt_written != (size_t)buf_len(contents))1037 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) {...@@ -645,21 +1118,19 @@ int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
6451118
646int os_get_cwd(Buf *out_cwd) {1119int os_get_cwd(Buf *out_cwd) {
647#if defined(ZIG_OS_WINDOWS)1120#if defined(ZIG_OS_WINDOWS)
648 buf_resize(out_cwd, 4096);1121 char buf[4096];
649 if (GetCurrentDirectory(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) {1122 if (GetCurrentDirectory(4096, buf) == 0) {
650 zig_panic("GetCurrentDirectory failed");1123 zig_panic("GetCurrentDirectory failed");
651 }1124 }
1125 buf_init_from_str(out_cwd, buf);
652 return 0;1126 return 0;
653#elif defined(ZIG_OS_POSIX)1127#elif defined(ZIG_OS_POSIX)
654 int err = ERANGE;1128 char buf[PATH_MAX];
655 buf_resize(out_cwd, 512);1129 char *res = getcwd(buf, PATH_MAX);
656 while (err == ERANGE) {1130 if (res == nullptr) {
657 buf_resize(out_cwd, buf_len(out_cwd) * 2);1131 zig_panic("unable to get cwd: %s", strerror(errno));
658 err = getcwd(buf_ptr(out_cwd), buf_len(out_cwd)) ? 0 : errno;
659 }1132 }
660 if (err)1133 buf_init_from_str(out_cwd, res);
661 zig_panic("unable to get cwd: %s", strerror(err));
662
663 return 0;1134 return 0;
664#else1135#else
665#error "missing os_get_cwd implementation"1136#error "missing os_get_cwd implementation"
...@@ -898,21 +1369,20 @@ double os_get_time(void) {...@@ -898,21 +1369,20 @@ double os_get_time(void) {
898}1369}
8991370
900int os_make_path(Buf *path) {1371int os_make_path(Buf *path) {
901 Buf *resolved_path = buf_alloc();1372 Buf resolved_path = os_path_resolve(&path, 1);
902 os_path_resolve(buf_create_from_str("."), path, resolved_path);
9031373
904 size_t end_index = buf_len(resolved_path);1374 size_t end_index = buf_len(&resolved_path);
905 int err;1375 int err;
906 while (true) {1376 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)))) {
908 if (err == ErrorPathAlreadyExists) {1378 if (err == ErrorPathAlreadyExists) {
909 if (end_index == buf_len(resolved_path))1379 if (end_index == buf_len(&resolved_path))
910 return 0;1380 return 0;
911 } else if (err == ErrorFileNotFound) {1381 } else if (err == ErrorFileNotFound) {
912 // march end_index backward until next path component1382 // march end_index backward until next path component
913 while (true) {1383 while (true) {
914 end_index -= 1;1384 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]))
916 break;1386 break;
917 }1387 }
918 continue;1388 continue;
...@@ -920,12 +1390,12 @@ int os_make_path(Buf *path) {...@@ -920,12 +1390,12 @@ int os_make_path(Buf *path) {
920 return err;1390 return err;
921 }1391 }
922 }1392 }
923 if (end_index == buf_len(resolved_path))1393 if (end_index == buf_len(&resolved_path))
924 return 0;1394 return 0;
925 // march end_index forward until next path component1395 // march end_index forward until next path component
926 while (true) {1396 while (true) {
927 end_index += 1;1397 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]))
929 break;1399 break;
930 }1400 }
931 }1401 }
src/os.hpp+1-1
...@@ -49,7 +49,7 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);...@@ -49,7 +49,7 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);
49void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);49void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);
50void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);50void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);
51int os_path_real(Buf *rel_path, Buf *out_abs_path);51int 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);
53bool os_path_is_absolute(Buf *path);53bool os_path_is_absolute(Buf *path);
5454
55int os_get_global_cache_directory(Buf *out_tmp_path);55int 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) {...@@ -186,4 +186,72 @@ static inline double zig_f16_to_double(float16_t x) {
186 return z;186 return z;
187}187}
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
189#endif257#endif
std/array_list.zig+27-2
...@@ -62,6 +62,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -62,6 +62,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
62 return self.len;62 return self.len;
63 }63 }
6464
65 pub fn capacity(self: Self) usize {
66 return self.items.len;
67 }
68
65 /// ArrayList takes ownership of the passed in slice. The slice must have been69 /// ArrayList takes ownership of the passed in slice. The slice must have been
66 /// allocated with `allocator`.70 /// allocated with `allocator`.
67 /// Deinitialize with `deinit` or use `toOwnedSlice`.71 /// Deinitialize with `deinit` or use `toOwnedSlice`.
...@@ -102,6 +106,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -102,6 +106,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
102 new_item_ptr.* = item;106 new_item_ptr.* = item;
103 }107 }
104108
109 pub fn appendAssumeCapacity(self: *Self, item: T) void {
110 const new_item_ptr = self.addOneAssumeCapacity();
111 new_item_ptr.* = item;
112 }
113
105 /// Removes the element at the specified index and returns it.114 /// Removes the element at the specified index and returns it.
106 /// The empty slot is filled from the end of the list.115 /// The empty slot is filled from the end of the list.
107 pub fn swapRemove(self: *Self, i: usize) T {116 pub fn swapRemove(self: *Self, i: usize) T {
...@@ -138,7 +147,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -138,7 +147,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
138 }147 }
139148
140 pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {149 pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {
141 var better_capacity = self.items.len;150 var better_capacity = self.capacity();
142 if (better_capacity >= new_capacity) return;151 if (better_capacity >= new_capacity) return;
143 while (true) {152 while (true) {
144 better_capacity += better_capacity / 2 + 8;153 better_capacity += better_capacity / 2 + 8;
...@@ -150,8 +159,13 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -150,8 +159,13 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
150 pub fn addOne(self: *Self) !*T {159 pub fn addOne(self: *Self) !*T {
151 const new_length = self.len + 1;160 const new_length = self.len + 1;
152 try self.ensureCapacity(new_length);161 try self.ensureCapacity(new_length);
162 return self.addOneAssumeCapacity();
163 }
164
165 pub fn addOneAssumeCapacity(self: *Self) *T {
166 assert(self.count() < self.capacity());
153 const result = &self.items[self.len];167 const result = &self.items[self.len];
154 self.len = new_length;168 self.len += 1;
155 return result;169 return result;
156 }170 }
157171
...@@ -191,6 +205,17 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -191,6 +205,17 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
191 };205 };
192}206}
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
194test "std.ArrayList.basic" {219test "std.ArrayList.basic" {
195 var bytes: [1024]u8 = undefined;220 var bytes: [1024]u8 = undefined;
196 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;221 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
std/build.zig+27
...@@ -48,6 +48,12 @@ pub const Builder = struct {...@@ -48,6 +48,12 @@ pub const Builder = struct {
48 cache_root: []const u8,48 cache_root: []const u8,
49 release_mode: ?builtin.Mode,49 release_mode: ?builtin.Mode,
5050
51 pub const CStd = enum {
52 C89,
53 C99,
54 C11,
55 };
56
51 const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);57 const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
52 const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);58 const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
5359
...@@ -817,6 +823,7 @@ pub const LibExeObjStep = struct {...@@ -817,6 +823,7 @@ pub const LibExeObjStep = struct {
817 frameworks: BufSet,823 frameworks: BufSet,
818 verbose_link: bool,824 verbose_link: bool,
819 no_rosegment: bool,825 no_rosegment: bool,
826 c_std: Builder.CStd,
820827
821 // zig only stuff828 // zig only stuff
822 root_src: ?[]const u8,829 root_src: ?[]const u8,
...@@ -918,6 +925,7 @@ pub const LibExeObjStep = struct {...@@ -918,6 +925,7 @@ pub const LibExeObjStep = struct {
918 .object_src = undefined,925 .object_src = undefined,
919 .disable_libc = true,926 .disable_libc = true,
920 .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,927 .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
928 .c_std = Builder.CStd.C99,
921 };929 };
922 self.computeOutFileNames();930 self.computeOutFileNames();
923 return self;931 return self;
...@@ -952,6 +960,7 @@ pub const LibExeObjStep = struct {...@@ -952,6 +960,7 @@ pub const LibExeObjStep = struct {
952 .disable_libc = false,960 .disable_libc = false,
953 .is_zig = false,961 .is_zig = false,
954 .linker_script = null,962 .linker_script = null,
963 .c_std = Builder.CStd.C99,
955964
956 .root_src = undefined,965 .root_src = undefined,
957 .verbose_link = false,966 .verbose_link = false,
...@@ -1392,6 +1401,13 @@ pub const LibExeObjStep = struct {...@@ -1392,6 +1401,13 @@ pub const LibExeObjStep = struct {
13921401
1393 const is_darwin = self.target.isDarwin();1402 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
1395 switch (self.kind) {1411 switch (self.kind) {
1396 Kind.Obj => {1412 Kind.Obj => {
1397 cc_args.append("-c") catch unreachable;1413 cc_args.append("-c") catch unreachable;
...@@ -1678,6 +1694,17 @@ pub const TestStep = struct {...@@ -1678,6 +1694,17 @@ pub const TestStep = struct {
1678 self.filter = text;1694 self.filter = text;
1679 }1695 }
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
1681 pub fn addObjectFile(self: *TestStep, path: []const u8) void {1708 pub fn addObjectFile(self: *TestStep, path: []const u8) void {
1682 self.object_files.append(path) catch unreachable;1709 self.object_files.append(path) catch unreachable;
1683 }1710 }
std/crypto/throughput_test.zig+1-1
...@@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void {...@@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void {
130130
131pub fn main() !void {131pub fn main() !void {
132 var stdout_file = try std.io.getStdOut();132 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);
134 const stdout = &stdout_out_stream.stream;134 const stdout = &stdout_out_stream.stream;
135135
136 var buffer: [1024]u8 = undefined;136 var buffer: [1024]u8 = undefined;
std/crypto/x25519.zig+12-1
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
44
5const std = @import("../index.zig");5const std = @import("../index.zig");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const fmt = std.fmt;
78
8const Endian = builtin.Endian;9const Endian = builtin.Endian;
9const readInt = std.mem.readInt;10const readInt = std.mem.readInt;
...@@ -114,7 +115,7 @@ pub const X25519 = struct {...@@ -114,7 +115,7 @@ pub const X25519 = struct {
114 return !zerocmp(u8, out);115 return !zerocmp(u8, out);
115 }116 }
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 {
118 var base_point = []u8{9} ++ []u8{0} ** 31;119 var base_point = []u8{9} ++ []u8{0} ** 31;
119 return create(public_key, private_key, base_point);120 return create(public_key, private_key, base_point);
120 }121 }
...@@ -573,6 +574,16 @@ const Fe = struct {...@@ -573,6 +574,16 @@ const Fe = struct {
573 }574 }
574};575};
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
576test "x25519 rfc7748 vector1" {587test "x25519 rfc7748 vector1" {
577 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";588 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";
578 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";589 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 {...@@ -9,12 +9,12 @@ comptime {
9 _ = @import("cases/bitcast.zig");9 _ = @import("cases/bitcast.zig");
10 _ = @import("cases/bool.zig");10 _ = @import("cases/bool.zig");
11 _ = @import("cases/bugs/1111.zig");11 _ = @import("cases/bugs/1111.zig");
12 _ = @import("cases/bugs/1230.zig");
13 _ = @import("cases/bugs/1277.zig");12 _ = @import("cases/bugs/1277.zig");
14 _ = @import("cases/bugs/1421.zig");13 _ = @import("cases/bugs/1421.zig");
15 _ = @import("cases/bugs/394.zig");14 _ = @import("cases/bugs/394.zig");
16 _ = @import("cases/bugs/655.zig");15 _ = @import("cases/bugs/655.zig");
17 _ = @import("cases/bugs/656.zig");16 _ = @import("cases/bugs/656.zig");
17 _ = @import("cases/bugs/726.zig");
18 _ = @import("cases/bugs/828.zig");18 _ = @import("cases/bugs/828.zig");
19 _ = @import("cases/bugs/920.zig");19 _ = @import("cases/bugs/920.zig");
20 _ = @import("cases/byval_arg_var.zig");20 _ = @import("cases/byval_arg_var.zig");
test/build_examples.zig+6
...@@ -28,4 +28,10 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {...@@ -28,4 +28,10 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {
28 // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it28 // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it
29 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");29 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");
30 }30 }
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 }
31}37}
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 {...@@ -356,6 +356,7 @@ fn testFloatToInts() void {
356 expectFloatToInt(f32, 255.1, u8, 255);356 expectFloatToInt(f32, 255.1, u8, 255);
357 expectFloatToInt(f32, 127.2, i8, 127);357 expectFloatToInt(f32, 127.2, i8, 127);
358 expectFloatToInt(f32, -128.2, i8, -128);358 expectFloatToInt(f32, -128.2, i8, -128);
359 expectFloatToInt(comptime_int, 1234, i16, 1234);
359}360}
360361
361fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {362fn 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" {...@@ -674,3 +674,11 @@ test "inline for with same type but different values" {
674 }674 }
675 assert(res == 5);675 assert(res == 5);
676}676}
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" {...@@ -176,3 +176,18 @@ test "pass by non-copying value as method, at comptime" {
176 assert(pt.addPointCoords() == 3);176 assert(pt.addPointCoords() == 3);
177 }177 }
178}178}
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 {...@@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool {
311 const y = TaggedUnionWithAVoid{ .A = x };311 const y = TaggedUnionWithAVoid{ .A = x };
312 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;312 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
313}313}
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 @@...@@ -1,6 +1,228 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub 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
4 cases.add(226 cases.add(
5 "switch with invalid expression parameter",227 "switch with invalid expression parameter",
6 \\export fn entry() void {228 \\export fn entry() void {
...@@ -340,15 +562,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -340,15 +562,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
340 ".tmp_source.zig:2:20: error: return type cannot be opaque",562 ".tmp_source.zig:2:20: error: return type cannot be opaque",
341 );563 );
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
352 cases.add(565 cases.add(
353 "use implicit casts to assign null to non-nullable pointer",566 "use implicit casts to assign null to non-nullable pointer",
354 \\export fn entry() void {567 \\export fn entry() void {
test/gen_h.zig+24-4
...@@ -20,6 +20,9 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -20,6 +20,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
20 \\ A: i32,20 \\ A: i32,
21 \\ B: f32,21 \\ B: f32,
22 \\ C: bool,22 \\ C: bool,
23 \\ D: u64,
24 \\ E: u64,
25 \\ F: u64,
23 \\};26 \\};
24 \\export fn entry(foo: Foo) void { }27 \\export fn entry(foo: Foo) void { }
25 ,28 ,
...@@ -27,6 +30,9 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -27,6 +30,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
27 \\ int32_t A;30 \\ int32_t A;
28 \\ float B;31 \\ float B;
29 \\ bool C;32 \\ bool C;
33 \\ uint64_t D;
34 \\ uint64_t E;
35 \\ uint64_t F;
30 \\};36 \\};
31 \\37 \\
32 \\TEST_EXPORT void entry(struct Foo foo);38 \\TEST_EXPORT void entry(struct Foo foo);
...@@ -34,17 +40,34 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -34,17 +40,34 @@ pub fn addCases(cases: *tests.GenHContext) void {
34 );40 );
3541
36 cases.add("declare union",42 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 \\};
37 \\const Foo = extern union {50 \\const Foo = extern union {
38 \\ A: i32,51 \\ A: i32,
39 \\ B: f32,52 \\ B: f32,
40 \\ C: bool,53 \\ C: bool,
54 \\ D: Big,
41 \\};55 \\};
42 \\export fn entry(foo: Foo) void { }56 \\export fn entry(foo: Foo) void {}
43 ,57 ,
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 \\
44 \\union Foo {66 \\union Foo {
45 \\ int32_t A;67 \\ int32_t A;
46 \\ float B;68 \\ float B;
47 \\ bool C;69 \\ bool C;
70 \\ struct Big D;
48 \\};71 \\};
49 \\72 \\
50 \\TEST_EXPORT void entry(union Foo foo);73 \\TEST_EXPORT void entry(union Foo foo);
...@@ -85,7 +108,6 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -85,7 +108,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
85 \\export fn a(s: *S) u8 {108 \\export fn a(s: *S) u8 {
86 \\ return s.a;109 \\ return s.a;
87 \\}110 \\}
88
89 ,111 ,
90 \\struct S;112 \\struct S;
91 \\TEST_EXPORT uint8_t a(struct S * s);113 \\TEST_EXPORT uint8_t a(struct S * s);
...@@ -101,7 +123,6 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -101,7 +123,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
101 \\export fn a(s: *U) u8 {123 \\export fn a(s: *U) u8 {
102 \\ return s.A;124 \\ return s.A;
103 \\}125 \\}
104
105 ,126 ,
106 \\union U;127 \\union U;
107 \\TEST_EXPORT uint8_t a(union U * s);128 \\TEST_EXPORT uint8_t a(union U * s);
...@@ -117,7 +138,6 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -117,7 +138,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
117 \\export fn a(s: *E) u8 {138 \\export fn a(s: *E) u8 {
118 \\ return @enumToInt(s.*);139 \\ return @enumToInt(s.*);
119 \\}140 \\}
120
121 ,141 ,
122 \\enum E;142 \\enum E;
123 \\TEST_EXPORT uint8_t a(enum E * s);143 \\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}