Daniil Kovalev
f0bf57a269
Resolve merge conflicts & address review comments
2025-11-10 19:18:25 +03:00
Daniil Kovalev
72431dbd2d
Merge branch 'main' into users/kovdan01/ast-bridges-for-autodiff-closure-spec
2025-11-10 18:46:04 +03:00
Becca Royal-Gordon
683ce9d639
Update and test ASTGen for module selectors
2025-10-16 13:30:30 -07:00
Daniil Kovalev
b3d31c7d51
Bridging: Implement bridges required for ongoing AutoDiff changes
...
In #83926 , part of the changes resolving #68944 is submitted. The AutoDiff
closure specialization optimizer pass relies on several bridges not
implemented yet.
This patch introduces these missing bridges. See the list of the changes below.
**AST:**
* Define `.asValueDecl` on each BridgedXXXDecl type that's also a ValueDecl.
* Define `.asNominalTypeDecl` on each BridgedXXXDecl type that's also a NominalTypeDecl.
* Define `.asGenericContext` on each BridgedXXXDecl type that's also a GenericContext.
* `class BridgedSourceFile`:
- Make nullable
- `func addTopLevelDecl(_ decl: BridgedDecl)`
* `class BridgedFileUnit`:
- `func castToSourceFile() -> BridgedNullableSourceFile`
* `class BridgedDecl`:
- `func getDeclContext() -> BridgedDeclContext`
* `class BridgedParamDecl`:
- `func cloneWithoutType() -> BridgedParamDecl`
- `func setInterfaceType(_ type : BridgedASTType)`
* Define `BridgedDecl.setImplicit()` instead of `BridgedParamDecl.setImplicit()`
* `class BridgedGenericContext`:
- `setGenericSignature(_ genSig: BridgedGenericSignature)`
* Change return type of `BridgedEnumDecl.createParsed(/*...*/)` from `BridgedNominalTypeDecl` to `BridgedEnumDecl`
* `class BridgedValueDecl`:
- `func setAccess(_ accessLevel: swift.AccessLevel)`
* `class BridgedNominalTypeDecl`:
- `func addMember(_ member: BridgedDecl)`
* `class BridgedGenericTypeParamDecl`:
- `func createImplicit(declContext: BridgedDeclContext, name: swift.Identifier, depth: UInt, index: UInt, paramKind: swift.GenericTypeParamKind)`
* `class ValueDecl`:
- `var baseIdentifier: swift.Identifier`
* `class NominalTypeDecl`:
- `var declaredInterfaceType: Type`
* `class EnumElementDecl`:
- `var parameterList: BridgedParameterList`
- `var nameStr: StringRef`
* `struct GenericSignature`:
- `var canonicalSignature: CanGenericSignature`
* `struct CanGenericSignature`:
- `var isEmpty: Bool`
- `var genericSignature: GenericSignature`
* `struct Type`:
- `func mapTypeOutOfContext() -> Type`
- `func getReducedType(sig: GenericSignature) -> CanonicalType`
- `func GenericTypeParam_getName() -> swift.Identifier`
- `func GenericTypeParam_getDepth() -> UInt`
- `func GenericTypeParam_getIndex() -> UInt`
- `func GenericTypeParam_getParamKind() -> swift.GenericTypeParamKind`
* `struct CanonicalType`:
- `func SILFunctionType_getSubstGenericSignature() -> CanGenericSignature`
- `func loweredType(in function: SIL.Function) -> SIL.Type`
**SIL:**
* `class Argument`:
- `func replaceAllUsesWith(newArg: Argument)`
* `class BasicBlock`:
- `func insertPhiArgument(atPosition: Int, type: Type, ownership: Ownership, _ context: some MutatingContext) -> Argument`
* `struct Builder`:
- `func createTuple(elements: [Value]) -> TupleInst`
* `protocol Context`:
- `func getTupleType(elements: [AST.Type]) -> AST.Type`
- `func getTupleTypeWithLabels(elements: [AST.Type], labels: [swift.Identifier]) -> AST.Type`
* `class Function`:
- `var sourceFile: BridgedNullableSourceFile`
- `func mapTypeIntoContext(_ type: Type) -> Type`
* `class PartialApplyInst`:
- `var substitutionMap: SubstitutionMap`
* `class SwitchEnumInst`:
- `var numCases: Int`
- `public func getSuccessorForDefault() -> BasicBlock?`
* `Type`:
- `var category: ValueCategory`
- `func getEnumCasePayload(caseIdx: Int, function: Function) -> Type`
- `func mapTypeOutOfContext() -> Type`
- `static func getPrimitiveType(canType: CanonicalType, silValueCategory: ValueCategory) -> Type`
* `struct EnumCase`:
- `let enumElementDecl: EnumElementDecl`
* `struct TupleElementArray`:
- `func label(at index: Int) -> swift.Identifier`
* Define `enum ValueCategory` with `address` and `object` elements
2025-10-06 17:56:38 +03: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
8cbf5a26e4
Bridging: Bridge swift::DeclBaseName directly
2025-07-10 17:58:13 +01:00
Anthony Latsis
0e0fbc4160
Bridging: Bridge swift::Identifier directly
2025-07-10 17:58:13 +01:00
Anthony Latsis
cf09773d66
ASTBridging: Bridge swift::Associativity directly
2025-06-19 18:11:40 +01:00
Anthony Latsis
3e9923f0c0
ASTBridging: Bridge swift::AccessorKind directly
2025-06-19 04:26:52 +01:00
Pavel Yaskevich
4b5105df5e
[ASTGen] Implement bridging for using declaration
2025-05-30 15:52:09 -07:00
Becca Royal-Gordon
e71f837b1f
[NFC] Stub module selector DeclNameRef/Loc members
2025-05-14 11:16:02 -07:00
Rintaro Ishizaki
ddd5b12661
[ASTGen] Handle trailing where clause in macro declarations
2025-03-16 17:41:21 -07:00
Rintaro Ishizaki
017c0d98ec
[ASTGen] Generate AutoDiff attributes
...
`@differentiable`, `@derivative` and `@transpose`
2025-03-06 10:36:13 -08:00
Rintaro Ishizaki
38bafb3872
Merge pull request #79513 from rintaro/astgen-macro-expanded-syntax
2025-02-24 15:06:24 -08:00
Rintaro Ishizaki
f48282c92b
[ASTGen] Generate trailing where clause for SubscriptDecl
...
It was just missing.
2025-02-21 11:36:29 -08: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
8833ff58a2
[AST] Sink the flag collection logic from Parse to AST
...
* Collect flag in `ParamDecl::setTypeRepr()`.
* [ASTGen] Separate `BridgedParamDecl.setTypeRepr(_:)` from
`BridgedParamDecl.createParsed(_:)` aligning with C++ API. The majority
of the creations don't set the typerepr.
* Update `ParamSpecifierRequest::evaluate` to handle non-implicit
`ParamDecl` without `TypeRepr` (i.e. untyped closure parameter), instead
of `setSpecifier(::Default)` manually in Parse.
2025-02-20 10:04:49 -08:00
Rintaro Ishizaki
6980509f8c
[ASTGen] Generate DefaultArgumentInitializer
...
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Rintaro Ishizaki
b7b28b6d8e
[ASTGen] Correctly store static spelling and location to PBD
2025-02-17 11:16:53 -08:00
Hamish Knight
1e8dc55b7f
[AST] NFC: Remove InitRetType
...
This is no longer used.
2025-02-16 18:52:23 +00: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
cb049d8ed1
[ASTGen] Generate anonymous closure parameters
...
E.g. '$0'
2025-02-07 19:39:57 -08:00
Becca Royal-Gordon
201ccaf053
[NFC] [ASTGen] Refactor attribute attachment
...
Use `Decl::attachParsedAttrs()` instead of `Decl::setAttrs()` to attach attributes to a declaration in ASTGen. This causes the common attribute-setup logic there to be run.
NFC in this commit because none of the attributes that have special setup logic are currently implemented in ASTGen. Prepares to add support for `@abi` in a future commit.
2024-12-19 15:49:35 -08:00
Rintaro Ishizaki
71ca3e129a
[ASTGen] Use syntax tree based interface hash
2024-12-12 09:51:09 -08:00
Rintaro Ishizaki
6d7b3d69d1
[ASTGen] Generate several attributes
...
* NonisolatedAttr
* SpecializeAttr
* UnavailableFromAsyncAttr
* DocumentationAttr
* StorageRestrictionsAttr
2024-12-05 15:12:00 -08:00
Rintaro Ishizaki
093d0dffb4
[ASTGen] Generate MacroDecl
2024-11-14 15:10:08 -08:00
Rintaro Ishizaki
dc156a644a
[ASTGen] Generate Swift key-path expressions
2024-11-05 13:38:21 -08:00
Rintaro Ishizaki
dfdba15121
[ASTGen] Generrate MacroExpansionExpr
2024-10-30 22:43:26 -07:00
Rintaro Ishizaki
b5859240ab
[ASTGen] Split ASTBridging.cpp into multiple files
...
ASTBridging.cpp was getting too big.
2024-10-04 10:48:56 -07:00