9 Commits

Author SHA1 Message Date
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
ffb474e0b9 [Basic] NFC: Factor out _FILENAME_FOR_ASSERT macro 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
Slava Pestov
19a991c530 Basic: Handle missing __FILE_NAME__ on Windows 2024-06-22 08:53:22 -04:00
Slava Pestov
8ebd36e629 Basic: Fix operator precedence issues with ASSERT macro 2024-06-21 16:21:36 -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
bb8c96c2b9 Optimize for assertion success and assertions disabled 2024-05-17 09:30:03 -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