authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-05 13:25:36+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-05 14:26:53+02:00
log0ecec5fcca3ae8f33bf307c2ca66b8d11baf3d1d
treec3b09089496106831a25e7597a0b59607e95c458
parent352c71873b1c018fed8821d275b490be8c881792

resolve some TODOs


5 files changed, 7 insertions(+), 55 deletions(-)

src/Sema.zig+2-4
......@@ -3319,8 +3319,6 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
33193319 operand_ty.childType()
33203320 else
33213321 operand_ty;
3322 // TODO this should be validated in a more generic instruction that is
3323 // emitted for all ifs and whiles with an error union condition.
33243322 if (err_union_ty.zigTypeTag() != .ErrorUnion) return;
33253323 const payload_ty = err_union_ty.errorUnionPayload().zigTypeTag();
33263324 if (payload_ty != .Void and payload_ty != .NoReturn) {
......@@ -21596,7 +21594,7 @@ fn zirVarExtended(
2159621594 .owner_decl = sema.owner_decl_index,
2159721595 .init = init_val,
2159821596 .is_extern = small.is_extern,
21599 .is_mutable = true, // TODO get rid of this unused field
21597 .is_mutable = true,
2160021598 .is_threadlocal = small.is_threadlocal,
2160121599 .is_weak_linkage = false,
2160221600 .lib_name = null,
......@@ -22075,7 +22073,7 @@ fn zirBuiltinExtern(
2207522073 .owner_decl = sema.owner_decl_index,
2207622074 .init = Value.initTag(.unreachable_value),
2207722075 .is_extern = true,
22078 .is_mutable = false, // TODO get rid of this unused field
22076 .is_mutable = false,
2207922077 .is_threadlocal = options.is_thread_local,
2208022078 .is_weak_linkage = options.linkage == .Weak,
2208122079 .lib_name = null,
src/Zir.zig+1-2
......@@ -100,8 +100,7 @@ pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {
100100
101101pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
102102 const raw_slice = code.extra[start..][0..len];
103 // TODO we should be able to directly `@ptrCast` the slice to the other slice type.
104 return @ptrCast([*]Inst.Ref, raw_slice.ptr)[0..len];
103 return @ptrCast([]Inst.Ref, raw_slice);
105104}
106105
107106pub fn hasCompileErrors(code: Zir) bool {
src/main.zig+1-2
......@@ -3412,8 +3412,7 @@ fn runOrTest(
34123412 } else if (watch) {
34133413 warn("process exited with code {d}", .{code});
34143414 } else {
3415 // TODO https://github.com/ziglang/zig/issues/6342
3416 process.exit(1);
3415 process.exit(code);
34173416 }
34183417 },
34193418 else => {
src/type.zig+2-44
......@@ -1236,7 +1236,7 @@ pub const Type = extern union {
12361236 // we can't hash these based on tags because they wouldn't match the expanded version.
12371237 .type_info => unreachable, // needed to resolve the type before now
12381238
1239 .bound_fn => unreachable, // TODO delete from the language
1239 .bound_fn => unreachable,
12401240 .var_args_param => unreachable, // can be any type
12411241 }
12421242 }
......@@ -3272,7 +3272,7 @@ pub const Type = extern union {
32723272 .fn_ccc_void_no_args => unreachable, // represents machine code; not a pointer
32733273 .function => unreachable, // represents machine code; not a pointer
32743274 .@"opaque" => unreachable, // no size available
3275 .bound_fn => unreachable, // TODO remove from the language
3275 .bound_fn => unreachable,
32763276 .noreturn => unreachable,
32773277 .inferred_alloc_const => unreachable,
32783278 .inferred_alloc_mut => unreachable,
......@@ -4088,47 +4088,6 @@ pub const Type = extern union {
40884088 }
40894089 }
40904090
4091 /// Returns if type can be used for a runtime variable
4092 pub fn isValidVarType(self: Type, is_extern: bool) bool {
4093 var ty = self;
4094 while (true) switch (ty.zigTypeTag()) {
4095 .Bool,
4096 .Int,
4097 .Float,
4098 .ErrorSet,
4099 .Enum,
4100 .Frame,
4101 .AnyFrame,
4102 => return true,
4103
4104 .Opaque => return is_extern,
4105 .ComptimeFloat,
4106 .ComptimeInt,
4107 .EnumLiteral,
4108 .NoReturn,
4109 .Type,
4110 .Void,
4111 .Undefined,
4112 .Null,
4113 => return false,
4114
4115 .Optional => {
4116 var buf: Payload.ElemType = undefined;
4117 return ty.optionalChild(&buf).isValidVarType(is_extern);
4118 },
4119 .Pointer, .Array, .Vector => ty = ty.elemType(),
4120 .ErrorUnion => ty = ty.errorUnionPayload(),
4121
4122 .Fn => @panic("TODO fn isValidVarType"),
4123 .Struct => {
4124 // TODO this is not always correct; introduce lazy value mechanism
4125 // and here we need to force a resolve of "type requires comptime".
4126 return true;
4127 },
4128 .Union => @panic("TODO union isValidVarType"),
4129 };
4130 }
4131
41324091 /// For *[N]T, returns [N]T.
41334092 /// For *T, returns T.
41344093 /// For [*]T, returns T.
......@@ -5434,7 +5393,6 @@ pub const Type = extern union {
54345393 }
54355394
54365395 /// Asserts the type is an enum or a union.
5437 /// TODO support unions
54385396 pub fn intTagType(ty: Type, buffer: *Payload.Bits) Type {
54395397 switch (ty.tag()) {
54405398 .enum_full, .enum_nonexhaustive => return ty.cast(Payload.EnumFull).?.data.tag_ty,
src/value.zig+1-3
......@@ -814,7 +814,6 @@ pub const Value = extern union {
814814 .float_80 => return out_stream.print("{}", .{val.castTag(.float_80).?.data}),
815815 .float_128 => return out_stream.print("{}", .{val.castTag(.float_128).?.data}),
816816 .@"error" => return out_stream.print("error.{s}", .{val.castTag(.@"error").?.data.name}),
817 // TODO to print this it should be error{ Set, Items }!T(val), but we need the type for that
818817 .eu_payload => {
819818 try out_stream.writeAll("(eu_payload) ");
820819 val = val.castTag(.eu_payload).?.data;
......@@ -989,8 +988,7 @@ pub const Value = extern union {
989988 switch (val.tag()) {
990989 .enum_field_index => {
991990 const field_index = val.castTag(.enum_field_index).?.data;
992 // TODO should `@intToEnum` do this `@intCast` for you?
993 return @intToEnum(E, @intCast(@typeInfo(E).Enum.tag_type, field_index));
991 return @intToEnum(E, field_index);
994992 },
995993 .the_only_possible_value => {
996994 const fields = std.meta.fields(E);