aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-01 14:03:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-01 14:03:32 -0700
commit18e42661dc9b8199311ee086b24ef5c85cf4708f (patch)
tree9a9a32ea7b4e58e733cd5548a2be5d2102385c66 /src
parent543bee0adf2d3b036654fa0983c16ff7023f504c (diff)
downloadzig-18e42661dc9b8199311ee086b24ef5c85cf4708f.tar.gz
zig-18e42661dc9b8199311ee086b24ef5c85cf4708f.zip
Sema: eliminate use of resolveAlreadyCoercedInt
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig11
-rw-r--r--src/Sema.zig35
-rw-r--r--src/type.zig1
3 files changed, 16 insertions, 31 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index e8d612fbc7..5de68e43e5 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -290,6 +290,7 @@ pub const ResultLoc = union(enum) {
};
pub const align_rl: ResultLoc = .{ .ty = .u16_type };
+pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u16_type };
pub const bool_rl: ResultLoc = .{ .ty = .bool_type };
pub const type_rl: ResultLoc = .{ .ty = .type_type };
pub const coerced_type_rl: ResultLoc = .{ .coerced_ty = .type_type };
@@ -2971,7 +2972,7 @@ fn ptrType(
trailing_count += 1;
}
if (ptr_info.ast.align_node != 0) {
- align_ref = try expr(gz, scope, align_rl, ptr_info.ast.align_node);
+ align_ref = try expr(gz, scope, coerced_align_rl, ptr_info.ast.align_node);
trailing_count += 1;
}
if (ptr_info.ast.addrspace_node != 0) {
@@ -2980,8 +2981,8 @@ fn ptrType(
}
if (ptr_info.ast.bit_range_start != 0) {
assert(ptr_info.ast.bit_range_end != 0);
- bit_start_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_start);
- bit_end_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_end);
+ bit_start_ref = try expr(gz, scope, .{ .coerced_ty = .u16_type }, ptr_info.ast.bit_range_start);
+ bit_end_ref = try expr(gz, scope, .{ .coerced_ty = .u16_type }, ptr_info.ast.bit_range_end);
trailing_count += 2;
}
@@ -7122,7 +7123,7 @@ fn builtinCall(
.error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int),
.int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u16_type }, params[0], .int_to_error),
.compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error),
- .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u32_type }, params[0], .set_eval_branch_quota),
+ .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota),
.enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int),
.bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int),
.embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
@@ -7437,7 +7438,7 @@ fn builtinCall(
},
.Vector => {
const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{
- .lhs = try comptimeExpr(gz, scope, .{ .ty = .u32_type }, params[0]),
+ .lhs = try comptimeExpr(gz, scope, .{ .coerced_ty = .u32_type }, params[0]),
.rhs = try typeExpr(gz, scope, params[1]),
});
return rvalue(gz, rl, result, node);
diff --git a/src/Sema.zig b/src/Sema.zig
index a71ddc773a..5bceb60aa0 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1464,26 +1464,6 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
return error.AnalysisFail;
}
-/// Appropriate to call when the coercion has already been done by result
-/// location semantics. Asserts the value fits in the provided `Int` type.
-/// Only supports `Int` types 64 bits or less.
-/// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty.
-fn resolveAlreadyCoercedInt(
- sema: *Sema,
- block: *Block,
- src: LazySrcLoc,
- zir_ref: Zir.Inst.Ref,
- comptime Int: type,
-) !Int {
- comptime assert(@typeInfo(Int).Int.bits <= 64);
- const air_inst = sema.resolveInst(zir_ref);
- const val = try sema.resolveConstValue(block, src, air_inst);
- switch (@typeInfo(Int).Int.signedness) {
- .signed => return @intCast(Int, val.toSignedInt()),
- .unsigned => return @intCast(Int, val.toUnsignedInt()),
- }
-}
-
fn resolveAlign(
sema: *Sema,
block: *Block,
@@ -3380,7 +3360,7 @@ fn storeToInferredAllocComptime(
fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
- const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32);
+ const quota = @intCast(u32, try sema.resolveInt(block, src, inst_data.operand, Type.u32));
if (sema.branch_quota < quota)
sema.branch_quota = quota;
}
@@ -5080,11 +5060,11 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
- const len = try sema.resolveAlreadyCoercedInt(block, len_src, extra.lhs, u32);
+ const len = try sema.resolveInt(block, len_src, extra.lhs, Type.u32);
const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
try sema.checkVectorElemType(block, elem_type_src, elem_type);
const vector_type = try Type.Tag.vector.create(sema.arena, .{
- .len = len,
+ .len = @intCast(u32, len),
.elem_type = elem_type,
});
return sema.addType(vector_type);
@@ -11341,7 +11321,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
const abi_align = if (inst_data.flags.has_align) blk: {
const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
extra_i += 1;
- break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u32);
+ const abi_align = try sema.resolveInt(block, .unneeded, ref, Type.u32);
+ break :blk @intCast(u32, abi_align);
} else 0;
const address_space = if (inst_data.flags.has_addrspace) blk: {
@@ -11353,13 +11334,15 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
const bit_offset = if (inst_data.flags.has_bit_range) blk: {
const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
extra_i += 1;
- break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);
+ const bit_offset = try sema.resolveInt(block, .unneeded, ref, Type.u16);
+ break :blk @intCast(u16, bit_offset);
} else 0;
const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
extra_i += 1;
- break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);
+ const host_size = try sema.resolveInt(block, .unneeded, ref, Type.u16);
+ break :blk @intCast(u16, host_size);
} else 0;
if (host_size != 0 and bit_offset >= host_size * 8) {
diff --git a/src/type.zig b/src/type.zig
index 96b8a78dea..40700f28af 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -5063,6 +5063,7 @@ pub const Type = extern union {
};
pub const @"u8" = initTag(.u8);
+ pub const @"u16" = initTag(.u16);
pub const @"u32" = initTag(.u32);
pub const @"u64" = initTag(.u64);