Commit Graph

2023 Commits

Author SHA1 Message Date
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
272b2b43de AST: Accept AvailabilityDomains as diagnostic arguments.
This simplifies the code to emit availabilty diagnostics and ensures that they
display domain names consistently. While updating existing diagnostics, improve
consistency along other dimensions as well.
2025-02-28 09:18:38 -08:00
Allan Shortlidge
aaa0e0a7b3 AST/Parse: Parse custom availability domain specs in if #available(...).
Delay resolution of availability domain identifiers parsed in availability
specifications until type-checking. This allows custom domain specifications to
be written in `if #available` queries.
2025-02-27 23:07:55 -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
62c8e72f23 AST: Centralize AvailabilityDomain lookup.
Implement lookup of availability domains for identifiers on
`AvailabilityDomainOrIdentifier`. Add a bit to that type which represents
whether or not lookup has already been attempted. This allows both
`AvailableAttr` and `AvailabilitySpec` to share a common implementation of
domain lookup.
2025-02-25 22:00:31 -08:00
Allan Shortlidge
db29a1c6f4 Parse/Sema: Move #available query wildcard diagnostics to Sema.
In order to unblock resolution of availability domains during type-checking
instead of parsing, diagnostics about missing or superfluous wildcards in
availability specification lists need to move to Sema.
2025-02-23 22:09:33 -08:00
Pavel Yaskevich
520c05b1b8 Merge pull request #79508 from xedin/feature-proof-execution-attrs
[Frontend] Rename `NonIsolatedAsyncInheritsIsolationFromContext` feature and add a feature for `@execution`
2025-02-21 09:07:04 -08:00
Pavel Yaskevich
dd1be8f6d4 [Frontend] Hide @execution attribute behind an experimental feature ExecutionAttribute
Since the proposal has not been approved yet we cannot expose
`@execution` attribute.
2025-02-20 00:05:03 -08:00
Pavel Yaskevich
613fbaf76e [Sema] Either variant of @execution is incompatible with other isolation
According to the proposal both variants cannot be used together
with other forms of isolation i.e. isolated parameters, global
actors, `@isolated(any)` attributes.
2025-02-19 20:06:15 -08:00
Pavel Yaskevich
e2ff3308be [Frontend] NFC: Rename NonIsolatedAsyncInheritsIsolationFromContext feature
New name is `AsyncCallerExecution` as stated by the proposal.
2025-02-19 20:00:56 -08:00
Michael Gottesman
3ef18eaf1d Merge pull request #79300 from gottesmm/pr-12bede947a34719b34b1aa8ea6c126a6126d6dd6
[concurrency] Implement serialization for execution(caller)/execution(concurrent).
2025-02-19 18:29:02 -08:00
Allan Shortlidge
6d624aab0e Tests: Increase test coverage for _PackageDescription availability. 2025-02-18 21:31:48 -08:00
Allan Shortlidge
3c8a57f86d AST: Use consolidated availability constraint query for diagnostics.
Switch to calling `swift::getAvailabilityConstraintsForDecl()` to get the
unsatisfied availability constraints that should be diagnosed.

This was intended to be NFC, but it turns out it fixed a bug in the recently
introduced objc_implementation_direct_to_storage.swift test. In the test,
the stored properties are as unavailable as the context that is accessing them
so the accesses should not be diagnosed. However, this test demonstrates a
bigger issue with `@objc @implementation`, which is that it allows the
implementations of Obj-C interfaces to be less available than the interface,
which effectively provides an availability checking loophole that can be used
to invoke unavailable code.
2025-02-16 07:44:45 -08:00
Pavel Yaskevich
1cd181dcfc [Sema] Only @execution(concurrent) cannot be used with other forms of isolation 2025-02-13 14:35:57 -08:00
Rintaro Ishizaki
153421f816 Merge pull request #79311 from rintaro/dump-declcontext
[ASTDumper] Dump DeclContext
2025-02-13 03:30:49 -08:00
Rintaro Ishizaki
71b24665fa [ASTDumper] Dump DeclContext
* Include `DeclContext` of the node where possible
* Add 'default-with-decl-contexts' dump style that dumps the dect context
  hierarchy in addition to the AST
