61 Commits

Author SHA1 Message Date
Doug Gregor
2a46916536 Reseat CompilerBuildConfiguration on top of StaticBuildConfiguration
Now that we have a per-ASTContext StaticBuildConfiguration, reimplement
(almost) everything in CompilerBuildConfiguration to sit on top of it.
Only canImport requires the full ASTContext, so that gets its own
implementation, as does one other operation that can produce an error.
Aside from more code sharing, this provides additional validation that
the StaticBuildConfiguration we build is complete and accurate.
2025-09-29 18:42:15 -07:00
Doug Gregor
3082b04b75 [Macros] Feed the static build configuration into macro expansions
Thread the static build configuration (formed from language options) in
to the macro plugin handler, which will serialize it for use in the
macro implementation. test this with a simple macro that checks
whether a particular custom configuration (set via `-D`) is enabled or
not.

This required some re-layering, sinking the logic for building a
StaticBuildConfiguration from language options down into a new
swiftBasicSwift library, which sits on top of the C++ swiftBasic and
provides Swift functionality for it. That can be used by the C++
swiftAST to cache the StaticBuildConfiguration on the ASTContext,
making it available for other parts of ASTGen.
2025-09-29 18:42:15 -07:00
Anthony Latsis
5620abbad8 Bridging: Bridge swift::CharSourceRange directly 2025-07-15 21:34:48 +01:00
Anthony Latsis
9001ce4687 Bridging: Bridge swift::SourceRange directly 2025-07-15 21:33:28 +01:00
Anthony Latsis
6eb5d7d857 Bridging: Bridge swift::SourceLoc directly 2025-07-15 21:33:06 +01:00
Anthony Latsis
f131fece3f [NFC] Bridging: Rework include caveats 2025-07-10 17:58:13 +01:00
Anthony Latsis
b803861257 Bridging: Rename USED_IN_CPP_SOURCE and define it in Basic/SwiftBridging.h 2025-07-10 17:58:13 +01:00
Anthony Latsis
38360fe625 ASTBridging: Bridge swift::DeclAttrKind directly 2025-06-19 18:11:39 +01:00
Anthony Latsis
7de8827169 BasicBridging: Turn BridgedOptional into a macro 2025-06-19 18:11:38 +01:00
Anthony Latsis
106d5f4461 {AST,Basic}Bridging: Use SWIFT_COMPUTED_PROPERTY 2025-06-16 19:11:32 +01:00
Anthony Latsis
08d71a46eb Basic, SIL: Include <swift/bridging> when avaiable instead of defining our own macros 2025-06-13 23:13:26 +01:00
Erik Eckstein
7f6fb74418 SILBridging: move BridgedInstruction.OptionalInt -> BridgedOptionalInt in BasicBridging.h 2025-05-15 21:29:02 +02:00
Anthony Latsis
ae70d384e0 [NFC] Basic: Restrict adoption mode to upcoming and experimental features 2025-03-11 01:15:33 +00:00
Anthony Latsis
6a3903bb53 Revert "Revert "Introduce adoption mode for Swift features""
This reverts commit 393c59c078.
2025-03-05 15:21:01 +00:00
Rintaro Ishizaki
393c59c078 Revert "Introduce adoption mode for Swift features" 2025-03-04 19:13:05 -08:00
Anthony Latsis
8dab67bcee Basic: Adjust feature macros for adoption mode 2025-03-04 13:43:28 +00:00
Rintaro Ishizaki
aae50a88c5 [ASTGen] Fix expanded macro buffer parsing and AST generation
Parse expanded buffer into dedicated syntax.

Also rename `BridgedGeneratedSourceFileKindAttribute` to
`BridgedGeneratedSourceFileKindAttributeFromClang` because C++ decl
(i.e. `GeneratedSourceInfo::Kind::AttributeFromClang`) was renamed a
while ago.
2025-02-21 09:56:36 -08:00
Rintaro Ishizaki
6ea6a31ec7 [ASTGen] Generate TopLevelCodeDecl for PatternBindingDecl
* Instead of hoisting VarDecl in the bridging functions, do it in
  ASTGen.
* Introduce `Decl::forEachDeclToHoist` to handle VarDecls in
  PatternBindingDecl, and EnumElementDecl in EnumCaseDecl.
* Intorduce `withBridgedSwiftClosure(closure:call:)` as a callback
  mechanism between Swift and C++
* In `generate(sourceFile:)`, instead of using `generate(codeBlockItem:)`
  handle `CodeBlockItemSyntax.Item` manually to handle `TLCD` wrapping
  and `VarDecl` hoisting.
* Make `generate(variableDecl:)` handle TLCD correctly.
2025-02-13 00:09:22 -08:00
Rintaro Ishizaki
ac2603cad6 Merge pull request #79168 from rintaro/astgen-tweaks
[ASTGen] Small followup tweaks after AvailableAttr
2025-02-05 16:48:35 -08:00
Rintaro Ishizaki
ebf7a421fd [Bridging] Add 'const' variations to BRIDGING_WRAPPER
Only for `AvailabilityMacroMap` for now.
2025-02-05 11:44:54 -08:00
Rintaro Ishizaki
1559b37c03 [Basic] Remove unnecessary 'const' from several briding functions 2025-02-05 10:37:56 -08:00
Rintaro Ishizaki
df2ada37df [ASTGen] Generate AvailableAttr
* Move `AvailabilitySpec` handling logic to AST, so they can be shared
  between libParse and ASTGen
* Requestify '-define-availability' arguments parsing and parse them
  with 'SwiftParser' according to the 'ParserASTGen' feature flag
* Implement 'AvailableAttr' generation in ASTGen
2025-02-04 23:40:01 -08:00
Rintaro Ishizaki
e153164677 [ASTGen] Handle '#sourceLocation' directives
Use `ExportedSourceFile.sourceLocationConverter.lineTable.virtualFiles`
to populate the information in `swift::SourceManger` and
`swift::SourceFile` when "parsing" with ASTGen
2024-11-21 08:23:08 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Rintaro Ishizaki
e566a746c8 [ASTGen] Support macro expanded buffer
* Make ExportedSourceFile hold any Syntax as the root node
* Move `ExportedSourceFileRequest::evaluate()` to `ParseRequests.cpp`
* Pass  the decl context and `GeneatedSourceFileInfo::Kind` to
  `swift_ASTGen_parseSourceFile()` to customize the parsing
* Make `ExportedSourceFile` to hold an arbitrary Syntax node
* Move round-trip checking into `ExportedSourceFileRequest::evaluate()`
* Split `parseSourceFileViaASTGen` completely from C++ parsing logic
  (in `ParseSourceFileRequest::evaluate()`)
* Remove 'ParserDiagnostics' experimental feature: Now that we have
  ParserASTGen mode which includes the swift-syntax parser diagnostics.
2024-11-05 11:00:33 -08:00
Hamish Knight
9d4a78678a [Sema] Add logic to diagnose regex feature availability
Add the necessary compiler-side logic to allow
the regex parsing library to hand back a set of
features for a regex literal, which can then be
diagnosed by ExprAvailabilityWalker if the
availability context isn't sufficient. No tests
as this only adds the necessary infrastructure,
we don't yet hand back the features from the regex
parsing library.
2024-10-28 17:09:47 +00:00
Erik Eckstein
ed67e36ce5 bridging: reduce #ifdef USED_IN_CPP_SOURCE in bridging headers
Especially avoid any constructors in `#ifdef USED_IN_CPP_SOURCE` blocks, because this breaks Windows ARM64.
2024-10-25 09:47:56 +02:00
Hiroshi Yamauchi
dedfb9e0ab Ensure that bridged types are indirectly returned on Windows ARM64
On Windows ARM64, how a struct value type is returned is sensitive to
conditions including whether a user-defined constructor exists,
etc. See

https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values

That caused a calling convention mismatch between the
non-USED_IN_CPP_SOURCE (Swift) side and the USE_IN_CPP_SOURCE (C++)
side and a crash.

Following https://github.com/swiftlang/swift/pull/76433 add
constructors to several bridged C++ struct/class types so that the
calling convention matches.

This is a partial fix for https://github.com/swiftlang/swift/issues/74866
2024-09-19 16:00:15 -07:00
Egor Zhdan
586ac0953c Merge pull request #76408 from swiftlang/egorzhdan/scs-owned-string
[cxx-interop][SwiftCompilerSources] Do not use `SWIFT_IMPORT_UNSAFE` with `BridgedOwnedString`
2024-09-16 20:00:20 +01:00
Rintaro Ishizaki
d7303d141c [Basic] Remove llvm::JSON C bridging
This was used for plugin message serialization, but it's migrated to
SwiftCompilerPluginMessageHandling JSON.
2024-09-12 12:04:28 -07:00
Egor Zhdan
35263ef9d6 [cxx-interop][SwiftCompilerSources] Do not use SWIFT_IMPORT_UNSAFE with BridgedOwnedString
`SWIFT_IMPORT_UNSAFE` is an escape hatch that can be used to make the Swift compiler ignore its usual safety heuristics for C++ types.

