authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-31 16:51:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-31 16:51:40-07:00
log79a93914142e33636c37957fd513d42f4ac46060
treefa56cc866f4d98f2b07fe49707a9791d51503536
parent7deb1f4f6c038eaef815d5d179633683a9574ff0

stage2: no Payload for Type.Tag.inferred_alloc

Simpler, less memory usage. The Value has all the info needed.

3 files changed, 9 insertions(+), 16 deletions(-)

BRANCH_TODO+1-1
......@@ -1,2 +1,2 @@
1 * no need for payload on inferred_alloc for the type
21 * compile error for "variable of type '{}' must be const or comptime" after resolving types
2 * test with branches
src/type.zig+7-14
......@@ -3073,7 +3073,11 @@ pub const Type = extern union {
30733073 single_const_pointer_to_comptime_int,
30743074 anyerror_void_error_union,
30753075 @"anyframe",
3076 const_slice_u8, // See last_no_payload_tag below.
3076 const_slice_u8,
3077 /// This is a special value that tracks a set of types that have been stored
3078 /// to an inferred allocation. It does not support most of the normal type queries.
3079 /// However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc.
3080 inferred_alloc, // See last_no_payload_tag below.
30773081 // After this, the tag requires a payload.
30783082
30793083 array_u8,
......@@ -3100,12 +3104,8 @@ pub const Type = extern union {
31003104 error_set,
31013105 error_set_single,
31023106 empty_struct,
3103 /// This is a special value that tracks a set of types that have been stored
3104 /// to an inferred allocation. It does not support most of the normal type queries.
3105 /// However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc.
3106 inferred_alloc,
31073107
3108 pub const last_no_payload_tag = Tag.const_slice_u8;
3108 pub const last_no_payload_tag = Tag.inferred_alloc;
31093109 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
31103110
31113111 pub fn Type(comptime t: Tag) type {
......@@ -3152,6 +3152,7 @@ pub const Type = extern union {
31523152 .anyerror_void_error_union,
31533153 .@"anyframe",
31543154 .const_slice_u8,
3155 .inferred_alloc,
31553156 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
31563157
31573158 .array_u8,
......@@ -3184,7 +3185,6 @@ pub const Type = extern union {
31843185 .error_set => Payload.Decl,
31853186 .error_set_single => Payload.Name,
31863187 .empty_struct => Payload.ContainerScope,
3187 .inferred_alloc => Payload.InferredAlloc,
31883188 };
31893189 }
31903190
......@@ -3298,13 +3298,6 @@ pub const Type = extern union {
32983298 base: Payload,
32993299 data: *Module.Scope.Container,
33003300 };
3301
3302 pub const InferredAlloc = struct {
3303 pub const base_tag = Tag.inferred_alloc;
3304
3305 base: Payload = .{ .tag = base_tag },
3306 data: *Value.Payload.InferredAlloc,
3307 };
33083301 };
33093302};
33103303
src/zir_sema.zig+1-1
......@@ -441,7 +441,7 @@ fn analyzeInstAllocInferred(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) I
441441 // to a normal instruction when we hit `resolve_inferred_alloc`. So we append
442442 // to the block even though it is currently a `.constant`.
443443 const result = try mod.constInst(scope, inst.base.src, .{
444 .ty = try Type.Tag.inferred_alloc.create(scope.arena(), val_payload),
444 .ty = Type.initTag(.inferred_alloc),
445445 .val = Value.initPayload(&val_payload.base),
446446 });
447447 const block = try mod.requireFunctionBlock(scope, inst.base.src);