Commit Graph

28404 Commits

Author SHA1 Message Date
Pavel Yaskevich
c110941c27 [Frontend] Rename AsyncCallerExecution upcoming feature to NonisolatedNonsendingBeDefault 2025-04-21 13:59:29 -07:00
Pavel Yaskevich
047d644ab3 Merge pull request #79717 from xedin/objc-handlers-are-execution-caller
[Sema/SILGen] Import ObjC async functions as `nonisolated(nonsending)` by …
2025-04-21 00:20:26 -07:00
Doug Gregor
54e4400e92 Merge pull request #80933 from DougGregor/safe-nested-in-unsafe-fixes
[Strict memory safety] Improve handling of safe types nested within unsafe ones
2025-04-20 02:31:48 -07:00
Doug Gregor
b7d41a55a5 [Strict memory safety] Treat the implicit call to a 'defer' function as implicitly 'unsafe'
This eliminates stray warnings.
2025-04-19 21:57:12 -07:00
Doug Gregor
53ca902267 [Strict memory safety] Type alias types are only unsafe if their underlying type is 2025-04-19 10:38:07 -07:00
Doug Gregor
8ec52c825c [Strict memory safety] Nested types are safe/unsafe independent of their enclosing type
When determining whether a nested type is safe, don't consider whether
its enclosing type is safe. They're independent.
2025-04-19 09:49:22 -07:00
Doug Gregor
0405f61207 [Strict memory safety] Only diagnose unsafe types in the canonical type
Typealiases involving unsafe types that resolve to safe types
should not be diagnosed.
2025-04-18 18:43:27 -07:00
Becca Royal-Gordon
8f75878455 Forbid @_borrowed in @abi
It has indirect effects on the accessors, so it shouldn’t matter, but we can defensively redirect the query to the API counterpart anyway.

This was the last `InferredInABIAttr` attribute, so we can now remove all of the infrastructure involved in supporting attribute inference.
2025-04-18 14:50:01 -07:00
Becca Royal-Gordon
239831403c Forbid lazy with @abi
It’s not clear how `@abi` would apply to the auxiliary decl used for `lazy`.
2025-04-18 14:50:01 -07:00
Becca Royal-Gordon
f01c0a7580 Diagnose CustomAttrs as needed in @abi
CustomAttr backs four different features, each of which requires a different behavior in `@abi`:

• Global actors: Permitted (and permitted to vary) since they can affect mangling
• Result builders: Forbidden inside an `@abi` since they have no ABI impact
• Property wrappers: Forbidden both inside an `@abi` and on a decl with an `@abi` since it’s not clear how we would apply `@abi` to the auxiliary decls
• Attached macros: Forbidden inside an `@abi` since an ABI-only decl has no body, accessors, members, peers, extensions, or (currently) conformances

Implement these behaviors (outside of `ABIDeclChecker` since they can’t be described there).

