Commit Graph

309 Commits

Author SHA1 Message Date
Erik Eckstein
67925ea27e Swift AST: add GenericSignature
and add `var Type.invocationGenericSignatureOfFunctionType`
2025-03-07 15:59:34 +01:00
Erik Eckstein
810064b7dc Cleanup and additions to AST and SIL Type/CanonicalType
* factor out common methods of AST Type/CanonicalType into a `TypeProperties` protocol.
* add more APIs to AST Type/CanoncialType.
* move `MetatypeRepresentation` from SIL.Type to AST.Type and implement it with a swift enum.
* let `Builder.createMetatype` get a CanonicalType as instance type, because the instance type must not be a lowered type.
2025-03-07 15:59:33 +01:00
Erik Eckstein
eadfbf6842 Swift AST: add some APIs to Type and CanonicalType 2025-03-07 15:59:33 +01:00
Rintaro Ishizaki
ff6cb11bb0 [ASTGen] Introduce 'AvailableAttr::createUnavailableInEmbedded()' 2025-03-07 04:14:50 -08:00
Rintaro Ishizaki
d60f1986a8 [ASTGen] Adopt AvailabilityDomainOrIdentifier scheme
Aligning with libParse
2025-03-07 04:14:50 -08:00
Rintaro Ishizaki
017c0d98ec [ASTGen] Generate AutoDiff attributes
`@differentiable`, `@derivative` and `@transpose`
2025-03-06 10:36:13 -08:00
Allan Shortlidge
cad1ee75d5 AST: Optimize the layout of AvailabilityRange.
`AvailabilityRange` is now being used as a currency type in more of the
compiler, and some of those uses are in permanent `ASTContext` allocations. The
class wraps the `VersionRange` utility, which is itself a wrapper around
`llvm::VersionTuple` with some additional storage for representing sentinel
values. Even though the two sentinel values can be be represented with just a
single bit of additional storage on top of the 16 bytes required to represent
`VersionTuple`, because of alignment requirements the sentinel values end up
bloating the layout of `VersionRange` by many bytes.

To make `AvailabilityRange` and `VersionRange` more efficient to store, we can
instead reserve two unlikely `llvm::VersionTuple` bit patterns as the sentinel
values instead. The values chosen are the same ones LLVM uses to represent
version tuple tombstones and empty keys in a `DenseMap`.
2025-03-05 07:15:15 -08:00
Allan Shortlidge
1409cb1a30 AST: Teach DiagnosticEngine to accept AvailabilityRange arguments. 2025-03-04 19:41:04 -08:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Allan Shortlidge
b0afd07e14 AST/Parse: Always delay AvailabilityDomain lookup to type-checking.
This will unblock parsing and type-checking availability queries that specify
custom availability domains, e.g.:

```
if #available(CustomDomain) {
  // Use declarations protected by @available(CustomDomain)
}
```
2025-02-26 21:46:14 -08:00
Rintaro Ishizaki
bdc953f418 Merge pull request #79629 from rintaro/astgen-rawlayout
[ASTGen] Generate '@_rawLayout' attribute
2025-02-26 15:13:25 -08:00
Rintaro Ishizaki
924e1e8bf1 [ASTGen] Generate '@_rawLayout' attribute
Introduce 'generateTypeRepr(expr:)'.
2025-02-26 10:20:51 -08:00
Rintaro Ishizaki
0c2309898f [ASTGen] Rework type specifiers
Handle multiple specifiers. Hanle previously missing 'sending'
specifiers.
2025-02-26 04:39:38 -08:00
Allan Shortlidge
c54825b4c3 AST: Use AvailabilityDomainOrIdentifier to store domains in AvailabilitySpec. 2025-02-25 09:02:47 -08:00
Rintaro Ishizaki
38bafb3872 Merge pull request #79513 from rintaro/astgen-macro-expanded-syntax 2025-02-24 15:06:24 -08:00
Doug Gregor
115abcb637 Merge pull request #79573 from DougGregor/unsafe-for-in-loop
[SE-0458] Implement "unsafe" effect for the for-in loop
2025-02-24 14:49:45 -08:00
Rintaro Ishizaki
af489ea32b Merge pull request #79544 from rintaro/astgen-small-fixes 2025-02-24 07:25:42 -08:00
Doug Gregor
50801f9c05 [SE-0458] Implement "unsafe" effect for the for-in loop
Memory unsafety in the iteration part of the for-in loop (i.e., the part
that works on the iterator) can be covered by the "unsafe" effect on
the for..in loop, before the pattern.
2025-02-23 22:50:39 -08:00
Allan Shortlidge
eb6506a1ad AST: Introduce SemanticAvailabilitySpec.
It wraps an type-checked `AvailabilitySpec`, which guarantees that the spec has
a valid `AvailabilityDomain` associated with it. This will unblock moving
AvailabilitySpec domain resolution from parsing to sema.
2025-02-23 10:53:06 -08:00
Rintaro Ishizaki
efea164d04 [ASTGen] Generate from 'MissingTypeSyntax'
Just emit ErrorTypeRepr
2025-02-21 11:36:29 -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
2b14a233b7 [ASTGen] Generate generic layout constraint 2025-02-19 16:38:00 -08:00
Rintaro Ishizaki
2ceb8f1e57 Merge pull request #79492 from rintaro/astgen-attr-as-modifier
[ASTGen] Add an assertion for attribute as an modifier
2025-02-19 15:56:55 -08:00
Rintaro Ishizaki
6aea6ce2f5 Merge pull request #79469 from rintaro/astgen-custom-type-attr
[ASTGen] Generate CustomAttr on types
2025-02-19 14:06:25 -08:00
Rintaro Ishizaki
81475be976 [ASTGen] Add an assertion for attribute as an modifier 2025-02-19 11:09:53 -08:00
Rintaro Ishizaki
d109a86bb7 [ASTGen] Generate CustomAttr on types
Rework TypeAttribute bridging facilities.
Eliminate the _fake_ `swift::TypeAttributes`, but just use the normal
`BridgedArrayRef` for briding the attribute list. Introduce
`BridgedTypeOrCustomAttr` tagged pointer which resembles
`swift::TypeOrCustomAttr`.
2025-02-18 13:08:50 -08:00
Rintaro Ishizaki
6980509f8c [ASTGen] Generate DefaultArgumentInitializer
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Rintaro Ishizaki
57b6d1e90b [ASTGen] Generate "minus" number literal expression 2025-02-17 21:34:11 -08:00
Rintaro Ishizaki
c7e8f58174 Merge pull request #79438 from rintaro/astgen-static-var
[ASTGen] Correctly store static spelling and location to PBD
2025-02-17 15:59:43 -08:00
Rintaro Ishizaki
b7b28b6d8e [ASTGen] Correctly store static spelling and location to PBD 2025-02-17 11:16:53 -08:00
Rintaro Ishizaki
94402b6c9d [ASTGen] Generate LifetimeAttr 2025-02-17 08:56:29 -08:00
Rintaro Ishizaki
6d85bb58c5 Merge pull request #79412 from rintaro/astgen-typeattrs
[ASTGen] Generate OpaqueReturnTypeOfTypeAttr
2025-02-16 13:55:39 -08:00
Rintaro Ishizaki
84875d147e [ASTGen] Bridge ASTContext.Id_x 2025-02-16 05:22:46 -08:00
Rintaro Ishizaki
0ced6e06b4 [ASTGen] Generate CaptureListExpr
Move the capture list entry construction logic to
CaptureListEntry::createParsed() so that ASTGen can use it.
2025-02-16 05:22:46 -08:00
Rintaro Ishizaki
214315b1cc [ASTGen] Generate several type attributes
Also rework existing type attribute generate functino to use standard
attribute generation facilities.
2025-02-14 18:18:24 -08:00
Rintaro Ishizaki
137e279d62 Merge pull request #79368 from rintaro/astgen-astnode
[ASTGen] Eliminate ASTGen.ASTNode
2025-02-14 11:53:17 -08:00
Rintaro Ishizaki
10aac858fb Merge pull request #79379 from rintaro/astgen-conventiontypeattr
[ASTGen] Generate ConventionTypeAttr
2025-02-14 07:10:27 -08:00
Rintaro Ishizaki
9229b0746d Merge pull request #79374 from rintaro/astgen-objectliteralexpr
[ASTGen] Generate ObjectLiteralExpr
2025-02-14 07:10:10 -08:00
Rintaro Ishizaki
f2db96cc60 [ASTGen] Eliminate ASTGen.ASTNode
We can simply use `BridgedASTNode`, no need to have its own ASTNode
2025-02-14 07:05:10 -08:00
Allan Shortlidge
06030d66aa AST: Introduce AvailabilityDomainOrIdentifier.
It provides a common way to represent either a parsed domain identifier or the
resolved domain.

NFC.
2025-02-13 21:18:05 -08:00
Rintaro Ishizaki
f08bf56722 [ASTGen] Generate ConventionTypeAttr
E.g. `@convention(c)`
2025-02-13 16:19:20 -08:00
Rintaro Ishizaki
e1dfed3f13 [ASTGen] Bridge TypeAttribute subclasses 2025-02-13 16:19:20 -08:00
Rintaro Ishizaki
13380da3b4 [ASTGen] Generate ObjectLiteralExpr
e.g. '#imageLiteral(..)'
2025-02-13 16:17:47 -08:00
Rintaro Ishizaki
e066bb266b Merge pull request #79355 from rintaro/astgen-toplevelvardecl
[ASTGen] Generate PatternBindingDecl at top level
2025-02-13 09:43:10 -08:00
Rintaro Ishizaki
73164a0ffd Merge pull request #79353 from rintaro/astgen-magic-ident-literal
[ASTGen] Generate MagicIdentifierLiteralExpr
2025-02-13 06:25:09 -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
563ddc47e2 [AST] Eliminate 'SYNTAX_KIND' from MagicIdentifierKinds.def
Nothing is using it.
2025-02-12 23:19:34 -08:00
Allan Shortlidge
670084a9ac AST: Retire PlatformVersionConstraintAvailabilitySpec. 2025-02-12 22:46:58 -08:00