stage2: rework ZIR/TZIR for optionals and error unions

* fix wrong pointer const-ness when unwrapping optionals
 * allow grouped expressions and orelse as lvalues
 * ZIR for unwrapping optionals: no redundant deref
   - add notes to please don't use rlWrapPtr, this function should be
     deleted
 * catch and orelse: better ZIR for non-lvalue: no redundant deref;
   operate entirely on values. lvalue case still works properly.
   - properly propagate the result location into the target expression
 * Test harness: better output when tests fail due to compile errors.
 * TZIR: add instruction variants. These allow fewer TZIR instructions to
   be emitted from zir_sema. See the commit diff for per-instruction
   documentation.
   - is_null
   - is_non_null
   - is_null_ptr
   - is_non_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload
   - optional_payload_ptr
 * TZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional
 * ZIR: add instruction variants. These allow fewer ZIR instructions to
   be emitted from astgen. See the commit diff for per-instruction
   documentation.
   - is_non_null
   - is_null
   - is_non_null_ptr
   - is_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload_safe
   - optional_payload_unsafe
   - optional_payload_safe_ptr
   - optional_payload_unsafe_ptr
   - err_union_payload_safe
   - err_union_payload_unsafe
   - err_union_payload_safe_ptr
   - err_union_payload_unsafe_ptr
   - err_union_code
   - err_union_code_ptr
 * ZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional_safe
   - unwrap_optional_unsafe
   - unwrap_err_safe
   - unwrap_err_unsafe
   - unwrap_err_code
This commit is contained in:
Andrew Kelley
2021-01-18 19:17:23 -07:00
parent 3c2a9220ed
commit ecc246efa2
7 changed files with 358 additions and 107 deletions
+24 -8
View File
@@ -73,9 +73,18 @@ pub const Inst = struct {
condbr,
constant,
dbg_stmt,
isnonnull,
isnull,
iserr,
// ?T => bool
is_null,
// ?T => bool (inverted logic)
is_non_null,
// *?T => bool
is_null_ptr,
// *?T => bool (inverted logic)
is_non_null_ptr,
// E!T => bool
is_err,
// *E!T => bool
is_err_ptr,
booland,
boolor,
/// Read a value from a pointer.
@@ -93,7 +102,10 @@ pub const Inst = struct {
not,
floatcast,
intcast,
unwrap_optional,
// ?T => T
optional_payload,
// *?T => *T
optional_payload_ptr,
wrap_optional,
xor,
switchbr,
@@ -111,14 +123,18 @@ pub const Inst = struct {
.ret,
.bitcast,
.not,
.isnonnull,
.isnull,
.iserr,
.is_non_null,
.is_non_null_ptr,
.is_null,
.is_null_ptr,
.is_err,
.is_err_ptr,
.ptrtoint,
.floatcast,
.intcast,
.load,
.unwrap_optional,
.optional_payload,
.optional_payload_ptr,
.wrap_optional,
=> UnOp,