Commit Graph

13 Commits

Author SHA1 Message Date
Hamish Knight
b9b2cb25c2 [Basic] Always dump message to stderr in _abortWithMessage
This allows it to be seen while e.g attached with a debugger.
2025-05-30 16:08:37 +01:00
Hamish Knight
be8604959e [Basic] Switch ASSERT and friends to _abortWithMessage
Ensure the message gets printed to the pretty stack trace, allowing
it to be picked up by CrashReporter.
2025-05-19 20:55:01 +01:00
Hamish Knight
a6e94ab0bd [Basic] Fallback to dumping to stderr when backtracing is disabled
Make sure we still output the error message when pretty backtracing
is disabled.
2025-05-19 20:55:01 +01:00
Hamish Knight
d672f750e7 [Basic] Rename abortWithPrettyStackTraceMessage to ABORT
Turn it into a wrapping macro that includes the file location, and
move into `Assertions.h`.
2025-05-19 20:55:01 +01:00
Hamish Knight
92641253f7 [Basic] NFC: Remove ASSERT_help from header
It's not clear this is a useful utility to expose since it will only
print the message once.
2025-05-19 20:55:01 +01:00
Tim Kientzle
e5376439c3 Correctly obey NDEBUG for CONDITIONAL_ASSERT
It looks like a piece of an old experiment never got removed, which
broke the intended behavior here.
2024-08-26 15:52:34 -07:00
Tim Kientzle
55663f6791 Merge branch 'main' into tbkka-assertions-3 2024-07-10 14:20:50 -07:00
Tim Kientzle
50b2b1bcdc Only print the last component of the filename
In particular, on Windows MSVC, the ASSERT macros
use `__FILE__` (with the full pathname) instead of
`__FILE_NAME__` (with only the last component).
2024-06-25 15:18:39 -07:00
Erik Eckstein
1f29622f08 Assertions: display the assertion help hint only once and after the assertion message
It's more readable if the first thing which is printed is the actual assertion message
2024-06-25 14:16:22 +02:00
Slava Pestov
b366ae238c Basic: Use llvm streams instead of iostream in Assertions.cpp 2024-06-22 08:53:22 -04:00
Tim Kientzle
967fde0750 Minor improvements to new ASSERT macros
Three minor changes:
* Remove unneeded stdint.h inclusion
* Use __FILE_NAME__ instead of __FILE__ to reduce code size
* Write location as "file:line" for better compatibility with existing tools
2024-06-20 11:34:36 -07:00
Tim Kientzle
37e5f30d0b Add some basic assertion handling control options 2024-05-16 15:04:49 -07:00
Tim Kientzle
5b49a04ddc New assertions support
This adds three new assertion macros:
* `ASSERT` - always compiled in, always checked
* `CONDITIONAL_ASSERT` - always compiled in, checked whenever the `-compiler-assertions` flag is provided
* `DEBUG_ASSERT` - only compiled into debug builds, always checked when compiled in  (functionally the same as Standard C `assert`)

The new `-compiler-assertions` flag is recognized by both `swift-frontend` and
`swiftc`.

The goal is to eventually replace every use of `assert` in the compiler with one of the above:
* Most assertions will use `ASSERT` (most assertions should always be present and checked, even in release builds)
* Expensive assertions can use `CONDITIONAL_ASSERT` to be suppressed by default
* A few very expensive and/or brittle assertions can use `DEBUG_ASSERT` to be compiled out of release builds

This should:
* Improve quality by catching errors earlier,
* Accelerate compiler triage and debugging by providing more accurate crash dumps by default, and
* Allow compiler engineers and end users alike to add `-compiler-assertions` to get more accurate failure diagnostics with any compiler
2024-05-16 11:38:00 -07:00