Macro-related tests are not included in this commit; they require matching swift-syntax changes which are being negotiated.
2025-04-18 14:47:04 -07:00
Becca Royal-Gordon
9d63cf84c7 Tweak redecl checking’s handling of generated code
Macro expansions are now treated like a part of the source file they belong to, for purposes of the “second declaration is the one that’s diagnosed” rule. This helps stabilize a behavior that was easy to perturb.
2025-04-18 14:44:24 -07:00
Becca Royal-Gordon
d81ffe854f Typecheck ABI-only VarDecls
The decl checker was effectively not being run on these because we weren’t typechecking the PBD and typechecking the VarDecl itself is basically a no-op.
2025-04-18 14:44:24 -07:00
nate-chandler
c832696226 Merge pull request #80889 from nate-chandler/rdar149352777
[CoroutineAccessors] Require underscored override.
2025-04-18 11:25:52 -07:00
Pavel Yaskevich
c25d2fab50 [Concurrency] Infer isolation of methods that override caller isolated @objc async handlers to be `@concurrent
This is behavior pre-SE-0461 which is the safest option instead
of inferring `nonisolated(nonsending)` and changing the calling
convention and foregoing Sendable checking.
2025-04-18 09:17:44 -07:00
Alexis Laferrière
e55c9bf2f8 Merge pull request #80900 from xymus/cdecl-reason-language
Sema: Simplify tracking the foreign language for @cdecl
2025-04-18 09:09:13 -07:00
Pavel Yaskevich
b3e48b40ae Merge pull request #80737 from xedin/rdar-148996589
[Concurrency] Downgrade non-Sendable type captures to warnings if clo…
2025-04-18 09:07:18 -07:00
Hamish Knight
3c302349ee Merge pull request #80853 from hamishknight/macro-async-warning 2025-04-18 16:22:28 +01:00
Pavel Yaskevich
07bad98f6d [Sema/SILGen] Import ObjC async functions as nonisolated(nonsending) by default
These functions already have special code generation that keeps them
in the caller's isolation context, so there is no behavior change here.

Resolves: rdar://145672343
2025-04-17 21:56:54 -07:00
Alexis Laferrière
384b0302c2 Sema: Simplify tracking the foreign language of an @objc decl
Apply review comments from #80744.
2025-04-17 15:33:46 -07:00
Alexis Laferrière
405a84e7d6 Merge pull request #80744 from xymus/cdecl-global-function-checking
Sema: Intro experimental @cdecl and basic C compatibility check
2025-04-17 15:31:30 -07:00
Pavel Yaskevich
f0bdecde34 Merge pull request #80872 from xedin/rdar-149107104
[TypeChecker] Allow closures to assume `nonisolated(nonsending)`
2025-04-17 13:08:58 -07:00
Nate Chandler
c28d295375 [CoroutineAccessors] Require underscored override.
If an overridden decl requires an underscored accessor, then the derived
decl requires one too.  Otherwise dispatch to a less-derived instance
could bind to the underscored accessor which lacks an override.

rdar://149352777
2025-04-17 09:23:24 -07:00
Nate Chandler
c72b1274cf [NFC] Sema: Extract static function.
In preparation for a recursive call and an additional private parameter.
2025-04-17 09:23:23 -07:00
Nate Chandler
d298602496 [NFC] CoroutineAccessors: Delete TODO.
Add a test case.
2025-04-17 09:23:23 -07:00
stzn
765f8acf7b Check sending in the process of diagnosing NonSendable types 2025-04-17 20:17:36 +09:00
nate-chandler
898075a95e Merge pull request #80828 from nate-chandler/rdar148783895
[CoroutineAccessors] Only reference when available
2025-04-16 20:38:31 -07:00
Pavel Yaskevich
3de72c5452 [TypeChecker] Allow closures to assume nonisolated(nonsending)
Always infer `nonisolated(nonsending)` from context directly on
a closure unless the closure is marked as `@concurrent`, otherwise
the closure is not going to get correct isolation and going to hop
to the wrong executor in its preamble.

Resolves: rdar://149107104
2025-04-16 17:19:21 -07:00
Hamish Knight
b36eb57dbd [Sema] Downgrade noasync diagnostic to warning for closure macro args
Downgrade to a warning until the next language mode. This is
necessary since we previously missed coercing macro arguments to
parameter types, resulting in cases where closure arguments weren't
being treated as `async` when they should have been.

rdar://149328745
2025-04-16 19:22:52 +01:00
Hamish Knight
14bd41159e NFC: Abstract away the use of '7' to represent the next language mode
Introduce `Version::getFutureMajorLanguageVersion` to make it easier
to find clients that will need to be updated once we have a new
language mode.
2025-04-16 19:22:52 +01:00
Hamish Knight
b6a09d1b33 Reapply: [CS] Make sure macro arguments go through coerceCallArguments
Previously we would avoid rewriting the arguments in CSApply, but
that can result in incorrect behavior in MiscDiagnostics passes, e.g
incorrectly treating all closure arguments as escaping. Make sure
we rewrite the arguments as we would in regular type-checking.

rdar://148665502
2025-04-16 19:22:52 +01:00
Hamish Knight
aa2bb0c9ea Merge pull request #80830 from swiftlang/revert-80583-macro-arg-apply
Revert "[CS] Make sure macro arguments go through `coerceCallArguments`"
2025-04-16 19:19:38 +01:00
Alexis Laferrière
a6beaf8deb Merge branch 'main' into cdecl-global-function-checking 2025-04-16 11:19:37 -07:00
Nate Chandler
7697a49ee9 [CoroutineAccessors] Only reference when available
Don't bind references to storage to use (new ABI) coroutine accessors
unless they're guaranteed to be available.  For example, when building
against a resilient module that has coroutine accessors, they can only
be used if the deployment target is >= the version of Swift that
includes the feature.

rdar://148783895
2025-04-15 21:13:57 -07:00
Nate Chandler
347689fb30 [NFC] AST: Extract helper method.
Several callers of `AbstractStorageDecl::getAccessStrategy` only cared
about whether the the access would be via physical storage.  Before
adding more arguments to `getAccessStrategy` for which such callers
would have to pass a sentinel value, add a convenience method for this.
2025-04-15 20:45:37 -07:00
Hamish Knight
475e02a381 Revert "[CS] Make sure macro arguments go through coerceCallArguments" 2025-04-15 18:44:14 +01:00
Alejandro Alonso
79a51dfcc1 Move resolving param type to CSApply 2025-04-14 15:33:08 -07:00
Alejandro Alonso
ae355007fc Store TypeRepr in TypeValueExpr 2025-04-14 15:33:08 -07:00
Alejandro Alonso
a884e5153d Don't ask for the typechecked body in featureset 2025-04-14 15:33:08 -07:00
Alejandro Alonso
b3f3dd79cf Handle dynamically accessing the static member from type(of:) 2025-04-14 15:32:46 -07:00
Alejandro Alonso
b34b6e58e0 Make it an error to redeclare properties with the same name as a value generic
Update value_generics.swift
2025-04-14 15:32:45 -07:00
Alejandro Alonso
1aaf2c9d29 Allow value generics to show up as static members 2025-04-14 15:32:43 -07:00
Doug Gregor
88d630446c [Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes
Thank you, Pavel!
2025-04-14 10:19:11 -07:00
Doug Gregor
c7c152b14c Downgrade more sendability errors involving metatypes to warnings 2025-04-14 08:25:27 -07:00
Doug Gregor
95b18d3482 Downgrade sendability errors to warnings when they involve non-Sendable metatypes
The introduction of non-Sendable metatypes in Swift 6.2 (via SE-0470)
will break some existing Swift 6 code. Downgrade concurrency errors
involving non-Sendable metatypes to warnings until some future
language mode to ease the transition.
2025-04-13 22:46:52 -07:00
Doug Gregor
3ed1d6c390 [SE-0470] Teach @Sendable inference on static methods about non-sendable metatypes
The code that determines whether a reference to a static method (that
is not a call) assumed that metatypes were always Sendable. This is no
longer the case, so update this code to go through the normal Sendable
checking on the metatype.
2025-04-13 15:42:04 -07:00
Doug Gregor
f09cdc2893 Fix deserialization assertion involving isolated conformances 2025-04-13 15:42:00 -07:00
Doug Gregor
e4f1b62c57 Fix crash involving captured-type checking for sendable metatypes 2025-04-13 15:41:59 -07:00
Doug Gregor
3380331e7e [SE-0470] Enable isolated conformances by default
The IsolatedConformances feature moves to a normal, supported feature.
Remove all of the experimental-feature flags on test cases and such.

The InferIsolatedConformances feature moves to an upcoming feature for
Swift 7. This should become an adoptable feature, adding "nonisolated"
where needed.
2025-04-13 15:41:53 -07:00
Doug Gregor
e8b3065293 [SE-0470] Downgrade some isolated conformance-related errors to warnings in Swift 5 2025-04-13 15:40:08 -07:00
Doug Gregor
92774e0a3c Move generic signature check for isolated conformances into GenericSignatureImpl
This is going to need a proper implementation in the requirement
machine. For the moment, provide a slightly-less-broken implementation
but leave a test case where we incorrectly accept racey code.
2025-04-13 15:40:02 -07:00