mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
resolve some TODOs
This commit is contained in:
parent
352c71873b
commit
0ecec5fcca
5 changed files with 7 additions and 55 deletions
|
|
@ -3319,8 +3319,6 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
|
|||
operand_ty.childType()
|
||||
else
|
||||
operand_ty;
|
||||
// TODO this should be validated in a more generic instruction that is
|
||||
// emitted for all ifs and whiles with an error union condition.
|
||||
if (err_union_ty.zigTypeTag() != .ErrorUnion) return;
|
||||
const payload_ty = err_union_ty.errorUnionPayload().zigTypeTag();
|
||||
if (payload_ty != .Void and payload_ty != .NoReturn) {
|
||||
|
|
@ -21596,7 +21594,7 @@ fn zirVarExtended(
|
|||
.owner_decl = sema.owner_decl_index,
|
||||
.init = init_val,
|
||||
.is_extern = small.is_extern,
|
||||
.is_mutable = true, // TODO get rid of this unused field
|
||||
.is_mutable = true,
|
||||
.is_threadlocal = small.is_threadlocal,
|
||||
.is_weak_linkage = false,
|
||||
.lib_name = null,
|
||||
|
|
@ -22075,7 +22073,7 @@ fn zirBuiltinExtern(
|
|||
.owner_decl = sema.owner_decl_index,
|
||||
.init = Value.initTag(.unreachable_value),
|
||||
.is_extern = true,
|
||||
.is_mutable = false, // TODO get rid of this unused field
|
||||
.is_mutable = false,
|
||||
.is_threadlocal = options.is_thread_local,
|
||||
.is_weak_linkage = options.linkage == .Weak,
|
||||
.lib_name = null,
|
||||
|
|
|
|||
|
|
@ -100,8 +100,7 @@ pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {
|
|||
|
||||
pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
|
||||
const raw_slice = code.extra[start..][0..len];
|
||||
// TODO we should be able to directly `@ptrCast` the slice to the other slice type.
|
||||
return @ptrCast([*]Inst.Ref, raw_slice.ptr)[0..len];
|
||||
return @ptrCast([]Inst.Ref, raw_slice);
|
||||
}
|
||||
|
||||
pub fn hasCompileErrors(code: Zir) bool {
|
||||
|
|
|
|||
|
|
@ -3412,8 +3412,7 @@ fn runOrTest(
|
|||
} else if (watch) {
|
||||
warn("process exited with code {d}", .{code});
|
||||
} else {
|
||||
// TODO https://github.com/ziglang/zig/issues/6342
|
||||
process.exit(1);
|
||||
process.exit(code);
|
||||
}
|
||||
},
|
||||
else => {
|
||||
|
|
|
|||
46
src/type.zig
46
src/type.zig
|
|
@ -1236,7 +1236,7 @@ pub const Type = extern union {
|
|||
// we can't hash these based on tags because they wouldn't match the expanded version.
|
||||
.type_info => unreachable, // needed to resolve the type before now
|
||||
|
||||
.bound_fn => unreachable, // TODO delete from the language
|
||||
.bound_fn => unreachable,
|
||||
.var_args_param => unreachable, // can be any type
|
||||
}
|
||||
}
|
||||
|
|
@ -3272,7 +3272,7 @@ pub const Type = extern union {
|
|||
.fn_ccc_void_no_args => unreachable, // represents machine code; not a pointer
|
||||
.function => unreachable, // represents machine code; not a pointer
|
||||
.@"opaque" => unreachable, // no size available
|
||||
.bound_fn => unreachable, // TODO remove from the language
|
||||
.bound_fn => unreachable,
|
||||
.noreturn => unreachable,
|
||||
.inferred_alloc_const => unreachable,
|
||||
.inferred_alloc_mut => unreachable,
|
||||
|
|
@ -4088,47 +4088,6 @@ pub const Type = extern union {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns if type can be used for a runtime variable
|
||||
pub fn isValidVarType(self: Type, is_extern: bool) bool {
|
||||
var ty = self;
|
||||
while (true) switch (ty.zigTypeTag()) {
|
||||
.Bool,
|
||||
.Int,
|
||||
.Float,
|
||||
.ErrorSet,
|
||||
.Enum,
|
||||
.Frame,
|
||||
.AnyFrame,
|
||||
=> return true,
|
||||
|
||||
.Opaque => return is_extern,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.EnumLiteral,
|
||||
.NoReturn,
|
||||
.Type,
|
||||
.Void,
|
||||
.Undefined,
|
||||
.Null,
|
||||
=> return false,
|
||||
|
||||
.Optional => {
|
||||
var buf: Payload.ElemType = undefined;
|
||||
return ty.optionalChild(&buf).isValidVarType(is_extern);
|
||||
},
|
||||
.Pointer, .Array, .Vector => ty = ty.elemType(),
|
||||
.ErrorUnion => ty = ty.errorUnionPayload(),
|
||||
|
||||
.Fn => @panic("TODO fn isValidVarType"),
|
||||
.Struct => {
|
||||
// TODO this is not always correct; introduce lazy value mechanism
|
||||
// and here we need to force a resolve of "type requires comptime".
|
||||
return true;
|
||||
},
|
||||
.Union => @panic("TODO union isValidVarType"),
|
||||
};
|
||||
}
|
||||
|
||||
/// For *[N]T, returns [N]T.
|
||||
/// For *T, returns T.
|
||||
/// For [*]T, returns T.
|
||||
|
|
@ -5434,7 +5393,6 @@ pub const Type = extern union {
|
|||
}
|
||||
|
||||
/// Asserts the type is an enum or a union.
|
||||
/// TODO support unions
|
||||
pub fn intTagType(ty: Type, buffer: *Payload.Bits) Type {
|
||||
switch (ty.tag()) {
|
||||
.enum_full, .enum_nonexhaustive => return ty.cast(Payload.EnumFull).?.data.tag_ty,
|
||||
|
|
|
|||
|
|
@ -814,7 +814,6 @@ pub const Value = extern union {
|
|||
.float_80 => return out_stream.print("{}", .{val.castTag(.float_80).?.data}),
|
||||
.float_128 => return out_stream.print("{}", .{val.castTag(.float_128).?.data}),
|
||||
.@"error" => return out_stream.print("error.{s}", .{val.castTag(.@"error").?.data.name}),
|
||||
// TODO to print this it should be error{ Set, Items }!T(val), but we need the type for that
|
||||
.eu_payload => {
|
||||
try out_stream.writeAll("(eu_payload) ");
|
||||
val = val.castTag(.eu_payload).?.data;
|
||||
|
|
@ -989,8 +988,7 @@ pub const Value = extern union {
|
|||
switch (val.tag()) {
|
||||
.enum_field_index => {
|
||||
const field_index = val.castTag(.enum_field_index).?.data;
|
||||
// TODO should `@intToEnum` do this `@intCast` for you?
|
||||
return @intToEnum(E, @intCast(@typeInfo(E).Enum.tag_type, field_index));
|
||||
return @intToEnum(E, field_index);
|
||||
},
|
||||
.the_only_possible_value => {
|
||||
const fields = std.meta.fields(E);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue