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,2 +1,2 @@
1 * no need for payload on inferred_alloc for the type
2 * compile error for "variable of type '{}' must be const or comptime" after resolving types1 * 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 {...@@ -3073,7 +3073,11 @@ pub const Type = extern union {
3073 single_const_pointer_to_comptime_int,3073 single_const_pointer_to_comptime_int,
3074 anyerror_void_error_union,3074 anyerror_void_error_union,
3075 @"anyframe",3075 @"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.
3077 // After this, the tag requires a payload.3081 // After this, the tag requires a payload.
30783082
3079 array_u8,3083 array_u8,
...@@ -3100,12 +3104,8 @@ pub const Type = extern union {...@@ -3100,12 +3104,8 @@ pub const Type = extern union {
3100 error_set,3104 error_set,
3101 error_set_single,3105 error_set_single,
3102 empty_struct,3106 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;
3109 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;3109 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
31103110
3111 pub fn Type(comptime t: Tag) type {3111 pub fn Type(comptime t: Tag) type {
...@@ -3152,6 +3152,7 @@ pub const Type = extern union {...@@ -3152,6 +3152,7 @@ pub const Type = extern union {
3152 .anyerror_void_error_union,3152 .anyerror_void_error_union,
3153 .@"anyframe",3153 .@"anyframe",
3154 .const_slice_u8,3154 .const_slice_u8,
3155 .inferred_alloc,
3155 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),3156 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
31563157
3157 .array_u8,3158 .array_u8,
...@@ -3184,7 +3185,6 @@ pub const Type = extern union {...@@ -3184,7 +3185,6 @@ pub const Type = extern union {
3184 .error_set => Payload.Decl,3185 .error_set => Payload.Decl,
3185 .error_set_single => Payload.Name,3186 .error_set_single => Payload.Name,
3186 .empty_struct => Payload.ContainerScope,3187 .empty_struct => Payload.ContainerScope,
3187 .inferred_alloc => Payload.InferredAlloc,
3188 };3188 };
3189 }3189 }
31903190
...@@ -3298,13 +3298,6 @@ pub const Type = extern union {...@@ -3298,13 +3298,6 @@ pub const Type = extern union {
3298 base: Payload,3298 base: Payload,
3299 data: *Module.Scope.Container,3299 data: *Module.Scope.Container,
3300 };3300 };
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 };
3308 };3301 };
3309};3302};
33103303
src/zir_sema.zig+1-1
...@@ -441,7 +441,7 @@ fn analyzeInstAllocInferred(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) I...@@ -441,7 +441,7 @@ fn analyzeInstAllocInferred(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) I
441 // to a normal instruction when we hit `resolve_inferred_alloc`. So we append441 // to a normal instruction when we hit `resolve_inferred_alloc`. So we append
442 // to the block even though it is currently a `.constant`.442 // to the block even though it is currently a `.constant`.
443 const result = try mod.constInst(scope, inst.base.src, .{443 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),
445 .val = Value.initPayload(&val_payload.base),445 .val = Value.initPayload(&val_payload.base),
446 });446 });
447 const block = try mod.requireFunctionBlock(scope, inst.base.src);447 const block = try mod.requireFunctionBlock(scope, inst.base.src);