Ensure predicate diagnostics contain source information when possible #1025
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.
#Predicate
currently performs its transformation in two passes over the AST:flatMap
(ex.foo?.bar
-->foo.flatMap { $0.bar }
)PredicateExpression
builder calls (ex.foo.bar()
-->PredicateExpressions.build_bar(PredicateExpressions.build_Arg(foo))
)Unfortunately, performing the rewrite in Step 1 creates a new AST that lacks all source information from the original code in the source file. This means that when diagnostics are emitted during pass 2, the diagnostics are detached from any source locations and only appear as standalone messages in the build log which makes for a challenging debugging experience.
After talking with the swift-syntax folks, in the fullness of time we will need to rewrite the
#Predicate
implementation to perform its rewrite in a single pass to retain all source location information. However, until we can perform such a rewrite (which is not trivial) this PR helps by "skipping" step 1 when optional chaining is not present. For predicates that don't contain optional chaining, pass 1 will now just pass on the original AST with source information so that pass 2 emits diagnostics with attached locations. This change also updates our unit testing infrastructure to fail if any diagnostics are emitted without attached source locations so that we'll pick up issues like this in CI in the future.Note: I also had to switch the package dependency from
[email protected]
toswift-syntax@main
. This is fine because when building Foundation in the toolchain, we build againstmain
anyways and this mirrors how we build againstswift-foundation-icu
.Resolves rdar://125125964