aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-09-18 14:49:18 +0100
committermlugg <mlugg@mlugg.co.uk>2023-09-23 22:01:08 +0100
commit09a57583a4ccce30603ffc8d0e3d7359dc3cb978 (patch)
treeaab67cf7749a799ae9b236cd4f26bc9f115b82c5 /test/compile_errors.zig
parent01906a3ad8b792627e55551686c25d02fef64e98 (diff)
downloadzig-09a57583a4ccce30603ffc8d0e3d7359dc3cb978.tar.gz
zig-09a57583a4ccce30603ffc8d0e3d7359dc3cb978.zip
compiler: preserve result type information through address-of operator
This commit introduces the new `ref_coerced_ty` result type into AstGen. This represents a expression which we want to treat as an lvalue, and the pointer will be coerced to a given type. This change gives known result types to many expressions, in particular struct and array initializations. This allows certain casts to work which previously required explicitly specifying types via `@as`. It also eliminates our dependence on anonymous struct types for expressions of the form `&.{ ... }` - this paves the way for #16865, and also results in less Sema magic happening for such initializations, also leading to potentially better runtime code. As part of these changes, this commit also implements #17194 by disallowing RLS on explicitly-typed struct and array initializations. Apologies for linking these changes - it seemed rather pointless to try and separate them, since they both make big changes to struct and array initializations in AstGen. The rationale for this change can be found in the proposal - in essence, performing RLS whilst maintaining the semantics of the intermediary type is a very difficult problem to solve. This allowed the problematic `coerce_result_ptr` ZIR instruction to be completely eliminated, which in turn also simplified the logic for inferred allocations in Sema - thanks to this, we almost break even on line count! In doing this, the ZIR instructions surrounding these initializations have been restructured - some have been added and removed, and others renamed for clarity (and their semantics changed slightly). In order to optimize ZIR tag count, the `struct_init_anon_ref` and `array_init_anon_ref` instructions have been removed in favour of using `ref` on a standard anonymous value initialization, since these instructions are now virtually never used. Lastly, it's worth noting that this commit introduces a slightly strange source of generic poison types: in the expression `@as(*anyopaque, &x)`, the sub-expression `x` has a generic poison result type, despite no generic code being involved. This turns out to be a logical choice, because we don't know the result type for `x`, and the generic poison type represents precisely this case, providing the semantics we need. Resolves: #16512 Resolves: #17194
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig6
1 files changed, 2 insertions, 4 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 5cc5c36f3f..5f787683c4 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -207,10 +207,8 @@ pub fn addCases(ctx: *Cases) !void {
":1:38: note: declared comptime here",
":8:36: error: runtime-known argument passed to comptime parameter",
":2:41: note: declared comptime here",
- ":13:29: error: runtime-known argument passed to parameter of comptime-only type",
- ":3:24: note: declared here",
- ":12:35: note: struct requires comptime because of this field",
- ":12:35: note: types are not available at runtime",
+ ":13:32: error: unable to resolve comptime value",
+ ":13:32: note: initializer of comptime only struct must be comptime-known",
});
case.addSourceFile("import.zig",