authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 21:50:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 21:50:12+02:00
logc57784aa15b50a9f38482154170924babab19c03
tree3a916fef243637252ce22f08e34e30cd0eb37020
parentf3d174aa616401117927988dfc499a1762db01a3
signature Commit is signed but in an unrecognized format.

add is_exhaustive field to typeinfo


3 files changed, 8 insertions(+), 1 deletions(-)

lib/std/builtin.zig+1
...@@ -253,6 +253,7 @@ pub const TypeInfo = union(enum) {...@@ -253,6 +253,7 @@ pub const TypeInfo = union(enum) {
253 tag_type: type,253 tag_type: type,
254 fields: []EnumField,254 fields: []EnumField,
255 decls: []Declaration,255 decls: []Declaration,
256 is_exhaustive: bool,
256 };257 };
257258
258 /// This data structure is used by the Zig language code generation and259 /// This data structure is used by the Zig language code generation and
src/ir.cpp+6-1
...@@ -23107,7 +23107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -23107,7 +23107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
23107 result->special = ConstValSpecialStatic;23107 result->special = ConstValSpecialStatic;
23108 result->type = ir_type_info_get_type(ira, "Enum", nullptr);23108 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2310923109
23110 ZigValue **fields = alloc_const_vals_ptrs(4);23110 ZigValue **fields = alloc_const_vals_ptrs(5);
23111 result->data.x_struct.fields = fields;23111 result->data.x_struct.fields = fields;
2311223112
23113 // layout: ContainerLayout23113 // layout: ContainerLayout
...@@ -23153,6 +23153,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -23153,6 +23153,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
23153 {23153 {
23154 return err;23154 return err;
23155 }23155 }
23156 // is_exhaustive: bool
23157 ensure_field_index(result->type, "is_exhaustive", 4);
23158 fields[4]->special = ConstValSpecialStatic;
23159 fields[4]->type = ira->codegen->builtin_types.entry_bool;
23160 fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;
2315623161
23157 break;23162 break;
23158 }23163 }
test/stage1/behavior/enum.zig+1
...@@ -46,6 +46,7 @@ test "non-exhaustive enum" {...@@ -46,6 +46,7 @@ test "non-exhaustive enum" {
46 expect(@enumToInt(e) == 12);46 expect(@enumToInt(e) == 12);
47 e = @intToEnum(E, y);47 e = @intToEnum(E, y);
48 expect(@enumToInt(e) == 52);48 expect(@enumToInt(e) == 52);
49 expect(@typeInfo(E).Enum.is_exhaustive == false);
49 }50 }
50 };51 };
51 S.doTheTest(52);52 S.doTheTest(52);