Commit Graph

28352 Commits

Author SHA1 Message Date
Pavel Yaskevich
eb7b76525c Merge pull request #79651 from xedin/sendability-checks-for-function-conversions
[Concurrency] Implement sendability checking for `@Sendable` function…
2025-03-04 09:33:59 -08:00
Doug Gregor
c169f8850b Merge pull request #79760 from DougGregor/isolated-conformances-checking
Ensure that isolated conformances originate in the same isolation domain
2025-03-04 07:49:53 -08:00
Artem Chikin
13a8d4b88e [Compile Time Values] Add a new experimental feature and the parsing of the '@const' attribute 2025-03-04 07:30:57 -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
Anthony Latsis
1fc853141f Sema: Implement adoption mode for ExistentialAny 2025-03-04 13:43:28 +00:00
Anthony Latsis
2771f36ced LangOptions: Refactor feature state and API to account for adoption mode 2025-03-04 13:43:28 +00:00
Doug Gregor
5c67cffbc0 Prevent infinite recursion with conformance enumeration. 2025-03-03 22:14:54 -08:00
Holly Borla
8be41edf6f [Concurrency] Add a macro for wrapping a function body in a new task. 2025-03-03 20:51:14 -08:00
Doug Gregor
064e0c6264 Ensure that isolated conformances originate in the same isolation domain
This is the missing check for "rule #1" in the isolated conformances proposal,
which states that an isolated conformance can only be referenced within
the same isolation domain as the conformance. For example, a
main-actor-isolated conformance can only be used within main-actor code.
2025-03-03 17:47:50 -08:00
Pavel Yaskevich
156a43d162 [Concurrency] Make sure that conversion that switches from one actor to another is not accepted 2025-03-03 15:23:34 -08:00
Pavel Yaskevich
23739ef9af [Concurrency] Converting from @execution(concurrent) to actor-isolated crosses an isolation boundary 2025-03-03 14:42:09 -08:00
Pavel Yaskevich
1a42c153b8 [Concurrency] Converting from nonisolated to @execution(caller) does not cross an isolation boundary 2025-03-03 14:25:11 -08:00
Allan Shortlidge
dc2fe53089 AST: Rename a couple of AvailabilityConstraint::Reason cases.
Choose names that don't imply availability is versioned, since custom
availability will support domains that are version-less (they are simply
available or unavailable).
2025-03-02 15:08:37 -08:00
Allan Shortlidge
dc3df46dd5 Merge pull request #79730 from tshortli/availability-comparisons
AST: Consolidate availability version remapping
2025-03-02 14:41:57 -08:00
Allan Shortlidge
3b9ca2f397 AST: Consolidate availability version remapping.
Introduce `SemanticAvailableAttr` conveniences to compute the deprecated and
obsoleted ranges for an attribute and ensure they remap versions when needed.
2025-03-01 20:23:11 -08:00
Doug Gregor
ee2450f212 Merge pull request #79724 from DougGregor/isolated-conformances-constraint-system
Prohibit isolated conformances with Sendable(Metatype) constraints
2025-03-01 13:16:32 -08:00
Doug Gregor
6a4d1a41c4 Prohibit isolated conformances with Sendable(Metatype) constraints
Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
2025-03-01 08:19:42 -08:00
Allan Shortlidge
309db1c220 Sema: Update feature availability diagnostics to take AvailabilityDomain. 2025-02-28 14:46:34 -08:00
Allan Shortlidge
bc982097b9 AST/Sema: Adopt AvailabilityDomain arguments in even more diagnostics.
Update potential unavailability diagnostics to take `AvailabilityDomain`
instead of a platform string.
2025-02-28 14:13:24 -08:00
Allan Shortlidge
c89df2fc38 AST/Sema: Adopt AvailabilityDomain arguments in more diagnostics.
Update explicit unavailability and deprecation diagnostics to take
`AvailabiiltyDomain` instead of a platform string.
2025-02-28 13:57:00 -08:00
Pavel Yaskevich
bb247d7eb7 [TypeChecker] Fix @_dynamicReplacement to skip sendable annotations on ObjC declarations
Refactors `@_dynamicReplacement` attribute verification to consider
only exact matches first, and if there are none, attempt to strip
away sendability on ObjC declarations to make sure that any new
`@Sendable` or `any Sendable` introduced to `@precocurrency` declarations
don't break the overload selection.
2025-02-28 13:24:05 -08:00
Pavel Yaskevich
3032add0ad [Sema] Allow associated type inference to skip @Sendable on ObjC witnesses
Witness checking itself is allowed to skip `@Sendable` mismatch in this
situation. This is a narrow fix for `SendableCompletionHandlers` feature
to make sure that the behavior doesn't change for non-ObjC witnesses
2025-02-28 13:24:00 -08:00
Doug Gregor
ffca6968ed [Isolated conformances] Diagnose conflict with isolated conformances and Sendable 2025-02-28 13:08:35 -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
Pavel Yaskevich
51c833f2a9 Merge pull request #79617 from xedin/isolate-buildBlock-in-if-and-case-statements
[BuilderTransform] Type-check `buildBlock` of each condition body separately from "join" operation
2025-02-27 16:45:22 -08:00
Slava Pestov
d8a1649722 Merge pull request #79666 from slavapestov/fix-rdar144644342
Sema: Fix Sendable generic parameter fixit
2025-02-27 18:37:50 -05:00
Slava Pestov
e37a2d065d Sema: Fix Sendable generic parameter fixit
Fixes rdar://problem/144644342.
2025-02-27 13:15:13 -05:00
Doug Gregor
7c7ea1dfd5 [SE-0458] Suppress "no unsafe operations" warnings outside of strict mode
This is a stop-gap solution to prevent spurious warnings when "unsafe"
expressions and for..in loops are used without strict memory safety.

