-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Frontend] Add support for named target buffer in -verify expected lines #84336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clang, which heavily inspired Swift's -verify flag, supports naming other files like so: ``` // expected-error@some-header.h:11:22{{some error}} ``` Swift hasn't had the same need for this, because of the lack of textual header inclusion (where the same header file can emit different diagnostics depending on where it's included). The lack of this functionality has made it impossible to use -verify in cases where diagnostics are emitted in a macro however, since the expected-lines can't be placed inside the generated macro buffer. Now the main Swift file can refer to diagnostics inside these generated buffers by naming the buffers. The generated names aren't pretty, but the identifier is stable, unique and it works. Here is an example of what it can look like: ``` // expected-error@@__swiftmacro_4main3bar.swift:10:15{{no exact matches in call to initializer}} // expected-note@+1{{in expansion of macro 'foo' on global function 'bar' here}} @foo func bar() {} ``` The double "@" is a result of the buffer name starting with an @, which is unfortunate but is how the mangling scheme works for macro buffer names.
The previous commit added support for checking diagnostics in other buffers, enabling diagnostic verification for e.g. macro expansions. Because the diagnostics are in a different buffer, there is no error for not marking them as "expected". This commit expands the scope to include generated sources originating in code in any checked buffer, to help make sure that errors aren't accidentally missed.
Now that the DiagnosticsVerifier supports verifying diagnostics in macro expansions it's time to enable this test case.
@swift-ci please smoke test |
Xazax-hun
approved these changes
Sep 17, 2025
This refactors the parsing of "expected-*" lines to a separate function, to enable recursive parsing in the next commit.
Since freestanding macro expansion buffer names include the line number of their invocation, it can become quite fiddly to try to update a test file with multiple macro expansions. This adds the option to use an expected-expansion block and use a relative line number, nesting other expected diagnostic statements inside this block. Example syntax: ```swift let myVar = #myMacro /* expected-expansion@-2:1{{ expected-error@13:37{{I can't believe you've done this}} expected-note@14:38{{look at this and ponder your mistake}} }} */ ```
@swift-ci please smoke test |
When the syntax `expected-error@:42{{}}` was used, this would accidentally trigger "absolute line" mode, despite not specifying a line, resulting in the target line always being line 0.
@swift-ci please smoke test |
When this function was extracted from a for loop, continue was mapped to return, but these nested continues should remain.
@swift-ci please smoke test |
This test case failed in CI when using a strict diff, because the output also contained the text "swift runtime: unknown backtracing setting 'warnings'". Switch to using FileCheck to ignore this output.
@swift-ci please smoke test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements support for testing diagnostics in macro expansions using the
-verify
flag.