Commit Graph

28234 Commits

Author SHA1 Message Date
Michael Gottesman
918756f854 Merge pull request #80374 from gottesmm/pr-ee297e6b432cd07483ec86444ffd6a8b5334c203
[concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
2025-03-31 09:20:01 -07:00
James Brown
913733f508 [CS] Dont wrap packexp in extra layer of expansion
Arguments that were already pack expansions were being wrapped in a
second layer--preventing some would-be unambiguous overloads from
resolving. This adds a check to avoid doing that.
2025-03-31 11:07:33 -04:00
Michael Gottesman
f245389bb3 [concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
Specifically:

1. I made it so that thunks from caller -> concurrent properly ignore the
isolated parameter of the thunk when calling the concurrent function.

rdar://148112362

2. I made it so that thunks from concurrent -> caller properly create a
Optional<any Actor>.none and pass that into the caller function.

rdar://148112384

3. I made it so that in cases where we are assigning an @Sendable caller to a
non-sendable caller variable, we allow for the conversion as long as the
parameters/results are sendable as well.

rdar://148112532

4. I made it so that when we generate a thunk from @execution(caller) ->
@GlobalActor, we mangle in @GlobalActor into the thunk.

rdar://148112569

5. I discovered that due to the way we handle function conversion expr/decl ref
expr, we were emitted two thunks when we assigned a global @caller function to a
local @caller variable. The result is that we would first cast from @caller ->
@concurrent and then back to @caller. The result of this would be that the
@caller function would always be called on the global queue.

rdar://148112646

I also added a bunch of basic tests as well that showed that this behavior was
broken.
2025-03-30 20:00:05 -07:00
Allan Shortlidge
e5d0cd4e51 Merge pull request #80322 from tshortli/allow-swift-runtime-symbol-declarations 2025-03-30 16:14:40 -07:00
Allan Shortlidge
8f2d5a759e Merge pull request #80321 from tshortli/warnings 2025-03-30 16:14:21 -07:00
Allan Shortlidge
2fb76a468a Merge pull request #80333 from tshortli/clock-measure-unsafe-inherit-executor 2025-03-30 16:14:07 -07:00
Anthony Latsis
880d7e5621 Merge pull request #80342 from AnthonyLatsis/andrias-japonicus
Diag: Handle `CustomAttr` in `formatDiagnosticArgument`
2025-03-29 20:36:48 +00:00
Hamish Knight
4efe08e3ae Merge pull request #80379 from hamishknight/extendable-expansion 2025-03-29 17:55:59 +00:00
Doug Gregor
813f1dcb85 Merge pull request #80384 from DougGregor/isolated-conformances-checkedcast-enable
Prohibit isolated conformances for checked casts to potentially-SendableMetatype types
2025-03-29 01:27:31 -07:00
Holly Borla
68b95f8764 Merge pull request #80382 from hborla/isolation-crash
[Concurrency] When expanding `#isolation` create a type-checked type expr for global actors.
2025-03-28 22:30:32 -07:00
Becca Royal-Gordon
65dc578de6 Merge pull request #80360 from beccadax/rdar144811653 2025-03-28 19:01:01 -07:00
Hamish Knight
b63ed2bf01 Merge pull request #80339 from hamishknight/macroscope
[ASTScope] Re-enable `checkSourceRangeBeforeAddingChild`
2025-03-29 00:36:50 +00:00
Doug Gregor
2f5c6d21bb Collapse experimental feature StrictSendableMetatypes into IsolatedConformances 2025-03-28 16:55:33 -07:00
Holly Borla
9c1f7e3ca5 [Concurrency] When expanding #isolation create a type-checked type
expr for global actors.

This eliminates a crash when type checking `#isolation` expansions
for global actors nested in other types, because the `TypeExpr`
does not properly represent the type repr for nested types. It's
simpler to provide the type directly instead of going through type
resolution.
2025-03-28 15:43:11 -07:00
Pavel Yaskevich
4c4ed53051 Merge pull request #80367 from xedin/rdar-137825558
[ConstraintSystem] Use `findSelectedOverloadFor` in `isArgumentGeneri…
2025-03-28 15:30:10 -07:00
Hamish Knight
a359816a3a [Macros] Ban extension macros on local nested types
Make sure we check whether we are in any local parent context.
2025-03-28 21:35:59 +00:00
Hamish Knight
aaeb38d7f4 [Macros] Expand extension macros at the top-level
Ensure we always expand extension macros after the top-level decl
for the given attached decl. This ensures correct unqualified lookup
behavior, and bans macro implementations from extending the
unqualified name (they're expected to use `providingExtensionsOf`
instead, which uses the qualified name).

rdar://148119538
2025-03-28 21:35:59 +00:00
Allan Shortlidge
5dc7a204cb Sema: Address -Wunused-but-set-variable warnings. 2025-03-28 12:33:40 -07:00
Allan Shortlidge
82cd87187f AST: Introduce the AllowRuntimeSymbolDeclarations experimental feature.
This feature only exists as a mechanism to suppress the warning introduced in
https://github.com/swiftlang/swift/pull/75378. The RegexParser module, which is
effectively part of the standard library, declares a Swift runtime symbol and
as a result every build of the compiler and stdlib produces warnings which
there are no plans to address. Warnings that are not going to be addressed need
some way of being suppressed, and an experimental features seems like a
reasonable mechanism for this one.
2025-03-28 12:32:47 -07:00
Doug Gregor
fd24d29055 Merge pull request #80357 from DougGregor/strict-safety-improvements
Strict safety improvements
2025-03-28 11:58:44 -07:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Pavel Yaskevich
62d19c5d45 [ConstraintSystem] Use findSelectedOverloadFor in isArgumentGenericFunction
Fixes a crash when existing logic cannot properly determine whether
argument is resolved or not.

Instead of ad-hoc code that checks `ResolvedOverloads` directly, let's
use a method that would reach of a callee locator to determine whether
argument is a reference to a generic function or not.

Resolves: rdar://137825558
2025-03-28 00:41:13 -07:00
Pavel Yaskevich
2bb098c0ba Merge pull request #79560 from stzn/fix-subscript-sending-result
Add sending to subscript sending result
2025-03-28 00:26:29 -07:00
Doug Gregor
a5df17ea3c Suppress new @safe @unsafe error in Swift interfaces 2025-03-27 22:06:38 -07:00
Anthony Latsis
72c0d4cc75 Diag: Handle CustomAttr in formatDiagnosticArgument 2025-03-28 02:03:38 +00:00
Anthony Latsis
fffa8c2f51 Diag: Abstract away some calls to DeclAttribute::getAttrName 2025-03-28 02:01:27 +00:00
Becca Royal-Gordon
ce8cc1780a Ignore bad @_hasStorage in module interfaces
An objcImpl bug previously caused `@_hasStorage` to be emitted inside some extensions in module interfaces. An earlier commit in this PR created an error for this, but for backwards compatibility, it would actually be better to simply ignore the attribute in module interfaces. Modify TypeCheckStorage to emit a warning, not an error, in this situation.

Additionally, modify the module interface loader to show warnings when you verify a module interface, but not for other module interface uses (like compiling or importing one). The assumption here is that if you’re verifying a module interface, you’re either the author of the module that created it or you’re investigating a problem with it, and in either case you’d like to be told about minor defects in case they’re related.

Fixes rdar://144811653 thoroughly.
2025-03-27 18:25:11 -07:00
Doug Gregor
8789871035 Diagnose @safe @unsafe when used together
Fixes rdar://147943857.
2025-03-27 16:28:44 -07:00
Becca Royal-Gordon
c44284d874 Diagnose invalid @_hasStorage attributes
A bug in `@objc @implementation` is causing incorrect `@_hasStorage` attributes to be printed into module interfaces. As an initial step towards fixing this, diagnose bad `@_hasStorage` attributes and treat them as computed properties so that these malformed interfaces don’t cause compiler crashes.

Partially fixes rdar://144811653.
2025-03-27 16:24:44 -07:00
Doug Gregor
d86f41a922 Improve Fix-It for if let x where x is a reference to an unsafe value
When we encounter unsafe code in `if let x`, we would produce a Fix-It
that would change it to the ill-formed `if let unsafe x`. Improve
tracking of the expressions that are synthesized for the right-hand
side of these conditions, so that we can produce a Fix-It that turns
this into the proper

    if let x = unsafe x

Fixes rdar://147944243.
2025-03-27 16:20:30 -07:00
Holly Borla
eaf00fecb4 Merge pull request #80330 from hborla/nonisolated-unsafe-let
[Concurrency] Never treat `nonisolated(unsafe)` properties as actor isolated.
2025-03-27 11:45:05 -07:00
Pavel Yaskevich
367e5e20f1 Merge pull request #80329 from xedin/execution-caller-func-to-parameter-isolation-func
[CSSimplify] Allow conversion from caller isolated to parameter isola…
2025-03-27 10:35:09 -07:00
Doug Gregor
90a2b3d8a0 Look through "unsafe" expressions when checking for single-value statements
We were rejecting the use of switch expressions on the right-hand side
of an assignment that was marked `unsafe`. Fixes rdar://147944753.
2025-03-27 09:49:34 -07:00
Pavel Yaskevich
6082173b8a Merge pull request #80280 from xedin/rdar-131732245
[TypeChecker] Avoid dropping pre-check diagnostics in `typeCheckParam…
2025-03-27 08:59:43 -07:00
Holly Borla
1732a4d4ba Merge pull request #80331 from hborla/isolated-sendable-local-function
[Concurrency] Infer `@Sendable` for global actor isolated function references.
2025-03-27 06:22:16 -07:00
Slava Pestov
09a4e16ac0 Merge pull request #80301 from slavapestov/subst-generic-function-type
Clean up GenericFunctionType substitution
2025-03-27 08:20:59 -04:00
Hamish Knight
21d09a047f [Macros] Handle function body source range for body macro
Make sure it receives a SourceRange that covers the entire body,
since that's what it replaces.
2025-03-27 11:31:24 +00:00
Allan Shortlidge
2f78ba8828 Sema: Extend _unsafeInheritExecutor_ hack to Clock.measure().
Fixes the bug in `swift::introduceUnsafeInheritExecutorReplacements()` that
prevented the hack from working with `Clock.measure()`. It isn't sufficient to
just check whether the nominal for the type base of a qualified lookup belongs
to the Concurrency module because that type may reference multiple types.
Instead, check all of the directly referenced types to match the behavior of
qualified lookup.

Resolves rdar://132581483.
2025-03-26 21:12:58 -07:00
Holly Borla
0983bb5f71 [Concurrency] Infer @Sendable for global actor isolated function references. 2025-03-26 20:38:20 -07:00
Holly Borla
796dc9218b [Concurrency] Never treat nonisolated(unsafe) properties as actor
isolated.
2025-03-26 19:31:01 -07:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Pavel Yaskevich
cdae26aece [CSSimplify] Allow conversion from caller isolated to parameter isolation function types
This requires special handling during function type matching
because caller isolated function types don't get an isolated
parameter until SILGen.
2025-03-26 17:55:48 -07:00
Slava Pestov
fef485b786 Distributed: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Slava Pestov
ed441e0ea2 Sema: Replace calls to subst() on a GenericFunctionType with substGenericArgs() 2025-03-26 20:06:07 -04:00
Slava Pestov
3b2cbbb3d9 Sema: Move old overload of substGenericArgs() to TypeOfReference.cpp 2025-03-26 20:06:06 -04:00
Hamish Knight
1de7b3fc9c Merge pull request #80303 from hamishknight/off-the-chain
[Sema] Fix optional chaining behavior with postfix operators
2025-03-26 23:22:08 +00:00
Pavel Yaskevich
d656f74652 [TypeChecker] Avoid dropping pre-check diagnostics in typeCheckParameterDefault
`typeCheck{Expression, Target}` has a pre-check phase which would
replace some invalid AST nodes (i.e. name references that are not
available in the given declaration context) with `ErrorExpr`s and
emit a diagnostic. Such diagnostics were then dropped by `abort()`
call to a diagnostic transaction. This results in invalid code being
accepted by Sema and forwarded to SILGen.

Resolves: https://github.com/swiftlang/swift/issues/73986
Resolves: rdar://131732245
2025-03-26 14:22:32 -07:00
Becca Royal-Gordon
715911142d Improve diagnosis of generic types in @abi
A same-type constraint in an enclosing `where` clause will eliminate a generic parameter’s ABI impact. Teach `ABIDeclChecker::checkType()` about this so it can handle a known-unsupported case for `Swift.Result.init(catching:)`.
2025-03-26 10:47:58 -07:00
Becca Royal-Gordon
446dc9d609 Diagnose mismatched typed throws in @abi 2025-03-26 10:47:58 -07:00
Becca Royal-Gordon
ef738e6b5a Make @abi type diagnostics more specific
Specify whether the type with the problem is a result type, parameter type (and which parameter), etc.
2025-03-26 10:47:58 -07:00