Commit Graph

2357 Commits

Author SHA1 Message Date
Pavel Yaskevich
82e111a276 Merge pull request #78704 from xedin/rdar-142920095
Implement experimental`@execution(concurrent | caller)` attribute
2025-01-21 09:04:39 -08:00
Allan Shortlidge
691f6fc646 AST: Model Embedded Swift availability with a domain.
Remove the bit on AvailableAttr that previously modeled this.

Resolves rdar://138802876.
2025-01-19 08:52:53 -08:00
Pavel Yaskevich
0445e5af5f [Parse] Implement parsing of @execution(...) decl attribute 2025-01-17 15:40:01 -08:00
Allan Shortlidge
393ad9872a Merge pull request #78541 from tshortli/available-attr-remodel
AST: Refactor `AvailableAttr` representation to use `AvailabilityDomain`
2025-01-11 02:39:27 -08:00
Allan Shortlidge
cfb4b8f99b Parse: Adopt new AvailableAttr constructor. 2025-01-10 18:43:12 -08:00
Allan Shortlidge
86ea1ae775 AST: Introduce a Kind enum and new constructor for AvailableAttr.
AvailableAttr::Kind and AvailabilityDomain are designed to replace
PlatformAgnosticAvailabilityKind, allowing AvailableAttr to more flexibly model
availability for arbitrary domains. For now, the new constructor just
translates its inputs into inputs for the existing constructor. Once all of the
callers of the existing AvailableAttr constructor have been updated to use the
new constructor, the representation of AvailableAttr will be updated to store
the new properties.
2025-01-10 18:43:12 -08:00
Doug Gregor
1b7707d2cc Remove the now-unused @safe(unchecked) 2025-01-10 10:39:16 -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
Becca Royal-Gordon
c9f539e146 [NFC] Extract autodiff parsing code to Decl.cpp
The `@differentiable` and `@derivative` attributes need a parent pointer. Move the code to populate it from Parser to AST so it can be more easily shared between the parsers.

Done in preparation for similar code to be added for `@abi`.
2024-12-19 15:47:07 -08:00
Andrew Trick
1d1b260c8f Merge pull request #78199 from atrick/lifedep-cleanup
LifetimeDependence: minor diagnostic quality fixes and related utilities
2024-12-15 04:45:08 -08:00
Andrew Trick
89ea8f6efa [NFC] Fix @lifetime SIL parsing: handle AST output
Disable inference diagnostics because the AST output makes implicit initializers
explicit.

Enable parsing the @lifetime declaration syntax to handle explicit annotations
on declarations.
2024-12-14 22:46:54 -08:00
Doug Gregor
e260d65f71 Add @safe(unchecked) to allow unsafe code within a declaration.
Introduce an attribute to allow unsafe code within the annotated
declaration without presenting an unsafe interface to users. This is,
by its nature, and unsafe construct, and is used to document where
unsafe behavior is encapsulated in safe constructs.

There is an optional message that can be used as part of an audit
trail.
2024-12-13 11:36:40 -08:00
Doug Gregor
d004d24560 Ensure that we wire up *all* custom attribute initializer contexts
Thank you again, Rintaro
2024-12-06 23:02:25 -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
cd13d7d777 AST: Remove AvailableAttr::RenameDecl.
The renamed decl is now stored exclusively in the split request evaluator
storage, which is more efficient since most availability attributes do not
specify a renamed decl.
2024-11-29 10:35:02 -05: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
Doug Gregor
7872fc6c4b Introduce DeclAttribute::clone() to clone declaration attributes (obviously) 2024-11-15 09:02:45 -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
Rintaro Ishizaki
0f1b650716 [AST] MacroRoleAttr accept any 'Expr *' as the conformances arguments 2024-11-14 15:10:11 -08:00
Meghana Gupta
184058e4ac Merge pull request #76588 from meg-gupta/lifetimeremovefeatureguardincompiler
Remove feature guard on lifetime dependence inference
2024-11-12 18:38:41 -08:00
nate-chandler
359f898bbf Merge pull request #77546 from nate-chandler/general-coro/20241110/1
[CoroutineAccessors] Ban read+_read and modify+_modify.
2024-11-12 10:40:52 -08:00
Meghana Gupta
9e4469e67c [NFC] Add test for ~Escapable features without NonEscapable feature flag 2024-11-11 23:18:29 -08:00
Nate Chandler
0089d4d54e [CoroutineAccessors] Ban _read+read. 2024-11-11 18:34:02 -08:00
Nate Chandler
de86cc037c [CoroutineAccessors] Tweak diags for old accessors
When the feature is enabled, refer to the old accessors as they are
actually spelled (i.e. `_read` and `_modify`).
2024-11-11 18:34:01 -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
Alex Hoppen
fb0b3fa90c Merge pull request #77149 from Azoy/swift-syntax-integer-types
[ASTGen/Parse] Implement ASTGen changes for integer generics from Swift Syntax and restrict parsing integer types in certain contexts
2024-11-07 14:04:26 -08:00
Doug Gregor
532022f17b Merge pull request #77423 from DougGregor/macro-expand-parser-infinite-loop
[C++ parser] Make sure break out of a parser loop on ill-formed macro expansion of members
2024-11-06 14:48:45 -08:00
Alejandro Alonso
8b1d08e008 Allow raw layout to parse integer types 2024-11-06 13:55:01 -08:00
Doug Gregor
7b3dce195a [C++ parser] Make sure break out of a parser loop on ill-formed macro expansion of members
The condition to make sure that the parser makes progress when there is
an ill-formed macro expansion to members was incorrect, causing an
infinite loop if there was at least one well-formed declaration
followed by ill-formed code (in this case, a `}`). Fix the condition.

