| author | |
| committer | |
| log | ebafdb958c1aa6b41c28fc7d45f44e38a69a3bd5 |
| tree | f61152ba5bbd2fe77fbfcdedc9e876a5d982550b |
| parent | 633fe41a2c2310d8cfab53ee9d87bb50ac4efc41 |
Instead, use ResultLoc.none to allow for the expression type to be
inferred [^1]. This effectively moves the type coercion to Sema, in
order to turn comptime values into usable values for the backends to
consume. Right now the coercion is applies as comptime_int -> usize and
comptime_float -> f64, as an arbitrary choice.
[^1]: https://github.com/ziglang/zig/blob/9f25c8140cb859fcea7023362afcb29b1e4df41f/src/AstGen.zig#L207-L2082 files changed, 9 insertions(+), 2 deletions(-)
src/AstGen.zig+1-1| ... | ... | @@ -6842,7 +6842,7 @@ fn asmExpr( |
| 6842 | 6842 | const name = try astgen.identAsString(symbolic_name); |
| 6843 | 6843 | const constraint_token = symbolic_name + 2; |
| 6844 | 6844 | const constraint = (try astgen.strLitAsString(constraint_token)).index; |
| 6845 | const operand = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input_node].lhs); | |
| 6845 | const operand = try expr(gz, scope, .none, node_datas[input_node].lhs); | |
| 6846 | 6846 | inputs[i] = .{ |
| 6847 | 6847 | .name = name, |
| 6848 | 6848 | .constraint = constraint, |
src/Sema.zig+8-1| ... | ... | @@ -10304,7 +10304,14 @@ fn zirAsm( |
| 10304 | 10304 | const name = sema.code.nullTerminatedString(input.data.name); |
| 10305 | 10305 | _ = name; // TODO: use the name |
| 10306 | 10306 | |
| 10307 | arg.* = sema.resolveInst(input.data.operand); | |
| 10307 | const uncasted_arg = sema.resolveInst(input.data.operand); | |
| 10308 | const uncasted_arg_ty = sema.typeOf(uncasted_arg); | |
| 10309 | switch (uncasted_arg_ty.zigTypeTag()) { | |
| 10310 | .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src), | |
| 10311 | .ComptimeFloat => arg.* = try sema.coerce(block, Type.initTag(.f64), uncasted_arg, src), | |
| 10312 | else => arg.* = uncasted_arg, | |
| 10313 | } | |
| 10314 | ||
| 10308 | 10315 | const constraint = sema.code.nullTerminatedString(input.data.constraint); |
| 10309 | 10316 | needed_capacity += constraint.len / 4 + 1; |
| 10310 | 10317 | inputs[arg_i] = constraint; |