* Support `-dump-parse` with `-dump-ast-format json`
2025-02-12 10:53:33 -08:00
Michael Gottesman
945d36ed97 [concurrency] Allow for nonisolated and execution(concurrent) to be used together.
After some discussions, we decided to allow for this since it doesnt harm anything. execution(caller) just takes primacy over it.
2025-02-12 10:38:06 -08:00
Allan Shortlidge
aa7bd6063c Tests: Add tests for decls that are unavailable and introduced later.
NFC.
2025-02-12 07:20:15 -08:00
Allan Shortlidge
19a0b93d33 Tests: Cover more cases in macCatalyst availability tests. 2025-02-08 22:47:01 -08:00
Michael Gottesman
d33371a51a Merge pull request #79178 from xedin/execution-attr-in-type-context
[AST/Parse] Initial implementation of `@execution(concurrent | caller)` in type context
2025-02-06 18:44:00 -08:00
Pavel Yaskevich
aad858d66c [Sema] Implement validation of @execution(...) in type context 2025-02-05 10:11:38 -08:00
Pavel Yaskevich
01e3bd0636 [AST] Disconnect @execution(...) attribute from the feature flag
The attribute has to be available without feature flag on so that
it could be adopted preemptively, before the behavior change.
2025-02-05 00:16:57 -08:00
Allan Shortlidge
8534f29ef5 Merge pull request #79122 from tshortli/loosen-more-available-than-enclosing-extension
Sema: Loosen more available than enclosing extension diagnostic
2025-02-04 16:31:20 -08:00
Tony Allevato
c5f0200680 Merge pull request #79059 from allevato/json-ast-followups
[ASTDumper] Some followups from the initial JSON PR and macro dumping improvements.
2025-02-04 01:13:46 -05:00
Allan Shortlidge
aed1a013e4 Sema: Loosen more available than enclosing extension diagnostic.
When diagnosing a declaration that is more available than its context, to
preserve source compatibility we need to downgrade the diagnostic to a warning
when the outermost declaration is an extension. This logic regressed with
https://github.com/swiftlang/swift/pull/77950 and my earlier attempt to fix
this (https://github.com/swiftlang/swift/pull/78832) misidentified what had
regressed.

Really resolves rdar://143423070.
2025-02-03 14:07:27 -08:00
Allan Shortlidge
1e76f19be9 Sema: Reject version specs in @available attributes for custom domains. 2025-01-31 17:31:13 -08:00
Allan Shortlidge
5c61a2d53e Sema: Require experimental feature to use custom availability domains. 2025-01-31 17:31:13 -08:00
Allan Shortlidge
770ddad742 AST/Sema: Look up custom availability domains by name.
Store the domain definitions defined on the command line on the `ModuleDecl` for
the main module.
2025-01-31 17:31:13 -08:00
Michael Gottesman
37720323d2 Merge pull request #78997 from gottesmm/wire-up-execution
[concurrency] Wire up execution(concurrent)/execution(caller)
2025-01-29 16:53:11 -08:00
Tony Allevato
5fe10ce86a ASTDumper: Label "interface type" -> "interface_type". 2025-01-29 13:55:00 -05:00
Allan Shortlidge
4d2a1ba479 Parse: Accept @available(DomainName).
For now `-enable-experimental-feature CustomAvailability` is required to accept
this spelling, though.
2025-01-28 13:47:42 -08:00
Allan Shortlidge
f1156765b8 Frontend: Introduce options for defining availability domains. 2025-01-28 13:47:42 -08:00
Allan Shortlidge
4fa8c559da Sema: Fix diagnostics for @available(noasync, swift). 2025-01-28 13:47:42 -08:00
Michael Gottesman
6a9afa53f7 [concurrency] Add back support for checking if we have a global actor/execution together. 2025-01-28 13:44:23 -08:00
Michael Gottesman
3415189442 [concurrency] Change execution to override inferred global actor isolation to match nonisolated.
Specifically, we were attempting to diagnose cases like the following:

```swift
@MainActor protocol P {
  func foo() async
}

struct S : P {
  @execution(concurrent) func foo() async {}
}
```

This was just an attempt to be more conservative. After some conversations, it
came up that nonisolated does not work that way... that is the compiler will
accept the following and just hop in the protocol witness thunk:

```swift
@MainActor protocol P {
  func foo() async
}

struct S : P {
  nonisolated func foo() async {}
}
```
2025-01-28 12:46:20 -08:00
Michael Gottesman
527616d105 [sema] Move some extra type checking from getIsolationFromAttribute to the attribute checker.
This never belonged in ActorIsolationRequest since it fits perfectly in the
attribute checker. This also simplifies the logic before I add code to
getIsolationFromAttribute to handle ExecutionAttribute.
2025-01-28 12:39:05 -08:00
Allan Shortlidge
174e57cdad Sema: Always allow method overrides to be as available as the context.
When a method override is as available as the class it's a member of, then it
can't be any more available. It doesn't make sense to diagnose such a method as
less available than the method it overrides. This regressed recently for
methods belonging to classes that are nested inside extensions. The
availability of the derived class may be defined by its context, but the
compiler was only checking the availability attributes directly on the class.

Resolves rdar://143600638.
2025-01-26 22:34:53 -08:00
Allan Shortlidge
904518088a Sema: Diagnose @available attibutes that cannot be noasync.
Instead of asserting.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
0854b93ec8 Tests: Upstream a few availability related tests for visionOS.
Resolves rdar://124158932.
2025-01-25 12:25:40 -08:00
Tony Allevato
9907afa0a0 Merge pull request #78463 from allevato/json-ast-new
Add a flag to dump the AST as JSON.
2025-01-24 15:30:24 -08:00
Allan Shortlidge
3b7ff19630 Sema: Loosen the decl more available than enclosing diagnostic.
Downgrade the `cannot be more available than enclosing scope` error to a
warning when the attribute making the decl too available is specified for a
less specific platform.

Resolves rdar://143423070.
2025-01-22 17:02:37 -08:00
Tony Allevato
8df48e52ff Address more reviewer feedback. 2025-01-22 14:26:14 -05:00
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
ec792c4292 Tests: Add regression tests for transitive Swift language mode availability. 2025-01-20 18:27:45 -08:00
Allan Shortlidge
113568f569 Tests: Fix spelling in attr_availability_transitive_osx.swift. 2025-01-20 18:27:45 -08:00
Pavel Yaskevich
c89ba5f58c [Sema] Diagnose clash between inferred global actor isolation and @execution(concurrent) 2025-01-17 15:40:01 -08:00
Pavel Yaskevich
b1e30b22b9 [Sema] Impliment initial validation of @execution(concurrent) attribute 2025-01-17 15:40:01 -08:00
Pavel Yaskevich
0445e5af5f [Parse] Implement parsing of @execution(...) decl attribute 2025-01-17 15:40:01 -08:00
Anthony Latsis
6a0834f2fc Sema: Minor improvements to access_control_non_objc_open_member message
* Use the '%kindonly' specifier.
* Make the object and its modifier agree on grammatical number.
* 'in extension' → 'declared in extension'.
2025-01-12 15:28:00 +00:00
Anthony Latsis
531ad28996 Sema: Specify compatibility margin for access_control_non_objc_open_member
This diagnostic was staged in
https://github.com/swiftlang/swift/pull/38991 as a warning to not break
source. Give it a reasonable margin and, in turn, convey that it is in
fact a compatibility warning and will become an error.
2025-01-12 03:03:49 +00:00