`BridgedOwnedString` fits into the definition of a self-contained C++ type in Swift: it manages the lifetimes of its own fields.

This removes the usages of `SWIFT_IMPORT_UNSAFE` for C++ functions that return `BridgedOwnedString`, and annotates `BridgedOwnedString` as a self-contained type.
2024-09-11 19:58:14 +01:00
Andrew Trick
22f01a956a [SwiftCompilerSources] add BridgedOStream and debugLog().
So we can trace optimizer passes using the same output stream as the
C++ passes and don't get garbled output.
2024-07-29 21:25:43 -07:00
Erik Eckstein
81005c18a2 SwiftCompilerSources: forward assertion and precondition failures to the assertion-handling in the C++ code base. 2024-06-25 14:14:43 +02:00
Anthony Latsis
de499d1060 [NFC] ASTGen: Refactor for recursive MemberTypeRepr representation 2024-02-09 17:23:40 +03:00
Ben Barham
d51c58a6f9 [Basic] hasFeature should succeed for promoted language features
Merge `$<Feature>` and `hasFeature` implementations.
  - `$<Feature>` did not support upcoming language features.
  - `hasFeature` did not support promoted language features and also
    didn't take into account `Options` in `Features.def`.

Remove `Options` entirely, it was always one of three cases:
  - `true`
  - `langOpts.hasFeature`
  - `hasSwiftSwiftParser`

Since `LangOptions::hasFeature` should always be used anyway, it's no
longer necessary. `hasSwiftSwiftParser` can be special cased when adding
the default promoted language features (by removing those features).

Resolves rdar://117917456.
2024-01-05 10:26:13 -08:00
Alex Hoppen
cc858ab253 Merge pull request #70008 from ahoppen/ahoppen/name-matcher-in-swift
Share implementation of local rename and related identifiers + implement `NameMatcher` in Swift
2023-11-30 09:37:53 -08:00
Alex Hoppen
14bc8148fe Don’t include vector in `BasicBridging.h 2023-11-28 14:03:31 -08:00
Erik Eckstein
8681131c58 add some comments in the bridging headers 2023-11-28 09:02:10 +01:00
Alex Hoppen
b31398215d Don’t include SourceLoc.h when USED_IN_CPP_SOURCE is not set 2023-11-27 19:34:27 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -08:00
Hamish Knight
9216672db7 Improve some bridging interfaces
Migrate a bunch of structs to classes, and
uppercase field names.
2023-10-31 11:06:41 +00:00
Hamish Knight
e2b8d98edc [Basic] Abstract BridgedOStream
Define using the wrapper macro.
2023-10-31 11:06:41 +00:00
Hamish Knight
5d99fe63e9 Rename get() -> unbridged() on bridging wrappers 2023-10-31 11:06:39 +00:00
Hamish Knight
3cb74e911b Address review feedback 2023-10-30 23:50:01 +00:00
Hamish Knight
2a6d93f505 [Basic] Improve API of BridgedArrayRef + BridgedData
Remove the default constructor footgun present with
the struct implementations, and sprinkle some
`SWIFT_NAME` and bridging utilities to make them
nicer to work with.
2023-10-30 23:49:59 +00:00
Hamish Knight
e0f57f84f0 [AST] Cleanup ASTBridging + BasicBridging
Sort AST node bridging functions into Expr, Stmt,
Decl, and TypeRepr, and tweak the headers to use
`MARK`.
2023-10-30 23:49:59 +00:00
Hamish Knight
25546d2178 [AST] Remove redundant typedefs
These aren't needed in C++
2023-10-30 23:49:58 +00:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Hamish Knight
fce1cb54d5 [AST] Merge BridgedDiagnosticEngine + BridgedDiagEngine
Introduce a macro that can stamp out wrapper
classes for underlying C++ pointers, and use
it to define BridgedDiagnosticEngine in
ASTBridging. Then, migrate users of
BridgedDiagEngine onto it.
2023-10-30 23:49:55 +00:00
Hamish Knight
ce23252a3f [Basic] Improve some bridging APIs
Improve APIs for BridgedStringRef,
BridgedOwnedString, and BridgedSourceLoc.
2023-10-30 23:49:53 +00:00