Fixes rdar://137828917.
2024-11-06 10:15:26 -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
Rintaro Ishizaki
1094ae03d5 [ASTGen] Disable ExportedSourceFile for macro expanded buffers 2024-10-31 09:53:34 -07:00
Allan Shortlidge
53413dd941 AST: Add an IsForEmbedded bit to AvailableAttr.
This bit is true for attributes written as `@_unavailableInEmbedded` in source.
2024-10-30 14:29:45 -07:00
Hamish Knight
499fe6dc48 Merge pull request #77072 from hamishknight/complete-options
[IDE] Pass LangOptions to `ide::isSourceInputComplete`
2024-10-30 20:17:47 +00: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
Slava Pestov
9d85221ae5 Parse: Save and restore InFreestandingMacroArgument when delayed parsing
Closures appearing in freestanding macro arguments don't have
discriminators assigned, since we don't actually emit them.

Similarly we skip recording opaque return types that appear in macro
arguments, since they don't get emitted.

However this logic didn't take delayed parsing into account, which must
save and restore the InFreestandingMacroArgument bit correctly.

As a result, if the freestanding macro argument contained a closure
which contained a local function with a declaration that has an
opaque return type, we would crash in serialization from attempting
to mangle an opaque return type nested inside of a closure without a
discriminator.

Fixes rdar://135445004
2024-10-24 17:19:50 -04:00
Nate Chandler
f797e19a29 [Parse] Updated protocol diagnostic to allow read.
With the `CoroutineAccessors` feature, `read` is allowed along with
`get` and `set`; alter the diagnostic that's issued when a disallowed
introducer is listed in the requirement list to indicate that `read` is
one of those which are valid, but only when the feature is enabled.
2024-10-22 18:03:03 -07:00
Nate Chandler
f2e3e8e857 [Sema] Permit read requirement.
Along with `get` and `set`, permit `read` to be required.  When a type
defines `read`, the read impl is that `read`.
2024-10-22 18:02:30 -07:00
Hamish Knight
81dc7d87ed [Parse] Remove TypeChecker and SIL options parameter from ParserUnit
Providing these is a bit of a layering violation,
the parser shouldn't care about these options (there
does seem to be one current use of `TypeCheckerOpts`
in the parser for designated operator types, but
that's a legacy feature that was never officially
supported).
2024-10-17 14:04:34 +01:00
Rintaro Ishizaki
cb6372a9c4 [ASTGen] Generate EditorPlaceholderExpr and 'do' expressions 2024-10-11 09:34:41 -07:00
Meghana Gupta
a3740ae557 Disallow target specification in SIL's @lifetime
SIL's @lifetime continues to be positional. Don't parse 'target:' in this case.
2024-10-08 15:39:37 -07:00
Meghana Gupta
271143405b Don't allow space between @lifetime and '(' 2024-10-08 15:21:39 -07:00
Meghana Gupta
b443ff76e4 [NFC] Use llvm::TrailingObjects to represent variable list of lifetime sources 2024-10-08 15:11:26 -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