Fixes
```
.../swift/lib/ASTGen/Sources/ASTGen/Types.swift:359:29: warning: 'specifier' is deprecated: Access the specifiers list instead
if let specifier = node.specifier {
^
```
TopLevelCodeDecl::getEndLoc() should return the token location of the
last token. If the last token is a string literal or a regex literal,
it should be the location of the literal token.
When building ASTGen and SIL using the Swift 6.0 compiler the compiler emits
diagnostics about various retroactive conformances. Since Swift code in the
compiler needs to remain compatible with the Swift 5.10 compiler for now, use
module qualification syntax to suppress the warning. I've also included the
`@retroactive` attribute in a comment to document the retroactive conformance
acknowledgement more explicitly.
NFC.
In the warning about having no try/throw within the body of a do..catch,
replace the walk of the inactive clauses of IfConfigDecl with a syntactic
check of inactive and unparsed regions to look for 'try' and 'throw'
keywords.
This both eliminates a dependency on IfConfigDecl and expands the
usefulness of this warning suppression to unparsed code.
Rather than walking into the inactive regions of IfConfigDecls looking for
references to a declaration before we diagnose it, go to the syntax
tree and look through inactive *and unparsed* regions for identifier
tokens that match. If we find one, suppress the diagnostic.
This reduces our dependency on IfConfigDecl in the AST, and also makes
the same suppression work with code in unparsed regions that had no
representation in IfConfigDecl.
Rather than potentially computing ConfiguredRegions multiple times in
ASTGen and other queries, cache the result in the ExportedSourceFile.
This is temporary; we should bring up a Swift equivalent to the
request-evaluator (or bridge to the C++ one) to manage state like
this.
Some requirement machine work
Rename requirement to Value
Rename more things to Value
Fix integer checking for requirement
some docs and parser changes
Minor fixes
Replace the existing C++ implementation of extractInlinableText with
a new implementation based on swift-syntax. It uses SwiftIfConfig to
remove inactive regions (with a special mode), and a new compiler-only
entrypoint in the library to remove comments and `#sourceLocation`.
Replace the C++ implementation of #if condition operator folding,
validation, and evaluation with the corresponding facilities in the
SwiftIfConfig library.
Leave the C++ implementation in place for now to permit the compiler
to continue building without swift-syntax.
Switch to the new `canImport` API that includes TokenSyntax nodes for each
import path, so we can provide better source locations. We no longer need
to stuff a random source location into `CompilerBuildConfiguration`.
Make use of `ConfiguredRegions.isActive(_:)` directly instead of going
through the older entrypoint.
When parser validation is enabled, we currently can end up with duplicated
diagnostics from canImport. This is going to require some requestification
to address.
Allow any declaration to be marked with `@unsafe`, meaning that it
involves unsafe code. This also extends to C declarations marked with
the `swift_attr("unsafe")` attribute.
Under a separate experimental flag (`DisallowUnsafe`), diagnose any
attempt to use an `@unsafe` declaration or any unsafe language feature
(such as `unowned(unsafe)`, `@unchecked Sendable`). This begins to
define a "safe" mode in Swift that prohibits memory-unsafe constructs.
Wherever there is a syntax collection in the syntax tree that can involve
an `#if` clause, evaluate the `#if` conditions to find the active clause,
then recurse into the active clause (if one exists) to "flatten" the
translated collection to only contain active elements.
Note that this does not yet handle #if for postfix expressions.
Unlike all of the other build configuration checks, `canImport` has
side effects including the emission of various diagnostics. Thread a
source location through here so the diagnostics end up on the right
line.
The SIL coverage map generation depends on the locations of the `#endif`
directives, but the mapping from SwiftIfConfig's configured regions wasn't
producing them. The information is implicitly available in the
SwiftIfConfig configured regions, so reconstitute it as we translate
regions.
The SwiftIfConfig library provides APIs for evaluating and extracting
the active #if regions in source code. Use its "configured regions" API
along with the ASTContext-backed build configuration to reimplement the
extraction of active/inactive regions from the source.
This approach has the benefit of being effectively stateless: where the
existing solution relies on the C++ parser recording all of the `#if`
clauses it sees as it is parsing (and then might have to sort them later),
this version does a scan of source to collect the list without requiring
any other state. The newer implementation is also conceptually cleaner,
and can be shared with other clients that have their own take on the
build configuration.
The primary client of this information is the SourceKit request that
identifies "inactive" regions within the source file, which IDEs can
use to grey out inactive code within the current build configuration.
There is also some profiling information that uses it. Those clients
should be unaffected by this under-the-hood change.
For the moment, I'm leaving the old code path in place for compiler
builds that don't have swift-syntax. This should be considered
temporary, and that code should be removed in favor of request'ifying
this function and removing the incrementally-built state entirely.
This concrete implementation of the BuildConfiguration allows the use of
the SwiftIfConfig library's APIs where the build configuration comes from
the compiler itself.
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.
@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.
rdar://122707697