| author | |
| committer | |
| log | 18e42661dc9b8199311ee086b24ef5c85cf4708f |
| tree | 9a9a32ea7b4e58e733cd5548a2be5d2102385c66 |
| parent | 543bee0adf2d3b036654fa0983c16ff7023f504c |
3 files changed, 16 insertions(+), 31 deletions(-)
src/AstGen.zig+6-5| ... | @@ -290,6 +290,7 @@ pub const ResultLoc = union(enum) { | ... | @@ -290,6 +290,7 @@ pub const ResultLoc = union(enum) { |
| 290 | }; | 290 | }; |
| 291 | 291 | ||
| 292 | pub const align_rl: ResultLoc = .{ .ty = .u16_type }; | 292 | pub const align_rl: ResultLoc = .{ .ty = .u16_type }; |
| 293 | pub const coerced_align_rl: ResultLoc = .{ .coerced_ty = .u16_type }; | ||
| 293 | pub const bool_rl: ResultLoc = .{ .ty = .bool_type }; | 294 | pub const bool_rl: ResultLoc = .{ .ty = .bool_type }; |
| 294 | pub const type_rl: ResultLoc = .{ .ty = .type_type }; | 295 | pub const type_rl: ResultLoc = .{ .ty = .type_type }; |
| 295 | pub const coerced_type_rl: ResultLoc = .{ .coerced_ty = .type_type }; | 296 | pub const coerced_type_rl: ResultLoc = .{ .coerced_ty = .type_type }; |
| ... | @@ -2971,7 +2972,7 @@ fn ptrType( | ... | @@ -2971,7 +2972,7 @@ fn ptrType( |
| 2971 | trailing_count += 1; | 2972 | trailing_count += 1; |
| 2972 | } | 2973 | } |
| 2973 | if (ptr_info.ast.align_node != 0) { | 2974 | if (ptr_info.ast.align_node != 0) { |
| 2974 | align_ref = try expr(gz, scope, align_rl, ptr_info.ast.align_node); | 2975 | align_ref = try expr(gz, scope, coerced_align_rl, ptr_info.ast.align_node); |
| 2975 | trailing_count += 1; | 2976 | trailing_count += 1; |
| 2976 | } | 2977 | } |
| 2977 | if (ptr_info.ast.addrspace_node != 0) { | 2978 | if (ptr_info.ast.addrspace_node != 0) { |
| ... | @@ -2980,8 +2981,8 @@ fn ptrType( | ... | @@ -2980,8 +2981,8 @@ fn ptrType( |
| 2980 | } | 2981 | } |
| 2981 | if (ptr_info.ast.bit_range_start != 0) { | 2982 | if (ptr_info.ast.bit_range_start != 0) { |
| 2982 | assert(ptr_info.ast.bit_range_end != 0); | 2983 | assert(ptr_info.ast.bit_range_end != 0); |
| 2983 | bit_start_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_start); | 2984 | bit_start_ref = try expr(gz, scope, .{ .coerced_ty = .u16_type }, ptr_info.ast.bit_range_start); |
| 2984 | bit_end_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_end); | 2985 | bit_end_ref = try expr(gz, scope, .{ .coerced_ty = .u16_type }, ptr_info.ast.bit_range_end); |
| 2985 | trailing_count += 2; | 2986 | trailing_count += 2; |
| 2986 | } | 2987 | } |
| 2987 | 2988 | ||
| ... | @@ -7122,7 +7123,7 @@ fn builtinCall( | ... | @@ -7122,7 +7123,7 @@ fn builtinCall( |
| 7122 | .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int), | 7123 | .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int), |
| 7123 | .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u16_type }, params[0], .int_to_error), | 7124 | .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u16_type }, params[0], .int_to_error), |
| 7124 | .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error), | 7125 | .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error), |
| 7125 | .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .ty = .u32_type }, params[0], .set_eval_branch_quota), | 7126 | .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota), |
| 7126 | .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int), | 7127 | .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int), |
| 7127 | .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int), | 7128 | .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int), |
| 7128 | .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file), | 7129 | .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file), |
| ... | @@ -7437,7 +7438,7 @@ fn builtinCall( | ... | @@ -7437,7 +7438,7 @@ fn builtinCall( |
| 7437 | }, | 7438 | }, |
| 7438 | .Vector => { | 7439 | .Vector => { |
| 7439 | const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{ | 7440 | const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{ |
| 7440 | .lhs = try comptimeExpr(gz, scope, .{ .ty = .u32_type }, params[0]), | 7441 | .lhs = try comptimeExpr(gz, scope, .{ .coerced_ty = .u32_type }, params[0]), |
| 7441 | .rhs = try typeExpr(gz, scope, params[1]), | 7442 | .rhs = try typeExpr(gz, scope, params[1]), |
| 7442 | }); | 7443 | }); |
| 7443 | return rvalue(gz, rl, result, node); | 7444 | return rvalue(gz, rl, result, node); |
src/Sema.zig+9-26| ... | @@ -1464,26 +1464,6 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | ... | @@ -1464,26 +1464,6 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 1464 | return error.AnalysisFail; | 1464 | return error.AnalysisFail; |
| 1465 | } | 1465 | } |
| 1466 | 1466 | ||
| 1467 | /// Appropriate to call when the coercion has already been done by result | ||
| 1468 | /// location semantics. Asserts the value fits in the provided `Int` type. | ||
| 1469 | /// Only supports `Int` types 64 bits or less. | ||
| 1470 | /// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty. | ||
| 1471 | fn resolveAlreadyCoercedInt( | ||
| 1472 | sema: *Sema, | ||
| 1473 | block: *Block, | ||
| 1474 | src: LazySrcLoc, | ||
| 1475 | zir_ref: Zir.Inst.Ref, | ||
| 1476 | comptime Int: type, | ||
| 1477 | ) !Int { | ||
| 1478 | comptime assert(@typeInfo(Int).Int.bits <= 64); | ||
| 1479 | const air_inst = sema.resolveInst(zir_ref); | ||
| 1480 | const val = try sema.resolveConstValue(block, src, air_inst); | ||
| 1481 | switch (@typeInfo(Int).Int.signedness) { | ||
| 1482 | .signed => return @intCast(Int, val.toSignedInt()), | ||
| 1483 | .unsigned => return @intCast(Int, val.toUnsignedInt()), | ||
| 1484 | } | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | fn resolveAlign( | 1467 | fn resolveAlign( |
| 1488 | sema: *Sema, | 1468 | sema: *Sema, |
| 1489 | block: *Block, | 1469 | block: *Block, |
| ... | @@ -3380,7 +3360,7 @@ fn storeToInferredAllocComptime( | ... | @@ -3380,7 +3360,7 @@ fn storeToInferredAllocComptime( |
| 3380 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 3360 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 3381 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3361 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3382 | const src = inst_data.src(); | 3362 | const src = inst_data.src(); |
| 3383 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); | 3363 | const quota = @intCast(u32, try sema.resolveInt(block, src, inst_data.operand, Type.u32)); |
| 3384 | if (sema.branch_quota < quota) | 3364 | if (sema.branch_quota < quota) |
| 3385 | sema.branch_quota = quota; | 3365 | sema.branch_quota = quota; |
| 3386 | } | 3366 | } |
| ... | @@ -5080,11 +5060,11 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -5080,11 +5060,11 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 5080 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5060 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5081 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 5061 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5082 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 5062 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5083 | const len = try sema.resolveAlreadyCoercedInt(block, len_src, extra.lhs, u32); | 5063 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.u32); |
| 5084 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); | 5064 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); |
| 5085 | try sema.checkVectorElemType(block, elem_type_src, elem_type); | 5065 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 5086 | const vector_type = try Type.Tag.vector.create(sema.arena, .{ | 5066 | const vector_type = try Type.Tag.vector.create(sema.arena, .{ |
| 5087 | .len = len, | 5067 | .len = @intCast(u32, len), |
| 5088 | .elem_type = elem_type, | 5068 | .elem_type = elem_type, |
| 5089 | }); | 5069 | }); |
| 5090 | return sema.addType(vector_type); | 5070 | return sema.addType(vector_type); |
| ... | @@ -11341,7 +11321,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -11341,7 +11321,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11341 | const abi_align = if (inst_data.flags.has_align) blk: { | 11321 | const abi_align = if (inst_data.flags.has_align) blk: { |
| 11342 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 11322 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 11343 | extra_i += 1; | 11323 | extra_i += 1; |
| 11344 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u32); | 11324 | const abi_align = try sema.resolveInt(block, .unneeded, ref, Type.u32); |
| 11325 | break :blk @intCast(u32, abi_align); | ||
| 11345 | } else 0; | 11326 | } else 0; |
| 11346 | 11327 | ||
| 11347 | const address_space = if (inst_data.flags.has_addrspace) blk: { | 11328 | 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 | ... | @@ -11353,13 +11334,15 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11353 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { | 11334 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { |
| 11354 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 11335 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 11355 | extra_i += 1; | 11336 | extra_i += 1; |
| 11356 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); | 11337 | const bit_offset = try sema.resolveInt(block, .unneeded, ref, Type.u16); |
| 11338 | break :blk @intCast(u16, bit_offset); | ||
| 11357 | } else 0; | 11339 | } else 0; |
| 11358 | 11340 | ||
| 11359 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 11341 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 11360 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 11342 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 11361 | extra_i += 1; | 11343 | extra_i += 1; |
| 11362 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); | 11344 | const host_size = try sema.resolveInt(block, .unneeded, ref, Type.u16); |
| 11345 | break :blk @intCast(u16, host_size); | ||
| 11363 | } else 0; | 11346 | } else 0; |
| 11364 | 11347 | ||
| 11365 | if (host_size != 0 and bit_offset >= host_size * 8) { | 11348 | if (host_size != 0 and bit_offset >= host_size * 8) { |
src/type.zig+1| ... | @@ -5063,6 +5063,7 @@ pub const Type = extern union { | ... | @@ -5063,6 +5063,7 @@ pub const Type = extern union { |
| 5063 | }; | 5063 | }; |
| 5064 | 5064 | ||
| 5065 | pub const @"u8" = initTag(.u8); | 5065 | pub const @"u8" = initTag(.u8); |
| 5066 | pub const @"u16" = initTag(.u16); | ||
| 5066 | pub const @"u32" = initTag(.u32); | 5067 | pub const @"u32" = initTag(.u32); |
| 5067 | pub const @"u64" = initTag(.u64); | 5068 | pub const @"u64" = initTag(.u64); |
| 5068 | 5069 |