The full answer is probably to determine where unsafe code is all the time,
so that we can still (correctly) diagnose "no unsafe operations" even outside
of strict memory safety mode.
2025-02-27 09:20:36 -08:00
Hamish Knight
af3e7e7655 Merge pull request #79633 from hamishknight/out-of-context
[Sema] Remove generic environment tracking from StmtChecker
2025-02-27 09:26:13 +00:00
Doug Gregor
db0d658351 Merge pull request #79645 from DougGregor/enable-se-0458-by-default
[SE-0458] Enable unsafe expressions / attributes / for..in effects by default
2025-02-26 18:51:58 -08:00
Pavel Yaskevich
45ca72ed73 [Concurrency] Implement sendability checking for @Sendable function type conversions
Function conversions that cross an isolation boundary require `Sendable`
argument and result types, and the destination function type must be `async`.
2025-02-26 16:11:16 -08:00
Doug Gregor
b7b5a2a19d [SE-0458] Enable unsafe expressions / attributes / for..in effects by default
With the acceptance of SE-0458, allow the use of unsafe expressions, the
@safe and @unsafe attributes, and the `unsafe` effect on the for..in loop
in all Swift code.

Introduce the `-strict-memory-safety` flag detailed in the proposal to
enable strict memory safety checking. This enables a new class of
feature, an optional feature (that is *not* upcoming or experimental),
and which can be detected via `hasFeature(StrictMemorySafety)`.
2025-02-26 12:30:07 -08:00
Alejandro Alonso
acbae0cf34 Merge pull request #79618 from Azoy/another-bug-another-dollar
[AST] Directly store GTPD in TypeValueExpr
2025-02-26 07:59:09 -08:00
Hamish Knight
1138bcc800 [Sema] Remove generic environment tracking from StmtChecker
This is no longer necessary now that we use
`mapLocalArchetypesOutOfContext` to assign depths for generic
signatures involving element archetypes.
2025-02-26 12:02:05 +00:00
Doug Gregor
71e23ac757 Check consistency of isolation of conformances within other conformances
When a protocol conformance somehow depends on an isolated conformance, it
must itself be isolated to the same global actor as the conformance on
which it depends.
2025-02-25 23:03:50 -08:00
Doug Gregor
52c46f838a Parsing and type checking for the definition of isolated conformances
Allow a conformance to be "isolated", meaning that it stays in the same
isolation domain as the conforming type. Only allow this for
global-actor-isolated types.

