aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-13 18:43:43 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-13 18:43:43 -0700
commitb0f80ef0d5517b5ce8ba60dfae6dd986346f8d4c (patch)
tree14dbc30206ceed6282ee010685de8da1ede4167d /src
parentdf7d6d263e4ad6adb302856235641ae9ceb142b6 (diff)
downloadzig-b0f80ef0d5517b5ce8ba60dfae6dd986346f8d4c.tar.gz
zig-b0f80ef0d5517b5ce8ba60dfae6dd986346f8d4c.zip
stage2: remove use of `builtin.stage2_arch` workaround
The LLVM backend no longer needs this hack! However, the other backends still do. So there are still some traces of this workaround in use for now.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig29
-rw-r--r--src/type.zig3
2 files changed, 19 insertions, 13 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 4485475eaf..d0c4bbec75 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -10186,7 +10186,7 @@ fn validateVarType(
is_extern: bool,
) CompileError!void {
var ty = var_ty;
- const ok: bool = while (true) switch (ty.zigTypeTag()) {
+ while (true) switch (ty.zigTypeTag()) {
.Bool,
.Int,
.Float,
@@ -10194,7 +10194,7 @@ fn validateVarType(
.Enum,
.Frame,
.AnyFrame,
- => break true,
+ => return,
.BoundFn,
.ComptimeFloat,
@@ -10205,14 +10205,14 @@ fn validateVarType(
.Void,
.Undefined,
.Null,
- => break false,
+ => break,
.Pointer => {
const elem_ty = ty.childType();
if (elem_ty.zigTypeTag() == .Opaque) return;
ty = elem_ty;
},
- .Opaque => break is_extern,
+ .Opaque => if (is_extern) return else break,
.Optional => {
var buf: Type.Payload.ElemType = undefined;
@@ -10223,15 +10223,17 @@ fn validateVarType(
.ErrorUnion => ty = ty.errorUnionPayload(),
- .Fn => @panic("TODO fn validateVarType"),
- .Struct, .Union => {
+ .Fn, .Struct, .Union => {
const resolved_ty = try sema.resolveTypeFields(block, src, ty);
- break !resolved_ty.requiresComptime();
+ if (resolved_ty.requiresComptime()) {
+ break;
+ } else {
+ return;
+ }
},
} else unreachable; // TODO should not need else unreachable
- if (!ok) {
- return sema.fail(block, src, "variable of type '{}' must be const or comptime", .{var_ty});
- }
+
+ return sema.fail(block, src, "variable of type '{}' must be const or comptime", .{var_ty});
}
pub const PanicId = enum {
@@ -11273,7 +11275,12 @@ fn coerce(
const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, target);
if (in_memory_result == .ok) {
- return sema.bitCast(block, dest_type, inst, inst_src);
+ if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
+ // Keep the comptime Value representation; take the new type.
+ return sema.addConstant(dest_type, val);
+ }
+ try sema.requireRuntimeBlock(block, inst_src);
+ return block.addTyOp(.bitcast, dest_type, inst);
}
// undefined to anything
diff --git a/src/type.zig b/src/type.zig
index 72430c9f65..055b32a048 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -1458,7 +1458,7 @@ pub const Type = extern union {
}
},
.union_tagged => {
- const union_obj = self.castTag(.@"union").?.data;
+ const union_obj = self.castTag(.union_tagged).?.data;
if (union_obj.tag_ty.hasCodeGenBits()) {
return true;
}
@@ -1470,7 +1470,6 @@ pub const Type = extern union {
}
},
- // TODO lazy types
.array, .vector => self.elemType().hasCodeGenBits() and self.arrayLen() != 0,
.array_u8 => self.arrayLen() != 0,