Commit Graph

725 Commits

Author SHA1 Message Date
Erik Eckstein
8935517eae ASTGen: fix a compiler warning
Fixes
```
.../swift/lib/ASTGen/Sources/ASTGen/Types.swift:359:29: warning: 'specifier' is deprecated: Access the specifiers list instead
    if let specifier = node.specifier {
                            ^
```
2024-10-09 10:52:41 +02:00
Rintaro Ishizaki
0df94f1551 [ASTGen] Fix end location of TopLevelCodeDecl
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.
2024-10-08 15:09:35 -07:00
Rintaro Ishizaki
e7a2102203 [ASTGen] Generate UnresolvedSpecializeExpr 2024-10-08 09:47:12 -07:00
Rintaro Ishizaki
834d98dca8 [ASTGen] Genrate InOutExpr 2024-10-08 09:47:11 -07:00
Rintaro Ishizaki
09f49b0c87 [ASTGen] Generate FloatLiteralExpr 2024-10-08 09:46:56 -07:00
Rintaro Ishizaki
7d9ba2d36d [ASTGen] Generate RegexLiteralExpr, SubscriptExpr, and SuperRefExpr 2024-10-08 09:34:17 -07:00
Rintaro Ishizaki
ea2b8ff749 [ASTGen] Remove all #if RESILIENT_SWIFT_SYNTAX
Building ASTGen with resilient swift-syntax modules is not a thing
anymore. `RESILIENT_SWIFT_SYNTAX` is never used.
2024-10-06 15:56:51 -07:00
Rintaro Ishizaki
d8cbdc35c3 Merge pull request #76843 from rintaro/cmake-astgen-cxxinterop
[CMake] Reorganize CMakeLists.txt for ASTGen
2024-10-03 10:51:08 -07:00
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
Rintaro Ishizaki
d480761a9c [CMake] Sink add_pure_swift_host_library call into actual source dirs
Instead of doing everything in lib/ASTGen/CMakeLists.txt
2024-10-02 19:35:45 -07:00
Rintaro Ishizaki
b3b7d35edc [ASTGen] Rename macro related @_cdecl functions to swift_Macros_*
Rename @_cdecl name of functions moved to swiftMacros module.
Also move those function decls to dedicated 'Macros.h' header.
2024-10-02 15:22:17 -07:00
Rintaro Ishizaki
134c0a1bdc [ASTGen] Move macros related code to a new dedicated module
Introduce 'swiftMacros' module.
2024-10-02 15:22:16 -07:00
Allan Shortlidge
6f91b4156c ASTGen/SIL: Suppress retroactive conformance warnings.
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.
2024-10-01 17:07:03 -07:00
Nate Chandler
66e6c59681 [Features] Added CoroutineAccessors. 2024-09-26 18:10:38 -07:00
Nate Chandler
053e79ed64 [ASTGen] Added feature-mapping for ref bindings. 2024-09-26 18:10:38 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Meghana Gupta
e61d87c01c Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations 2024-09-09 22:02:42 -07:00
Doug Gregor
42809af51e Merge pull request #76327 from DougGregor/suppress-warnings-in-inactive-regions-without-ifconfigdecl
Suppress certain warnings in inactive `#if` regions without relying on `IfConfigDecl`
2024-09-07 10:16:20 -07:00
Doug Gregor
48db8767b5 Suppress the warning for inactive try/throw in do..catch
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.
2024-09-06 22:38:04 -07:00
Doug Gregor
4a4c0f68f1 Teach the "unused variable / value" diagnostics to use SwiftIfConfig
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.
2024-09-06 22:14:52 -07:00
Doug Gregor
66dba4aa46 Use a cached copy of ConfiguredRegions within an ExportedSourceFile
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.
2024-09-06 21:22:05 -07:00
Alex Hoppen
bf96347d63 Merge pull request #76298 from ahoppen/no-sending-args
[ASTGen] Don’t map `sendingArgsAndResults`
2024-09-06 13:04:16 -07:00
Alex Hoppen
530cff15d0 [ASTGen] Don’t map sendingArgsAndResults
The corresponding evolution proposal has been accepted and the experimental feature no longer exists in swift-syntax.
2024-09-05 14:52:15 -07:00
Alejandro Alonso
bfffd7e119 Set the param kind in ASTGen 2024-09-04 15:13:47 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
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
2024-09-04 15:13:25 -07:00
Doug Gregor
a73711ef4b Implement extractInlinableText with swift-syntax
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`.
2024-08-30 16:43:41 -07:00
Doug Gregor
256f39e5ee Use the SwiftIfConfig library for evaluating #if conditions.
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.
2024-08-24 21:31:40 -07:00
Doug Gregor
0e72c53f02 [SwiftIfConfig] Adopt updated APIs to for build configuration handling
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.
2024-08-23 22:39:40 -07:00
Doug Gregor
c241e782e0 Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-22 22:33:53 -07:00
Doug Gregor
fc5ba4c7d5 Revert "Use SwiftIfConfig to determine where to emit new parser diagnostics"
This reverts commit 1da2631c4e.
2024-08-22 09:22:20 -07:00
Doug Gregor
e27f19520c Merge pull request #75937 from DougGregor/astgen-swiftifconfig 2024-08-21 06:34:17 -07:00
Doug Gregor
afd365b53a Make CompilerBuildConfiguration a struct again 2024-08-20 22:12:13 -07:00
Doug Gregor
dfe17e4d39 Be consistent about deallocating memory allocated from C++ in C++
Fixes a crash on Windows due to mismatched allocators.
2024-08-20 22:12:12 -07:00
Doug Gregor
cccf6c1114 Introduce @unsafe and the ability to prohibit use of unsafe declarations
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.
2024-08-19 14:33:07 -07:00
Doug Gregor
1da2631c4e Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-17 22:48:18 -07:00
Doug Gregor
0f2cedb92b [ASTGen] Implement #if config handling using the SwiftIfConfig library
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.
2024-08-17 22:48:18 -07:00
Hamish Knight
55aed16ee6 Requestify FallthroughStmt source and destination lookup
Follow a similar pattern to BreakTargetRequest
and ContinueTargetRequest.
2024-08-14 19:59:05 +01:00
Mateus Rodrigues
ac57e61278 Merge branch 'main' into trailing-comma 2024-08-06 09:34:43 -03:00
Doug Gregor
cfd0a3fc53 Thread a source location through canImport evaluation in CompilerBuildConfiguration
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.
2024-08-04 05:58:53 -07:00
Doug Gregor
a844f4fa0b Free memory allocated in Swift from Swift, not C++ 2024-08-02 10:04:29 -07:00
Doug Gregor
ddbbb5a71e Address code review comments and build failure 2024-08-02 10:04:28 -07:00
Doug Gregor
ca588b7aea Insert #endif directives into #if config ranges list produced by SwiftIfConfig
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.
2024-08-02 10:04:27 -07:00
Doug Gregor
d06e40877f Re-implement SourceFile::getIfConfigClauseRanges on top of SwiftIfConfig
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.
2024-08-02 10:04:27 -07:00
Doug Gregor
5c3b7777e7 Implement a SwiftIfConfig.BuildConfiguration that queries the ASTContext
This concrete implementation of the BuildConfiguration allows the use of
the SwiftIfConfig library's APIs where the build configuration comes from
the compiler itself.
2024-08-02 10:04:26 -07:00
Kai Lau
e561d3d446 [ASTGen] Update for new FixIt.Change API in Swift-Syntax
- covered the new case in exhaustive switch statements
2024-07-31 01:01:57 -07:00
Michael Gottesman
34195ff213 Merge pull request #74610 from gottesmm/pr-324fd70c13e87a329334341aae4667f2d1be152c
[sending] Remove transferring.
2024-07-02 14:02:18 -07:00
Xiaodi Wu
e1f537107f Merge branch 'main' into trailing-comma 2024-06-29 16:36:06 -04:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
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
2024-06-27 09:44:04 -07:00
Rintaro Ishizaki
5ebd715a2a Merge pull request #73725 from rintaro/macros-inproc-plugin
[Macros] In-process plugin server
2024-06-26 06:33:38 -07:00