From 05947ea870f95ab90a75e174079492f546baaf72 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Mar 2022 22:19:06 -0700 Subject: stage2: implement `@intToError` with safety This commit introduces a new AIR instruction `cmp_lt_errors_len`. It's specific to this use case for two reasons: * The total number of errors is not stable during semantic analysis; it can only be reliably checked when flush() is called. So the backend that is lowering the instruction must emit a relocation of some kind and then populate it during flush(). * The fewer AIR instructions in memory, the better for compiler performance, so we squish complex meanings into AIR tags without hesitation. The instruction is implemented only in the LLVM backend so far. It does this by creating a simple function which is gutted and re-populated with each flush(). AstGen now uses ResultLoc.coerced_ty for `@intToError` and Sema does the coercion. --- src/codegen/c.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 38a105c172..19556fe8c4 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1767,7 +1767,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .cmp_eq => try airEquality(f, inst, "((", "=="), .cmp_neq => try airEquality(f, inst, "!((", "!="), - .cmp_vector => return f.fail("TODO: C backend: implement binary op for tag '{s}'", .{@tagName(Air.Inst.Tag.cmp_vector)}), + .cmp_vector => return f.fail("TODO: C backend: implement cmp_vector", .{}), + .cmp_lt_errors_len => return f.fail("TODO: C backend: implement cmp_lt_errors_len", .{}), // bool_and and bool_or are non-short-circuit operations .bool_and => try airBinOp(f, inst, " & "), -- cgit v1.2.3