1154 Commits

Author SHA1 Message Date
Becca Royal-Gordon
96e6b1d618 Fix malformed arg label error with module selector
The legacy parser has a special case for code like `fn(:)` which corrects it to `fn(_:)`, but the new `::` token was interfering with cases where there were two adjacent colons (e.g. `fn(::)`). Correct this issue.
2025-10-18 03:15:53 -07:00
Becca Royal-Gordon
f82881cc8e Parse module selectors in permitted locations 2025-10-16 13:30:29 -07:00
Becca Royal-Gordon
f1db5d3a6a [NFC] Add tok::colon_colon to parser 2025-10-16 13:30:29 -07:00
Becca Royal-Gordon
58954734a0 [NFC-ish] Do lookahead without llvm::function_ref 2025-10-16 13:30:29 -07:00
Becca Royal-Gordon
c9bb85a875 [NFC] Add DeclNameLoc to specialize/dynamicReplacement 2025-10-16 13:30:28 -07:00
Becca Royal-Gordon
cab38afcf7 Use parseDeclNameRef in a few more places 2025-10-16 13:30:26 -07:00
Rintaro Ishizaki
b119407966 [Parse] Change whitespace rule between attribute name and '(' in Swift 6
In Swift 6 and later, whitespace is no longer permitted between an
attribute name and the opening parenthesis. Update the parser so that
in Swift 6+, a `(` without preceding whitespace is always treated as
the start of the argument list, while a '(' with preceding whitespace is
considered the start of the argument list _only when_ it is unambiguous.

This change makes the following closure be parsed correctly:

  { @MainActor (arg: Int) in ... }

rdar://147785544
2025-09-09 16:44:29 -07:00
Hamish Knight
114ea293c4 Merge pull request #82058 from a7medev/feat/access-control-set-fix-it
[Diagnostics] Add fix-its for missing `set` and `)` after access modifier
2025-08-16 18:42:28 +01:00
Ahmed Mahmoud
df0eda93f4 [IDE] Update comments for access control missing set fix-its 2025-08-15 15:23:29 +03:00
Ahmed Mahmoud
3cd3c048cf [Diagnostics] Add fix-its for missing set and ) of access modifier 2025-08-10 01:57:02 +03:00
Allan Shortlidge
2b8ab7fbab AST: Re-baseline SendingArgsAndResults feature. 2025-07-31 10:21:55 -07:00
Meghana Gupta
dcf072f9d0 Introduce a new suppressible experimental feature to guard @_lifetime 2025-06-07 12:49:07 -07:00
Meghana Gupta
0dfa1fc312 Update spelling for representing lifetime dependencies to @_lifetime 2025-06-07 12:49:07 -07:00
Pavel Yaskevich
4ad27ba61e [Parse] Implement parsing for using declarations 2025-05-31 10:49:45 -07:00
Arnold Schwaighofer
13ff5abdb8 Introduce @specialized attribute
Implements SE-0460 -- the non-underscored version of @specialized.

It allows to specify "internal" (not abi affecting) specializations.

