Commit Graph

650 Commits

Author SHA1 Message Date
Allan Shortlidge
0288eaa3b7 AST: Introduce Decl::getSemanticAvailableAttrs().
This new attribute iterator returned from the query makes it simpler to
implement algorithms that need access to both the `AvailableAttr *` and its
corresponding `AvailabilityDomain`. This is also work towards making it
possible to return an optional `AvailabilityDomain` from
`Decl::getDomainForAvailableAttr()`.
2024-12-19 08:40:00 -08:00
Doug Gregor
f9b904f672 Implement printing of @safe(unchecked) attribute 2024-12-14 21:47:42 -08:00
Doug Gregor
268de018f4 When determining the start of a declaration, ignore attributes that aren't at the start
Otherwise, we get bad attribute/modifier insertion locations for 'rethrows' functions
2024-12-14 21:47:40 -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
Allan Shortlidge
9b7764a298 AST: Introduce AvailabilityDomain. 2024-12-08 17:29:04 -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
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
985edf5916 Merge pull request #77905 from rintaro/astgen-declattr-pt2
[ASTGen] Generate several attributes
2024-12-06 09:24:07 -08:00
Rintaro Ishizaki
6d7b3d69d1 [ASTGen] Generate several attributes
* NonisolatedAttr
* SpecializeAttr
* UnavailableFromAsyncAttr
* DocumentationAttr
* StorageRestrictionsAttr
2024-12-05 15:12:00 -08:00
Doug Gregor
0c91a3409c Formalize the notion of "can clone" so we don't try to clone an attribute that won't work 2024-12-04 15:25:13 -08:00
Allan Shortlidge
d8c946d186 AST: Introduce Decl::getActiveAvailableAttrForCurrentPlatform(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
5cdcb5d116 AST: Introduce Decl::getNoAsyncAttr(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
5143382265 AST: Introduce Decl::isUnavailableInCurrentSwiftVersion(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
c5398e17d3 AST: Introduce Decl::getDeprecatedAttr().
It replaces `DeclAttr::getDeprecated()` as the designated way to query for the
attribute that makes a decl deprecated.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
3e50a90c45 AST: Introduce Decl::getUnavailableAttr().
It replaces `DeclAttr::getUnavailable()` and `AvailableAttr::isUnavailable()`
as the designated way to query for the attribute that makes a decl unavailable.
2024-12-02 07:35:58 -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
Allan Shortlidge
e6741d5e9e AST: Adopt ValueDecl::getRenamedDecl().
This unblocks removing `RenameDecl` from `AvailableAttr`.
2024-11-29 10:34:49 -05:00
Allan Shortlidge
9d884bfbcb AST: Adopt split caching for RenamedDeclRequest.
In the common case where there is no renamed decl for the attribute, just set a
few bits in inline storage for `AvailableAttr`.
2024-11-29 10:34:49 -05:00
Allan Shortlidge
5de7211984 AST: Rename createForAlternative() to createForAsyncAlternative(). 2024-11-22 14:35:47 -08:00
Allan Shortlidge
afad02e393 AST: Adopt AvailableAttr::isLanguageVersionSpecific(). 2024-11-21 09:10:36 -08:00
Allan Shortlidge
2e03ba27e7 AST: Store Platform and PlatformAgnostic in AvailableAttr's bits. 2024-11-21 09:10:36 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Allan Shortlidge
b3f6421091 AST: Remove DeclAttributes::getPotentiallyUnavailable().
This utility duplicated logic that is now meant to be encapsulated by
`getUnsatisfiedAvailabilityConstraint()`.
2024-11-19 17:19:51 -08:00
Doug Gregor
901ffb7978 Add static checking to ensure every DeclAttribute subclass has a properly-typed clone()
Code review identified some incorrect UNIMPLEMENTED_CLONEs in DeclAttribute (thank you
Hamish and Rintaro). Fix those, and make sure this can't happen again by checking the type
signatures of clone() in every DeclAttribute subclass.
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
0f1b650716 [AST] MacroRoleAttr accept any 'Expr *' as the conformances arguments 2024-11-14 15:10:11 -08:00
Allan Shortlidge
239720897a AST: Rename TypeRefinementContext to AvailabilityScope. 2024-11-12 11:34:25 -08: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
Allan Shortlidge
0e4c881eb3 AST: Store the IsSPI bit of AvailableAttr inline in DecAttribute.
Reduces the layout requirements for `AvailableAttr` by one byte.
2024-10-30 14:29:45 -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
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
Meghana Gupta
bf41473da8 Merge pull request #76810 from meg-gupta/lifetimeupdate
Update LAST_DECL_ATTR and add verification to ensure it is always updated
2024-10-02 16:30:35 -07:00
Meghana Gupta
30b1c968c3 Update LAST_DECL_ATTR and add verification 2024-10-01 15:24:50 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
Allan Shortlidge
0fb36a5f39 AST: Make $SpecializeAttributeWithAvailability a baseline feature.
It has been available since at least Swift 5.8.
2024-09-23 21:48:09 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Meghana Gupta
7af6c11e7e Store parsed @lifetime attribute on the function type 2024-09-09 22:02:44 -07:00
Meghana Gupta
2b011b0a3a [NFC] Rename/reorg LifetimeDependence utils 2024-09-09 22:02:44 -07:00
Meghana Gupta
e61d87c01c Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations 2024-09-09 22:02:42 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Mykola Pokhylets
e0ad7bde82 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/AST/ASTPrinter.cpp
#	lib/AST/FeatureSet.cpp
2024-08-29 11:28:43 +02:00
Allan Shortlidge
f042ba8284 ModuleInterface: Skip attributes referencing SPI platforms.
When printing the public `.swiftinterface` for a `-library-level=api` module,
skip emitting `@available`, `@backDeployed`, and `@_originallyDefinedIn`
attributes that reference "SPI" platforms.

Resolves rdar://133990140.
2024-08-20 14:02:00 -07:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Allan Shortlidge
f7ff3f0001 SILGen: Introduce macCatalyst support for @backDeployed.
Upstreams the necessary changes to compile references to `@backDeployed`
declarations correctly when a `macabi` target triple or a `-target-variant` is
specified.
2024-07-23 17:00:10 -07:00
Mykola Pokhylets
816d62c972 Merge remote-tracking branch 'upstream/main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/SILGen/SILGenDestructor.cpp
#	test/Concurrency/flow_isolation.swift
#	test/abi/macOS/arm64/concurrency.swift
#	test/abi/macOS/x86_64/concurrency.swift
2024-07-11 13:11:59 +02:00
Mykola Pokhylets
2cb7e8d7b8 Implemented suppressing isolated deinit for compatibility with older compiler versions 2024-07-11 13:09:08 +02:00
Allan Shortlidge
8093783e21 AST: Promote ExtensionMacroAttr feature to baseline. 2024-07-09 14:28:29 -07:00
Hamish Knight
42f563d6d8 [Completion] Use TypeAttr.def for simple type attributes
Pick up all non-underscored simple type attributes
for code completion, and add support for
`@isolated(any)`.

rdar://130741006
rdar://130288443
2024-07-03 11:41:58 +01:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00