0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/lib
Cody Tapscott d060cbbec7 stage2: Keep error return traces alive when storing to const
This change extends the "lifetime" of the error return trace associated
with an error to continue throughout the block of a `const` variable
that it is assigned to.

This is necessary to support patterns like this one in test_runner.zig:
```zig
const result = foo();
if (result) |_| {
    // ... success logic
} else |err| {
    // `foo()` should be included in the error trace here
    return error.TestFailed;
}
```

To make this happen, the majority of the error return trace popping logic
needed to move into Sema, since `const x = foo();` cannot be examined
syntactically to determine whether it modifies the error return trace. We
also have to make sure not to delete pertinent block information before it
makes it to Sema, so that Sema can pop/restore around blocks correctly.

* Why do this only for `const` and not `var`? *

There is room to relax things for `var`, but only a little bit. We could
do the same thing we do for const and keep the error trace alive for the
remainder of the block where the *assignment* happens. Any wider scope
would violate the stack discipline for traces, so it's not viable.

In the end, I decided the most consistent behavior for the user is just
to kill all error return traces assigned to a mutable `var`.
History 2022-10-21 12:40:29 -07:00
..
compiler_rt all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
docs Merge pull request #13055 from alichraghi/m2m 2022-10-18 14:42:55 -04:00
include update C headers to LLVM 15 rc3 2022-08-29 15:14:58 -07:00
init-exe init-exe template: add flushing to the buffered writer 2022-08-04 21:12:42 +02:00
init-lib flatten lib/std/special and improve "pkg inside another" logic 2022-05-06 22:41:00 -07:00
libc update mingw-w64 crt files to v10.0.0 2022-10-11 01:05:42 -07:00
libcxx update libcxx to LLVM 15.0.3 2022-10-18 10:18:09 -07:00
libcxxabi update libcxxabi to LLVM 15 2022-08-04 18:02:01 -07:00
libunwind update libunwind to LLVM 15 2022-08-04 18:09:10 -07:00
std UEFI: Querying memory map size with no allocation 2022-10-21 12:17:41 +02:00
tsan update libcxx, libcxxabi, libunwind, and tsan to llvm 13 rc1 2021-08-16 23:32:13 -07:00
build_runner.zig stage2: implement referenced by trace for error messages 2022-09-15 00:50:18 +03:00
c.zig Merge pull request #11747 from Luukdegram/compiler-rt 2022-10-17 18:12:22 -04:00
compiler_rt.zig Merge pull request #11747 from Luukdegram/compiler-rt 2022-10-17 18:12:22 -04:00
ssp.zig std: add return address parameter to panic fn 2022-09-20 19:05:00 -07:00
test_runner.zig stage2: Keep error return traces alive when storing to const 2022-10-21 12:40:29 -07:00