authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 18:42:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 18:42:56-04:00
log8400163e0245f68833e29db22ae3bcc1fb8bf9ae
tree5eb0d4463b2437534963159147b16af5a120ce44
parent1f5c7ff4d7360f83f83f422adf167df5d756e3b4
signaturelock-open Commit is signed but in an unrecognized format.

stage1: rename more TypeTableEntry types to ZigType


4 files changed, 1920 insertions(+), 1920 deletions(-)

src/all_types.hpp+52-52
...@@ -1004,7 +1004,7 @@ enum PtrLen {...@@ -1004,7 +1004,7 @@ enum PtrLen {
1004 PtrLenSingle,1004 PtrLenSingle,
1005};1005};
10061006
1007struct TypeTableEntryPointer {1007struct ZigTypePointer {
1008 ZigType *child_type;1008 ZigType *child_type;
1009 PtrLen ptr_len;1009 PtrLen ptr_len;
1010 bool is_const;1010 bool is_const;
...@@ -1015,16 +1015,16 @@ struct TypeTableEntryPointer {...@@ -1015,16 +1015,16 @@ struct TypeTableEntryPointer {
1015 ZigType *slice_parent;1015 ZigType *slice_parent;
1016};1016};
10171017
1018struct TypeTableEntryInt {1018struct ZigTypeInt {
1019 uint32_t bit_count;1019 uint32_t bit_count;
1020 bool is_signed;1020 bool is_signed;
1021};1021};
10221022
1023struct TypeTableEntryFloat {1023struct ZigTypeFloat {
1024 size_t bit_count;1024 size_t bit_count;
1025};1025};
10261026
1027struct TypeTableEntryArray {1027struct ZigTypeArray {
1028 ZigType *child_type;1028 ZigType *child_type;
1029 uint64_t len;1029 uint64_t len;
1030};1030};
...@@ -1040,7 +1040,7 @@ struct TypeStructField {...@@ -1040,7 +1040,7 @@ struct TypeStructField {
1040 size_t unaligned_bit_count;1040 size_t unaligned_bit_count;
1041 AstNode *decl_node;1041 AstNode *decl_node;
1042};1042};
1043struct TypeTableEntryStruct {1043struct ZigTypeStruct {
1044 AstNode *decl_node;1044 AstNode *decl_node;
1045 ContainerLayout layout;1045 ContainerLayout layout;
1046 uint32_t src_field_count;1046 uint32_t src_field_count;
...@@ -1068,22 +1068,22 @@ struct TypeTableEntryStruct {...@@ -1068,22 +1068,22 @@ struct TypeTableEntryStruct {
1068 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;1068 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
1069};1069};
10701070
1071struct TypeTableEntryOptional {1071struct ZigTypeOptional {
1072 ZigType *child_type;1072 ZigType *child_type;
1073};1073};
10741074
1075struct TypeTableEntryErrorUnion {1075struct ZigTypeErrorUnion {
1076 ZigType *err_set_type;1076 ZigType *err_set_type;
1077 ZigType *payload_type;1077 ZigType *payload_type;
1078};1078};
10791079
1080struct TypeTableEntryErrorSet {1080struct ZigTypeErrorSet {
1081 uint32_t err_count;1081 uint32_t err_count;
1082 ErrorTableEntry **errors;1082 ErrorTableEntry **errors;
1083 ZigFn *infer_fn;1083 ZigFn *infer_fn;
1084};1084};
10851085
1086struct TypeTableEntryEnum {1086struct ZigTypeEnum {
1087 AstNode *decl_node;1087 AstNode *decl_node;
1088 ContainerLayout layout;1088 ContainerLayout layout;
1089 uint32_t src_field_count;1089 uint32_t src_field_count;
...@@ -1110,7 +1110,7 @@ struct TypeTableEntryEnum {...@@ -1110,7 +1110,7 @@ struct TypeTableEntryEnum {
1110uint32_t type_ptr_hash(const ZigType *ptr);1110uint32_t type_ptr_hash(const ZigType *ptr);
1111bool type_ptr_eql(const ZigType *a, const ZigType *b);1111bool type_ptr_eql(const ZigType *a, const ZigType *b);
11121112
1113struct TypeTableEntryUnion {1113struct ZigTypeUnion {
1114 AstNode *decl_node;1114 AstNode *decl_node;
1115 ContainerLayout layout;1115 ContainerLayout layout;
1116 uint32_t src_field_count;1116 uint32_t src_field_count;
...@@ -1154,7 +1154,7 @@ struct FnGenParamInfo {...@@ -1154,7 +1154,7 @@ struct FnGenParamInfo {
1154 ZigType *type;1154 ZigType *type;
1155};1155};
11561156
1157struct TypeTableEntryFn {1157struct ZigTypeFn {
1158 FnTypeId fn_type_id;1158 FnTypeId fn_type_id;
1159 bool is_generic;1159 bool is_generic;
1160 ZigType *gen_return_type;1160 ZigType *gen_return_type;
...@@ -1166,42 +1166,42 @@ struct TypeTableEntryFn {...@@ -1166,42 +1166,42 @@ struct TypeTableEntryFn {
1166 ZigType *bound_fn_parent;1166 ZigType *bound_fn_parent;
1167};1167};
11681168
1169struct TypeTableEntryBoundFn {1169struct ZigTypeBoundFn {
1170 ZigType *fn_type;1170 ZigType *fn_type;
1171};1171};
11721172
1173struct TypeTableEntryPromise {1173struct ZigTypePromise {
1174 // null if `promise` instead of `promise->T`1174 // null if `promise` instead of `promise->T`
1175 ZigType *result_type;1175 ZigType *result_type;
1176};1176};
11771177
1178enum ZigTypeId {1178enum ZigTypeId {
1179 TypeTableEntryIdInvalid,1179 ZigTypeIdInvalid,
1180 TypeTableEntryIdMetaType,1180 ZigTypeIdMetaType,
1181 TypeTableEntryIdVoid,1181 ZigTypeIdVoid,
1182 TypeTableEntryIdBool,1182 ZigTypeIdBool,
1183 TypeTableEntryIdUnreachable,1183 ZigTypeIdUnreachable,
1184 TypeTableEntryIdInt,1184 ZigTypeIdInt,
1185 TypeTableEntryIdFloat,1185 ZigTypeIdFloat,
1186 TypeTableEntryIdPointer,1186 ZigTypeIdPointer,
1187 TypeTableEntryIdArray,1187 ZigTypeIdArray,
1188 TypeTableEntryIdStruct,1188 ZigTypeIdStruct,
1189 TypeTableEntryIdComptimeFloat,1189 ZigTypeIdComptimeFloat,
1190 TypeTableEntryIdComptimeInt,1190 ZigTypeIdComptimeInt,
1191 TypeTableEntryIdUndefined,1191 ZigTypeIdUndefined,
1192 TypeTableEntryIdNull,1192 ZigTypeIdNull,
1193 TypeTableEntryIdOptional,1193 ZigTypeIdOptional,
1194 TypeTableEntryIdErrorUnion,1194 ZigTypeIdErrorUnion,
1195 TypeTableEntryIdErrorSet,1195 ZigTypeIdErrorSet,
1196 TypeTableEntryIdEnum,1196 ZigTypeIdEnum,
1197 TypeTableEntryIdUnion,1197 ZigTypeIdUnion,
1198 TypeTableEntryIdFn,1198 ZigTypeIdFn,
1199 TypeTableEntryIdNamespace,1199 ZigTypeIdNamespace,
1200 TypeTableEntryIdBlock,1200 ZigTypeIdBlock,
1201 TypeTableEntryIdBoundFn,1201 ZigTypeIdBoundFn,
1202 TypeTableEntryIdArgTuple,1202 ZigTypeIdArgTuple,
1203 TypeTableEntryIdOpaque,1203 ZigTypeIdOpaque,
1204 TypeTableEntryIdPromise,1204 ZigTypeIdPromise,
1205};1205};
12061206
1207struct ZigType {1207struct ZigType {
...@@ -1216,19 +1216,19 @@ struct ZigType {...@@ -1216,19 +1216,19 @@ struct ZigType {
1216 bool gen_h_loop_flag;1216 bool gen_h_loop_flag;
12171217
1218 union {1218 union {
1219 TypeTableEntryPointer pointer;1219 ZigTypePointer pointer;
1220 TypeTableEntryInt integral;1220 ZigTypeInt integral;
1221 TypeTableEntryFloat floating;1221 ZigTypeFloat floating;
1222 TypeTableEntryArray array;1222 ZigTypeArray array;
1223 TypeTableEntryStruct structure;1223 ZigTypeStruct structure;
1224 TypeTableEntryOptional maybe;1224 ZigTypeOptional maybe;
1225 TypeTableEntryErrorUnion error_union;1225 ZigTypeErrorUnion error_union;
1226 TypeTableEntryErrorSet error_set;1226 ZigTypeErrorSet error_set;
1227 TypeTableEntryEnum enumeration;1227 ZigTypeEnum enumeration;
1228 TypeTableEntryUnion unionation;1228 ZigTypeUnion unionation;
1229 TypeTableEntryFn fn;1229 ZigTypeFn fn;
1230 TypeTableEntryBoundFn bound_fn;1230 ZigTypeBoundFn bound_fn;
1231 TypeTableEntryPromise promise;1231 ZigTypePromise promise;
1232 } data;1232 } data;
12331233
1234 // use these fields to make sure we don't duplicate type table entries for the same type1234 // use these fields to make sure we don't duplicate type table entries for the same type
src/analyze.cpp+695-695
...@@ -77,11 +77,11 @@ ZigType *new_type_table_entry(ZigTypeId id) {...@@ -77,11 +77,11 @@ ZigType *new_type_table_entry(ZigTypeId id) {
77}77}
7878
79static ScopeDecls **get_container_scope_ptr(ZigType *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();
...@@ -220,36 +220,36 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {...@@ -220,36 +220,36 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {
220220
221AstNode *type_decl_node(ZigType *type_entry) {221AstNode *type_decl_node(ZigType *type_entry) {
222 switch (type_entry->id) {222 switch (type_entry->id) {
223 case TypeTableEntryIdInvalid:223 case ZigTypeIdInvalid:
224 zig_unreachable();224 zig_unreachable();
225 case TypeTableEntryIdStruct:225 case ZigTypeIdStruct:
226 return type_entry->data.structure.decl_node;226 return type_entry->data.structure.decl_node;
227 case TypeTableEntryIdEnum:227 case ZigTypeIdEnum:
228 return type_entry->data.enumeration.decl_node;228 return type_entry->data.enumeration.decl_node;
229 case TypeTableEntryIdUnion:229 case ZigTypeIdUnion:
230 return type_entry->data.unionation.decl_node;230 return type_entry->data.unionation.decl_node;
231 case TypeTableEntryIdOpaque:231 case ZigTypeIdOpaque:
232 case TypeTableEntryIdMetaType:232 case ZigTypeIdMetaType:
233 case TypeTableEntryIdVoid:233 case ZigTypeIdVoid:
234 case TypeTableEntryIdBool:234 case ZigTypeIdBool:
235 case TypeTableEntryIdUnreachable:235 case ZigTypeIdUnreachable:
236 case TypeTableEntryIdInt:236 case ZigTypeIdInt:
237 case TypeTableEntryIdFloat:237 case ZigTypeIdFloat:
238 case TypeTableEntryIdPointer:238 case ZigTypeIdPointer:
239 case TypeTableEntryIdArray:239 case ZigTypeIdArray:
240 case TypeTableEntryIdComptimeFloat:240 case ZigTypeIdComptimeFloat:
241 case TypeTableEntryIdComptimeInt:241 case ZigTypeIdComptimeInt:
242 case TypeTableEntryIdUndefined:242 case ZigTypeIdUndefined:
243 case TypeTableEntryIdNull:243 case ZigTypeIdNull:
244 case TypeTableEntryIdOptional:244 case ZigTypeIdOptional:
245 case TypeTableEntryIdErrorUnion:245 case ZigTypeIdErrorUnion:
246 case TypeTableEntryIdErrorSet:246 case ZigTypeIdErrorSet:
247 case TypeTableEntryIdFn:247 case ZigTypeIdFn:
248 case TypeTableEntryIdNamespace:248 case ZigTypeIdNamespace:
249 case TypeTableEntryIdBlock:249 case ZigTypeIdBlock:
250 case TypeTableEntryIdBoundFn:250 case ZigTypeIdBoundFn:
251 case TypeTableEntryIdArgTuple:251 case ZigTypeIdArgTuple:
252 case TypeTableEntryIdPromise:252 case ZigTypeIdPromise:
253 return nullptr;253 return nullptr;
254 }254 }
255 zig_unreachable();255 zig_unreachable();
...@@ -257,37 +257,37 @@ AstNode *type_decl_node(ZigType *type_entry) {...@@ -257,37 +257,37 @@ AstNode *type_decl_node(ZigType *type_entry) {
257257
258bool type_is_complete(ZigType *type_entry) {258bool type_is_complete(ZigType *type_entry) {
259 switch (type_entry->id) {259 switch (type_entry->id) {
260 case TypeTableEntryIdInvalid:260 case ZigTypeIdInvalid:
261 zig_unreachable();261 zig_unreachable();
262 case TypeTableEntryIdStruct:262 case ZigTypeIdStruct:
263 return type_entry->data.structure.complete;263 return type_entry->data.structure.complete;
264 case TypeTableEntryIdEnum:264 case ZigTypeIdEnum:
265 return type_entry->data.enumeration.complete;265 return type_entry->data.enumeration.complete;
266 case TypeTableEntryIdUnion:266 case ZigTypeIdUnion:
267 return type_entry->data.unionation.complete;267 return type_entry->data.unionation.complete;
268 case TypeTableEntryIdOpaque:268 case ZigTypeIdOpaque:
269 return false;269 return false;
270 case TypeTableEntryIdMetaType:270 case ZigTypeIdMetaType:
271 case TypeTableEntryIdVoid:271 case ZigTypeIdVoid:
272 case TypeTableEntryIdBool:272 case ZigTypeIdBool:
273 case TypeTableEntryIdUnreachable:273 case ZigTypeIdUnreachable:
274 case TypeTableEntryIdInt:274 case ZigTypeIdInt:
275 case TypeTableEntryIdFloat:275 case ZigTypeIdFloat:
276 case TypeTableEntryIdPointer:276 case ZigTypeIdPointer:
277 case TypeTableEntryIdArray:277 case ZigTypeIdArray:
278 case TypeTableEntryIdComptimeFloat:278 case ZigTypeIdComptimeFloat:
279 case TypeTableEntryIdComptimeInt:279 case ZigTypeIdComptimeInt:
280 case TypeTableEntryIdUndefined:280 case ZigTypeIdUndefined:
281 case TypeTableEntryIdNull:281 case ZigTypeIdNull:
282 case TypeTableEntryIdOptional:282 case ZigTypeIdOptional:
283 case TypeTableEntryIdErrorUnion:283 case ZigTypeIdErrorUnion:
284 case TypeTableEntryIdErrorSet:284 case ZigTypeIdErrorSet:
285 case TypeTableEntryIdFn:285 case ZigTypeIdFn:
286 case TypeTableEntryIdNamespace:286 case ZigTypeIdNamespace:
287 case TypeTableEntryIdBlock:287 case ZigTypeIdBlock:
288 case TypeTableEntryIdBoundFn:288 case ZigTypeIdBoundFn:
289 case TypeTableEntryIdArgTuple:289 case ZigTypeIdArgTuple:
290 case TypeTableEntryIdPromise:290 case ZigTypeIdPromise:
291 return true;291 return true;
292 }292 }
293 zig_unreachable();293 zig_unreachable();
...@@ -295,36 +295,36 @@ bool type_is_complete(ZigType *type_entry) {...@@ -295,36 +295,36 @@ bool type_is_complete(ZigType *type_entry) {
295295
296bool type_has_zero_bits_known(ZigType *type_entry) {296bool type_has_zero_bits_known(ZigType *type_entry) {
297 switch (type_entry->id) {297 switch (type_entry->id) {
298 case TypeTableEntryIdInvalid:298 case ZigTypeIdInvalid:
299 zig_unreachable();299 zig_unreachable();
300 case TypeTableEntryIdStruct:300 case ZigTypeIdStruct:
301 return type_entry->data.structure.zero_bits_known;301 return type_entry->data.structure.zero_bits_known;
302 case TypeTableEntryIdEnum:302 case ZigTypeIdEnum:
303 return type_entry->data.enumeration.zero_bits_known;303 return type_entry->data.enumeration.zero_bits_known;
304 case TypeTableEntryIdUnion:304 case ZigTypeIdUnion:
305 return type_entry->data.unionation.zero_bits_known;305 return type_entry->data.unionation.zero_bits_known;
306 case TypeTableEntryIdMetaType:306 case ZigTypeIdMetaType:
307 case TypeTableEntryIdVoid:307 case ZigTypeIdVoid:
308 case TypeTableEntryIdBool:308 case ZigTypeIdBool:
309 case TypeTableEntryIdUnreachable:309 case ZigTypeIdUnreachable:
310 case TypeTableEntryIdInt:310 case ZigTypeIdInt:
311 case TypeTableEntryIdFloat:311 case ZigTypeIdFloat:
312 case TypeTableEntryIdPointer:312 case ZigTypeIdPointer:
313 case TypeTableEntryIdArray:313 case ZigTypeIdArray:
314 case TypeTableEntryIdComptimeFloat:314 case ZigTypeIdComptimeFloat:
315 case TypeTableEntryIdComptimeInt:315 case ZigTypeIdComptimeInt:
316 case TypeTableEntryIdUndefined:316 case ZigTypeIdUndefined:
317 case TypeTableEntryIdNull:317 case ZigTypeIdNull:
318 case TypeTableEntryIdOptional:318 case ZigTypeIdOptional:
319 case TypeTableEntryIdErrorUnion:319 case ZigTypeIdErrorUnion:
320 case TypeTableEntryIdErrorSet:320 case ZigTypeIdErrorSet:
321 case TypeTableEntryIdFn:321 case ZigTypeIdFn:
322 case TypeTableEntryIdNamespace:322 case ZigTypeIdNamespace:
323 case TypeTableEntryIdBlock:323 case ZigTypeIdBlock:
324 case TypeTableEntryIdBoundFn:324 case ZigTypeIdBoundFn:
325 case TypeTableEntryIdArgTuple:325 case ZigTypeIdArgTuple:
326 case TypeTableEntryIdOpaque:326 case ZigTypeIdOpaque:
327 case TypeTableEntryIdPromise:327 case ZigTypeIdPromise:
328 return true;328 return true;
329 }329 }
330 zig_unreachable();330 zig_unreachable();
...@@ -337,12 +337,12 @@ uint64_t type_size(CodeGen *g, ZigType *type_entry) {...@@ -337,12 +337,12 @@ uint64_t type_size(CodeGen *g, ZigType *type_entry) {
337 if (!type_has_bits(type_entry))337 if (!type_has_bits(type_entry))
338 return 0;338 return 0;
339339
340 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {340 if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
341 uint64_t size_in_bits = type_size_bits(g, type_entry);341 uint64_t size_in_bits = type_size_bits(g, type_entry);
342 return (size_in_bits + 7) / 8;342 return (size_in_bits + 7) / 8;
343 } else if (type_entry->id == TypeTableEntryIdArray) {343 } else if (type_entry->id == ZigTypeIdArray) {
344 ZigType *child_type = type_entry->data.array.child_type;344 ZigType *child_type = type_entry->data.array.child_type;
345 if (child_type->id == TypeTableEntryIdStruct &&345 if (child_type->id == ZigTypeIdStruct &&
346 child_type->data.structure.layout == ContainerLayoutPacked)346 child_type->data.structure.layout == ContainerLayoutPacked)
347 {347 {
348 uint64_t size_in_bits = type_size_bits(g, type_entry);348 uint64_t size_in_bits = type_size_bits(g, type_entry);
...@@ -359,15 +359,15 @@ uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) {...@@ -359,15 +359,15 @@ uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) {
359 if (!type_has_bits(type_entry))359 if (!type_has_bits(type_entry))
360 return 0;360 return 0;
361361
362 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {362 if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
363 uint64_t result = 0;363 uint64_t result = 0;
364 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) {
365 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);
366 }366 }
367 return result;367 return result;
368 } else if (type_entry->id == TypeTableEntryIdArray) {368 } else if (type_entry->id == ZigTypeIdArray) {
369 ZigType *child_type = type_entry->data.array.child_type;369 ZigType *child_type = type_entry->data.array.child_type;
370 if (child_type->id == TypeTableEntryIdStruct &&370 if (child_type->id == ZigTypeIdStruct &&
371 child_type->data.structure.layout == ContainerLayoutPacked)371 child_type->data.structure.layout == ContainerLayoutPacked)
372 {372 {
373 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);
...@@ -395,7 +395,7 @@ Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) {...@@ -395,7 +395,7 @@ Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) {
395}395}
396396
397static bool is_slice(ZigType *type) {397static bool is_slice(ZigType *type) {
398 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;398 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
399}399}
400400
401ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {401ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
...@@ -410,7 +410,7 @@ ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {...@@ -410,7 +410,7 @@ ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
410 }410 }
411411
412 ZigType *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);
413 ZigType *entry = new_type_table_entry(TypeTableEntryIdPromise);413 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
414 entry->type_ref = u8_ptr_type->type_ref;414 entry->type_ref = u8_ptr_type->type_ref;
415 entry->zero_bits = false;415 entry->zero_bits = false;
416 entry->data.promise.result_type = result_type;416 entry->data.promise.result_type = result_type;
...@@ -432,13 +432,13 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -432,13 +432,13 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
432 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)
433{433{
434 assert(!type_is_invalid(child_type));434 assert(!type_is_invalid(child_type));
435 assert(ptr_len == PtrLenSingle || child_type->id != TypeTableEntryIdOpaque);435 assert(ptr_len == PtrLenSingle || child_type->id != ZigTypeIdOpaque);
436436
437 TypeId type_id = {};437 TypeId type_id = {};
438 ZigType **parent_pointer = nullptr;438 ZigType **parent_pointer = nullptr;
439 uint32_t abi_alignment = get_abi_alignment(g, child_type);439 uint32_t abi_alignment = get_abi_alignment(g, child_type);
440 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) {
441 type_id.id = TypeTableEntryIdPointer;441 type_id.id = ZigTypeIdPointer;
442 type_id.data.pointer.child_type = child_type;442 type_id.data.pointer.child_type = child_type;
443 type_id.data.pointer.is_const = is_const;443 type_id.data.pointer.is_const = is_const;
444 type_id.data.pointer.is_volatile = is_volatile;444 type_id.data.pointer.is_volatile = is_volatile;
...@@ -461,7 +461,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -461,7 +461,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
461461
462 assertNoError(type_ensure_zero_bits_known(g, child_type));462 assertNoError(type_ensure_zero_bits_known(g, child_type));
463463
464 ZigType *entry = new_type_table_entry(TypeTableEntryIdPointer);464 ZigType *entry = new_type_table_entry(ZigTypeIdPointer);
465 entry->is_copyable = true;465 entry->is_copyable = true;
466466
467 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";467 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
...@@ -478,7 +478,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons...@@ -478,7 +478,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
478 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));
479 }479 }
480480
481 assert(child_type->id != TypeTableEntryIdInvalid);481 assert(child_type->id != ZigTypeIdInvalid);
482482
483 entry->zero_bits = !type_has_bits(child_type);483 entry->zero_bits = !type_has_bits(child_type);
484484
...@@ -568,7 +568,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {...@@ -568,7 +568,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
568 } else {568 } else {
569 assertNoError(ensure_complete_type(g, child_type));569 assertNoError(ensure_complete_type(g, child_type));
570570
571 ZigType *entry = new_type_table_entry(TypeTableEntryIdOptional);571 ZigType *entry = new_type_table_entry(ZigTypeIdOptional);
572 assert(child_type->type_ref || child_type->zero_bits);572 assert(child_type->type_ref || child_type->zero_bits);
573 entry->is_copyable = type_is_copyable(g, child_type).unwrap();573 entry->is_copyable = type_is_copyable(g, child_type).unwrap();
574574
...@@ -646,11 +646,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {...@@ -646,11 +646,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
646}646}
647647
648ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) {648ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) {
649 assert(err_set_type->id == TypeTableEntryIdErrorSet);649 assert(err_set_type->id == ZigTypeIdErrorSet);
650 assert(!type_is_invalid(payload_type));650 assert(!type_is_invalid(payload_type));
651651
652 TypeId type_id = {};652 TypeId type_id = {};
653 type_id.id = TypeTableEntryIdErrorUnion;653 type_id.id = ZigTypeIdErrorUnion;
654 type_id.data.error_union.err_set_type = err_set_type;654 type_id.data.error_union.err_set_type = err_set_type;
655 type_id.data.error_union.payload_type = payload_type;655 type_id.data.error_union.payload_type = payload_type;
656656
...@@ -659,7 +659,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -659,7 +659,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
659 return existing_entry->value;659 return existing_entry->value;
660 }660 }
661661
662 ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorUnion);662 ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion);
663 entry->is_copyable = true;663 entry->is_copyable = true;
664 assert(payload_type->di_type);664 assert(payload_type->di_type);
665 assertNoError(ensure_complete_type(g, payload_type));665 assertNoError(ensure_complete_type(g, payload_type));
...@@ -742,7 +742,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -742,7 +742,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
742742
743ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {743ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {
744 TypeId type_id = {};744 TypeId type_id = {};
745 type_id.id = TypeTableEntryIdArray;745 type_id.id = ZigTypeIdArray;
746 type_id.data.array.child_type = child_type;746 type_id.data.array.child_type = child_type;
747 type_id.data.array.size = array_size;747 type_id.data.array.size = array_size;
748 auto existing_entry = g->type_table.maybe_get(type_id);748 auto existing_entry = g->type_table.maybe_get(type_id);
...@@ -753,7 +753,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {...@@ -753,7 +753,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {
753753
754 assertNoError(ensure_complete_type(g, child_type));754 assertNoError(ensure_complete_type(g, child_type));
755755
756 ZigType *entry = new_type_table_entry(TypeTableEntryIdArray);756 ZigType *entry = new_type_table_entry(ZigTypeIdArray);
757 entry->zero_bits = (array_size == 0) || child_type->zero_bits;757 entry->zero_bits = (array_size == 0) || child_type->zero_bits;
758 entry->is_copyable = false;758 entry->is_copyable = false;
759759
...@@ -812,7 +812,7 @@ static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *e...@@ -812,7 +812,7 @@ static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *e
812}812}
813813
814ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {814ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
815 assert(ptr_type->id == TypeTableEntryIdPointer);815 assert(ptr_type->id == ZigTypeIdPointer);
816 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);816 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);
817817
818 ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent;818 ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent;
...@@ -820,7 +820,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -820,7 +820,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
820 return *parent_pointer;820 return *parent_pointer;
821 }821 }
822822
823 ZigType *entry = new_type_table_entry(TypeTableEntryIdStruct);823 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
824 entry->is_copyable = true;824 entry->is_copyable = true;
825825
826 // 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
...@@ -853,7 +853,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -853,7 +853,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
853 // 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.
854 if (is_slice(child_type)) {854 if (is_slice(child_type)) {
855 ZigType *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;
856 assert(child_ptr_type->id == TypeTableEntryIdPointer);856 assert(child_ptr_type->id == ZigTypeIdPointer);
857 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;857 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
858 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 ||
859 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))
...@@ -972,7 +972,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -972,7 +972,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
972}972}
973973
974ZigType *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) {
975 ZigType *entry = new_type_table_entry(TypeTableEntryIdOpaque);975 ZigType *entry = new_type_table_entry(ZigTypeIdOpaque);
976976
977 buf_init_from_str(&entry->name, name);977 buf_init_from_str(&entry->name, name);
978978
...@@ -993,11 +993,11 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c...@@ -993,11 +993,11 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c
993993
994ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {994ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
995 ZigType *fn_type = fn_entry->type_entry;995 ZigType *fn_type = fn_entry->type_entry;
996 assert(fn_type->id == TypeTableEntryIdFn);996 assert(fn_type->id == ZigTypeIdFn);
997 if (fn_type->data.fn.bound_fn_parent)997 if (fn_type->data.fn.bound_fn_parent)
998 return fn_type->data.fn.bound_fn_parent;998 return fn_type->data.fn.bound_fn_parent;
999999
1000 ZigType *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn);1000 ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn);
1001 bound_fn_type->is_copyable = false;1001 bound_fn_type->is_copyable = false;
1002 bound_fn_type->data.bound_fn.fn_type = fn_type;1002 bound_fn_type->data.bound_fn.fn_type = fn_type;
1003 bound_fn_type->zero_bits = true;1003 bound_fn_type->zero_bits = true;
...@@ -1054,7 +1054,7 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -1054,7 +1054,7 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {
1054ZigType *get_ptr_to_stack_trace_type(CodeGen *g) {1054ZigType *get_ptr_to_stack_trace_type(CodeGen *g) {
1055 if (g->stack_trace_type == nullptr) {1055 if (g->stack_trace_type == nullptr) {
1056 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");1056 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
1057 assert(stack_trace_type_val->type->id == TypeTableEntryIdMetaType);1057 assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
1058 g->stack_trace_type = stack_trace_type_val->data.x_type;1058 g->stack_trace_type = stack_trace_type_val->data.x_type;
1059 g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);1059 g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);
1060 }1060 }
...@@ -1070,12 +1070,12 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1070,12 +1070,12 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1070 if (fn_type_id->return_type != nullptr) {1070 if (fn_type_id->return_type != nullptr) {
1071 if ((err = ensure_complete_type(g, fn_type_id->return_type)))1071 if ((err = ensure_complete_type(g, fn_type_id->return_type)))
1072 return g->builtin_types.entry_invalid;1072 return g->builtin_types.entry_invalid;
1073 assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);1073 assert(fn_type_id->return_type->id != ZigTypeIdOpaque);
1074 } else {1074 } else {
1075 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");1075 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
1076 }1076 }
10771077
1078 ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn);1078 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1079 fn_type->is_copyable = true;1079 fn_type->is_copyable = true;
1080 fn_type->data.fn.fn_type_id = *fn_type_id;1080 fn_type->data.fn.fn_type_id = *fn_type_id;
10811081
...@@ -1222,11 +1222,11 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1222,11 +1222,11 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1222static ZigTypeId container_to_type(ContainerKind kind) {1222static ZigTypeId container_to_type(ContainerKind kind) {
1223 switch (kind) {1223 switch (kind) {
1224 case ContainerKindStruct:1224 case ContainerKindStruct:
1225 return TypeTableEntryIdStruct;1225 return ZigTypeIdStruct;
1226 case ContainerKindEnum:1226 case ContainerKindEnum:
1227 return TypeTableEntryIdEnum;1227 return ZigTypeIdEnum;
1228 case ContainerKindUnion:1228 case ContainerKindUnion:
1229 return TypeTableEntryIdUnion;1229 return ZigTypeIdUnion;
1230 }1230 }
1231 zig_unreachable();1231 zig_unreachable();
1232}1232}
...@@ -1275,7 +1275,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod...@@ -1275,7 +1275,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod
12751275
1276ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {1276ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1277 IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);1277 IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);
1278 if (result->value.type->id == TypeTableEntryIdInvalid)1278 if (result->value.type->id == ZigTypeIdInvalid)
1279 return g->builtin_types.entry_invalid;1279 return g->builtin_types.entry_invalid;
12801280
1281 assert(result->value.special != ConstValSpecialRuntime);1281 assert(result->value.special != ConstValSpecialRuntime);
...@@ -1283,7 +1283,7 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {...@@ -1283,7 +1283,7 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1283}1283}
12841284
1285ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {1285ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1286 ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn);1286 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1287 fn_type->is_copyable = false;1287 fn_type->is_copyable = false;
1288 buf_resize(&fn_type->name, 0);1288 buf_resize(&fn_type->name, 0);
1289 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {1289 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
...@@ -1384,41 +1384,41 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1384,41 +1384,41 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
13841384
1385static bool type_allowed_in_packed_struct(ZigType *type_entry) {1385static bool type_allowed_in_packed_struct(ZigType *type_entry) {
1386 switch (type_entry->id) {1386 switch (type_entry->id) {
1387 case TypeTableEntryIdInvalid:1387 case ZigTypeIdInvalid:
1388 zig_unreachable();1388 zig_unreachable();
1389 case TypeTableEntryIdMetaType:1389 case ZigTypeIdMetaType:
1390 case TypeTableEntryIdUnreachable:1390 case ZigTypeIdUnreachable:
1391 case TypeTableEntryIdComptimeFloat:1391 case ZigTypeIdComptimeFloat:
1392 case TypeTableEntryIdComptimeInt:1392 case ZigTypeIdComptimeInt:
1393 case TypeTableEntryIdUndefined:1393 case ZigTypeIdUndefined:
1394 case TypeTableEntryIdNull:1394 case ZigTypeIdNull:
1395 case TypeTableEntryIdErrorUnion:1395 case ZigTypeIdErrorUnion:
1396 case TypeTableEntryIdErrorSet:1396 case ZigTypeIdErrorSet:
1397 case TypeTableEntryIdNamespace:1397 case ZigTypeIdNamespace:
1398 case TypeTableEntryIdBlock:1398 case ZigTypeIdBlock:
1399 case TypeTableEntryIdBoundFn:1399 case ZigTypeIdBoundFn:
1400 case TypeTableEntryIdArgTuple:1400 case ZigTypeIdArgTuple:
1401 case TypeTableEntryIdOpaque:1401 case ZigTypeIdOpaque:
1402 case TypeTableEntryIdPromise:1402 case ZigTypeIdPromise:
1403 return false;1403 return false;
1404 case TypeTableEntryIdVoid:1404 case ZigTypeIdVoid:
1405 case TypeTableEntryIdBool:1405 case ZigTypeIdBool:
1406 case TypeTableEntryIdInt:1406 case ZigTypeIdInt:
1407 case TypeTableEntryIdFloat:1407 case ZigTypeIdFloat:
1408 case TypeTableEntryIdPointer:1408 case ZigTypeIdPointer:
1409 case TypeTableEntryIdArray:1409 case ZigTypeIdArray:
1410 case TypeTableEntryIdFn:1410 case ZigTypeIdFn:
1411 return true;1411 return true;
1412 case TypeTableEntryIdStruct:1412 case ZigTypeIdStruct:
1413 return type_entry->data.structure.layout == ContainerLayoutPacked;1413 return type_entry->data.structure.layout == ContainerLayoutPacked;
1414 case TypeTableEntryIdUnion:1414 case ZigTypeIdUnion:
1415 return type_entry->data.unionation.layout == ContainerLayoutPacked;1415 return type_entry->data.unionation.layout == ContainerLayoutPacked;
1416 case TypeTableEntryIdOptional:1416 case ZigTypeIdOptional:
1417 {1417 {
1418 ZigType *child_type = type_entry->data.maybe.child_type;1418 ZigType *child_type = type_entry->data.maybe.child_type;
1419 return type_is_codegen_pointer(child_type);1419 return type_is_codegen_pointer(child_type);
1420 }1420 }
1421 case TypeTableEntryIdEnum:1421 case ZigTypeIdEnum:
1422 return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;1422 return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;
1423 }1423 }
1424 zig_unreachable();1424 zig_unreachable();
...@@ -1426,27 +1426,27 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) {...@@ -1426,27 +1426,27 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) {
14261426
1427static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {1427static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
1428 switch (type_entry->id) {1428 switch (type_entry->id) {
1429 case TypeTableEntryIdInvalid:1429 case ZigTypeIdInvalid:
1430 zig_unreachable();1430 zig_unreachable();
1431 case TypeTableEntryIdMetaType:1431 case ZigTypeIdMetaType:
1432 case TypeTableEntryIdComptimeFloat:1432 case ZigTypeIdComptimeFloat:
1433 case TypeTableEntryIdComptimeInt:1433 case ZigTypeIdComptimeInt:
1434 case TypeTableEntryIdUndefined:1434 case ZigTypeIdUndefined:
1435 case TypeTableEntryIdNull:1435 case ZigTypeIdNull:
1436 case TypeTableEntryIdErrorUnion:1436 case ZigTypeIdErrorUnion:
1437 case TypeTableEntryIdErrorSet:1437 case ZigTypeIdErrorSet:
1438 case TypeTableEntryIdNamespace:1438 case ZigTypeIdNamespace:
1439 case TypeTableEntryIdBlock:1439 case ZigTypeIdBlock:
1440 case TypeTableEntryIdBoundFn:1440 case ZigTypeIdBoundFn:
1441 case TypeTableEntryIdArgTuple:1441 case ZigTypeIdArgTuple:
1442 case TypeTableEntryIdPromise:1442 case ZigTypeIdPromise:
1443 case TypeTableEntryIdVoid:1443 case ZigTypeIdVoid:
1444 return false;1444 return false;
1445 case TypeTableEntryIdOpaque:1445 case ZigTypeIdOpaque:
1446 case TypeTableEntryIdUnreachable:1446 case ZigTypeIdUnreachable:
1447 case TypeTableEntryIdBool:1447 case ZigTypeIdBool:
1448 return true;1448 return true;
1449 case TypeTableEntryIdInt:1449 case ZigTypeIdInt:
1450 switch (type_entry->data.integral.bit_count) {1450 switch (type_entry->data.integral.bit_count) {
1451 case 8:1451 case 8:
1452 case 16:1452 case 16:
...@@ -1457,36 +1457,36 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {...@@ -1457,36 +1457,36 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
1457 default:1457 default:
1458 return false;1458 return false;
1459 }1459 }
1460 case TypeTableEntryIdFloat:1460 case ZigTypeIdFloat:
1461 return true;1461 return true;
1462 case TypeTableEntryIdArray:1462 case ZigTypeIdArray:
1463 return type_allowed_in_extern(g, type_entry->data.array.child_type);1463 return type_allowed_in_extern(g, type_entry->data.array.child_type);
1464 case TypeTableEntryIdFn:1464 case ZigTypeIdFn:
1465 return type_entry->data.fn.fn_type_id.cc == CallingConventionC;1465 return type_entry->data.fn.fn_type_id.cc == CallingConventionC;
1466 case TypeTableEntryIdPointer:1466 case ZigTypeIdPointer:
1467 if (type_size(g, type_entry) == 0)1467 if (type_size(g, type_entry) == 0)
1468 return false;1468 return false;
1469 return true;1469 return true;
1470 case TypeTableEntryIdStruct:1470 case ZigTypeIdStruct:
1471 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;1471 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
1472 case TypeTableEntryIdOptional:1472 case ZigTypeIdOptional:
1473 {1473 {
1474 ZigType *child_type = type_entry->data.maybe.child_type;1474 ZigType *child_type = type_entry->data.maybe.child_type;
1475 if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) {1475 if (child_type->id != ZigTypeIdPointer && child_type->id != ZigTypeIdFn) {
1476 return false;1476 return false;
1477 }1477 }
1478 return type_allowed_in_extern(g, child_type);1478 return type_allowed_in_extern(g, child_type);
1479 }1479 }
1480 case TypeTableEntryIdEnum:1480 case ZigTypeIdEnum:
1481 return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;1481 return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;
1482 case TypeTableEntryIdUnion:1482 case ZigTypeIdUnion:
1483 return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;1483 return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;
1484 }1484 }
1485 zig_unreachable();1485 zig_unreachable();
1486}1486}
14871487
1488ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {1488ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1489 ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);1489 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
1490 buf_resize(&err_set_type->name, 0);1490 buf_resize(&err_set_type->name, 0);
1491 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));1491 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
1492 err_set_type->is_copyable = true;1492 err_set_type->is_copyable = true;
...@@ -1581,36 +1581,36 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1581,36 +1581,36 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1581 }1581 }
15821582
1583 switch (type_entry->id) {1583 switch (type_entry->id) {
1584 case TypeTableEntryIdInvalid:1584 case ZigTypeIdInvalid:
1585 zig_unreachable();1585 zig_unreachable();
1586 case TypeTableEntryIdUnreachable:1586 case ZigTypeIdUnreachable:
1587 case TypeTableEntryIdUndefined:1587 case ZigTypeIdUndefined:
1588 case TypeTableEntryIdNull:1588 case ZigTypeIdNull:
1589 case TypeTableEntryIdArgTuple:1589 case ZigTypeIdArgTuple:
1590 case TypeTableEntryIdOpaque:1590 case ZigTypeIdOpaque:
1591 add_node_error(g, param_node->data.param_decl.type,1591 add_node_error(g, param_node->data.param_decl.type,
1592 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));1592 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
1593 return g->builtin_types.entry_invalid;1593 return g->builtin_types.entry_invalid;
1594 case TypeTableEntryIdComptimeFloat:1594 case ZigTypeIdComptimeFloat:
1595 case TypeTableEntryIdComptimeInt:1595 case ZigTypeIdComptimeInt:
1596 case TypeTableEntryIdNamespace:1596 case ZigTypeIdNamespace:
1597 case TypeTableEntryIdBlock:1597 case ZigTypeIdBlock:
1598 case TypeTableEntryIdBoundFn:1598 case ZigTypeIdBoundFn:
1599 case TypeTableEntryIdMetaType:1599 case ZigTypeIdMetaType:
1600 case TypeTableEntryIdVoid:1600 case ZigTypeIdVoid:
1601 case TypeTableEntryIdBool:1601 case ZigTypeIdBool:
1602 case TypeTableEntryIdInt:1602 case ZigTypeIdInt:
1603 case TypeTableEntryIdFloat:1603 case ZigTypeIdFloat:
1604 case TypeTableEntryIdPointer:1604 case ZigTypeIdPointer:
1605 case TypeTableEntryIdArray:1605 case ZigTypeIdArray:
1606 case TypeTableEntryIdStruct:1606 case ZigTypeIdStruct:
1607 case TypeTableEntryIdOptional:1607 case ZigTypeIdOptional:
1608 case TypeTableEntryIdErrorUnion:1608 case ZigTypeIdErrorUnion:
1609 case TypeTableEntryIdErrorSet:1609 case ZigTypeIdErrorSet:
1610 case TypeTableEntryIdEnum:1610 case ZigTypeIdEnum:
1611 case TypeTableEntryIdUnion:1611 case ZigTypeIdUnion:
1612 case TypeTableEntryIdFn:1612 case ZigTypeIdFn:
1613 case TypeTableEntryIdPromise:1613 case ZigTypeIdPromise:
1614 if ((err = type_ensure_zero_bits_known(g, type_entry)))1614 if ((err = type_ensure_zero_bits_known(g, type_entry)))
1615 return g->builtin_types.entry_invalid;1615 return g->builtin_types.entry_invalid;
1616 if (type_requires_comptime(type_entry)) {1616 if (type_requires_comptime(type_entry)) {
...@@ -1659,7 +1659,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1659,7 +1659,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1659 }1659 }
16601660
1661 if (!calling_convention_allows_zig_types(fn_type_id.cc) &&1661 if (!calling_convention_allows_zig_types(fn_type_id.cc) &&
1662 fn_type_id.return_type->id != TypeTableEntryIdVoid &&1662 fn_type_id.return_type->id != ZigTypeIdVoid &&
1663 !type_allowed_in_extern(g, fn_type_id.return_type))1663 !type_allowed_in_extern(g, fn_type_id.return_type))
1664 {1664 {
1665 add_node_error(g, fn_proto->return_type,1665 add_node_error(g, fn_proto->return_type,
...@@ -1670,38 +1670,38 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1670,38 +1670,38 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1670 }1670 }
16711671
1672 switch (fn_type_id.return_type->id) {1672 switch (fn_type_id.return_type->id) {
1673 case TypeTableEntryIdInvalid:1673 case ZigTypeIdInvalid:
1674 zig_unreachable();1674 zig_unreachable();
16751675
1676 case TypeTableEntryIdUndefined:1676 case ZigTypeIdUndefined:
1677 case TypeTableEntryIdNull:1677 case ZigTypeIdNull:
1678 case TypeTableEntryIdArgTuple:1678 case ZigTypeIdArgTuple:
1679 case TypeTableEntryIdOpaque:1679 case ZigTypeIdOpaque:
1680 add_node_error(g, fn_proto->return_type,1680 add_node_error(g, fn_proto->return_type,
1681 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));1681 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
1682 return g->builtin_types.entry_invalid;1682 return g->builtin_types.entry_invalid;
16831683
1684 case TypeTableEntryIdComptimeFloat:1684 case ZigTypeIdComptimeFloat:
1685 case TypeTableEntryIdComptimeInt:1685 case ZigTypeIdComptimeInt:
1686 case TypeTableEntryIdNamespace:1686 case ZigTypeIdNamespace:
1687 case TypeTableEntryIdBlock:1687 case ZigTypeIdBlock:
1688 case TypeTableEntryIdBoundFn:1688 case ZigTypeIdBoundFn:
1689 case TypeTableEntryIdMetaType:1689 case ZigTypeIdMetaType:
1690 case TypeTableEntryIdUnreachable:1690 case ZigTypeIdUnreachable:
1691 case TypeTableEntryIdVoid:1691 case ZigTypeIdVoid:
1692 case TypeTableEntryIdBool:1692 case ZigTypeIdBool:
1693 case TypeTableEntryIdInt:1693 case ZigTypeIdInt:
1694 case TypeTableEntryIdFloat:1694 case ZigTypeIdFloat:
1695 case TypeTableEntryIdPointer:1695 case ZigTypeIdPointer:
1696 case TypeTableEntryIdArray:1696 case ZigTypeIdArray:
1697 case TypeTableEntryIdStruct:1697 case ZigTypeIdStruct:
1698 case TypeTableEntryIdOptional:1698 case ZigTypeIdOptional:
1699 case TypeTableEntryIdErrorUnion:1699 case ZigTypeIdErrorUnion:
1700 case TypeTableEntryIdErrorSet:1700 case ZigTypeIdErrorSet:
1701 case TypeTableEntryIdEnum:1701 case ZigTypeIdEnum:
1702 case TypeTableEntryIdUnion:1702 case ZigTypeIdUnion:
1703 case TypeTableEntryIdFn:1703 case ZigTypeIdFn:
1704 case TypeTableEntryIdPromise:1704 case ZigTypeIdPromise:
1705 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))1705 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
1706 return g->builtin_types.entry_invalid;1706 return g->builtin_types.entry_invalid;
1707 if (type_requires_comptime(fn_type_id.return_type)) {1707 if (type_requires_comptime(fn_type_id.return_type)) {
...@@ -1725,13 +1725,13 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1725,13 +1725,13 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17251725
1726bool type_is_invalid(ZigType *type_entry) {1726bool type_is_invalid(ZigType *type_entry) {
1727 switch (type_entry->id) {1727 switch (type_entry->id) {
1728 case TypeTableEntryIdInvalid:1728 case ZigTypeIdInvalid:
1729 return true;1729 return true;
1730 case TypeTableEntryIdStruct:1730 case ZigTypeIdStruct:
1731 return type_entry->data.structure.is_invalid;1731 return type_entry->data.structure.is_invalid;
1732 case TypeTableEntryIdEnum:1732 case ZigTypeIdEnum:
1733 return type_entry->data.enumeration.is_invalid;1733 return type_entry->data.enumeration.is_invalid;
1734 case TypeTableEntryIdUnion:1734 case ZigTypeIdUnion:
1735 return type_entry->data.unionation.is_invalid;1735 return type_entry->data.unionation.is_invalid;
1736 default:1736 default:
1737 return false;1737 return false;
...@@ -1741,7 +1741,7 @@ bool type_is_invalid(ZigType *type_entry) {...@@ -1741,7 +1741,7 @@ bool type_is_invalid(ZigType *type_entry) {
17411741
17421742
1743static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {1743static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1744 assert(enum_type->id == TypeTableEntryIdEnum);1744 assert(enum_type->id == ZigTypeIdEnum);
17451745
1746 if (enum_type->data.enumeration.is_invalid)1746 if (enum_type->data.enumeration.is_invalid)
1747 return ErrorSemanticAnalyzeFail;1747 return ErrorSemanticAnalyzeFail;
...@@ -1837,7 +1837,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {...@@ -1837,7 +1837,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
1837ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],1837ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
1838 ZigType *field_types[], size_t field_count)1838 ZigType *field_types[], size_t field_count)
1839{1839{
1840 ZigType *struct_type = new_type_table_entry(TypeTableEntryIdStruct);1840 ZigType *struct_type = new_type_table_entry(ZigTypeIdStruct);
18411841
1842 buf_init_from_str(&struct_type->name, type_name);1842 buf_init_from_str(&struct_type->name, type_name);
18431843
...@@ -1914,7 +1914,7 @@ ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_na...@@ -1914,7 +1914,7 @@ ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_na
1914}1914}
19151915
1916static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {1916static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1917 assert(struct_type->id == TypeTableEntryIdStruct);1917 assert(struct_type->id == ZigTypeIdStruct);
19181918
1919 if (struct_type->data.structure.complete)1919 if (struct_type->data.structure.complete)
1920 return ErrorNone;1920 return ErrorNone;
...@@ -2092,7 +2092,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2092,7 +2092,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
20922092
2093 // if the field is a function, actually the debug info should be a pointer.2093 // if the field is a function, actually the debug info should be a pointer.
2094 ZigLLVMDIType *field_di_type;2094 ZigLLVMDIType *field_di_type;
2095 if (field_type->id == TypeTableEntryIdFn) {2095 if (field_type->id == ZigTypeIdFn) {
2096 ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true);2096 ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true);
2097 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);2097 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);
2098 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);2098 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);
...@@ -2148,7 +2148,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2148,7 +2148,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2148}2148}
21492149
2150static Error resolve_union_type(CodeGen *g, ZigType *union_type) {2150static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2151 assert(union_type->id == TypeTableEntryIdUnion);2151 assert(union_type->id == ZigTypeIdUnion);
21522152
2153 if (union_type->data.unionation.complete)2153 if (union_type->data.unionation.complete)
2154 return ErrorNone;2154 return ErrorNone;
...@@ -2388,7 +2388,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2388,7 +2388,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2388}2388}
23892389
2390static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {2390static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2391 assert(enum_type->id == TypeTableEntryIdEnum);2391 assert(enum_type->id == ZigTypeIdEnum);
23922392
2393 if (enum_type->data.enumeration.zero_bits_known)2393 if (enum_type->data.enumeration.zero_bits_known)
2394 return ErrorNone;2394 return ErrorNone;
...@@ -2440,7 +2440,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2440,7 +2440,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2440 ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);2440 ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
2441 if (type_is_invalid(wanted_tag_int_type)) {2441 if (type_is_invalid(wanted_tag_int_type)) {
2442 enum_type->data.enumeration.is_invalid = true;2442 enum_type->data.enumeration.is_invalid = true;
2443 } else if (wanted_tag_int_type->id != TypeTableEntryIdInt) {2443 } else if (wanted_tag_int_type->id != ZigTypeIdInt) {
2444 enum_type->data.enumeration.is_invalid = true;2444 enum_type->data.enumeration.is_invalid = true;
2445 add_node_error(g, decl_node->data.container_decl.init_arg_expr,2445 add_node_error(g, decl_node->data.container_decl.init_arg_expr,
2446 buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name)));2446 buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name)));
...@@ -2489,12 +2489,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2489,12 +2489,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2489 // In a second pass we will fill in the unspecified ones.2489 // In a second pass we will fill in the unspecified ones.
2490 if (tag_value != nullptr) {2490 if (tag_value != nullptr) {
2491 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2491 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
2492 if (result_inst->value.type->id == TypeTableEntryIdInvalid) {2492 if (result_inst->value.type->id == ZigTypeIdInvalid) {
2493 enum_type->data.enumeration.is_invalid = true;2493 enum_type->data.enumeration.is_invalid = true;
2494 continue;2494 continue;
2495 }2495 }
2496 assert(result_inst->value.special != ConstValSpecialRuntime);2496 assert(result_inst->value.special != ConstValSpecialRuntime);
2497 assert(result_inst->value.type->id == TypeTableEntryIdInt);2497 assert(result_inst->value.type->id == ZigTypeIdInt);
2498 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);2498 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
2499 if (entry == nullptr) {2499 if (entry == nullptr) {
2500 bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint);2500 bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint);
...@@ -2551,7 +2551,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2551,7 +2551,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2551}2551}
25522552
2553static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {2553static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2554 assert(struct_type->id == TypeTableEntryIdStruct);2554 assert(struct_type->id == ZigTypeIdStruct);
25552555
2556 Error err;2556 Error err;
25572557
...@@ -2670,7 +2670,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2670,7 +2670,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2670}2670}
26712671
2672static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {2672static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2673 assert(union_type->id == TypeTableEntryIdUnion);2673 assert(union_type->id == ZigTypeIdUnion);
26742674
2675 Error err;2675 Error err;
26762676
...@@ -2751,7 +2751,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2751,7 +2751,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2751 union_type->data.unionation.is_invalid = true;2751 union_type->data.unionation.is_invalid = true;
2752 return ErrorSemanticAnalyzeFail;2752 return ErrorSemanticAnalyzeFail;
2753 }2753 }
2754 if (tag_int_type->id != TypeTableEntryIdInt) {2754 if (tag_int_type->id != ZigTypeIdInt) {
2755 add_node_error(g, enum_type_node,2755 add_node_error(g, enum_type_node,
2756 buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));2756 buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));
2757 union_type->data.unionation.is_invalid = true;2757 union_type->data.unionation.is_invalid = true;
...@@ -2762,7 +2762,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2762,7 +2762,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2762 }2762 }
2763 abi_alignment_so_far = get_abi_alignment(g, tag_int_type);2763 abi_alignment_so_far = get_abi_alignment(g, tag_int_type);
27642764
2765 tag_type = new_type_table_entry(TypeTableEntryIdEnum);2765 tag_type = new_type_table_entry(ZigTypeIdEnum);
2766 buf_resize(&tag_type->name, 0);2766 buf_resize(&tag_type->name, 0);
2767 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));2767 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));
2768 tag_type->is_copyable = true;2768 tag_type->is_copyable = true;
...@@ -2784,7 +2784,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2784,7 +2784,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2784 union_type->data.unionation.is_invalid = true;2784 union_type->data.unionation.is_invalid = true;
2785 return ErrorSemanticAnalyzeFail;2785 return ErrorSemanticAnalyzeFail;
2786 }2786 }
2787 if (enum_type->id != TypeTableEntryIdEnum) {2787 if (enum_type->id != ZigTypeIdEnum) {
2788 union_type->data.unionation.is_invalid = true;2788 union_type->data.unionation.is_invalid = true;
2789 add_node_error(g, enum_type_node,2789 add_node_error(g, enum_type_node,
2790 buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name)));2790 buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name)));
...@@ -2862,12 +2862,12 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2862,12 +2862,12 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2862 if (tag_value != nullptr) {2862 if (tag_value != nullptr) {
2863 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;2863 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
2864 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2864 IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
2865 if (result_inst->value.type->id == TypeTableEntryIdInvalid) {2865 if (result_inst->value.type->id == ZigTypeIdInvalid) {
2866 union_type->data.unionation.is_invalid = true;2866 union_type->data.unionation.is_invalid = true;
2867 continue;2867 continue;
2868 }2868 }
2869 assert(result_inst->value.special != ConstValSpecialRuntime);2869 assert(result_inst->value.special != ConstValSpecialRuntime);
2870 assert(result_inst->value.type->id == TypeTableEntryIdInt);2870 assert(result_inst->value.type->id == ZigTypeIdInt);
2871 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);2871 auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
2872 if (entry == nullptr) {2872 if (entry == nullptr) {
2873 bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint);2873 bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint);
...@@ -3192,7 +3192,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3192,7 +3192,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3192 }3192 }
3193 }3193 }
31943194
3195 if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {3195 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
3196 tld_fn->base.resolution = TldResolutionInvalid;3196 tld_fn->base.resolution = TldResolutionInvalid;
3197 return;3197 return;
3198 }3198 }
...@@ -3448,13 +3448,13 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {...@@ -3448,13 +3448,13 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
3448 assert(type_entry);3448 assert(type_entry);
34493449
3450 switch (type_entry->id) {3450 switch (type_entry->id) {
3451 case TypeTableEntryIdStruct:3451 case ZigTypeIdStruct:
3452 resolve_struct_type(g, tld_container->type_entry);3452 resolve_struct_type(g, tld_container->type_entry);
3453 return;3453 return;
3454 case TypeTableEntryIdEnum:3454 case ZigTypeIdEnum:
3455 resolve_enum_type(g, tld_container->type_entry);3455 resolve_enum_type(g, tld_container->type_entry);
3456 return;3456 return;
3457 case TypeTableEntryIdUnion:3457 case ZigTypeIdUnion:
3458 resolve_union_type(g, tld_container->type_entry);3458 resolve_union_type(g, tld_container->type_entry);
3459 return;3459 return;
3460 default:3460 default:
...@@ -3464,36 +3464,36 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {...@@ -3464,36 +3464,36 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
34643464
3465ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) {3465ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) {
3466 switch (type_entry->id) {3466 switch (type_entry->id) {
3467 case TypeTableEntryIdInvalid:3467 case ZigTypeIdInvalid:
3468 return g->builtin_types.entry_invalid;3468 return g->builtin_types.entry_invalid;
3469 case TypeTableEntryIdUnreachable:3469 case ZigTypeIdUnreachable:
3470 case TypeTableEntryIdUndefined:3470 case ZigTypeIdUndefined:
3471 case TypeTableEntryIdNull:3471 case ZigTypeIdNull:
3472 case TypeTableEntryIdBlock:3472 case ZigTypeIdBlock:
3473 case TypeTableEntryIdArgTuple:3473 case ZigTypeIdArgTuple:
3474 case TypeTableEntryIdOpaque:3474 case ZigTypeIdOpaque:
3475 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",3475 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
3476 buf_ptr(&type_entry->name)));3476 buf_ptr(&type_entry->name)));
3477 return g->builtin_types.entry_invalid;3477 return g->builtin_types.entry_invalid;
3478 case TypeTableEntryIdComptimeFloat:3478 case ZigTypeIdComptimeFloat:
3479 case TypeTableEntryIdComptimeInt:3479 case ZigTypeIdComptimeInt:
3480 case TypeTableEntryIdNamespace:3480 case ZigTypeIdNamespace:
3481 case TypeTableEntryIdMetaType:3481 case ZigTypeIdMetaType:
3482 case TypeTableEntryIdVoid:3482 case ZigTypeIdVoid:
3483 case TypeTableEntryIdBool:3483 case ZigTypeIdBool:
3484 case TypeTableEntryIdInt:3484 case ZigTypeIdInt:
3485 case TypeTableEntryIdFloat:3485 case ZigTypeIdFloat:
3486 case TypeTableEntryIdPointer:3486 case ZigTypeIdPointer:
3487 case TypeTableEntryIdArray:3487 case ZigTypeIdArray:
3488 case TypeTableEntryIdStruct:3488 case ZigTypeIdStruct:
3489 case TypeTableEntryIdOptional:3489 case ZigTypeIdOptional:
3490 case TypeTableEntryIdErrorUnion:3490 case ZigTypeIdErrorUnion:
3491 case TypeTableEntryIdErrorSet:3491 case ZigTypeIdErrorSet:
3492 case TypeTableEntryIdEnum:3492 case ZigTypeIdEnum:
3493 case TypeTableEntryIdUnion:3493 case ZigTypeIdUnion:
3494 case TypeTableEntryIdFn:3494 case ZigTypeIdFn:
3495 case TypeTableEntryIdBoundFn:3495 case ZigTypeIdBoundFn:
3496 case TypeTableEntryIdPromise:3496 case ZigTypeIdPromise:
3497 return type_entry;3497 return type_entry;
3498 }3498 }
3499 zig_unreachable();3499 zig_unreachable();
...@@ -3598,30 +3598,30 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {...@@ -3598,30 +3598,30 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
35983598
3599 // TODO more validation for types that can't be used for export/extern variables3599 // TODO more validation for types that can't be used for export/extern variables
3600 ZigType *implicit_type = nullptr;3600 ZigType *implicit_type = nullptr;
3601 if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) {3601 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {
3602 implicit_type = explicit_type;3602 implicit_type = explicit_type;
3603 } else if (var_decl->expr) {3603 } else if (var_decl->expr) {
3604 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);3604 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);
3605 assert(init_value);3605 assert(init_value);
3606 implicit_type = init_value->value.type;3606 implicit_type = init_value->value.type;
36073607
3608 if (implicit_type->id == TypeTableEntryIdUnreachable) {3608 if (implicit_type->id == ZigTypeIdUnreachable) {
3609 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));3609 add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
3610 implicit_type = g->builtin_types.entry_invalid;3610 implicit_type = g->builtin_types.entry_invalid;
3611 } else if ((!is_const || linkage == VarLinkageExternal) &&3611 } else if ((!is_const || linkage == VarLinkageExternal) &&
3612 (implicit_type->id == TypeTableEntryIdComptimeFloat ||3612 (implicit_type->id == ZigTypeIdComptimeFloat ||
3613 implicit_type->id == TypeTableEntryIdComptimeInt))3613 implicit_type->id == ZigTypeIdComptimeInt))
3614 {3614 {
3615 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));3615 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
3616 implicit_type = g->builtin_types.entry_invalid;3616 implicit_type = g->builtin_types.entry_invalid;
3617 } else if (implicit_type->id == TypeTableEntryIdNull) {3617 } else if (implicit_type->id == ZigTypeIdNull) {
3618 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));3618 add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
3619 implicit_type = g->builtin_types.entry_invalid;3619 implicit_type = g->builtin_types.entry_invalid;
3620 } else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) {3620 } else if (implicit_type->id == ZigTypeIdMetaType && !is_const) {
3621 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));3621 add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));
3622 implicit_type = g->builtin_types.entry_invalid;3622 implicit_type = g->builtin_types.entry_invalid;
3623 }3623 }
3624 assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime);3624 assert(implicit_type->id == ZigTypeIdInvalid || init_value->value.special != ConstValSpecialRuntime);
3625 } else if (linkage != VarLinkageExternal) {3625 } else if (linkage != VarLinkageExternal) {
3626 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));3626 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
3627 implicit_type = g->builtin_types.entry_invalid;3627 implicit_type = g->builtin_types.entry_invalid;
...@@ -3790,7 +3790,7 @@ ZigFn *scope_get_fn_if_root(Scope *scope) {...@@ -3790,7 +3790,7 @@ ZigFn *scope_get_fn_if_root(Scope *scope) {
3790}3790}
37913791
3792TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {3792TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
3793 assert(enum_type->id == TypeTableEntryIdEnum);3793 assert(enum_type->id == ZigTypeIdEnum);
3794 if (enum_type->data.enumeration.src_field_count == 0)3794 if (enum_type->data.enumeration.src_field_count == 0)
3795 return nullptr;3795 return nullptr;
3796 auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);3796 auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);
...@@ -3800,7 +3800,7 @@ TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {...@@ -3800,7 +3800,7 @@ TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
3800}3800}
38013801
3802TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {3802TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {
3803 assert(type_entry->id == TypeTableEntryIdStruct);3803 assert(type_entry->id == ZigTypeIdStruct);
3804 assert(type_entry->data.structure.complete);3804 assert(type_entry->data.structure.complete);
3805 if (type_entry->data.structure.src_field_count == 0)3805 if (type_entry->data.structure.src_field_count == 0)
3806 return nullptr;3806 return nullptr;
...@@ -3811,7 +3811,7 @@ TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {...@@ -3811,7 +3811,7 @@ TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {
3811}3811}
38123812
3813TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {3813TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {
3814 assert(type_entry->id == TypeTableEntryIdUnion);3814 assert(type_entry->id == ZigTypeIdUnion);
3815 assert(type_entry->data.unionation.zero_bits_known);3815 assert(type_entry->data.unionation.zero_bits_known);
3816 if (type_entry->data.unionation.src_field_count == 0)3816 if (type_entry->data.unionation.src_field_count == 0)
3817 return nullptr;3817 return nullptr;
...@@ -3822,7 +3822,7 @@ TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {...@@ -3822,7 +3822,7 @@ TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {
3822}3822}
38233823
3824TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) {3824TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) {
3825 assert(type_entry->id == TypeTableEntryIdUnion);3825 assert(type_entry->id == ZigTypeIdUnion);
3826 assert(type_entry->data.unionation.zero_bits_known);3826 assert(type_entry->data.unionation.zero_bits_known);
3827 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {3827 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
3828 TypeUnionField *field = &type_entry->data.unionation.fields[i];3828 TypeUnionField *field = &type_entry->data.unionation.fields[i];
...@@ -3847,47 +3847,47 @@ TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) {...@@ -3847,47 +3847,47 @@ TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) {
38473847
3848static bool is_container(ZigType *type_entry) {3848static bool is_container(ZigType *type_entry) {
3849 switch (type_entry->id) {3849 switch (type_entry->id) {
3850 case TypeTableEntryIdInvalid:3850 case ZigTypeIdInvalid:
3851 zig_unreachable();3851 zig_unreachable();
3852 case TypeTableEntryIdStruct:3852 case ZigTypeIdStruct:
3853 case TypeTableEntryIdEnum:3853 case ZigTypeIdEnum:
3854 case TypeTableEntryIdUnion:3854 case ZigTypeIdUnion:
3855 return true;3855 return true;
3856 case TypeTableEntryIdPointer:3856 case ZigTypeIdPointer:
3857 case TypeTableEntryIdMetaType:3857 case ZigTypeIdMetaType:
3858 case TypeTableEntryIdVoid:3858 case ZigTypeIdVoid:
3859 case TypeTableEntryIdBool:3859 case ZigTypeIdBool:
3860 case TypeTableEntryIdUnreachable:3860 case ZigTypeIdUnreachable:
3861 case TypeTableEntryIdInt:3861 case ZigTypeIdInt:
3862 case TypeTableEntryIdFloat:3862 case ZigTypeIdFloat:
3863 case TypeTableEntryIdArray:3863 case ZigTypeIdArray:
3864 case TypeTableEntryIdComptimeFloat:3864 case ZigTypeIdComptimeFloat:
3865 case TypeTableEntryIdComptimeInt:3865 case ZigTypeIdComptimeInt:
3866 case TypeTableEntryIdUndefined:3866 case ZigTypeIdUndefined:
3867 case TypeTableEntryIdNull:3867 case ZigTypeIdNull:
3868 case TypeTableEntryIdOptional:3868 case ZigTypeIdOptional:
3869 case TypeTableEntryIdErrorUnion:3869 case ZigTypeIdErrorUnion:
3870 case TypeTableEntryIdErrorSet:3870 case ZigTypeIdErrorSet:
3871 case TypeTableEntryIdFn:3871 case ZigTypeIdFn:
3872 case TypeTableEntryIdNamespace:3872 case ZigTypeIdNamespace:
3873 case TypeTableEntryIdBlock:3873 case ZigTypeIdBlock:
3874 case TypeTableEntryIdBoundFn:3874 case ZigTypeIdBoundFn:
3875 case TypeTableEntryIdArgTuple:3875 case ZigTypeIdArgTuple:
3876 case TypeTableEntryIdOpaque:3876 case ZigTypeIdOpaque:
3877 case TypeTableEntryIdPromise:3877 case ZigTypeIdPromise:
3878 return false;3878 return false;
3879 }3879 }
3880 zig_unreachable();3880 zig_unreachable();
3881}3881}
38823882
3883bool is_ref(ZigType *type_entry) {3883bool is_ref(ZigType *type_entry) {
3884 return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;3884 return type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
3885}3885}
38863886
3887bool is_array_ref(ZigType *type_entry) {3887bool is_array_ref(ZigType *type_entry) {
3888 ZigType *array = is_ref(type_entry) ?3888 ZigType *array = is_ref(type_entry) ?
3889 type_entry->data.pointer.child_type : type_entry;3889 type_entry->data.pointer.child_type : type_entry;
3890 return array->id == TypeTableEntryIdArray;3890 return array->id == ZigTypeIdArray;
3891}3891}
38923892
3893bool is_container_ref(ZigType *type_entry) {3893bool is_container_ref(ZigType *type_entry) {
...@@ -3903,50 +3903,50 @@ ZigType *container_ref_type(ZigType *type_entry) {...@@ -3903,50 +3903,50 @@ ZigType *container_ref_type(ZigType *type_entry) {
39033903
3904void resolve_container_type(CodeGen *g, ZigType *type_entry) {3904void resolve_container_type(CodeGen *g, ZigType *type_entry) {
3905 switch (type_entry->id) {3905 switch (type_entry->id) {
3906 case TypeTableEntryIdStruct:3906 case ZigTypeIdStruct:
3907 resolve_struct_type(g, type_entry);3907 resolve_struct_type(g, type_entry);
3908 break;3908 break;
3909 case TypeTableEntryIdEnum:3909 case ZigTypeIdEnum:
3910 resolve_enum_type(g, type_entry);3910 resolve_enum_type(g, type_entry);
3911 break;3911 break;
3912 case TypeTableEntryIdUnion:3912 case ZigTypeIdUnion:
3913 resolve_union_type(g, type_entry);3913 resolve_union_type(g, type_entry);
3914 break;3914 break;
3915 case TypeTableEntryIdPointer:3915 case ZigTypeIdPointer:
3916 case TypeTableEntryIdMetaType:3916 case ZigTypeIdMetaType:
3917 case TypeTableEntryIdVoid:3917 case ZigTypeIdVoid:
3918 case TypeTableEntryIdBool:3918 case ZigTypeIdBool:
3919 case TypeTableEntryIdUnreachable:3919 case ZigTypeIdUnreachable:
3920 case TypeTableEntryIdInt:3920 case ZigTypeIdInt:
3921 case TypeTableEntryIdFloat:3921 case ZigTypeIdFloat:
3922 case TypeTableEntryIdArray:3922 case ZigTypeIdArray:
3923 case TypeTableEntryIdComptimeFloat:3923 case ZigTypeIdComptimeFloat:
3924 case TypeTableEntryIdComptimeInt:3924 case ZigTypeIdComptimeInt:
3925 case TypeTableEntryIdUndefined:3925 case ZigTypeIdUndefined:
3926 case TypeTableEntryIdNull:3926 case ZigTypeIdNull:
3927 case TypeTableEntryIdOptional:3927 case ZigTypeIdOptional:
3928 case TypeTableEntryIdErrorUnion:3928 case ZigTypeIdErrorUnion:
3929 case TypeTableEntryIdErrorSet:3929 case ZigTypeIdErrorSet:
3930 case TypeTableEntryIdFn:3930 case ZigTypeIdFn:
3931 case TypeTableEntryIdNamespace:3931 case ZigTypeIdNamespace:
3932 case TypeTableEntryIdBlock:3932 case ZigTypeIdBlock:
3933 case TypeTableEntryIdBoundFn:3933 case ZigTypeIdBoundFn:
3934 case TypeTableEntryIdInvalid:3934 case ZigTypeIdInvalid:
3935 case TypeTableEntryIdArgTuple:3935 case ZigTypeIdArgTuple:
3936 case TypeTableEntryIdOpaque:3936 case ZigTypeIdOpaque:
3937 case TypeTableEntryIdPromise:3937 case ZigTypeIdPromise:
3938 zig_unreachable();3938 zig_unreachable();
3939 }3939 }
3940}3940}
39413941
3942ZigType *get_codegen_ptr_type(ZigType *type) {3942ZigType *get_codegen_ptr_type(ZigType *type) {
3943 if (type->id == TypeTableEntryIdPointer) return type;3943 if (type->id == ZigTypeIdPointer) return type;
3944 if (type->id == TypeTableEntryIdFn) return type;3944 if (type->id == ZigTypeIdFn) return type;
3945 if (type->id == TypeTableEntryIdPromise) return type;3945 if (type->id == ZigTypeIdPromise) return type;
3946 if (type->id == TypeTableEntryIdOptional) {3946 if (type->id == ZigTypeIdOptional) {
3947 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;3947 if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type;
3948 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;3948 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
3949 if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;3949 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
3950 }3950 }
3951 return nullptr;3951 return nullptr;
3952}3952}
...@@ -3957,11 +3957,11 @@ bool type_is_codegen_pointer(ZigType *type) {...@@ -3957,11 +3957,11 @@ bool type_is_codegen_pointer(ZigType *type) {
39573957
3958uint32_t get_ptr_align(ZigType *type) {3958uint32_t get_ptr_align(ZigType *type) {
3959 ZigType *ptr_type = get_codegen_ptr_type(type);3959 ZigType *ptr_type = get_codegen_ptr_type(type);
3960 if (ptr_type->id == TypeTableEntryIdPointer) {3960 if (ptr_type->id == ZigTypeIdPointer) {
3961 return ptr_type->data.pointer.alignment;3961 return ptr_type->data.pointer.alignment;
3962 } else if (ptr_type->id == TypeTableEntryIdFn) {3962 } else if (ptr_type->id == ZigTypeIdFn) {
3963 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;3963 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
3964 } else if (ptr_type->id == TypeTableEntryIdPromise) {3964 } else if (ptr_type->id == ZigTypeIdPromise) {
3965 return 1;3965 return 1;
3966 } else {3966 } else {
3967 zig_unreachable();3967 zig_unreachable();
...@@ -3970,11 +3970,11 @@ uint32_t get_ptr_align(ZigType *type) {...@@ -3970,11 +3970,11 @@ uint32_t get_ptr_align(ZigType *type) {
39703970
3971bool get_ptr_const(ZigType *type) {3971bool get_ptr_const(ZigType *type) {
3972 ZigType *ptr_type = get_codegen_ptr_type(type);3972 ZigType *ptr_type = get_codegen_ptr_type(type);
3973 if (ptr_type->id == TypeTableEntryIdPointer) {3973 if (ptr_type->id == ZigTypeIdPointer) {
3974 return ptr_type->data.pointer.is_const;3974 return ptr_type->data.pointer.is_const;
3975 } else if (ptr_type->id == TypeTableEntryIdFn) {3975 } else if (ptr_type->id == ZigTypeIdFn) {
3976 return true;3976 return true;
3977 } else if (ptr_type->id == TypeTableEntryIdPromise) {3977 } else if (ptr_type->id == ZigTypeIdPromise) {
3978 return true;3978 return true;
3979 } else {3979 } else {
3980 zig_unreachable();3980 zig_unreachable();
...@@ -4067,13 +4067,13 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node)...@@ -4067,13 +4067,13 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node)
4067 return;4067 return;
4068 }4068 }
40694069
4070 if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) {4070 if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {
4071 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;4071 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
4072 if (return_err_set_type->data.error_set.infer_fn != nullptr) {4072 if (return_err_set_type->data.error_set.infer_fn != nullptr) {
4073 ZigType *inferred_err_set_type;4073 ZigType *inferred_err_set_type;
4074 if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) {4074 if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorSet) {
4075 inferred_err_set_type = fn_table_entry->src_implicit_return_type;4075 inferred_err_set_type = fn_table_entry->src_implicit_return_type;
4076 } else if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorUnion) {4076 } else if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorUnion) {
4077 inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;4077 inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;
4078 } else {4078 } else {
4079 add_node_error(g, return_type_node,4079 add_node_error(g, return_type_node,
...@@ -4154,7 +4154,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -4154,7 +4154,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
4154 }4154 }
41554155
4156 IrInstruction *use_target_value = src_use_node->data.use.value;4156 IrInstruction *use_target_value = src_use_node->data.use.value;
4157 if (use_target_value->value.type->id == TypeTableEntryIdInvalid) {4157 if (use_target_value->value.type->id == ZigTypeIdInvalid) {
4158 dst_use_node->owner->any_imports_failed = true;4158 dst_use_node->owner->any_imports_failed = true;
4159 return;4159 return;
4160 }4160 }
...@@ -4230,7 +4230,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {...@@ -4230,7 +4230,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
4230 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,4230 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
4231 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);4231 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
42324232
4233 if (result->value.type->id == TypeTableEntryIdInvalid)4233 if (result->value.type->id == ZigTypeIdInvalid)
4234 node->owner->any_imports_failed = true;4234 node->owner->any_imports_failed = true;
42354235
4236 node->data.use.value = result;4236 node->data.use.value = result;
...@@ -4357,7 +4357,7 @@ void semantic_analyze(CodeGen *g) {...@@ -4357,7 +4357,7 @@ void semantic_analyze(CodeGen *g) {
43574357
4358ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {4358ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
4359 TypeId type_id = {};4359 TypeId type_id = {};
4360 type_id.id = TypeTableEntryIdInt;4360 type_id.id = ZigTypeIdInt;
4361 type_id.data.integer.is_signed = is_signed;4361 type_id.data.integer.is_signed = is_signed;
4362 type_id.data.integer.bit_count = size_in_bits;4362 type_id.data.integer.bit_count = size_in_bits;
43634363
...@@ -4382,38 +4382,38 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {...@@ -4382,38 +4382,38 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
43824382
4383bool handle_is_ptr(ZigType *type_entry) {4383bool handle_is_ptr(ZigType *type_entry) {
4384 switch (type_entry->id) {4384 switch (type_entry->id) {
4385 case TypeTableEntryIdInvalid:4385 case ZigTypeIdInvalid:
4386 case TypeTableEntryIdMetaType:4386 case ZigTypeIdMetaType:
4387 case TypeTableEntryIdComptimeFloat:4387 case ZigTypeIdComptimeFloat:
4388 case TypeTableEntryIdComptimeInt:4388 case ZigTypeIdComptimeInt:
4389 case TypeTableEntryIdUndefined:4389 case ZigTypeIdUndefined:
4390 case TypeTableEntryIdNull:4390 case ZigTypeIdNull:
4391 case TypeTableEntryIdNamespace:4391 case ZigTypeIdNamespace:
4392 case TypeTableEntryIdBlock:4392 case ZigTypeIdBlock:
4393 case TypeTableEntryIdBoundFn:4393 case ZigTypeIdBoundFn:
4394 case TypeTableEntryIdArgTuple:4394 case ZigTypeIdArgTuple:
4395 case TypeTableEntryIdOpaque:4395 case ZigTypeIdOpaque:
4396 zig_unreachable();4396 zig_unreachable();
4397 case TypeTableEntryIdUnreachable:4397 case ZigTypeIdUnreachable:
4398 case TypeTableEntryIdVoid:4398 case ZigTypeIdVoid:
4399 case TypeTableEntryIdBool:4399 case ZigTypeIdBool:
4400 case TypeTableEntryIdInt:4400 case ZigTypeIdInt:
4401 case TypeTableEntryIdFloat:4401 case ZigTypeIdFloat:
4402 case TypeTableEntryIdPointer:4402 case ZigTypeIdPointer:
4403 case TypeTableEntryIdErrorSet:4403 case ZigTypeIdErrorSet:
4404 case TypeTableEntryIdFn:4404 case ZigTypeIdFn:
4405 case TypeTableEntryIdEnum:4405 case ZigTypeIdEnum:
4406 case TypeTableEntryIdPromise:4406 case ZigTypeIdPromise:
4407 return false;4407 return false;
4408 case TypeTableEntryIdArray:4408 case ZigTypeIdArray:
4409 case TypeTableEntryIdStruct:4409 case ZigTypeIdStruct:
4410 return type_has_bits(type_entry);4410 return type_has_bits(type_entry);
4411 case TypeTableEntryIdErrorUnion:4411 case ZigTypeIdErrorUnion:
4412 return type_has_bits(type_entry->data.error_union.payload_type);4412 return type_has_bits(type_entry->data.error_union.payload_type);
4413 case TypeTableEntryIdOptional:4413 case ZigTypeIdOptional:
4414 return type_has_bits(type_entry->data.maybe.child_type) &&4414 return type_has_bits(type_entry->data.maybe.child_type) &&
4415 !type_is_codegen_pointer(type_entry->data.maybe.child_type);4415 !type_is_codegen_pointer(type_entry->data.maybe.child_type);
4416 case TypeTableEntryIdUnion:4416 case ZigTypeIdUnion:
4417 assert(type_entry->data.unionation.complete);4417 assert(type_entry->data.unionation.complete);
4418 if (type_entry->data.unionation.gen_field_count == 0)4418 if (type_entry->data.unionation.gen_field_count == 0)
4419 return false;4419 return false;
...@@ -4697,16 +4697,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {...@@ -4697,16 +4697,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
4697static uint32_t hash_const_val(ConstExprValue *const_val) {4697static uint32_t hash_const_val(ConstExprValue *const_val) {
4698 assert(const_val->special == ConstValSpecialStatic);4698 assert(const_val->special == ConstValSpecialStatic);
4699 switch (const_val->type->id) {4699 switch (const_val->type->id) {
4700 case TypeTableEntryIdOpaque:4700 case ZigTypeIdOpaque:
4701 zig_unreachable();4701 zig_unreachable();
4702 case TypeTableEntryIdBool:4702 case ZigTypeIdBool:
4703 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;4703 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
4704 case TypeTableEntryIdMetaType:4704 case ZigTypeIdMetaType:
4705 return hash_ptr(const_val->data.x_type);4705 return hash_ptr(const_val->data.x_type);
4706 case TypeTableEntryIdVoid:4706 case ZigTypeIdVoid:
4707 return (uint32_t)4149439618;4707 return (uint32_t)4149439618;
4708 case TypeTableEntryIdInt:4708 case ZigTypeIdInt:
4709 case TypeTableEntryIdComptimeInt:4709 case ZigTypeIdComptimeInt:
4710 {4710 {
4711 uint32_t result = 1331471175;4711 uint32_t result = 1331471175;
4712 for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {4712 for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {
...@@ -4715,7 +4715,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4715,7 +4715,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4715 }4715 }
4716 return result;4716 return result;
4717 }4717 }
4718 case TypeTableEntryIdEnum:4718 case ZigTypeIdEnum:
4719 {4719 {
4720 uint32_t result = 31643936;4720 uint32_t result = 31643936;
4721 for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) {4721 for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) {
...@@ -4724,7 +4724,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4724,7 +4724,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4724 }4724 }
4725 return result;4725 return result;
4726 }4726 }
4727 case TypeTableEntryIdFloat:4727 case ZigTypeIdFloat:
4728 switch (const_val->type->data.floating.bit_count) {4728 switch (const_val->type->data.floating.bit_count) {
4729 case 16:4729 case 16:
4730 {4730 {
...@@ -4754,39 +4754,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4754,39 +4754,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4754 default:4754 default:
4755 zig_unreachable();4755 zig_unreachable();
4756 }4756 }
4757 case TypeTableEntryIdComptimeFloat:4757 case ZigTypeIdComptimeFloat:
4758 {4758 {
4759 float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);4759 float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
4760 uint32_t ints[4];4760 uint32_t ints[4];
4761 memcpy(&ints[0], &f128, 16);4761 memcpy(&ints[0], &f128, 16);
4762 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;4762 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;
4763 }4763 }
4764 case TypeTableEntryIdArgTuple:4764 case ZigTypeIdArgTuple:
4765 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +4765 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
4766 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;4766 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
4767 case TypeTableEntryIdFn:4767 case ZigTypeIdFn:
4768 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);4768 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
4769 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);4769 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
4770 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);4770 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4771 case TypeTableEntryIdPointer:4771 case ZigTypeIdPointer:
4772 return hash_const_val_ptr(const_val);4772 return hash_const_val_ptr(const_val);
4773 case TypeTableEntryIdPromise:4773 case ZigTypeIdPromise:
4774 // TODO better hashing algorithm4774 // TODO better hashing algorithm
4775 return 223048345;4775 return 223048345;
4776 case TypeTableEntryIdUndefined:4776 case ZigTypeIdUndefined:
4777 return 162837799;4777 return 162837799;
4778 case TypeTableEntryIdNull:4778 case ZigTypeIdNull:
4779 return 844854567;4779 return 844854567;
4780 case TypeTableEntryIdArray:4780 case ZigTypeIdArray:
4781 // TODO better hashing algorithm4781 // TODO better hashing algorithm
4782 return 1166190605;4782 return 1166190605;
4783 case TypeTableEntryIdStruct:4783 case ZigTypeIdStruct:
4784 // TODO better hashing algorithm4784 // TODO better hashing algorithm
4785 return 1532530855;4785 return 1532530855;
4786 case TypeTableEntryIdUnion:4786 case ZigTypeIdUnion:
4787 // TODO better hashing algorithm4787 // TODO better hashing algorithm
4788 return 2709806591;4788 return 2709806591;
4789 case TypeTableEntryIdOptional:4789 case ZigTypeIdOptional:
4790 if (get_codegen_ptr_type(const_val->type) != nullptr) {4790 if (get_codegen_ptr_type(const_val->type) != nullptr) {
4791 return hash_const_val(const_val) * 1992916303;4791 return hash_const_val(const_val) * 1992916303;
4792 } else {4792 } else {
...@@ -4796,19 +4796,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4796,19 +4796,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4796 return 4016830364;4796 return 4016830364;
4797 }4797 }
4798 }4798 }
4799 case TypeTableEntryIdErrorUnion:4799 case ZigTypeIdErrorUnion:
4800 // TODO better hashing algorithm4800 // TODO better hashing algorithm
4801 return 3415065496;4801 return 3415065496;
4802 case TypeTableEntryIdErrorSet:4802 case ZigTypeIdErrorSet:
4803 assert(const_val->data.x_err_set != nullptr);4803 assert(const_val->data.x_err_set != nullptr);
4804 return const_val->data.x_err_set->value ^ 2630160122;4804 return const_val->data.x_err_set->value ^ 2630160122;
4805 case TypeTableEntryIdNamespace:4805 case ZigTypeIdNamespace:
4806 return hash_ptr(const_val->data.x_import);4806 return hash_ptr(const_val->data.x_import);
4807 case TypeTableEntryIdBlock:4807 case ZigTypeIdBlock:
4808 return hash_ptr(const_val->data.x_block);4808 return hash_ptr(const_val->data.x_block);
4809 case TypeTableEntryIdBoundFn:4809 case ZigTypeIdBoundFn:
4810 case TypeTableEntryIdInvalid:4810 case ZigTypeIdInvalid:
4811 case TypeTableEntryIdUnreachable:4811 case ZigTypeIdUnreachable:
4812 zig_unreachable();4812 zig_unreachable();
4813 }4813 }
4814 zig_unreachable();4814 zig_unreachable();
...@@ -4851,32 +4851,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {...@@ -4851,32 +4851,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
4851static bool can_mutate_comptime_var_state(ConstExprValue *value) {4851static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4852 assert(value != nullptr);4852 assert(value != nullptr);
4853 switch (value->type->id) {4853 switch (value->type->id) {
4854 case TypeTableEntryIdInvalid:4854 case ZigTypeIdInvalid:
4855 zig_unreachable();4855 zig_unreachable();
4856 case TypeTableEntryIdMetaType:4856 case ZigTypeIdMetaType:
4857 case TypeTableEntryIdVoid:4857 case ZigTypeIdVoid:
4858 case TypeTableEntryIdBool:4858 case ZigTypeIdBool:
4859 case TypeTableEntryIdUnreachable:4859 case ZigTypeIdUnreachable:
4860 case TypeTableEntryIdInt:4860 case ZigTypeIdInt:
4861 case TypeTableEntryIdFloat:4861 case ZigTypeIdFloat:
4862 case TypeTableEntryIdComptimeFloat:4862 case ZigTypeIdComptimeFloat:
4863 case TypeTableEntryIdComptimeInt:4863 case ZigTypeIdComptimeInt:
4864 case TypeTableEntryIdUndefined:4864 case ZigTypeIdUndefined:
4865 case TypeTableEntryIdNull:4865 case ZigTypeIdNull:
4866 case TypeTableEntryIdNamespace:4866 case ZigTypeIdNamespace:
4867 case TypeTableEntryIdBoundFn:4867 case ZigTypeIdBoundFn:
4868 case TypeTableEntryIdFn:4868 case ZigTypeIdFn:
4869 case TypeTableEntryIdBlock:4869 case ZigTypeIdBlock:
4870 case TypeTableEntryIdOpaque:4870 case ZigTypeIdOpaque:
4871 case TypeTableEntryIdPromise:4871 case ZigTypeIdPromise:
4872 case TypeTableEntryIdErrorSet:4872 case ZigTypeIdErrorSet:
4873 case TypeTableEntryIdEnum:4873 case ZigTypeIdEnum:
4874 return false;4874 return false;
48754875
4876 case TypeTableEntryIdPointer:4876 case ZigTypeIdPointer:
4877 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;4877 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
48784878
4879 case TypeTableEntryIdArray:4879 case ZigTypeIdArray:
4880 if (value->type->data.array.len == 0)4880 if (value->type->data.array.len == 0)
4881 return false;4881 return false;
4882 if (value->data.x_array.special == ConstArraySpecialUndef)4882 if (value->data.x_array.special == ConstArraySpecialUndef)
...@@ -4887,30 +4887,30 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4887,30 +4887,30 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4887 }4887 }
4888 return false;4888 return false;
48894889
4890 case TypeTableEntryIdStruct:4890 case ZigTypeIdStruct:
4891 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {4891 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
4892 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))4892 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))
4893 return true;4893 return true;
4894 }4894 }
4895 return false;4895 return false;
48964896
4897 case TypeTableEntryIdOptional:4897 case ZigTypeIdOptional:
4898 if (get_codegen_ptr_type(value->type) != nullptr)4898 if (get_codegen_ptr_type(value->type) != nullptr)
4899 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;4899 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
4900 if (value->data.x_optional == nullptr)4900 if (value->data.x_optional == nullptr)
4901 return false;4901 return false;
4902 return can_mutate_comptime_var_state(value->data.x_optional);4902 return can_mutate_comptime_var_state(value->data.x_optional);
49034903
4904 case TypeTableEntryIdErrorUnion:4904 case ZigTypeIdErrorUnion:
4905 if (value->data.x_err_union.err != nullptr)4905 if (value->data.x_err_union.err != nullptr)
4906 return false;4906 return false;
4907 assert(value->data.x_err_union.payload != nullptr);4907 assert(value->data.x_err_union.payload != nullptr);
4908 return can_mutate_comptime_var_state(value->data.x_err_union.payload);4908 return can_mutate_comptime_var_state(value->data.x_err_union.payload);
49094909
4910 case TypeTableEntryIdUnion:4910 case ZigTypeIdUnion:
4911 return can_mutate_comptime_var_state(value->data.x_union.payload);4911 return can_mutate_comptime_var_state(value->data.x_union.payload);
49124912
4913 case TypeTableEntryIdArgTuple:4913 case ZigTypeIdArgTuple:
4914 zig_panic("TODO var args at comptime is currently not supported");4914 zig_panic("TODO var args at comptime is currently not supported");
4915 }4915 }
4916 zig_unreachable();4916 zig_unreachable();
...@@ -4918,41 +4918,41 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4918,41 +4918,41 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
49184918
4919static bool return_type_is_cacheable(ZigType *return_type) {4919static bool return_type_is_cacheable(ZigType *return_type) {
4920 switch (return_type->id) {4920 switch (return_type->id) {
4921 case TypeTableEntryIdInvalid:4921 case ZigTypeIdInvalid:
4922 zig_unreachable();4922 zig_unreachable();
4923 case TypeTableEntryIdMetaType:4923 case ZigTypeIdMetaType:
4924 case TypeTableEntryIdVoid:4924 case ZigTypeIdVoid:
4925 case TypeTableEntryIdBool:4925 case ZigTypeIdBool:
4926 case TypeTableEntryIdUnreachable:4926 case ZigTypeIdUnreachable:
4927 case TypeTableEntryIdInt:4927 case ZigTypeIdInt:
4928 case TypeTableEntryIdFloat:4928 case ZigTypeIdFloat:
4929 case TypeTableEntryIdComptimeFloat:4929 case ZigTypeIdComptimeFloat:
4930 case TypeTableEntryIdComptimeInt:4930 case ZigTypeIdComptimeInt:
4931 case TypeTableEntryIdUndefined:4931 case ZigTypeIdUndefined:
4932 case TypeTableEntryIdNull:4932 case ZigTypeIdNull:
4933 case TypeTableEntryIdNamespace:4933 case ZigTypeIdNamespace:
4934 case TypeTableEntryIdBoundFn:4934 case ZigTypeIdBoundFn:
4935 case TypeTableEntryIdFn:4935 case ZigTypeIdFn:
4936 case TypeTableEntryIdBlock:4936 case ZigTypeIdBlock:
4937 case TypeTableEntryIdOpaque:4937 case ZigTypeIdOpaque:
4938 case TypeTableEntryIdPromise:4938 case ZigTypeIdPromise:
4939 case TypeTableEntryIdErrorSet:4939 case ZigTypeIdErrorSet:
4940 case TypeTableEntryIdEnum:4940 case ZigTypeIdEnum:
4941 case TypeTableEntryIdPointer:4941 case ZigTypeIdPointer:
4942 return true;4942 return true;
49434943
4944 case TypeTableEntryIdArray:4944 case ZigTypeIdArray:
4945 case TypeTableEntryIdStruct:4945 case ZigTypeIdStruct:
4946 case TypeTableEntryIdUnion:4946 case ZigTypeIdUnion:
4947 return false;4947 return false;
49484948
4949 case TypeTableEntryIdOptional:4949 case ZigTypeIdOptional:
4950 return return_type_is_cacheable(return_type->data.maybe.child_type);4950 return return_type_is_cacheable(return_type->data.maybe.child_type);
49514951
4952 case TypeTableEntryIdErrorUnion:4952 case ZigTypeIdErrorUnion:
4953 return return_type_is_cacheable(return_type->data.error_union.payload_type);4953 return return_type_is_cacheable(return_type->data.error_union.payload_type);
49544954
4955 case TypeTableEntryIdArgTuple:4955 case ZigTypeIdArgTuple:
4956 zig_panic("TODO var args at comptime is currently not supported");4956 zig_panic("TODO var args at comptime is currently not supported");
4957 }4957 }
4958 zig_unreachable();4958 zig_unreachable();
...@@ -5029,54 +5029,54 @@ bool fn_eval_eql(Scope *a, Scope *b) {...@@ -5029,54 +5029,54 @@ bool fn_eval_eql(Scope *a, Scope *b) {
50295029
5030bool type_has_bits(ZigType *type_entry) {5030bool type_has_bits(ZigType *type_entry) {
5031 assert(type_entry);5031 assert(type_entry);
5032 assert(type_entry->id != TypeTableEntryIdInvalid);5032 assert(type_entry->id != ZigTypeIdInvalid);
5033 assert(type_has_zero_bits_known(type_entry));5033 assert(type_has_zero_bits_known(type_entry));
5034 return !type_entry->zero_bits;5034 return !type_entry->zero_bits;
5035}5035}
50365036
5037bool type_requires_comptime(ZigType *type_entry) {5037bool type_requires_comptime(ZigType *type_entry) {
5038 switch (type_entry->id) {5038 switch (type_entry->id) {
5039 case TypeTableEntryIdInvalid:5039 case ZigTypeIdInvalid:
5040 case TypeTableEntryIdOpaque:5040 case ZigTypeIdOpaque:
5041 zig_unreachable();5041 zig_unreachable();
5042 case TypeTableEntryIdComptimeFloat:5042 case ZigTypeIdComptimeFloat:
5043 case TypeTableEntryIdComptimeInt:5043 case ZigTypeIdComptimeInt:
5044 case TypeTableEntryIdUndefined:5044 case ZigTypeIdUndefined:
5045 case TypeTableEntryIdNull:5045 case ZigTypeIdNull:
5046 case TypeTableEntryIdMetaType:5046 case ZigTypeIdMetaType:
5047 case TypeTableEntryIdNamespace:5047 case ZigTypeIdNamespace:
5048 case TypeTableEntryIdBlock:5048 case ZigTypeIdBlock:
5049 case TypeTableEntryIdBoundFn:5049 case ZigTypeIdBoundFn:
5050 case TypeTableEntryIdArgTuple:5050 case ZigTypeIdArgTuple:
5051 return true;5051 return true;
5052 case TypeTableEntryIdArray:5052 case ZigTypeIdArray:
5053 return type_requires_comptime(type_entry->data.array.child_type);5053 return type_requires_comptime(type_entry->data.array.child_type);
5054 case TypeTableEntryIdStruct:5054 case ZigTypeIdStruct:
5055 assert(type_has_zero_bits_known(type_entry));5055 assert(type_has_zero_bits_known(type_entry));
5056 return type_entry->data.structure.requires_comptime;5056 return type_entry->data.structure.requires_comptime;
5057 case TypeTableEntryIdUnion:5057 case ZigTypeIdUnion:
5058 assert(type_has_zero_bits_known(type_entry));5058 assert(type_has_zero_bits_known(type_entry));
5059 return type_entry->data.unionation.requires_comptime;5059 return type_entry->data.unionation.requires_comptime;
5060 case TypeTableEntryIdOptional:5060 case ZigTypeIdOptional:
5061 return type_requires_comptime(type_entry->data.maybe.child_type);5061 return type_requires_comptime(type_entry->data.maybe.child_type);
5062 case TypeTableEntryIdErrorUnion:5062 case ZigTypeIdErrorUnion:
5063 return type_requires_comptime(type_entry->data.error_union.payload_type);5063 return type_requires_comptime(type_entry->data.error_union.payload_type);
5064 case TypeTableEntryIdPointer:5064 case ZigTypeIdPointer:
5065 if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) {5065 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
5066 return false;5066 return false;
5067 } else {5067 } else {
5068 return type_requires_comptime(type_entry->data.pointer.child_type);5068 return type_requires_comptime(type_entry->data.pointer.child_type);
5069 }5069 }
5070 case TypeTableEntryIdFn:5070 case ZigTypeIdFn:
5071 return type_entry->data.fn.is_generic;5071 return type_entry->data.fn.is_generic;
5072 case TypeTableEntryIdEnum:5072 case ZigTypeIdEnum:
5073 case TypeTableEntryIdErrorSet:5073 case ZigTypeIdErrorSet:
5074 case TypeTableEntryIdBool:5074 case ZigTypeIdBool:
5075 case TypeTableEntryIdInt:5075 case ZigTypeIdInt:
5076 case TypeTableEntryIdFloat:5076 case ZigTypeIdFloat:
5077 case TypeTableEntryIdVoid:5077 case ZigTypeIdVoid:
5078 case TypeTableEntryIdUnreachable:5078 case ZigTypeIdUnreachable:
5079 case TypeTableEntryIdPromise:5079 case ZigTypeIdPromise:
5080 return false;5080 return false;
5081 }5081 }
5082 zig_unreachable();5082 zig_unreachable();
...@@ -5192,9 +5192,9 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) {...@@ -5192,9 +5192,9 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
5192void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {5192void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5193 const_val->special = ConstValSpecialStatic;5193 const_val->special = ConstValSpecialStatic;
5194 const_val->type = type;5194 const_val->type = type;
5195 if (type->id == TypeTableEntryIdComptimeFloat) {5195 if (type->id == ZigTypeIdComptimeFloat) {
5196 bigfloat_init_64(&const_val->data.x_bigfloat, value);5196 bigfloat_init_64(&const_val->data.x_bigfloat, value);
5197 } else if (type->id == TypeTableEntryIdFloat) {5197 } else if (type->id == ZigTypeIdFloat) {
5198 switch (type->data.floating.bit_count) {5198 switch (type->data.floating.bit_count) {
5199 case 16:5199 case 16:
5200 const_val->data.x_f16 = zig_double_to_f16(value);5200 const_val->data.x_f16 = zig_double_to_f16(value);
...@@ -5273,7 +5273,7 @@ ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {...@@ -5273,7 +5273,7 @@ ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {
5273void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5273void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
5274 size_t start, size_t len, bool is_const)5274 size_t start, size_t len, bool is_const)
5275{5275{
5276 assert(array_val->type->id == TypeTableEntryIdArray);5276 assert(array_val->type->id == ZigTypeIdArray);
52775277
5278 ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,5278 ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
5279 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),5279 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),
...@@ -5297,7 +5297,7 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t...@@ -5297,7 +5297,7 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
5297void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,5297void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
5298 size_t elem_index, bool is_const, PtrLen ptr_len)5298 size_t elem_index, bool is_const, PtrLen ptr_len)
5299{5299{
5300 assert(array_val->type->id == TypeTableEntryIdArray);5300 assert(array_val->type->id == ZigTypeIdArray);
5301 ZigType *child_type = array_val->type->data.array.child_type;5301 ZigType *child_type = array_val->type->data.array.child_type;
53025302
5303 const_val->special = ConstValSpecialStatic;5303 const_val->special = ConstValSpecialStatic;
...@@ -5363,10 +5363,10 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_...@@ -5363,10 +5363,10 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
5363void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {5363void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
5364 Error err;5364 Error err;
5365 ZigType *wanted_type = const_val->type;5365 ZigType *wanted_type = const_val->type;
5366 if (wanted_type->id == TypeTableEntryIdArray) {5366 if (wanted_type->id == ZigTypeIdArray) {
5367 const_val->special = ConstValSpecialStatic;5367 const_val->special = ConstValSpecialStatic;
5368 const_val->data.x_array.special = ConstArraySpecialUndef;5368 const_val->data.x_array.special = ConstArraySpecialUndef;
5369 } else if (wanted_type->id == TypeTableEntryIdStruct) {5369 } else if (wanted_type->id == ZigTypeIdStruct) {
5370 if ((err = ensure_complete_type(g, wanted_type))) {5370 if ((err = ensure_complete_type(g, wanted_type))) {
5371 return;5371 return;
5372 }5372 }
...@@ -5403,13 +5403,13 @@ ConstExprValue *create_const_vals(size_t count) {...@@ -5403,13 +5403,13 @@ ConstExprValue *create_const_vals(size_t count) {
5403Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {5403Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {
5404 if (type_is_invalid(type_entry))5404 if (type_is_invalid(type_entry))
5405 return ErrorSemanticAnalyzeFail;5405 return ErrorSemanticAnalyzeFail;
5406 if (type_entry->id == TypeTableEntryIdStruct) {5406 if (type_entry->id == ZigTypeIdStruct) {
5407 if (!type_entry->data.structure.complete)5407 if (!type_entry->data.structure.complete)
5408 return resolve_struct_type(g, type_entry);5408 return resolve_struct_type(g, type_entry);
5409 } else if (type_entry->id == TypeTableEntryIdEnum) {5409 } else if (type_entry->id == ZigTypeIdEnum) {
5410 if (!type_entry->data.enumeration.complete)5410 if (!type_entry->data.enumeration.complete)
5411 return resolve_enum_type(g, type_entry);5411 return resolve_enum_type(g, type_entry);
5412 } else if (type_entry->id == TypeTableEntryIdUnion) {5412 } else if (type_entry->id == ZigTypeIdUnion) {
5413 if (!type_entry->data.unionation.complete)5413 if (!type_entry->data.unionation.complete)
5414 return resolve_union_type(g, type_entry);5414 return resolve_union_type(g, type_entry);
5415 }5415 }
...@@ -5419,11 +5419,11 @@ Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {...@@ -5419,11 +5419,11 @@ Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {
5419Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {5419Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {
5420 if (type_is_invalid(type_entry))5420 if (type_is_invalid(type_entry))
5421 return ErrorSemanticAnalyzeFail;5421 return ErrorSemanticAnalyzeFail;
5422 if (type_entry->id == TypeTableEntryIdStruct) {5422 if (type_entry->id == ZigTypeIdStruct) {
5423 return resolve_struct_zero_bits(g, type_entry);5423 return resolve_struct_zero_bits(g, type_entry);
5424 } else if (type_entry->id == TypeTableEntryIdEnum) {5424 } else if (type_entry->id == ZigTypeIdEnum) {
5425 return resolve_enum_zero_bits(g, type_entry);5425 return resolve_enum_zero_bits(g, type_entry);
5426 } else if (type_entry->id == TypeTableEntryIdUnion) {5426 } else if (type_entry->id == ZigTypeIdUnion) {
5427 return resolve_union_zero_bits(g, type_entry);5427 return resolve_union_zero_bits(g, type_entry);
5428 }5428 }
5429 return ErrorNone;5429 return ErrorNone;
...@@ -5488,11 +5488,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5488,11 +5488,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5488 assert(a->special == ConstValSpecialStatic);5488 assert(a->special == ConstValSpecialStatic);
5489 assert(b->special == ConstValSpecialStatic);5489 assert(b->special == ConstValSpecialStatic);
5490 switch (a->type->id) {5490 switch (a->type->id) {
5491 case TypeTableEntryIdOpaque:5491 case ZigTypeIdOpaque:
5492 zig_unreachable();5492 zig_unreachable();
5493 case TypeTableEntryIdEnum:5493 case ZigTypeIdEnum:
5494 return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;5494 return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;
5495 case TypeTableEntryIdUnion: {5495 case ZigTypeIdUnion: {
5496 ConstUnionValue *union1 = &a->data.x_union;5496 ConstUnionValue *union1 = &a->data.x_union;
5497 ConstUnionValue *union2 = &b->data.x_union;5497 ConstUnionValue *union2 = &b->data.x_union;
54985498
...@@ -5507,15 +5507,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5507,15 +5507,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5507 }5507 }
5508 return false;5508 return false;
5509 }5509 }
5510 case TypeTableEntryIdMetaType:5510 case ZigTypeIdMetaType:
5511 return a->data.x_type == b->data.x_type;5511 return a->data.x_type == b->data.x_type;
5512 case TypeTableEntryIdVoid:5512 case ZigTypeIdVoid:
5513 return true;5513 return true;
5514 case TypeTableEntryIdErrorSet:5514 case ZigTypeIdErrorSet:
5515 return a->data.x_err_set->value == b->data.x_err_set->value;5515 return a->data.x_err_set->value == b->data.x_err_set->value;
5516 case TypeTableEntryIdBool:5516 case ZigTypeIdBool:
5517 return a->data.x_bool == b->data.x_bool;5517 return a->data.x_bool == b->data.x_bool;
5518 case TypeTableEntryIdFloat:5518 case ZigTypeIdFloat:
5519 assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);5519 assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);
5520 switch (a->type->data.floating.bit_count) {5520 switch (a->type->data.floating.bit_count) {
5521 case 16:5521 case 16:
...@@ -5529,15 +5529,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5529,15 +5529,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5529 default:5529 default:
5530 zig_unreachable();5530 zig_unreachable();
5531 }5531 }
5532 case TypeTableEntryIdComptimeFloat:5532 case ZigTypeIdComptimeFloat:
5533 return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;5533 return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;
5534 case TypeTableEntryIdInt:5534 case ZigTypeIdInt:
5535 case TypeTableEntryIdComptimeInt:5535 case ZigTypeIdComptimeInt:
5536 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;5536 return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
5537 case TypeTableEntryIdPointer:5537 case ZigTypeIdPointer:
5538 case TypeTableEntryIdFn:5538 case ZigTypeIdFn:
5539 return const_values_equal_ptr(a, b);5539 return const_values_equal_ptr(a, b);
5540 case TypeTableEntryIdArray: {5540 case ZigTypeIdArray: {
5541 assert(a->type->data.array.len == b->type->data.array.len);5541 assert(a->type->data.array.len == b->type->data.array.len);
5542 assert(a->data.x_array.special != ConstArraySpecialUndef);5542 assert(a->data.x_array.special != ConstArraySpecialUndef);
5543 assert(b->data.x_array.special != ConstArraySpecialUndef);5543 assert(b->data.x_array.special != ConstArraySpecialUndef);
...@@ -5553,7 +5553,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5553,7 +5553,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
55535553
5554 return true;5554 return true;
5555 }5555 }
5556 case TypeTableEntryIdStruct:5556 case ZigTypeIdStruct:
5557 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {5557 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
5558 ConstExprValue *field_a = &a->data.x_struct.fields[i];5558 ConstExprValue *field_a = &a->data.x_struct.fields[i];
5559 ConstExprValue *field_b = &b->data.x_struct.fields[i];5559 ConstExprValue *field_b = &b->data.x_struct.fields[i];
...@@ -5561,11 +5561,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5561,11 +5561,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5561 return false;5561 return false;
5562 }5562 }
5563 return true;5563 return true;
5564 case TypeTableEntryIdUndefined:5564 case ZigTypeIdUndefined:
5565 zig_panic("TODO");5565 zig_panic("TODO");
5566 case TypeTableEntryIdNull:5566 case ZigTypeIdNull:
5567 zig_panic("TODO");5567 zig_panic("TODO");
5568 case TypeTableEntryIdOptional:5568 case ZigTypeIdOptional:
5569 if (get_codegen_ptr_type(a->type) != nullptr)5569 if (get_codegen_ptr_type(a->type) != nullptr)
5570 return const_values_equal_ptr(a, b);5570 return const_values_equal_ptr(a, b);
5571 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {5571 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
...@@ -5573,26 +5573,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5573,26 +5573,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5573 } else {5573 } else {
5574 return const_values_equal(a->data.x_optional, b->data.x_optional);5574 return const_values_equal(a->data.x_optional, b->data.x_optional);
5575 }5575 }
5576 case TypeTableEntryIdErrorUnion:5576 case ZigTypeIdErrorUnion:
5577 zig_panic("TODO");5577 zig_panic("TODO");
5578 case TypeTableEntryIdNamespace:5578 case ZigTypeIdNamespace:
5579 return a->data.x_import == b->data.x_import;5579 return a->data.x_import == b->data.x_import;
5580 case TypeTableEntryIdBlock:5580 case ZigTypeIdBlock:
5581 return a->data.x_block == b->data.x_block;5581 return a->data.x_block == b->data.x_block;
5582 case TypeTableEntryIdArgTuple:5582 case ZigTypeIdArgTuple:
5583 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&5583 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
5584 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;5584 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
5585 case TypeTableEntryIdBoundFn:5585 case ZigTypeIdBoundFn:
5586 case TypeTableEntryIdInvalid:5586 case ZigTypeIdInvalid:
5587 case TypeTableEntryIdUnreachable:5587 case ZigTypeIdUnreachable:
5588 case TypeTableEntryIdPromise:5588 case ZigTypeIdPromise:
5589 zig_unreachable();5589 zig_unreachable();
5590 }5590 }
5591 zig_unreachable();5591 zig_unreachable();
5592}5592}
55935593
5594void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) {5594void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) {
5595 assert(int_type->id == TypeTableEntryIdInt);5595 assert(int_type->id == ZigTypeIdInt);
5596 if (int_type->data.integral.bit_count == 0) {5596 if (int_type->data.integral.bit_count == 0) {
5597 bigint_init_unsigned(bigint, 0);5597 bigint_init_unsigned(bigint, 0);
5598 return;5598 return;
...@@ -5629,13 +5629,13 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool...@@ -5629,13 +5629,13 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool
5629}5629}
56305630
5631void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {5631void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {
5632 if (type_entry->id == TypeTableEntryIdInt) {5632 if (type_entry->id == ZigTypeIdInt) {
5633 const_val->special = ConstValSpecialStatic;5633 const_val->special = ConstValSpecialStatic;
5634 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);5634 eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);
5635 } else if (type_entry->id == TypeTableEntryIdBool) {5635 } else if (type_entry->id == ZigTypeIdBool) {
5636 const_val->special = ConstValSpecialStatic;5636 const_val->special = ConstValSpecialStatic;
5637 const_val->data.x_bool = is_max;5637 const_val->data.x_bool = is_max;
5638 } else if (type_entry->id == TypeTableEntryIdVoid) {5638 } else if (type_entry->id == ZigTypeIdVoid) {
5639 // nothing to do5639 // nothing to do
5640 } else {5640 } else {
5641 zig_unreachable();5641 zig_unreachable();
...@@ -5692,18 +5692,18 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5692,18 +5692,18 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
56925692
5693 ZigType *type_entry = const_val->type;5693 ZigType *type_entry = const_val->type;
5694 switch (type_entry->id) {5694 switch (type_entry->id) {
5695 case TypeTableEntryIdOpaque:5695 case ZigTypeIdOpaque:
5696 zig_unreachable();5696 zig_unreachable();
5697 case TypeTableEntryIdInvalid:5697 case ZigTypeIdInvalid:
5698 buf_appendf(buf, "(invalid)");5698 buf_appendf(buf, "(invalid)");
5699 return;5699 return;
5700 case TypeTableEntryIdVoid:5700 case ZigTypeIdVoid:
5701 buf_appendf(buf, "{}");5701 buf_appendf(buf, "{}");
5702 return;5702 return;
5703 case TypeTableEntryIdComptimeFloat:5703 case ZigTypeIdComptimeFloat:
5704 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);5704 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
5705 return;5705 return;
5706 case TypeTableEntryIdFloat:5706 case ZigTypeIdFloat:
5707 switch (type_entry->data.floating.bit_count) {5707 switch (type_entry->data.floating.bit_count) {
5708 case 16:5708 case 16:
5709 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));5709 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
...@@ -5731,23 +5731,23 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5731,23 +5731,23 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5731 default:5731 default:
5732 zig_unreachable();5732 zig_unreachable();
5733 }5733 }
5734 case TypeTableEntryIdComptimeInt:5734 case ZigTypeIdComptimeInt:
5735 case TypeTableEntryIdInt:5735 case ZigTypeIdInt:
5736 bigint_append_buf(buf, &const_val->data.x_bigint, 10);5736 bigint_append_buf(buf, &const_val->data.x_bigint, 10);
5737 return;5737 return;
5738 case TypeTableEntryIdMetaType:5738 case ZigTypeIdMetaType:
5739 buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));5739 buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));
5740 return;5740 return;
5741 case TypeTableEntryIdUnreachable:5741 case ZigTypeIdUnreachable:
5742 buf_appendf(buf, "unreachable");5742 buf_appendf(buf, "unreachable");
5743 return;5743 return;
5744 case TypeTableEntryIdBool:5744 case ZigTypeIdBool:
5745 {5745 {
5746 const char *value = const_val->data.x_bool ? "true" : "false";5746 const char *value = const_val->data.x_bool ? "true" : "false";
5747 buf_appendf(buf, "%s", value);5747 buf_appendf(buf, "%s", value);
5748 return;5748 return;
5749 }5749 }
5750 case TypeTableEntryIdFn:5750 case ZigTypeIdFn:
5751 {5751 {
5752 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);5752 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
5753 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);5753 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
...@@ -5755,15 +5755,15 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5755,15 +5755,15 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5755 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));5755 buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
5756 return;5756 return;
5757 }5757 }
5758 case TypeTableEntryIdPointer:5758 case ZigTypeIdPointer:
5759 return render_const_val_ptr(g, buf, const_val, type_entry);5759 return render_const_val_ptr(g, buf, const_val, type_entry);
5760 case TypeTableEntryIdBlock:5760 case ZigTypeIdBlock:
5761 {5761 {
5762 AstNode *node = const_val->data.x_block->source_node;5762 AstNode *node = const_val->data.x_block->source_node;
5763 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);5763 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
5764 return;5764 return;
5765 }5765 }
5766 case TypeTableEntryIdArray:5766 case ZigTypeIdArray:
5767 {5767 {
5768 ZigType *child_type = type_entry->data.array.child_type;5768 ZigType *child_type = type_entry->data.array.child_type;
5769 uint64_t len = type_entry->data.array.len;5769 uint64_t len = type_entry->data.array.len;
...@@ -5774,7 +5774,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5774,7 +5774,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5774 }5774 }
57755775
5776 // if it's []u8, assume UTF-8 and output a string5776 // if it's []u8, assume UTF-8 and output a string
5777 if (child_type->id == TypeTableEntryIdInt &&5777 if (child_type->id == ZigTypeIdInt &&
5778 child_type->data.integral.bit_count == 8 &&5778 child_type->data.integral.bit_count == 8 &&
5779 !child_type->data.integral.is_signed)5779 !child_type->data.integral.is_signed)
5780 {5780 {
...@@ -5804,17 +5804,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5804,17 +5804,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5804 buf_appendf(buf, "}");5804 buf_appendf(buf, "}");
5805 return;5805 return;
5806 }5806 }
5807 case TypeTableEntryIdNull:5807 case ZigTypeIdNull:
5808 {5808 {
5809 buf_appendf(buf, "null");5809 buf_appendf(buf, "null");
5810 return;5810 return;
5811 }5811 }
5812 case TypeTableEntryIdUndefined:5812 case ZigTypeIdUndefined:
5813 {5813 {
5814 buf_appendf(buf, "undefined");5814 buf_appendf(buf, "undefined");
5815 return;5815 return;
5816 }5816 }
5817 case TypeTableEntryIdOptional:5817 case ZigTypeIdOptional:
5818 {5818 {
5819 if (get_codegen_ptr_type(const_val->type) != nullptr)5819 if (get_codegen_ptr_type(const_val->type) != nullptr)
5820 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);5820 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
...@@ -5825,7 +5825,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5825,7 +5825,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5825 }5825 }
5826 return;5826 return;
5827 }5827 }
5828 case TypeTableEntryIdNamespace:5828 case ZigTypeIdNamespace:
5829 {5829 {
5830 ImportTableEntry *import = const_val->data.x_import;5830 ImportTableEntry *import = const_val->data.x_import;
5831 if (import->c_import_node) {5831 if (import->c_import_node) {
...@@ -5835,51 +5835,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5835,51 +5835,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5835 }5835 }
5836 return;5836 return;
5837 }5837 }
5838 case TypeTableEntryIdBoundFn:5838 case ZigTypeIdBoundFn:
5839 {5839 {
5840 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;5840 ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
5841 buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));5841 buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));
5842 return;5842 return;
5843 }5843 }
5844 case TypeTableEntryIdStruct:5844 case ZigTypeIdStruct:
5845 {5845 {
5846 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));5846 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));
5847 return;5847 return;
5848 }5848 }
5849 case TypeTableEntryIdEnum:5849 case ZigTypeIdEnum:
5850 {5850 {
5851 TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);5851 TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);
5852 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));5852 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));
5853 return;5853 return;
5854 }5854 }
5855 case TypeTableEntryIdErrorUnion:5855 case ZigTypeIdErrorUnion:
5856 {5856 {
5857 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));5857 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));
5858 return;5858 return;
5859 }5859 }
5860 case TypeTableEntryIdUnion:5860 case ZigTypeIdUnion:
5861 {5861 {
5862 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));5862 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));
5863 return;5863 return;
5864 }5864 }
5865 case TypeTableEntryIdErrorSet:5865 case ZigTypeIdErrorSet:
5866 {5866 {
5867 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));5867 buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));
5868 return;5868 return;
5869 }5869 }
5870 case TypeTableEntryIdArgTuple:5870 case ZigTypeIdArgTuple:
5871 {5871 {
5872 buf_appendf(buf, "(args value)");5872 buf_appendf(buf, "(args value)");
5873 return;5873 return;
5874 }5874 }
5875 case TypeTableEntryIdPromise:5875 case ZigTypeIdPromise:
5876 zig_unreachable();5876 zig_unreachable();
5877 }5877 }
5878 zig_unreachable();5878 zig_unreachable();
5879}5879}
58805880
5881ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {5881ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
5882 ZigType *entry = new_type_table_entry(TypeTableEntryIdInt);5882 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
5883 entry->is_copyable = true;5883 entry->is_copyable = true;
5884 entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);5884 entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);
5885 entry->zero_bits = (size_in_bits == 0);5885 entry->zero_bits = (size_in_bits == 0);
...@@ -5913,32 +5913,32 @@ ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {...@@ -5913,32 +5913,32 @@ ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
59135913
5914uint32_t type_id_hash(TypeId x) {5914uint32_t type_id_hash(TypeId x) {
5915 switch (x.id) {5915 switch (x.id) {
5916 case TypeTableEntryIdInvalid:5916 case ZigTypeIdInvalid:
5917 case TypeTableEntryIdOpaque:5917 case ZigTypeIdOpaque:
5918 case TypeTableEntryIdMetaType:5918 case ZigTypeIdMetaType:
5919 case TypeTableEntryIdVoid:5919 case ZigTypeIdVoid:
5920 case TypeTableEntryIdBool:5920 case ZigTypeIdBool:
5921 case TypeTableEntryIdUnreachable:5921 case ZigTypeIdUnreachable:
5922 case TypeTableEntryIdFloat:5922 case ZigTypeIdFloat:
5923 case TypeTableEntryIdStruct:5923 case ZigTypeIdStruct:
5924 case TypeTableEntryIdComptimeFloat:5924 case ZigTypeIdComptimeFloat:
5925 case TypeTableEntryIdComptimeInt:5925 case ZigTypeIdComptimeInt:
5926 case TypeTableEntryIdUndefined:5926 case ZigTypeIdUndefined:
5927 case TypeTableEntryIdNull:5927 case ZigTypeIdNull:
5928 case TypeTableEntryIdOptional:5928 case ZigTypeIdOptional:
5929 case TypeTableEntryIdErrorSet:5929 case ZigTypeIdErrorSet:
5930 case TypeTableEntryIdEnum:5930 case ZigTypeIdEnum:
5931 case TypeTableEntryIdUnion:5931 case ZigTypeIdUnion:
5932 case TypeTableEntryIdFn:5932 case ZigTypeIdFn:
5933 case TypeTableEntryIdNamespace:5933 case ZigTypeIdNamespace:
5934 case TypeTableEntryIdBlock:5934 case ZigTypeIdBlock:
5935 case TypeTableEntryIdBoundFn:5935 case ZigTypeIdBoundFn:
5936 case TypeTableEntryIdArgTuple:5936 case ZigTypeIdArgTuple:
5937 case TypeTableEntryIdPromise:5937 case ZigTypeIdPromise:
5938 zig_unreachable();5938 zig_unreachable();
5939 case TypeTableEntryIdErrorUnion:5939 case ZigTypeIdErrorUnion:
5940 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);5940 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
5941 case TypeTableEntryIdPointer:5941 case ZigTypeIdPointer:
5942 return hash_ptr(x.data.pointer.child_type) +5942 return hash_ptr(x.data.pointer.child_type) +
5943 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +5943 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
5944 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +5944 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
...@@ -5946,10 +5946,10 @@ uint32_t type_id_hash(TypeId x) {...@@ -5946,10 +5946,10 @@ uint32_t type_id_hash(TypeId x) {
5946 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +5946 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
5947 (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +5947 (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +
5948 (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);5948 (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);
5949 case TypeTableEntryIdArray:5949 case ZigTypeIdArray:
5950 return hash_ptr(x.data.array.child_type) +5950 return hash_ptr(x.data.array.child_type) +
5951 ((uint32_t)x.data.array.size ^ (uint32_t)2122979968);5951 ((uint32_t)x.data.array.size ^ (uint32_t)2122979968);
5952 case TypeTableEntryIdInt:5952 case ZigTypeIdInt:
5953 return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +5953 return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +
5954 (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);5954 (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);
5955 }5955 }
...@@ -5960,34 +5960,34 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5960,34 +5960,34 @@ bool type_id_eql(TypeId a, TypeId b) {
5960 if (a.id != b.id)5960 if (a.id != b.id)
5961 return false;5961 return false;
5962 switch (a.id) {5962 switch (a.id) {
5963 case TypeTableEntryIdInvalid:5963 case ZigTypeIdInvalid:
5964 case TypeTableEntryIdMetaType:5964 case ZigTypeIdMetaType:
5965 case TypeTableEntryIdVoid:5965 case ZigTypeIdVoid:
5966 case TypeTableEntryIdBool:5966 case ZigTypeIdBool:
5967 case TypeTableEntryIdUnreachable:5967 case ZigTypeIdUnreachable:
5968 case TypeTableEntryIdFloat:5968 case ZigTypeIdFloat:
5969 case TypeTableEntryIdStruct:5969 case ZigTypeIdStruct:
5970 case TypeTableEntryIdComptimeFloat:5970 case ZigTypeIdComptimeFloat:
5971 case TypeTableEntryIdComptimeInt:5971 case ZigTypeIdComptimeInt:
5972 case TypeTableEntryIdUndefined:5972 case ZigTypeIdUndefined:
5973 case TypeTableEntryIdNull:5973 case ZigTypeIdNull:
5974 case TypeTableEntryIdOptional:5974 case ZigTypeIdOptional:
5975 case TypeTableEntryIdPromise:5975 case ZigTypeIdPromise:
5976 case TypeTableEntryIdErrorSet:5976 case ZigTypeIdErrorSet:
5977 case TypeTableEntryIdEnum:5977 case ZigTypeIdEnum:
5978 case TypeTableEntryIdUnion:5978 case ZigTypeIdUnion:
5979 case TypeTableEntryIdFn:5979 case ZigTypeIdFn:
5980 case TypeTableEntryIdNamespace:5980 case ZigTypeIdNamespace:
5981 case TypeTableEntryIdBlock:5981 case ZigTypeIdBlock:
5982 case TypeTableEntryIdBoundFn:5982 case ZigTypeIdBoundFn:
5983 case TypeTableEntryIdArgTuple:5983 case ZigTypeIdArgTuple:
5984 case TypeTableEntryIdOpaque:5984 case ZigTypeIdOpaque:
5985 zig_unreachable();5985 zig_unreachable();
5986 case TypeTableEntryIdErrorUnion:5986 case ZigTypeIdErrorUnion:
5987 return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&5987 return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&
5988 a.data.error_union.payload_type == b.data.error_union.payload_type;5988 a.data.error_union.payload_type == b.data.error_union.payload_type;
59895989
5990 case TypeTableEntryIdPointer:5990 case ZigTypeIdPointer:
5991 return a.data.pointer.child_type == b.data.pointer.child_type &&5991 return a.data.pointer.child_type == b.data.pointer.child_type &&
5992 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&5992 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
5993 a.data.pointer.is_const == b.data.pointer.is_const &&5993 a.data.pointer.is_const == b.data.pointer.is_const &&
...@@ -5995,10 +5995,10 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5995,10 +5995,10 @@ bool type_id_eql(TypeId a, TypeId b) {
5995 a.data.pointer.alignment == b.data.pointer.alignment &&5995 a.data.pointer.alignment == b.data.pointer.alignment &&
5996 a.data.pointer.bit_offset == b.data.pointer.bit_offset &&5996 a.data.pointer.bit_offset == b.data.pointer.bit_offset &&
5997 a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;5997 a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;
5998 case TypeTableEntryIdArray:5998 case ZigTypeIdArray:
5999 return a.data.array.child_type == b.data.array.child_type &&5999 return a.data.array.child_type == b.data.array.child_type &&
6000 a.data.array.size == b.data.array.size;6000 a.data.array.size == b.data.array.size;
6001 case TypeTableEntryIdInt:6001 case ZigTypeIdInt:
6002 return a.data.integer.is_signed == b.data.integer.is_signed &&6002 return a.data.integer.is_signed == b.data.integer.is_signed &&
6003 a.data.integer.bit_count == b.data.integer.bit_count;6003 a.data.integer.bit_count == b.data.integer.bit_count;
6004 }6004 }
...@@ -6050,7 +6050,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {...@@ -6050,7 +6050,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
6050}6050}
60516051
6052void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {6052void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
6053 assert(const_val->type->id == TypeTableEntryIdArray);6053 assert(const_val->type->id == ZigTypeIdArray);
6054 if (const_val->data.x_array.special == ConstArraySpecialUndef) {6054 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
6055 const_val->data.x_array.special = ConstArraySpecialNone;6055 const_val->data.x_array.special = ConstArraySpecialNone;
6056 size_t elem_count = const_val->type->data.array.len;6056 size_t elem_count = const_val->type->data.array.len;
...@@ -6072,43 +6072,43 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {...@@ -6072,43 +6072,43 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
6072ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {6072ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {
6073 assert(value->type);6073 assert(value->type);
6074 ZigType *type_entry = value->type;6074 ZigType *type_entry = value->type;
6075 if (type_entry->id == TypeTableEntryIdArray) {6075 if (type_entry->id == ZigTypeIdArray) {
6076 expand_undef_array(g, value);6076 expand_undef_array(g, value);
6077 return &value->data.x_array.s_none.parent;6077 return &value->data.x_array.s_none.parent;
6078 } else if (type_entry->id == TypeTableEntryIdStruct) {6078 } else if (type_entry->id == ZigTypeIdStruct) {
6079 return &value->data.x_struct.parent;6079 return &value->data.x_struct.parent;
6080 } else if (type_entry->id == TypeTableEntryIdUnion) {6080 } else if (type_entry->id == ZigTypeIdUnion) {
6081 return &value->data.x_union.parent;6081 return &value->data.x_union.parent;
6082 }6082 }
6083 return nullptr;6083 return nullptr;
6084}6084}
60856085
6086static const ZigTypeId all_type_ids[] = {6086static const ZigTypeId all_type_ids[] = {
6087 TypeTableEntryIdMetaType,6087 ZigTypeIdMetaType,
6088 TypeTableEntryIdVoid,6088 ZigTypeIdVoid,
6089 TypeTableEntryIdBool,6089 ZigTypeIdBool,
6090 TypeTableEntryIdUnreachable,6090 ZigTypeIdUnreachable,
6091 TypeTableEntryIdInt,6091 ZigTypeIdInt,
6092 TypeTableEntryIdFloat,6092 ZigTypeIdFloat,
6093 TypeTableEntryIdPointer,6093 ZigTypeIdPointer,
6094 TypeTableEntryIdArray,6094 ZigTypeIdArray,
6095 TypeTableEntryIdStruct,6095 ZigTypeIdStruct,
6096 TypeTableEntryIdComptimeFloat,6096 ZigTypeIdComptimeFloat,
6097 TypeTableEntryIdComptimeInt,6097 ZigTypeIdComptimeInt,
6098 TypeTableEntryIdUndefined,6098 ZigTypeIdUndefined,
6099 TypeTableEntryIdNull,6099 ZigTypeIdNull,
6100 TypeTableEntryIdOptional,6100 ZigTypeIdOptional,
6101 TypeTableEntryIdErrorUnion,6101 ZigTypeIdErrorUnion,
6102 TypeTableEntryIdErrorSet,6102 ZigTypeIdErrorSet,
6103 TypeTableEntryIdEnum,6103 ZigTypeIdEnum,
6104 TypeTableEntryIdUnion,6104 ZigTypeIdUnion,
6105 TypeTableEntryIdFn,6105 ZigTypeIdFn,
6106 TypeTableEntryIdNamespace,6106 ZigTypeIdNamespace,
6107 TypeTableEntryIdBlock,6107 ZigTypeIdBlock,
6108 TypeTableEntryIdBoundFn,6108 ZigTypeIdBoundFn,
6109 TypeTableEntryIdArgTuple,6109 ZigTypeIdArgTuple,
6110 TypeTableEntryIdOpaque,6110 ZigTypeIdOpaque,
6111 TypeTableEntryIdPromise,6111 ZigTypeIdPromise,
6112};6112};
61136113
6114ZigTypeId type_id_at_index(size_t index) {6114ZigTypeId type_id_at_index(size_t index) {
...@@ -6122,59 +6122,59 @@ size_t type_id_len() {...@@ -6122,59 +6122,59 @@ size_t type_id_len() {
61226122
6123size_t type_id_index(ZigType *entry) {6123size_t type_id_index(ZigType *entry) {
6124 switch (entry->id) {6124 switch (entry->id) {
6125 case TypeTableEntryIdInvalid:6125 case ZigTypeIdInvalid:
6126 zig_unreachable();6126 zig_unreachable();
6127 case TypeTableEntryIdMetaType:6127 case ZigTypeIdMetaType:
6128 return 0;6128 return 0;
6129 case TypeTableEntryIdVoid:6129 case ZigTypeIdVoid:
6130 return 1;6130 return 1;
6131 case TypeTableEntryIdBool:6131 case ZigTypeIdBool:
6132 return 2;6132 return 2;
6133 case TypeTableEntryIdUnreachable:6133 case ZigTypeIdUnreachable:
6134 return 3;6134 return 3;
6135 case TypeTableEntryIdInt:6135 case ZigTypeIdInt:
6136 return 4;6136 return 4;
6137 case TypeTableEntryIdFloat:6137 case ZigTypeIdFloat:
6138 return 5;6138 return 5;
6139 case TypeTableEntryIdPointer:6139 case ZigTypeIdPointer:
6140 return 6;6140 return 6;
6141 case TypeTableEntryIdArray:6141 case ZigTypeIdArray:
6142 return 7;6142 return 7;
6143 case TypeTableEntryIdStruct:6143 case ZigTypeIdStruct:
6144 if (entry->data.structure.is_slice)6144 if (entry->data.structure.is_slice)
6145 return 6;6145 return 6;
6146 return 8;6146 return 8;
6147 case TypeTableEntryIdComptimeFloat:6147 case ZigTypeIdComptimeFloat:
6148 return 9;6148 return 9;
6149 case TypeTableEntryIdComptimeInt:6149 case ZigTypeIdComptimeInt:
6150 return 10;6150 return 10;
6151 case TypeTableEntryIdUndefined:6151 case ZigTypeIdUndefined:
6152 return 11;6152 return 11;
6153 case TypeTableEntryIdNull:6153 case ZigTypeIdNull:
6154 return 12;6154 return 12;
6155 case TypeTableEntryIdOptional:6155 case ZigTypeIdOptional:
6156 return 13;6156 return 13;
6157 case TypeTableEntryIdErrorUnion:6157 case ZigTypeIdErrorUnion:
6158 return 14;6158 return 14;
6159 case TypeTableEntryIdErrorSet:6159 case ZigTypeIdErrorSet:
6160 return 15;6160 return 15;
6161 case TypeTableEntryIdEnum:6161 case ZigTypeIdEnum:
6162 return 16;6162 return 16;
6163 case TypeTableEntryIdUnion:6163 case ZigTypeIdUnion:
6164 return 17;6164 return 17;
6165 case TypeTableEntryIdFn:6165 case ZigTypeIdFn:
6166 return 18;6166 return 18;
6167 case TypeTableEntryIdNamespace:6167 case ZigTypeIdNamespace:
6168 return 19;6168 return 19;
6169 case TypeTableEntryIdBlock:6169 case ZigTypeIdBlock:
6170 return 20;6170 return 20;
6171 case TypeTableEntryIdBoundFn:6171 case ZigTypeIdBoundFn:
6172 return 21;6172 return 21;
6173 case TypeTableEntryIdArgTuple:6173 case ZigTypeIdArgTuple:
6174 return 22;6174 return 22;
6175 case TypeTableEntryIdOpaque:6175 case ZigTypeIdOpaque:
6176 return 23;6176 return 23;
6177 case TypeTableEntryIdPromise:6177 case ZigTypeIdPromise:
6178 return 24;6178 return 24;
6179 }6179 }
6180 zig_unreachable();6180 zig_unreachable();
...@@ -6182,57 +6182,57 @@ size_t type_id_index(ZigType *entry) {...@@ -6182,57 +6182,57 @@ size_t type_id_index(ZigType *entry) {
61826182
6183const char *type_id_name(ZigTypeId id) {6183const char *type_id_name(ZigTypeId id) {
6184 switch (id) {6184 switch (id) {
6185 case TypeTableEntryIdInvalid:6185 case ZigTypeIdInvalid:
6186 zig_unreachable();6186 zig_unreachable();
6187 case TypeTableEntryIdMetaType:6187 case ZigTypeIdMetaType:
6188 return "Type";6188 return "Type";
6189 case TypeTableEntryIdVoid:6189 case ZigTypeIdVoid:
6190 return "Void";6190 return "Void";
6191 case TypeTableEntryIdBool:6191 case ZigTypeIdBool:
6192 return "Bool";6192 return "Bool";
6193 case TypeTableEntryIdUnreachable:6193 case ZigTypeIdUnreachable:
6194 return "NoReturn";6194 return "NoReturn";
6195 case TypeTableEntryIdInt:6195 case ZigTypeIdInt:
6196 return "Int";6196 return "Int";
6197 case TypeTableEntryIdFloat:6197 case ZigTypeIdFloat:
6198 return "Float";6198 return "Float";
6199 case TypeTableEntryIdPointer:6199 case ZigTypeIdPointer:
6200 return "Pointer";6200 return "Pointer";
6201 case TypeTableEntryIdArray:6201 case ZigTypeIdArray:
6202 return "Array";6202 return "Array";
6203 case TypeTableEntryIdStruct:6203 case ZigTypeIdStruct:
6204 return "Struct";6204 return "Struct";
6205 case TypeTableEntryIdComptimeFloat:6205 case ZigTypeIdComptimeFloat:
6206 return "ComptimeFloat";6206 return "ComptimeFloat";
6207 case TypeTableEntryIdComptimeInt:6207 case ZigTypeIdComptimeInt:
6208 return "ComptimeInt";6208 return "ComptimeInt";
6209 case TypeTableEntryIdUndefined:6209 case ZigTypeIdUndefined:
6210 return "Undefined";6210 return "Undefined";
6211 case TypeTableEntryIdNull:6211 case ZigTypeIdNull:
6212 return "Null";6212 return "Null";
6213 case TypeTableEntryIdOptional:6213 case ZigTypeIdOptional:
6214 return "Optional";6214 return "Optional";
6215 case TypeTableEntryIdErrorUnion:6215 case ZigTypeIdErrorUnion:
6216 return "ErrorUnion";6216 return "ErrorUnion";
6217 case TypeTableEntryIdErrorSet:6217 case ZigTypeIdErrorSet:
6218 return "ErrorSet";6218 return "ErrorSet";
6219 case TypeTableEntryIdEnum:6219 case ZigTypeIdEnum:
6220 return "Enum";6220 return "Enum";
6221 case TypeTableEntryIdUnion:6221 case ZigTypeIdUnion:
6222 return "Union";6222 return "Union";
6223 case TypeTableEntryIdFn:6223 case ZigTypeIdFn:
6224 return "Fn";6224 return "Fn";
6225 case TypeTableEntryIdNamespace:6225 case ZigTypeIdNamespace:
6226 return "Namespace";6226 return "Namespace";
6227 case TypeTableEntryIdBlock:6227 case ZigTypeIdBlock:
6228 return "Block";6228 return "Block";
6229 case TypeTableEntryIdBoundFn:6229 case ZigTypeIdBoundFn:
6230 return "BoundFn";6230 return "BoundFn";
6231 case TypeTableEntryIdArgTuple:6231 case ZigTypeIdArgTuple:
6232 return "ArgTuple";6232 return "ArgTuple";
6233 case TypeTableEntryIdOpaque:6233 case ZigTypeIdOpaque:
6234 return "Opaque";6234 return "Opaque";
6235 case TypeTableEntryIdPromise:6235 case ZigTypeIdPromise:
6236 return "Promise";6236 return "Promise";
6237 }6237 }
6238 zig_unreachable();6238 zig_unreachable();
...@@ -6272,18 +6272,18 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {...@@ -6272,18 +6272,18 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {
62726272
6273 // We need to make this function work without requiring ensure_complete_type6273 // We need to make this function work without requiring ensure_complete_type
6274 // so that we can have structs with fields that are pointers to their own type.6274 // so that we can have structs with fields that are pointers to their own type.
6275 if (type_entry->id == TypeTableEntryIdStruct) {6275 if (type_entry->id == ZigTypeIdStruct) {
6276 assert(type_entry->data.structure.abi_alignment != 0);6276 assert(type_entry->data.structure.abi_alignment != 0);
6277 return type_entry->data.structure.abi_alignment;6277 return type_entry->data.structure.abi_alignment;
6278 } else if (type_entry->id == TypeTableEntryIdUnion) {6278 } else if (type_entry->id == ZigTypeIdUnion) {
6279 assert(type_entry->data.unionation.abi_alignment != 0);6279 assert(type_entry->data.unionation.abi_alignment != 0);
6280 return type_entry->data.unionation.abi_alignment;6280 return type_entry->data.unionation.abi_alignment;
6281 } else if (type_entry->id == TypeTableEntryIdOpaque) {6281 } else if (type_entry->id == ZigTypeIdOpaque) {
6282 return 1;6282 return 1;
6283 } else {6283 } else {
6284 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);6284 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
6285 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw6285 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
6286 if (type_entry->id == TypeTableEntryIdPromise && llvm_alignment < 8) {6286 if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) {
6287 return 8;6287 return 8;
6288 }6288 }
6289 return llvm_alignment;6289 return llvm_alignment;
...@@ -6317,7 +6317,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {...@@ -6317,7 +6317,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
6317}6317}
63186318
6319bool type_is_global_error_set(ZigType *err_set_type) {6319bool type_is_global_error_set(ZigType *err_set_type) {
6320 assert(err_set_type->id == TypeTableEntryIdErrorSet);6320 assert(err_set_type->id == ZigTypeIdErrorSet);
6321 assert(err_set_type->data.error_set.infer_fn == nullptr);6321 assert(err_set_type->data.error_set.infer_fn == nullptr);
6322 return err_set_type->data.error_set.err_count == UINT32_MAX;6322 return err_set_type->data.error_set.err_count == UINT32_MAX;
6323}6323}
...@@ -6327,7 +6327,7 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {...@@ -6327,7 +6327,7 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {
6327}6327}
63286328
6329bool type_can_fail(ZigType *type_entry) {6329bool type_can_fail(ZigType *type_entry) {
6330 return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet;6330 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
6331}6331}
63326332
6333bool fn_type_can_fail(FnTypeId *fn_type_id) {6333bool fn_type_can_fail(FnTypeId *fn_type_id) {
src/codegen.cpp+277-277
...@@ -533,7 +533,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {...@@ -533,7 +533,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
533 }533 }
534534
535 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;535 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
536 if (return_type->id == TypeTableEntryIdUnreachable) {536 if (return_type->id == ZigTypeIdUnreachable) {
537 addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");537 addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");
538 }538 }
539539
...@@ -600,10 +600,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {...@@ -600,10 +600,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
600 if (param_info->is_noalias) {600 if (param_info->is_noalias) {
601 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias");601 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias");
602 }602 }
603 if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) {603 if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {
604 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly");604 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly");
605 }605 }
606 if (param_type->id == TypeTableEntryIdPointer) {606 if (param_type->id == ZigTypeIdPointer) {
607 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull");607 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull");
608 }608 }
609 }609 }
...@@ -693,7 +693,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,...@@ -693,7 +693,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,
693{693{
694 char fn_name[64];694 char fn_name[64];
695695
696 assert(type_entry->id == TypeTableEntryIdInt);696 assert(type_entry->id == ZigTypeIdInt);
697 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;697 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
698 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);698 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);
699699
...@@ -713,7 +713,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,...@@ -713,7 +713,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,
713}713}
714714
715static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {715static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {
716 assert(type_entry->id == TypeTableEntryIdInt);716 assert(type_entry->id == ZigTypeIdInt);
717717
718 ZigLLVMFnKey key = {};718 ZigLLVMFnKey key = {};
719 key.id = ZigLLVMFnIdOverflowArithmetic;719 key.id = ZigLLVMFnIdOverflowArithmetic;
...@@ -743,7 +743,7 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubM...@@ -743,7 +743,7 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubM
743}743}
744744
745static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) {745static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) {
746 assert(type_entry->id == TypeTableEntryIdFloat);746 assert(type_entry->id == ZigTypeIdFloat);
747747
748 ZigLLVMFnKey key = {};748 ZigLLVMFnKey key = {};
749 key.id = fn_id;749 key.id = fn_id;
...@@ -788,7 +788,7 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR...@@ -788,7 +788,7 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR
788}788}
789789
790static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) {790static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) {
791 assert(ptr_type->id == TypeTableEntryIdPointer);791 assert(ptr_type->id == ZigTypeIdPointer);
792 return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);792 return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
793}793}
794794
...@@ -806,7 +806,7 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig...@@ -806,7 +806,7 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
806}806}
807807
808static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {808static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
809 assert(ptr_type->id == TypeTableEntryIdPointer);809 assert(ptr_type->id == ZigTypeIdPointer);
810 return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);810 return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);
811}811}
812812
...@@ -815,7 +815,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type...@@ -815,7 +815,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
815 if (handle_is_ptr(type)) {815 if (handle_is_ptr(type)) {
816 return ptr;816 return ptr;
817 } else {817 } else {
818 assert(ptr_type->id == TypeTableEntryIdPointer);818 assert(ptr_type->id == ZigTypeIdPointer);
819 return gen_load(g, ptr, ptr_type, "");819 return gen_load(g, ptr, ptr_type, "");
820 }820 }
821 } else {821 } else {
...@@ -1656,17 +1656,17 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z...@@ -1656,17 +1656,17 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z
16561656
1657 uint64_t actual_bits;1657 uint64_t actual_bits;
1658 uint64_t wanted_bits;1658 uint64_t wanted_bits;
1659 if (actual_type->id == TypeTableEntryIdFloat) {1659 if (actual_type->id == ZigTypeIdFloat) {
1660 actual_bits = actual_type->data.floating.bit_count;1660 actual_bits = actual_type->data.floating.bit_count;
1661 wanted_bits = wanted_type->data.floating.bit_count;1661 wanted_bits = wanted_type->data.floating.bit_count;
1662 } else if (actual_type->id == TypeTableEntryIdInt) {1662 } else if (actual_type->id == ZigTypeIdInt) {
1663 actual_bits = actual_type->data.integral.bit_count;1663 actual_bits = actual_type->data.integral.bit_count;
1664 wanted_bits = wanted_type->data.integral.bit_count;1664 wanted_bits = wanted_type->data.integral.bit_count;
1665 } else {1665 } else {
1666 zig_unreachable();1666 zig_unreachable();
1667 }1667 }
16681668
1669 if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&1669 if (actual_bits >= wanted_bits && actual_type->id == ZigTypeIdInt &&
1670 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&1670 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
1671 want_runtime_safety)1671 want_runtime_safety)
1672 {1672 {
...@@ -1686,9 +1686,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z...@@ -1686,9 +1686,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z
1686 if (actual_bits == wanted_bits) {1686 if (actual_bits == wanted_bits) {
1687 return expr_val;1687 return expr_val;
1688 } else if (actual_bits < wanted_bits) {1688 } else if (actual_bits < wanted_bits) {
1689 if (actual_type->id == TypeTableEntryIdFloat) {1689 if (actual_type->id == ZigTypeIdFloat) {
1690 return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");1690 return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");
1691 } else if (actual_type->id == TypeTableEntryIdInt) {1691 } else if (actual_type->id == ZigTypeIdInt) {
1692 if (actual_type->data.integral.is_signed) {1692 if (actual_type->data.integral.is_signed) {
1693 return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");1693 return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");
1694 } else {1694 } else {
...@@ -1698,9 +1698,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z...@@ -1698,9 +1698,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z
1698 zig_unreachable();1698 zig_unreachable();
1699 }1699 }
1700 } else if (actual_bits > wanted_bits) {1700 } else if (actual_bits > wanted_bits) {
1701 if (actual_type->id == TypeTableEntryIdFloat) {1701 if (actual_type->id == ZigTypeIdFloat) {
1702 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");1702 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1703 } else if (actual_type->id == TypeTableEntryIdInt) {1703 } else if (actual_type->id == ZigTypeIdInt) {
1704 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");1704 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1705 if (!want_runtime_safety) {1705 if (!want_runtime_safety) {
1706 return trunc_val;1706 return trunc_val;
...@@ -1792,7 +1792,7 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) {...@@ -1792,7 +1792,7 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) {
1792static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,1792static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
1793 LLVMValueRef value)1793 LLVMValueRef value)
1794{1794{
1795 assert(ptr_type->id == TypeTableEntryIdPointer);1795 assert(ptr_type->id == ZigTypeIdPointer);
1796 ZigType *child_type = ptr_type->data.pointer.child_type;1796 ZigType *child_type = ptr_type->data.pointer.child_type;
17971797
1798 if (!type_has_bits(child_type))1798 if (!type_has_bits(child_type))
...@@ -1878,7 +1878,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -1878,7 +1878,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1878 render_const_val_global(g, &instruction->value, "");1878 render_const_val_global(g, &instruction->value, "");
1879 ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);1879 ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
1880 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, "");1880 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, "");
1881 } else if (instruction->value.type->id == TypeTableEntryIdPointer) {1881 } else if (instruction->value.type->id == ZigTypeIdPointer) {
1882 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");1882 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");
1883 } else {1883 } else {
1884 instruction->llvm_value = instruction->value.global_refs->llvm_value;1884 instruction->llvm_value = instruction->value.global_refs->llvm_value;
...@@ -1929,7 +1929,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,...@@ -1929,7 +1929,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,
1929 // if the values don't match, we have an overflow1929 // if the values don't match, we have an overflow
1930 // for signed left shifting we do the same except arithmetic shift right1930 // for signed left shifting we do the same except arithmetic shift right
19311931
1932 assert(type_entry->id == TypeTableEntryIdInt);1932 assert(type_entry->id == ZigTypeIdInt);
19331933
1934 LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");1934 LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");
1935 LLVMValueRef orig_val;1935 LLVMValueRef orig_val;
...@@ -1954,7 +1954,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,...@@ -1954,7 +1954,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,
1954static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,1954static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,
1955 LLVMValueRef val1, LLVMValueRef val2)1955 LLVMValueRef val1, LLVMValueRef val2)
1956{1956{
1957 assert(type_entry->id == TypeTableEntryIdInt);1957 assert(type_entry->id == ZigTypeIdInt);
19581958
1959 LLVMValueRef result;1959 LLVMValueRef result;
1960 if (type_entry->data.integral.is_signed) {1960 if (type_entry->data.integral.is_signed) {
...@@ -1977,7 +1977,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,...@@ -1977,7 +1977,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,
1977}1977}
19781978
1979static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {1979static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
1980 if (type_entry->id == TypeTableEntryIdInt)1980 if (type_entry->id == ZigTypeIdInt)
1981 return val;1981 return val;
19821982
1983 LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);1983 LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);
...@@ -1985,7 +1985,7 @@ static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry)...@@ -1985,7 +1985,7 @@ static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry)
1985}1985}
19861986
1987static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {1987static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
1988 if (type_entry->id == TypeTableEntryIdInt)1988 if (type_entry->id == ZigTypeIdInt)
1989 return val;1989 return val;
19901990
1991 LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil);1991 LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil);
...@@ -2023,11 +2023,11 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2023,11 +2023,11 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
2023 ZigLLVMSetFastMath(g->builder, want_fast_math);2023 ZigLLVMSetFastMath(g->builder, want_fast_math);
20242024
2025 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);2025 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
2026 if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {2026 if (want_runtime_safety && (want_fast_math || type_entry->id != ZigTypeIdFloat)) {
2027 LLVMValueRef is_zero_bit;2027 LLVMValueRef is_zero_bit;
2028 if (type_entry->id == TypeTableEntryIdInt) {2028 if (type_entry->id == ZigTypeIdInt) {
2029 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");2029 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");
2030 } else if (type_entry->id == TypeTableEntryIdFloat) {2030 } else if (type_entry->id == ZigTypeIdFloat) {
2031 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");2031 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
2032 } else {2032 } else {
2033 zig_unreachable();2033 zig_unreachable();
...@@ -2041,7 +2041,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2041,7 +2041,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
20412041
2042 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);2042 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);
20432043
2044 if (type_entry->id == TypeTableEntryIdInt && type_entry->data.integral.is_signed) {2044 if (type_entry->id == ZigTypeIdInt && type_entry->data.integral.is_signed) {
2045 LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);2045 LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);
2046 BigInt int_min_bi = {0};2046 BigInt int_min_bi = {0};
2047 eval_min_max_value_int(g, type_entry, &int_min_bi, false);2047 eval_min_max_value_int(g, type_entry, &int_min_bi, false);
...@@ -2060,7 +2060,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2060,7 +2060,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
2060 }2060 }
2061 }2061 }
20622062
2063 if (type_entry->id == TypeTableEntryIdFloat) {2063 if (type_entry->id == ZigTypeIdFloat) {
2064 LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");2064 LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");
2065 switch (div_kind) {2065 switch (div_kind) {
2066 case DivKindFloat:2066 case DivKindFloat:
...@@ -2111,7 +2111,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2111,7 +2111,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
2111 zig_unreachable();2111 zig_unreachable();
2112 }2112 }
21132113
2114 assert(type_entry->id == TypeTableEntryIdInt);2114 assert(type_entry->id == ZigTypeIdInt);
21152115
2116 switch (div_kind) {2116 switch (div_kind) {
2117 case DivKindFloat:2117 case DivKindFloat:
...@@ -2184,10 +2184,10 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2184,10 +2184,10 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
2184 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);2184 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
2185 if (want_runtime_safety) {2185 if (want_runtime_safety) {
2186 LLVMValueRef is_zero_bit;2186 LLVMValueRef is_zero_bit;
2187 if (type_entry->id == TypeTableEntryIdInt) {2187 if (type_entry->id == ZigTypeIdInt) {
2188 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;2188 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;
2189 is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");2189 is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");
2190 } else if (type_entry->id == TypeTableEntryIdFloat) {2190 } else if (type_entry->id == ZigTypeIdFloat) {
2191 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");2191 is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
2192 } else {2192 } else {
2193 zig_unreachable();2193 zig_unreachable();
...@@ -2202,7 +2202,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2202,7 +2202,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
2202 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);2202 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
2203 }2203 }
22042204
2205 if (type_entry->id == TypeTableEntryIdFloat) {2205 if (type_entry->id == ZigTypeIdFloat) {
2206 if (rem_kind == RemKindRem) {2206 if (rem_kind == RemKindRem) {
2207 return LLVMBuildFRem(g->builder, val1, val2, "");2207 return LLVMBuildFRem(g->builder, val1, val2, "");
2208 } else {2208 } else {
...@@ -2213,7 +2213,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2213,7 +2213,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
2213 return LLVMBuildSelect(g->builder, ltz, c, a, "");2213 return LLVMBuildSelect(g->builder, ltz, c, a, "");
2214 }2214 }
2215 } else {2215 } else {
2216 assert(type_entry->id == TypeTableEntryIdInt);2216 assert(type_entry->id == ZigTypeIdInt);
2217 if (type_entry->data.integral.is_signed) {2217 if (type_entry->data.integral.is_signed) {
2218 if (rem_kind == RemKindRem) {2218 if (rem_kind == RemKindRem) {
2219 return LLVMBuildSRem(g->builder, val1, val2, "");2219 return LLVMBuildSRem(g->builder, val1, val2, "");
...@@ -2241,8 +2241,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2241,8 +2241,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2241 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||2241 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
2242 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||2242 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2243 op_id == IrBinOpBitShiftRightExact ||2243 op_id == IrBinOpBitShiftRightExact ||
2244 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||2244 (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) ||
2245 (op1->value.type->id == TypeTableEntryIdPointer &&2245 (op1->value.type->id == ZigTypeIdPointer &&
2246 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&2246 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2247 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)2247 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
2248 );2248 );
...@@ -2272,16 +2272,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2272,16 +2272,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2272 case IrBinOpCmpGreaterThan:2272 case IrBinOpCmpGreaterThan:
2273 case IrBinOpCmpLessOrEq:2273 case IrBinOpCmpLessOrEq:
2274 case IrBinOpCmpGreaterOrEq:2274 case IrBinOpCmpGreaterOrEq:
2275 if (type_entry->id == TypeTableEntryIdFloat) {2275 if (type_entry->id == ZigTypeIdFloat) {
2276 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2276 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2277 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);2277 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
2278 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");2278 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
2279 } else if (type_entry->id == TypeTableEntryIdInt) {2279 } else if (type_entry->id == ZigTypeIdInt) {
2280 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);2280 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);
2281 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");2281 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
2282 } else if (type_entry->id == TypeTableEntryIdEnum ||2282 } else if (type_entry->id == ZigTypeIdEnum ||
2283 type_entry->id == TypeTableEntryIdErrorSet ||2283 type_entry->id == ZigTypeIdErrorSet ||
2284 type_entry->id == TypeTableEntryIdBool ||2284 type_entry->id == ZigTypeIdBool ||
2285 get_codegen_ptr_type(type_entry) != nullptr)2285 get_codegen_ptr_type(type_entry) != nullptr)
2286 {2286 {
2287 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);2287 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
...@@ -2291,14 +2291,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2291,14 +2291,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2291 }2291 }
2292 case IrBinOpAdd:2292 case IrBinOpAdd:
2293 case IrBinOpAddWrap:2293 case IrBinOpAddWrap:
2294 if (type_entry->id == TypeTableEntryIdPointer) {2294 if (type_entry->id == ZigTypeIdPointer) {
2295 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);2295 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2296 // TODO runtime safety2296 // TODO runtime safety
2297 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");2297 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
2298 } else if (type_entry->id == TypeTableEntryIdFloat) {2298 } else if (type_entry->id == ZigTypeIdFloat) {
2299 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2299 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2300 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");2300 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
2301 } else if (type_entry->id == TypeTableEntryIdInt) {2301 } else if (type_entry->id == ZigTypeIdInt) {
2302 bool is_wrapping = (op_id == IrBinOpAddWrap);2302 bool is_wrapping = (op_id == IrBinOpAddWrap);
2303 if (is_wrapping) {2303 if (is_wrapping) {
2304 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");2304 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
...@@ -2321,7 +2321,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2321,7 +2321,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2321 case IrBinOpBitShiftLeftLossy:2321 case IrBinOpBitShiftLeftLossy:
2322 case IrBinOpBitShiftLeftExact:2322 case IrBinOpBitShiftLeftExact:
2323 {2323 {
2324 assert(type_entry->id == TypeTableEntryIdInt);2324 assert(type_entry->id == ZigTypeIdInt);
2325 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2325 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
2326 type_entry, op2_value);2326 type_entry, op2_value);
2327 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);2327 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
...@@ -2338,7 +2338,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2338,7 +2338,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2338 case IrBinOpBitShiftRightLossy:2338 case IrBinOpBitShiftRightLossy:
2339 case IrBinOpBitShiftRightExact:2339 case IrBinOpBitShiftRightExact:
2340 {2340 {
2341 assert(type_entry->id == TypeTableEntryIdInt);2341 assert(type_entry->id == ZigTypeIdInt);
2342 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2342 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
2343 type_entry, op2_value);2343 type_entry, op2_value);
2344 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);2344 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
...@@ -2358,15 +2358,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2358,15 +2358,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2358 }2358 }
2359 case IrBinOpSub:2359 case IrBinOpSub:
2360 case IrBinOpSubWrap:2360 case IrBinOpSubWrap:
2361 if (type_entry->id == TypeTableEntryIdPointer) {2361 if (type_entry->id == ZigTypeIdPointer) {
2362 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);2362 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2363 // TODO runtime safety2363 // TODO runtime safety
2364 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");2364 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
2365 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");2365 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2366 } else if (type_entry->id == TypeTableEntryIdFloat) {2366 } else if (type_entry->id == ZigTypeIdFloat) {
2367 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2367 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2368 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");2368 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
2369 } else if (type_entry->id == TypeTableEntryIdInt) {2369 } else if (type_entry->id == ZigTypeIdInt) {
2370 bool is_wrapping = (op_id == IrBinOpSubWrap);2370 bool is_wrapping = (op_id == IrBinOpSubWrap);
2371 if (is_wrapping) {2371 if (is_wrapping) {
2372 return LLVMBuildSub(g->builder, op1_value, op2_value, "");2372 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
...@@ -2382,10 +2382,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2382,10 +2382,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2382 }2382 }
2383 case IrBinOpMult:2383 case IrBinOpMult:
2384 case IrBinOpMultWrap:2384 case IrBinOpMultWrap:
2385 if (type_entry->id == TypeTableEntryIdFloat) {2385 if (type_entry->id == ZigTypeIdFloat) {
2386 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2386 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2387 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");2387 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
2388 } else if (type_entry->id == TypeTableEntryIdInt) {2388 } else if (type_entry->id == ZigTypeIdInt) {
2389 bool is_wrapping = (op_id == IrBinOpMultWrap);2389 bool is_wrapping = (op_id == IrBinOpMultWrap);
2390 if (is_wrapping) {2390 if (is_wrapping) {
2391 return LLVMBuildMul(g->builder, op1_value, op2_value, "");2391 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
...@@ -2422,7 +2422,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2422,7 +2422,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2422}2422}
24232423
2424static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) {2424static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) {
2425 assert(err_set_type->id == TypeTableEntryIdErrorSet);2425 assert(err_set_type->id == ZigTypeIdErrorSet);
24262426
2427 if (type_is_global_error_set(err_set_type)) {2427 if (type_is_global_error_set(err_set_type)) {
2428 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);2428 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);
...@@ -2486,9 +2486,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2486,9 +2486,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2486 case CastOpResizeSlice:2486 case CastOpResizeSlice:
2487 {2487 {
2488 assert(cast_instruction->tmp_ptr);2488 assert(cast_instruction->tmp_ptr);
2489 assert(wanted_type->id == TypeTableEntryIdStruct);2489 assert(wanted_type->id == ZigTypeIdStruct);
2490 assert(wanted_type->data.structure.is_slice);2490 assert(wanted_type->data.structure.is_slice);
2491 assert(actual_type->id == TypeTableEntryIdStruct);2491 assert(actual_type->id == ZigTypeIdStruct);
2492 assert(actual_type->data.structure.is_slice);2492 assert(actual_type->data.structure.is_slice);
24932493
2494 ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;2494 ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
...@@ -2549,9 +2549,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2549,9 +2549,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2549 case CastOpBytesToSlice:2549 case CastOpBytesToSlice:
2550 {2550 {
2551 assert(cast_instruction->tmp_ptr);2551 assert(cast_instruction->tmp_ptr);
2552 assert(wanted_type->id == TypeTableEntryIdStruct);2552 assert(wanted_type->id == ZigTypeIdStruct);
2553 assert(wanted_type->data.structure.is_slice);2553 assert(wanted_type->data.structure.is_slice);
2554 assert(actual_type->id == TypeTableEntryIdArray);2554 assert(actual_type->id == ZigTypeIdArray);
25552555
2556 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;2556 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
2557 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;2557 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
...@@ -2573,14 +2573,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2573,14 +2573,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2573 return cast_instruction->tmp_ptr;2573 return cast_instruction->tmp_ptr;
2574 }2574 }
2575 case CastOpIntToFloat:2575 case CastOpIntToFloat:
2576 assert(actual_type->id == TypeTableEntryIdInt);2576 assert(actual_type->id == ZigTypeIdInt);
2577 if (actual_type->data.integral.is_signed) {2577 if (actual_type->data.integral.is_signed) {
2578 return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");2578 return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");
2579 } else {2579 } else {
2580 return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");2580 return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");
2581 }2581 }
2582 case CastOpFloatToInt: {2582 case CastOpFloatToInt: {
2583 assert(wanted_type->id == TypeTableEntryIdInt);2583 assert(wanted_type->id == ZigTypeIdInt);
2584 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));2584 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));
25852585
2586 bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);2586 bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);
...@@ -2615,8 +2615,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2615,8 +2615,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2615 return result;2615 return result;
2616 }2616 }
2617 case CastOpBoolToInt:2617 case CastOpBoolToInt:
2618 assert(wanted_type->id == TypeTableEntryIdInt);2618 assert(wanted_type->id == ZigTypeIdInt);
2619 assert(actual_type->id == TypeTableEntryIdBool);2619 assert(actual_type->id == ZigTypeIdBool);
2620 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");2620 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
2621 case CastOpErrSet:2621 case CastOpErrSet:
2622 if (ir_want_runtime_safety(g, &cast_instruction->base)) {2622 if (ir_want_runtime_safety(g, &cast_instruction->base)) {
...@@ -2627,9 +2627,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2627,9 +2627,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2627 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");2627 return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");
2628 case CastOpPtrOfArrayToSlice: {2628 case CastOpPtrOfArrayToSlice: {
2629 assert(cast_instruction->tmp_ptr);2629 assert(cast_instruction->tmp_ptr);
2630 assert(actual_type->id == TypeTableEntryIdPointer);2630 assert(actual_type->id == ZigTypeIdPointer);
2631 ZigType *array_type = actual_type->data.pointer.child_type;2631 ZigType *array_type = actual_type->data.pointer.child_type;
2632 assert(array_type->id == TypeTableEntryIdArray);2632 assert(array_type->id == ZigTypeIdArray);
26332633
2634 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,2634 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
2635 slice_ptr_index, "");2635 slice_ptr_index, "");
...@@ -2678,7 +2678,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa...@@ -2678,7 +2678,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
2678 // TODO instead of this logic, use the Noop instruction to change the type from2678 // TODO instead of this logic, use the Noop instruction to change the type from
2679 // enum_tag to the underlying int type2679 // enum_tag to the underlying int type
2680 ZigType *int_type;2680 ZigType *int_type;
2681 if (actual_type->id == TypeTableEntryIdEnum) {2681 if (actual_type->id == ZigTypeIdEnum) {
2682 int_type = actual_type->data.enumeration.tag_int_type;2682 int_type = actual_type->data.enumeration.tag_int_type;
2683 } else {2683 } else {
2684 int_type = actual_type;2684 int_type = actual_type;
...@@ -2702,7 +2702,7 @@ static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, I...@@ -2702,7 +2702,7 @@ static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, I
27022702
2703static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {2703static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
2704 ZigType *wanted_type = instruction->base.value.type;2704 ZigType *wanted_type = instruction->base.value.type;
2705 assert(wanted_type->id == TypeTableEntryIdEnum);2705 assert(wanted_type->id == ZigTypeIdEnum);
2706 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;2706 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
27072707
2708 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2708 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
...@@ -2729,10 +2729,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,...@@ -2729,10 +2729,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
27292729
2730static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {2730static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
2731 ZigType *wanted_type = instruction->base.value.type;2731 ZigType *wanted_type = instruction->base.value.type;
2732 assert(wanted_type->id == TypeTableEntryIdErrorSet);2732 assert(wanted_type->id == ZigTypeIdErrorSet);
27332733
2734 ZigType *actual_type = instruction->target->value.type;2734 ZigType *actual_type = instruction->target->value.type;
2735 assert(actual_type->id == TypeTableEntryIdInt);2735 assert(actual_type->id == ZigTypeIdInt);
2736 assert(!actual_type->data.integral.is_signed);2736 assert(!actual_type->data.integral.is_signed);
27372737
2738 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2738 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
...@@ -2746,16 +2746,16 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -2746,16 +2746,16 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
27462746
2747static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {2747static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
2748 ZigType *wanted_type = instruction->base.value.type;2748 ZigType *wanted_type = instruction->base.value.type;
2749 assert(wanted_type->id == TypeTableEntryIdInt);2749 assert(wanted_type->id == ZigTypeIdInt);
2750 assert(!wanted_type->data.integral.is_signed);2750 assert(!wanted_type->data.integral.is_signed);
27512751
2752 ZigType *actual_type = instruction->target->value.type;2752 ZigType *actual_type = instruction->target->value.type;
2753 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2753 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
27542754
2755 if (actual_type->id == TypeTableEntryIdErrorSet) {2755 if (actual_type->id == ZigTypeIdErrorSet) {
2756 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),2756 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
2757 g->err_tag_type, wanted_type, target_val);2757 g->err_tag_type, wanted_type, target_val);
2758 } else if (actual_type->id == TypeTableEntryIdErrorUnion) {2758 } else if (actual_type->id == ZigTypeIdErrorUnion) {
2759 // this should have been a compile time constant2759 // this should have been a compile time constant
2760 assert(type_has_bits(actual_type->data.error_union.err_set_type));2760 assert(type_has_bits(actual_type->data.error_union.err_set_type));
27612761
...@@ -2809,10 +2809,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst...@@ -2809,10 +2809,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
2809 case IrUnOpNegation:2809 case IrUnOpNegation:
2810 case IrUnOpNegationWrap:2810 case IrUnOpNegationWrap:
2811 {2811 {
2812 if (expr_type->id == TypeTableEntryIdFloat) {2812 if (expr_type->id == ZigTypeIdFloat) {
2813 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));2813 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
2814 return LLVMBuildFNeg(g->builder, expr, "");2814 return LLVMBuildFNeg(g->builder, expr, "");
2815 } else if (expr_type->id == TypeTableEntryIdInt) {2815 } else if (expr_type->id == ZigTypeIdInt) {
2816 if (op_id == IrUnOpNegationWrap) {2816 if (op_id == IrUnOpNegationWrap) {
2817 return LLVMBuildNeg(g->builder, expr, "");2817 return LLVMBuildNeg(g->builder, expr, "");
2818 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {2818 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
...@@ -2921,7 +2921,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2921,7 +2921,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI
29212921
2922 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);2922 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
2923 ZigType *ptr_type = instruction->ptr->value.type;2923 ZigType *ptr_type = instruction->ptr->value.type;
2924 assert(ptr_type->id == TypeTableEntryIdPointer);2924 assert(ptr_type->id == ZigTypeIdPointer);
29252925
2926 uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;2926 uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;
2927 if (unaligned_bit_count == 0)2927 if (unaligned_bit_count == 0)
...@@ -2946,7 +2946,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -2946,7 +2946,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
2946 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);2946 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
2947 LLVMValueRef value = ir_llvm_value(g, instruction->value);2947 LLVMValueRef value = ir_llvm_value(g, instruction->value);
29482948
2949 assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);2949 assert(instruction->ptr->value.type->id == ZigTypeIdPointer);
2950 ZigType *ptr_type = instruction->ptr->value.type;2950 ZigType *ptr_type = instruction->ptr->value.type;
29512951
2952 gen_assign_raw(g, ptr, ptr_type, value);2952 gen_assign_raw(g, ptr, ptr_type, value);
...@@ -2967,7 +2967,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -2967,7 +2967,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
2967static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {2967static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
2968 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);2968 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
2969 ZigType *array_ptr_type = instruction->array_ptr->value.type;2969 ZigType *array_ptr_type = instruction->array_ptr->value.type;
2970 assert(array_ptr_type->id == TypeTableEntryIdPointer);2970 assert(array_ptr_type->id == ZigTypeIdPointer);
2971 ZigType *array_type = array_ptr_type->data.pointer.child_type;2971 ZigType *array_type = array_ptr_type->data.pointer.child_type;
2972 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);2972 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
2973 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);2973 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
...@@ -2978,11 +2978,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2978,11 +2978,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
29782978
2979 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;2979 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
29802980
2981 if (array_type->id == TypeTableEntryIdArray ||2981 if (array_type->id == ZigTypeIdArray ||
2982 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))2982 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
2983 {2983 {
2984 if (array_type->id == TypeTableEntryIdPointer) {2984 if (array_type->id == ZigTypeIdPointer) {
2985 assert(array_type->data.pointer.child_type->id == TypeTableEntryIdArray);2985 assert(array_type->data.pointer.child_type->id == ZigTypeIdArray);
2986 array_type = array_type->data.pointer.child_type;2986 array_type = array_type->data.pointer.child_type;
2987 }2987 }
2988 if (safety_check_on) {2988 if (safety_check_on) {
...@@ -2994,7 +2994,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2994,7 +2994,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
2994 return array_ptr_ptr;2994 return array_ptr_ptr;
2995 }2995 }
2996 ZigType *child_type = array_type->data.array.child_type;2996 ZigType *child_type = array_type->data.array.child_type;
2997 if (child_type->id == TypeTableEntryIdStruct &&2997 if (child_type->id == ZigTypeIdStruct &&
2998 child_type->data.structure.layout == ContainerLayoutPacked)2998 child_type->data.structure.layout == ContainerLayoutPacked)
2999 {2999 {
3000 size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;3000 size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;
...@@ -3017,13 +3017,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -3017,13 +3017,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
3017 subscript_value3017 subscript_value
3018 };3018 };
3019 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");3019 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");
3020 } else if (array_type->id == TypeTableEntryIdPointer) {3020 } else if (array_type->id == ZigTypeIdPointer) {
3021 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);3021 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
3022 LLVMValueRef indices[] = {3022 LLVMValueRef indices[] = {
3023 subscript_value3023 subscript_value
3024 };3024 };
3025 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");3025 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
3026 } else if (array_type->id == TypeTableEntryIdStruct) {3026 } else if (array_type->id == ZigTypeIdStruct) {
3027 assert(array_type->data.structure.is_slice);3027 assert(array_type->data.structure.is_slice);
3028 if (!type_has_bits(instruction->base.value.type)) {3028 if (!type_has_bits(instruction->base.value.type)) {
3029 if (safety_check_on) {3029 if (safety_check_on) {
...@@ -3056,8 +3056,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -3056,8 +3056,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
30563056
3057static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {3057static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {
3058 return g->have_err_ret_tracing &&3058 return g->have_err_ret_tracing &&
3059 (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion ||3059 (fn_type_id->return_type->id == ZigTypeIdErrorUnion ||
3060 fn_type_id->return_type->id == TypeTableEntryIdErrorSet ||3060 fn_type_id->return_type->id == ZigTypeIdErrorSet ||
3061 fn_type_id->cc == CallingConventionAsync);3061 fn_type_id->cc == CallingConventionAsync);
3062}3062}
30633063
...@@ -3201,7 +3201,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3201,7 +3201,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3201 return instruction->tmp_ptr;3201 return instruction->tmp_ptr;
3202 }3202 }
32033203
3204 if (src_return_type->id == TypeTableEntryIdUnreachable) {3204 if (src_return_type->id == ZigTypeIdUnreachable) {
3205 return LLVMBuildUnreachable(g->builder);3205 return LLVMBuildUnreachable(g->builder);
3206 } else if (!ret_has_bits) {3206 } else if (!ret_has_bits) {
3207 return nullptr;3207 return nullptr;
...@@ -3221,14 +3221,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -3221,14 +3221,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
3221 IrInstructionStructFieldPtr *instruction)3221 IrInstructionStructFieldPtr *instruction)
3222{3222{
3223 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);3223 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
3224 // not necessarily a pointer. could be TypeTableEntryIdStruct3224 // not necessarily a pointer. could be ZigTypeIdStruct
3225 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;3225 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;
3226 TypeStructField *field = instruction->field;3226 TypeStructField *field = instruction->field;
32273227
3228 if (!type_has_bits(field->type_entry))3228 if (!type_has_bits(field->type_entry))
3229 return nullptr;3229 return nullptr;
32303230
3231 if (struct_ptr_type->id == TypeTableEntryIdPointer &&3231 if (struct_ptr_type->id == ZigTypeIdPointer &&
3232 struct_ptr_type->data.pointer.unaligned_bit_count != 0)3232 struct_ptr_type->data.pointer.unaligned_bit_count != 0)
3233 {3233 {
3234 return struct_ptr;3234 return struct_ptr;
...@@ -3242,9 +3242,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab...@@ -3242,9 +3242,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
3242 IrInstructionUnionFieldPtr *instruction)3242 IrInstructionUnionFieldPtr *instruction)
3243{3243{
3244 ZigType *union_ptr_type = instruction->union_ptr->value.type;3244 ZigType *union_ptr_type = instruction->union_ptr->value.type;
3245 assert(union_ptr_type->id == TypeTableEntryIdPointer);3245 assert(union_ptr_type->id == ZigTypeIdPointer);
3246 ZigType *union_type = union_ptr_type->data.pointer.child_type;3246 ZigType *union_type = union_ptr_type->data.pointer.child_type;
3247 assert(union_type->id == TypeTableEntryIdUnion);3247 assert(union_type->id == ZigTypeIdUnion);
32483248
3249 TypeUnionField *field = instruction->field;3249 TypeUnionField *field = instruction->field;
32503250
...@@ -3412,7 +3412,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3412,7 +3412,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3412}3412}
34133413
3414static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {3414static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
3415 assert(maybe_type->id == TypeTableEntryIdOptional);3415 assert(maybe_type->id == ZigTypeIdOptional);
3416 ZigType *child_type = maybe_type->data.maybe.child_type;3416 ZigType *child_type = maybe_type->data.maybe.child_type;
3417 if (child_type->zero_bits) {3417 if (child_type->zero_bits) {
3418 return maybe_handle;3418 return maybe_handle;
...@@ -3437,9 +3437,9 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,...@@ -3437,9 +3437,9 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
3437 IrInstructionUnwrapOptional *instruction)3437 IrInstructionUnwrapOptional *instruction)
3438{3438{
3439 ZigType *ptr_type = instruction->value->value.type;3439 ZigType *ptr_type = instruction->value->value.type;
3440 assert(ptr_type->id == TypeTableEntryIdPointer);3440 assert(ptr_type->id == ZigTypeIdPointer);
3441 ZigType *maybe_type = ptr_type->data.pointer.child_type;3441 ZigType *maybe_type = ptr_type->data.pointer.child_type;
3442 assert(maybe_type->id == TypeTableEntryIdOptional);3442 assert(maybe_type->id == ZigTypeIdOptional);
3443 ZigType *child_type = maybe_type->data.maybe.child_type;3443 ZigType *child_type = maybe_type->data.maybe.child_type;
3444 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);3444 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
3445 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);3445 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
...@@ -3612,7 +3612,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI...@@ -3612,7 +3612,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
3612}3612}
36133613
3614static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {3614static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
3615 assert(enum_type->id == TypeTableEntryIdEnum);3615 assert(enum_type->id == ZigTypeIdEnum);
3616 if (enum_type->data.enumeration.name_function)3616 if (enum_type->data.enumeration.name_function)
3617 return enum_type->data.enumeration.name_function;3617 return enum_type->data.enumeration.name_function;
36183618
...@@ -3710,7 +3710,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable...@@ -3710,7 +3710,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
3710 IrInstructionTagName *instruction)3710 IrInstructionTagName *instruction)
3711{3711{
3712 ZigType *enum_type = instruction->target->value.type;3712 ZigType *enum_type = instruction->target->value.type;
3713 assert(enum_type->id == TypeTableEntryIdEnum);3713 assert(enum_type->id == ZigTypeIdEnum);
37143714
3715 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);3715 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);
37163716
...@@ -3723,7 +3723,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa...@@ -3723,7 +3723,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
3723 IrInstructionFieldParentPtr *instruction)3723 IrInstructionFieldParentPtr *instruction)
3724{3724{
3725 ZigType *container_ptr_type = instruction->base.value.type;3725 ZigType *container_ptr_type = instruction->base.value.type;
3726 assert(container_ptr_type->id == TypeTableEntryIdPointer);3726 assert(container_ptr_type->id == ZigTypeIdPointer);
37273727
3728 ZigType *container_type = container_ptr_type->data.pointer.child_type;3728 ZigType *container_type = container_ptr_type->data.pointer.child_type;
37293729
...@@ -3760,27 +3760,27 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -3760,27 +3760,27 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
3760 uint32_t align_bytes;3760 uint32_t align_bytes;
3761 LLVMValueRef ptr_val;3761 LLVMValueRef ptr_val;
37623762
3763 if (target_type->id == TypeTableEntryIdPointer) {3763 if (target_type->id == ZigTypeIdPointer) {
3764 align_bytes = target_type->data.pointer.alignment;3764 align_bytes = target_type->data.pointer.alignment;
3765 ptr_val = target_val;3765 ptr_val = target_val;
3766 } else if (target_type->id == TypeTableEntryIdFn) {3766 } else if (target_type->id == ZigTypeIdFn) {
3767 align_bytes = target_type->data.fn.fn_type_id.alignment;3767 align_bytes = target_type->data.fn.fn_type_id.alignment;
3768 ptr_val = target_val;3768 ptr_val = target_val;
3769 } else if (target_type->id == TypeTableEntryIdOptional &&3769 } else if (target_type->id == ZigTypeIdOptional &&
3770 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)3770 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
3771 {3771 {
3772 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;3772 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
3773 ptr_val = target_val;3773 ptr_val = target_val;
3774 } else if (target_type->id == TypeTableEntryIdOptional &&3774 } else if (target_type->id == ZigTypeIdOptional &&
3775 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)3775 target_type->data.maybe.child_type->id == ZigTypeIdFn)
3776 {3776 {
3777 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;3777 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
3778 ptr_val = target_val;3778 ptr_val = target_val;
3779 } else if (target_type->id == TypeTableEntryIdOptional &&3779 } else if (target_type->id == ZigTypeIdOptional &&
3780 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)3780 target_type->data.maybe.child_type->id == ZigTypeIdPromise)
3781 {3781 {
3782 zig_panic("TODO audit this function");3782 zig_panic("TODO audit this function");
3783 } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) {3783 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
3784 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;3784 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
3785 align_bytes = slice_ptr_type->data.pointer.alignment;3785 align_bytes = slice_ptr_type->data.pointer.alignment;
37863786
...@@ -3878,7 +3878,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -3878,7 +3878,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
3878 success_order, failure_order, instruction->is_weak);3878 success_order, failure_order, instruction->is_weak);
38793879
3880 ZigType *maybe_type = instruction->base.value.type;3880 ZigType *maybe_type = instruction->base.value.type;
3881 assert(maybe_type->id == TypeTableEntryIdOptional);3881 assert(maybe_type->id == ZigTypeIdOptional);
3882 ZigType *child_type = maybe_type->data.maybe.child_type;3882 ZigType *child_type = maybe_type->data.maybe.child_type;
38833883
3884 if (type_is_codegen_pointer(child_type)) {3884 if (type_is_codegen_pointer(child_type)) {
...@@ -3932,7 +3932,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -3932,7 +3932,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
3932 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");3932 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
39333933
3934 ZigType *ptr_type = instruction->dest_ptr->value.type;3934 ZigType *ptr_type = instruction->dest_ptr->value.type;
3935 assert(ptr_type->id == TypeTableEntryIdPointer);3935 assert(ptr_type->id == ZigTypeIdPointer);
39363936
3937 LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ?3937 LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ?
3938 LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());3938 LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());
...@@ -3964,8 +3964,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -3964,8 +3964,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
3964 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;3964 ZigType *dest_ptr_type = instruction->dest_ptr->value.type;
3965 ZigType *src_ptr_type = instruction->src_ptr->value.type;3965 ZigType *src_ptr_type = instruction->src_ptr->value.type;
39663966
3967 assert(dest_ptr_type->id == TypeTableEntryIdPointer);3967 assert(dest_ptr_type->id == ZigTypeIdPointer);
3968 assert(src_ptr_type->id == TypeTableEntryIdPointer);3968 assert(src_ptr_type->id == ZigTypeIdPointer);
39693969
3970 LLVMValueRef is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile) ?3970 LLVMValueRef is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile) ?
3971 LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());3971 LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());
...@@ -3990,7 +3990,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3990,7 +3990,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
39903990
3991 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);3991 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
3992 ZigType *array_ptr_type = instruction->ptr->value.type;3992 ZigType *array_ptr_type = instruction->ptr->value.type;
3993 assert(array_ptr_type->id == TypeTableEntryIdPointer);3993 assert(array_ptr_type->id == ZigTypeIdPointer);
3994 ZigType *array_type = array_ptr_type->data.pointer.child_type;3994 ZigType *array_type = array_ptr_type->data.pointer.child_type;
3995 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);3995 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
39963996
...@@ -3998,10 +3998,10 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3998,10 +3998,10 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
39983998
3999 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);3999 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
40004000
4001 if (array_type->id == TypeTableEntryIdArray ||4001 if (array_type->id == ZigTypeIdArray ||
4002 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))4002 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
4003 {4003 {
4004 if (array_type->id == TypeTableEntryIdPointer) {4004 if (array_type->id == ZigTypeIdPointer) {
4005 array_type = array_type->data.pointer.child_type;4005 array_type = array_type->data.pointer.child_type;
4006 }4006 }
4007 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);4007 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
...@@ -4042,7 +4042,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -4042,7 +4042,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
4042 gen_store_untyped(g, len_value, len_field_ptr, 0, false);4042 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
40434043
4044 return tmp_struct_ptr;4044 return tmp_struct_ptr;
4045 } else if (array_type->id == TypeTableEntryIdPointer) {4045 } else if (array_type->id == ZigTypeIdPointer) {
4046 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);4046 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
4047 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);4047 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
4048 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);4048 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
...@@ -4064,7 +4064,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -4064,7 +4064,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
4064 gen_store_untyped(g, len_value, len_field_ptr, 0, false);4064 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
40654065
4066 return tmp_struct_ptr;4066 return tmp_struct_ptr;
4067 } else if (array_type->id == TypeTableEntryIdStruct) {4067 } else if (array_type->id == ZigTypeIdStruct) {
4068 assert(array_type->data.structure.is_slice);4068 assert(array_type->data.structure.is_slice);
4069 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);4069 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
4070 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);4070 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
...@@ -4179,7 +4179,7 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,...@@ -4179,7 +4179,7 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
41794179
4180static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {4180static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
4181 ZigType *int_type = instruction->result_ptr_type;4181 ZigType *int_type = instruction->result_ptr_type;
4182 assert(int_type->id == TypeTableEntryIdInt);4182 assert(int_type->id == ZigTypeIdInt);
41834183
4184 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);4184 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
4185 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);4185 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
...@@ -4219,7 +4219,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -4219,7 +4219,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
4219 }4219 }
42204220
4221 ZigType *int_type = instruction->result_ptr_type;4221 ZigType *int_type = instruction->result_ptr_type;
4222 assert(int_type->id == TypeTableEntryIdInt);4222 assert(int_type->id == ZigTypeIdInt);
42234223
4224 LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);4224 LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);
42254225
...@@ -4259,7 +4259,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI...@@ -4259,7 +4259,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
42594259
4260static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {4260static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
4261 ZigType *ptr_type = instruction->value->value.type;4261 ZigType *ptr_type = instruction->value->value.type;
4262 assert(ptr_type->id == TypeTableEntryIdPointer);4262 assert(ptr_type->id == ZigTypeIdPointer);
4263 ZigType *err_union_type = ptr_type->data.pointer.child_type;4263 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4264 ZigType *payload_type = err_union_type->data.error_union.payload_type;4264 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4265 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);4265 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
...@@ -4275,7 +4275,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab...@@ -4275,7 +4275,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
42754275
4276static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {4276static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
4277 ZigType *ptr_type = instruction->value->value.type;4277 ZigType *ptr_type = instruction->value->value.type;
4278 assert(ptr_type->id == TypeTableEntryIdPointer);4278 assert(ptr_type->id == ZigTypeIdPointer);
4279 ZigType *err_union_type = ptr_type->data.pointer.child_type;4279 ZigType *err_union_type = ptr_type->data.pointer.child_type;
4280 ZigType *payload_type = err_union_type->data.error_union.payload_type;4280 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4281 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);4281 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
...@@ -4315,7 +4315,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -4315,7 +4315,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
4315static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {4315static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
4316 ZigType *wanted_type = instruction->base.value.type;4316 ZigType *wanted_type = instruction->base.value.type;
43174317
4318 assert(wanted_type->id == TypeTableEntryIdOptional);4318 assert(wanted_type->id == ZigTypeIdOptional);
43194319
4320 ZigType *child_type = wanted_type->data.maybe.child_type;4320 ZigType *child_type = wanted_type->data.maybe.child_type;
43214321
...@@ -4342,7 +4342,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I...@@ -4342,7 +4342,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
4342static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {4342static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
4343 ZigType *wanted_type = instruction->base.value.type;4343 ZigType *wanted_type = instruction->base.value.type;
43444344
4345 assert(wanted_type->id == TypeTableEntryIdErrorUnion);4345 assert(wanted_type->id == ZigTypeIdErrorUnion);
43464346
4347 ZigType *payload_type = wanted_type->data.error_union.payload_type;4347 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4348 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;4348 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
...@@ -4363,7 +4363,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable...@@ -4363,7 +4363,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
4363static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {4363static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
4364 ZigType *wanted_type = instruction->base.value.type;4364 ZigType *wanted_type = instruction->base.value.type;
43654365
4366 assert(wanted_type->id == TypeTableEntryIdErrorUnion);4366 assert(wanted_type->id == ZigTypeIdErrorUnion);
43674367
4368 ZigType *payload_type = wanted_type->data.error_union.payload_type;4368 ZigType *payload_type = wanted_type->data.error_union.payload_type;
4369 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;4369 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
...@@ -4471,7 +4471,7 @@ static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *exec...@@ -4471,7 +4471,7 @@ static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *exec
4471 IrInstructionContainerInitList *instruction)4471 IrInstructionContainerInitList *instruction)
4472{4472{
4473 ZigType *array_type = instruction->base.value.type;4473 ZigType *array_type = instruction->base.value.type;
4474 assert(array_type->id == TypeTableEntryIdArray);4474 assert(array_type->id == ZigTypeIdArray);
4475 LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;4475 LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;
4476 assert(tmp_array_ptr);4476 assert(tmp_array_ptr);
44774477
...@@ -4605,7 +4605,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f...@@ -4605,7 +4605,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
4605 if (g->coro_alloc_helper_fn_val != nullptr)4605 if (g->coro_alloc_helper_fn_val != nullptr)
4606 return g->coro_alloc_helper_fn_val;4606 return g->coro_alloc_helper_fn_val;
46074607
4608 assert(fn_type->id == TypeTableEntryIdFn);4608 assert(fn_type->id == ZigTypeIdFn);
46094609
4610 ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);4610 ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
46114611
...@@ -4734,7 +4734,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -4734,7 +4734,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
4734{4734{
4735 bool is_signed;4735 bool is_signed;
4736 ZigType *operand_type = instruction->operand->value.type;4736 ZigType *operand_type = instruction->operand->value.type;
4737 if (operand_type->id == TypeTableEntryIdInt) {4737 if (operand_type->id == ZigTypeIdInt) {
4738 is_signed = operand_type->data.integral.is_signed;4738 is_signed = operand_type->data.integral.is_signed;
4739 } else {4739 } else {
4740 is_signed = false;4740 is_signed = false;
...@@ -4789,7 +4789,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e...@@ -4789,7 +4789,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e
47894789
4790static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {4790static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {
4791 LLVMValueRef op = ir_llvm_value(g, instruction->op);4791 LLVMValueRef op = ir_llvm_value(g, instruction->op);
4792 assert(instruction->base.value.type->id == TypeTableEntryIdFloat);4792 assert(instruction->base.value.type->id == ZigTypeIdFloat);
4793 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);4793 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);
4794 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");4794 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
4795}4795}
...@@ -5146,56 +5146,56 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -5146,56 +5146,56 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
5146 ZigType *type_entry = const_val->type;5146 ZigType *type_entry = const_val->type;
5147 assert(!type_entry->zero_bits);5147 assert(!type_entry->zero_bits);
5148 switch (type_entry->id) {5148 switch (type_entry->id) {
5149 case TypeTableEntryIdInvalid:5149 case ZigTypeIdInvalid:
5150 case TypeTableEntryIdMetaType:5150 case ZigTypeIdMetaType:
5151 case TypeTableEntryIdUnreachable:5151 case ZigTypeIdUnreachable:
5152 case TypeTableEntryIdComptimeFloat:5152 case ZigTypeIdComptimeFloat:
5153 case TypeTableEntryIdComptimeInt:5153 case ZigTypeIdComptimeInt:
5154 case TypeTableEntryIdUndefined:5154 case ZigTypeIdUndefined:
5155 case TypeTableEntryIdNull:5155 case ZigTypeIdNull:
5156 case TypeTableEntryIdErrorUnion:5156 case ZigTypeIdErrorUnion:
5157 case TypeTableEntryIdErrorSet:5157 case ZigTypeIdErrorSet:
5158 case TypeTableEntryIdNamespace:5158 case ZigTypeIdNamespace:
5159 case TypeTableEntryIdBlock:5159 case ZigTypeIdBlock:
5160 case TypeTableEntryIdBoundFn:5160 case ZigTypeIdBoundFn:
5161 case TypeTableEntryIdArgTuple:5161 case ZigTypeIdArgTuple:
5162 case TypeTableEntryIdVoid:5162 case ZigTypeIdVoid:
5163 case TypeTableEntryIdOpaque:5163 case ZigTypeIdOpaque:
5164 zig_unreachable();5164 zig_unreachable();
5165 case TypeTableEntryIdBool:5165 case ZigTypeIdBool:
5166 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);5166 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);
5167 case TypeTableEntryIdEnum:5167 case ZigTypeIdEnum:
5168 {5168 {
5169 assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);5169 assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);
5170 LLVMValueRef int_val = gen_const_val(g, const_val, "");5170 LLVMValueRef int_val = gen_const_val(g, const_val, "");
5171 return LLVMConstZExt(int_val, big_int_type_ref);5171 return LLVMConstZExt(int_val, big_int_type_ref);
5172 }5172 }
5173 case TypeTableEntryIdInt:5173 case ZigTypeIdInt:
5174 {5174 {
5175 LLVMValueRef int_val = gen_const_val(g, const_val, "");5175 LLVMValueRef int_val = gen_const_val(g, const_val, "");
5176 return LLVMConstZExt(int_val, big_int_type_ref);5176 return LLVMConstZExt(int_val, big_int_type_ref);
5177 }5177 }
5178 case TypeTableEntryIdFloat:5178 case ZigTypeIdFloat:
5179 {5179 {
5180 LLVMValueRef float_val = gen_const_val(g, const_val, "");5180 LLVMValueRef float_val = gen_const_val(g, const_val, "");
5181 LLVMValueRef int_val = LLVMConstFPToUI(float_val,5181 LLVMValueRef int_val = LLVMConstFPToUI(float_val,
5182 LLVMIntType((unsigned)type_entry->data.floating.bit_count));5182 LLVMIntType((unsigned)type_entry->data.floating.bit_count));
5183 return LLVMConstZExt(int_val, big_int_type_ref);5183 return LLVMConstZExt(int_val, big_int_type_ref);
5184 }5184 }
5185 case TypeTableEntryIdPointer:5185 case ZigTypeIdPointer:
5186 case TypeTableEntryIdFn:5186 case ZigTypeIdFn:
5187 case TypeTableEntryIdOptional:5187 case ZigTypeIdOptional:
5188 case TypeTableEntryIdPromise:5188 case ZigTypeIdPromise:
5189 {5189 {
5190 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");5190 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
5191 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);5191 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);
5192 return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);5192 return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);
5193 }5193 }
5194 case TypeTableEntryIdArray:5194 case ZigTypeIdArray:
5195 zig_panic("TODO bit pack an array");5195 zig_panic("TODO bit pack an array");
5196 case TypeTableEntryIdUnion:5196 case ZigTypeIdUnion:
5197 zig_panic("TODO bit pack a union");5197 zig_panic("TODO bit pack a union");
5198 case TypeTableEntryIdStruct:5198 case ZigTypeIdStruct:
5199 {5199 {
5200 assert(type_entry->data.structure.layout == ContainerLayoutPacked);5200 assert(type_entry->data.structure.layout == ContainerLayoutPacked);
5201 bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type5201 bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type
...@@ -5253,7 +5253,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5253,7 +5253,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5253 render_const_val_global(g, const_val, name);5253 render_const_val_global(g, const_val, name);
5254 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;5254 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
5255 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;5255 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
5256 assert(array_const_val->type->id == TypeTableEntryIdArray);5256 assert(array_const_val->type->id == ZigTypeIdArray);
5257 if (array_const_val->type->zero_bits) {5257 if (array_const_val->type->zero_bits) {
5258 // make this a null pointer5258 // make this a null pointer
5259 ZigType *usize = g->builtin_types.entry_usize;5259 ZigType *usize = g->builtin_types.entry_usize;
...@@ -5273,7 +5273,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5273,7 +5273,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5273 {5273 {
5274 render_const_val_global(g, const_val, name);5274 render_const_val_global(g, const_val, name);
5275 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;5275 ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
5276 assert(struct_const_val->type->id == TypeTableEntryIdStruct);5276 assert(struct_const_val->type->id == ZigTypeIdStruct);
5277 if (struct_const_val->type->zero_bits) {5277 if (struct_const_val->type->zero_bits) {
5278 // make this a null pointer5278 // make this a null pointer
5279 ZigType *usize = g->builtin_types.entry_usize;5279 ZigType *usize = g->builtin_types.entry_usize;
...@@ -5322,13 +5322,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5322,13 +5322,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5322 }5322 }
53235323
5324 switch (type_entry->id) {5324 switch (type_entry->id) {
5325 case TypeTableEntryIdInt:5325 case ZigTypeIdInt:
5326 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);5326 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);
5327 case TypeTableEntryIdErrorSet:5327 case ZigTypeIdErrorSet:
5328 assert(const_val->data.x_err_set != nullptr);5328 assert(const_val->data.x_err_set != nullptr);
5329 return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,5329 return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,
5330 const_val->data.x_err_set->value, false);5330 const_val->data.x_err_set->value, false);
5331 case TypeTableEntryIdFloat:5331 case ZigTypeIdFloat:
5332 switch (type_entry->data.floating.bit_count) {5332 switch (type_entry->data.floating.bit_count) {
5333 case 16:5333 case 16:
5334 return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16));5334 return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16));
...@@ -5348,13 +5348,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5348,13 +5348,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5348 default:5348 default:
5349 zig_unreachable();5349 zig_unreachable();
5350 }5350 }
5351 case TypeTableEntryIdBool:5351 case ZigTypeIdBool:
5352 if (const_val->data.x_bool) {5352 if (const_val->data.x_bool) {
5353 return LLVMConstAllOnes(LLVMInt1Type());5353 return LLVMConstAllOnes(LLVMInt1Type());
5354 } else {5354 } else {
5355 return LLVMConstNull(LLVMInt1Type());5355 return LLVMConstNull(LLVMInt1Type());
5356 }5356 }
5357 case TypeTableEntryIdOptional:5357 case ZigTypeIdOptional:
5358 {5358 {
5359 ZigType *child_type = type_entry->data.maybe.child_type;5359 ZigType *child_type = type_entry->data.maybe.child_type;
5360 if (child_type->zero_bits) {5360 if (child_type->zero_bits) {
...@@ -5387,7 +5387,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5387,7 +5387,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5387 }5387 }
5388 }5388 }
5389 }5389 }
5390 case TypeTableEntryIdStruct:5390 case ZigTypeIdStruct:
5391 {5391 {
5392 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);5392 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
5393 size_t src_field_count = type_entry->data.structure.src_field_count;5393 size_t src_field_count = type_entry->data.structure.src_field_count;
...@@ -5463,7 +5463,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5463,7 +5463,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5463 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);5463 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);
5464 }5464 }
5465 }5465 }
5466 case TypeTableEntryIdArray:5466 case ZigTypeIdArray:
5467 {5467 {
5468 uint64_t len = type_entry->data.array.len;5468 uint64_t len = type_entry->data.array.len;
5469 if (const_val->data.x_array.special == ConstArraySpecialUndef) {5469 if (const_val->data.x_array.special == ConstArraySpecialUndef) {
...@@ -5485,7 +5485,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5485,7 +5485,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5485 return LLVMConstArray(element_type_ref, values, (unsigned)len);5485 return LLVMConstArray(element_type_ref, values, (unsigned)len);
5486 }5486 }
5487 }5487 }
5488 case TypeTableEntryIdUnion:5488 case ZigTypeIdUnion:
5489 {5489 {
5490 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;5490 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
54915491
...@@ -5549,15 +5549,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5549,15 +5549,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
55495549
5550 }5550 }
55515551
5552 case TypeTableEntryIdEnum:5552 case ZigTypeIdEnum:
5553 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);5553 return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);
5554 case TypeTableEntryIdFn:5554 case ZigTypeIdFn:
5555 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);5555 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
5556 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);5556 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
5557 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);5557 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
5558 case TypeTableEntryIdPointer:5558 case ZigTypeIdPointer:
5559 return gen_const_val_ptr(g, const_val, name);5559 return gen_const_val_ptr(g, const_val, name);
5560 case TypeTableEntryIdErrorUnion:5560 case ZigTypeIdErrorUnion:
5561 {5561 {
5562 ZigType *payload_type = type_entry->data.error_union.payload_type;5562 ZigType *payload_type = type_entry->data.error_union.payload_type;
5563 ZigType *err_set_type = type_entry->data.error_union.err_set_type;5563 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
...@@ -5593,21 +5593,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5593,21 +5593,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5593 }5593 }
5594 }5594 }
5595 }5595 }
5596 case TypeTableEntryIdVoid:5596 case ZigTypeIdVoid:
5597 return nullptr;5597 return nullptr;
5598 case TypeTableEntryIdInvalid:5598 case ZigTypeIdInvalid:
5599 case TypeTableEntryIdMetaType:5599 case ZigTypeIdMetaType:
5600 case TypeTableEntryIdUnreachable:5600 case ZigTypeIdUnreachable:
5601 case TypeTableEntryIdComptimeFloat:5601 case ZigTypeIdComptimeFloat:
5602 case TypeTableEntryIdComptimeInt:5602 case ZigTypeIdComptimeInt:
5603 case TypeTableEntryIdUndefined:5603 case ZigTypeIdUndefined:
5604 case TypeTableEntryIdNull:5604 case ZigTypeIdNull:
5605 case TypeTableEntryIdNamespace:5605 case ZigTypeIdNamespace:
5606 case TypeTableEntryIdBlock:5606 case ZigTypeIdBlock:
5607 case TypeTableEntryIdBoundFn:5607 case ZigTypeIdBoundFn:
5608 case TypeTableEntryIdArgTuple:5608 case ZigTypeIdArgTuple:
5609 case TypeTableEntryIdOpaque:5609 case ZigTypeIdOpaque:
5610 case TypeTableEntryIdPromise:5610 case ZigTypeIdPromise:
5611 zig_unreachable();5611 zig_unreachable();
56125612
5613 }5613 }
...@@ -5790,7 +5790,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5790,7 +5790,7 @@ static void do_code_gen(CodeGen *g) {
5790 TldVar *tld_var = g->global_vars.at(i);5790 TldVar *tld_var = g->global_vars.at(i);
5791 ZigVar *var = tld_var->var;5791 ZigVar *var = tld_var->var;
57925792
5793 if (var->value->type->id == TypeTableEntryIdComptimeFloat) {5793 if (var->value->type->id == ZigTypeIdComptimeFloat) {
5794 // Generate debug info for it but that's it.5794 // Generate debug info for it but that's it.
5795 ConstExprValue *const_val = var->value;5795 ConstExprValue *const_val = var->value;
5796 assert(const_val->special != ConstValSpecialRuntime);5796 assert(const_val->special != ConstValSpecialRuntime);
...@@ -5804,7 +5804,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5804,7 +5804,7 @@ static void do_code_gen(CodeGen *g) {
5804 continue;5804 continue;
5805 }5805 }
58065806
5807 if (var->value->type->id == TypeTableEntryIdComptimeInt) {5807 if (var->value->type->id == ZigTypeIdComptimeInt) {
5808 // Generate debug info for it but that's it.5808 // Generate debug info for it but that's it.
5809 ConstExprValue *const_val = var->value;5809 ConstExprValue *const_val = var->value;
5810 assert(const_val->special != ConstValSpecialRuntime);5810 assert(const_val->special != ConstValSpecialRuntime);
...@@ -5852,7 +5852,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5852,7 +5852,7 @@ static void do_code_gen(CodeGen *g) {
5852 LLVMSetAlignment(global_value, var->align_bytes);5852 LLVMSetAlignment(global_value, var->align_bytes);
58535853
5854 // TODO debug info for function pointers5854 // TODO debug info for function pointers
5855 if (var->gen_is_const && var->value->type->id != TypeTableEntryIdFn) {5855 if (var->gen_is_const && var->value->type->id != ZigTypeIdFn) {
5856 gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);5856 gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);
5857 }5857 }
58585858
...@@ -5910,7 +5910,7 @@ static void do_code_gen(CodeGen *g) {...@@ -5910,7 +5910,7 @@ static void do_code_gen(CodeGen *g) {
5910 } else if (instruction->id == IrInstructionIdRef) {5910 } else if (instruction->id == IrInstructionIdRef) {
5911 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;5911 IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;
5912 slot = &ref_instruction->tmp_ptr;5912 slot = &ref_instruction->tmp_ptr;
5913 assert(instruction->value.type->id == TypeTableEntryIdPointer);5913 assert(instruction->value.type->id == ZigTypeIdPointer);
5914 slot_type = instruction->value.type->data.pointer.child_type;5914 slot_type = instruction->value.type->data.pointer.child_type;
5915 } else if (instruction->id == IrInstructionIdContainerInitList) {5915 } else if (instruction->id == IrInstructionIdContainerInitList) {
5916 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;5916 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
...@@ -6173,51 +6173,51 @@ static const GlobalLinkageValue global_linkage_values[] = {...@@ -6173,51 +6173,51 @@ static const GlobalLinkageValue global_linkage_values[] = {
6173static void define_builtin_types(CodeGen *g) {6173static void define_builtin_types(CodeGen *g) {
6174 {6174 {
6175 // if this type is anywhere in the AST, we should never hit codegen.6175 // if this type is anywhere in the AST, we should never hit codegen.
6176 ZigType *entry = new_type_table_entry(TypeTableEntryIdInvalid);6176 ZigType *entry = new_type_table_entry(ZigTypeIdInvalid);
6177 buf_init_from_str(&entry->name, "(invalid)");6177 buf_init_from_str(&entry->name, "(invalid)");
6178 entry->zero_bits = true;6178 entry->zero_bits = true;
6179 g->builtin_types.entry_invalid = entry;6179 g->builtin_types.entry_invalid = entry;
6180 }6180 }
6181 {6181 {
6182 ZigType *entry = new_type_table_entry(TypeTableEntryIdNamespace);6182 ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
6183 buf_init_from_str(&entry->name, "(namespace)");6183 buf_init_from_str(&entry->name, "(namespace)");
6184 entry->zero_bits = true;6184 entry->zero_bits = true;
6185 g->builtin_types.entry_namespace = entry;6185 g->builtin_types.entry_namespace = entry;
6186 }6186 }
6187 {6187 {
6188 ZigType *entry = new_type_table_entry(TypeTableEntryIdBlock);6188 ZigType *entry = new_type_table_entry(ZigTypeIdBlock);
6189 buf_init_from_str(&entry->name, "(block)");6189 buf_init_from_str(&entry->name, "(block)");
6190 entry->zero_bits = true;6190 entry->zero_bits = true;
6191 g->builtin_types.entry_block = entry;6191 g->builtin_types.entry_block = entry;
6192 }6192 }
6193 {6193 {
6194 ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat);6194 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
6195 buf_init_from_str(&entry->name, "comptime_float");6195 buf_init_from_str(&entry->name, "comptime_float");
6196 entry->zero_bits = true;6196 entry->zero_bits = true;
6197 g->builtin_types.entry_num_lit_float = entry;6197 g->builtin_types.entry_num_lit_float = entry;
6198 g->primitive_type_table.put(&entry->name, entry);6198 g->primitive_type_table.put(&entry->name, entry);
6199 }6199 }
6200 {6200 {
6201 ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeInt);6201 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeInt);
6202 buf_init_from_str(&entry->name, "comptime_int");6202 buf_init_from_str(&entry->name, "comptime_int");
6203 entry->zero_bits = true;6203 entry->zero_bits = true;
6204 g->builtin_types.entry_num_lit_int = entry;6204 g->builtin_types.entry_num_lit_int = entry;
6205 g->primitive_type_table.put(&entry->name, entry);6205 g->primitive_type_table.put(&entry->name, entry);
6206 }6206 }
6207 {6207 {
6208 ZigType *entry = new_type_table_entry(TypeTableEntryIdUndefined);6208 ZigType *entry = new_type_table_entry(ZigTypeIdUndefined);
6209 buf_init_from_str(&entry->name, "(undefined)");6209 buf_init_from_str(&entry->name, "(undefined)");
6210 entry->zero_bits = true;6210 entry->zero_bits = true;
6211 g->builtin_types.entry_undef = entry;6211 g->builtin_types.entry_undef = entry;
6212 }6212 }
6213 {6213 {
6214 ZigType *entry = new_type_table_entry(TypeTableEntryIdNull);6214 ZigType *entry = new_type_table_entry(ZigTypeIdNull);
6215 buf_init_from_str(&entry->name, "(null)");6215 buf_init_from_str(&entry->name, "(null)");
6216 entry->zero_bits = true;6216 entry->zero_bits = true;
6217 g->builtin_types.entry_null = entry;6217 g->builtin_types.entry_null = entry;
6218 }6218 }
6219 {6219 {
6220 ZigType *entry = new_type_table_entry(TypeTableEntryIdArgTuple);6220 ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
6221 buf_init_from_str(&entry->name, "(args)");6221 buf_init_from_str(&entry->name, "(args)");
6222 entry->zero_bits = true;6222 entry->zero_bits = true;
6223 g->builtin_types.entry_arg_tuple = entry;6223 g->builtin_types.entry_arg_tuple = entry;
...@@ -6228,7 +6228,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6228,7 +6228,7 @@ static void define_builtin_types(CodeGen *g) {
6228 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);6228 uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
6229 bool is_signed = info->is_signed;6229 bool is_signed = info->is_signed;
62306230
6231 ZigType *entry = new_type_table_entry(TypeTableEntryIdInt);6231 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
6232 entry->type_ref = LLVMIntType(size_in_bits);6232 entry->type_ref = LLVMIntType(size_in_bits);
62336233
6234 buf_init_from_str(&entry->name, info->name);6234 buf_init_from_str(&entry->name, info->name);
...@@ -6245,7 +6245,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6245,7 +6245,7 @@ static void define_builtin_types(CodeGen *g) {
6245 }6245 }
62466246
6247 {6247 {
6248 ZigType *entry = new_type_table_entry(TypeTableEntryIdBool);6248 ZigType *entry = new_type_table_entry(ZigTypeIdBool);
6249 entry->type_ref = LLVMInt1Type();6249 entry->type_ref = LLVMInt1Type();
6250 buf_init_from_str(&entry->name, "bool");6250 buf_init_from_str(&entry->name, "bool");
6251 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);6251 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
...@@ -6259,7 +6259,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6259,7 +6259,7 @@ static void define_builtin_types(CodeGen *g) {
6259 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {6259 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
6260 bool is_signed = is_signed_list[sign_i];6260 bool is_signed = is_signed_list[sign_i];
62616261
6262 ZigType *entry = new_type_table_entry(TypeTableEntryIdInt);6262 ZigType *entry = new_type_table_entry(ZigTypeIdInt);
6263 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);6263 entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
62646264
6265 const char u_or_i = is_signed ? 'i' : 'u';6265 const char u_or_i = is_signed ? 'i' : 'u';
...@@ -6287,7 +6287,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6287,7 +6287,7 @@ static void define_builtin_types(CodeGen *g) {
6287 uint32_t bit_count,6287 uint32_t bit_count,
6288 LLVMTypeRef type_ref,6288 LLVMTypeRef type_ref,
6289 ZigType **field) {6289 ZigType **field) {
6290 ZigType *entry = new_type_table_entry(TypeTableEntryIdFloat);6290 ZigType *entry = new_type_table_entry(ZigTypeIdFloat);
6291 entry->type_ref = type_ref;6291 entry->type_ref = type_ref;
6292 buf_init_from_str(&entry->name, name);6292 buf_init_from_str(&entry->name, name);
6293 entry->data.floating.bit_count = bit_count;6293 entry->data.floating.bit_count = bit_count;
...@@ -6306,7 +6306,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6306,7 +6306,7 @@ static void define_builtin_types(CodeGen *g) {
6306 add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);6306 add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);
63076307
6308 {6308 {
6309 ZigType *entry = new_type_table_entry(TypeTableEntryIdVoid);6309 ZigType *entry = new_type_table_entry(ZigTypeIdVoid);
6310 entry->type_ref = LLVMVoidType();6310 entry->type_ref = LLVMVoidType();
6311 entry->zero_bits = true;6311 entry->zero_bits = true;
6312 buf_init_from_str(&entry->name, "void");6312 buf_init_from_str(&entry->name, "void");
...@@ -6317,7 +6317,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6317,7 +6317,7 @@ static void define_builtin_types(CodeGen *g) {
6317 g->primitive_type_table.put(&entry->name, entry);6317 g->primitive_type_table.put(&entry->name, entry);
6318 }6318 }
6319 {6319 {
6320 ZigType *entry = new_type_table_entry(TypeTableEntryIdUnreachable);6320 ZigType *entry = new_type_table_entry(ZigTypeIdUnreachable);
6321 entry->type_ref = LLVMVoidType();6321 entry->type_ref = LLVMVoidType();
6322 entry->zero_bits = true;6322 entry->zero_bits = true;
6323 buf_init_from_str(&entry->name, "noreturn");6323 buf_init_from_str(&entry->name, "noreturn");
...@@ -6326,7 +6326,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6326,7 +6326,7 @@ static void define_builtin_types(CodeGen *g) {
6326 g->primitive_type_table.put(&entry->name, entry);6326 g->primitive_type_table.put(&entry->name, entry);
6327 }6327 }
6328 {6328 {
6329 ZigType *entry = new_type_table_entry(TypeTableEntryIdMetaType);6329 ZigType *entry = new_type_table_entry(ZigTypeIdMetaType);
6330 buf_init_from_str(&entry->name, "type");6330 buf_init_from_str(&entry->name, "type");
6331 entry->zero_bits = true;6331 entry->zero_bits = true;
6332 g->builtin_types.entry_type = entry;6332 g->builtin_types.entry_type = entry;
...@@ -6348,7 +6348,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -6348,7 +6348,7 @@ static void define_builtin_types(CodeGen *g) {
6348 }6348 }
63496349
6350 {6350 {
6351 ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorSet);6351 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
6352 buf_init_from_str(&entry->name, "error");6352 buf_init_from_str(&entry->name, "error");
6353 entry->data.error_set.err_count = UINT32_MAX;6353 entry->data.error_set.err_count = UINT32_MAX;
63546354
...@@ -7226,57 +7226,57 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e...@@ -7226,57 +7226,57 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
7226 type_entry->gen_h_loop_flag = true;7226 type_entry->gen_h_loop_flag = true;
72277227
7228 switch (type_entry->id) {7228 switch (type_entry->id) {
7229 case TypeTableEntryIdInvalid:7229 case ZigTypeIdInvalid:
7230 case TypeTableEntryIdMetaType:7230 case ZigTypeIdMetaType:
7231 case TypeTableEntryIdComptimeFloat:7231 case ZigTypeIdComptimeFloat:
7232 case TypeTableEntryIdComptimeInt:7232 case ZigTypeIdComptimeInt:
7233 case TypeTableEntryIdUndefined:7233 case ZigTypeIdUndefined:
7234 case TypeTableEntryIdNull:7234 case ZigTypeIdNull:
7235 case TypeTableEntryIdNamespace:7235 case ZigTypeIdNamespace:
7236 case TypeTableEntryIdBlock:7236 case ZigTypeIdBlock:
7237 case TypeTableEntryIdBoundFn:7237 case ZigTypeIdBoundFn:
7238 case TypeTableEntryIdArgTuple:7238 case ZigTypeIdArgTuple:
7239 case TypeTableEntryIdErrorUnion:7239 case ZigTypeIdErrorUnion:
7240 case TypeTableEntryIdErrorSet:7240 case ZigTypeIdErrorSet:
7241 case TypeTableEntryIdPromise:7241 case ZigTypeIdPromise:
7242 zig_unreachable();7242 zig_unreachable();
7243 case TypeTableEntryIdVoid:7243 case ZigTypeIdVoid:
7244 case TypeTableEntryIdUnreachable:7244 case ZigTypeIdUnreachable:
7245 case TypeTableEntryIdBool:7245 case ZigTypeIdBool:
7246 case TypeTableEntryIdInt:7246 case ZigTypeIdInt:
7247 case TypeTableEntryIdFloat:7247 case ZigTypeIdFloat:
7248 return;7248 return;
7249 case TypeTableEntryIdOpaque:7249 case ZigTypeIdOpaque:
7250 gen_h->types_to_declare.append(type_entry);7250 gen_h->types_to_declare.append(type_entry);
7251 return;7251 return;
7252 case TypeTableEntryIdStruct:7252 case ZigTypeIdStruct:
7253 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {7253 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
7254 TypeStructField *field = &type_entry->data.structure.fields[i];7254 TypeStructField *field = &type_entry->data.structure.fields[i];
7255 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);7255 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
7256 }7256 }
7257 gen_h->types_to_declare.append(type_entry);7257 gen_h->types_to_declare.append(type_entry);
7258 return;7258 return;
7259 case TypeTableEntryIdUnion:7259 case ZigTypeIdUnion:
7260 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {7260 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
7261 TypeUnionField *field = &type_entry->data.unionation.fields[i];7261 TypeUnionField *field = &type_entry->data.unionation.fields[i];
7262 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);7262 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
7263 }7263 }
7264 gen_h->types_to_declare.append(type_entry);7264 gen_h->types_to_declare.append(type_entry);
7265 return;7265 return;
7266 case TypeTableEntryIdEnum:7266 case ZigTypeIdEnum:
7267 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);7267 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
7268 gen_h->types_to_declare.append(type_entry);7268 gen_h->types_to_declare.append(type_entry);
7269 return;7269 return;
7270 case TypeTableEntryIdPointer:7270 case ZigTypeIdPointer:
7271 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);7271 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
7272 return;7272 return;
7273 case TypeTableEntryIdArray:7273 case ZigTypeIdArray:
7274 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);7274 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
7275 return;7275 return;
7276 case TypeTableEntryIdOptional:7276 case ZigTypeIdOptional:
7277 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);7277 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
7278 return;7278 return;
7279 case TypeTableEntryIdFn:7279 case ZigTypeIdFn:
7280 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {7280 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
7281 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);7281 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
7282 }7282 }
...@@ -7316,17 +7316,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -7316,17 +7316,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
7316 prepend_c_type_to_decl_list(g, gen_h, type_entry);7316 prepend_c_type_to_decl_list(g, gen_h, type_entry);
73177317
7318 switch (type_entry->id) {7318 switch (type_entry->id) {
7319 case TypeTableEntryIdVoid:7319 case ZigTypeIdVoid:
7320 buf_init_from_str(out_buf, "void");7320 buf_init_from_str(out_buf, "void");
7321 break;7321 break;
7322 case TypeTableEntryIdBool:7322 case ZigTypeIdBool:
7323 buf_init_from_str(out_buf, "bool");7323 buf_init_from_str(out_buf, "bool");
7324 g->c_want_stdbool = true;7324 g->c_want_stdbool = true;
7325 break;7325 break;
7326 case TypeTableEntryIdUnreachable:7326 case ZigTypeIdUnreachable:
7327 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");7327 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");
7328 break;7328 break;
7329 case TypeTableEntryIdFloat:7329 case ZigTypeIdFloat:
7330 switch (type_entry->data.floating.bit_count) {7330 switch (type_entry->data.floating.bit_count) {
7331 case 32:7331 case 32:
7332 buf_init_from_str(out_buf, "float");7332 buf_init_from_str(out_buf, "float");
...@@ -7344,14 +7344,14 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -7344,14 +7344,14 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
7344 zig_unreachable();7344 zig_unreachable();
7345 }7345 }
7346 break;7346 break;
7347 case TypeTableEntryIdInt:7347 case ZigTypeIdInt:
7348 g->c_want_stdint = true;7348 g->c_want_stdint = true;
7349 buf_resize(out_buf, 0);7349 buf_resize(out_buf, 0);
7350 buf_appendf(out_buf, "%sint%" PRIu32 "_t",7350 buf_appendf(out_buf, "%sint%" PRIu32 "_t",
7351 type_entry->data.integral.is_signed ? "" : "u",7351 type_entry->data.integral.is_signed ? "" : "u",
7352 type_entry->data.integral.bit_count);7352 type_entry->data.integral.bit_count);
7353 break;7353 break;
7354 case TypeTableEntryIdPointer:7354 case ZigTypeIdPointer:
7355 {7355 {
7356 Buf child_buf = BUF_INIT;7356 Buf child_buf = BUF_INIT;
7357 ZigType *child_type = type_entry->data.pointer.child_type;7357 ZigType *child_type = type_entry->data.pointer.child_type;
...@@ -7362,7 +7362,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -7362,7 +7362,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
7362 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));7362 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
7363 break;7363 break;
7364 }7364 }
7365 case TypeTableEntryIdOptional:7365 case ZigTypeIdOptional:
7366 {7366 {
7367 ZigType *child_type = type_entry->data.maybe.child_type;7367 ZigType *child_type = type_entry->data.maybe.child_type;
7368 if (child_type->zero_bits) {7368 if (child_type->zero_bits) {
...@@ -7374,28 +7374,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -7374,28 +7374,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
7374 zig_unreachable();7374 zig_unreachable();
7375 }7375 }
7376 }7376 }
7377 case TypeTableEntryIdStruct:7377 case ZigTypeIdStruct:
7378 case TypeTableEntryIdOpaque:7378 case ZigTypeIdOpaque:
7379 {7379 {
7380 buf_init_from_str(out_buf, "struct ");7380 buf_init_from_str(out_buf, "struct ");
7381 buf_append_buf(out_buf, &type_entry->name);7381 buf_append_buf(out_buf, &type_entry->name);
7382 return;7382 return;
7383 }7383 }
7384 case TypeTableEntryIdUnion:7384 case ZigTypeIdUnion:
7385 {7385 {
7386 buf_init_from_str(out_buf, "union ");7386 buf_init_from_str(out_buf, "union ");
7387 buf_append_buf(out_buf, &type_entry->name);7387 buf_append_buf(out_buf, &type_entry->name);
7388 return;7388 return;
7389 }7389 }
7390 case TypeTableEntryIdEnum:7390 case ZigTypeIdEnum:
7391 {7391 {
7392 buf_init_from_str(out_buf, "enum ");7392 buf_init_from_str(out_buf, "enum ");
7393 buf_append_buf(out_buf, &type_entry->name);7393 buf_append_buf(out_buf, &type_entry->name);
7394 return;7394 return;
7395 }7395 }
7396 case TypeTableEntryIdArray:7396 case ZigTypeIdArray:
7397 {7397 {
7398 TypeTableEntryArray *array_data = &type_entry->data.array;7398 ZigTypeArray *array_data = &type_entry->data.array;
73997399
7400 Buf *child_buf = buf_alloc();7400 Buf *child_buf = buf_alloc();
7401 get_c_type(g, gen_h, array_data->child_type, child_buf);7401 get_c_type(g, gen_h, array_data->child_type, child_buf);
...@@ -7404,21 +7404,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -7404,21 +7404,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
7404 buf_appendf(out_buf, "%s", buf_ptr(child_buf));7404 buf_appendf(out_buf, "%s", buf_ptr(child_buf));
7405 return;7405 return;
7406 }7406 }
7407 case TypeTableEntryIdErrorUnion:7407 case ZigTypeIdErrorUnion:
7408 case TypeTableEntryIdErrorSet:7408 case ZigTypeIdErrorSet:
7409 case TypeTableEntryIdFn:7409 case ZigTypeIdFn:
7410 zig_panic("TODO implement get_c_type for more types");7410 zig_panic("TODO implement get_c_type for more types");
7411 case TypeTableEntryIdInvalid:7411 case ZigTypeIdInvalid:
7412 case TypeTableEntryIdMetaType:7412 case ZigTypeIdMetaType:
7413 case TypeTableEntryIdBoundFn:7413 case ZigTypeIdBoundFn:
7414 case TypeTableEntryIdNamespace:7414 case ZigTypeIdNamespace:
7415 case TypeTableEntryIdBlock:7415 case ZigTypeIdBlock:
7416 case TypeTableEntryIdComptimeFloat:7416 case ZigTypeIdComptimeFloat:
7417 case TypeTableEntryIdComptimeInt:7417 case ZigTypeIdComptimeInt:
7418 case TypeTableEntryIdUndefined:7418 case ZigTypeIdUndefined:
7419 case TypeTableEntryIdNull:7419 case ZigTypeIdNull:
7420 case TypeTableEntryIdArgTuple:7420 case ZigTypeIdArgTuple:
7421 case TypeTableEntryIdPromise:7421 case ZigTypeIdPromise:
7422 zig_unreachable();7422 zig_unreachable();
7423 }7423 }
7424}7424}
...@@ -7509,7 +7509,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7509,7 +7509,7 @@ static void gen_h_file(CodeGen *g) {
7509 const char *restrict_str = param_info->is_noalias ? "restrict" : "";7509 const char *restrict_str = param_info->is_noalias ? "restrict" : "";
7510 get_c_type(g, gen_h, param_info->type, &param_type_c);7510 get_c_type(g, gen_h, param_info->type, &param_type_c);
75117511
7512 if (param_info->type->id == TypeTableEntryIdArray) {7512 if (param_info->type->id == ZigTypeIdArray) {
7513 // Arrays decay to pointers7513 // Arrays decay to pointers
7514 buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),7514 buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),
7515 restrict_str, buf_ptr(param_name));7515 restrict_str, buf_ptr(param_name));
...@@ -7557,30 +7557,30 @@ static void gen_h_file(CodeGen *g) {...@@ -7557,30 +7557,30 @@ static void gen_h_file(CodeGen *g) {
7557 for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {7557 for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
7558 ZigType *type_entry = gen_h->types_to_declare.at(type_i);7558 ZigType *type_entry = gen_h->types_to_declare.at(type_i);
7559 switch (type_entry->id) {7559 switch (type_entry->id) {
7560 case TypeTableEntryIdInvalid:7560 case ZigTypeIdInvalid:
7561 case TypeTableEntryIdMetaType:7561 case ZigTypeIdMetaType:
7562 case TypeTableEntryIdVoid:7562 case ZigTypeIdVoid:
7563 case TypeTableEntryIdBool:7563 case ZigTypeIdBool:
7564 case TypeTableEntryIdUnreachable:7564 case ZigTypeIdUnreachable:
7565 case TypeTableEntryIdInt:7565 case ZigTypeIdInt:
7566 case TypeTableEntryIdFloat:7566 case ZigTypeIdFloat:
7567 case TypeTableEntryIdPointer:7567 case ZigTypeIdPointer:
7568 case TypeTableEntryIdComptimeFloat:7568 case ZigTypeIdComptimeFloat:
7569 case TypeTableEntryIdComptimeInt:7569 case ZigTypeIdComptimeInt:
7570 case TypeTableEntryIdArray:7570 case ZigTypeIdArray:
7571 case TypeTableEntryIdUndefined:7571 case ZigTypeIdUndefined:
7572 case TypeTableEntryIdNull:7572 case ZigTypeIdNull:
7573 case TypeTableEntryIdErrorUnion:7573 case ZigTypeIdErrorUnion:
7574 case TypeTableEntryIdErrorSet:7574 case ZigTypeIdErrorSet:
7575 case TypeTableEntryIdNamespace:7575 case ZigTypeIdNamespace:
7576 case TypeTableEntryIdBlock:7576 case ZigTypeIdBlock:
7577 case TypeTableEntryIdBoundFn:7577 case ZigTypeIdBoundFn:
7578 case TypeTableEntryIdArgTuple:7578 case ZigTypeIdArgTuple:
7579 case TypeTableEntryIdOptional:7579 case ZigTypeIdOptional:
7580 case TypeTableEntryIdFn:7580 case ZigTypeIdFn:
7581 case TypeTableEntryIdPromise:7581 case ZigTypeIdPromise:
7582 zig_unreachable();7582 zig_unreachable();
7583 case TypeTableEntryIdEnum:7583 case ZigTypeIdEnum:
7584 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {7584 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
7585 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));7585 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
7586 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {7586 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
...@@ -7598,7 +7598,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7598,7 +7598,7 @@ static void gen_h_file(CodeGen *g) {
7598 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));7598 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
7599 }7599 }
7600 break;7600 break;
7601 case TypeTableEntryIdStruct:7601 case ZigTypeIdStruct:
7602 if (type_entry->data.structure.layout == ContainerLayoutExtern) {7602 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
7603 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));7603 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
7604 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {7604 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
...@@ -7607,7 +7607,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7607,7 +7607,7 @@ static void gen_h_file(CodeGen *g) {
7607 Buf *type_name_buf = buf_alloc();7607 Buf *type_name_buf = buf_alloc();
7608 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);7608 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
76097609
7610 if (struct_field->type_entry->id == TypeTableEntryIdArray) {7610 if (struct_field->type_entry->id == ZigTypeIdArray) {
7611 fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),7611 fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
7612 buf_ptr(struct_field->name),7612 buf_ptr(struct_field->name),
7613 struct_field->type_entry->data.array.len);7613 struct_field->type_entry->data.array.len);
...@@ -7621,7 +7621,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7621,7 +7621,7 @@ static void gen_h_file(CodeGen *g) {
7621 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));7621 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
7622 }7622 }
7623 break;7623 break;
7624 case TypeTableEntryIdUnion:7624 case ZigTypeIdUnion:
7625 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {7625 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
7626 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));7626 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
7627 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {7627 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
...@@ -7636,7 +7636,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7636,7 +7636,7 @@ static void gen_h_file(CodeGen *g) {
7636 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));7636 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
7637 }7637 }
7638 break;7638 break;
7639 case TypeTableEntryIdOpaque:7639 case ZigTypeIdOpaque:
7640 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));7640 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
7641 break;7641 break;
7642 }7642 }
src/ir.cpp+896-896
...@@ -198,7 +198,7 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {...@@ -198,7 +198,7 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
198198
199ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {199ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
200 ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val);200 ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val);
201 if (const_val->type->id == TypeTableEntryIdPointer) {201 if (const_val->type->id == ZigTypeIdPointer) {
202 assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type));202 assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type));
203 }203 }
204 return result;204 return result;
...@@ -253,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {...@@ -253,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {
253}253}
254254
255static bool instr_is_unreachable(IrInstruction *instruction) {255static bool instr_is_unreachable(IrInstruction *instruction) {
256 return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable;256 return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable;
257}257}
258258
259static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {259static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {
...@@ -3072,7 +3072,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -3072,7 +3072,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
3072 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;3072 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
3073 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);3073 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
3074 if (defer_expr_value != irb->codegen->invalid_instruction) {3074 if (defer_expr_value != irb->codegen->invalid_instruction) {
3075 if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) {3075 if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == ZigTypeIdUnreachable) {
3076 is_noreturn = true;3076 is_noreturn = true;
3077 } else {3077 } else {
3078 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));3078 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));
...@@ -6587,10 +6587,10 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,...@@ -6587,10 +6587,10 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
65876587
6588// errors should be populated with set1's values6588// errors should be populated with set1's values
6589static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {6589static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {
6590 assert(set1->id == TypeTableEntryIdErrorSet);6590 assert(set1->id == ZigTypeIdErrorSet);
6591 assert(set2->id == TypeTableEntryIdErrorSet);6591 assert(set2->id == ZigTypeIdErrorSet);
65926592
6593 ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);6593 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
6594 buf_resize(&err_set_type->name, 0);6594 buf_resize(&err_set_type->name, 0);
6595 buf_appendf(&err_set_type->name, "error{");6595 buf_appendf(&err_set_type->name, "error{");
65966596
...@@ -6642,7 +6642,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp...@@ -6642,7 +6642,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
6642static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,6642static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,
6643 ErrorTableEntry *err_entry)6643 ErrorTableEntry *err_entry)
6644{6644{
6645 ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);6645 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
6646 buf_resize(&err_set_type->name, 0);6646 buf_resize(&err_set_type->name, 0);
6647 buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));6647 buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));
6648 err_set_type->is_copyable = true;6648 err_set_type->is_copyable = true;
...@@ -6664,7 +6664,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A...@@ -6664,7 +6664,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
6664 uint32_t err_count = node->data.err_set_decl.decls.length;6664 uint32_t err_count = node->data.err_set_decl.decls.length;
66656665
6666 Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);6666 Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);
6667 ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);6667 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
6668 buf_init_from_buf(&err_set_type->name, type_name);6668 buf_init_from_buf(&err_set_type->name, type_name);
6669 err_set_type->is_copyable = true;6669 err_set_type->is_copyable = true;
6670 err_set_type->data.error_set.err_count = err_count;6670 err_set_type->data.error_set.err_count = err_count;
...@@ -7628,7 +7628,7 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,...@@ -7628,7 +7628,7 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
7628static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) {7628static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) {
7629 ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val);7629 ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val);
7630 assert(val != nullptr);7630 assert(val != nullptr);
7631 assert(const_val->type->id == TypeTableEntryIdPointer);7631 assert(const_val->type->id == ZigTypeIdPointer);
7632 ZigType *expected_type = const_val->type->data.pointer.child_type;7632 ZigType *expected_type = const_val->type->data.pointer.child_type;
7633 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {7633 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {
7634 ir_add_error_node(ira, source_node,7634 ir_add_error_node(ira, source_node,
...@@ -7669,16 +7669,16 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so...@@ -7669,16 +7669,16 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
7669}7669}
76707670
7671static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {7671static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {
7672 return ((num_lit_type->id == TypeTableEntryIdComptimeFloat &&7672 return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
7673 (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) ||7673 (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
7674 (num_lit_type->id == TypeTableEntryIdComptimeInt &&7674 (num_lit_type->id == ZigTypeIdComptimeInt &&
7675 (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt)));7675 (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
7676}7676}
76777677
7678static bool float_has_fraction(ConstExprValue *const_val) {7678static bool float_has_fraction(ConstExprValue *const_val) {
7679 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7679 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7680 return bigfloat_has_fraction(&const_val->data.x_bigfloat);7680 return bigfloat_has_fraction(&const_val->data.x_bigfloat);
7681 } else if (const_val->type->id == TypeTableEntryIdFloat) {7681 } else if (const_val->type->id == ZigTypeIdFloat) {
7682 switch (const_val->type->data.floating.bit_count) {7682 switch (const_val->type->data.floating.bit_count) {
7683 case 16:7683 case 16:
7684 {7684 {
...@@ -7704,9 +7704,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {...@@ -7704,9 +7704,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {
7704}7704}
77057705
7706static void float_append_buf(Buf *buf, ConstExprValue *const_val) {7706static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
7707 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7707 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7708 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);7708 bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
7709 } else if (const_val->type->id == TypeTableEntryIdFloat) {7709 } else if (const_val->type->id == ZigTypeIdFloat) {
7710 switch (const_val->type->data.floating.bit_count) {7710 switch (const_val->type->data.floating.bit_count) {
7711 case 16:7711 case 16:
7712 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));7712 buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
...@@ -7742,9 +7742,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {...@@ -7742,9 +7742,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
7742}7742}
77437743
7744static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {7744static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
7745 if (const_val->type->id == TypeTableEntryIdComptimeFloat) {7745 if (const_val->type->id == ZigTypeIdComptimeFloat) {
7746 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);7746 bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
7747 } else if (const_val->type->id == TypeTableEntryIdFloat) {7747 } else if (const_val->type->id == ZigTypeIdFloat) {
7748 switch (const_val->type->data.floating.bit_count) {7748 switch (const_val->type->data.floating.bit_count) {
7749 case 16:7749 case 16:
7750 {7750 {
...@@ -7789,9 +7789,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {...@@ -7789,9 +7789,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
7789}7789}
77907790
7791static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {7791static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
7792 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7792 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7793 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);7793 bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
7794 } else if (dest_val->type->id == TypeTableEntryIdFloat) {7794 } else if (dest_val->type->id == ZigTypeIdFloat) {
7795 switch (dest_val->type->data.floating.bit_count) {7795 switch (dest_val->type->data.floating.bit_count) {
7796 case 16:7796 case 16:
7797 dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);7797 dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);
...@@ -7814,9 +7814,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {...@@ -7814,9 +7814,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
7814}7814}
78157815
7816static void float_init_f16(ConstExprValue *dest_val, float16_t x) {7816static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
7817 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7817 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7818 bigfloat_init_16(&dest_val->data.x_bigfloat, x);7818 bigfloat_init_16(&dest_val->data.x_bigfloat, x);
7819 } else if (dest_val->type->id == TypeTableEntryIdFloat) {7819 } else if (dest_val->type->id == ZigTypeIdFloat) {
7820 switch (dest_val->type->data.floating.bit_count) {7820 switch (dest_val->type->data.floating.bit_count) {
7821 case 16:7821 case 16:
7822 dest_val->data.x_f16 = x;7822 dest_val->data.x_f16 = x;
...@@ -7839,9 +7839,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {...@@ -7839,9 +7839,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
7839}7839}
78407840
7841static void float_init_f32(ConstExprValue *dest_val, float x) {7841static void float_init_f32(ConstExprValue *dest_val, float x) {
7842 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7842 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7843 bigfloat_init_32(&dest_val->data.x_bigfloat, x);7843 bigfloat_init_32(&dest_val->data.x_bigfloat, x);
7844 } else if (dest_val->type->id == TypeTableEntryIdFloat) {7844 } else if (dest_val->type->id == ZigTypeIdFloat) {
7845 switch (dest_val->type->data.floating.bit_count) {7845 switch (dest_val->type->data.floating.bit_count) {
7846 case 16:7846 case 16:
7847 dest_val->data.x_f16 = zig_double_to_f16(x);7847 dest_val->data.x_f16 = zig_double_to_f16(x);
...@@ -7868,9 +7868,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {...@@ -7868,9 +7868,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
7868}7868}
78697869
7870static void float_init_f64(ConstExprValue *dest_val, double x) {7870static void float_init_f64(ConstExprValue *dest_val, double x) {
7871 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7871 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7872 bigfloat_init_64(&dest_val->data.x_bigfloat, x);7872 bigfloat_init_64(&dest_val->data.x_bigfloat, x);
7873 } else if (dest_val->type->id == TypeTableEntryIdFloat) {7873 } else if (dest_val->type->id == ZigTypeIdFloat) {
7874 switch (dest_val->type->data.floating.bit_count) {7874 switch (dest_val->type->data.floating.bit_count) {
7875 case 16:7875 case 16:
7876 dest_val->data.x_f16 = zig_double_to_f16(x);7876 dest_val->data.x_f16 = zig_double_to_f16(x);
...@@ -7897,9 +7897,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {...@@ -7897,9 +7897,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
7897}7897}
78987898
7899static void float_init_f128(ConstExprValue *dest_val, float128_t x) {7899static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
7900 if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {7900 if (dest_val->type->id == ZigTypeIdComptimeFloat) {
7901 bigfloat_init_128(&dest_val->data.x_bigfloat, x);7901 bigfloat_init_128(&dest_val->data.x_bigfloat, x);
7902 } else if (dest_val->type->id == TypeTableEntryIdFloat) {7902 } else if (dest_val->type->id == ZigTypeIdFloat) {
7903 switch (dest_val->type->data.floating.bit_count) {7903 switch (dest_val->type->data.floating.bit_count) {
7904 case 16:7904 case 16:
7905 dest_val->data.x_f16 = f128M_to_f16(&x);7905 dest_val->data.x_f16 = f128M_to_f16(&x);
...@@ -7930,9 +7930,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {...@@ -7930,9 +7930,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
7930}7930}
79317931
7932static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {7932static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
7933 if (src_val->type->id == TypeTableEntryIdComptimeFloat) {7933 if (src_val->type->id == ZigTypeIdComptimeFloat) {
7934 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);7934 float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
7935 } else if (src_val->type->id == TypeTableEntryIdFloat) {7935 } else if (src_val->type->id == ZigTypeIdFloat) {
7936 switch (src_val->type->data.floating.bit_count) {7936 switch (src_val->type->data.floating.bit_count) {
7937 case 16:7937 case 16:
7938 float_init_f16(dest_val, src_val->data.x_f16);7938 float_init_f16(dest_val, src_val->data.x_f16);
...@@ -7956,9 +7956,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)...@@ -7956,9 +7956,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
79567956
7957static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {7957static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
7958 assert(op1->type == op2->type);7958 assert(op1->type == op2->type);
7959 if (op1->type->id == TypeTableEntryIdComptimeFloat) {7959 if (op1->type->id == ZigTypeIdComptimeFloat) {
7960 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);7960 return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
7961 } else if (op1->type->id == TypeTableEntryIdFloat) {7961 } else if (op1->type->id == ZigTypeIdFloat) {
7962 switch (op1->type->data.floating.bit_count) {7962 switch (op1->type->data.floating.bit_count) {
7963 case 16:7963 case 16:
7964 if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {7964 if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {
...@@ -8001,9 +8001,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {...@@ -8001,9 +8001,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
8001}8001}
80028002
8003static Cmp float_cmp_zero(ConstExprValue *op) {8003static Cmp float_cmp_zero(ConstExprValue *op) {
8004 if (op->type->id == TypeTableEntryIdComptimeFloat) {8004 if (op->type->id == ZigTypeIdComptimeFloat) {
8005 return bigfloat_cmp_zero(&op->data.x_bigfloat);8005 return bigfloat_cmp_zero(&op->data.x_bigfloat);
8006 } else if (op->type->id == TypeTableEntryIdFloat) {8006 } else if (op->type->id == ZigTypeIdFloat) {
8007 switch (op->type->data.floating.bit_count) {8007 switch (op->type->data.floating.bit_count) {
8008 case 16:8008 case 16:
8009 {8009 {
...@@ -8053,9 +8053,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {...@@ -8053,9 +8053,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
8053static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8053static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8054 assert(op1->type == op2->type);8054 assert(op1->type == op2->type);
8055 out_val->type = op1->type;8055 out_val->type = op1->type;
8056 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8056 if (op1->type->id == ZigTypeIdComptimeFloat) {
8057 bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8057 bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8058 } else if (op1->type->id == TypeTableEntryIdFloat) {8058 } else if (op1->type->id == ZigTypeIdFloat) {
8059 switch (op1->type->data.floating.bit_count) {8059 switch (op1->type->data.floating.bit_count) {
8060 case 16:8060 case 16:
8061 out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16);8061 out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16);
...@@ -8080,9 +8080,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -8080,9 +8080,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8080static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8080static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8081 assert(op1->type == op2->type);8081 assert(op1->type == op2->type);
8082 out_val->type = op1->type;8082 out_val->type = op1->type;
8083 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8083 if (op1->type->id == ZigTypeIdComptimeFloat) {
8084 bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8084 bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8085 } else if (op1->type->id == TypeTableEntryIdFloat) {8085 } else if (op1->type->id == ZigTypeIdFloat) {
8086 switch (op1->type->data.floating.bit_count) {8086 switch (op1->type->data.floating.bit_count) {
8087 case 16:8087 case 16:
8088 out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16);8088 out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16);
...@@ -8107,9 +8107,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -8107,9 +8107,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8107static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8107static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8108 assert(op1->type == op2->type);8108 assert(op1->type == op2->type);
8109 out_val->type = op1->type;8109 out_val->type = op1->type;
8110 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8110 if (op1->type->id == ZigTypeIdComptimeFloat) {
8111 bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8111 bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8112 } else if (op1->type->id == TypeTableEntryIdFloat) {8112 } else if (op1->type->id == ZigTypeIdFloat) {
8113 switch (op1->type->data.floating.bit_count) {8113 switch (op1->type->data.floating.bit_count) {
8114 case 16:8114 case 16:
8115 out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16);8115 out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16);
...@@ -8134,9 +8134,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -8134,9 +8134,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8134static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8134static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8135 assert(op1->type == op2->type);8135 assert(op1->type == op2->type);
8136 out_val->type = op1->type;8136 out_val->type = op1->type;
8137 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8137 if (op1->type->id == ZigTypeIdComptimeFloat) {
8138 bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8138 bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8139 } else if (op1->type->id == TypeTableEntryIdFloat) {8139 } else if (op1->type->id == ZigTypeIdFloat) {
8140 switch (op1->type->data.floating.bit_count) {8140 switch (op1->type->data.floating.bit_count) {
8141 case 16:8141 case 16:
8142 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8142 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
...@@ -8161,9 +8161,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -8161,9 +8161,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
8161static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8161static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8162 assert(op1->type == op2->type);8162 assert(op1->type == op2->type);
8163 out_val->type = op1->type;8163 out_val->type = op1->type;
8164 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8164 if (op1->type->id == ZigTypeIdComptimeFloat) {
8165 bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8165 bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8166 } else if (op1->type->id == TypeTableEntryIdFloat) {8166 } else if (op1->type->id == ZigTypeIdFloat) {
8167 switch (op1->type->data.floating.bit_count) {8167 switch (op1->type->data.floating.bit_count) {
8168 case 16:8168 case 16:
8169 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8169 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
...@@ -8190,9 +8190,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -8190,9 +8190,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
8190static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8190static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8191 assert(op1->type == op2->type);8191 assert(op1->type == op2->type);
8192 out_val->type = op1->type;8192 out_val->type = op1->type;
8193 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8193 if (op1->type->id == ZigTypeIdComptimeFloat) {
8194 bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8194 bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8195 } else if (op1->type->id == TypeTableEntryIdFloat) {8195 } else if (op1->type->id == ZigTypeIdFloat) {
8196 switch (op1->type->data.floating.bit_count) {8196 switch (op1->type->data.floating.bit_count) {
8197 case 16:8197 case 16:
8198 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);8198 out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
...@@ -8219,9 +8219,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE...@@ -8219,9 +8219,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
8219static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8219static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8220 assert(op1->type == op2->type);8220 assert(op1->type == op2->type);
8221 out_val->type = op1->type;8221 out_val->type = op1->type;
8222 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8222 if (op1->type->id == ZigTypeIdComptimeFloat) {
8223 bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8223 bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8224 } else if (op1->type->id == TypeTableEntryIdFloat) {8224 } else if (op1->type->id == ZigTypeIdFloat) {
8225 switch (op1->type->data.floating.bit_count) {8225 switch (op1->type->data.floating.bit_count) {
8226 case 16:8226 case 16:
8227 out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16);8227 out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16);
...@@ -8264,9 +8264,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*...@@ -8264,9 +8264,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
8264static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {8264static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
8265 assert(op1->type == op2->type);8265 assert(op1->type == op2->type);
8266 out_val->type = op1->type;8266 out_val->type = op1->type;
8267 if (op1->type->id == TypeTableEntryIdComptimeFloat) {8267 if (op1->type->id == ZigTypeIdComptimeFloat) {
8268 bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);8268 bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
8269 } else if (op1->type->id == TypeTableEntryIdFloat) {8269 } else if (op1->type->id == ZigTypeIdFloat) {
8270 switch (op1->type->data.floating.bit_count) {8270 switch (op1->type->data.floating.bit_count) {
8271 case 16:8271 case 16:
8272 out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16);8272 out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16);
...@@ -8290,9 +8290,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal...@@ -8290,9 +8290,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
82908290
8291static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {8291static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
8292 out_val->type = op->type;8292 out_val->type = op->type;
8293 if (op->type->id == TypeTableEntryIdComptimeFloat) {8293 if (op->type->id == ZigTypeIdComptimeFloat) {
8294 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);8294 bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
8295 } else if (op->type->id == TypeTableEntryIdFloat) {8295 } else if (op->type->id == ZigTypeIdFloat) {
8296 switch (op->type->data.floating.bit_count) {8296 switch (op->type->data.floating.bit_count) {
8297 case 16:8297 case 16:
8298 {8298 {
...@@ -8320,7 +8320,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {...@@ -8320,7 +8320,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
8320}8320}
83218321
8322void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {8322void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
8323 if (op->type->id == TypeTableEntryIdFloat) {8323 if (op->type->id == ZigTypeIdFloat) {
8324 switch (op->type->data.floating.bit_count) {8324 switch (op->type->data.floating.bit_count) {
8325 case 16:8325 case 16:
8326 memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian8326 memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian
...@@ -8343,7 +8343,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {...@@ -8343,7 +8343,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
8343}8343}
83448344
8345void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {8345void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
8346 if (val->type->id == TypeTableEntryIdFloat) {8346 if (val->type->id == ZigTypeIdFloat) {
8347 switch (val->type->data.floating.bit_count) {8347 switch (val->type->data.floating.bit_count) {
8348 case 16:8348 case 16:
8349 memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian8349 memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian
...@@ -8375,13 +8375,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8375,13 +8375,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8375 ConstExprValue *const_val = &instruction->value;8375 ConstExprValue *const_val = &instruction->value;
8376 assert(const_val->special != ConstValSpecialRuntime);8376 assert(const_val->special != ConstValSpecialRuntime);
83778377
8378 bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt ||8378 bool const_val_is_int = (const_val->type->id == ZigTypeIdInt ||
8379 const_val->type->id == TypeTableEntryIdComptimeInt);8379 const_val->type->id == ZigTypeIdComptimeInt);
8380 bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat ||8380 bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat ||
8381 const_val->type->id == TypeTableEntryIdComptimeFloat);8381 const_val->type->id == ZigTypeIdComptimeFloat);
8382 if (other_type->id == TypeTableEntryIdFloat) {8382 if (other_type->id == ZigTypeIdFloat) {
8383 return true;8383 return true;
8384 } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) {8384 } else if (other_type->id == ZigTypeIdInt && const_val_is_int) {
8385 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {8385 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
8386 Buf *val_buf = buf_alloc();8386 Buf *val_buf = buf_alloc();
8387 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);8387 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
...@@ -8398,11 +8398,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8398,11 +8398,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8398 }8398 }
8399 } else if (const_val_fits_in_num_lit(const_val, other_type)) {8399 } else if (const_val_fits_in_num_lit(const_val, other_type)) {
8400 return true;8400 return true;
8401 } else if (other_type->id == TypeTableEntryIdOptional) {8401 } else if (other_type->id == ZigTypeIdOptional) {
8402 ZigType *child_type = other_type->data.maybe.child_type;8402 ZigType *child_type = other_type->data.maybe.child_type;
8403 if (const_val_fits_in_num_lit(const_val, child_type)) {8403 if (const_val_fits_in_num_lit(const_val, child_type)) {
8404 return true;8404 return true;
8405 } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) {8405 } else if (child_type->id == ZigTypeIdInt && const_val_is_int) {
8406 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {8406 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
8407 Buf *val_buf = buf_alloc();8407 Buf *val_buf = buf_alloc();
8408 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);8408 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
...@@ -8418,11 +8418,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8418,11 +8418,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8418 {8418 {
8419 return true;8419 return true;
8420 }8420 }
8421 } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) {8421 } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) {
8422 return true;8422 return true;
8423 }8423 }
8424 }8424 }
8425 if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) &&8425 if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) &&
8426 const_val_is_float)8426 const_val_is_float)
8427 {8427 {
8428 if (float_has_fraction(const_val)) {8428 if (float_has_fraction(const_val)) {
...@@ -8435,7 +8435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8435,7 +8435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8435 buf_ptr(&other_type->name)));8435 buf_ptr(&other_type->name)));
8436 return false;8436 return false;
8437 } else {8437 } else {
8438 if (other_type->id == TypeTableEntryIdComptimeInt) {8438 if (other_type->id == ZigTypeIdComptimeInt) {
8439 return true;8439 return true;
8440 } else {8440 } else {
8441 BigInt bigint;8441 BigInt bigint;
...@@ -8468,7 +8468,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -8468,7 +8468,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
8468}8468}
84698469
8470static bool is_slice(ZigType *type) {8470static bool is_slice(ZigType *type) {
8471 return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;8471 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
8472}8472}
84738473
8474static bool slice_is_const(ZigType *type) {8474static bool slice_is_const(ZigType *type) {
...@@ -8479,8 +8479,8 @@ static bool slice_is_const(ZigType *type) {...@@ -8479,8 +8479,8 @@ static bool slice_is_const(ZigType *type) {
8479static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2,8479static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2,
8480 AstNode *source_node)8480 AstNode *source_node)
8481{8481{
8482 assert(set1->id == TypeTableEntryIdErrorSet);8482 assert(set1->id == ZigTypeIdErrorSet);
8483 assert(set2->id == TypeTableEntryIdErrorSet);8483 assert(set2->id == ZigTypeIdErrorSet);
84848484
8485 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {8485 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
8486 return ira->codegen->builtin_types.entry_invalid;8486 return ira->codegen->builtin_types.entry_invalid;
...@@ -8502,7 +8502,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp...@@ -8502,7 +8502,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
8502 }8502 }
8503 ZigList<ErrorTableEntry *> intersection_list = {};8503 ZigList<ErrorTableEntry *> intersection_list = {};
85048504
8505 ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);8505 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
8506 buf_resize(&err_set_type->name, 0);8506 buf_resize(&err_set_type->name, 0);
8507 buf_appendf(&err_set_type->name, "error{");8507 buf_appendf(&err_set_type->name, "error{");
85088508
...@@ -8544,9 +8544,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8544,9 +8544,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8544 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively8544 // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively
8545 // but not if we want a mutable pointer8545 // but not if we want a mutable pointer
8546 // and not if the actual pointer has zero bits8546 // and not if the actual pointer has zero bits
8547 if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional &&8547 if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&
8548 wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&8548 wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&
8549 actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type))8549 actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))
8550 {8550 {
8551 ConstCastOnly child = types_match_const_cast_only(ira,8551 ConstCastOnly child = types_match_const_cast_only(ira,
8552 wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);8552 wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);
...@@ -8559,10 +8559,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8559,10 +8559,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8559 }8559 }
85608560
8561 // *T and [*]T can always cast to *c_void8561 // *T and [*]T can always cast to *c_void
8562 if (wanted_type->id == TypeTableEntryIdPointer &&8562 if (wanted_type->id == ZigTypeIdPointer &&
8563 wanted_type->data.pointer.ptr_len == PtrLenSingle &&8563 wanted_type->data.pointer.ptr_len == PtrLenSingle &&
8564 wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&8564 wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&
8565 actual_type->id == TypeTableEntryIdPointer &&8565 actual_type->id == ZigTypeIdPointer &&
8566 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&8566 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
8567 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))8567 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
8568 {8568 {
...@@ -8571,7 +8571,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8571,7 +8571,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8571 }8571 }
85728572
8573 // pointer const8573 // pointer const
8574 if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) {8574 if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) {
8575 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,8575 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
8576 actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);8576 actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);
8577 if (child.id != ConstCastResultIdOk) {8577 if (child.id != ConstCastResultIdOk) {
...@@ -8617,7 +8617,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8617,7 +8617,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8617 }8617 }
86188618
8619 // maybe8619 // maybe
8620 if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {8620 if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) {
8621 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,8621 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,
8622 actual_type->data.maybe.child_type, source_node, wanted_is_mutable);8622 actual_type->data.maybe.child_type, source_node, wanted_is_mutable);
8623 if (child.id != ConstCastResultIdOk) {8623 if (child.id != ConstCastResultIdOk) {
...@@ -8631,7 +8631,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8631,7 +8631,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8631 }8631 }
86328632
8633 // error union8633 // error union
8634 if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {8634 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) {
8635 ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,8635 ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,
8636 actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);8636 actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);
8637 if (payload_child.id != ConstCastResultIdOk) {8637 if (payload_child.id != ConstCastResultIdOk) {
...@@ -8656,7 +8656,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8656,7 +8656,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8656 }8656 }
86578657
8658 // error set8658 // error set
8659 if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {8659 if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) {
8660 ZigType *contained_set = actual_type;8660 ZigType *contained_set = actual_type;
8661 ZigType *container_set = wanted_type;8661 ZigType *container_set = wanted_type;
86628662
...@@ -8701,14 +8701,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8701,14 +8701,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8701 }8701 }
87028702
8703 if (wanted_type == ira->codegen->builtin_types.entry_promise &&8703 if (wanted_type == ira->codegen->builtin_types.entry_promise &&
8704 actual_type->id == TypeTableEntryIdPromise)8704 actual_type->id == ZigTypeIdPromise)
8705 {8705 {
8706 return result;8706 return result;
8707 }8707 }
87088708
8709 // fn8709 // fn
8710 if (wanted_type->id == TypeTableEntryIdFn &&8710 if (wanted_type->id == ZigTypeIdFn &&
8711 actual_type->id == TypeTableEntryIdFn)8711 actual_type->id == ZigTypeIdFn)
8712 {8712 {
8713 if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {8713 if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
8714 result.id = ConstCastResultIdFnAlign;8714 result.id = ConstCastResultIdFnAlign;
...@@ -8727,7 +8727,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -8727,7 +8727,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
8727 return result;8727 return result;
8728 }8728 }
8729 if (!wanted_type->data.fn.is_generic &&8729 if (!wanted_type->data.fn.is_generic &&
8730 actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable)8730 actual_type->data.fn.fn_type_id.return_type->id != ZigTypeIdUnreachable)
8731 {8731 {
8732 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,8732 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,
8733 actual_type->data.fn.fn_type_id.return_type, source_node, false);8733 actual_type->data.fn.fn_type_id.return_type, source_node, false);
...@@ -8807,7 +8807,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8807,7 +8807,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8807 ErrorTableEntry **errors = nullptr;8807 ErrorTableEntry **errors = nullptr;
8808 size_t errors_count = 0;8808 size_t errors_count = 0;
8809 ZigType *err_set_type = nullptr;8809 ZigType *err_set_type = nullptr;
8810 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {8810 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
8811 if (type_is_global_error_set(prev_inst->value.type)) {8811 if (type_is_global_error_set(prev_inst->value.type)) {
8812 err_set_type = ira->codegen->builtin_types.entry_global_error_set;8812 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
8813 } else {8813 } else {
...@@ -8825,7 +8825,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8825,7 +8825,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8825 }8825 }
8826 }8826 }
88278827
8828 bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull);8828 bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
8829 bool convert_to_const_slice = false;8829 bool convert_to_const_slice = false;
8830 for (size_t i = 1; i < instruction_count; i += 1) {8830 for (size_t i = 1; i < instruction_count; i += 1) {
8831 IrInstruction *cur_inst = instructions[i];8831 IrInstruction *cur_inst = instructions[i];
...@@ -8836,18 +8836,18 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8836,18 +8836,18 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8836 return cur_type;8836 return cur_type;
8837 }8837 }
88388838
8839 if (prev_type->id == TypeTableEntryIdUnreachable) {8839 if (prev_type->id == ZigTypeIdUnreachable) {
8840 prev_inst = cur_inst;8840 prev_inst = cur_inst;
8841 continue;8841 continue;
8842 }8842 }
88438843
8844 if (cur_type->id == TypeTableEntryIdUnreachable) {8844 if (cur_type->id == ZigTypeIdUnreachable) {
8845 continue;8845 continue;
8846 }8846 }
88478847
8848 if (prev_type->id == TypeTableEntryIdErrorSet) {8848 if (prev_type->id == ZigTypeIdErrorSet) {
8849 assert(err_set_type != nullptr);8849 assert(err_set_type != nullptr);
8850 if (cur_type->id == TypeTableEntryIdErrorSet) {8850 if (cur_type->id == ZigTypeIdErrorSet) {
8851 if (type_is_global_error_set(err_set_type)) {8851 if (type_is_global_error_set(err_set_type)) {
8852 continue;8852 continue;
8853 }8853 }
...@@ -8911,7 +8911,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8911,7 +8911,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8911 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);8911 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);
8912 assert(errors != nullptr);8912 assert(errors != nullptr);
8913 continue;8913 continue;
8914 } else if (cur_type->id == TypeTableEntryIdErrorUnion) {8914 } else if (cur_type->id == ZigTypeIdErrorUnion) {
8915 if (type_is_global_error_set(err_set_type)) {8915 if (type_is_global_error_set(err_set_type)) {
8916 prev_inst = cur_inst;8916 prev_inst = cur_inst;
8917 continue;8917 continue;
...@@ -8969,8 +8969,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8969,8 +8969,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8969 }8969 }
8970 }8970 }
89718971
8972 if (cur_type->id == TypeTableEntryIdErrorSet) {8972 if (cur_type->id == ZigTypeIdErrorSet) {
8973 if (prev_type->id == TypeTableEntryIdArray) {8973 if (prev_type->id == ZigTypeIdArray) {
8974 convert_to_const_slice = true;8974 convert_to_const_slice = true;
8975 }8975 }
8976 if (type_is_global_error_set(cur_type)) {8976 if (type_is_global_error_set(cur_type)) {
...@@ -8987,7 +8987,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -8987,7 +8987,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
8987 update_errors_helper(ira->codegen, &errors, &errors_count);8987 update_errors_helper(ira->codegen, &errors, &errors_count);
89888988
8989 if (err_set_type == nullptr) {8989 if (err_set_type == nullptr) {
8990 if (prev_type->id == TypeTableEntryIdErrorUnion) {8990 if (prev_type->id == ZigTypeIdErrorUnion) {
8991 err_set_type = prev_type->data.error_union.err_set_type;8991 err_set_type = prev_type->data.error_union.err_set_type;
8992 } else {8992 } else {
8993 err_set_type = cur_type;8993 err_set_type = cur_type;
...@@ -9020,7 +9020,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9020,7 +9020,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9020 continue;9020 continue;
9021 }9021 }
90229022
9023 if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) {9023 if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) {
9024 ZigType *prev_payload_type = prev_type->data.error_union.payload_type;9024 ZigType *prev_payload_type = prev_type->data.error_union.payload_type;
9025 ZigType *cur_payload_type = cur_type->data.error_union.payload_type;9025 ZigType *cur_payload_type = cur_type->data.error_union.payload_type;
90269026
...@@ -9104,12 +9104,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9104,12 +9104,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9104 }9104 }
9105 }9105 }
91069106
9107 if (prev_type->id == TypeTableEntryIdNull) {9107 if (prev_type->id == ZigTypeIdNull) {
9108 prev_inst = cur_inst;9108 prev_inst = cur_inst;
9109 continue;9109 continue;
9110 }9110 }
91119111
9112 if (cur_type->id == TypeTableEntryIdNull) {9112 if (cur_type->id == ZigTypeIdNull) {
9113 any_are_null = true;9113 any_are_null = true;
9114 continue;9114 continue;
9115 }9115 }
...@@ -9123,8 +9123,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9123,8 +9123,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9123 continue;9123 continue;
9124 }9124 }
91259125
9126 if (prev_type->id == TypeTableEntryIdInt &&9126 if (prev_type->id == ZigTypeIdInt &&
9127 cur_type->id == TypeTableEntryIdInt &&9127 cur_type->id == ZigTypeIdInt &&
9128 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)9128 prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)
9129 {9129 {
9130 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {9130 if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {
...@@ -9133,21 +9133,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9133,21 +9133,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9133 continue;9133 continue;
9134 }9134 }
91359135
9136 if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) {9136 if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) {
9137 if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {9137 if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {
9138 prev_inst = cur_inst;9138 prev_inst = cur_inst;
9139 }9139 }
9140 continue;9140 continue;
9141 }9141 }
91429142
9143 if (prev_type->id == TypeTableEntryIdErrorUnion &&9143 if (prev_type->id == ZigTypeIdErrorUnion &&
9144 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,9144 types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,
9145 source_node, false).id == ConstCastResultIdOk)9145 source_node, false).id == ConstCastResultIdOk)
9146 {9146 {
9147 continue;9147 continue;
9148 }9148 }
91499149
9150 if (cur_type->id == TypeTableEntryIdErrorUnion &&9150 if (cur_type->id == ZigTypeIdErrorUnion &&
9151 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,9151 types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,
9152 source_node, false).id == ConstCastResultIdOk)9152 source_node, false).id == ConstCastResultIdOk)
9153 {9153 {
...@@ -9170,14 +9170,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9170,14 +9170,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9170 continue;9170 continue;
9171 }9171 }
91729172
9173 if (prev_type->id == TypeTableEntryIdOptional &&9173 if (prev_type->id == ZigTypeIdOptional &&
9174 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,9174 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,
9175 source_node, false).id == ConstCastResultIdOk)9175 source_node, false).id == ConstCastResultIdOk)
9176 {9176 {
9177 continue;9177 continue;
9178 }9178 }
91799179
9180 if (cur_type->id == TypeTableEntryIdOptional &&9180 if (cur_type->id == ZigTypeIdOptional &&
9181 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,9181 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,
9182 source_node, false).id == ConstCastResultIdOk)9182 source_node, false).id == ConstCastResultIdOk)
9183 {9183 {
...@@ -9185,17 +9185,17 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9185,17 +9185,17 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9185 continue;9185 continue;
9186 }9186 }
91879187
9188 if (cur_type->id == TypeTableEntryIdUndefined) {9188 if (cur_type->id == ZigTypeIdUndefined) {
9189 continue;9189 continue;
9190 }9190 }
91919191
9192 if (prev_type->id == TypeTableEntryIdUndefined) {9192 if (prev_type->id == ZigTypeIdUndefined) {
9193 prev_inst = cur_inst;9193 prev_inst = cur_inst;
9194 continue;9194 continue;
9195 }9195 }
91969196
9197 if (prev_type->id == TypeTableEntryIdComptimeInt ||9197 if (prev_type->id == ZigTypeIdComptimeInt ||
9198 prev_type->id == TypeTableEntryIdComptimeFloat)9198 prev_type->id == ZigTypeIdComptimeFloat)
9199 {9199 {
9200 if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {9200 if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {
9201 prev_inst = cur_inst;9201 prev_inst = cur_inst;
...@@ -9205,8 +9205,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9205,8 +9205,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9205 }9205 }
9206 }9206 }
92079207
9208 if (cur_type->id == TypeTableEntryIdComptimeInt ||9208 if (cur_type->id == ZigTypeIdComptimeInt ||
9209 cur_type->id == TypeTableEntryIdComptimeFloat)9209 cur_type->id == ZigTypeIdComptimeFloat)
9210 {9210 {
9211 if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {9211 if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {
9212 continue;9212 continue;
...@@ -9215,7 +9215,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9215,7 +9215,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9215 }9215 }
9216 }9216 }
92179217
9218 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&9218 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
9219 cur_type->data.array.len != prev_type->data.array.len &&9219 cur_type->data.array.len != prev_type->data.array.len &&
9220 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,9220 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
9221 source_node, false).id == ConstCastResultIdOk)9221 source_node, false).id == ConstCastResultIdOk)
...@@ -9225,7 +9225,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9225,7 +9225,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9225 continue;9225 continue;
9226 }9226 }
92279227
9228 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&9228 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
9229 cur_type->data.array.len != prev_type->data.array.len &&9229 cur_type->data.array.len != prev_type->data.array.len &&
9230 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,9230 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
9231 source_node, false).id == ConstCastResultIdOk)9231 source_node, false).id == ConstCastResultIdOk)
...@@ -9234,7 +9234,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9234,7 +9234,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9234 continue;9234 continue;
9235 }9235 }
92369236
9237 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&9237 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
9238 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||9238 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
9239 cur_type->data.array.len == 0) &&9239 cur_type->data.array.len == 0) &&
9240 types_match_const_cast_only(ira,9240 types_match_const_cast_only(ira,
...@@ -9245,7 +9245,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9245,7 +9245,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9245 continue;9245 continue;
9246 }9246 }
92479247
9248 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&9248 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
9249 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||9249 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
9250 prev_type->data.array.len == 0) &&9250 prev_type->data.array.len == 0) &&
9251 types_match_const_cast_only(ira,9251 types_match_const_cast_only(ira,
...@@ -9257,7 +9257,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9257,7 +9257,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9257 continue;9257 continue;
9258 }9258 }
92599259
9260 if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion &&9260 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
9261 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))9261 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
9262 {9262 {
9263 if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type)))9263 if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type)))
...@@ -9267,7 +9267,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9267,7 +9267,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9267 }9267 }
9268 }9268 }
92699269
9270 if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion &&9270 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion &&
9271 (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))9271 (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
9272 {9272 {
9273 if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type)))9273 if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type)))
...@@ -9292,7 +9292,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9292,7 +9292,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9292 free(errors);9292 free(errors);
92939293
9294 if (convert_to_const_slice) {9294 if (convert_to_const_slice) {
9295 assert(prev_inst->value.type->id == TypeTableEntryIdArray);9295 assert(prev_inst->value.type->id == ZigTypeIdArray);
9296 ZigType *ptr_type = get_pointer_to_type_extra(9296 ZigType *ptr_type = get_pointer_to_type_extra(
9297 ira->codegen, prev_inst->value.type->data.array.child_type,9297 ira->codegen, prev_inst->value.type->data.array.child_type,
9298 true, false, PtrLenUnknown,9298 true, false, PtrLenUnknown,
...@@ -9305,20 +9305,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9305,20 +9305,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9305 return slice_type;9305 return slice_type;
9306 }9306 }
9307 } else if (err_set_type != nullptr) {9307 } else if (err_set_type != nullptr) {
9308 if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {9308 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
9309 return err_set_type;9309 return err_set_type;
9310 } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) {9310 } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {
9311 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type);9311 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type);
9312 } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) {9312 } else if (expected_type != nullptr && expected_type->id == ZigTypeIdErrorUnion) {
9313 return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);9313 return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);
9314 } else {9314 } else {
9315 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||9315 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9316 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)9316 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
9317 {9317 {
9318 ir_add_error_node(ira, source_node,9318 ir_add_error_node(ira, source_node,
9319 buf_sprintf("unable to make error union out of number literal"));9319 buf_sprintf("unable to make error union out of number literal"));
9320 return ira->codegen->builtin_types.entry_invalid;9320 return ira->codegen->builtin_types.entry_invalid;
9321 } else if (prev_inst->value.type->id == TypeTableEntryIdNull) {9321 } else if (prev_inst->value.type->id == ZigTypeIdNull) {
9322 ir_add_error_node(ira, source_node,9322 ir_add_error_node(ira, source_node,
9323 buf_sprintf("unable to make error union out of null literal"));9323 buf_sprintf("unable to make error union out of null literal"));
9324 return ira->codegen->builtin_types.entry_invalid;9324 return ira->codegen->builtin_types.entry_invalid;
...@@ -9326,14 +9326,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9326,14 +9326,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9326 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);9326 return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);
9327 }9327 }
9328 }9328 }
9329 } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) {9329 } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {
9330 if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||9330 if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
9331 prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)9331 prev_inst->value.type->id == ZigTypeIdComptimeFloat)
9332 {9332 {
9333 ir_add_error_node(ira, source_node,9333 ir_add_error_node(ira, source_node,
9334 buf_sprintf("unable to make maybe out of number literal"));9334 buf_sprintf("unable to make maybe out of number literal"));
9335 return ira->codegen->builtin_types.entry_invalid;9335 return ira->codegen->builtin_types.entry_invalid;
9336 } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) {9336 } else if (prev_inst->value.type->id == ZigTypeIdOptional) {
9337 return prev_inst->value.type;9337 return prev_inst->value.type;
9338 } else {9338 } else {
9339 return get_optional_type(ira->codegen, prev_inst->value.type);9339 return get_optional_type(ira->codegen, prev_inst->value.type);
...@@ -9357,7 +9357,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_...@@ -9357,7 +9357,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
9357 *dest = *src;9357 *dest = *src;
9358 if (!same_global_refs) {9358 if (!same_global_refs) {
9359 dest->global_refs = global_refs;9359 dest->global_refs = global_refs;
9360 if (dest->type->id == TypeTableEntryIdStruct) {9360 if (dest->type->id == ZigTypeIdStruct) {
9361 dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);9361 dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);
9362 memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);9362 memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);
9363 }9363 }
...@@ -9387,8 +9387,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9387,8 +9387,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9387 break;9387 break;
9388 }9388 }
9389 case CastOpNumLitToConcrete:9389 case CastOpNumLitToConcrete:
9390 if (other_val->type->id == TypeTableEntryIdComptimeFloat) {9390 if (other_val->type->id == ZigTypeIdComptimeFloat) {
9391 assert(new_type->id == TypeTableEntryIdFloat);9391 assert(new_type->id == ZigTypeIdFloat);
9392 switch (new_type->data.floating.bit_count) {9392 switch (new_type->data.floating.bit_count) {
9393 case 16:9393 case 16:
9394 const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat);9394 const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat);
...@@ -9405,7 +9405,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9405,7 +9405,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9405 default:9405 default:
9406 zig_unreachable();9406 zig_unreachable();
9407 }9407 }
9408 } else if (other_val->type->id == TypeTableEntryIdComptimeInt) {9408 } else if (other_val->type->id == ZigTypeIdComptimeInt) {
9409 bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);9409 bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);
9410 } else {9410 } else {
9411 zig_unreachable();9411 zig_unreachable();
...@@ -9418,7 +9418,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9418,7 +9418,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9418 zig_unreachable();9418 zig_unreachable();
9419 case CastOpIntToFloat:9419 case CastOpIntToFloat:
9420 {9420 {
9421 assert(new_type->id == TypeTableEntryIdFloat);9421 assert(new_type->id == ZigTypeIdFloat);
94229422
9423 BigFloat bigfloat;9423 BigFloat bigfloat;
9424 bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);9424 bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);
...@@ -9443,7 +9443,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -9443,7 +9443,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
9443 }9443 }
9444 case CastOpFloatToInt:9444 case CastOpFloatToInt:
9445 float_init_bigint(&const_val->data.x_bigint, other_val);9445 float_init_bigint(&const_val->data.x_bigint, other_val);
9446 if (new_type->id == TypeTableEntryIdInt) {9446 if (new_type->id == ZigTypeIdInt) {
9447 if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,9447 if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,
9448 new_type->data.integral.is_signed))9448 new_type->data.integral.is_signed))
9449 {9449 {
...@@ -9493,7 +9493,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -9493,7 +9493,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
9493static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,9493static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
9494 IrInstruction *value, ZigType *wanted_type)9494 IrInstruction *value, ZigType *wanted_type)
9495{9495{
9496 assert(value->value.type->id == TypeTableEntryIdPointer);9496 assert(value->value.type->id == ZigTypeIdPointer);
9497 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);9497 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
94989498
9499 if (instr_is_comptime(value)) {9499 if (instr_is_comptime(value)) {
...@@ -9529,7 +9529,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -9529,7 +9529,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
9529 if (pointee == nullptr)9529 if (pointee == nullptr)
9530 return ira->codegen->invalid_instruction;9530 return ira->codegen->invalid_instruction;
9531 if (pointee->special != ConstValSpecialRuntime) {9531 if (pointee->special != ConstValSpecialRuntime) {
9532 assert(value->value.type->id == TypeTableEntryIdPointer);9532 assert(value->value.type->id == ZigTypeIdPointer);
9533 ZigType *array_type = value->value.type->data.pointer.child_type;9533 ZigType *array_type = value->value.type->data.pointer.child_type;
9534 assert(is_slice(wanted_type));9534 assert(is_slice(wanted_type));
9535 bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;9535 bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
...@@ -9552,9 +9552,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -9552,9 +9552,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
9552}9552}
95539553
9554static bool is_container(ZigType *type) {9554static bool is_container(ZigType *type) {
9555 return type->id == TypeTableEntryIdStruct ||9555 return type->id == ZigTypeIdStruct ||
9556 type->id == TypeTableEntryIdEnum ||9556 type->id == ZigTypeIdEnum ||
9557 type->id == TypeTableEntryIdUnion;9557 type->id == ZigTypeIdUnion;
9558}9558}
95599559
9560static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {9560static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
...@@ -9665,7 +9665,7 @@ static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction,...@@ -9665,7 +9665,7 @@ static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction,
9665}9665}
96669666
9667static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) {9667static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) {
9668 if (result_type->id == TypeTableEntryIdUnreachable)9668 if (result_type->id == ZigTypeIdUnreachable)
9669 ir_finish_bb(ira);9669 ir_finish_bb(ira);
9670 return result_type;9670 return result_type;
9671}9671}
...@@ -9803,7 +9803,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -9803,7 +9803,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
9803 if (type_is_invalid(type_value->value.type))9803 if (type_is_invalid(type_value->value.type))
9804 return ira->codegen->builtin_types.entry_invalid;9804 return ira->codegen->builtin_types.entry_invalid;
98059805
9806 if (type_value->value.type->id != TypeTableEntryIdMetaType) {9806 if (type_value->value.type->id != ZigTypeIdMetaType) {
9807 ir_add_error(ira, type_value,9807 ir_add_error(ira, type_value,
9808 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));9808 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
9809 return ira->codegen->builtin_types.entry_invalid;9809 return ira->codegen->builtin_types.entry_invalid;
...@@ -9823,7 +9823,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -9823,7 +9823,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9823 if (type_is_invalid(fn_value->value.type))9823 if (type_is_invalid(fn_value->value.type))
9824 return nullptr;9824 return nullptr;
98259825
9826 if (fn_value->value.type->id != TypeTableEntryIdFn) {9826 if (fn_value->value.type->id != ZigTypeIdFn) {
9827 ir_add_error_node(ira, fn_value->source_node,9827 ir_add_error_node(ira, fn_value->source_node,
9828 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));9828 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));
9829 return nullptr;9829 return nullptr;
...@@ -9838,7 +9838,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -9838,7 +9838,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9838}9838}
98399839
9840static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {9840static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9841 assert(wanted_type->id == TypeTableEntryIdOptional);9841 assert(wanted_type->id == ZigTypeIdOptional);
98429842
9843 if (instr_is_comptime(value)) {9843 if (instr_is_comptime(value)) {
9844 ZigType *payload_type = wanted_type->data.maybe.child_type;9844 ZigType *payload_type = wanted_type->data.maybe.child_type;
...@@ -9872,7 +9872,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -9872,7 +9872,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
9872static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,9872static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
9873 IrInstruction *value, ZigType *wanted_type)9873 IrInstruction *value, ZigType *wanted_type)
9874{9874{
9875 assert(wanted_type->id == TypeTableEntryIdErrorUnion);9875 assert(wanted_type->id == ZigTypeIdErrorUnion);
98769876
9877 if (instr_is_comptime(value)) {9877 if (instr_is_comptime(value)) {
9878 ZigType *payload_type = wanted_type->data.error_union.payload_type;9878 ZigType *payload_type = wanted_type->data.error_union.payload_type;
...@@ -9903,8 +9903,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -9903,8 +9903,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
9903static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,9903static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
9904 ZigType *wanted_type)9904 ZigType *wanted_type)
9905{9905{
9906 assert(value->value.type->id == TypeTableEntryIdErrorSet);9906 assert(value->value.type->id == ZigTypeIdErrorSet);
9907 assert(wanted_type->id == TypeTableEntryIdErrorSet);9907 assert(wanted_type->id == ZigTypeIdErrorSet);
99089908
9909 if (instr_is_comptime(value)) {9909 if (instr_is_comptime(value)) {
9910 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);9910 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -9944,7 +9944,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -9944,7 +9944,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
9944}9944}
99459945
9946static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {9946static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
9947 assert(wanted_type->id == TypeTableEntryIdErrorUnion);9947 assert(wanted_type->id == ZigTypeIdErrorUnion);
99489948
9949 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);9949 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
99509950
...@@ -10006,7 +10006,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_...@@ -10006,7 +10006,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
10006}10006}
1000710007
10008static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {10008static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
10009 assert(wanted_type->id == TypeTableEntryIdOptional);10009 assert(wanted_type->id == ZigTypeIdOptional);
10010 assert(instr_is_comptime(value));10010 assert(instr_is_comptime(value));
1001110011
10012 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);10012 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -10062,14 +10062,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s...@@ -10062,14 +10062,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1006210062
10063 IrInstruction *array_ptr = nullptr;10063 IrInstruction *array_ptr = nullptr;
10064 IrInstruction *array;10064 IrInstruction *array;
10065 if (array_arg->value.type->id == TypeTableEntryIdPointer) {10065 if (array_arg->value.type->id == ZigTypeIdPointer) {
10066 array = ir_get_deref(ira, source_instr, array_arg);10066 array = ir_get_deref(ira, source_instr, array_arg);
10067 array_ptr = array_arg;10067 array_ptr = array_arg;
10068 } else {10068 } else {
10069 array = array_arg;10069 array = array_arg;
10070 }10070 }
10071 ZigType *array_type = array->value.type;10071 ZigType *array_type = array->value.type;
10072 assert(array_type->id == TypeTableEntryIdArray);10072 assert(array_type->id == ZigTypeIdArray);
1007310073
10074 if (instr_is_comptime(array)) {10074 if (instr_is_comptime(array)) {
10075 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10075 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
...@@ -10103,7 +10103,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -10103,7 +10103,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
10103 IrInstruction *target, ZigType *wanted_type)10103 IrInstruction *target, ZigType *wanted_type)
10104{10104{
10105 Error err;10105 Error err;
10106 assert(wanted_type->id == TypeTableEntryIdInt);10106 assert(wanted_type->id == ZigTypeIdInt);
1010710107
10108 ZigType *actual_type = target->value.type;10108 ZigType *actual_type = target->value.type;
10109 if ((err = ensure_complete_type(ira->codegen, actual_type)))10109 if ((err = ensure_complete_type(ira->codegen, actual_type)))
...@@ -10117,7 +10117,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -10117,7 +10117,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
10117 return ira->codegen->invalid_instruction;10117 return ira->codegen->invalid_instruction;
10118 }10118 }
1011910119
10120 assert(actual_type->id == TypeTableEntryIdEnum);10120 assert(actual_type->id == ZigTypeIdEnum);
1012110121
10122 if (instr_is_comptime(target)) {10122 if (instr_is_comptime(target)) {
10123 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10123 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10138,8 +10138,8 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -10138,8 +10138,8 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
10138static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,10138static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
10139 IrInstruction *target, ZigType *wanted_type)10139 IrInstruction *target, ZigType *wanted_type)
10140{10140{
10141 assert(target->value.type->id == TypeTableEntryIdUnion);10141 assert(target->value.type->id == ZigTypeIdUnion);
10142 assert(wanted_type->id == TypeTableEntryIdEnum);10142 assert(wanted_type->id == ZigTypeIdEnum);
10143 assert(wanted_type == target->value.type->data.unionation.tag_type);10143 assert(wanted_type == target->value.type->data.unionation.tag_type);
1014410144
10145 if (instr_is_comptime(target)) {10145 if (instr_is_comptime(target)) {
...@@ -10173,8 +10173,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -10173,8 +10173,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
10173 IrInstruction *target, ZigType *wanted_type)10173 IrInstruction *target, ZigType *wanted_type)
10174{10174{
10175 Error err;10175 Error err;
10176 assert(wanted_type->id == TypeTableEntryIdUnion);10176 assert(wanted_type->id == ZigTypeIdUnion);
10177 assert(target->value.type->id == TypeTableEntryIdEnum);10177 assert(target->value.type->id == ZigTypeIdEnum);
1017810178
10179 if (instr_is_comptime(target)) {10179 if (instr_is_comptime(target)) {
10180 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10180 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10231,13 +10231,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -10231,13 +10231,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
10231static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,10231static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
10232 IrInstruction *target, ZigType *wanted_type)10232 IrInstruction *target, ZigType *wanted_type)
10233{10233{
10234 assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat);10234 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1023510235
10236 if (instr_is_comptime(target)) {10236 if (instr_is_comptime(target)) {
10237 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10237 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
10238 if (!val)10238 if (!val)
10239 return ira->codegen->invalid_instruction;10239 return ira->codegen->invalid_instruction;
10240 if (wanted_type->id == TypeTableEntryIdInt) {10240 if (wanted_type->id == ZigTypeIdInt) {
10241 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {10241 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
10242 ir_add_error(ira, source_instr,10242 ir_add_error(ira, source_instr,
10243 buf_sprintf("attempt to cast negative value to unsigned integer"));10243 buf_sprintf("attempt to cast negative value to unsigned integer"));
...@@ -10255,7 +10255,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -10255,7 +10255,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
10255 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10255 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
10256 source_instr->source_node, wanted_type);10256 source_instr->source_node, wanted_type);
10257 result->value.type = wanted_type;10257 result->value.type = wanted_type;
10258 if (wanted_type->id == TypeTableEntryIdInt) {10258 if (wanted_type->id == ZigTypeIdInt) {
10259 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);10259 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
10260 } else {10260 } else {
10261 float_init_float(&result->value, val);10261 float_init_float(&result->value, val);
...@@ -10273,7 +10273,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -10273,7 +10273,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
10273 IrInstruction *target, ZigType *wanted_type)10273 IrInstruction *target, ZigType *wanted_type)
10274{10274{
10275 Error err;10275 Error err;
10276 assert(wanted_type->id == TypeTableEntryIdEnum);10276 assert(wanted_type->id == ZigTypeIdEnum);
1027710277
10278 ZigType *actual_type = target->value.type;10278 ZigType *actual_type = target->value.type;
1027910279
...@@ -10288,7 +10288,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -10288,7 +10288,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
10288 return ira->codegen->invalid_instruction;10288 return ira->codegen->invalid_instruction;
10289 }10289 }
1029010290
10291 assert(actual_type->id == TypeTableEntryIdInt);10291 assert(actual_type->id == ZigTypeIdInt);
1029210292
10293 if (instr_is_comptime(target)) {10293 if (instr_is_comptime(target)) {
10294 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10294 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10328,9 +10328,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -10328,9 +10328,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1032810328
10329 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,10329 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
10330 source_instr->source_node, wanted_type);10330 source_instr->source_node, wanted_type);
10331 if (wanted_type->id == TypeTableEntryIdComptimeFloat) {10331 if (wanted_type->id == ZigTypeIdComptimeFloat) {
10332 float_init_float(&result->value, val);10332 float_init_float(&result->value, val);
10333 } else if (wanted_type->id == TypeTableEntryIdComptimeInt) {10333 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
10334 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);10334 bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
10335 } else {10335 } else {
10336 zig_unreachable();10336 zig_unreachable();
...@@ -10341,9 +10341,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -10341,9 +10341,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
10341static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10341static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10342 ZigType *wanted_type)10342 ZigType *wanted_type)
10343{10343{
10344 assert(target->value.type->id == TypeTableEntryIdInt);10344 assert(target->value.type->id == ZigTypeIdInt);
10345 assert(!target->value.type->data.integral.is_signed);10345 assert(!target->value.type->data.integral.is_signed);
10346 assert(wanted_type->id == TypeTableEntryIdErrorSet);10346 assert(wanted_type->id == ZigTypeIdErrorSet);
1034710347
10348 if (instr_is_comptime(target)) {10348 if (instr_is_comptime(target)) {
10349 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10349 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
...@@ -10406,7 +10406,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -10406,7 +10406,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
10406static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10406static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10407 ZigType *wanted_type)10407 ZigType *wanted_type)
10408{10408{
10409 assert(wanted_type->id == TypeTableEntryIdInt);10409 assert(wanted_type->id == ZigTypeIdInt);
1041010410
10411 ZigType *err_type = target->value.type;10411 ZigType *err_type = target->value.type;
1041210412
...@@ -10419,9 +10419,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10419,9 +10419,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10419 source_instr->source_node, wanted_type);10419 source_instr->source_node, wanted_type);
1042010420
10421 ErrorTableEntry *err;10421 ErrorTableEntry *err;
10422 if (err_type->id == TypeTableEntryIdErrorUnion) {10422 if (err_type->id == ZigTypeIdErrorUnion) {
10423 err = val->data.x_err_union.err;10423 err = val->data.x_err_union.err;
10424 } else if (err_type->id == TypeTableEntryIdErrorSet) {10424 } else if (err_type->id == ZigTypeIdErrorSet) {
10425 err = val->data.x_err_set;10425 err = val->data.x_err_set;
10426 } else {10426 } else {
10427 zig_unreachable();10427 zig_unreachable();
...@@ -10443,9 +10443,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10443,9 +10443,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10443 }10443 }
1044410444
10445 ZigType *err_set_type;10445 ZigType *err_set_type;
10446 if (err_type->id == TypeTableEntryIdErrorUnion) {10446 if (err_type->id == ZigTypeIdErrorUnion) {
10447 err_set_type = err_type->data.error_union.err_set_type;10447 err_set_type = err_type->data.error_union.err_set_type;
10448 } else if (err_type->id == TypeTableEntryIdErrorSet) {10448 } else if (err_type->id == ZigTypeIdErrorSet) {
10449 err_set_type = err_type;10449 err_set_type = err_type;
10450 } else {10450 } else {
10451 zig_unreachable();10451 zig_unreachable();
...@@ -10486,10 +10486,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -10486,10 +10486,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
10486static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,10486static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
10487 ZigType *wanted_type)10487 ZigType *wanted_type)
10488{10488{
10489 assert(wanted_type->id == TypeTableEntryIdPointer);10489 assert(wanted_type->id == ZigTypeIdPointer);
10490 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment);10490 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment);
10491 ZigType *array_type = wanted_type->data.pointer.child_type;10491 ZigType *array_type = wanted_type->data.pointer.child_type;
10492 assert(array_type->id == TypeTableEntryIdArray);10492 assert(array_type->id == ZigTypeIdArray);
10493 assert(array_type->data.array.len == 1);10493 assert(array_type->data.array.len == 1);
1049410494
10495 if (instr_is_comptime(target)) {10495 if (instr_is_comptime(target)) {
...@@ -10497,7 +10497,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -10497,7 +10497,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
10497 if (!val)10497 if (!val)
10498 return ira->codegen->invalid_instruction;10498 return ira->codegen->invalid_instruction;
1049910499
10500 assert(val->type->id == TypeTableEntryIdPointer);10500 assert(val->type->id == ZigTypeIdPointer);
10501 ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);10501 ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);
10502 if (pointee == nullptr)10502 if (pointee == nullptr)
10503 return ira->codegen->invalid_instruction;10503 return ira->codegen->invalid_instruction;
...@@ -10638,8 +10638,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10638,8 +10638,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10638 }10638 }
1063910639
10640 // widening conversion10640 // widening conversion
10641 if (wanted_type->id == TypeTableEntryIdInt &&10641 if (wanted_type->id == ZigTypeIdInt &&
10642 actual_type->id == TypeTableEntryIdInt &&10642 actual_type->id == ZigTypeIdInt &&
10643 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&10643 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
10644 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)10644 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
10645 {10645 {
...@@ -10647,16 +10647,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10647,16 +10647,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10647 }10647 }
1064810648
10649 // small enough unsigned ints can get casted to large enough signed ints10649 // small enough unsigned ints can get casted to large enough signed ints
10650 if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed &&10650 if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed &&
10651 actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed &&10651 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
10652 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)10652 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
10653 {10653 {
10654 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);10654 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
10655 }10655 }
1065610656
10657 // float widening conversion10657 // float widening conversion
10658 if (wanted_type->id == TypeTableEntryIdFloat &&10658 if (wanted_type->id == ZigTypeIdFloat &&
10659 actual_type->id == TypeTableEntryIdFloat &&10659 actual_type->id == ZigTypeIdFloat &&
10660 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)10660 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
10661 {10661 {
10662 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);10662 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
...@@ -10664,9 +10664,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10664,9 +10664,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1066410664
1066510665
10666 // cast from [N]T to []const T10666 // cast from [N]T to []const T
10667 if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) {10667 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
10668 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10668 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10669 assert(ptr_type->id == TypeTableEntryIdPointer);10669 assert(ptr_type->id == ZigTypeIdPointer);
10670 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10670 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10671 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10671 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10672 source_node, false).id == ConstCastResultIdOk)10672 source_node, false).id == ConstCastResultIdOk)
...@@ -10677,12 +10677,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10677,12 +10677,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1067710677
10678 // cast from *const [N]T to []const T10678 // cast from *const [N]T to []const T
10679 if (is_slice(wanted_type) &&10679 if (is_slice(wanted_type) &&
10680 actual_type->id == TypeTableEntryIdPointer &&10680 actual_type->id == ZigTypeIdPointer &&
10681 actual_type->data.pointer.is_const &&10681 actual_type->data.pointer.is_const &&
10682 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)10682 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
10683 {10683 {
10684 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10684 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10685 assert(ptr_type->id == TypeTableEntryIdPointer);10685 assert(ptr_type->id == ZigTypeIdPointer);
1068610686
10687 ZigType *array_type = actual_type->data.pointer.child_type;10687 ZigType *array_type = actual_type->data.pointer.child_type;
1068810688
...@@ -10695,14 +10695,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10695,14 +10695,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10695 }10695 }
1069610696
10697 // cast from [N]T to *const []const T10697 // cast from [N]T to *const []const T
10698 if (wanted_type->id == TypeTableEntryIdPointer &&10698 if (wanted_type->id == ZigTypeIdPointer &&
10699 wanted_type->data.pointer.is_const &&10699 wanted_type->data.pointer.is_const &&
10700 is_slice(wanted_type->data.pointer.child_type) &&10700 is_slice(wanted_type->data.pointer.child_type) &&
10701 actual_type->id == TypeTableEntryIdArray)10701 actual_type->id == ZigTypeIdArray)
10702 {10702 {
10703 ZigType *ptr_type =10703 ZigType *ptr_type =
10704 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;10704 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
10705 assert(ptr_type->id == TypeTableEntryIdPointer);10705 assert(ptr_type->id == ZigTypeIdPointer);
10706 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10706 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10707 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10707 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10708 source_node, false).id == ConstCastResultIdOk)10708 source_node, false).id == ConstCastResultIdOk)
...@@ -10720,13 +10720,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10720,13 +10720,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10720 }10720 }
1072110721
10722 // cast from [N]T to ?[]const T10722 // cast from [N]T to ?[]const T
10723 if (wanted_type->id == TypeTableEntryIdOptional &&10723 if (wanted_type->id == ZigTypeIdOptional &&
10724 is_slice(wanted_type->data.maybe.child_type) &&10724 is_slice(wanted_type->data.maybe.child_type) &&
10725 actual_type->id == TypeTableEntryIdArray)10725 actual_type->id == ZigTypeIdArray)
10726 {10726 {
10727 ZigType *ptr_type =10727 ZigType *ptr_type =
10728 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;10728 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
10729 assert(ptr_type->id == TypeTableEntryIdPointer);10729 assert(ptr_type->id == ZigTypeIdPointer);
10730 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10730 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10731 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10731 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10732 source_node, false).id == ConstCastResultIdOk)10732 source_node, false).id == ConstCastResultIdOk)
...@@ -10744,11 +10744,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10744,11 +10744,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10744 }10744 }
1074510745
10746 // *[N]T to [*]T10746 // *[N]T to [*]T
10747 if (wanted_type->id == TypeTableEntryIdPointer &&10747 if (wanted_type->id == ZigTypeIdPointer &&
10748 wanted_type->data.pointer.ptr_len == PtrLenUnknown &&10748 wanted_type->data.pointer.ptr_len == PtrLenUnknown &&
10749 actual_type->id == TypeTableEntryIdPointer &&10749 actual_type->id == ZigTypeIdPointer &&
10750 actual_type->data.pointer.ptr_len == PtrLenSingle &&10750 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10751 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&10751 actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
10752 actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&10752 actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&
10753 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,10753 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
10754 actual_type->data.pointer.child_type->data.array.child_type, source_node,10754 actual_type->data.pointer.child_type->data.array.child_type, source_node,
...@@ -10759,12 +10759,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10759,12 +10759,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1075910759
10760 // *[N]T to []T10760 // *[N]T to []T
10761 if (is_slice(wanted_type) &&10761 if (is_slice(wanted_type) &&
10762 actual_type->id == TypeTableEntryIdPointer &&10762 actual_type->id == ZigTypeIdPointer &&
10763 actual_type->data.pointer.ptr_len == PtrLenSingle &&10763 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10764 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)10764 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
10765 {10765 {
10766 ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;10766 ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
10767 assert(slice_ptr_type->id == TypeTableEntryIdPointer);10767 assert(slice_ptr_type->id == ZigTypeIdPointer);
10768 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,10768 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
10769 actual_type->data.pointer.child_type->data.array.child_type, source_node,10769 actual_type->data.pointer.child_type->data.array.child_type, source_node,
10770 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)10770 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)
...@@ -10776,23 +10776,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10776,23 +10776,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1077610776
10777 // cast from T to ?T10777 // cast from T to ?T
10778 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism10778 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism
10779 if (wanted_type->id == TypeTableEntryIdOptional) {10779 if (wanted_type->id == ZigTypeIdOptional) {
10780 ZigType *wanted_child_type = wanted_type->data.maybe.child_type;10780 ZigType *wanted_child_type = wanted_type->data.maybe.child_type;
10781 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,10781 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
10782 false).id == ConstCastResultIdOk)10782 false).id == ConstCastResultIdOk)
10783 {10783 {
10784 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);10784 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
10785 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||10785 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10786 actual_type->id == TypeTableEntryIdComptimeFloat)10786 actual_type->id == ZigTypeIdComptimeFloat)
10787 {10787 {
10788 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {10788 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
10789 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);10789 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
10790 } else {10790 } else {
10791 return ira->codegen->invalid_instruction;10791 return ira->codegen->invalid_instruction;
10792 }10792 }
10793 } else if (wanted_child_type->id == TypeTableEntryIdPointer &&10793 } else if (wanted_child_type->id == ZigTypeIdPointer &&
10794 wanted_child_type->data.pointer.is_const &&10794 wanted_child_type->data.pointer.is_const &&
10795 (actual_type->id == TypeTableEntryIdPointer || is_container(actual_type)))10795 (actual_type->id == ZigTypeIdPointer || is_container(actual_type)))
10796 {10796 {
10797 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);10797 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);
10798 if (type_is_invalid(cast1->value.type))10798 if (type_is_invalid(cast1->value.type))
...@@ -10804,11 +10804,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10804,11 +10804,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1080410804
10805 return cast2;10805 return cast2;
10806 } else if (10806 } else if (
10807 wanted_child_type->id == TypeTableEntryIdPointer &&10807 wanted_child_type->id == ZigTypeIdPointer &&
10808 wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&10808 wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&
10809 actual_type->id == TypeTableEntryIdPointer &&10809 actual_type->id == ZigTypeIdPointer &&
10810 actual_type->data.pointer.ptr_len == PtrLenSingle &&10810 actual_type->data.pointer.ptr_len == PtrLenSingle &&
10811 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&10811 actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
10812 actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&10812 actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&
10813 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,10813 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
10814 actual_type->data.pointer.child_type->data.array.child_type, source_node,10814 actual_type->data.pointer.child_type->data.array.child_type, source_node,
...@@ -10822,20 +10822,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10822,20 +10822,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10822 }10822 }
1082310823
10824 // cast from null literal to maybe type10824 // cast from null literal to maybe type
10825 if (wanted_type->id == TypeTableEntryIdOptional &&10825 if (wanted_type->id == ZigTypeIdOptional &&
10826 actual_type->id == TypeTableEntryIdNull)10826 actual_type->id == ZigTypeIdNull)
10827 {10827 {
10828 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);10828 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
10829 }10829 }
1083010830
10831 // cast from child type of error type to error type10831 // cast from child type of error type to error type
10832 if (wanted_type->id == TypeTableEntryIdErrorUnion) {10832 if (wanted_type->id == ZigTypeIdErrorUnion) {
10833 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,10833 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
10834 source_node, false).id == ConstCastResultIdOk)10834 source_node, false).id == ConstCastResultIdOk)
10835 {10835 {
10836 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);10836 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
10837 } else if (actual_type->id == TypeTableEntryIdComptimeInt ||10837 } else if (actual_type->id == ZigTypeIdComptimeInt ||
10838 actual_type->id == TypeTableEntryIdComptimeFloat)10838 actual_type->id == ZigTypeIdComptimeFloat)
10839 {10839 {
10840 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {10840 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
10841 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);10841 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
...@@ -10846,13 +10846,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10846,13 +10846,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10846 }10846 }
1084710847
10848 // cast from [N]T to E![]const T10848 // cast from [N]T to E![]const T
10849 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10849 if (wanted_type->id == ZigTypeIdErrorUnion &&
10850 is_slice(wanted_type->data.error_union.payload_type) &&10850 is_slice(wanted_type->data.error_union.payload_type) &&
10851 actual_type->id == TypeTableEntryIdArray)10851 actual_type->id == ZigTypeIdArray)
10852 {10852 {
10853 ZigType *ptr_type =10853 ZigType *ptr_type =
10854 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;10854 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
10855 assert(ptr_type->id == TypeTableEntryIdPointer);10855 assert(ptr_type->id == ZigTypeIdPointer);
10856 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&10856 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
10857 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,10857 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
10858 source_node, false).id == ConstCastResultIdOk)10858 source_node, false).id == ConstCastResultIdOk)
...@@ -10870,22 +10870,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10870,22 +10870,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10870 }10870 }
1087110871
10872 // cast from error set to error union type10872 // cast from error set to error union type
10873 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10873 if (wanted_type->id == ZigTypeIdErrorUnion &&
10874 actual_type->id == TypeTableEntryIdErrorSet)10874 actual_type->id == ZigTypeIdErrorSet)
10875 {10875 {
10876 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);10876 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);
10877 }10877 }
1087810878
10879 // cast from T to E!?T10879 // cast from T to E!?T
10880 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10880 if (wanted_type->id == ZigTypeIdErrorUnion &&
10881 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&10881 wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional &&
10882 actual_type->id != TypeTableEntryIdOptional)10882 actual_type->id != ZigTypeIdOptional)
10883 {10883 {
10884 ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;10884 ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
10885 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||10885 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||
10886 actual_type->id == TypeTableEntryIdNull ||10886 actual_type->id == ZigTypeIdNull ||
10887 actual_type->id == TypeTableEntryIdComptimeInt ||10887 actual_type->id == ZigTypeIdComptimeInt ||
10888 actual_type->id == TypeTableEntryIdComptimeFloat)10888 actual_type->id == ZigTypeIdComptimeFloat)
10889 {10889 {
10890 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);10890 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
10891 if (type_is_invalid(cast1->value.type))10891 if (type_is_invalid(cast1->value.type))
...@@ -10901,12 +10901,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10901,12 +10901,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1090110901
10902 // cast from number literal to another type10902 // cast from number literal to another type
10903 // cast from number literal to *const integer10903 // cast from number literal to *const integer
10904 if (actual_type->id == TypeTableEntryIdComptimeFloat ||10904 if (actual_type->id == ZigTypeIdComptimeFloat ||
10905 actual_type->id == TypeTableEntryIdComptimeInt)10905 actual_type->id == ZigTypeIdComptimeInt)
10906 {10906 {
10907 if ((err = ensure_complete_type(ira->codegen, wanted_type)))10907 if ((err = ensure_complete_type(ira->codegen, wanted_type)))
10908 return ira->codegen->invalid_instruction;10908 return ira->codegen->invalid_instruction;
10909 if (wanted_type->id == TypeTableEntryIdEnum) {10909 if (wanted_type->id == ZigTypeIdEnum) {
10910 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);10910 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
10911 if (type_is_invalid(cast1->value.type))10911 if (type_is_invalid(cast1->value.type))
10912 return ira->codegen->invalid_instruction;10912 return ira->codegen->invalid_instruction;
...@@ -10916,7 +10916,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10916,7 +10916,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10916 return ira->codegen->invalid_instruction;10916 return ira->codegen->invalid_instruction;
1091710917
10918 return cast2;10918 return cast2;
10919 } else if (wanted_type->id == TypeTableEntryIdPointer &&10919 } else if (wanted_type->id == ZigTypeIdPointer &&
10920 wanted_type->data.pointer.is_const)10920 wanted_type->data.pointer.is_const)
10921 {10921 {
10922 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);10922 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
...@@ -10930,15 +10930,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10930,15 +10930,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10930 return cast2;10930 return cast2;
10931 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {10931 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
10932 CastOp op;10932 CastOp op;
10933 if ((actual_type->id == TypeTableEntryIdComptimeFloat &&10933 if ((actual_type->id == ZigTypeIdComptimeFloat &&
10934 wanted_type->id == TypeTableEntryIdFloat) ||10934 wanted_type->id == ZigTypeIdFloat) ||
10935 (actual_type->id == TypeTableEntryIdComptimeInt &&10935 (actual_type->id == ZigTypeIdComptimeInt &&
10936 wanted_type->id == TypeTableEntryIdInt))10936 wanted_type->id == ZigTypeIdInt))
10937 {10937 {
10938 op = CastOpNumLitToConcrete;10938 op = CastOpNumLitToConcrete;
10939 } else if (wanted_type->id == TypeTableEntryIdInt) {10939 } else if (wanted_type->id == ZigTypeIdInt) {
10940 op = CastOpFloatToInt;10940 op = CastOpFloatToInt;
10941 } else if (wanted_type->id == TypeTableEntryIdFloat) {10941 } else if (wanted_type->id == ZigTypeIdFloat) {
10942 op = CastOpIntToFloat;10942 op = CastOpIntToFloat;
10943 } else {10943 } else {
10944 zig_unreachable();10944 zig_unreachable();
...@@ -10952,14 +10952,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10952,14 +10952,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10952 // cast from typed number to integer or float literal.10952 // cast from typed number to integer or float literal.
10953 // works when the number is known at compile time10953 // works when the number is known at compile time
10954 if (instr_is_comptime(value) &&10954 if (instr_is_comptime(value) &&
10955 ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) ||10955 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
10956 (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat)))10956 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
10957 {10957 {
10958 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);10958 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
10959 }10959 }
1096010960
10961 // cast from union to the enum type of the union10961 // cast from union to the enum type of the union
10962 if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) {10962 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
10963 if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))10963 if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))
10964 return ira->codegen->invalid_instruction;10964 return ira->codegen->invalid_instruction;
1096510965
...@@ -10969,7 +10969,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10969,7 +10969,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10969 }10969 }
1097010970
10971 // enum to union which has the enum as the tag type10971 // enum to union which has the enum as the tag type
10972 if (wanted_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum &&10972 if (wanted_type->id == ZigTypeIdUnion && actual_type->id == ZigTypeIdEnum &&
10973 (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||10973 (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||
10974 wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))10974 wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
10975 {10975 {
...@@ -10982,7 +10982,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10982,7 +10982,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10982 }10982 }
1098310983
10984 // enum to &const union which has the enum as the tag type10984 // enum to &const union which has the enum as the tag type
10985 if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) {10985 if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) {
10986 ZigType *union_type = wanted_type->data.pointer.child_type;10986 ZigType *union_type = wanted_type->data.pointer.child_type;
10987 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||10987 if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
10988 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)10988 union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
...@@ -11005,11 +11005,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -11005,11 +11005,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
11005 }11005 }
1100611006
11007 // cast from *T to *[1]T11007 // cast from *T to *[1]T
11008 if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&11008 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
11009 actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)11009 actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
11010 {11010 {
11011 ZigType *array_type = wanted_type->data.pointer.child_type;11011 ZigType *array_type = wanted_type->data.pointer.child_type;
11012 if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 &&11012 if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 &&
11013 types_match_const_cast_only(ira, array_type->data.array.child_type,11013 types_match_const_cast_only(ira, array_type->data.array.child_type,
11014 actual_type->data.pointer.child_type, source_node,11014 actual_type->data.pointer.child_type, source_node,
11015 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)11015 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
...@@ -11029,7 +11029,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -11029,7 +11029,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
11029 }11029 }
1103011030
11031 // cast from T to *T where T is zero bits11031 // cast from T to *T where T is zero bits
11032 if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&11032 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
11033 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,11033 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
11034 actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)11034 actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
11035 {11035 {
...@@ -11043,7 +11043,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -11043,7 +11043,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1104311043
1104411044
11045 // cast from undefined to anything11045 // cast from undefined to anything
11046 if (actual_type->id == TypeTableEntryIdUndefined) {11046 if (actual_type->id == ZigTypeIdUndefined) {
11047 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);11047 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
11048 }11048 }
1104911049
...@@ -11073,7 +11073,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig...@@ -11073,7 +11073,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig
11073 return value; // anything will do11073 return value; // anything will do
11074 if (expected_type == value->value.type)11074 if (expected_type == value->value.type)
11075 return value; // match11075 return value; // match
11076 if (value->value.type->id == TypeTableEntryIdUnreachable)11076 if (value->value.type->id == ZigTypeIdUnreachable)
11077 return value;11077 return value;
1107811078
11079 return ir_analyze_cast(ira, value, expected_type, value);11079 return ir_analyze_cast(ira, value, expected_type, value);
...@@ -11083,7 +11083,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -11083,7 +11083,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
11083 ZigType *type_entry = ptr->value.type;11083 ZigType *type_entry = ptr->value.type;
11084 if (type_is_invalid(type_entry)) {11084 if (type_is_invalid(type_entry)) {
11085 return ira->codegen->invalid_instruction;11085 return ira->codegen->invalid_instruction;
11086 } else if (type_entry->id == TypeTableEntryIdPointer) {11086 } else if (type_entry->id == ZigTypeIdPointer) {
11087 ZigType *child_type = type_entry->data.pointer.child_type;11087 ZigType *child_type = type_entry->data.pointer.child_type;
11088 if (instr_is_comptime(ptr)) {11088 if (instr_is_comptime(ptr)) {
11089 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||11089 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||
...@@ -11198,7 +11198,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -11198,7 +11198,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
11198 return false;11198 return false;
1119911199
11200 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");11200 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
11201 assert(atomic_order_val->type->id == TypeTableEntryIdMetaType);11201 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
11202 ZigType *atomic_order_type = atomic_order_val->data.x_type;11202 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1120311203
11204 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);11204 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
...@@ -11218,7 +11218,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -11218,7 +11218,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
11218 return false;11218 return false;
1121911219
11220 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");11220 ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
11221 assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType);11221 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
11222 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;11222 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1122311223
11224 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);11224 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
...@@ -11238,7 +11238,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -11238,7 +11238,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
11238 return false;11238 return false;
1123911239
11240 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");11240 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
11241 assert(global_linkage_val->type->id == TypeTableEntryIdMetaType);11241 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
11242 ZigType *global_linkage_type = global_linkage_val->data.x_type;11242 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1124311243
11244 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);11244 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
...@@ -11258,7 +11258,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -11258,7 +11258,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
11258 return false;11258 return false;
1125911259
11260 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");11260 ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
11261 assert(float_mode_val->type->id == TypeTableEntryIdMetaType);11261 assert(float_mode_val->type->id == ZigTypeIdMetaType);
11262 ZigType *float_mode_type = float_mode_val->data.x_type;11262 ZigType *float_mode_type = float_mode_val->data.x_type;
1126311263
11264 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);11264 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
...@@ -11340,7 +11340,7 @@ static ZigType *ir_analyze_instruction_return(IrAnalyze *ira,...@@ -11340,7 +11340,7 @@ static ZigType *ir_analyze_instruction_return(IrAnalyze *ira,
11340 return ir_unreach_error(ira);11340 return ir_unreach_error(ira);
1134111341
11342 if (casted_value->value.special == ConstValSpecialRuntime &&11342 if (casted_value->value.special == ConstValSpecialRuntime &&
11343 casted_value->value.type->id == TypeTableEntryIdPointer &&11343 casted_value->value.type->id == ZigTypeIdPointer &&
11344 casted_value->value.data.rh_ptr == RuntimeHintPtrStack)11344 casted_value->value.data.rh_ptr == RuntimeHintPtrStack)
11345 {11345 {
11346 ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable"));11346 ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable"));
...@@ -11388,8 +11388,8 @@ static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_o...@@ -11388,8 +11388,8 @@ static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_o
11388 if (op2_val == nullptr)11388 if (op2_val == nullptr)
11389 return ira->codegen->builtin_types.entry_invalid;11389 return ira->codegen->builtin_types.entry_invalid;
1139011390
11391 assert(casted_op1->value.type->id == TypeTableEntryIdBool);11391 assert(casted_op1->value.type->id == ZigTypeIdBool);
11392 assert(casted_op2->value.type->id == TypeTableEntryIdBool);11392 assert(casted_op2->value.type->id == ZigTypeIdBool);
11393 if (bin_op_instruction->op_id == IrBinOpBoolOr) {11393 if (bin_op_instruction->op_id == IrBinOpBoolOr) {
11394 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;11394 out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;
11395 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {11395 } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {
...@@ -11442,19 +11442,19 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op...@@ -11442,19 +11442,19 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
11442 IrBinOp op_id = bin_op_instruction->op_id;11442 IrBinOp op_id = bin_op_instruction->op_id;
11443 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);11443 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
11444 if (is_equality_cmp &&11444 if (is_equality_cmp &&
11445 ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) ||11445 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||
11446 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||11446 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) ||
11447 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))11447 (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull)))
11448 {11448 {
11449 if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {11449 if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) {
11450 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);11450 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
11451 out_val->data.x_bool = (op_id == IrBinOpCmpEq);11451 out_val->data.x_bool = (op_id == IrBinOpCmpEq);
11452 return ira->codegen->builtin_types.entry_bool;11452 return ira->codegen->builtin_types.entry_bool;
11453 }11453 }
11454 IrInstruction *maybe_op;11454 IrInstruction *maybe_op;
11455 if (op1->value.type->id == TypeTableEntryIdNull) {11455 if (op1->value.type->id == ZigTypeIdNull) {
11456 maybe_op = op2;11456 maybe_op = op2;
11457 } else if (op2->value.type->id == TypeTableEntryIdNull) {11457 } else if (op2->value.type->id == ZigTypeIdNull) {
11458 maybe_op = op1;11458 maybe_op = op1;
11459 } else {11459 } else {
11460 zig_unreachable();11460 zig_unreachable();
...@@ -11481,7 +11481,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op...@@ -11481,7 +11481,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
11481 return ira->codegen->builtin_types.entry_bool;11481 return ira->codegen->builtin_types.entry_bool;
11482 }11482 }
1148311483
11484 if (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) {11484 if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) {
11485 if (!is_equality_cmp) {11485 if (!is_equality_cmp) {
11486 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));11486 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
11487 return ira->codegen->builtin_types.entry_invalid;11487 return ira->codegen->builtin_types.entry_invalid;
...@@ -11575,42 +11575,42 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op...@@ -11575,42 +11575,42 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
1157511575
11576 bool operator_allowed;11576 bool operator_allowed;
11577 switch (resolved_type->id) {11577 switch (resolved_type->id) {
11578 case TypeTableEntryIdInvalid:11578 case ZigTypeIdInvalid:
11579 zig_unreachable(); // handled above11579 zig_unreachable(); // handled above
1158011580
11581 case TypeTableEntryIdComptimeFloat:11581 case ZigTypeIdComptimeFloat:
11582 case TypeTableEntryIdComptimeInt:11582 case ZigTypeIdComptimeInt:
11583 case TypeTableEntryIdInt:11583 case ZigTypeIdInt:
11584 case TypeTableEntryIdFloat:11584 case ZigTypeIdFloat:
11585 operator_allowed = true;11585 operator_allowed = true;
11586 break;11586 break;
1158711587
11588 case TypeTableEntryIdBool:11588 case ZigTypeIdBool:
11589 case TypeTableEntryIdMetaType:11589 case ZigTypeIdMetaType:
11590 case TypeTableEntryIdVoid:11590 case ZigTypeIdVoid:
11591 case TypeTableEntryIdPointer:11591 case ZigTypeIdPointer:
11592 case TypeTableEntryIdErrorSet:11592 case ZigTypeIdErrorSet:
11593 case TypeTableEntryIdFn:11593 case ZigTypeIdFn:
11594 case TypeTableEntryIdOpaque:11594 case ZigTypeIdOpaque:
11595 case TypeTableEntryIdNamespace:11595 case ZigTypeIdNamespace:
11596 case TypeTableEntryIdBlock:11596 case ZigTypeIdBlock:
11597 case TypeTableEntryIdBoundFn:11597 case ZigTypeIdBoundFn:
11598 case TypeTableEntryIdArgTuple:11598 case ZigTypeIdArgTuple:
11599 case TypeTableEntryIdPromise:11599 case ZigTypeIdPromise:
11600 case TypeTableEntryIdEnum:11600 case ZigTypeIdEnum:
11601 operator_allowed = is_equality_cmp;11601 operator_allowed = is_equality_cmp;
11602 break;11602 break;
1160311603
11604 case TypeTableEntryIdUnreachable:11604 case ZigTypeIdUnreachable:
11605 case TypeTableEntryIdArray:11605 case ZigTypeIdArray:
11606 case TypeTableEntryIdStruct:11606 case ZigTypeIdStruct:
11607 case TypeTableEntryIdUndefined:11607 case ZigTypeIdUndefined:
11608 case TypeTableEntryIdNull:11608 case ZigTypeIdNull:
11609 case TypeTableEntryIdErrorUnion:11609 case ZigTypeIdErrorUnion:
11610 case TypeTableEntryIdUnion:11610 case ZigTypeIdUnion:
11611 operator_allowed = false;11611 operator_allowed = false;
11612 break;11612 break;
11613 case TypeTableEntryIdOptional:11613 case ZigTypeIdOptional:
11614 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;11614 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
11615 break;11615 break;
11616 }11616 }
...@@ -11638,10 +11638,10 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op...@@ -11638,10 +11638,10 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
11638 return ira->codegen->builtin_types.entry_invalid;11638 return ira->codegen->builtin_types.entry_invalid;
1163911639
11640 bool answer;11640 bool answer;
11641 if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {11641 if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) {
11642 Cmp cmp_result = float_cmp(op1_val, op2_val);11642 Cmp cmp_result = float_cmp(op1_val, op2_val);
11643 answer = resolve_cmp_op_id(op_id, cmp_result);11643 answer = resolve_cmp_op_id(op_id, cmp_result);
11644 } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) {11644 } else if (resolved_type->id == ZigTypeIdComptimeInt || resolved_type->id == ZigTypeIdInt) {
11645 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);11645 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
11646 answer = resolve_cmp_op_id(op_id, cmp_result);11646 answer = resolve_cmp_op_id(op_id, cmp_result);
11647 } else {11647 } else {
...@@ -11661,7 +11661,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op...@@ -11661,7 +11661,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
11661 }11661 }
1166211662
11663 // some comparisons with unsigned numbers can be evaluated11663 // some comparisons with unsigned numbers can be evaluated
11664 if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) {11664 if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
11665 ConstExprValue *known_left_val;11665 ConstExprValue *known_left_val;
11666 IrBinOp flipped_op_id;11666 IrBinOp flipped_op_id;
11667 if (instr_is_comptime(casted_op1)) {11667 if (instr_is_comptime(casted_op1)) {
...@@ -11711,12 +11711,12 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11711,12 +11711,12 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11711 bool is_int;11711 bool is_int;
11712 bool is_float;11712 bool is_float;
11713 Cmp op2_zcmp;11713 Cmp op2_zcmp;
11714 if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) {11714 if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) {
11715 is_int = true;11715 is_int = true;
11716 is_float = false;11716 is_float = false;
11717 op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);11717 op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);
11718 } else if (type_entry->id == TypeTableEntryIdFloat ||11718 } else if (type_entry->id == ZigTypeIdFloat ||
11719 type_entry->id == TypeTableEntryIdComptimeFloat)11719 type_entry->id == ZigTypeIdComptimeFloat)
11720 {11720 {
11721 is_int = false;11721 is_int = false;
11722 is_float = true;11722 is_float = true;
...@@ -11766,7 +11766,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11766,7 +11766,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11766 bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);11766 bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
11767 break;11767 break;
11768 case IrBinOpBitShiftLeftLossy:11768 case IrBinOpBitShiftLeftLossy:
11769 assert(type_entry->id == TypeTableEntryIdInt);11769 assert(type_entry->id == ZigTypeIdInt);
11770 bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11770 bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11771 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11771 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11772 break;11772 break;
...@@ -11793,7 +11793,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11793,7 +11793,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11793 }11793 }
11794 break;11794 break;
11795 case IrBinOpAddWrap:11795 case IrBinOpAddWrap:
11796 assert(type_entry->id == TypeTableEntryIdInt);11796 assert(type_entry->id == ZigTypeIdInt);
11797 bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11797 bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11798 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11798 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11799 break;11799 break;
...@@ -11805,7 +11805,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11805,7 +11805,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11805 }11805 }
11806 break;11806 break;
11807 case IrBinOpSubWrap:11807 case IrBinOpSubWrap:
11808 assert(type_entry->id == TypeTableEntryIdInt);11808 assert(type_entry->id == ZigTypeIdInt);
11809 bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11809 bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11810 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11810 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11811 break;11811 break;
...@@ -11817,7 +11817,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11817,7 +11817,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11817 }11817 }
11818 break;11818 break;
11819 case IrBinOpMultWrap:11819 case IrBinOpMultWrap:
11820 assert(type_entry->id == TypeTableEntryIdInt);11820 assert(type_entry->id == ZigTypeIdInt);
11821 bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,11821 bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
11822 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);11822 type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
11823 break;11823 break;
...@@ -11872,7 +11872,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,...@@ -11872,7 +11872,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
11872 break;11872 break;
11873 }11873 }
1187411874
11875 if (type_entry->id == TypeTableEntryIdInt) {11875 if (type_entry->id == ZigTypeIdInt) {
11876 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,11876 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
11877 type_entry->data.integral.is_signed))11877 type_entry->data.integral.is_signed))
11878 {11878 {
...@@ -11890,7 +11890,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_...@@ -11890,7 +11890,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_
11890 if (type_is_invalid(op1->value.type))11890 if (type_is_invalid(op1->value.type))
11891 return ira->codegen->builtin_types.entry_invalid;11891 return ira->codegen->builtin_types.entry_invalid;
1189211892
11893 if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) {11893 if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) {
11894 ir_add_error(ira, &bin_op_instruction->base,11894 ir_add_error(ira, &bin_op_instruction->base,
11895 buf_sprintf("bit shifting operation expected integer type, found '%s'",11895 buf_sprintf("bit shifting operation expected integer type, found '%s'",
11896 buf_ptr(&op1->value.type->name)));11896 buf_ptr(&op1->value.type->name)));
...@@ -11903,7 +11903,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_...@@ -11903,7 +11903,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_
1190311903
11904 IrInstruction *casted_op2;11904 IrInstruction *casted_op2;
11905 IrBinOp op_id = bin_op_instruction->op_id;11905 IrBinOp op_id = bin_op_instruction->op_id;
11906 if (op1->value.type->id == TypeTableEntryIdComptimeInt) {11906 if (op1->value.type->id == ZigTypeIdComptimeInt) {
11907 casted_op2 = op2;11907 casted_op2 = op2;
1190811908
11909 if (op_id == IrBinOpBitShiftLeftLossy) {11909 if (op_id == IrBinOpBitShiftLeftLossy) {
...@@ -11920,7 +11920,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_...@@ -11920,7 +11920,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_
11920 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,11920 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
11921 op1->value.type->data.integral.bit_count - 1);11921 op1->value.type->data.integral.bit_count - 1);
11922 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&11922 if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
11923 op2->value.type->id == TypeTableEntryIdComptimeInt) {11923 op2->value.type->id == ZigTypeIdComptimeInt) {
11924 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,11924 if (!bigint_fits_in_bits(&op2->value.data.x_bigint,
11925 shift_amt_type->data.integral.bit_count,11925 shift_amt_type->data.integral.bit_count,
11926 op2->value.data.x_bigint.is_negative)) {11926 op2->value.data.x_bigint.is_negative)) {
...@@ -11974,7 +11974,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_...@@ -11974,7 +11974,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_
1197411974
11975 ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);11975 ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);
11976 return op1->value.type;11976 return op1->value.type;
11977 } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) {11977 } else if (op1->value.type->id == ZigTypeIdComptimeInt) {
11978 ir_add_error(ira, &bin_op_instruction->base,11978 ir_add_error(ira, &bin_op_instruction->base,
11979 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));11979 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
11980 return ira->codegen->builtin_types.entry_invalid;11980 return ira->codegen->builtin_types.entry_invalid;
...@@ -11997,7 +11997,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o...@@ -11997,7 +11997,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o
11997 IrBinOp op_id = bin_op_instruction->op_id;11997 IrBinOp op_id = bin_op_instruction->op_id;
1199811998
11999 // look for pointer math11999 // look for pointer math
12000 if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&12000 if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
12001 (op_id == IrBinOpAdd || op_id == IrBinOpSub))12001 (op_id == IrBinOpAdd || op_id == IrBinOpSub))
12002 {12002 {
12003 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);12003 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
...@@ -12016,15 +12016,15 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o...@@ -12016,15 +12016,15 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o
12016 if (type_is_invalid(resolved_type))12016 if (type_is_invalid(resolved_type))
12017 return resolved_type;12017 return resolved_type;
1201812018
12019 bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt;12019 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
12020 bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat;12020 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
12021 bool is_signed_div = (12021 bool is_signed_div = (
12022 (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) ||12022 (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
12023 resolved_type->id == TypeTableEntryIdFloat ||12023 resolved_type->id == ZigTypeIdFloat ||
12024 (resolved_type->id == TypeTableEntryIdComptimeFloat &&12024 (resolved_type->id == ZigTypeIdComptimeFloat &&
12025 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=12025 ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
12026 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||12026 (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
12027 (resolved_type->id == TypeTableEntryIdComptimeInt &&12027 (resolved_type->id == ZigTypeIdComptimeInt &&
12028 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=12028 ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
12029 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))12029 (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
12030 );12030 );
...@@ -12146,7 +12146,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o...@@ -12146,7 +12146,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o
12146 return ira->codegen->builtin_types.entry_invalid;12146 return ira->codegen->builtin_types.entry_invalid;
12147 }12147 }
1214812148
12149 if (resolved_type->id == TypeTableEntryIdComptimeInt) {12149 if (resolved_type->id == ZigTypeIdComptimeInt) {
12150 if (op_id == IrBinOpAddWrap) {12150 if (op_id == IrBinOpAddWrap) {
12151 op_id = IrBinOpAdd;12151 op_id = IrBinOpAdd;
12152 } else if (op_id == IrBinOpSubWrap) {12152 } else if (op_id == IrBinOpSubWrap) {
...@@ -12229,12 +12229,12 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc...@@ -12229,12 +12229,12 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc
12229 size_t op1_array_index;12229 size_t op1_array_index;
12230 size_t op1_array_end;12230 size_t op1_array_end;
12231 ZigType *child_type;12231 ZigType *child_type;
12232 if (op1_type->id == TypeTableEntryIdArray) {12232 if (op1_type->id == ZigTypeIdArray) {
12233 child_type = op1_type->data.array.child_type;12233 child_type = op1_type->data.array.child_type;
12234 op1_array_val = op1_val;12234 op1_array_val = op1_val;
12235 op1_array_index = 0;12235 op1_array_index = 0;
12236 op1_array_end = op1_type->data.array.len;12236 op1_array_end = op1_type->data.array.len;
12237 } else if (op1_type->id == TypeTableEntryIdPointer &&12237 } else if (op1_type->id == ZigTypeIdPointer &&
12238 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&12238 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
12239 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&12239 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
12240 op1_val->data.x_ptr.data.base_array.is_cstr)12240 op1_val->data.x_ptr.data.base_array.is_cstr)
...@@ -12260,7 +12260,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc...@@ -12260,7 +12260,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc
12260 ConstExprValue *op2_array_val;12260 ConstExprValue *op2_array_val;
12261 size_t op2_array_index;12261 size_t op2_array_index;
12262 size_t op2_array_end;12262 size_t op2_array_end;
12263 if (op2_type->id == TypeTableEntryIdArray) {12263 if (op2_type->id == ZigTypeIdArray) {
12264 if (op2_type->data.array.child_type != child_type) {12264 if (op2_type->data.array.child_type != child_type) {
12265 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",12265 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
12266 buf_ptr(&child_type->name),12266 buf_ptr(&child_type->name),
...@@ -12270,7 +12270,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc...@@ -12270,7 +12270,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc
12270 op2_array_val = op2_val;12270 op2_array_val = op2_val;
12271 op2_array_index = 0;12271 op2_array_index = 0;
12272 op2_array_end = op2_array_val->type->data.array.len;12272 op2_array_end = op2_array_val->type->data.array.len;
12273 } else if (op2_type->id == TypeTableEntryIdPointer &&12273 } else if (op2_type->id == ZigTypeIdPointer &&
12274 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&12274 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
12275 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&12275 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
12276 op2_val->data.x_ptr.data.base_array.is_cstr)12276 op2_val->data.x_ptr.data.base_array.is_cstr)
...@@ -12308,7 +12308,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc...@@ -12308,7 +12308,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc
12308 ZigType *result_type;12308 ZigType *result_type;
12309 ConstExprValue *out_array_val;12309 ConstExprValue *out_array_val;
12310 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);12310 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
12311 if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) {12311 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
12312 result_type = get_array_type(ira->codegen, child_type, new_len);12312 result_type = get_array_type(ira->codegen, child_type, new_len);
1231312313
12314 out_array_val = out_val;12314 out_array_val = out_val;
...@@ -12392,7 +12392,7 @@ static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instru...@@ -12392,7 +12392,7 @@ static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instru
12392 return ira->codegen->builtin_types.entry_invalid;12392 return ira->codegen->builtin_types.entry_invalid;
1239312393
12394 ZigType *array_type = op1->value.type;12394 ZigType *array_type = op1->value.type;
12395 if (array_type->id != TypeTableEntryIdArray) {12395 if (array_type->id != ZigTypeIdArray) {
12396 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));12396 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
12397 return ira->codegen->builtin_types.entry_invalid;12397 return ira->codegen->builtin_types.entry_invalid;
12398 }12398 }
...@@ -12555,8 +12555,8 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec...@@ -12555,8 +12555,8 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec
12555 }12555 }
1255612556
12557 if (!type_is_invalid(result_type)) {12557 if (!type_is_invalid(result_type)) {
12558 if (result_type->id == TypeTableEntryIdUnreachable ||12558 if (result_type->id == ZigTypeIdUnreachable ||
12559 result_type->id == TypeTableEntryIdOpaque)12559 result_type->id == ZigTypeIdOpaque)
12560 {12560 {
12561 ir_add_error_node(ira, source_node,12561 ir_add_error_node(ira, source_node,
12562 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));12562 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
...@@ -12571,7 +12571,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec...@@ -12571,7 +12571,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec
12571 }12571 }
12572 } else {12572 } else {
12573 if (casted_init_value->value.special == ConstValSpecialStatic &&12573 if (casted_init_value->value.special == ConstValSpecialStatic &&
12574 casted_init_value->value.type->id == TypeTableEntryIdFn &&12574 casted_init_value->value.type->id == ZigTypeIdFn &&
12575 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)12575 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
12576 {12576 {
12577 var_class_requires_const = true;12577 var_class_requires_const = true;
...@@ -12680,10 +12680,10 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor...@@ -12680,10 +12680,10 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
12680 }12680 }
1268112681
12682 switch (target->value.type->id) {12682 switch (target->value.type->id) {
12683 case TypeTableEntryIdInvalid:12683 case ZigTypeIdInvalid:
12684 case TypeTableEntryIdUnreachable:12684 case ZigTypeIdUnreachable:
12685 zig_unreachable();12685 zig_unreachable();
12686 case TypeTableEntryIdFn: {12686 case ZigTypeIdFn: {
12687 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);12687 assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);
12688 ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;12688 ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
12689 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;12689 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
...@@ -12706,7 +12706,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor...@@ -12706,7 +12706,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
12706 break;12706 break;
12707 }12707 }
12708 } break;12708 } break;
12709 case TypeTableEntryIdStruct:12709 case ZigTypeIdStruct:
12710 if (is_slice(target->value.type)) {12710 if (is_slice(target->value.type)) {
12711 ir_add_error(ira, target,12711 ir_add_error(ira, target,
12712 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));12712 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));
...@@ -12716,26 +12716,26 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor...@@ -12716,26 +12716,26 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
12716 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));12716 add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));
12717 }12717 }
12718 break;12718 break;
12719 case TypeTableEntryIdUnion:12719 case ZigTypeIdUnion:
12720 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {12720 if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {
12721 ErrorMsg *msg = ir_add_error(ira, target,12721 ErrorMsg *msg = ir_add_error(ira, target,
12722 buf_sprintf("exported union value must be declared extern"));12722 buf_sprintf("exported union value must be declared extern"));
12723 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));12723 add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));
12724 }12724 }
12725 break;12725 break;
12726 case TypeTableEntryIdEnum:12726 case ZigTypeIdEnum:
12727 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {12727 if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {
12728 ErrorMsg *msg = ir_add_error(ira, target,12728 ErrorMsg *msg = ir_add_error(ira, target,
12729 buf_sprintf("exported enum value must be declared extern"));12729 buf_sprintf("exported enum value must be declared extern"));
12730 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));12730 add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));
12731 }12731 }
12732 break;12732 break;
12733 case TypeTableEntryIdMetaType: {12733 case ZigTypeIdMetaType: {
12734 ZigType *type_value = target->value.data.x_type;12734 ZigType *type_value = target->value.data.x_type;
12735 switch (type_value->id) {12735 switch (type_value->id) {
12736 case TypeTableEntryIdInvalid:12736 case ZigTypeIdInvalid:
12737 zig_unreachable();12737 zig_unreachable();
12738 case TypeTableEntryIdStruct:12738 case ZigTypeIdStruct:
12739 if (is_slice(type_value)) {12739 if (is_slice(type_value)) {
12740 ir_add_error(ira, target,12740 ir_add_error(ira, target,
12741 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));12741 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
...@@ -12745,73 +12745,73 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor...@@ -12745,73 +12745,73 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
12745 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));12745 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
12746 }12746 }
12747 break;12747 break;
12748 case TypeTableEntryIdUnion:12748 case ZigTypeIdUnion:
12749 if (type_value->data.unionation.layout != ContainerLayoutExtern) {12749 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
12750 ErrorMsg *msg = ir_add_error(ira, target,12750 ErrorMsg *msg = ir_add_error(ira, target,
12751 buf_sprintf("exported union must be declared extern"));12751 buf_sprintf("exported union must be declared extern"));
12752 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));12752 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
12753 }12753 }
12754 break;12754 break;
12755 case TypeTableEntryIdEnum:12755 case ZigTypeIdEnum:
12756 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {12756 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
12757 ErrorMsg *msg = ir_add_error(ira, target,12757 ErrorMsg *msg = ir_add_error(ira, target,
12758 buf_sprintf("exported enum must be declared extern"));12758 buf_sprintf("exported enum must be declared extern"));
12759 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));12759 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
12760 }12760 }
12761 break;12761 break;
12762 case TypeTableEntryIdFn: {12762 case ZigTypeIdFn: {
12763 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {12763 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
12764 ir_add_error(ira, target,12764 ir_add_error(ira, target,
12765 buf_sprintf("exported function type must specify calling convention"));12765 buf_sprintf("exported function type must specify calling convention"));
12766 }12766 }
12767 } break;12767 } break;
12768 case TypeTableEntryIdInt:12768 case ZigTypeIdInt:
12769 case TypeTableEntryIdFloat:12769 case ZigTypeIdFloat:
12770 case TypeTableEntryIdPointer:12770 case ZigTypeIdPointer:
12771 case TypeTableEntryIdArray:12771 case ZigTypeIdArray:
12772 case TypeTableEntryIdBool:12772 case ZigTypeIdBool:
12773 break;12773 break;
12774 case TypeTableEntryIdMetaType:12774 case ZigTypeIdMetaType:
12775 case TypeTableEntryIdVoid:12775 case ZigTypeIdVoid:
12776 case TypeTableEntryIdUnreachable:12776 case ZigTypeIdUnreachable:
12777 case TypeTableEntryIdComptimeFloat:12777 case ZigTypeIdComptimeFloat:
12778 case TypeTableEntryIdComptimeInt:12778 case ZigTypeIdComptimeInt:
12779 case TypeTableEntryIdUndefined:12779 case ZigTypeIdUndefined:
12780 case TypeTableEntryIdNull:12780 case ZigTypeIdNull:
12781 case TypeTableEntryIdOptional:12781 case ZigTypeIdOptional:
12782 case TypeTableEntryIdErrorUnion:12782 case ZigTypeIdErrorUnion:
12783 case TypeTableEntryIdErrorSet:12783 case ZigTypeIdErrorSet:
12784 case TypeTableEntryIdNamespace:12784 case ZigTypeIdNamespace:
12785 case TypeTableEntryIdBlock:12785 case ZigTypeIdBlock:
12786 case TypeTableEntryIdBoundFn:12786 case ZigTypeIdBoundFn:
12787 case TypeTableEntryIdArgTuple:12787 case ZigTypeIdArgTuple:
12788 case TypeTableEntryIdOpaque:12788 case ZigTypeIdOpaque:
12789 case TypeTableEntryIdPromise:12789 case ZigTypeIdPromise:
12790 ir_add_error(ira, target,12790 ir_add_error(ira, target,
12791 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));12791 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
12792 break;12792 break;
12793 }12793 }
12794 } break;12794 } break;
12795 case TypeTableEntryIdVoid:12795 case ZigTypeIdVoid:
12796 case TypeTableEntryIdBool:12796 case ZigTypeIdBool:
12797 case TypeTableEntryIdInt:12797 case ZigTypeIdInt:
12798 case TypeTableEntryIdFloat:12798 case ZigTypeIdFloat:
12799 case TypeTableEntryIdPointer:12799 case ZigTypeIdPointer:
12800 case TypeTableEntryIdArray:12800 case ZigTypeIdArray:
12801 case TypeTableEntryIdComptimeFloat:12801 case ZigTypeIdComptimeFloat:
12802 case TypeTableEntryIdComptimeInt:12802 case ZigTypeIdComptimeInt:
12803 case TypeTableEntryIdUndefined:12803 case ZigTypeIdUndefined:
12804 case TypeTableEntryIdNull:12804 case ZigTypeIdNull:
12805 case TypeTableEntryIdOptional:12805 case ZigTypeIdOptional:
12806 case TypeTableEntryIdErrorUnion:12806 case ZigTypeIdErrorUnion:
12807 case TypeTableEntryIdErrorSet:12807 case ZigTypeIdErrorSet:
12808 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));12808 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
12809 case TypeTableEntryIdNamespace:12809 case ZigTypeIdNamespace:
12810 case TypeTableEntryIdBlock:12810 case ZigTypeIdBlock:
12811 case TypeTableEntryIdBoundFn:12811 case ZigTypeIdBoundFn:
12812 case TypeTableEntryIdArgTuple:12812 case ZigTypeIdArgTuple:
12813 case TypeTableEntryIdOpaque:12813 case ZigTypeIdOpaque:
12814 case TypeTableEntryIdPromise:12814 case ZigTypeIdPromise:
12815 ir_add_error(ira, target,12815 ir_add_error(ira, target,
12816 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));12816 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
12817 break;12817 break;
...@@ -12863,7 +12863,7 @@ static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -12863,7 +12863,7 @@ static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira,
12863 if (type_is_invalid(payload_type))12863 if (type_is_invalid(payload_type))
12864 return ira->codegen->builtin_types.entry_invalid;12864 return ira->codegen->builtin_types.entry_invalid;
1286512865
12866 if (err_set_type->id != TypeTableEntryIdErrorSet) {12866 if (err_set_type->id != ZigTypeIdErrorSet) {
12867 ir_add_error(ira, instruction->err_set->other,12867 ir_add_error(ira, instruction->err_set->other,
12868 buf_sprintf("expected error set type, found type '%s'",12868 buf_sprintf("expected error set type, found type '%s'",
12869 buf_ptr(&err_set_type->name)));12869 buf_ptr(&err_set_type->name)));
...@@ -12918,7 +12918,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c...@@ -12918,7 +12918,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
12918{12918{
12919 Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);12919 Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);
12920 //Buf *free_field_name = buf_create_from_str("freeFn");12920 //Buf *free_field_name = buf_create_from_str("freeFn");
12921 assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer);12921 assert(async_allocator_inst->value.type->id == ZigTypeIdPointer);
12922 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;12922 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
12923 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,12923 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,
12924 async_allocator_inst, container_type);12924 async_allocator_inst, container_type);
...@@ -12926,17 +12926,17 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c...@@ -12926,17 +12926,17 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
12926 return ira->codegen->invalid_instruction;12926 return ira->codegen->invalid_instruction;
12927 }12927 }
12928 ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type;12928 ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
12929 assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer);12929 assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer);
1293012930
12931 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;12931 ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
12932 if (alloc_fn_type->id != TypeTableEntryIdFn) {12932 if (alloc_fn_type->id != ZigTypeIdFn) {
12933 ir_add_error(ira, &call_instruction->base,12933 ir_add_error(ira, &call_instruction->base,
12934 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));12934 buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));
12935 return ira->codegen->invalid_instruction;12935 return ira->codegen->invalid_instruction;
12936 }12936 }
1293712937
12938 ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;12938 ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
12939 if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) {12939 if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) {
12940 ir_add_error(ira, fn_ref,12940 ir_add_error(ira, fn_ref,
12941 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));12941 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));
12942 return ira->codegen->invalid_instruction;12942 return ira->codegen->invalid_instruction;
...@@ -13015,7 +13015,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -13015,7 +13015,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
13015 }13015 }
1301613016
13017 bool comptime_arg = param_decl_node->data.param_decl.is_inline ||13017 bool comptime_arg = param_decl_node->data.param_decl.is_inline ||
13018 casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat;13018 casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;
1301913019
13020 ConstExprValue *arg_val;13020 ConstExprValue *arg_val;
1302113021
...@@ -13041,8 +13041,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -13041,8 +13041,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
13041 var->shadowable = !comptime_arg;13041 var->shadowable = !comptime_arg;
1304213042
13043 *next_proto_i += 1;13043 *next_proto_i += 1;
13044 } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt ||13044 } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||
13045 casted_arg->value.type->id == TypeTableEntryIdComptimeFloat)13045 casted_arg->value.type->id == ZigTypeIdComptimeFloat)
13046 {13046 {
13047 ir_add_error(ira, casted_arg,13047 ir_add_error(ira, casted_arg,
13048 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));13048 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
...@@ -13177,7 +13177,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13177,7 +13177,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13177 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;13177 size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
13178 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {13178 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
13179 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value;13179 ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value;
13180 if (arg_tuple_value->type->id == TypeTableEntryIdArgTuple) {13180 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
13181 call_param_count -= 1;13181 call_param_count -= 1;
13182 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -13182 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
13183 arg_tuple_value->data.x_arg_tuple.start_index;13183 arg_tuple_value->data.x_arg_tuple.start_index;
...@@ -13245,14 +13245,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13245,14 +13245,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
1324513245
13246 size_t next_proto_i = 0;13246 size_t next_proto_i = 0;
13247 if (first_arg_ptr) {13247 if (first_arg_ptr) {
13248 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);13248 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1324913249
13250 bool first_arg_known_bare = false;13250 bool first_arg_known_bare = false;
13251 if (fn_type_id->next_param_index >= 1) {13251 if (fn_type_id->next_param_index >= 1) {
13252 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;13252 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
13253 if (type_is_invalid(param_type))13253 if (type_is_invalid(param_type))
13254 return ira->codegen->builtin_types.entry_invalid;13254 return ira->codegen->builtin_types.entry_invalid;
13255 first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;13255 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
13256 }13256 }
1325713257
13258 IrInstruction *first_arg;13258 IrInstruction *first_arg;
...@@ -13314,7 +13314,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13314,7 +13314,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
1331413314
13315 if (inferred_err_set_type != nullptr) {13315 if (inferred_err_set_type != nullptr) {
13316 inferred_err_set_type->data.error_set.infer_fn = nullptr;13316 inferred_err_set_type->data.error_set.infer_fn = nullptr;
13317 if (result->value.type->id == TypeTableEntryIdErrorUnion) {13317 if (result->value.type->id == ZigTypeIdErrorUnion) {
13318 if (result->value.data.x_err_union.err != nullptr) {13318 if (result->value.data.x_err_union.err != nullptr) {
13319 inferred_err_set_type->data.error_set.err_count = 1;13319 inferred_err_set_type->data.error_set.err_count = 1;
13320 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);13320 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
...@@ -13323,7 +13323,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13323,7 +13323,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13323 ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;13323 ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
13324 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;13324 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;
13325 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;13325 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;
13326 } else if (result->value.type->id == TypeTableEntryIdErrorSet) {13326 } else if (result->value.type->id == ZigTypeIdErrorSet) {
13327 inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;13327 inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;
13328 inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;13328 inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;
13329 }13329 }
...@@ -13371,7 +13371,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13371,7 +13371,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13371 if (type_is_invalid(arg->value.type))13371 if (type_is_invalid(arg->value.type))
13372 return ira->codegen->builtin_types.entry_invalid;13372 return ira->codegen->builtin_types.entry_invalid;
1337313373
13374 if (arg->value.type->id == TypeTableEntryIdArgTuple) {13374 if (arg->value.type->id == ZigTypeIdArgTuple) {
13375 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;13375 new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;
13376 } else {13376 } else {
13377 new_fn_arg_count += 1;13377 new_fn_arg_count += 1;
...@@ -13401,14 +13401,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13401,14 +13401,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13401 size_t next_proto_i = 0;13401 size_t next_proto_i = 0;
1340213402
13403 if (first_arg_ptr) {13403 if (first_arg_ptr) {
13404 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);13404 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1340513405
13406 bool first_arg_known_bare = false;13406 bool first_arg_known_bare = false;
13407 if (fn_type_id->next_param_index >= 1) {13407 if (fn_type_id->next_param_index >= 1) {
13408 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;13408 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
13409 if (type_is_invalid(param_type))13409 if (type_is_invalid(param_type))
13410 return ira->codegen->builtin_types.entry_invalid;13410 return ira->codegen->builtin_types.entry_invalid;
13411 first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;13411 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
13412 }13412 }
1341313413
13414 IrInstruction *first_arg;13414 IrInstruction *first_arg;
...@@ -13437,7 +13437,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13437,7 +13437,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13437 if (type_is_invalid(arg->value.type))13437 if (type_is_invalid(arg->value.type))
13438 return ira->codegen->builtin_types.entry_invalid;13438 return ira->codegen->builtin_types.entry_invalid;
1343913439
13440 if (arg->value.type->id == TypeTableEntryIdArgTuple) {13440 if (arg->value.type->id == ZigTypeIdArgTuple) {
13441 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;13441 for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;
13442 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)13442 arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
13443 {13443 {
...@@ -13616,14 +13616,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr...@@ -13616,14 +13616,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr
13616 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);13616 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
13617 size_t next_arg_index = 0;13617 size_t next_arg_index = 0;
13618 if (first_arg_ptr) {13618 if (first_arg_ptr) {
13619 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);13619 assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
1362013620
13621 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;13621 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
13622 if (type_is_invalid(param_type))13622 if (type_is_invalid(param_type))
13623 return ira->codegen->builtin_types.entry_invalid;13623 return ira->codegen->builtin_types.entry_invalid;
1362413624
13625 IrInstruction *first_arg;13625 IrInstruction *first_arg;
13626 if (param_type->id == TypeTableEntryIdPointer &&13626 if (param_type->id == ZigTypeIdPointer &&
13627 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))13627 handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
13628 {13628 {
13629 first_arg = first_arg_ptr;13629 first_arg = first_arg_ptr;
...@@ -13712,7 +13712,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c...@@ -13712,7 +13712,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c
13712 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);13712 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
1371313713
13714 if (is_comptime || instr_is_comptime(fn_ref)) {13714 if (is_comptime || instr_is_comptime(fn_ref)) {
13715 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {13715 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
13716 ZigType *dest_type = ir_resolve_type(ira, fn_ref);13716 ZigType *dest_type = ir_resolve_type(ira, fn_ref);
13717 if (type_is_invalid(dest_type))13717 if (type_is_invalid(dest_type))
13718 return ira->codegen->builtin_types.entry_invalid;13718 return ira->codegen->builtin_types.entry_invalid;
...@@ -13733,13 +13733,13 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c...@@ -13733,13 +13733,13 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c
1373313733
13734 ir_link_new_instruction(cast_instruction, &call_instruction->base);13734 ir_link_new_instruction(cast_instruction, &call_instruction->base);
13735 return ir_finish_anal(ira, cast_instruction->value.type);13735 return ir_finish_anal(ira, cast_instruction->value.type);
13736 } else if (fn_ref->value.type->id == TypeTableEntryIdFn) {13736 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
13737 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);13737 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
13738 if (fn_table_entry == nullptr)13738 if (fn_table_entry == nullptr)
13739 return ira->codegen->builtin_types.entry_invalid;13739 return ira->codegen->builtin_types.entry_invalid;
13740 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,13740 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
13741 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);13741 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
13742 } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {13742 } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {
13743 assert(fn_ref->value.special == ConstValSpecialStatic);13743 assert(fn_ref->value.special == ConstValSpecialStatic);
13744 ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;13744 ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
13745 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;13745 IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;
...@@ -13752,7 +13752,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c...@@ -13752,7 +13752,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c
13752 }13752 }
13753 }13753 }
1375413754
13755 if (fn_ref->value.type->id == TypeTableEntryIdFn) {13755 if (fn_ref->value.type->id == ZigTypeIdFn) {
13756 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,13756 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
13757 fn_ref, nullptr, false, FnInlineAuto);13757 fn_ref, nullptr, false, FnInlineAuto);
13758 } else {13758 } else {
...@@ -13801,7 +13801,7 @@ static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_...@@ -13801,7 +13801,7 @@ static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_
13801 ZigType *child_type;13801 ZigType *child_type;
13802 if (type_is_invalid(ptr_type)) {13802 if (type_is_invalid(ptr_type)) {
13803 return ira->codegen->builtin_types.entry_invalid;13803 return ira->codegen->builtin_types.entry_invalid;
13804 } else if (ptr_type->id == TypeTableEntryIdPointer) {13804 } else if (ptr_type->id == ZigTypeIdPointer) {
13805 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {13805 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
13806 ir_add_error_node(ira, un_op_instruction->base.source_node,13806 ir_add_error_node(ira, un_op_instruction->base.source_node,
13807 buf_sprintf("index syntax required for unknown-length pointer type '%s'",13807 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
...@@ -13845,38 +13845,38 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru...@@ -13845,38 +13845,38 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru
13845 return ira->codegen->builtin_types.entry_invalid;13845 return ira->codegen->builtin_types.entry_invalid;
1384613846
13847 switch (type_entry->id) {13847 switch (type_entry->id) {
13848 case TypeTableEntryIdInvalid:13848 case ZigTypeIdInvalid:
13849 zig_unreachable();13849 zig_unreachable();
13850 case TypeTableEntryIdMetaType:13850 case ZigTypeIdMetaType:
13851 case TypeTableEntryIdVoid:13851 case ZigTypeIdVoid:
13852 case TypeTableEntryIdBool:13852 case ZigTypeIdBool:
13853 case TypeTableEntryIdInt:13853 case ZigTypeIdInt:
13854 case TypeTableEntryIdFloat:13854 case ZigTypeIdFloat:
13855 case TypeTableEntryIdPointer:13855 case ZigTypeIdPointer:
13856 case TypeTableEntryIdArray:13856 case ZigTypeIdArray:
13857 case TypeTableEntryIdStruct:13857 case ZigTypeIdStruct:
13858 case TypeTableEntryIdComptimeFloat:13858 case ZigTypeIdComptimeFloat:
13859 case TypeTableEntryIdComptimeInt:13859 case ZigTypeIdComptimeInt:
13860 case TypeTableEntryIdUndefined:13860 case ZigTypeIdUndefined:
13861 case TypeTableEntryIdNull:13861 case ZigTypeIdNull:
13862 case TypeTableEntryIdOptional:13862 case ZigTypeIdOptional:
13863 case TypeTableEntryIdErrorUnion:13863 case ZigTypeIdErrorUnion:
13864 case TypeTableEntryIdErrorSet:13864 case ZigTypeIdErrorSet:
13865 case TypeTableEntryIdEnum:13865 case ZigTypeIdEnum:
13866 case TypeTableEntryIdUnion:13866 case ZigTypeIdUnion:
13867 case TypeTableEntryIdFn:13867 case ZigTypeIdFn:
13868 case TypeTableEntryIdNamespace:13868 case ZigTypeIdNamespace:
13869 case TypeTableEntryIdBlock:13869 case ZigTypeIdBlock:
13870 case TypeTableEntryIdBoundFn:13870 case ZigTypeIdBoundFn:
13871 case TypeTableEntryIdArgTuple:13871 case ZigTypeIdArgTuple:
13872 case TypeTableEntryIdPromise:13872 case ZigTypeIdPromise:
13873 {13873 {
13874 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);13874 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
13875 out_val->data.x_type = get_optional_type(ira->codegen, type_entry);13875 out_val->data.x_type = get_optional_type(ira->codegen, type_entry);
13876 return ira->codegen->builtin_types.entry_type;13876 return ira->codegen->builtin_types.entry_type;
13877 }13877 }
13878 case TypeTableEntryIdUnreachable:13878 case ZigTypeIdUnreachable:
13879 case TypeTableEntryIdOpaque:13879 case ZigTypeIdOpaque:
13880 ir_add_error_node(ira, un_op_instruction->base.source_node,13880 ir_add_error_node(ira, un_op_instruction->base.source_node,
13881 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));13881 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));
13882 return ira->codegen->builtin_types.entry_invalid;13882 return ira->codegen->builtin_types.entry_invalid;
...@@ -13892,10 +13892,10 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins...@@ -13892,10 +13892,10 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins
1389213892
13893 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);13893 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
1389413894
13895 bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat);13895 bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat);
1389613896
13897 if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||13897 if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) ||
13898 expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op))13898 expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op))
13899 {13899 {
13900 if (instr_is_comptime(value)) {13900 if (instr_is_comptime(value)) {
13901 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);13901 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
...@@ -13911,7 +13911,7 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins...@@ -13911,7 +13911,7 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins
13911 } else {13911 } else {
13912 bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);13912 bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);
13913 }13913 }
13914 if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) {13914 if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) {
13915 return expr_type;13915 return expr_type;
13916 }13916 }
1391713917
...@@ -13937,7 +13937,7 @@ static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instructio...@@ -13937,7 +13937,7 @@ static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instructio
13937 if (type_is_invalid(expr_type))13937 if (type_is_invalid(expr_type))
13938 return ira->codegen->builtin_types.entry_invalid;13938 return ira->codegen->builtin_types.entry_invalid;
1393913939
13940 if (expr_type->id == TypeTableEntryIdInt) {13940 if (expr_type->id == ZigTypeIdInt) {
13941 if (instr_is_comptime(value)) {13941 if (instr_is_comptime(value)) {
13942 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);13942 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
13943 if (target_const_val == nullptr)13943 if (target_const_val == nullptr)
...@@ -14082,7 +14082,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi...@@ -14082,7 +14082,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi
14082 IrInstruction *old_value = phi_instruction->incoming_values[i];14082 IrInstruction *old_value = phi_instruction->incoming_values[i];
14083 assert(old_value);14083 assert(old_value);
14084 IrInstruction *new_value = old_value->other;14084 IrInstruction *new_value = old_value->other;
14085 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr)14085 if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
14086 continue;14086 continue;
1408714087
14088 if (type_is_invalid(new_value->value.type))14088 if (type_is_invalid(new_value->value.type))
...@@ -14110,17 +14110,17 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi...@@ -14110,17 +14110,17 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi
14110 if (type_is_invalid(resolved_type))14110 if (type_is_invalid(resolved_type))
14111 return resolved_type;14111 return resolved_type;
1411214112
14113 if (resolved_type->id == TypeTableEntryIdComptimeFloat ||14113 if (resolved_type->id == ZigTypeIdComptimeFloat ||
14114 resolved_type->id == TypeTableEntryIdComptimeInt ||14114 resolved_type->id == ZigTypeIdComptimeInt ||
14115 resolved_type->id == TypeTableEntryIdNull ||14115 resolved_type->id == ZigTypeIdNull ||
14116 resolved_type->id == TypeTableEntryIdUndefined)14116 resolved_type->id == ZigTypeIdUndefined)
14117 {14117 {
14118 ir_add_error_node(ira, phi_instruction->base.source_node,14118 ir_add_error_node(ira, phi_instruction->base.source_node,
14119 buf_sprintf("unable to infer expression type"));14119 buf_sprintf("unable to infer expression type"));
14120 return ira->codegen->builtin_types.entry_invalid;14120 return ira->codegen->builtin_types.entry_invalid;
14121 }14121 }
1412214122
14123 bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer);14123 bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer);
1412414124
14125 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.14125 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
14126 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and14126 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
...@@ -14171,7 +14171,7 @@ static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarP...@@ -14171,7 +14171,7 @@ static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarP
14171}14171}
1417214172
14173static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) {14173static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) {
14174 assert(ptr_type->id == TypeTableEntryIdPointer);14174 assert(ptr_type->id == ZigTypeIdPointer);
14175 return get_pointer_to_type_extra(g,14175 return get_pointer_to_type_extra(g,
14176 ptr_type->data.pointer.child_type,14176 ptr_type->data.pointer.child_type,
14177 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,14177 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
...@@ -14188,7 +14188,7 @@ static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new...@@ -14188,7 +14188,7 @@ static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new
14188}14188}
1418914189
14190static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {14190static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
14191 assert(ptr_type->id == TypeTableEntryIdPointer);14191 assert(ptr_type->id == ZigTypeIdPointer);
14192 return get_pointer_to_type_extra(g,14192 return get_pointer_to_type_extra(g,
14193 ptr_type->data.pointer.child_type,14193 ptr_type->data.pointer.child_type,
14194 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,14194 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
...@@ -14210,7 +14210,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14210,7 +14210,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14210 return ira->codegen->builtin_types.entry_invalid;14210 return ira->codegen->builtin_types.entry_invalid;
1421114211
14212 ZigType *ptr_type = orig_array_ptr_val->type;14212 ZigType *ptr_type = orig_array_ptr_val->type;
14213 assert(ptr_type->id == TypeTableEntryIdPointer);14213 assert(ptr_type->id == ZigTypeIdPointer);
1421414214
14215 ZigType *array_type = ptr_type->data.pointer.child_type;14215 ZigType *array_type = ptr_type->data.pointer.child_type;
1421614216
...@@ -14220,12 +14220,12 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14220,12 +14220,12 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
1422014220
14221 if (type_is_invalid(array_type)) {14221 if (type_is_invalid(array_type)) {
14222 return array_type;14222 return array_type;
14223 } else if (array_type->id == TypeTableEntryIdArray ||14223 } else if (array_type->id == ZigTypeIdArray ||
14224 (array_type->id == TypeTableEntryIdPointer &&14224 (array_type->id == ZigTypeIdPointer &&
14225 array_type->data.pointer.ptr_len == PtrLenSingle &&14225 array_type->data.pointer.ptr_len == PtrLenSingle &&
14226 array_type->data.pointer.child_type->id == TypeTableEntryIdArray))14226 array_type->data.pointer.child_type->id == ZigTypeIdArray))
14227 {14227 {
14228 if (array_type->id == TypeTableEntryIdPointer) {14228 if (array_type->id == ZigTypeIdPointer) {
14229 array_type = array_type->data.pointer.child_type;14229 array_type = array_type->data.pointer.child_type;
14230 ptr_type = ptr_type->data.pointer.child_type;14230 ptr_type = ptr_type->data.pointer.child_type;
14231 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {14231 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
...@@ -14259,7 +14259,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14259,7 +14259,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14259 elem_ptr_instruction->ptr_len,14259 elem_ptr_instruction->ptr_len,
14260 1, (uint32_t)bit_offset, (uint32_t)bit_width);14260 1, (uint32_t)bit_offset, (uint32_t)bit_width);
14261 }14261 }
14262 } else if (array_type->id == TypeTableEntryIdPointer) {14262 } else if (array_type->id == ZigTypeIdPointer) {
14263 if (array_type->data.pointer.ptr_len == PtrLenSingle) {14263 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
14264 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14264 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14265 buf_sprintf("index of single-item pointer"));14265 buf_sprintf("index of single-item pointer"));
...@@ -14269,7 +14269,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14269,7 +14269,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14269 } else if (is_slice(array_type)) {14269 } else if (is_slice(array_type)) {
14270 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,14270 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
14271 elem_ptr_instruction->ptr_len);14271 elem_ptr_instruction->ptr_len);
14272 } else if (array_type->id == TypeTableEntryIdArgTuple) {14272 } else if (array_type->id == ZigTypeIdArgTuple) {
14273 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);14273 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
14274 if (!ptr_val)14274 if (!ptr_val)
14275 return ira->codegen->builtin_types.entry_invalid;14275 return ira->codegen->builtin_types.entry_invalid;
...@@ -14320,7 +14320,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14320,7 +14320,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14320 uint64_t ptr_align = return_type->data.pointer.alignment;14320 uint64_t ptr_align = return_type->data.pointer.alignment;
14321 if (instr_is_comptime(casted_elem_index)) {14321 if (instr_is_comptime(casted_elem_index)) {
14322 uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);14322 uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);
14323 if (array_type->id == TypeTableEntryIdArray) {14323 if (array_type->id == ZigTypeIdArray) {
14324 uint64_t array_len = array_type->data.array.len;14324 uint64_t array_len = array_type->data.array.len;
14325 if (index >= array_len) {14325 if (index >= array_len) {
14326 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,14326 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
...@@ -14353,7 +14353,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14353,7 +14353,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
1435314353
14354 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&14354 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
14355 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||14355 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
14356 array_type->id == TypeTableEntryIdArray))14356 array_type->id == ZigTypeIdArray))
14357 {14357 {
14358 ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,14358 ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
14359 elem_ptr_instruction->base.source_node);14359 elem_ptr_instruction->base.source_node);
...@@ -14361,10 +14361,10 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14361,10 +14361,10 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14361 return ira->codegen->builtin_types.entry_invalid;14361 return ira->codegen->builtin_types.entry_invalid;
1436214362
14363 if (array_ptr_val->special != ConstValSpecialRuntime &&14363 if (array_ptr_val->special != ConstValSpecialRuntime &&
14364 (array_type->id != TypeTableEntryIdPointer ||14364 (array_type->id != ZigTypeIdPointer ||
14365 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))14365 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
14366 {14366 {
14367 if (array_type->id == TypeTableEntryIdPointer) {14367 if (array_type->id == ZigTypeIdPointer) {
14368 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);14368 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14369 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;14369 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
14370 size_t new_index;14370 size_t new_index;
...@@ -14461,7 +14461,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle...@@ -14461,7 +14461,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle
14461 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");14461 zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
14462 }14462 }
14463 return return_type;14463 return return_type;
14464 } else if (array_type->id == TypeTableEntryIdArray) {14464 } else if (array_type->id == ZigTypeIdArray) {
14465 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);14465 ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
14466 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;14466 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14467 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;14467 out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
...@@ -14521,11 +14521,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14521,11 +14521,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14521 const char *prefix_name;14521 const char *prefix_name;
14522 if (is_slice(bare_struct_type)) {14522 if (is_slice(bare_struct_type)) {
14523 prefix_name = "";14523 prefix_name = "";
14524 } else if (bare_struct_type->id == TypeTableEntryIdStruct) {14524 } else if (bare_struct_type->id == ZigTypeIdStruct) {
14525 prefix_name = "struct ";14525 prefix_name = "struct ";
14526 } else if (bare_struct_type->id == TypeTableEntryIdEnum) {14526 } else if (bare_struct_type->id == ZigTypeIdEnum) {
14527 prefix_name = "enum ";14527 prefix_name = "enum ";
14528 } else if (bare_struct_type->id == TypeTableEntryIdUnion) {14528 } else if (bare_struct_type->id == ZigTypeIdUnion) {
14529 prefix_name = "union ";14529 prefix_name = "union ";
14530 } else {14530 } else {
14531 prefix_name = "";14531 prefix_name = "";
...@@ -14544,10 +14544,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14544,10 +14544,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14544 if ((err = ensure_complete_type(ira->codegen, bare_type)))14544 if ((err = ensure_complete_type(ira->codegen, bare_type)))
14545 return ira->codegen->invalid_instruction;14545 return ira->codegen->invalid_instruction;
1454614546
14547 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14547 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14548 bool is_const = container_ptr->value.type->data.pointer.is_const;14548 bool is_const = container_ptr->value.type->data.pointer.is_const;
14549 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;14549 bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;
14550 if (bare_type->id == TypeTableEntryIdStruct) {14550 if (bare_type->id == ZigTypeIdStruct) {
14551 TypeStructField *field = find_struct_type_field(bare_type, field_name);14551 TypeStructField *field = find_struct_type_field(bare_type, field_name);
14552 if (field) {14552 if (field) {
14553 bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);14553 bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);
...@@ -14594,10 +14594,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14594,10 +14594,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14594 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14594 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14595 source_instr, container_ptr, container_type);14595 source_instr, container_ptr, container_type);
14596 }14596 }
14597 } else if (bare_type->id == TypeTableEntryIdEnum) {14597 } else if (bare_type->id == ZigTypeIdEnum) {
14598 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14598 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14599 source_instr, container_ptr, container_type);14599 source_instr, container_ptr, container_type);
14600 } else if (bare_type->id == TypeTableEntryIdUnion) {14600 } else if (bare_type->id == ZigTypeIdUnion) {
14601 TypeUnionField *field = find_union_type_field(bare_type, field_name);14601 TypeUnionField *field = find_union_type_field(bare_type, field_name);
14602 if (field) {14602 if (field) {
14603 if (instr_is_comptime(container_ptr)) {14603 if (instr_is_comptime(container_ptr)) {
...@@ -14626,7 +14626,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14626,7 +14626,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14626 ConstExprValue *payload_val = union_val->data.x_union.payload;14626 ConstExprValue *payload_val = union_val->data.x_union.payload;
1462714627
14628 ZigType *field_type = field->type_entry;14628 ZigType *field_type = field->type_entry;
14629 if (field_type->id == TypeTableEntryIdVoid) {14629 if (field_type->id == ZigTypeIdVoid) {
14630 assert(payload_val == nullptr);14630 assert(payload_val == nullptr);
14631 payload_val = create_const_vals(1);14631 payload_val = create_const_vals(1);
14632 payload_val->special = ConstValSpecialStatic;14632 payload_val->special = ConstValSpecialStatic;
...@@ -14732,7 +14732,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru...@@ -14732,7 +14732,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru
14732}14732}
1473314733
14734static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) {14734static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) {
14735 assert(err_set_type->id == TypeTableEntryIdErrorSet);14735 assert(err_set_type->id == ZigTypeIdErrorSet);
14736 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {14736 for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
14737 ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];14737 ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];
14738 if (buf_eql_buf(&err_table_entry->name, field_name)) {14738 if (buf_eql_buf(&err_table_entry->name, field_name)) {
...@@ -14749,7 +14749,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14749,7 +14749,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14749 return ira->codegen->builtin_types.entry_invalid;14749 return ira->codegen->builtin_types.entry_invalid;
1475014750
14751 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;14751 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
14752 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14752 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1475314753
14754 Buf *field_name = field_ptr_instruction->field_name_buffer;14754 Buf *field_name = field_ptr_instruction->field_name_buffer;
14755 if (!field_name) {14755 if (!field_name) {
...@@ -14765,8 +14765,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14765,8 +14765,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14765 if (type_is_invalid(container_type)) {14765 if (type_is_invalid(container_type)) {
14766 return container_type;14766 return container_type;
14767 } else if (is_container_ref(container_type)) {14767 } else if (is_container_ref(container_type)) {
14768 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14768 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14769 if (container_type->id == TypeTableEntryIdPointer) {14769 if (container_type->id == ZigTypeIdPointer) {
14770 ZigType *bare_type = container_ref_type(container_type);14770 ZigType *bare_type = container_ref_type(container_type);
14771 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);14771 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
14772 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);14772 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);
...@@ -14780,7 +14780,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14780,7 +14780,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14780 } else if (is_array_ref(container_type)) {14780 } else if (is_array_ref(container_type)) {
14781 if (buf_eql_str(field_name, "len")) {14781 if (buf_eql_str(field_name, "len")) {
14782 ConstExprValue *len_val = create_const_vals(1);14782 ConstExprValue *len_val = create_const_vals(1);
14783 if (container_type->id == TypeTableEntryIdPointer) {14783 if (container_type->id == ZigTypeIdPointer) {
14784 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);14784 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
14785 } else {14785 } else {
14786 init_const_usize(ira->codegen, len_val, container_type->data.array.len);14786 init_const_usize(ira->codegen, len_val, container_type->data.array.len);
...@@ -14797,12 +14797,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14797,12 +14797,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14797 buf_ptr(&container_type->name)));14797 buf_ptr(&container_type->name)));
14798 return ira->codegen->builtin_types.entry_invalid;14798 return ira->codegen->builtin_types.entry_invalid;
14799 }14799 }
14800 } else if (container_type->id == TypeTableEntryIdArgTuple) {14800 } else if (container_type->id == ZigTypeIdArgTuple) {
14801 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);14801 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
14802 if (!container_ptr_val)14802 if (!container_ptr_val)
14803 return ira->codegen->builtin_types.entry_invalid;14803 return ira->codegen->builtin_types.entry_invalid;
1480414804
14805 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14805 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14806 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);14806 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
14807 if (child_val == nullptr)14807 if (child_val == nullptr)
14808 return ira->codegen->builtin_types.entry_invalid;14808 return ira->codegen->builtin_types.entry_invalid;
...@@ -14823,12 +14823,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14823,12 +14823,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14823 buf_ptr(&container_type->name)));14823 buf_ptr(&container_type->name)));
14824 return ira->codegen->builtin_types.entry_invalid;14824 return ira->codegen->builtin_types.entry_invalid;
14825 }14825 }
14826 } else if (container_type->id == TypeTableEntryIdMetaType) {14826 } else if (container_type->id == ZigTypeIdMetaType) {
14827 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);14827 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
14828 if (!container_ptr_val)14828 if (!container_ptr_val)
14829 return ira->codegen->builtin_types.entry_invalid;14829 return ira->codegen->builtin_types.entry_invalid;
1483014830
14831 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);14831 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14832 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);14832 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
14833 if (child_val == nullptr)14833 if (child_val == nullptr)
14834 return ira->codegen->builtin_types.entry_invalid;14834 return ira->codegen->builtin_types.entry_invalid;
...@@ -14841,14 +14841,14 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14841,14 +14841,14 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14841 bool ptr_is_const = true;14841 bool ptr_is_const = true;
14842 bool ptr_is_volatile = false;14842 bool ptr_is_volatile = false;
14843 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];14843 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
14844 assert(ptr_field->type_entry->id == TypeTableEntryIdPointer);14844 assert(ptr_field->type_entry->id == ZigTypeIdPointer);
14845 ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;14845 ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;
14846 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,14846 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
14847 create_const_type(ira->codegen, child_type),14847 create_const_type(ira->codegen, child_type),
14848 ira->codegen->builtin_types.entry_type,14848 ira->codegen->builtin_types.entry_type,
14849 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);14849 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
14850 }14850 }
14851 if (child_type->id == TypeTableEntryIdEnum) {14851 if (child_type->id == ZigTypeIdEnum) {
14852 if ((err = ensure_complete_type(ira->codegen, child_type)))14852 if ((err = ensure_complete_type(ira->codegen, child_type)))
14853 return ira->codegen->builtin_types.entry_invalid;14853 return ira->codegen->builtin_types.entry_invalid;
1485414854
...@@ -14869,7 +14869,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14869,7 +14869,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14869 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);14869 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
14870 }14870 }
14871 }14871 }
14872 if (child_type->id == TypeTableEntryIdUnion &&14872 if (child_type->id == ZigTypeIdUnion &&
14873 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||14873 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
14874 child_type->data.unionation.decl_node->data.container_decl.auto_enum))14874 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
14875 {14875 {
...@@ -14889,7 +14889,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14889,7 +14889,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14889 buf_sprintf("container '%s' has no member called '%s'",14889 buf_sprintf("container '%s' has no member called '%s'",
14890 buf_ptr(&child_type->name), buf_ptr(field_name)));14890 buf_ptr(&child_type->name), buf_ptr(field_name)));
14891 return ira->codegen->builtin_types.entry_invalid;14891 return ira->codegen->builtin_types.entry_invalid;
14892 } else if (child_type->id == TypeTableEntryIdErrorSet) {14892 } else if (child_type->id == ZigTypeIdErrorSet) {
14893 ErrorTableEntry *err_entry;14893 ErrorTableEntry *err_entry;
14894 ZigType *err_set_type;14894 ZigType *err_set_type;
14895 if (type_is_global_error_set(child_type)) {14895 if (type_is_global_error_set(child_type)) {
...@@ -14935,7 +14935,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14935,7 +14935,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14935 bool ptr_is_volatile = false;14935 bool ptr_is_volatile = false;
14936 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,14936 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,
14937 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);14937 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
14938 } else if (child_type->id == TypeTableEntryIdInt) {14938 } else if (child_type->id == ZigTypeIdInt) {
14939 if (buf_eql_str(field_name, "bit_count")) {14939 if (buf_eql_str(field_name, "bit_count")) {
14940 bool ptr_is_const = true;14940 bool ptr_is_const = true;
14941 bool ptr_is_volatile = false;14941 bool ptr_is_volatile = false;
...@@ -14957,7 +14957,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14957,7 +14957,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14957 buf_ptr(&child_type->name), buf_ptr(field_name)));14957 buf_ptr(&child_type->name), buf_ptr(field_name)));
14958 return ira->codegen->builtin_types.entry_invalid;14958 return ira->codegen->builtin_types.entry_invalid;
14959 }14959 }
14960 } else if (child_type->id == TypeTableEntryIdFloat) {14960 } else if (child_type->id == ZigTypeIdFloat) {
14961 if (buf_eql_str(field_name, "bit_count")) {14961 if (buf_eql_str(field_name, "bit_count")) {
14962 bool ptr_is_const = true;14962 bool ptr_is_const = true;
14963 bool ptr_is_volatile = false;14963 bool ptr_is_volatile = false;
...@@ -14972,7 +14972,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14972,7 +14972,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14972 buf_ptr(&child_type->name), buf_ptr(field_name)));14972 buf_ptr(&child_type->name), buf_ptr(field_name)));
14973 return ira->codegen->builtin_types.entry_invalid;14973 return ira->codegen->builtin_types.entry_invalid;
14974 }14974 }
14975 } else if (child_type->id == TypeTableEntryIdPointer) {14975 } else if (child_type->id == ZigTypeIdPointer) {
14976 if (buf_eql_str(field_name, "Child")) {14976 if (buf_eql_str(field_name, "Child")) {
14977 bool ptr_is_const = true;14977 bool ptr_is_const = true;
14978 bool ptr_is_volatile = false;14978 bool ptr_is_volatile = false;
...@@ -14994,7 +14994,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14994,7 +14994,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14994 buf_ptr(&child_type->name), buf_ptr(field_name)));14994 buf_ptr(&child_type->name), buf_ptr(field_name)));
14995 return ira->codegen->builtin_types.entry_invalid;14995 return ira->codegen->builtin_types.entry_invalid;
14996 }14996 }
14997 } else if (child_type->id == TypeTableEntryIdArray) {14997 } else if (child_type->id == ZigTypeIdArray) {
14998 if (buf_eql_str(field_name, "Child")) {14998 if (buf_eql_str(field_name, "Child")) {
14999 bool ptr_is_const = true;14999 bool ptr_is_const = true;
15000 bool ptr_is_volatile = false;15000 bool ptr_is_volatile = false;
...@@ -15016,7 +15016,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -15016,7 +15016,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
15016 buf_ptr(&child_type->name), buf_ptr(field_name)));15016 buf_ptr(&child_type->name), buf_ptr(field_name)));
15017 return ira->codegen->builtin_types.entry_invalid;15017 return ira->codegen->builtin_types.entry_invalid;
15018 }15018 }
15019 } else if (child_type->id == TypeTableEntryIdErrorUnion) {15019 } else if (child_type->id == ZigTypeIdErrorUnion) {
15020 if (buf_eql_str(field_name, "Payload")) {15020 if (buf_eql_str(field_name, "Payload")) {
15021 bool ptr_is_const = true;15021 bool ptr_is_const = true;
15022 bool ptr_is_volatile = false;15022 bool ptr_is_volatile = false;
...@@ -15037,7 +15037,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -15037,7 +15037,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
15037 buf_ptr(&child_type->name), buf_ptr(field_name)));15037 buf_ptr(&child_type->name), buf_ptr(field_name)));
15038 return ira->codegen->builtin_types.entry_invalid;15038 return ira->codegen->builtin_types.entry_invalid;
15039 }15039 }
15040 } else if (child_type->id == TypeTableEntryIdOptional) {15040 } else if (child_type->id == ZigTypeIdOptional) {
15041 if (buf_eql_str(field_name, "Child")) {15041 if (buf_eql_str(field_name, "Child")) {
15042 bool ptr_is_const = true;15042 bool ptr_is_const = true;
15043 bool ptr_is_volatile = false;15043 bool ptr_is_volatile = false;
...@@ -15051,7 +15051,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -15051,7 +15051,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
15051 buf_ptr(&child_type->name), buf_ptr(field_name)));15051 buf_ptr(&child_type->name), buf_ptr(field_name)));
15052 return ira->codegen->builtin_types.entry_invalid;15052 return ira->codegen->builtin_types.entry_invalid;
15053 }15053 }
15054 } else if (child_type->id == TypeTableEntryIdFn) {15054 } else if (child_type->id == ZigTypeIdFn) {
15055 if (buf_eql_str(field_name, "ReturnType")) {15055 if (buf_eql_str(field_name, "ReturnType")) {
15056 if (child_type->data.fn.fn_type_id.return_type == nullptr) {15056 if (child_type->data.fn.fn_type_id.return_type == nullptr) {
15057 // Return type can only ever be null, if the function is generic15057 // Return type can only ever be null, if the function is generic
...@@ -15093,8 +15093,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -15093,8 +15093,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
15093 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));15093 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
15094 return ira->codegen->builtin_types.entry_invalid;15094 return ira->codegen->builtin_types.entry_invalid;
15095 }15095 }
15096 } else if (container_type->id == TypeTableEntryIdNamespace) {15096 } else if (container_type->id == ZigTypeIdNamespace) {
15097 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);15097 assert(container_ptr->value.type->id == ZigTypeIdPointer);
15098 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);15098 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
15099 if (!container_ptr_val)15099 if (!container_ptr_val)
15100 return ira->codegen->builtin_types.entry_invalid;15100 return ira->codegen->builtin_types.entry_invalid;
...@@ -15151,7 +15151,7 @@ static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionSt...@@ -15151,7 +15151,7 @@ static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionSt
15151 if (type_is_invalid(value->value.type))15151 if (type_is_invalid(value->value.type))
15152 return value->value.type;15152 return value->value.type;
1515315153
15154 if (ptr->value.type->id != TypeTableEntryIdPointer) {15154 if (ptr->value.type->id != ZigTypeIdPointer) {
15155 ir_add_error(ira, ptr,15155 ir_add_error(ira, ptr,
15156 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));15156 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
15157 return ira->codegen->builtin_types.entry_invalid;15157 return ira->codegen->builtin_types.entry_invalid;
...@@ -15208,33 +15208,33 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO...@@ -15208,33 +15208,33 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO
15208 if (type_is_invalid(type_entry))15208 if (type_is_invalid(type_entry))
15209 return ira->codegen->builtin_types.entry_invalid;15209 return ira->codegen->builtin_types.entry_invalid;
15210 switch (type_entry->id) {15210 switch (type_entry->id) {
15211 case TypeTableEntryIdInvalid:15211 case ZigTypeIdInvalid:
15212 zig_unreachable(); // handled above15212 zig_unreachable(); // handled above
15213 case TypeTableEntryIdComptimeFloat:15213 case ZigTypeIdComptimeFloat:
15214 case TypeTableEntryIdComptimeInt:15214 case ZigTypeIdComptimeInt:
15215 case TypeTableEntryIdUndefined:15215 case ZigTypeIdUndefined:
15216 case TypeTableEntryIdNull:15216 case ZigTypeIdNull:
15217 case TypeTableEntryIdNamespace:15217 case ZigTypeIdNamespace:
15218 case TypeTableEntryIdBlock:15218 case ZigTypeIdBlock:
15219 case TypeTableEntryIdBoundFn:15219 case ZigTypeIdBoundFn:
15220 case TypeTableEntryIdMetaType:15220 case ZigTypeIdMetaType:
15221 case TypeTableEntryIdVoid:15221 case ZigTypeIdVoid:
15222 case TypeTableEntryIdBool:15222 case ZigTypeIdBool:
15223 case TypeTableEntryIdUnreachable:15223 case ZigTypeIdUnreachable:
15224 case TypeTableEntryIdInt:15224 case ZigTypeIdInt:
15225 case TypeTableEntryIdFloat:15225 case ZigTypeIdFloat:
15226 case TypeTableEntryIdPointer:15226 case ZigTypeIdPointer:
15227 case TypeTableEntryIdArray:15227 case ZigTypeIdArray:
15228 case TypeTableEntryIdStruct:15228 case ZigTypeIdStruct:
15229 case TypeTableEntryIdOptional:15229 case ZigTypeIdOptional:
15230 case TypeTableEntryIdErrorUnion:15230 case ZigTypeIdErrorUnion:
15231 case TypeTableEntryIdErrorSet:15231 case ZigTypeIdErrorSet:
15232 case TypeTableEntryIdEnum:15232 case ZigTypeIdEnum:
15233 case TypeTableEntryIdUnion:15233 case ZigTypeIdUnion:
15234 case TypeTableEntryIdFn:15234 case ZigTypeIdFn:
15235 case TypeTableEntryIdArgTuple:15235 case ZigTypeIdArgTuple:
15236 case TypeTableEntryIdOpaque:15236 case ZigTypeIdOpaque:
15237 case TypeTableEntryIdPromise:15237 case ZigTypeIdPromise:
15238 {15238 {
15239 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);15239 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
15240 out_val->data.x_type = type_entry;15240 out_val->data.x_type = type_entry;
...@@ -15255,11 +15255,11 @@ static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,...@@ -15255,11 +15255,11 @@ static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
15255 return type_entry;15255 return type_entry;
1525615256
15257 ZigType *ptr_type;15257 ZigType *ptr_type;
15258 if (type_entry->id == TypeTableEntryIdArray) {15258 if (type_entry->id == ZigTypeIdArray) {
15259 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);15259 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
15260 } else if (is_slice(type_entry)) {15260 } else if (is_slice(type_entry)) {
15261 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);15261 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);
15262 } else if (type_entry->id == TypeTableEntryIdArgTuple) {15262 } else if (type_entry->id == ZigTypeIdArgTuple) {
15263 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);15263 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
15264 if (!arg_tuple_val)15264 if (!arg_tuple_val)
15265 return ira->codegen->builtin_types.entry_invalid;15265 return ira->codegen->builtin_types.entry_invalid;
...@@ -15283,7 +15283,7 @@ static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -15283,7 +15283,7 @@ static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
15283 if (type_is_invalid(type_entry))15283 if (type_is_invalid(type_entry))
15284 return type_entry;15284 return type_entry;
1528515285
15286 if (type_entry->id != TypeTableEntryIdPointer) {15286 if (type_entry->id != ZigTypeIdPointer) {
15287 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,15287 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
15288 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));15288 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
15289 return ira->codegen->builtin_types.entry_invalid;15289 return ira->codegen->builtin_types.entry_invalid;
...@@ -15400,24 +15400,24 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15400,24 +15400,24 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1540015400
15401 bool *fast_math_on_ptr;15401 bool *fast_math_on_ptr;
15402 AstNode **fast_math_set_node_ptr;15402 AstNode **fast_math_set_node_ptr;
15403 if (target_type->id == TypeTableEntryIdBlock) {15403 if (target_type->id == ZigTypeIdBlock) {
15404 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;15404 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
15405 fast_math_on_ptr = &block_scope->fast_math_on;15405 fast_math_on_ptr = &block_scope->fast_math_on;
15406 fast_math_set_node_ptr = &block_scope->fast_math_set_node;15406 fast_math_set_node_ptr = &block_scope->fast_math_set_node;
15407 } else if (target_type->id == TypeTableEntryIdFn) {15407 } else if (target_type->id == ZigTypeIdFn) {
15408 assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);15408 assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
15409 ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry;15409 ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
15410 assert(target_fn->def_scope);15410 assert(target_fn->def_scope);
15411 fast_math_on_ptr = &target_fn->def_scope->fast_math_on;15411 fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
15412 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;15412 fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
15413 } else if (target_type->id == TypeTableEntryIdMetaType) {15413 } else if (target_type->id == ZigTypeIdMetaType) {
15414 ScopeDecls *decls_scope;15414 ScopeDecls *decls_scope;
15415 ZigType *type_arg = target_val->data.x_type;15415 ZigType *type_arg = target_val->data.x_type;
15416 if (type_arg->id == TypeTableEntryIdStruct) {15416 if (type_arg->id == ZigTypeIdStruct) {
15417 decls_scope = type_arg->data.structure.decls_scope;15417 decls_scope = type_arg->data.structure.decls_scope;
15418 } else if (type_arg->id == TypeTableEntryIdEnum) {15418 } else if (type_arg->id == ZigTypeIdEnum) {
15419 decls_scope = type_arg->data.enumeration.decls_scope;15419 decls_scope = type_arg->data.enumeration.decls_scope;
15420 } else if (type_arg->id == TypeTableEntryIdUnion) {15420 } else if (type_arg->id == ZigTypeIdUnion) {
15421 decls_scope = type_arg->data.unionation.decls_scope;15421 decls_scope = type_arg->data.unionation.decls_scope;
15422 } else {15422 } else {
15423 ir_add_error_node(ira, target_instruction->source_node,15423 ir_add_error_node(ira, target_instruction->source_node,
...@@ -15476,36 +15476,36 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -15476,36 +15476,36 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,
15476 bool is_volatile = slice_type_instruction->is_volatile;15476 bool is_volatile = slice_type_instruction->is_volatile;
1547715477
15478 switch (child_type->id) {15478 switch (child_type->id) {
15479 case TypeTableEntryIdInvalid: // handled above15479 case ZigTypeIdInvalid: // handled above
15480 zig_unreachable();15480 zig_unreachable();
15481 case TypeTableEntryIdUnreachable:15481 case ZigTypeIdUnreachable:
15482 case TypeTableEntryIdUndefined:15482 case ZigTypeIdUndefined:
15483 case TypeTableEntryIdNull:15483 case ZigTypeIdNull:
15484 case TypeTableEntryIdBlock:15484 case ZigTypeIdBlock:
15485 case TypeTableEntryIdArgTuple:15485 case ZigTypeIdArgTuple:
15486 case TypeTableEntryIdOpaque:15486 case ZigTypeIdOpaque:
15487 ir_add_error_node(ira, slice_type_instruction->base.source_node,15487 ir_add_error_node(ira, slice_type_instruction->base.source_node,
15488 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));15488 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));
15489 return ira->codegen->builtin_types.entry_invalid;15489 return ira->codegen->builtin_types.entry_invalid;
15490 case TypeTableEntryIdMetaType:15490 case ZigTypeIdMetaType:
15491 case TypeTableEntryIdVoid:15491 case ZigTypeIdVoid:
15492 case TypeTableEntryIdBool:15492 case ZigTypeIdBool:
15493 case TypeTableEntryIdInt:15493 case ZigTypeIdInt:
15494 case TypeTableEntryIdFloat:15494 case ZigTypeIdFloat:
15495 case TypeTableEntryIdPointer:15495 case ZigTypeIdPointer:
15496 case TypeTableEntryIdArray:15496 case ZigTypeIdArray:
15497 case TypeTableEntryIdStruct:15497 case ZigTypeIdStruct:
15498 case TypeTableEntryIdComptimeFloat:15498 case ZigTypeIdComptimeFloat:
15499 case TypeTableEntryIdComptimeInt:15499 case ZigTypeIdComptimeInt:
15500 case TypeTableEntryIdOptional:15500 case ZigTypeIdOptional:
15501 case TypeTableEntryIdErrorUnion:15501 case ZigTypeIdErrorUnion:
15502 case TypeTableEntryIdErrorSet:15502 case ZigTypeIdErrorSet:
15503 case TypeTableEntryIdEnum:15503 case ZigTypeIdEnum:
15504 case TypeTableEntryIdUnion:15504 case ZigTypeIdUnion:
15505 case TypeTableEntryIdFn:15505 case ZigTypeIdFn:
15506 case TypeTableEntryIdNamespace:15506 case ZigTypeIdNamespace:
15507 case TypeTableEntryIdBoundFn:15507 case ZigTypeIdBoundFn:
15508 case TypeTableEntryIdPromise:15508 case ZigTypeIdPromise:
15509 {15509 {
15510 if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))15510 if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))
15511 return ira->codegen->builtin_types.entry_invalid;15511 return ira->codegen->builtin_types.entry_invalid;
...@@ -15587,36 +15587,36 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -15587,36 +15587,36 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,
15587 if (type_is_invalid(child_type))15587 if (type_is_invalid(child_type))
15588 return ira->codegen->builtin_types.entry_invalid;15588 return ira->codegen->builtin_types.entry_invalid;
15589 switch (child_type->id) {15589 switch (child_type->id) {
15590 case TypeTableEntryIdInvalid: // handled above15590 case ZigTypeIdInvalid: // handled above
15591 zig_unreachable();15591 zig_unreachable();
15592 case TypeTableEntryIdUnreachable:15592 case ZigTypeIdUnreachable:
15593 case TypeTableEntryIdUndefined:15593 case ZigTypeIdUndefined:
15594 case TypeTableEntryIdNull:15594 case ZigTypeIdNull:
15595 case TypeTableEntryIdBlock:15595 case ZigTypeIdBlock:
15596 case TypeTableEntryIdArgTuple:15596 case ZigTypeIdArgTuple:
15597 case TypeTableEntryIdOpaque:15597 case ZigTypeIdOpaque:
15598 ir_add_error_node(ira, array_type_instruction->base.source_node,15598 ir_add_error_node(ira, array_type_instruction->base.source_node,
15599 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));15599 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
15600 return ira->codegen->builtin_types.entry_invalid;15600 return ira->codegen->builtin_types.entry_invalid;
15601 case TypeTableEntryIdMetaType:15601 case ZigTypeIdMetaType:
15602 case TypeTableEntryIdVoid:15602 case ZigTypeIdVoid:
15603 case TypeTableEntryIdBool:15603 case ZigTypeIdBool:
15604 case TypeTableEntryIdInt:15604 case ZigTypeIdInt:
15605 case TypeTableEntryIdFloat:15605 case ZigTypeIdFloat:
15606 case TypeTableEntryIdPointer:15606 case ZigTypeIdPointer:
15607 case TypeTableEntryIdArray:15607 case ZigTypeIdArray:
15608 case TypeTableEntryIdStruct:15608 case ZigTypeIdStruct:
15609 case TypeTableEntryIdComptimeFloat:15609 case ZigTypeIdComptimeFloat:
15610 case TypeTableEntryIdComptimeInt:15610 case ZigTypeIdComptimeInt:
15611 case TypeTableEntryIdOptional:15611 case ZigTypeIdOptional:
15612 case TypeTableEntryIdErrorUnion:15612 case ZigTypeIdErrorUnion:
15613 case TypeTableEntryIdErrorSet:15613 case ZigTypeIdErrorSet:
15614 case TypeTableEntryIdEnum:15614 case ZigTypeIdEnum:
15615 case TypeTableEntryIdUnion:15615 case ZigTypeIdUnion:
15616 case TypeTableEntryIdFn:15616 case ZigTypeIdFn:
15617 case TypeTableEntryIdNamespace:15617 case ZigTypeIdNamespace:
15618 case TypeTableEntryIdBoundFn:15618 case ZigTypeIdBoundFn:
15619 case TypeTableEntryIdPromise:15619 case ZigTypeIdPromise:
15620 {15620 {
15621 if ((err = ensure_complete_type(ira->codegen, child_type)))15621 if ((err = ensure_complete_type(ira->codegen, child_type)))
15622 return ira->codegen->builtin_types.entry_invalid;15622 return ira->codegen->builtin_types.entry_invalid;
...@@ -15658,36 +15658,36 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -15658,36 +15658,36 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,
15658 return ira->codegen->builtin_types.entry_invalid;15658 return ira->codegen->builtin_types.entry_invalid;
1565915659
15660 switch (type_entry->id) {15660 switch (type_entry->id) {
15661 case TypeTableEntryIdInvalid: // handled above15661 case ZigTypeIdInvalid: // handled above
15662 zig_unreachable();15662 zig_unreachable();
15663 case TypeTableEntryIdUnreachable:15663 case ZigTypeIdUnreachable:
15664 case TypeTableEntryIdUndefined:15664 case ZigTypeIdUndefined:
15665 case TypeTableEntryIdNull:15665 case ZigTypeIdNull:
15666 case TypeTableEntryIdBlock:15666 case ZigTypeIdBlock:
15667 case TypeTableEntryIdComptimeFloat:15667 case ZigTypeIdComptimeFloat:
15668 case TypeTableEntryIdComptimeInt:15668 case ZigTypeIdComptimeInt:
15669 case TypeTableEntryIdBoundFn:15669 case ZigTypeIdBoundFn:
15670 case TypeTableEntryIdMetaType:15670 case ZigTypeIdMetaType:
15671 case TypeTableEntryIdNamespace:15671 case ZigTypeIdNamespace:
15672 case TypeTableEntryIdArgTuple:15672 case ZigTypeIdArgTuple:
15673 case TypeTableEntryIdOpaque:15673 case ZigTypeIdOpaque:
15674 ir_add_error_node(ira, size_of_instruction->base.source_node,15674 ir_add_error_node(ira, size_of_instruction->base.source_node,
15675 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));15675 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
15676 return ira->codegen->builtin_types.entry_invalid;15676 return ira->codegen->builtin_types.entry_invalid;
15677 case TypeTableEntryIdVoid:15677 case ZigTypeIdVoid:
15678 case TypeTableEntryIdBool:15678 case ZigTypeIdBool:
15679 case TypeTableEntryIdInt:15679 case ZigTypeIdInt:
15680 case TypeTableEntryIdFloat:15680 case ZigTypeIdFloat:
15681 case TypeTableEntryIdPointer:15681 case ZigTypeIdPointer:
15682 case TypeTableEntryIdArray:15682 case ZigTypeIdArray:
15683 case TypeTableEntryIdStruct:15683 case ZigTypeIdStruct:
15684 case TypeTableEntryIdOptional:15684 case ZigTypeIdOptional:
15685 case TypeTableEntryIdErrorUnion:15685 case ZigTypeIdErrorUnion:
15686 case TypeTableEntryIdErrorSet:15686 case ZigTypeIdErrorSet:
15687 case TypeTableEntryIdEnum:15687 case ZigTypeIdEnum:
15688 case TypeTableEntryIdUnion:15688 case ZigTypeIdUnion:
15689 case TypeTableEntryIdFn:15689 case ZigTypeIdFn:
15690 case TypeTableEntryIdPromise:15690 case ZigTypeIdPromise:
15691 {15691 {
15692 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);15692 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
15693 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);15693 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);
...@@ -15705,7 +15705,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi...@@ -15705,7 +15705,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi
1570515705
15706 ZigType *type_entry = value->value.type;15706 ZigType *type_entry = value->value.type;
1570715707
15708 if (type_entry->id == TypeTableEntryIdOptional) {15708 if (type_entry->id == ZigTypeIdOptional) {
15709 if (instr_is_comptime(value)) {15709 if (instr_is_comptime(value)) {
15710 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);15710 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
15711 if (!maybe_val)15711 if (!maybe_val)
...@@ -15718,7 +15718,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi...@@ -15718,7 +15718,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi
1571815718
15719 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);15719 ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
15720 return ira->codegen->builtin_types.entry_bool;15720 return ira->codegen->builtin_types.entry_bool;
15721 } else if (type_entry->id == TypeTableEntryIdNull) {15721 } else if (type_entry->id == ZigTypeIdNull) {
15722 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);15722 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
15723 out_val->data.x_bool = false;15723 out_val->data.x_bool = false;
15724 return ira->codegen->builtin_types.entry_bool;15724 return ira->codegen->builtin_types.entry_bool;
...@@ -15737,12 +15737,12 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -15737,12 +15737,12 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15737 return ira->codegen->builtin_types.entry_invalid;15737 return ira->codegen->builtin_types.entry_invalid;
1573815738
15739 ZigType *ptr_type = value->value.type;15739 ZigType *ptr_type = value->value.type;
15740 assert(ptr_type->id == TypeTableEntryIdPointer);15740 assert(ptr_type->id == ZigTypeIdPointer);
1574115741
15742 ZigType *type_entry = ptr_type->data.pointer.child_type;15742 ZigType *type_entry = ptr_type->data.pointer.child_type;
15743 if (type_is_invalid(type_entry)) {15743 if (type_is_invalid(type_entry)) {
15744 return ira->codegen->builtin_types.entry_invalid;15744 return ira->codegen->builtin_types.entry_invalid;
15745 } else if (type_entry->id != TypeTableEntryIdOptional) {15745 } else if (type_entry->id != ZigTypeIdOptional) {
15746 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,15746 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
15747 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));15747 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
15748 return ira->codegen->builtin_types.entry_invalid;15748 return ira->codegen->builtin_types.entry_invalid;
...@@ -15787,7 +15787,7 @@ static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz...@@ -15787,7 +15787,7 @@ static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz
15787 IrInstruction *value = ctz_instruction->value->other;15787 IrInstruction *value = ctz_instruction->value->other;
15788 if (type_is_invalid(value->value.type)) {15788 if (type_is_invalid(value->value.type)) {
15789 return ira->codegen->builtin_types.entry_invalid;15789 return ira->codegen->builtin_types.entry_invalid;
15790 } else if (value->value.type->id == TypeTableEntryIdInt) {15790 } else if (value->value.type->id == ZigTypeIdInt) {
15791 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,15791 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
15792 value->value.type->data.integral.bit_count);15792 value->value.type->data.integral.bit_count);
15793 if (value->value.special != ConstValSpecialRuntime) {15793 if (value->value.special != ConstValSpecialRuntime) {
...@@ -15811,7 +15811,7 @@ static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz...@@ -15811,7 +15811,7 @@ static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz
15811 IrInstruction *value = clz_instruction->value->other;15811 IrInstruction *value = clz_instruction->value->other;
15812 if (type_is_invalid(value->value.type)) {15812 if (type_is_invalid(value->value.type)) {
15813 return ira->codegen->builtin_types.entry_invalid;15813 return ira->codegen->builtin_types.entry_invalid;
15814 } else if (value->value.type->id == TypeTableEntryIdInt) {15814 } else if (value->value.type->id == ZigTypeIdInt) {
15815 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,15815 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
15816 value->value.type->data.integral.bit_count);15816 value->value.type->data.integral.bit_count);
15817 if (value->value.special != ConstValSpecialRuntime) {15817 if (value->value.special != ConstValSpecialRuntime) {
...@@ -15836,7 +15836,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo...@@ -15836,7 +15836,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo
15836 if (type_is_invalid(value->value.type))15836 if (type_is_invalid(value->value.type))
15837 return ira->codegen->builtin_types.entry_invalid;15837 return ira->codegen->builtin_types.entry_invalid;
1583815838
15839 if (value->value.type->id != TypeTableEntryIdInt && value->value.type->id != TypeTableEntryIdComptimeInt) {15839 if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) {
15840 ir_add_error(ira, value,15840 ir_add_error(ira, value,
15841 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));15841 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
15842 return ira->codegen->builtin_types.entry_invalid;15842 return ira->codegen->builtin_types.entry_invalid;
...@@ -15852,7 +15852,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo...@@ -15852,7 +15852,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo
15852 bigint_init_unsigned(&out_val->data.x_bigint, result);15852 bigint_init_unsigned(&out_val->data.x_bigint, result);
15853 return ira->codegen->builtin_types.entry_num_lit_int;15853 return ira->codegen->builtin_types.entry_num_lit_int;
15854 }15854 }
15855 if (value->value.type->id == TypeTableEntryIdComptimeInt) {15855 if (value->value.type->id == ZigTypeIdComptimeInt) {
15856 Buf *val_buf = buf_alloc();15856 Buf *val_buf = buf_alloc();
15857 bigint_append_buf(val_buf, &val->data.x_bigint, 10);15857 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
15858 ir_add_error(ira, &instruction->base,15858 ir_add_error(ira, &instruction->base,
...@@ -15877,11 +15877,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -15877,11 +15877,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
15877 if (type_is_invalid(value->value.type))15877 if (type_is_invalid(value->value.type))
15878 return ira->codegen->invalid_instruction;15878 return ira->codegen->invalid_instruction;
1587915879
15880 if (value->value.type->id == TypeTableEntryIdEnum) {15880 if (value->value.type->id == ZigTypeIdEnum) {
15881 return value;15881 return value;
15882 }15882 }
1588315883
15884 if (value->value.type->id != TypeTableEntryIdUnion) {15884 if (value->value.type->id != ZigTypeIdUnion) {
15885 ir_add_error(ira, value,15885 ir_add_error(ira, value,
15886 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));15886 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));
15887 return ira->codegen->invalid_instruction;15887 return ira->codegen->invalid_instruction;
...@@ -15896,7 +15896,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -15896,7 +15896,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
15896 }15896 }
1589715897
15898 ZigType *tag_type = value->value.type->data.unionation.tag_type;15898 ZigType *tag_type = value->value.type->data.unionation.tag_type;
15899 assert(tag_type->id == TypeTableEntryIdEnum);15899 assert(tag_type->id == ZigTypeIdEnum);
1590015900
15901 if (instr_is_comptime(value)) {15901 if (instr_is_comptime(value)) {
15902 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);15902 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -15948,7 +15948,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -15948,7 +15948,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15948 if (type_is_invalid(case_value->value.type))15948 if (type_is_invalid(case_value->value.type))
15949 return ir_unreach_error(ira);15949 return ir_unreach_error(ira);
1595015950
15951 if (case_value->value.type->id == TypeTableEntryIdEnum) {15951 if (case_value->value.type->id == ZigTypeIdEnum) {
15952 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);15952 case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);
15953 if (type_is_invalid(case_value->value.type))15953 if (type_is_invalid(case_value->value.type))
15954 return ir_unreach_error(ira);15954 return ir_unreach_error(ira);
...@@ -15995,7 +15995,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -15995,7 +15995,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,
15995 if (type_is_invalid(new_value->value.type))15995 if (type_is_invalid(new_value->value.type))
15996 continue;15996 continue;
1599715997
15998 if (new_value->value.type->id == TypeTableEntryIdEnum) {15998 if (new_value->value.type->id == ZigTypeIdEnum) {
15999 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);15999 new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);
16000 if (type_is_invalid(new_value->value.type))16000 if (type_is_invalid(new_value->value.type))
16001 continue;16001 continue;
...@@ -16032,17 +16032,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16032,17 +16032,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16032 if (type_is_invalid(target_value_ptr->value.type))16032 if (type_is_invalid(target_value_ptr->value.type))
16033 return ira->codegen->builtin_types.entry_invalid;16033 return ira->codegen->builtin_types.entry_invalid;
1603416034
16035 if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {16035 if (target_value_ptr->value.type->id == ZigTypeIdMetaType) {
16036 assert(instr_is_comptime(target_value_ptr));16036 assert(instr_is_comptime(target_value_ptr));
16037 ZigType *ptr_type = target_value_ptr->value.data.x_type;16037 ZigType *ptr_type = target_value_ptr->value.data.x_type;
16038 assert(ptr_type->id == TypeTableEntryIdPointer);16038 assert(ptr_type->id == ZigTypeIdPointer);
16039 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16039 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
16040 out_val->type = ira->codegen->builtin_types.entry_type;16040 out_val->type = ira->codegen->builtin_types.entry_type;
16041 out_val->data.x_type = ptr_type->data.pointer.child_type;16041 out_val->data.x_type = ptr_type->data.pointer.child_type;
16042 return out_val->type;16042 return out_val->type;
16043 }16043 }
1604416044
16045 if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {16045 if (target_value_ptr->value.type->id != ZigTypeIdPointer) {
16046 ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));16046 ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
16047 return ira->codegen->builtin_types.entry_invalid;16047 return ira->codegen->builtin_types.entry_invalid;
16048 }16048 }
...@@ -16061,20 +16061,20 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16061,20 +16061,20 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16061 return ira->codegen->builtin_types.entry_invalid;16061 return ira->codegen->builtin_types.entry_invalid;
1606216062
16063 switch (target_type->id) {16063 switch (target_type->id) {
16064 case TypeTableEntryIdInvalid:16064 case ZigTypeIdInvalid:
16065 zig_unreachable();16065 zig_unreachable();
16066 case TypeTableEntryIdMetaType:16066 case ZigTypeIdMetaType:
16067 case TypeTableEntryIdVoid:16067 case ZigTypeIdVoid:
16068 case TypeTableEntryIdBool:16068 case ZigTypeIdBool:
16069 case TypeTableEntryIdInt:16069 case ZigTypeIdInt:
16070 case TypeTableEntryIdFloat:16070 case ZigTypeIdFloat:
16071 case TypeTableEntryIdComptimeFloat:16071 case ZigTypeIdComptimeFloat:
16072 case TypeTableEntryIdComptimeInt:16072 case ZigTypeIdComptimeInt:
16073 case TypeTableEntryIdPointer:16073 case ZigTypeIdPointer:
16074 case TypeTableEntryIdPromise:16074 case ZigTypeIdPromise:
16075 case TypeTableEntryIdFn:16075 case ZigTypeIdFn:
16076 case TypeTableEntryIdNamespace:16076 case ZigTypeIdNamespace:
16077 case TypeTableEntryIdErrorSet:16077 case ZigTypeIdErrorSet:
16078 if (pointee_val) {16078 if (pointee_val) {
16079 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16079 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
16080 copy_const_val(out_val, pointee_val, true);16080 copy_const_val(out_val, pointee_val, true);
...@@ -16084,7 +16084,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16084,7 +16084,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1608416084
16085 ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);16085 ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);
16086 return target_type;16086 return target_type;
16087 case TypeTableEntryIdUnion: {16087 case ZigTypeIdUnion: {
16088 AstNode *decl_node = target_type->data.unionation.decl_node;16088 AstNode *decl_node = target_type->data.unionation.decl_node;
16089 if (!decl_node->data.container_decl.auto_enum &&16089 if (!decl_node->data.container_decl.auto_enum &&
16090 decl_node->data.container_decl.init_arg_expr == nullptr)16090 decl_node->data.container_decl.init_arg_expr == nullptr)
...@@ -16097,7 +16097,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16097,7 +16097,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16097 }16097 }
16098 ZigType *tag_type = target_type->data.unionation.tag_type;16098 ZigType *tag_type = target_type->data.unionation.tag_type;
16099 assert(tag_type != nullptr);16099 assert(tag_type != nullptr);
16100 assert(tag_type->id == TypeTableEntryIdEnum);16100 assert(tag_type->id == ZigTypeIdEnum);
16101 if (pointee_val) {16101 if (pointee_val) {
16102 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);16102 ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
16103 bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag);16103 bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag);
...@@ -16120,7 +16120,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16120,7 +16120,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16120 ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);16120 ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);
16121 return tag_type;16121 return tag_type;
16122 }16122 }
16123 case TypeTableEntryIdEnum: {16123 case ZigTypeIdEnum: {
16124 if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))16124 if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))
16125 return ira->codegen->builtin_types.entry_invalid;16125 return ira->codegen->builtin_types.entry_invalid;
16126 if (target_type->data.enumeration.src_field_count < 2) {16126 if (target_type->data.enumeration.src_field_count < 2) {
...@@ -16142,17 +16142,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16142,17 +16142,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16142 ir_link_new_instruction(enum_value, &switch_target_instruction->base);16142 ir_link_new_instruction(enum_value, &switch_target_instruction->base);
16143 return target_type;16143 return target_type;
16144 }16144 }
16145 case TypeTableEntryIdErrorUnion:16145 case ZigTypeIdErrorUnion:
16146 case TypeTableEntryIdUnreachable:16146 case ZigTypeIdUnreachable:
16147 case TypeTableEntryIdArray:16147 case ZigTypeIdArray:
16148 case TypeTableEntryIdStruct:16148 case ZigTypeIdStruct:
16149 case TypeTableEntryIdUndefined:16149 case ZigTypeIdUndefined:
16150 case TypeTableEntryIdNull:16150 case ZigTypeIdNull:
16151 case TypeTableEntryIdOptional:16151 case ZigTypeIdOptional:
16152 case TypeTableEntryIdBlock:16152 case ZigTypeIdBlock:
16153 case TypeTableEntryIdBoundFn:16153 case ZigTypeIdBoundFn:
16154 case TypeTableEntryIdArgTuple:16154 case ZigTypeIdArgTuple:
16155 case TypeTableEntryIdOpaque:16155 case ZigTypeIdOpaque:
16156 ir_add_error(ira, &switch_target_instruction->base,16156 ir_add_error(ira, &switch_target_instruction->base,
16157 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));16157 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
16158 return ira->codegen->builtin_types.entry_invalid;16158 return ira->codegen->builtin_types.entry_invalid;
...@@ -16169,14 +16169,14 @@ static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionS...@@ -16169,14 +16169,14 @@ static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionS
16169 if (type_is_invalid(prong_value->value.type))16169 if (type_is_invalid(prong_value->value.type))
16170 return ira->codegen->builtin_types.entry_invalid;16170 return ira->codegen->builtin_types.entry_invalid;
1617116171
16172 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);16172 assert(target_value_ptr->value.type->id == ZigTypeIdPointer);
16173 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;16173 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
16174 if (target_type->id == TypeTableEntryIdUnion) {16174 if (target_type->id == ZigTypeIdUnion) {
16175 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);16175 ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);
16176 if (!prong_val)16176 if (!prong_val)
16177 return ira->codegen->builtin_types.entry_invalid;16177 return ira->codegen->builtin_types.entry_invalid;
1617816178
16179 assert(prong_value->value.type->id == TypeTableEntryIdEnum);16179 assert(prong_value->value.type->id == ZigTypeIdEnum);
16180 TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);16180 TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);
1618116181
16182 if (instr_is_comptime(target_value_ptr)) {16182 if (instr_is_comptime(target_value_ptr)) {
...@@ -16285,7 +16285,7 @@ static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira,...@@ -16285,7 +16285,7 @@ static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira,
16285 ZigType *type_entry = array_value->value.type;16285 ZigType *type_entry = array_value->value.type;
16286 if (type_is_invalid(type_entry)) {16286 if (type_is_invalid(type_entry)) {
16287 return ira->codegen->builtin_types.entry_invalid;16287 return ira->codegen->builtin_types.entry_invalid;
16288 } else if (type_entry->id == TypeTableEntryIdArray) {16288 } else if (type_entry->id == ZigTypeIdArray) {
16289 return ir_analyze_const_usize(ira, &array_len_instruction->base,16289 return ir_analyze_const_usize(ira, &array_len_instruction->base,
16290 type_entry->data.array.len);16290 type_entry->data.array.len);
16291 } else if (is_slice(type_entry)) {16291 } else if (is_slice(type_entry)) {
...@@ -16318,7 +16318,7 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc...@@ -16318,7 +16318,7 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc
16318 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)16318 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16319{16319{
16320 Error err;16320 Error err;
16321 assert(container_type->id == TypeTableEntryIdUnion);16321 assert(container_type->id == ZigTypeIdUnion);
1632216322
16323 if ((err = ensure_complete_type(ira->codegen, container_type)))16323 if ((err = ensure_complete_type(ira->codegen, container_type)))
16324 return ira->codegen->builtin_types.entry_invalid;16324 return ira->codegen->builtin_types.entry_invalid;
...@@ -16384,10 +16384,10 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *...@@ -16384,10 +16384,10 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *
16384 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)16384 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
16385{16385{
16386 Error err;16386 Error err;
16387 if (container_type->id == TypeTableEntryIdUnion) {16387 if (container_type->id == ZigTypeIdUnion) {
16388 return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);16388 return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);
16389 }16389 }
16390 if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {16390 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
16391 ir_add_error(ira, instruction,16391 ir_add_error(ira, instruction,
16392 buf_sprintf("type '%s' does not support struct initialization syntax",16392 buf_sprintf("type '%s' does not support struct initialization syntax",
16393 buf_ptr(&container_type->name)));16393 buf_ptr(&container_type->name)));
...@@ -16508,18 +16508,18 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16508,18 +16508,18 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16508 return ira->codegen->builtin_types.entry_invalid;16508 return ira->codegen->builtin_types.entry_invalid;
1650916509
16510 size_t elem_count = instruction->item_count;16510 size_t elem_count = instruction->item_count;
16511 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {16511 if (container_type_value->value.type->id == ZigTypeIdMetaType) {
16512 ZigType *container_type = ir_resolve_type(ira, container_type_value);16512 ZigType *container_type = ir_resolve_type(ira, container_type_value);
16513 if (type_is_invalid(container_type))16513 if (type_is_invalid(container_type))
16514 return ira->codegen->builtin_types.entry_invalid;16514 return ira->codegen->builtin_types.entry_invalid;
1651516515
16516 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {16516 if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
16517 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,16517 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
16518 0, nullptr);16518 0, nullptr);
16519 } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) {16519 } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
16520 // array is same as slice init but we make a compile error if the length is wrong16520 // array is same as slice init but we make a compile error if the length is wrong
16521 ZigType *child_type;16521 ZigType *child_type;
16522 if (container_type->id == TypeTableEntryIdArray) {16522 if (container_type->id == ZigTypeIdArray) {
16523 child_type = container_type->data.array.child_type;16523 child_type = container_type->data.array.child_type;
16524 if (container_type->data.array.len != elem_count) {16524 if (container_type->data.array.len != elem_count) {
16525 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);16525 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);
...@@ -16531,7 +16531,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16531,7 +16531,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16531 }16531 }
16532 } else {16532 } else {
16533 ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;16533 ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
16534 assert(pointer_type->id == TypeTableEntryIdPointer);16534 assert(pointer_type->id == ZigTypeIdPointer);
16535 child_type = pointer_type->data.pointer.child_type;16535 child_type = pointer_type->data.pointer.child_type;
16536 }16536 }
1653716537
...@@ -16598,7 +16598,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16598,7 +16598,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16598 container_type_value, elem_count, new_items);16598 container_type_value, elem_count, new_items);
16599 ir_add_alloca(ira, new_instruction, fixed_size_array_type);16599 ir_add_alloca(ira, new_instruction, fixed_size_array_type);
16600 return fixed_size_array_type;16600 return fixed_size_array_type;
16601 } else if (container_type->id == TypeTableEntryIdVoid) {16601 } else if (container_type->id == ZigTypeIdVoid) {
16602 if (elem_count != 0) {16602 if (elem_count != 0) {
16603 ir_add_error_node(ira, instruction->base.source_node,16603 ir_add_error_node(ira, instruction->base.source_node,
16604 buf_sprintf("void expression expects no arguments"));16604 buf_sprintf("void expression expects no arguments"));
...@@ -16635,43 +16635,43 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc...@@ -16635,43 +16635,43 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc
16635 if (type_is_invalid(target_type))16635 if (type_is_invalid(target_type))
16636 return ira->codegen->builtin_types.entry_invalid;16636 return ira->codegen->builtin_types.entry_invalid;
16637 switch (target_type->id) {16637 switch (target_type->id) {
16638 case TypeTableEntryIdInvalid:16638 case ZigTypeIdInvalid:
16639 zig_unreachable();16639 zig_unreachable();
16640 case TypeTableEntryIdInt:16640 case ZigTypeIdInt:
16641 {16641 {
16642 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);16642 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
16643 eval_min_max_value(ira->codegen, target_type, out_val, is_max);16643 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
16644 return ira->codegen->builtin_types.entry_num_lit_int;16644 return ira->codegen->builtin_types.entry_num_lit_int;
16645 }16645 }
16646 case TypeTableEntryIdBool:16646 case ZigTypeIdBool:
16647 case TypeTableEntryIdVoid:16647 case ZigTypeIdVoid:
16648 {16648 {
16649 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);16649 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
16650 eval_min_max_value(ira->codegen, target_type, out_val, is_max);16650 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
16651 return target_type;16651 return target_type;
16652 }16652 }
16653 case TypeTableEntryIdEnum:16653 case ZigTypeIdEnum:
16654 case TypeTableEntryIdFloat:16654 case ZigTypeIdFloat:
16655 case TypeTableEntryIdMetaType:16655 case ZigTypeIdMetaType:
16656 case TypeTableEntryIdUnreachable:16656 case ZigTypeIdUnreachable:
16657 case TypeTableEntryIdPointer:16657 case ZigTypeIdPointer:
16658 case TypeTableEntryIdPromise:16658 case ZigTypeIdPromise:
16659 case TypeTableEntryIdArray:16659 case ZigTypeIdArray:
16660 case TypeTableEntryIdStruct:16660 case ZigTypeIdStruct:
16661 case TypeTableEntryIdComptimeFloat:16661 case ZigTypeIdComptimeFloat:
16662 case TypeTableEntryIdComptimeInt:16662 case ZigTypeIdComptimeInt:
16663 case TypeTableEntryIdUndefined:16663 case ZigTypeIdUndefined:
16664 case TypeTableEntryIdNull:16664 case ZigTypeIdNull:
16665 case TypeTableEntryIdOptional:16665 case ZigTypeIdOptional:
16666 case TypeTableEntryIdErrorUnion:16666 case ZigTypeIdErrorUnion:
16667 case TypeTableEntryIdErrorSet:16667 case ZigTypeIdErrorSet:
16668 case TypeTableEntryIdUnion:16668 case ZigTypeIdUnion:
16669 case TypeTableEntryIdFn:16669 case ZigTypeIdFn:
16670 case TypeTableEntryIdNamespace:16670 case ZigTypeIdNamespace:
16671 case TypeTableEntryIdBlock:16671 case ZigTypeIdBlock:
16672 case TypeTableEntryIdBoundFn:16672 case ZigTypeIdBoundFn:
16673 case TypeTableEntryIdArgTuple:16673 case ZigTypeIdArgTuple:
16674 case TypeTableEntryIdOpaque:16674 case ZigTypeIdOpaque:
16675 {16675 {
16676 const char *err_format = is_max ?16676 const char *err_format = is_max ?
16677 "no max value available for type '%s'" :16677 "no max value available for type '%s'" :
...@@ -16774,7 +16774,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi...@@ -16774,7 +16774,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi
16774 if (type_is_invalid(target->value.type))16774 if (type_is_invalid(target->value.type))
16775 return ira->codegen->builtin_types.entry_invalid;16775 return ira->codegen->builtin_types.entry_invalid;
1677616776
16777 assert(target->value.type->id == TypeTableEntryIdEnum);16777 assert(target->value.type->id == ZigTypeIdEnum);
1677816778
16779 if (instr_is_comptime(target)) {16779 if (instr_is_comptime(target)) {
16780 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))16780 if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
...@@ -16816,7 +16816,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16816,7 +16816,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16816 if (type_is_invalid(field_ptr->value.type))16816 if (type_is_invalid(field_ptr->value.type))
16817 return ira->codegen->builtin_types.entry_invalid;16817 return ira->codegen->builtin_types.entry_invalid;
1681816818
16819 if (container_type->id != TypeTableEntryIdStruct) {16819 if (container_type->id != ZigTypeIdStruct) {
16820 ir_add_error(ira, type_value,16820 ir_add_error(ira, type_value,
16821 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));16821 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16822 return ira->codegen->builtin_types.entry_invalid;16822 return ira->codegen->builtin_types.entry_invalid;
...@@ -16833,7 +16833,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16833,7 +16833,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16833 return ira->codegen->builtin_types.entry_invalid;16833 return ira->codegen->builtin_types.entry_invalid;
16834 }16834 }
1683516835
16836 if (field_ptr->value.type->id != TypeTableEntryIdPointer) {16836 if (field_ptr->value.type->id != ZigTypeIdPointer) {
16837 ir_add_error(ira, field_ptr,16837 ir_add_error(ira, field_ptr,
16838 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));16838 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));
16839 return ira->codegen->builtin_types.entry_invalid;16839 return ira->codegen->builtin_types.entry_invalid;
...@@ -16908,7 +16908,7 @@ static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira,...@@ -16908,7 +16908,7 @@ static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira,
16908 if (!field_name)16908 if (!field_name)
16909 return ira->codegen->builtin_types.entry_invalid;16909 return ira->codegen->builtin_types.entry_invalid;
1691016910
16911 if (container_type->id != TypeTableEntryIdStruct) {16911 if (container_type->id != ZigTypeIdStruct) {
16912 ir_add_error(ira, type_value,16912 ir_add_error(ira, type_value,
16913 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));16913 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16914 return ira->codegen->builtin_types.entry_invalid;16914 return ira->codegen->builtin_types.entry_invalid;
...@@ -16951,11 +16951,11 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -16951,11 +16951,11 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
16951 static ZigType *type_info_type = nullptr;16951 static ZigType *type_info_type = nullptr;
16952 if (type_info_var == nullptr) {16952 if (type_info_var == nullptr) {
16953 type_info_var = get_builtin_value(ira->codegen, "TypeInfo");16953 type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
16954 assert(type_info_var->type->id == TypeTableEntryIdMetaType);16954 assert(type_info_var->type->id == ZigTypeIdMetaType);
1695516955
16956 assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));16956 assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));
16957 type_info_type = type_info_var->data.x_type;16957 type_info_type = type_info_var->data.x_type;
16958 assert(type_info_type->id == TypeTableEntryIdUnion);16958 assert(type_info_type->id == ZigTypeIdUnion);
16959 }16959 }
1696016960
16961 if (type_name == nullptr && root == nullptr)16961 if (type_name == nullptr && root == nullptr)
...@@ -16980,7 +16980,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -16980,7 +16980,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
1698016980
16981 if ((err = ensure_complete_type(ira->codegen, var->value->type)))16981 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
16982 return ira->codegen->builtin_types.entry_invalid;16982 return ira->codegen->builtin_types.entry_invalid;
16983 assert(var->value->type->id == TypeTableEntryIdMetaType);16983 assert(var->value->type->id == ZigTypeIdMetaType);
16984 return var->value->data.x_type;16984 return var->value->data.x_type;
16985}16985}
1698616986
...@@ -17078,7 +17078,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco...@@ -17078,7 +17078,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
17078 if ((err = ensure_complete_type(ira->codegen, var->value->type)))17078 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
17079 return ErrorSemanticAnalyzeFail;17079 return ErrorSemanticAnalyzeFail;
1708017080
17081 if (var->value->type->id == TypeTableEntryIdMetaType)17081 if (var->value->type->id == ZigTypeIdMetaType)
17082 {17082 {
17083 // We have a variable of type 'type', so it's actually a type definition.17083 // We have a variable of type 'type', so it's actually a type definition.
17084 // 0: Data.Type: type17084 // 0: Data.Type: type
...@@ -17238,7 +17238,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -17238,7 +17238,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
17238 if (is_slice(ptr_type_entry)) {17238 if (is_slice(ptr_type_entry)) {
17239 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;17239 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
17240 size_enum_index = 2;17240 size_enum_index = 2;
17241 } else if (ptr_type_entry->id == TypeTableEntryIdPointer) {17241 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
17242 attrs_type = ptr_type_entry;17242 attrs_type = ptr_type_entry;
17243 size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;17243 size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;
17244 } else {17244 } else {
...@@ -17320,20 +17320,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17320,20 +17320,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
17320 ConstExprValue *result = nullptr;17320 ConstExprValue *result = nullptr;
17321 switch (type_entry->id)17321 switch (type_entry->id)
17322 {17322 {
17323 case TypeTableEntryIdInvalid:17323 case ZigTypeIdInvalid:
17324 zig_unreachable();17324 zig_unreachable();
17325 case TypeTableEntryIdMetaType:17325 case ZigTypeIdMetaType:
17326 case TypeTableEntryIdVoid:17326 case ZigTypeIdVoid:
17327 case TypeTableEntryIdBool:17327 case ZigTypeIdBool:
17328 case TypeTableEntryIdUnreachable:17328 case ZigTypeIdUnreachable:
17329 case TypeTableEntryIdComptimeFloat:17329 case ZigTypeIdComptimeFloat:
17330 case TypeTableEntryIdComptimeInt:17330 case ZigTypeIdComptimeInt:
17331 case TypeTableEntryIdUndefined:17331 case ZigTypeIdUndefined:
17332 case TypeTableEntryIdNull:17332 case ZigTypeIdNull:
17333 case TypeTableEntryIdNamespace:17333 case ZigTypeIdNamespace:
17334 case TypeTableEntryIdBlock:17334 case ZigTypeIdBlock:
17335 case TypeTableEntryIdArgTuple:17335 case ZigTypeIdArgTuple:
17336 case TypeTableEntryIdOpaque:17336 case ZigTypeIdOpaque:
17337 *out = nullptr;17337 *out = nullptr;
17338 return ErrorNone;17338 return ErrorNone;
17339 default:17339 default:
...@@ -17347,7 +17347,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17347,7 +17347,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1734717347
17348 // Fallthrough if we don't find one.17348 // Fallthrough if we don't find one.
17349 }17349 }
17350 case TypeTableEntryIdInt:17350 case ZigTypeIdInt:
17351 {17351 {
17352 result = create_const_vals(1);17352 result = create_const_vals(1);
17353 result->special = ConstValSpecialStatic;17353 result->special = ConstValSpecialStatic;
...@@ -17369,7 +17369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17369,7 +17369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1736917369
17370 break;17370 break;
17371 }17371 }
17372 case TypeTableEntryIdFloat:17372 case ZigTypeIdFloat:
17373 {17373 {
17374 result = create_const_vals(1);17374 result = create_const_vals(1);
17375 result->special = ConstValSpecialStatic;17375 result->special = ConstValSpecialStatic;
...@@ -17386,12 +17386,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17386,12 +17386,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1738617386
17387 break;17387 break;
17388 }17388 }
17389 case TypeTableEntryIdPointer:17389 case ZigTypeIdPointer:
17390 {17390 {
17391 result = create_ptr_like_type_info(ira, type_entry);17391 result = create_ptr_like_type_info(ira, type_entry);
17392 break;17392 break;
17393 }17393 }
17394 case TypeTableEntryIdArray:17394 case ZigTypeIdArray:
17395 {17395 {
17396 result = create_const_vals(1);17396 result = create_const_vals(1);
17397 result->special = ConstValSpecialStatic;17397 result->special = ConstValSpecialStatic;
...@@ -17413,7 +17413,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17413,7 +17413,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1741317413
17414 break;17414 break;
17415 }17415 }
17416 case TypeTableEntryIdOptional:17416 case ZigTypeIdOptional:
17417 {17417 {
17418 result = create_const_vals(1);17418 result = create_const_vals(1);
17419 result->special = ConstValSpecialStatic;17419 result->special = ConstValSpecialStatic;
...@@ -17430,7 +17430,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17430,7 +17430,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1743017430
17431 break;17431 break;
17432 }17432 }
17433 case TypeTableEntryIdPromise:17433 case ZigTypeIdPromise:
17434 {17434 {
17435 result = create_const_vals(1);17435 result = create_const_vals(1);
17436 result->special = ConstValSpecialStatic;17436 result->special = ConstValSpecialStatic;
...@@ -17456,7 +17456,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17456,7 +17456,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1745617456
17457 break;17457 break;
17458 }17458 }
17459 case TypeTableEntryIdEnum:17459 case ZigTypeIdEnum:
17460 {17460 {
17461 result = create_const_vals(1);17461 result = create_const_vals(1);
17462 result->special = ConstValSpecialStatic;17462 result->special = ConstValSpecialStatic;
...@@ -17506,7 +17506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17506,7 +17506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1750617506
17507 break;17507 break;
17508 }17508 }
17509 case TypeTableEntryIdErrorSet:17509 case ZigTypeIdErrorSet:
17510 {17510 {
17511 result = create_const_vals(1);17511 result = create_const_vals(1);
17512 result->special = ConstValSpecialStatic;17512 result->special = ConstValSpecialStatic;
...@@ -17555,7 +17555,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17555,7 +17555,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1755517555
17556 break;17556 break;
17557 }17557 }
17558 case TypeTableEntryIdErrorUnion:17558 case ZigTypeIdErrorUnion:
17559 {17559 {
17560 result = create_const_vals(1);17560 result = create_const_vals(1);
17561 result->special = ConstValSpecialStatic;17561 result->special = ConstValSpecialStatic;
...@@ -17578,7 +17578,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17578,7 +17578,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1757817578
17579 break;17579 break;
17580 }17580 }
17581 case TypeTableEntryIdUnion:17581 case ZigTypeIdUnion:
17582 {17582 {
17583 result = create_const_vals(1);17583 result = create_const_vals(1);
17584 result->special = ConstValSpecialStatic;17584 result->special = ConstValSpecialStatic;
...@@ -17663,7 +17663,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17663,7 +17663,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1766317663
17664 break;17664 break;
17665 }17665 }
17666 case TypeTableEntryIdStruct:17666 case ZigTypeIdStruct:
17667 {17667 {
17668 if (type_entry->data.structure.is_slice) {17668 if (type_entry->data.structure.is_slice) {
17669 result = create_ptr_like_type_info(ira, type_entry);17669 result = create_ptr_like_type_info(ira, type_entry);
...@@ -17737,7 +17737,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17737,7 +17737,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1773717737
17738 break;17738 break;
17739 }17739 }
17740 case TypeTableEntryIdFn:17740 case ZigTypeIdFn:
17741 {17741 {
17742 result = create_const_vals(1);17742 result = create_const_vals(1);
17743 result->special = ConstValSpecialStatic;17743 result->special = ConstValSpecialStatic;
...@@ -17842,10 +17842,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17842,10 +17842,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1784217842
17843 break;17843 break;
17844 }17844 }
17845 case TypeTableEntryIdBoundFn:17845 case ZigTypeIdBoundFn:
17846 {17846 {
17847 ZigType *fn_type = type_entry->data.bound_fn.fn_type;17847 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
17848 assert(fn_type->id == TypeTableEntryIdFn);17848 assert(fn_type->id == ZigTypeIdFn);
17849 if ((err = ir_make_type_info_value(ira, fn_type, &result)))17849 if ((err = ir_make_type_info_value(ira, fn_type, &result)))
17850 return err;17850 return err;
1785117851
...@@ -17880,7 +17880,7 @@ static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -17880,7 +17880,7 @@ static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira,
17880 out_val->data.x_union.payload = payload;17880 out_val->data.x_union.payload = payload;
1788117881
17882 if (payload != nullptr) {17882 if (payload != nullptr) {
17883 assert(payload->type->id == TypeTableEntryIdStruct);17883 assert(payload->type->id == ZigTypeIdStruct);
17884 payload->data.x_struct.parent.id = ConstParentIdUnion;17884 payload->data.x_struct.parent.id = ConstParentIdUnion;
17885 payload->data.x_struct.parent.data.p_union.union_val = out_val;17885 payload->data.x_struct.parent.data.p_union.union_val = out_val;
17886 }17886 }
...@@ -17897,7 +17897,7 @@ static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira,...@@ -17897,7 +17897,7 @@ static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira,
17897 return ira->codegen->builtin_types.entry_invalid;17897 return ira->codegen->builtin_types.entry_invalid;
1789817898
17899 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");17899 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");
17900 assert(var_value->type->id == TypeTableEntryIdMetaType);17900 assert(var_value->type->id == ZigTypeIdMetaType);
17901 ZigType *result_type = var_value->data.x_type;17901 ZigType *result_type = var_value->data.x_type;
1790217902
17903 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);17903 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -18206,8 +18206,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru...@@ -18206,8 +18206,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru
18206 if (type_is_invalid(dest_type))18206 if (type_is_invalid(dest_type))
18207 return ira->codegen->builtin_types.entry_invalid;18207 return ira->codegen->builtin_types.entry_invalid;
1820818208
18209 if (dest_type->id != TypeTableEntryIdInt &&18209 if (dest_type->id != ZigTypeIdInt &&
18210 dest_type->id != TypeTableEntryIdComptimeInt)18210 dest_type->id != ZigTypeIdComptimeInt)
18211 {18211 {
18212 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));18212 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
18213 return ira->codegen->builtin_types.entry_invalid;18213 return ira->codegen->builtin_types.entry_invalid;
...@@ -18218,8 +18218,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru...@@ -18218,8 +18218,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru
18218 if (type_is_invalid(src_type))18218 if (type_is_invalid(src_type))
18219 return ira->codegen->builtin_types.entry_invalid;18219 return ira->codegen->builtin_types.entry_invalid;
1822018220
18221 if (src_type->id != TypeTableEntryIdInt &&18221 if (src_type->id != ZigTypeIdInt &&
18222 src_type->id != TypeTableEntryIdComptimeInt)18222 src_type->id != ZigTypeIdComptimeInt)
18223 {18223 {
18224 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));18224 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
18225 return ira->codegen->builtin_types.entry_invalid;18225 return ira->codegen->builtin_types.entry_invalid;
...@@ -18253,7 +18253,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt...@@ -18253,7 +18253,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt
18253 if (type_is_invalid(dest_type))18253 if (type_is_invalid(dest_type))
18254 return ira->codegen->builtin_types.entry_invalid;18254 return ira->codegen->builtin_types.entry_invalid;
1825518255
18256 if (dest_type->id != TypeTableEntryIdInt) {18256 if (dest_type->id != ZigTypeIdInt) {
18257 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));18257 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
18258 return ira->codegen->builtin_types.entry_invalid;18258 return ira->codegen->builtin_types.entry_invalid;
18259 }18259 }
...@@ -18262,7 +18262,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt...@@ -18262,7 +18262,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt
18262 if (type_is_invalid(target->value.type))18262 if (type_is_invalid(target->value.type))
18263 return ira->codegen->builtin_types.entry_invalid;18263 return ira->codegen->builtin_types.entry_invalid;
1826418264
18265 if (target->value.type->id == TypeTableEntryIdComptimeInt) {18265 if (target->value.type->id == ZigTypeIdComptimeInt) {
18266 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {18266 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
18267 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,18267 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,
18268 CastOpNumLitToConcrete, false);18268 CastOpNumLitToConcrete, false);
...@@ -18275,7 +18275,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt...@@ -18275,7 +18275,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt
18275 }18275 }
18276 }18276 }
1827718277
18278 if (target->value.type->id != TypeTableEntryIdInt) {18278 if (target->value.type->id != ZigTypeIdInt) {
18279 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",18279 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
18280 buf_ptr(&target->value.type->name)));18280 buf_ptr(&target->value.type->name)));
18281 return ira->codegen->builtin_types.entry_invalid;18281 return ira->codegen->builtin_types.entry_invalid;
...@@ -18294,7 +18294,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF...@@ -18294,7 +18294,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF
18294 if (type_is_invalid(dest_type))18294 if (type_is_invalid(dest_type))
18295 return ira->codegen->builtin_types.entry_invalid;18295 return ira->codegen->builtin_types.entry_invalid;
1829618296
18297 if (dest_type->id != TypeTableEntryIdFloat) {18297 if (dest_type->id != ZigTypeIdFloat) {
18298 ir_add_error(ira, instruction->dest_type,18298 ir_add_error(ira, instruction->dest_type,
18299 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));18299 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
18300 return ira->codegen->builtin_types.entry_invalid;18300 return ira->codegen->builtin_types.entry_invalid;
...@@ -18304,12 +18304,12 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF...@@ -18304,12 +18304,12 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF
18304 if (type_is_invalid(target->value.type))18304 if (type_is_invalid(target->value.type))
18305 return ira->codegen->builtin_types.entry_invalid;18305 return ira->codegen->builtin_types.entry_invalid;
1830618306
18307 if (target->value.type->id == TypeTableEntryIdComptimeInt ||18307 if (target->value.type->id == ZigTypeIdComptimeInt ||
18308 target->value.type->id == TypeTableEntryIdComptimeFloat)18308 target->value.type->id == ZigTypeIdComptimeFloat)
18309 {18309 {
18310 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {18310 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
18311 CastOp op;18311 CastOp op;
18312 if (target->value.type->id == TypeTableEntryIdComptimeInt) {18312 if (target->value.type->id == ZigTypeIdComptimeInt) {
18313 op = CastOpIntToFloat;18313 op = CastOpIntToFloat;
18314 } else {18314 } else {
18315 op = CastOpNumLitToConcrete;18315 op = CastOpNumLitToConcrete;
...@@ -18324,7 +18324,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF...@@ -18324,7 +18324,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF
18324 }18324 }
18325 }18325 }
1832618326
18327 if (target->value.type->id != TypeTableEntryIdFloat) {18327 if (target->value.type->id != ZigTypeIdFloat) {
18328 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",18328 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
18329 buf_ptr(&target->value.type->name)));18329 buf_ptr(&target->value.type->name)));
18330 return ira->codegen->builtin_types.entry_invalid;18330 return ira->codegen->builtin_types.entry_invalid;
...@@ -18342,7 +18342,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio...@@ -18342,7 +18342,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio
18342 if (type_is_invalid(dest_type))18342 if (type_is_invalid(dest_type))
18343 return ira->codegen->builtin_types.entry_invalid;18343 return ira->codegen->builtin_types.entry_invalid;
1834418344
18345 if (dest_type->id != TypeTableEntryIdErrorSet) {18345 if (dest_type->id != ZigTypeIdErrorSet) {
18346 ir_add_error(ira, instruction->dest_type,18346 ir_add_error(ira, instruction->dest_type,
18347 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));18347 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
18348 return ira->codegen->builtin_types.entry_invalid;18348 return ira->codegen->builtin_types.entry_invalid;
...@@ -18352,7 +18352,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio...@@ -18352,7 +18352,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio
18352 if (type_is_invalid(target->value.type))18352 if (type_is_invalid(target->value.type))
18353 return ira->codegen->builtin_types.entry_invalid;18353 return ira->codegen->builtin_types.entry_invalid;
1835418354
18355 if (target->value.type->id != TypeTableEntryIdErrorSet) {18355 if (target->value.type->id != ZigTypeIdErrorSet) {
18356 ir_add_error(ira, instruction->target,18356 ir_add_error(ira, instruction->target,
18357 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));18357 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));
18358 return ira->codegen->builtin_types.entry_invalid;18358 return ira->codegen->builtin_types.entry_invalid;
...@@ -18377,7 +18377,7 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF...@@ -18377,7 +18377,7 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF
18377 bool src_ptr_const;18377 bool src_ptr_const;
18378 bool src_ptr_volatile;18378 bool src_ptr_volatile;
18379 uint32_t src_ptr_align;18379 uint32_t src_ptr_align;
18380 if (target->value.type->id == TypeTableEntryIdPointer) {18380 if (target->value.type->id == ZigTypeIdPointer) {
18381 src_ptr_const = target->value.type->data.pointer.is_const;18381 src_ptr_const = target->value.type->data.pointer.is_const;
18382 src_ptr_volatile = target->value.type->data.pointer.is_volatile;18382 src_ptr_volatile = target->value.type->data.pointer.is_volatile;
18383 src_ptr_align = target->value.type->data.pointer.alignment;18383 src_ptr_align = target->value.type->data.pointer.alignment;
...@@ -18477,7 +18477,7 @@ static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructio...@@ -18477,7 +18477,7 @@ static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructio
18477 if (type_is_invalid(target->value.type))18477 if (type_is_invalid(target->value.type))
18478 return ira->codegen->builtin_types.entry_invalid;18478 return ira->codegen->builtin_types.entry_invalid;
1847918479
18480 if (target->value.type->id != TypeTableEntryIdInt && target->value.type->id != TypeTableEntryIdComptimeInt) {18480 if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) {
18481 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",18481 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
18482 buf_ptr(&target->value.type->name)));18482 buf_ptr(&target->value.type->name)));
18483 return ira->codegen->builtin_types.entry_invalid;18483 return ira->codegen->builtin_types.entry_invalid;
...@@ -18497,7 +18497,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio...@@ -18497,7 +18497,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio
18497 if (type_is_invalid(target->value.type))18497 if (type_is_invalid(target->value.type))
18498 return ira->codegen->builtin_types.entry_invalid;18498 return ira->codegen->builtin_types.entry_invalid;
1849918499
18500 if (target->value.type->id == TypeTableEntryIdComptimeInt) {18500 if (target->value.type->id == ZigTypeIdComptimeInt) {
18501 IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type);18501 IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type);
18502 if (type_is_invalid(casted_value->value.type))18502 if (type_is_invalid(casted_value->value.type))
18503 return ira->codegen->builtin_types.entry_invalid;18503 return ira->codegen->builtin_types.entry_invalid;
...@@ -18505,7 +18505,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio...@@ -18505,7 +18505,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio
18505 return casted_value->value.type;18505 return casted_value->value.type;
18506 }18506 }
1850718507
18508 if (target->value.type->id != TypeTableEntryIdFloat && target->value.type->id != TypeTableEntryIdComptimeFloat) {18508 if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {
18509 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",18509 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
18510 buf_ptr(&target->value.type->name)));18510 buf_ptr(&target->value.type->name)));
18511 return ira->codegen->builtin_types.entry_invalid;18511 return ira->codegen->builtin_types.entry_invalid;
...@@ -18522,7 +18522,7 @@ static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionE...@@ -18522,7 +18522,7 @@ static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionE
18522 return ira->codegen->builtin_types.entry_invalid;18522 return ira->codegen->builtin_types.entry_invalid;
1852318523
18524 IrInstruction *casted_target;18524 IrInstruction *casted_target;
18525 if (target->value.type->id == TypeTableEntryIdErrorSet) {18525 if (target->value.type->id == ZigTypeIdErrorSet) {
18526 casted_target = target;18526 casted_target = target;
18527 } else {18527 } else {
18528 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);18528 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
...@@ -18554,7 +18554,7 @@ static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstruction...@@ -18554,7 +18554,7 @@ static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstruction
18554 if (type_is_invalid(target->value.type))18554 if (type_is_invalid(target->value.type))
18555 return ira->codegen->builtin_types.entry_invalid;18555 return ira->codegen->builtin_types.entry_invalid;
1855618556
18557 if (target->value.type->id != TypeTableEntryIdBool) {18557 if (target->value.type->id != ZigTypeIdBool) {
18558 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",18558 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
18559 buf_ptr(&target->value.type->name)));18559 buf_ptr(&target->value.type->name)));
18560 return ira->codegen->builtin_types.entry_invalid;18560 return ira->codegen->builtin_types.entry_invalid;
...@@ -18631,12 +18631,12 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse...@@ -18631,12 +18631,12 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse
18631 return ira->codegen->builtin_types.entry_invalid;18631 return ira->codegen->builtin_types.entry_invalid;
1863218632
18633 ZigType *dest_uncasted_type = dest_ptr->value.type;18633 ZigType *dest_uncasted_type = dest_ptr->value.type;
18634 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&18634 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
18635 dest_uncasted_type->data.pointer.is_volatile;18635 dest_uncasted_type->data.pointer.is_volatile;
1863618636
18637 ZigType *usize = ira->codegen->builtin_types.entry_usize;18637 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18638 ZigType *u8 = ira->codegen->builtin_types.entry_u8;18638 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18639 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?18639 uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
18640 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18640 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
18641 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,18641 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
18642 PtrLenUnknown, dest_align, 0, 0);18642 PtrLenUnknown, dest_align, 0, 0);
...@@ -18725,13 +18725,13 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp...@@ -18725,13 +18725,13 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp
18725 ZigType *u8 = ira->codegen->builtin_types.entry_u8;18725 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
18726 ZigType *dest_uncasted_type = dest_ptr->value.type;18726 ZigType *dest_uncasted_type = dest_ptr->value.type;
18727 ZigType *src_uncasted_type = src_ptr->value.type;18727 ZigType *src_uncasted_type = src_ptr->value.type;
18728 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&18728 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
18729 dest_uncasted_type->data.pointer.is_volatile;18729 dest_uncasted_type->data.pointer.is_volatile;
18730 bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) &&18730 bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&
18731 src_uncasted_type->data.pointer.is_volatile;18731 src_uncasted_type->data.pointer.is_volatile;
18732 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?18732 uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
18733 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18733 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
18734 uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ?18734 uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ?
18735 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);18735 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
1873618736
18737 ZigType *usize = ira->codegen->builtin_types.entry_usize;18737 ZigType *usize = ira->codegen->builtin_types.entry_usize;
...@@ -18850,7 +18850,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -18850,7 +18850,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
18850 return ira->codegen->builtin_types.entry_invalid;18850 return ira->codegen->builtin_types.entry_invalid;
1885118851
18852 ZigType *ptr_type = ptr_ptr->value.type;18852 ZigType *ptr_type = ptr_ptr->value.type;
18853 assert(ptr_type->id == TypeTableEntryIdPointer);18853 assert(ptr_type->id == ZigTypeIdPointer);
18854 ZigType *array_type = ptr_type->data.pointer.child_type;18854 ZigType *array_type = ptr_type->data.pointer.child_type;
1885518855
18856 IrInstruction *start = instruction->start->other;18856 IrInstruction *start = instruction->start->other;
...@@ -18876,7 +18876,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -18876,7 +18876,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
1887618876
18877 ZigType *return_type;18877 ZigType *return_type;
1887818878
18879 if (array_type->id == TypeTableEntryIdArray) {18879 if (array_type->id == ZigTypeIdArray) {
18880 uint32_t byte_alignment = ptr_type->data.pointer.alignment;18880 uint32_t byte_alignment = ptr_type->data.pointer.alignment;
18881 if (array_type->data.array.len == 0 && byte_alignment == 0) {18881 if (array_type->data.array.len == 0 && byte_alignment == 0) {
18882 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);18882 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
...@@ -18889,10 +18889,10 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -18889,10 +18889,10 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
18889 PtrLenUnknown,18889 PtrLenUnknown,
18890 byte_alignment, 0, 0);18890 byte_alignment, 0, 0);
18891 return_type = get_slice_type(ira->codegen, slice_ptr_type);18891 return_type = get_slice_type(ira->codegen, slice_ptr_type);
18892 } else if (array_type->id == TypeTableEntryIdPointer) {18892 } else if (array_type->id == ZigTypeIdPointer) {
18893 if (array_type->data.pointer.ptr_len == PtrLenSingle) {18893 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
18894 ZigType *main_type = array_type->data.pointer.child_type;18894 ZigType *main_type = array_type->data.pointer.child_type;
18895 if (main_type->id == TypeTableEntryIdArray) {18895 if (main_type->id == ZigTypeIdArray) {
18896 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,18896 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
18897 main_type->data.pointer.child_type,18897 main_type->data.pointer.child_type,
18898 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,18898 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
...@@ -18932,12 +18932,12 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -18932,12 +18932,12 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
18932 size_t abs_offset;18932 size_t abs_offset;
18933 size_t rel_end;18933 size_t rel_end;
18934 bool ptr_is_undef = false;18934 bool ptr_is_undef = false;
18935 if (array_type->id == TypeTableEntryIdArray ||18935 if (array_type->id == ZigTypeIdArray ||
18936 (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))18936 (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
18937 {18937 {
18938 if (array_type->id == TypeTableEntryIdPointer) {18938 if (array_type->id == ZigTypeIdPointer) {
18939 ZigType *child_array_type = array_type->data.pointer.child_type;18939 ZigType *child_array_type = array_type->data.pointer.child_type;
18940 assert(child_array_type->id == TypeTableEntryIdArray);18940 assert(child_array_type->id == ZigTypeIdArray);
18941 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18941 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18942 if (parent_ptr == nullptr)18942 if (parent_ptr == nullptr)
18943 return ira->codegen->builtin_types.entry_invalid;18943 return ira->codegen->builtin_types.entry_invalid;
...@@ -18956,7 +18956,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -18956,7 +18956,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
18956 parent_ptr = nullptr;18956 parent_ptr = nullptr;
18957 abs_offset = 0;18957 abs_offset = 0;
18958 }18958 }
18959 } else if (array_type->id == TypeTableEntryIdPointer) {18959 } else if (array_type->id == ZigTypeIdPointer) {
18960 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);18960 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
18961 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18961 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
18962 if (parent_ptr == nullptr)18962 if (parent_ptr == nullptr)
...@@ -19063,11 +19063,11 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice...@@ -19063,11 +19063,11 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice
19063 size_t index = abs_offset + start_scalar;19063 size_t index = abs_offset + start_scalar;
19064 bool is_const = slice_is_const(return_type);19064 bool is_const = slice_is_const(return_type);
19065 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);19065 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);
19066 if (array_type->id == TypeTableEntryIdArray) {19066 if (array_type->id == ZigTypeIdArray) {
19067 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;19067 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
19068 } else if (is_slice(array_type)) {19068 } else if (is_slice(array_type)) {
19069 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;19069 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
19070 } else if (array_type->id == TypeTableEntryIdPointer) {19070 } else if (array_type->id == ZigTypeIdPointer) {
19071 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;19071 ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
19072 }19072 }
19073 } else if (ptr_is_undef) {19073 } else if (ptr_is_undef) {
...@@ -19122,13 +19122,13 @@ static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructio...@@ -19122,13 +19122,13 @@ static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructio
19122 uint64_t result;19122 uint64_t result;
19123 if (type_is_invalid(container_type)) {19123 if (type_is_invalid(container_type)) {
19124 return ira->codegen->builtin_types.entry_invalid;19124 return ira->codegen->builtin_types.entry_invalid;
19125 } else if (container_type->id == TypeTableEntryIdEnum) {19125 } else if (container_type->id == ZigTypeIdEnum) {
19126 result = container_type->data.enumeration.src_field_count;19126 result = container_type->data.enumeration.src_field_count;
19127 } else if (container_type->id == TypeTableEntryIdStruct) {19127 } else if (container_type->id == ZigTypeIdStruct) {
19128 result = container_type->data.structure.src_field_count;19128 result = container_type->data.structure.src_field_count;
19129 } else if (container_type->id == TypeTableEntryIdUnion) {19129 } else if (container_type->id == ZigTypeIdUnion) {
19130 result = container_type->data.unionation.src_field_count;19130 result = container_type->data.unionation.src_field_count;
19131 } else if (container_type->id == TypeTableEntryIdErrorSet) {19131 } else if (container_type->id == ZigTypeIdErrorSet) {
19132 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {19132 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
19133 return ira->codegen->builtin_types.entry_invalid;19133 return ira->codegen->builtin_types.entry_invalid;
19134 }19134 }
...@@ -19163,7 +19163,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction...@@ -19163,7 +19163,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction
19163 if (!ir_resolve_usize(ira, index_value, &member_index))19163 if (!ir_resolve_usize(ira, index_value, &member_index))
19164 return ira->codegen->builtin_types.entry_invalid;19164 return ira->codegen->builtin_types.entry_invalid;
1916519165
19166 if (container_type->id == TypeTableEntryIdStruct) {19166 if (container_type->id == ZigTypeIdStruct) {
19167 if (member_index >= container_type->data.structure.src_field_count) {19167 if (member_index >= container_type->data.structure.src_field_count) {
19168 ir_add_error(ira, index_value,19168 ir_add_error(ira, index_value,
19169 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19169 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
...@@ -19175,7 +19175,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction...@@ -19175,7 +19175,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction
19175 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19175 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19176 out_val->data.x_type = field->type_entry;19176 out_val->data.x_type = field->type_entry;
19177 return ira->codegen->builtin_types.entry_type;19177 return ira->codegen->builtin_types.entry_type;
19178 } else if (container_type->id == TypeTableEntryIdUnion) {19178 } else if (container_type->id == ZigTypeIdUnion) {
19179 if (member_index >= container_type->data.unionation.src_field_count) {19179 if (member_index >= container_type->data.unionation.src_field_count) {
19180 ir_add_error(ira, index_value,19180 ir_add_error(ira, index_value,
19181 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19181 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
...@@ -19209,7 +19209,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction...@@ -19209,7 +19209,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction
19209 if (!ir_resolve_usize(ira, index_value, &member_index))19209 if (!ir_resolve_usize(ira, index_value, &member_index))
19210 return ira->codegen->builtin_types.entry_invalid;19210 return ira->codegen->builtin_types.entry_invalid;
1921119211
19212 if (container_type->id == TypeTableEntryIdStruct) {19212 if (container_type->id == ZigTypeIdStruct) {
19213 if (member_index >= container_type->data.structure.src_field_count) {19213 if (member_index >= container_type->data.structure.src_field_count) {
19214 ir_add_error(ira, index_value,19214 ir_add_error(ira, index_value,
19215 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19215 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
...@@ -19221,7 +19221,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction...@@ -19221,7 +19221,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction
19221 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19221 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19222 init_const_str_lit(ira->codegen, out_val, field->name);19222 init_const_str_lit(ira->codegen, out_val, field->name);
19223 return out_val->type;19223 return out_val->type;
19224 } else if (container_type->id == TypeTableEntryIdEnum) {19224 } else if (container_type->id == ZigTypeIdEnum) {
19225 if (member_index >= container_type->data.enumeration.src_field_count) {19225 if (member_index >= container_type->data.enumeration.src_field_count) {
19226 ir_add_error(ira, index_value,19226 ir_add_error(ira, index_value,
19227 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19227 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
...@@ -19233,7 +19233,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction...@@ -19233,7 +19233,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction
19233 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19233 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19234 init_const_str_lit(ira->codegen, out_val, field->name);19234 init_const_str_lit(ira->codegen, out_val, field->name);
19235 return out_val->type;19235 return out_val->type;
19236 } else if (container_type->id == TypeTableEntryIdUnion) {19236 } else if (container_type->id == ZigTypeIdUnion) {
19237 if (member_index >= container_type->data.unionation.src_field_count) {19237 if (member_index >= container_type->data.unionation.src_field_count) {
19238 ir_add_error(ira, index_value,19238 ir_add_error(ira, index_value,
19239 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",19239 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
...@@ -19292,36 +19292,36 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli...@@ -19292,36 +19292,36 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli
19292 return ira->codegen->builtin_types.entry_invalid;19292 return ira->codegen->builtin_types.entry_invalid;
1929319293
19294 switch (type_entry->id) {19294 switch (type_entry->id) {
19295 case TypeTableEntryIdInvalid:19295 case ZigTypeIdInvalid:
19296 zig_unreachable();19296 zig_unreachable();
19297 case TypeTableEntryIdMetaType:19297 case ZigTypeIdMetaType:
19298 case TypeTableEntryIdUnreachable:19298 case ZigTypeIdUnreachable:
19299 case TypeTableEntryIdComptimeFloat:19299 case ZigTypeIdComptimeFloat:
19300 case TypeTableEntryIdComptimeInt:19300 case ZigTypeIdComptimeInt:
19301 case TypeTableEntryIdUndefined:19301 case ZigTypeIdUndefined:
19302 case TypeTableEntryIdNull:19302 case ZigTypeIdNull:
19303 case TypeTableEntryIdNamespace:19303 case ZigTypeIdNamespace:
19304 case TypeTableEntryIdBlock:19304 case ZigTypeIdBlock:
19305 case TypeTableEntryIdBoundFn:19305 case ZigTypeIdBoundFn:
19306 case TypeTableEntryIdArgTuple:19306 case ZigTypeIdArgTuple:
19307 case TypeTableEntryIdVoid:19307 case ZigTypeIdVoid:
19308 case TypeTableEntryIdOpaque:19308 case ZigTypeIdOpaque:
19309 ir_add_error(ira, instruction->type_value,19309 ir_add_error(ira, instruction->type_value,
19310 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));19310 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
19311 return ira->codegen->builtin_types.entry_invalid;19311 return ira->codegen->builtin_types.entry_invalid;
19312 case TypeTableEntryIdBool:19312 case ZigTypeIdBool:
19313 case TypeTableEntryIdInt:19313 case ZigTypeIdInt:
19314 case TypeTableEntryIdFloat:19314 case ZigTypeIdFloat:
19315 case TypeTableEntryIdPointer:19315 case ZigTypeIdPointer:
19316 case TypeTableEntryIdPromise:19316 case ZigTypeIdPromise:
19317 case TypeTableEntryIdArray:19317 case ZigTypeIdArray:
19318 case TypeTableEntryIdStruct:19318 case ZigTypeIdStruct:
19319 case TypeTableEntryIdOptional:19319 case ZigTypeIdOptional:
19320 case TypeTableEntryIdErrorUnion:19320 case ZigTypeIdErrorUnion:
19321 case TypeTableEntryIdErrorSet:19321 case ZigTypeIdErrorSet:
19322 case TypeTableEntryIdEnum:19322 case ZigTypeIdEnum:
19323 case TypeTableEntryIdUnion:19323 case ZigTypeIdUnion:
19324 case TypeTableEntryIdFn:19324 case ZigTypeIdFn:
19325 {19325 {
19326 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);19326 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);
19327 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19327 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -19341,7 +19341,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction...@@ -19341,7 +19341,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction
19341 if (type_is_invalid(dest_type))19341 if (type_is_invalid(dest_type))
19342 return ira->codegen->builtin_types.entry_invalid;19342 return ira->codegen->builtin_types.entry_invalid;
1934319343
19344 if (dest_type->id != TypeTableEntryIdInt) {19344 if (dest_type->id != ZigTypeIdInt) {
19345 ir_add_error(ira, type_value,19345 ir_add_error(ira, type_value,
19346 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));19346 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19347 return ira->codegen->builtin_types.entry_invalid;19347 return ira->codegen->builtin_types.entry_invalid;
...@@ -19375,7 +19375,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction...@@ -19375,7 +19375,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction
19375 return ira->codegen->builtin_types.entry_invalid;19375 return ira->codegen->builtin_types.entry_invalid;
1937619376
19377 ZigType *expected_ptr_type;19377 ZigType *expected_ptr_type;
19378 if (result_ptr->value.type->id == TypeTableEntryIdPointer) {19378 if (result_ptr->value.type->id == ZigTypeIdPointer) {
19379 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,19379 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
19380 false, result_ptr->value.type->data.pointer.is_volatile,19380 false, result_ptr->value.type->data.pointer.is_volatile,
19381 PtrLenSingle,19381 PtrLenSingle,
...@@ -19439,7 +19439,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes...@@ -19439,7 +19439,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes
19439 ZigType *type_entry = value->value.type;19439 ZigType *type_entry = value->value.type;
19440 if (type_is_invalid(type_entry)) {19440 if (type_is_invalid(type_entry)) {
19441 return ira->codegen->builtin_types.entry_invalid;19441 return ira->codegen->builtin_types.entry_invalid;
19442 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19442 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19443 if (instr_is_comptime(value)) {19443 if (instr_is_comptime(value)) {
19444 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);19444 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
19445 if (!err_union_val)19445 if (!err_union_val)
...@@ -19467,7 +19467,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes...@@ -19467,7 +19467,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes
1946719467
19468 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);19468 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
19469 return ira->codegen->builtin_types.entry_bool;19469 return ira->codegen->builtin_types.entry_bool;
19470 } else if (type_entry->id == TypeTableEntryIdErrorSet) {19470 } else if (type_entry->id == ZigTypeIdErrorSet) {
19471 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);19471 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
19472 out_val->data.x_bool = true;19472 out_val->data.x_bool = true;
19473 return ira->codegen->builtin_types.entry_bool;19473 return ira->codegen->builtin_types.entry_bool;
...@@ -19487,12 +19487,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -19487,12 +19487,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
19487 ZigType *ptr_type = value->value.type;19487 ZigType *ptr_type = value->value.type;
1948819488
19489 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.19489 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
19490 assert(ptr_type->id == TypeTableEntryIdPointer);19490 assert(ptr_type->id == ZigTypeIdPointer);
1949119491
19492 ZigType *type_entry = ptr_type->data.pointer.child_type;19492 ZigType *type_entry = ptr_type->data.pointer.child_type;
19493 if (type_is_invalid(type_entry)) {19493 if (type_is_invalid(type_entry)) {
19494 return ira->codegen->builtin_types.entry_invalid;19494 return ira->codegen->builtin_types.entry_invalid;
19495 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19495 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19496 if (instr_is_comptime(value)) {19496 if (instr_is_comptime(value)) {
19497 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);19497 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
19498 if (!ptr_val)19498 if (!ptr_val)
...@@ -19529,12 +19529,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -19529,12 +19529,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
19529 ZigType *ptr_type = value->value.type;19529 ZigType *ptr_type = value->value.type;
1953019530
19531 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.19531 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
19532 assert(ptr_type->id == TypeTableEntryIdPointer);19532 assert(ptr_type->id == ZigTypeIdPointer);
1953319533
19534 ZigType *type_entry = ptr_type->data.pointer.child_type;19534 ZigType *type_entry = ptr_type->data.pointer.child_type;
19535 if (type_is_invalid(type_entry)) {19535 if (type_is_invalid(type_entry)) {
19536 return ira->codegen->builtin_types.entry_invalid;19536 return ira->codegen->builtin_types.entry_invalid;
19537 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {19537 } else if (type_entry->id == ZigTypeIdErrorUnion) {
19538 ZigType *payload_type = type_entry->data.error_union.payload_type;19538 ZigType *payload_type = type_entry->data.error_union.payload_type;
19539 if (type_is_invalid(payload_type)) {19539 if (type_is_invalid(payload_type)) {
19540 return ira->codegen->builtin_types.entry_invalid;19540 return ira->codegen->builtin_types.entry_invalid;
...@@ -19633,7 +19633,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP...@@ -19633,7 +19633,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP
19633 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);19633 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
19634 if (type_is_invalid(fn_type_id.return_type))19634 if (type_is_invalid(fn_type_id.return_type))
19635 return ira->codegen->builtin_types.entry_invalid;19635 return ira->codegen->builtin_types.entry_invalid;
19636 if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) {19636 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
19637 ir_add_error(ira, instruction->return_type,19637 ir_add_error(ira, instruction->return_type,
19638 buf_sprintf("return type cannot be opaque"));19638 buf_sprintf("return type cannot be opaque"));
19639 return ira->codegen->builtin_types.entry_invalid;19639 return ira->codegen->builtin_types.entry_invalid;
...@@ -19674,7 +19674,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19674,7 +19674,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19674 if (type_is_invalid(switch_type))19674 if (type_is_invalid(switch_type))
19675 return ira->codegen->builtin_types.entry_invalid;19675 return ira->codegen->builtin_types.entry_invalid;
1967619676
19677 if (switch_type->id == TypeTableEntryIdEnum) {19677 if (switch_type->id == ZigTypeIdEnum) {
19678 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};19678 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
19679 field_prev_uses.init(switch_type->data.enumeration.src_field_count);19679 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
1968019680
...@@ -19689,7 +19689,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19689,7 +19689,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19689 if (type_is_invalid(end_value->value.type))19689 if (type_is_invalid(end_value->value.type))
19690 return ira->codegen->builtin_types.entry_invalid;19690 return ira->codegen->builtin_types.entry_invalid;
1969119691
19692 if (start_value->value.type->id != TypeTableEntryIdEnum) {19692 if (start_value->value.type->id != ZigTypeIdEnum) {
19693 ir_add_error(ira, range->start, buf_sprintf("not an enum type"));19693 ir_add_error(ira, range->start, buf_sprintf("not an enum type"));
19694 return ira->codegen->builtin_types.entry_invalid;19694 return ira->codegen->builtin_types.entry_invalid;
19695 }19695 }
...@@ -19697,7 +19697,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19697,7 +19697,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19697 BigInt start_index;19697 BigInt start_index;
19698 bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);19698 bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);
1969919699
19700 assert(end_value->value.type->id == TypeTableEntryIdEnum);19700 assert(end_value->value.type->id == ZigTypeIdEnum);
19701 BigInt end_index;19701 BigInt end_index;
19702 bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);19702 bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);
1970319703
...@@ -19733,7 +19733,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19733,7 +19733,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19733 }19733 }
19734 }19734 }
19735 }19735 }
19736 } else if (switch_type->id == TypeTableEntryIdErrorSet) {19736 } else if (switch_type->id == ZigTypeIdErrorSet) {
19737 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {19737 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
19738 return ira->codegen->builtin_types.entry_invalid;19738 return ira->codegen->builtin_types.entry_invalid;
19739 }19739 }
...@@ -19751,10 +19751,10 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19751,10 +19751,10 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19751 if (type_is_invalid(end_value->value.type))19751 if (type_is_invalid(end_value->value.type))
19752 return ira->codegen->builtin_types.entry_invalid;19752 return ira->codegen->builtin_types.entry_invalid;
1975319753
19754 assert(start_value->value.type->id == TypeTableEntryIdErrorSet);19754 assert(start_value->value.type->id == ZigTypeIdErrorSet);
19755 uint32_t start_index = start_value->value.data.x_err_set->value;19755 uint32_t start_index = start_value->value.data.x_err_set->value;
1975619756
19757 assert(end_value->value.type->id == TypeTableEntryIdErrorSet);19757 assert(end_value->value.type->id == ZigTypeIdErrorSet);
19758 uint32_t end_index = end_value->value.data.x_err_set->value;19758 uint32_t end_index = end_value->value.data.x_err_set->value;
1975919759
19760 if (start_index != end_index) {19760 if (start_index != end_index) {
...@@ -19790,7 +19790,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19790,7 +19790,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19790 }19790 }
1979119791
19792 free(field_prev_uses);19792 free(field_prev_uses);
19793 } else if (switch_type->id == TypeTableEntryIdInt) {19793 } else if (switch_type->id == ZigTypeIdInt) {
19794 RangeSet rs = {0};19794 RangeSet rs = {0};
19795 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {19795 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
19796 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];19796 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
...@@ -19817,8 +19817,8 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19817,8 +19817,8 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19817 if (!end_val)19817 if (!end_val)
19818 return ira->codegen->builtin_types.entry_invalid;19818 return ira->codegen->builtin_types.entry_invalid;
1981919819
19820 assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);19820 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
19821 assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);19821 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
19822 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,19822 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
19823 start_value->source_node);19823 start_value->source_node);
19824 if (prev_node != nullptr) {19824 if (prev_node != nullptr) {
...@@ -19854,7 +19854,7 @@ static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,...@@ -19854,7 +19854,7 @@ static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
19854 if (type_is_invalid(statement_type))19854 if (type_is_invalid(statement_type))
19855 return ira->codegen->builtin_types.entry_invalid;19855 return ira->codegen->builtin_types.entry_invalid;
1985619856
19857 if (statement_type->id != TypeTableEntryIdVoid) {19857 if (statement_type->id != ZigTypeIdVoid) {
19858 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));19858 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
19859 }19859 }
1986019860
...@@ -19892,24 +19892,24 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -19892,24 +19892,24 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
19892 ZigType *result_type;19892 ZigType *result_type;
19893 uint32_t old_align_bytes;19893 uint32_t old_align_bytes;
1989419894
19895 if (target_type->id == TypeTableEntryIdPointer) {19895 if (target_type->id == ZigTypeIdPointer) {
19896 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);19896 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
19897 old_align_bytes = target_type->data.pointer.alignment;19897 old_align_bytes = target_type->data.pointer.alignment;
19898 } else if (target_type->id == TypeTableEntryIdFn) {19898 } else if (target_type->id == ZigTypeIdFn) {
19899 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;19899 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
19900 old_align_bytes = fn_type_id.alignment;19900 old_align_bytes = fn_type_id.alignment;
19901 fn_type_id.alignment = align_bytes;19901 fn_type_id.alignment = align_bytes;
19902 result_type = get_fn_type(ira->codegen, &fn_type_id);19902 result_type = get_fn_type(ira->codegen, &fn_type_id);
19903 } else if (target_type->id == TypeTableEntryIdOptional &&19903 } else if (target_type->id == ZigTypeIdOptional &&
19904 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)19904 target_type->data.maybe.child_type->id == ZigTypeIdPointer)
19905 {19905 {
19906 ZigType *ptr_type = target_type->data.maybe.child_type;19906 ZigType *ptr_type = target_type->data.maybe.child_type;
19907 old_align_bytes = ptr_type->data.pointer.alignment;19907 old_align_bytes = ptr_type->data.pointer.alignment;
19908 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);19908 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
1990919909
19910 result_type = get_optional_type(ira->codegen, better_ptr_type);19910 result_type = get_optional_type(ira->codegen, better_ptr_type);
19911 } else if (target_type->id == TypeTableEntryIdOptional &&19911 } else if (target_type->id == ZigTypeIdOptional &&
19912 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)19912 target_type->data.maybe.child_type->id == ZigTypeIdFn)
19913 {19913 {
19914 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;19914 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;
19915 old_align_bytes = fn_type_id.alignment;19915 old_align_bytes = fn_type_id.alignment;
...@@ -20033,33 +20033,33 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr...@@ -20033,33 +20033,33 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr
20033static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {20033static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
20034 assert(val->special == ConstValSpecialStatic);20034 assert(val->special == ConstValSpecialStatic);
20035 switch (val->type->id) {20035 switch (val->type->id) {
20036 case TypeTableEntryIdInvalid:20036 case ZigTypeIdInvalid:
20037 case TypeTableEntryIdMetaType:20037 case ZigTypeIdMetaType:
20038 case TypeTableEntryIdOpaque:20038 case ZigTypeIdOpaque:
20039 case TypeTableEntryIdBoundFn:20039 case ZigTypeIdBoundFn:
20040 case TypeTableEntryIdArgTuple:20040 case ZigTypeIdArgTuple:
20041 case TypeTableEntryIdNamespace:20041 case ZigTypeIdNamespace:
20042 case TypeTableEntryIdBlock:20042 case ZigTypeIdBlock:
20043 case TypeTableEntryIdUnreachable:20043 case ZigTypeIdUnreachable:
20044 case TypeTableEntryIdComptimeFloat:20044 case ZigTypeIdComptimeFloat:
20045 case TypeTableEntryIdComptimeInt:20045 case ZigTypeIdComptimeInt:
20046 case TypeTableEntryIdUndefined:20046 case ZigTypeIdUndefined:
20047 case TypeTableEntryIdNull:20047 case ZigTypeIdNull:
20048 case TypeTableEntryIdPromise:20048 case ZigTypeIdPromise:
20049 zig_unreachable();20049 zig_unreachable();
20050 case TypeTableEntryIdVoid:20050 case ZigTypeIdVoid:
20051 return;20051 return;
20052 case TypeTableEntryIdBool:20052 case ZigTypeIdBool:
20053 buf[0] = val->data.x_bool ? 1 : 0;20053 buf[0] = val->data.x_bool ? 1 : 0;
20054 return;20054 return;
20055 case TypeTableEntryIdInt:20055 case ZigTypeIdInt:
20056 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20056 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
20057 codegen->is_big_endian);20057 codegen->is_big_endian);
20058 return;20058 return;
20059 case TypeTableEntryIdFloat:20059 case ZigTypeIdFloat:
20060 float_write_ieee597(val, buf, codegen->is_big_endian);20060 float_write_ieee597(val, buf, codegen->is_big_endian);
20061 return;20061 return;
20062 case TypeTableEntryIdPointer:20062 case ZigTypeIdPointer:
20063 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {20063 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
20064 BigInt bn;20064 BigInt bn;
20065 bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr);20065 bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr);
...@@ -20068,7 +20068,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20068,7 +20068,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20068 } else {20068 } else {
20069 zig_unreachable();20069 zig_unreachable();
20070 }20070 }
20071 case TypeTableEntryIdArray:20071 case ZigTypeIdArray:
20072 {20072 {
20073 size_t buf_i = 0;20073 size_t buf_i = 0;
20074 expand_undef_array(codegen, val);20074 expand_undef_array(codegen, val);
...@@ -20079,19 +20079,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20079,19 +20079,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20079 }20079 }
20080 }20080 }
20081 return;20081 return;
20082 case TypeTableEntryIdStruct:20082 case ZigTypeIdStruct:
20083 zig_panic("TODO buf_write_value_bytes struct type");20083 zig_panic("TODO buf_write_value_bytes struct type");
20084 case TypeTableEntryIdOptional:20084 case ZigTypeIdOptional:
20085 zig_panic("TODO buf_write_value_bytes maybe type");20085 zig_panic("TODO buf_write_value_bytes maybe type");
20086 case TypeTableEntryIdErrorUnion:20086 case ZigTypeIdErrorUnion:
20087 zig_panic("TODO buf_write_value_bytes error union");20087 zig_panic("TODO buf_write_value_bytes error union");
20088 case TypeTableEntryIdErrorSet:20088 case ZigTypeIdErrorSet:
20089 zig_panic("TODO buf_write_value_bytes pure error type");20089 zig_panic("TODO buf_write_value_bytes pure error type");
20090 case TypeTableEntryIdEnum:20090 case ZigTypeIdEnum:
20091 zig_panic("TODO buf_write_value_bytes enum type");20091 zig_panic("TODO buf_write_value_bytes enum type");
20092 case TypeTableEntryIdFn:20092 case ZigTypeIdFn:
20093 zig_panic("TODO buf_write_value_bytes fn type");20093 zig_panic("TODO buf_write_value_bytes fn type");
20094 case TypeTableEntryIdUnion:20094 case ZigTypeIdUnion:
20095 zig_panic("TODO buf_write_value_bytes union type");20095 zig_panic("TODO buf_write_value_bytes union type");
20096 }20096 }
20097 zig_unreachable();20097 zig_unreachable();
...@@ -20100,33 +20100,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20100,33 +20100,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20100static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {20100static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
20101 assert(val->special == ConstValSpecialStatic);20101 assert(val->special == ConstValSpecialStatic);
20102 switch (val->type->id) {20102 switch (val->type->id) {
20103 case TypeTableEntryIdInvalid:20103 case ZigTypeIdInvalid:
20104 case TypeTableEntryIdMetaType:20104 case ZigTypeIdMetaType:
20105 case TypeTableEntryIdOpaque:20105 case ZigTypeIdOpaque:
20106 case TypeTableEntryIdBoundFn:20106 case ZigTypeIdBoundFn:
20107 case TypeTableEntryIdArgTuple:20107 case ZigTypeIdArgTuple:
20108 case TypeTableEntryIdNamespace:20108 case ZigTypeIdNamespace:
20109 case TypeTableEntryIdBlock:20109 case ZigTypeIdBlock:
20110 case TypeTableEntryIdUnreachable:20110 case ZigTypeIdUnreachable:
20111 case TypeTableEntryIdComptimeFloat:20111 case ZigTypeIdComptimeFloat:
20112 case TypeTableEntryIdComptimeInt:20112 case ZigTypeIdComptimeInt:
20113 case TypeTableEntryIdUndefined:20113 case ZigTypeIdUndefined:
20114 case TypeTableEntryIdNull:20114 case ZigTypeIdNull:
20115 case TypeTableEntryIdPromise:20115 case ZigTypeIdPromise:
20116 zig_unreachable();20116 zig_unreachable();
20117 case TypeTableEntryIdVoid:20117 case ZigTypeIdVoid:
20118 return;20118 return;
20119 case TypeTableEntryIdBool:20119 case ZigTypeIdBool:
20120 val->data.x_bool = (buf[0] != 0);20120 val->data.x_bool = (buf[0] != 0);
20121 return;20121 return;
20122 case TypeTableEntryIdInt:20122 case ZigTypeIdInt:
20123 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20123 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
20124 codegen->is_big_endian, val->type->data.integral.is_signed);20124 codegen->is_big_endian, val->type->data.integral.is_signed);
20125 return;20125 return;
20126 case TypeTableEntryIdFloat:20126 case ZigTypeIdFloat:
20127 float_read_ieee597(val, buf, codegen->is_big_endian);20127 float_read_ieee597(val, buf, codegen->is_big_endian);
20128 return;20128 return;
20129 case TypeTableEntryIdPointer:20129 case ZigTypeIdPointer:
20130 {20130 {
20131 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;20131 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
20132 BigInt bn;20132 BigInt bn;
...@@ -20135,21 +20135,21 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20135,21 +20135,21 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20135 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);20135 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
20136 return;20136 return;
20137 }20137 }
20138 case TypeTableEntryIdArray:20138 case ZigTypeIdArray:
20139 zig_panic("TODO buf_read_value_bytes array type");20139 zig_panic("TODO buf_read_value_bytes array type");
20140 case TypeTableEntryIdStruct:20140 case ZigTypeIdStruct:
20141 zig_panic("TODO buf_read_value_bytes struct type");20141 zig_panic("TODO buf_read_value_bytes struct type");
20142 case TypeTableEntryIdOptional:20142 case ZigTypeIdOptional:
20143 zig_panic("TODO buf_read_value_bytes maybe type");20143 zig_panic("TODO buf_read_value_bytes maybe type");
20144 case TypeTableEntryIdErrorUnion:20144 case ZigTypeIdErrorUnion:
20145 zig_panic("TODO buf_read_value_bytes error union");20145 zig_panic("TODO buf_read_value_bytes error union");
20146 case TypeTableEntryIdErrorSet:20146 case ZigTypeIdErrorSet:
20147 zig_panic("TODO buf_read_value_bytes pure error type");20147 zig_panic("TODO buf_read_value_bytes pure error type");
20148 case TypeTableEntryIdEnum:20148 case ZigTypeIdEnum:
20149 zig_panic("TODO buf_read_value_bytes enum type");20149 zig_panic("TODO buf_read_value_bytes enum type");
20150 case TypeTableEntryIdFn:20150 case ZigTypeIdFn:
20151 zig_panic("TODO buf_read_value_bytes fn type");20151 zig_panic("TODO buf_read_value_bytes fn type");
20152 case TypeTableEntryIdUnion:20152 case ZigTypeIdUnion:
20153 zig_panic("TODO buf_read_value_bytes union type");20153 zig_panic("TODO buf_read_value_bytes union type");
20154 }20154 }
20155 zig_unreachable();20155 zig_unreachable();
...@@ -20180,18 +20180,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit...@@ -20180,18 +20180,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit
20180 }20180 }
2018120181
20182 switch (src_type->id) {20182 switch (src_type->id) {
20183 case TypeTableEntryIdInvalid:20183 case ZigTypeIdInvalid:
20184 case TypeTableEntryIdMetaType:20184 case ZigTypeIdMetaType:
20185 case TypeTableEntryIdOpaque:20185 case ZigTypeIdOpaque:
20186 case TypeTableEntryIdBoundFn:20186 case ZigTypeIdBoundFn:
20187 case TypeTableEntryIdArgTuple:20187 case ZigTypeIdArgTuple:
20188 case TypeTableEntryIdNamespace:20188 case ZigTypeIdNamespace:
20189 case TypeTableEntryIdBlock:20189 case ZigTypeIdBlock:
20190 case TypeTableEntryIdUnreachable:20190 case ZigTypeIdUnreachable:
20191 case TypeTableEntryIdComptimeFloat:20191 case ZigTypeIdComptimeFloat:
20192 case TypeTableEntryIdComptimeInt:20192 case ZigTypeIdComptimeInt:
20193 case TypeTableEntryIdUndefined:20193 case ZigTypeIdUndefined:
20194 case TypeTableEntryIdNull:20194 case ZigTypeIdNull:
20195 ir_add_error(ira, dest_type_value,20195 ir_add_error(ira, dest_type_value,
20196 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));20196 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
20197 return ira->codegen->builtin_types.entry_invalid;20197 return ira->codegen->builtin_types.entry_invalid;
...@@ -20206,18 +20206,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit...@@ -20206,18 +20206,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit
20206 }20206 }
2020720207
20208 switch (dest_type->id) {20208 switch (dest_type->id) {
20209 case TypeTableEntryIdInvalid:20209 case ZigTypeIdInvalid:
20210 case TypeTableEntryIdMetaType:20210 case ZigTypeIdMetaType:
20211 case TypeTableEntryIdOpaque:20211 case ZigTypeIdOpaque:
20212 case TypeTableEntryIdBoundFn:20212 case ZigTypeIdBoundFn:
20213 case TypeTableEntryIdArgTuple:20213 case ZigTypeIdArgTuple:
20214 case TypeTableEntryIdNamespace:20214 case ZigTypeIdNamespace:
20215 case TypeTableEntryIdBlock:20215 case ZigTypeIdBlock:
20216 case TypeTableEntryIdUnreachable:20216 case ZigTypeIdUnreachable:
20217 case TypeTableEntryIdComptimeFloat:20217 case ZigTypeIdComptimeFloat:
20218 case TypeTableEntryIdComptimeInt:20218 case ZigTypeIdComptimeInt:
20219 case TypeTableEntryIdUndefined:20219 case ZigTypeIdUndefined:
20220 case TypeTableEntryIdNull:20220 case ZigTypeIdNull:
20221 ir_add_error(ira, dest_type_value,20221 ir_add_error(ira, dest_type_value,
20222 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));20222 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
20223 return ira->codegen->builtin_types.entry_invalid;20223 return ira->codegen->builtin_types.entry_invalid;
...@@ -20384,7 +20384,7 @@ static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionP...@@ -20384,7 +20384,7 @@ static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionP
20384 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);20384 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
20385 if (!val)20385 if (!val)
20386 return ira->codegen->builtin_types.entry_invalid;20386 return ira->codegen->builtin_types.entry_invalid;
20387 if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {20387 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
20388 IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,20388 IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,
20389 instruction->base.source_node, usize);20389 instruction->base.source_node, usize);
20390 bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);20390 bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
...@@ -20406,10 +20406,10 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr...@@ -20406,10 +20406,10 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr
20406 if (type_is_invalid(child_type))20406 if (type_is_invalid(child_type))
20407 return ira->codegen->builtin_types.entry_invalid;20407 return ira->codegen->builtin_types.entry_invalid;
2040820408
20409 if (child_type->id == TypeTableEntryIdUnreachable) {20409 if (child_type->id == ZigTypeIdUnreachable) {
20410 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));20410 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
20411 return ira->codegen->builtin_types.entry_invalid;20411 return ira->codegen->builtin_types.entry_invalid;
20412 } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) {20412 } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) {
20413 ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));20413 ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));
20414 return ira->codegen->builtin_types.entry_invalid;20414 return ira->codegen->builtin_types.entry_invalid;
20415 }20415 }
...@@ -20510,7 +20510,7 @@ static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArg...@@ -20510,7 +20510,7 @@ static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArg
20510 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))20510 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
20511 return ira->codegen->builtin_types.entry_invalid;20511 return ira->codegen->builtin_types.entry_invalid;
2051220512
20513 if (fn_type->id != TypeTableEntryIdFn) {20513 if (fn_type->id != ZigTypeIdFn) {
20514 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));20514 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
20515 return ira->codegen->builtin_types.entry_invalid;20515 return ira->codegen->builtin_types.entry_invalid;
20516 }20516 }
...@@ -20545,14 +20545,14 @@ static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTag...@@ -20545,14 +20545,14 @@ static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTag
20545 if (type_is_invalid(enum_type))20545 if (type_is_invalid(enum_type))
20546 return ira->codegen->builtin_types.entry_invalid;20546 return ira->codegen->builtin_types.entry_invalid;
2054720547
20548 if (enum_type->id == TypeTableEntryIdEnum) {20548 if (enum_type->id == ZigTypeIdEnum) {
20549 if ((err = ensure_complete_type(ira->codegen, enum_type)))20549 if ((err = ensure_complete_type(ira->codegen, enum_type)))
20550 return ira->codegen->builtin_types.entry_invalid;20550 return ira->codegen->builtin_types.entry_invalid;
2055120551
20552 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);20552 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
20553 out_val->data.x_type = enum_type->data.enumeration.tag_int_type;20553 out_val->data.x_type = enum_type->data.enumeration.tag_int_type;
20554 return ira->codegen->builtin_types.entry_type;20554 return ira->codegen->builtin_types.entry_type;
20555 } else if (enum_type->id == TypeTableEntryIdUnion) {20555 } else if (enum_type->id == ZigTypeIdUnion) {
20556 if ((err = ensure_complete_type(ira->codegen, enum_type)))20556 if ((err = ensure_complete_type(ira->codegen, enum_type)))
20557 return ira->codegen->builtin_types.entry_invalid;20557 return ira->codegen->builtin_types.entry_invalid;
2055820558
...@@ -20734,7 +20734,7 @@ static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructio...@@ -20734,7 +20734,7 @@ static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructio
20734 if (type_is_invalid(coro_handle->value.type))20734 if (type_is_invalid(coro_handle->value.type))
20735 return ira->codegen->builtin_types.entry_invalid;20735 return ira->codegen->builtin_types.entry_invalid;
2073620736
20737 if (coro_handle->value.type->id != TypeTableEntryIdPromise ||20737 if (coro_handle->value.type->id != ZigTypeIdPromise ||
20738 coro_handle->value.type->data.promise.result_type == nullptr)20738 coro_handle->value.type->data.promise.result_type == nullptr)
20739 {20739 {
20740 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20740 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
...@@ -20774,7 +20774,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op...@@ -20774,7 +20774,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
20774 if (type_is_invalid(operand_type))20774 if (type_is_invalid(operand_type))
20775 return ira->codegen->builtin_types.entry_invalid;20775 return ira->codegen->builtin_types.entry_invalid;
2077620776
20777 if (operand_type->id == TypeTableEntryIdInt) {20777 if (operand_type->id == ZigTypeIdInt) {
20778 if (operand_type->data.integral.bit_count < 8) {20778 if (operand_type->data.integral.bit_count < 8) {
20779 ir_add_error(ira, op,20779 ir_add_error(ira, op,
20780 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",20780 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
...@@ -20907,7 +20907,7 @@ static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrIns...@@ -20907,7 +20907,7 @@ static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrIns
20907 if (type_is_invalid(promise_type))20907 if (type_is_invalid(promise_type))
20908 return ira->codegen->builtin_types.entry_invalid;20908 return ira->codegen->builtin_types.entry_invalid;
2090920909
20910 if (promise_type->id != TypeTableEntryIdPromise || promise_type->data.promise.result_type == nullptr) {20910 if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
20911 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",20911 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
20912 buf_ptr(&promise_type->name)));20912 buf_ptr(&promise_type->name)));
20913 return ira->codegen->builtin_types.entry_invalid;20913 return ira->codegen->builtin_types.entry_invalid;
...@@ -20942,9 +20942,9 @@ static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,...@@ -20942,9 +20942,9 @@ static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
20942 if (type_is_invalid(coro_promise_ptr->value.type))20942 if (type_is_invalid(coro_promise_ptr->value.type))
20943 return ira->codegen->builtin_types.entry_invalid;20943 return ira->codegen->builtin_types.entry_invalid;
2094420944
20945 assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer);20945 assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer);
20946 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;20946 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
20947 assert(promise_frame_type->id == TypeTableEntryIdStruct);20947 assert(promise_frame_type->id == ZigTypeIdStruct);
20948 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;20948 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
2094920949
20950 if (!type_can_fail(promise_result_type)) {20950 if (!type_can_fail(promise_result_type)) {
...@@ -20997,7 +20997,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i...@@ -20997,7 +20997,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i
20997 if (type_is_invalid(op->value.type))20997 if (type_is_invalid(op->value.type))
20998 return ira->codegen->builtin_types.entry_invalid;20998 return ira->codegen->builtin_types.entry_invalid;
2099920999
21000 bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat;21000 bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat;
21001 if (!ok_type) {21001 if (!ok_type) {
21002 ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));21002 ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));
21003 return ira->codegen->builtin_types.entry_invalid;21003 return ira->codegen->builtin_types.entry_invalid;
...@@ -21014,9 +21014,9 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i...@@ -21014,9 +21014,9 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i
2101421014
21015 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);21015 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
2101621016
21017 if (float_type->id == TypeTableEntryIdComptimeFloat) {21017 if (float_type->id == ZigTypeIdComptimeFloat) {
21018 bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);21018 bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);
21019 } else if (float_type->id == TypeTableEntryIdFloat) {21019 } else if (float_type->id == ZigTypeIdFloat) {
21020 switch (float_type->data.floating.bit_count) {21020 switch (float_type->data.floating.bit_count) {
21021 case 16:21021 case 16:
21022 out_val->data.x_f16 = f16_sqrt(val->data.x_f16);21022 out_val->data.x_f16 = f16_sqrt(val->data.x_f16);
...@@ -21040,7 +21040,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i...@@ -21040,7 +21040,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i
21040 return float_type;21040 return float_type;
21041 }21041 }
2104221042
21043 assert(float_type->id == TypeTableEntryIdFloat);21043 assert(float_type->id == ZigTypeIdFloat);
21044 if (float_type->data.floating.bit_count != 16 &&21044 if (float_type->data.floating.bit_count != 16 &&
21045 float_type->data.floating.bit_count != 32 &&21045 float_type->data.floating.bit_count != 32 &&
21046 float_type->data.floating.bit_count != 64) {21046 float_type->data.floating.bit_count != 64) {
...@@ -21061,7 +21061,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction...@@ -21061,7 +21061,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction
21061 if (type_is_invalid(target->value.type))21061 if (type_is_invalid(target->value.type))
21062 return ira->codegen->builtin_types.entry_invalid;21062 return ira->codegen->builtin_types.entry_invalid;
2106321063
21064 if (target->value.type->id != TypeTableEntryIdEnum) {21064 if (target->value.type->id != ZigTypeIdEnum) {
21065 ir_add_error(ira, instruction->target,21065 ir_add_error(ira, instruction->target,
21066 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));21066 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
21067 return ira->codegen->builtin_types.entry_invalid;21067 return ira->codegen->builtin_types.entry_invalid;
...@@ -21084,7 +21084,7 @@ static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstruction...@@ -21084,7 +21084,7 @@ static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstruction
21084 if (type_is_invalid(dest_type))21084 if (type_is_invalid(dest_type))
21085 return ira->codegen->builtin_types.entry_invalid;21085 return ira->codegen->builtin_types.entry_invalid;
2108621086
21087 if (dest_type->id != TypeTableEntryIdEnum) {21087 if (dest_type->id != ZigTypeIdEnum) {
21088 ir_add_error(ira, instruction->dest_type,21088 ir_add_error(ira, instruction->dest_type,
21089 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));21089 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
21090 return ira->codegen->builtin_types.entry_invalid;21090 return ira->codegen->builtin_types.entry_invalid;
...@@ -21420,8 +21420,8 @@ static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instructio...@@ -21420,8 +21420,8 @@ static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instructio
21420 if (instruction->other) {21420 if (instruction->other) {
21421 instruction->other->value.type = instruction_type;21421 instruction->other->value.type = instruction_type;
21422 } else {21422 } else {
21423 assert(instruction_type->id == TypeTableEntryIdInvalid ||21423 assert(instruction_type->id == ZigTypeIdInvalid ||
21424 instruction_type->id == TypeTableEntryIdUnreachable);21424 instruction_type->id == ZigTypeIdUnreachable);
21425 instruction->other = instruction;21425 instruction->other = instruction;
21426 }21426 }
2142721427
...@@ -21478,7 +21478,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -21478,7 +21478,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
21478 }21478 }
2147921479
21480 // unreachable instructions do their own control flow.21480 // unreachable instructions do their own control flow.
21481 if (return_type->id == TypeTableEntryIdUnreachable)21481 if (return_type->id == ZigTypeIdUnreachable)
21482 continue;21482 continue;
2148321483
21484 ira->instruction_index += 1;21484 ira->instruction_index += 1;