| author | |
| committer | |
| log | c61e0a078cea2a6845ed7b03189409829d2cdf24 |
| tree | 8a64733d2ecf5121dbdf0db998f4d69a4e5629e6 |
| parent | 3021e5ca67acca6cf7420bc5e2400aa6965596f9 |
| signature | Commit is signed but in an unrecognized format. |
all std lib tests passing now6 files changed, 44 insertions(+), 35 deletions(-)
src/analyze.cpp+3-11| ... | @@ -5001,12 +5001,9 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { | ... | @@ -5001,12 +5001,9 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 5001 | field_val->type = wanted_type->data.structure.fields[i].type_entry; | 5001 | field_val->type = wanted_type->data.structure.fields[i].type_entry; |
| 5002 | assert(field_val->type); | 5002 | assert(field_val->type); |
| 5003 | init_const_undefined(g, field_val); | 5003 | init_const_undefined(g, field_val); |
| 5004 | ConstParent *parent = get_const_val_parent(g, field_val); | 5004 | field_val->parent.id = ConstParentIdStruct; |
| 5005 | if (parent != nullptr) { | 5005 | field_val->parent.data.p_struct.struct_val = const_val; |
| 5006 | parent->id = ConstParentIdStruct; | 5006 | field_val->parent.data.p_struct.field_index = i; |
| 5007 | parent->data.p_struct.struct_val = const_val; | ||
| 5008 | parent->data.p_struct.field_index = i; | ||
| 5009 | } | ||
| 5010 | } | 5007 | } |
| 5011 | } else { | 5008 | } else { |
| 5012 | const_val->special = ConstValSpecialUndef; | 5009 | const_val->special = ConstValSpecialUndef; |
| ... | @@ -5842,11 +5839,6 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { | ... | @@ -5842,11 +5839,6 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { |
| 5842 | zig_unreachable(); | 5839 | zig_unreachable(); |
| 5843 | } | 5840 | } |
| 5844 | 5841 | ||
| 5845 | // Deprecated. Reference the parent field directly. | ||
| 5846 | ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) { | ||
| 5847 | return &value->parent; | ||
| 5848 | } | ||
| 5849 | |||
| 5850 | static const ZigTypeId all_type_ids[] = { | 5842 | static const ZigTypeId all_type_ids[] = { |
| 5851 | ZigTypeIdMetaType, | 5843 | ZigTypeIdMetaType, |
| 5852 | ZigTypeIdVoid, | 5844 | ZigTypeIdVoid, |
src/analyze.hpp-1| ... | @@ -180,7 +180,6 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val); | ... | @@ -180,7 +180,6 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val); |
| 180 | ConstExprValue *create_const_vals(size_t count); | 180 | ConstExprValue *create_const_vals(size_t count); |
| 181 | 181 | ||
| 182 | ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); | 182 | ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); |
| 183 | ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value); | ||
| 184 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); | 183 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); |
| 185 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); | 184 | void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); |
| 186 | 185 |
src/codegen.cpp+13-1| ... | @@ -3873,8 +3873,20 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab | ... | @@ -3873,8 +3873,20 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab |
| 3873 | 3873 | ||
| 3874 | TypeUnionField *field = instruction->field; | 3874 | TypeUnionField *field = instruction->field; |
| 3875 | 3875 | ||
| 3876 | if (!type_has_bits(field->type_entry)) | 3876 | if (!type_has_bits(field->type_entry)) { |
| 3877 | if (union_type->data.unionation.gen_tag_index == SIZE_MAX) { | ||
| 3878 | return nullptr; | ||
| 3879 | } | ||
| 3880 | if (instruction->initializing) { | ||
| 3881 | LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr); | ||
| 3882 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, | ||
| 3883 | union_type->data.unionation.gen_tag_index, ""); | ||
| 3884 | LLVMValueRef tag_value = bigint_to_llvm_const(get_llvm_type(g, union_type->data.unionation.tag_type), | ||
| 3885 | &field->enum_field->value); | ||
| 3886 | gen_store_untyped(g, tag_value, tag_field_ptr, 0, false); | ||
| 3887 | } | ||
| 3877 | return nullptr; | 3888 | return nullptr; |
| 3889 | } | ||
| 3878 | 3890 | ||
| 3879 | LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr); | 3891 | LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr); |
| 3880 | LLVMTypeRef field_type_ref = LLVMPointerType(get_llvm_type(g, field->type_entry), 0); | 3892 | LLVMTypeRef field_type_ref = LLVMPointerType(get_llvm_type(g, field->type_entry), 0); |
src/ir.cpp+7-11| ... | @@ -17425,11 +17425,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction | ... | @@ -17425,11 +17425,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 17425 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[i]; | 17425 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[i]; |
| 17426 | field_val->special = ConstValSpecialUndef; | 17426 | field_val->special = ConstValSpecialUndef; |
| 17427 | field_val->type = struct_type->data.structure.fields[i].type_entry; | 17427 | field_val->type = struct_type->data.structure.fields[i].type_entry; |
| 17428 | ConstParent *parent = get_const_val_parent(ira->codegen, field_val); | 17428 | field_val->parent.id = ConstParentIdStruct; |
| 17429 | assert(parent != nullptr); | 17429 | field_val->parent.data.p_struct.struct_val = struct_val; |
| 17430 | parent->id = ConstParentIdStruct; | 17430 | field_val->parent.data.p_struct.field_index = i; |
| 17431 | parent->data.p_struct.struct_val = struct_val; | ||
| 17432 | parent->data.p_struct.field_index = i; | ||
| 17433 | } | 17431 | } |
| 17434 | } | 17432 | } |
| 17435 | IrInstruction *result; | 17433 | IrInstruction *result; |
| ... | @@ -17507,11 +17505,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -17507,11 +17505,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 17507 | ConstExprValue *payload_val = create_const_vals(1); | 17505 | ConstExprValue *payload_val = create_const_vals(1); |
| 17508 | payload_val->special = ConstValSpecialUndef; | 17506 | payload_val->special = ConstValSpecialUndef; |
| 17509 | payload_val->type = field->type_entry; | 17507 | payload_val->type = field->type_entry; |
| 17510 | ConstParent *parent = get_const_val_parent(ira->codegen, payload_val); | 17508 | payload_val->parent.id = ConstParentIdUnion; |
| 17511 | if (parent != nullptr) { | 17509 | payload_val->parent.data.p_union.union_val = union_val; |
| 17512 | parent->id = ConstParentIdUnion; | ||
| 17513 | parent->data.p_union.union_val = union_val; | ||
| 17514 | } | ||
| 17515 | 17510 | ||
| 17516 | union_val->special = ConstValSpecialStatic; | 17511 | union_val->special = ConstValSpecialStatic; |
| 17517 | bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value); | 17512 | bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value); |
| ... | @@ -25289,7 +25284,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -25289,7 +25284,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 25289 | case IrInstructionIdReturnPtr: | 25284 | case IrInstructionIdReturnPtr: |
| 25290 | case IrInstructionIdTypeOf: | 25285 | case IrInstructionIdTypeOf: |
| 25291 | case IrInstructionIdStructFieldPtr: | 25286 | case IrInstructionIdStructFieldPtr: |
| 25292 | case IrInstructionIdUnionFieldPtr: | ||
| 25293 | case IrInstructionIdArrayType: | 25287 | case IrInstructionIdArrayType: |
| 25294 | case IrInstructionIdPromiseType: | 25288 | case IrInstructionIdPromiseType: |
| 25295 | case IrInstructionIdSliceType: | 25289 | case IrInstructionIdSliceType: |
| ... | @@ -25389,6 +25383,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -25389,6 +25383,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 25389 | } | 25383 | } |
| 25390 | case IrInstructionIdUnwrapErrCode: | 25384 | case IrInstructionIdUnwrapErrCode: |
| 25391 | return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing; | 25385 | return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing; |
| 25386 | case IrInstructionIdUnionFieldPtr: | ||
| 25387 | return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing; | ||
| 25392 | case IrInstructionIdErrWrapPayload: | 25388 | case IrInstructionIdErrWrapPayload: |
| 25393 | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; | 25389 | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 25394 | case IrInstructionIdErrWrapCode: | 25390 | case IrInstructionIdErrWrapCode: |
std/zig/parser_test.zig+1-11| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | // TODO remove `use` keyword eventually | 1 | // TODO remove `use` keyword eventually: https://github.com/ziglang/zig/issues/2591 |
| 2 | test "zig fmt: change use to usingnamespace" { | 2 | test "zig fmt: change use to usingnamespace" { |
| 3 | try testTransform( | 3 | try testTransform( |
| 4 | \\use @import("std"); | 4 | \\use @import("std"); |
| ... | @@ -105,7 +105,6 @@ test "zig fmt: linksection" { | ... | @@ -105,7 +105,6 @@ test "zig fmt: linksection" { |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | test "zig fmt: correctly move doc comments on struct fields" { | 107 | test "zig fmt: correctly move doc comments on struct fields" { |
| 108 | if (true) return error.SkipZigTest; // TODO | ||
| 109 | try testTransform( | 108 | try testTransform( |
| 110 | \\pub const section_64 = extern struct { | 109 | \\pub const section_64 = extern struct { |
| 111 | \\ sectname: [16]u8, /// name of this section | 110 | \\ sectname: [16]u8, /// name of this section |
| ... | @@ -917,7 +916,6 @@ test "zig fmt: statements with empty line between" { | ... | @@ -917,7 +916,6 @@ test "zig fmt: statements with empty line between" { |
| 917 | } | 916 | } |
| 918 | 917 | ||
| 919 | test "zig fmt: ptr deref operator and unwrap optional operator" { | 918 | test "zig fmt: ptr deref operator and unwrap optional operator" { |
| 920 | if (true) return error.SkipZigTest; // TODO | ||
| 921 | try testCanonical( | 919 | try testCanonical( |
| 922 | \\const a = b.*; | 920 | \\const a = b.*; |
| 923 | \\const a = b.?; | 921 | \\const a = b.?; |
| ... | @@ -1020,7 +1018,6 @@ test "zig fmt: same-line comment after a statement" { | ... | @@ -1020,7 +1018,6 @@ test "zig fmt: same-line comment after a statement" { |
| 1020 | } | 1018 | } |
| 1021 | 1019 | ||
| 1022 | test "zig fmt: same-line comment after var decl in struct" { | 1020 | test "zig fmt: same-line comment after var decl in struct" { |
| 1023 | if (true) return error.SkipZigTest; // TODO | ||
| 1024 | try testCanonical( | 1021 | try testCanonical( |
| 1025 | \\pub const vfs_cap_data = extern struct { | 1022 | \\pub const vfs_cap_data = extern struct { |
| 1026 | \\ const Data = struct {}; // when on disk. | 1023 | \\ const Data = struct {}; // when on disk. |
| ... | @@ -1030,7 +1027,6 @@ test "zig fmt: same-line comment after var decl in struct" { | ... | @@ -1030,7 +1027,6 @@ test "zig fmt: same-line comment after var decl in struct" { |
| 1030 | } | 1027 | } |
| 1031 | 1028 | ||
| 1032 | test "zig fmt: same-line comment after field decl" { | 1029 | test "zig fmt: same-line comment after field decl" { |
| 1033 | if (true) return error.SkipZigTest; // TODO | ||
| 1034 | try testCanonical( | 1030 | try testCanonical( |
| 1035 | \\pub const dirent = extern struct { | 1031 | \\pub const dirent = extern struct { |
| 1036 | \\ d_name: u8, | 1032 | \\ d_name: u8, |
| ... | @@ -1106,7 +1102,6 @@ test "zig fmt: line comments in struct initializer" { | ... | @@ -1106,7 +1102,6 @@ test "zig fmt: line comments in struct initializer" { |
| 1106 | } | 1102 | } |
| 1107 | 1103 | ||
| 1108 | test "zig fmt: first line comment in struct initializer" { | 1104 | test "zig fmt: first line comment in struct initializer" { |
| 1109 | if (true) return error.SkipZigTest; // TODO | ||
| 1110 | try testCanonical( | 1105 | try testCanonical( |
| 1111 | \\pub async fn acquire(self: *Self) HeldLock { | 1106 | \\pub async fn acquire(self: *Self) HeldLock { |
| 1112 | \\ return HeldLock{ | 1107 | \\ return HeldLock{ |
| ... | @@ -1120,7 +1115,6 @@ test "zig fmt: first line comment in struct initializer" { | ... | @@ -1120,7 +1115,6 @@ test "zig fmt: first line comment in struct initializer" { |
| 1120 | } | 1115 | } |
| 1121 | 1116 | ||
| 1122 | test "zig fmt: doc comments before struct field" { | 1117 | test "zig fmt: doc comments before struct field" { |
| 1123 | if (true) return error.SkipZigTest; // TODO | ||
| 1124 | try testCanonical( | 1118 | try testCanonical( |
| 1125 | \\pub const Allocator = struct { | 1119 | \\pub const Allocator = struct { |
| 1126 | \\ /// Allocate byte_count bytes and return them in a slice, with the | 1120 | \\ /// Allocate byte_count bytes and return them in a slice, with the |
| ... | @@ -1218,7 +1212,6 @@ test "zig fmt: comments before switch prong" { | ... | @@ -1218,7 +1212,6 @@ test "zig fmt: comments before switch prong" { |
| 1218 | } | 1212 | } |
| 1219 | 1213 | ||
| 1220 | test "zig fmt: comments before var decl in struct" { | 1214 | test "zig fmt: comments before var decl in struct" { |
| 1221 | if (true) return error.SkipZigTest; // TODO | ||
| 1222 | try testCanonical( | 1215 | try testCanonical( |
| 1223 | \\pub const vfs_cap_data = extern struct { | 1216 | \\pub const vfs_cap_data = extern struct { |
| 1224 | \\ // All of these are mandated as little endian | 1217 | \\ // All of these are mandated as little endian |
| ... | @@ -1609,7 +1602,6 @@ test "zig fmt: indexing" { | ... | @@ -1609,7 +1602,6 @@ test "zig fmt: indexing" { |
| 1609 | } | 1602 | } |
| 1610 | 1603 | ||
| 1611 | test "zig fmt: struct declaration" { | 1604 | test "zig fmt: struct declaration" { |
| 1612 | if (true) return error.SkipZigTest; // TODO | ||
| 1613 | try testCanonical( | 1605 | try testCanonical( |
| 1614 | \\const S = struct { | 1606 | \\const S = struct { |
| 1615 | \\ const Self = @This(); | 1607 | \\ const Self = @This(); |
| ... | @@ -1641,7 +1633,6 @@ test "zig fmt: struct declaration" { | ... | @@ -1641,7 +1633,6 @@ test "zig fmt: struct declaration" { |
| 1641 | } | 1633 | } |
| 1642 | 1634 | ||
| 1643 | test "zig fmt: enum declaration" { | 1635 | test "zig fmt: enum declaration" { |
| 1644 | if (true) return error.SkipZigTest; // TODO | ||
| 1645 | try testCanonical( | 1636 | try testCanonical( |
| 1646 | \\const E = enum { | 1637 | \\const E = enum { |
| 1647 | \\ Ok, | 1638 | \\ Ok, |
| ... | @@ -1670,7 +1661,6 @@ test "zig fmt: enum declaration" { | ... | @@ -1670,7 +1661,6 @@ test "zig fmt: enum declaration" { |
| 1670 | } | 1661 | } |
| 1671 | 1662 | ||
| 1672 | test "zig fmt: union declaration" { | 1663 | test "zig fmt: union declaration" { |
| 1673 | if (true) return error.SkipZigTest; // TODO | ||
| 1674 | try testCanonical( | 1664 | try testCanonical( |
| 1675 | \\const U = union { | 1665 | \\const U = union { |
| 1676 | \\ Int: u8, | 1666 | \\ Int: u8, |
test/stage1/behavior/union.zig+20| ... | @@ -402,3 +402,23 @@ test "comptime union field value equality" { | ... | @@ -402,3 +402,23 @@ test "comptime union field value equality" { |
| 402 | expect(a0 != a1); | 402 | expect(a0 != a1); |
| 403 | expect(b0 != b1); | 403 | expect(b0 != b1); |
| 404 | } | 404 | } |
| 405 | |||
| 406 | test "return union init with void payload" { | ||
| 407 | const S = struct { | ||
| 408 | fn entry() void { | ||
| 409 | expect(func().state == State.one); | ||
| 410 | } | ||
| 411 | const Outer = union(enum) { | ||
| 412 | state: State, | ||
| 413 | }; | ||
| 414 | const State = union(enum) { | ||
| 415 | one: void, | ||
| 416 | two: u32, | ||
| 417 | }; | ||
| 418 | fn func() Outer { | ||
| 419 | return Outer{ .state = State{ .one = {} }}; | ||
| 420 | } | ||
| 421 | }; | ||
| 422 | S.entry(); | ||
| 423 | comptime S.entry(); | ||
| 424 | } |