rdar://150033316
2025-05-23 13:12:47 -07:00
Pavel Yaskevich
54b62ae983 [AST/Parse] Implement nonisolated(nonsending) type modifier 2025-04-11 15:59:25 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Rintaro Ishizaki
5eac58e1e0 [AST] SwitchStmt only hold CaseStmt
Now that there is no way SwitchStmt to hold AST nodes other than
CaseStmt.
2025-03-08 09:14:40 -08:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -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
Allan Shortlidge
ff17263e56 Merge pull request #79480 from tshortli/exclude-parser-diags
Parse: Avoid including `DiagnosticsParse.h` in `Parser.h`
2025-02-19 18:19:29 -08:00
Allan Shortlidge
e8329d292b Parse: Avoid including DiagnosticsParse.h in Parser.h.
This prevents the include of DiagnosticsParse.h from leaking into `.cpp` files
in libraries besides Parse.
2025-02-19 07:56:38 -08:00
Rintaro Ishizaki
6980509f8c [ASTGen] Generate DefaultArgumentInitializer
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Becca Royal-Gordon
5c28f1d73d Merge pull request #78313 from beccadax/llvm_reachable 2025-02-18 01:04:55 -08:00
Allan Shortlidge
670084a9ac AST: Retire PlatformVersionConstraintAvailabilitySpec. 2025-02-12 22:46:58 -08:00
Allan Shortlidge
0722efe97e AST: Retire PlatformAgnosticVersionConstraintAvailabilitySpec. 2025-02-12 20:41:00 -08:00
Allan Shortlidge
6daea78ccf AST: Remove AvailabilitySpec.h include from Stmt.h.
Include it where it's actually used instead to improve compile times.
2025-02-11 20:03:01 -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
Becca Royal-Gordon
90f7724ec6 Fix parsing of @_unavailableFromAsync
There’s a very easy to reach `llvm_unreachable()` in this code which ought to be a diagnostic, as well as a couple of other issues. Rework it into something that’s a bit better at handling the edge cases.
2024-12-20 17:59:23 -08:00
Becca Royal-Gordon
94ff062edd Parse and serialize @abi attribute
This attribute will allow you to specify an alternate version of the declaration used for mangling. It will allow minor adjustments to be made to declarations so long as they’re still compatible at the calling convention level, such as refining isolation or sendability, renaming without breaking ABI, etc.

The attribute is behind the experimental feature flag `ABIAttribute`.
2024-12-19 15:48:54 -08:00
Doug Gregor
02a20ded57 [Parsers] Stop sharing CustomAttributeInitializer instances across properties
We don't need to share them, and it's far simpler if we don't.
2024-12-06 17:40:34 -08:00
Doug Gregor
ee9c066050 Introduce a new Initializer subclass for the arguments of custom attributes
Since the introduction of custom attributes (as part of property
wrappers), we've modeled the context of expressions within these
attributes as PatternBindingInitializers. These
PatternBindingInitializers would get wired in to the variable
declarations they apply to, establishing the appropriate declaration
context hierarchy. This worked because property wrappers only every
applied to---you guessed it!---properties, so the
PatternBindingInitializer would always get filled in.

