| ... | @@ -5288,141 +5288,6 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ | ... | @@ -5288,141 +5288,6 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ |
| 5288 | return const_val; | 5288 | return const_val; |
| 5289 | } | 5289 | } |
| 5290 | | 5290 | |
| 5291 | bool contains_comptime_undefined_value(ConstExprValue *value) { | | |
| 5292 | assert(value->special != ConstValSpecialRuntime); | | |
| 5293 | if (value->special == ConstValSpecialUndef) | | |
| 5294 | return true; | | |
| 5295 | | | |
| 5296 | switch (value->type->id) { | | |
| 5297 | case TypeTableEntryIdInvalid: | | |
| 5298 | zig_unreachable(); | | |
| 5299 | | | |
| 5300 | case TypeTableEntryIdPointer: { | | |
| 5301 | ConstPtrValue *ptr = &value->data.x_ptr; | | |
| 5302 | if (ptr->mut == ConstPtrMutRuntimeVar) | | |
| 5303 | return false; | | |
| 5304 | | | |
| 5305 | switch (ptr->special) { | | |
| 5306 | case ConstPtrSpecialInvalid: | | |
| 5307 | zig_unreachable(); | | |
| 5308 | case ConstPtrSpecialRef: | | |
| 5309 | return contains_comptime_undefined_value(ptr->data.ref.pointee); | | |
| 5310 | case ConstPtrSpecialBaseArray: { | | |
| 5311 | size_t index = ptr->data.base_array.elem_index; | | |
| 5312 | ConstExprValue *arr = ptr->data.base_array.array_val; | | |
| 5313 | if (arr->special == ConstValSpecialUndef) | | |
| 5314 | return true; | | |
| 5315 | if (arr->data.x_array.special == ConstArraySpecialUndef) | | |
| 5316 | return true; | | |
| 5317 | | | |
| 5318 | return contains_comptime_undefined_value(&arr->data.x_array.s_none.elements[index]); | | |
| 5319 | } | | |
| 5320 | case ConstPtrSpecialBaseStruct: { | | |
| 5321 | size_t index = ptr->data.base_struct.field_index; | | |
| 5322 | ConstExprValue *str = ptr->data.base_struct.struct_val; | | |
| 5323 | if (str->special == ConstValSpecialUndef) | | |
| 5324 | return true; | | |
| 5325 | | | |
| 5326 | return contains_comptime_undefined_value(&str->data.x_struct.fields[index]); | | |
| 5327 | } | | |
| 5328 | case ConstPtrSpecialFunction: // TODO: Can a fn ptr have an undefined value? | | |
| 5329 | case ConstPtrSpecialDiscard: | | |
| 5330 | case ConstPtrSpecialHardCodedAddr: | | |
| 5331 | return false; | | |
| 5332 | } | | |
| 5333 | } | | |
| 5334 | case TypeTableEntryIdArray: { | | |
| 5335 | ConstArrayValue *arr = &value->data.x_array; | | |
| 5336 | if (arr->special == ConstArraySpecialUndef) | | |
| 5337 | return true; | | |
| 5338 | | | |
| 5339 | for (size_t i = 0; i < value->type->data.array.len; ++i) { | | |
| 5340 | if (contains_comptime_undefined_value(&arr->s_none.elements[i])) | | |
| 5341 | return true; | | |
| 5342 | } | | |
| 5343 | return false; | | |
| 5344 | } | | |
| 5345 | case TypeTableEntryIdStruct: { | | |
| 5346 | ConstStructValue *str = &value->data.x_struct; | | |
| 5347 | if (value->type->data.structure.is_slice) { | | |
| 5348 | ConstExprValue *len = &str->fields[slice_len_index]; | | |
| 5349 | ConstExprValue *ptr = &str->fields[slice_ptr_index]; | | |
| 5350 | if (len->special == ConstValSpecialUndef) | | |
| 5351 | return true; | | |
| 5352 | if (ptr->special == ConstValSpecialUndef) | | |
| 5353 | return true; | | |
| 5354 | | | |
| 5355 | switch (ptr->data.x_ptr.special) { | | |
| 5356 | case ConstPtrSpecialRef: | | |
| 5357 | return contains_comptime_undefined_value(ptr->data.x_ptr.data.ref.pointee); | | |
| 5358 | case ConstPtrSpecialBaseArray: { | | |
| 5359 | size_t offset = ptr->data.x_ptr.data.base_array.elem_index; | | |
| 5360 | ConstExprValue *arr = ptr->data.x_ptr.data.base_array.array_val; | | |
| 5361 | if (arr->special == ConstValSpecialUndef) | | |
| 5362 | return true; | | |
| 5363 | if (arr->data.x_array.special == ConstArraySpecialUndef) | | |
| 5364 | return true; | | |
| 5365 | | | |
| 5366 | uint64_t slice_len = bigint_as_unsigned(&len->data.x_bigint); | | |
| 5367 | for (size_t i = 0; i < slice_len; ++i) { | | |
| 5368 | if (contains_comptime_undefined_value(&arr->data.x_array.s_none.elements[i + offset])) | | |
| 5369 | return true; | | |
| 5370 | } | | |
| 5371 | | | |
| 5372 | return false; | | |
| 5373 | } | | |
| 5374 | case ConstPtrSpecialBaseStruct: | | |
| 5375 | case ConstPtrSpecialInvalid: | | |
| 5376 | case ConstPtrSpecialFunction: | | |
| 5377 | case ConstPtrSpecialDiscard: | | |
| 5378 | case ConstPtrSpecialHardCodedAddr: | | |
| 5379 | zig_unreachable(); | | |
| 5380 | } | | |
| 5381 | } | | |
| 5382 | | | |
| 5383 | for (size_t i = 0; i < value->type->data.structure.src_field_count; ++i) { | | |
| 5384 | if (contains_comptime_undefined_value(&str->fields[i])) | | |
| 5385 | return true; | | |
| 5386 | } | | |
| 5387 | return false; | | |
| 5388 | } | | |
| 5389 | case TypeTableEntryIdOptional: | | |
| 5390 | if (value->data.x_optional == nullptr) | | |
| 5391 | return false; | | |
| 5392 | | | |
| 5393 | return contains_comptime_undefined_value(value->data.x_optional); | | |
| 5394 | case TypeTableEntryIdErrorUnion: | | |
| 5395 | // TODO: Can error union error be undefined? | | |
| 5396 | if (value->data.x_err_union.err != nullptr) | | |
| 5397 | return false; | | |
| 5398 | | | |
| 5399 | return contains_comptime_undefined_value(value->data.x_err_union.payload); | | |
| 5400 | case TypeTableEntryIdUnion: | | |
| 5401 | return contains_comptime_undefined_value(value->data.x_union.payload); | | |
| 5402 | | | |
| 5403 | case TypeTableEntryIdArgTuple: | | |
| 5404 | case TypeTableEntryIdVoid: | | |
| 5405 | case TypeTableEntryIdBool: | | |
| 5406 | case TypeTableEntryIdUnreachable: | | |
| 5407 | case TypeTableEntryIdInt: | | |
| 5408 | case TypeTableEntryIdFloat: | | |
| 5409 | case TypeTableEntryIdComptimeFloat: | | |
| 5410 | case TypeTableEntryIdComptimeInt: | | |
| 5411 | case TypeTableEntryIdUndefined: | | |
| 5412 | case TypeTableEntryIdNull: | | |
| 5413 | case TypeTableEntryIdErrorSet: | | |
| 5414 | case TypeTableEntryIdEnum: | | |
| 5415 | case TypeTableEntryIdFn: | | |
| 5416 | case TypeTableEntryIdNamespace: | | |
| 5417 | case TypeTableEntryIdBlock: | | |
| 5418 | case TypeTableEntryIdBoundFn: | | |
| 5419 | case TypeTableEntryIdMetaType: | | |
| 5420 | case TypeTableEntryIdOpaque: | | |
| 5421 | case TypeTableEntryIdPromise: | | |
| 5422 | return false; | | |
| 5423 | } | | |
| 5424 | zig_unreachable(); | | |
| 5425 | } | | |
| 5426 | | 5291 | |
| 5427 | void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { | 5292 | void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 5428 | TypeTableEntry *wanted_type = const_val->type; | 5293 | TypeTableEntry *wanted_type = const_val->type; |