When a conformance is isolated, a nonisolated requirement can be
witnessed by a declaration with the same global actor isolation as the
enclosing type.
2025-02-25 21:16:51 -08:00
Allan Shortlidge
9c9ba6805a Parse/Sema: Fix diagnostics for missing wildcards in @available.
The previous algorithm failed to correctly handle the cases where some grouped
`@available` attributes could be marked invalid prior to type checking
attributes.
2025-02-25 19:45:39 -08:00
Slava Pestov
7e58d8271f Merge pull request #79619 from slavapestov/cleanups-from-optimize-optional-conversion
Small cleanups from "optimize optional conversion"
2025-02-25 22:28:19 -05:00
Pavel Yaskevich
ffbbfb76bc [ConstraintSystem] Strip Sendable while processing AnyObject lookup results
All of the declarations returned by dynamic `AnyObject` lookup
are `@objc` and hence `@preconcurrency` which means that it should
be possible to introduce `@Sendable` and `any Sendable` annotations
without affecting lookup and shadowing behavior.
2025-02-25 15:40:49 -08:00
Slava Pestov
3a01f206c5 Sema: Rename LocatorPathElt::OptionalPayload to ::OptionalInjection 2025-02-25 17:22:41 -05:00
Slava Pestov
d56d7045a2 Sema: Remove dead diagnostic 2025-02-25 17:22:41 -05:00
Slava Pestov
b35f929dc8 Sema: Rename TypeCheckSourceFileRequest to TypeCheckPrimaryFileRequest 2025-02-25 17:22:41 -05:00
Allan Shortlidge
d07e852db1 Merge pull request #79602 from tshortli/availability-spec-storage
AST: Use `AvailabilityDomainOrIdentifier` to store domains in `AvailabilitySpec`
2025-02-25 14:21:23 -08:00
Alejandro Alonso
15c32e117b Directly store GTPD in TypeValueExpr 2025-02-25 14:11:55 -08:00
Pavel Yaskevich
d70f14e936 [BuilderTransform] If: Save result of buildBlock into a variable before using in buildEither
Similar to `case` statements, if chain is non-optional, let's
isolate `buildBlock` of every branch into a separate type variable.
2025-02-25 13:09:35 -08:00
Pavel Yaskevich
3add37514e [BuilderTransform] Case: Save result of buildBlock into a variable before using in buildEither
Fixes implementation issue where build block is type-checked as part
of `buildEither(...)`. This is incorrect according to the original
proposal (SE-0289), `buildBlock` should be type-checked independently
and `buildEither` should have no effect on what overload of `buildBlock`
gets selected.
2025-02-25 13:09:34 -08:00
Doug Gregor
47a7867f88 Merge pull request #79593 from DougGregor/unsafe-conformances-outside-unsafe
[SE-0458] Don't warn about unsafe conformances outside of strict safety mode
2025-02-25 12:07:15 -08:00
Pavel Yaskevich
050c69df17 Merge pull request #79592 from xedin/rdar-131819800
[CSFix] Fix a null pointer dereference in `getStructuralTypeContext`
2025-02-25 09:56:37 -08:00
Pavel Yaskevich
fabe70eff3 Merge pull request #79599 from xedin/rdar-145341605
[Concurrency/Diagnostics] A few fixes to diagnostic downgrades and tracking
2025-02-25 09:55:50 -08:00