When custom attributes were extended to apply to anything for the
purposes of macros, the use of PatternBindingInitializer became less
appropriate. Specifically, the binding declaration would never get
filled in (it's always NULL), so any place in the compiler that
accesses the binding might have to deal with it being NULL, which is a
new requirement. Few did, crashes ensued.

Rather than continue to play whack-a-mole with the abused
PatternBindingInitializer, introduce a new CustomAttributeInitializer
to model the context of custom attribute arguments. When the
attributes are assigned to a declaration that has a
PatternBindingInitializer, we reparent this new initializer to the
PatternBindingInitializer. This helps separate out the logic for
custom attributes vs. actual initializers.

Fixes https://github.com/swiftlang/swift/issues/76409 / rdar://136997841
2024-12-06 17:40:32 -08:00
Rintaro Ishizaki
6d7b3d69d1 [ASTGen] Generate several attributes
* NonisolatedAttr
* SpecializeAttr
* UnavailableFromAsyncAttr
* DocumentationAttr
* StorageRestrictionsAttr
2024-12-05 15:12:00 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Meghana Gupta
ae28d667ff Introduce LifetimeDependence experimental feature 2024-11-18 18:08:32 -08:00
Doug Gregor
c5de02f60e Merge pull request #77628 from DougGregor/clang-importer-parse-request
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
2024-11-16 01:12:27 -08:00
Doug Gregor
f8f14b4ab6 [Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
The Clang importer was directly calling into the parser to parse the
attribute (or modifier) within swift_attr. Aside from being gross, this
isn't possible with ASTGen.

Instead, teach ParseSourceFileRequest to deal with modifiers in the
same way that the Clang importer was hardcoding, and have the Clang
importer pull the attributes/modifiers off of the "missing"
declaration introduced by the request.

One benefit of this approach is that we're only parsing each
swift_attr source buffer once, then cloning the attributes each time
it's used, so we should be doing less work overall.

Fixes rdar://139119159.
2024-11-15 09:02:47 -08:00
Rintaro Ishizaki
1fc00ae248 [ASTGen] Remove LegacyParser ping-pong mechanism
Now that ASTGen should be able to generate most Swift code. Let's
remove "legacy parser" call-in, and remove the unhealthy cyclic
dependency between lib/Parse and ASTGen.
2024-11-14 22:46:43 -08:00
Doug Gregor
cf68d28400 Merge pull request #76951 from kovdan01/issue60102
[AutoDiff] Enhance performance of custom derivatives lookup
2024-11-11 14:55:54 -08:00
Alejandro Alonso
90ce2cd361 Restrict parsing integer types in certain contexts 2024-11-06 13:55:01 -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
Rintaro Ishizaki
d4db99ce9d [Parse] Remove unnecessary dependencies to Parser.h
C++ swift::Parser is going to be replaced with SwiftParser+ASTGen.
Direct dependencies to it should be removed. Before that, remove
unnecessary '#include "swift/Parse/Parser.h"' to clarify what actually
depends on 'swift::Parser'.

Split 'swift::parseDeclName()' et al. into the dedicated files.
2024-11-02 01:23:59 -07:00
Daniil Kovalev
0d7e37e4ec [AutoDiff] Enhance performance of custom derivatives lookup
In #58965, lookup for custom derivatives in non-primary source files was
introduced. It required triggering delayed members parsing of nominal types in
a file if the file was compiled with differential programming enabled.

This patch introduces `CustomDerivativesRequest` to address the issue.
We only parse delayed members if tokens `@` and `derivative` appear
together inside skipped nominal type body (similar to how member operators
are handled).

Resolves #60102
2024-10-29 12:45:14 +03:00
Rintaro Ishizaki
8e8e4d0193 [Parse/Sema] Move OptionalEvaluationExpr wrapping to PreCheckTarget
This simplify the Parser diagnostics and some type checker logic.
2024-10-11 13:12:48 -07:00
Meghana Gupta
f591680c2a Update SIL printing of @lifetime
Lifetime dependencies in SIL tests continue to be represented as a type modifier on the target.

As before, they are represented as a LifetimeDependentTypeRepr in the AST.
2024-10-08 15:10:59 -07:00
Meghana Gupta
31c1dc7eb5 Add support for specifying target in @lifetime
@lifetime(target: source1, source2...) where target can be any
parameter or 'self'. We cannot have @lifetime attributes with duplicate targets.

Also, update the internal data structures. Previously LifetimeEntry stored
pairwise (target, source) dependencies. Now, LifetimeEntry will store an optional
target descriptor and an array of source descriptors.
2024-10-08 15:10:48 -07:00
Meghana Gupta
011b5bf10c Delete dependsOn support
Lifetime dependencies will now be represented with @lifetime attribute in the language.

dependsOn is a type modifier and was represented as a LifetimeDependentTypeRepr in the AST.

I am deleting dependsOn syntax parsing support and retaining LifetimeDependentTypeRepr support.

We may want to represent lifetime dependencies in a function type with a type attribute in the future.
If we use a decl attribute instead, then support for LifetimeDependentTypeRepr can be deleted.
2024-10-07 00:24:35 -07:00
Alexis Laferrière
ff803c6df1 Sema: Move the availability macros cache to the ASTContext
The availability macros definitions are parsed from the command line and
stored in a cache. The cache was in the Parser, which would have it be
computed for each file using availability macros. Let's move it to the
ASTContext instead where it can generally be computed once per invocation
and used across the module.

rdar://134797088
2024-10-01 09:07:56 -07:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Doug Gregor
d762dd53f8 Stop parsing into IfConfiDecl nodes in the C++ parser
When parsing #if...#endif regions, parse the active clause directly into
place in the AST without ever producing an IfConfigDecl instance.
2024-09-18 20:51:09 -07:00