Commit Graph

21504 Commits

Author SHA1 Message Date
Nate Chandler
de1d5ae894 [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-16 11:05:02 -07:00
Nate Chandler
85860f6960 [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-16 11:05:01 -07:00
Pavel Yaskevich
fde841704c [AST/Parse] Implement nonisolated(nonsending) type modifier 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
d8c64c1ff0 [AST/Sema] Intoduce nonisolated(nonsending) as a replacement for @execution(caller) 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
4a973f7b4b [AST/Sema] Replace @execution(concurrent) with @concurrent 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
8598ec670d [AST/ASTGen] Introduce @concurrent attribute to replace @execution(concurrent) spelling 2025-04-16 10:06:08 -07:00
Erik Eckstein
9f9942855a Guard the copy_block optimization with an experimental feature flag CopyBlockOptimization 2025-04-16 14:33:27 +02:00
Guillaume Lessard
353e31edfa [LifetimeDependenceMutableAccessors] add a long feature flag 2025-04-15 22:25:18 -07:00
Steven Wu
bd23859a4a Merge pull request #80751 from cachemeifyoucan/eng/PR-148465899-6.2
[6.2][Caching][Macro] Make macro plugin options cacheable
2025-04-15 09:05:33 -07:00
Doug Gregor
89f246985e Collapse two implementations into ExistentialLayout::containsNonMarkerProtocols
(cherry picked from commit 53707a121c)
2025-04-14 16:38:41 -07:00
Doug Gregor
b9ace6fb3c 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.

(cherry picked from commit 95b18d3482)
2025-04-14 16:38:37 -07:00
Doug Gregor
80d68d53e4 [SE-0470] Treat metatype of archetype/existential type with no protocol requirements as Sendable
A metatype for an archetype or existential with no (non-marker)
protocol requirements cannot, by definition, carry any (isolated)
protocol conformances with it, so it's safe to treat such metatypes as
Sendable.

(cherry picked from commit 8626404de3)
2025-04-14 16:38:33 -07:00
Doug Gregor
5e29333d6b [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.

(cherry picked from commit 3380331e7e)
2025-04-14 16:38:22 -07:00
Doug Gregor
49ebfcbab2 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.

(cherry picked from commit 92774e0a3c)
2025-04-14 16:36:54 -07:00
Allan Shortlidge
64fadaf828 AST: Stop diagnosing potentially unavailable declarations in unavailable contexts.
Potential unavailability of a declaration has always been diagnosed in contexts
that do not have a sufficient platform introduction constraint, even when those
contexts are also unavailable on the target platform. This behavior is overly
strict, since the potential unavailability will never matter, but it's a
longstanding quirk of availability checking. As a result, some source code has
been written to work around this quirk by marking declarations as
simultaneously unavailable and introduced for a given platform:

```
@available(macOS, unavailable, introduced: 15)
func unavailableAndIntroducedInMacOS15() {
  // ... allowed to call functions introduced in macOS 15.
}
```

When availability checking was refactored to be based on a constraint engine in
https://github.com/swiftlang/swift/pull/79260, the compiler started effectively
treating `@available(macOS, unavailable, introduced: 15)` as just
`@available(macOS, unavailable)` because the introduction constraint was
treated as lower priority and therefore superseded by the unavailability
constraint. This caused a regression for the code that was written to work
around the availability checker's strictness.

We could try to match the behavior from previous releases, but it's actually
tricky to match the behavior well enough in the new availability checking
architecture to fully fix source compatibility. Consequently, it seems like the
best fix is actually to address this long standing issue and stop diagnosing
potential unavailability in unavailable contexts. The main risk of this
approach is source compatibility for regions of unavailable code. It's
theoretically possible that restricting available declarations by introduction
version in unavailable contexts is important to prevent ambiguities during
overload resolution in some codebases. If we find that is a problem that is too
prevalent, we may have to take a different approach.

Resolves rdar://147945883.
2025-04-11 11:55:05 -07:00
Steven Wu
f96b81975a [Caching][Macro] Make macro plugin options cacheable
Currently, the macro plugin options are included as cache key and the
absolute path of the plugin executable and library will affect cache
hit, even the plugin itself is identical.

Using the new option `-resolved-plugin-validation` flag, the macro
plugin paths are remapped just like the other paths during dependency
scanning. `swift-frontend` will unmap to its original path during the
compilation, make sure the content hasn't changed, and load the plugin.
It also hands few other corner cases for macro plugins:

* Make sure the plugin options in the swift module is prefix mapped.
* Make sure the remarks of the macro loading is not cached, as the
  mesasge includes the absolute path of the plugin, and is not
  cacheable.

rdar://148465899
(cherry picked from commit 3d38d0dd56)
2025-04-10 16:52:15 -07:00
fahadnayyar
c37700b316 Merge pull request #80715 from swiftlang/fahadnayyar/6.2/cxx-frt-ctor
🍒 [6.2] [cxx-interop] Import public constructor of C++ foreign reference types as Swift initializers
2025-04-10 15:47:05 -07:00
fahadnayyar
f3ecb7ea8b [cxx-interop] convert CXXForeignReferenceTypeInitializers into SuppressCXXForeignReferenceTypeInitializers to be an opt-out flag
Turning the feature "ctor of C++ foreign reference types is callable as Swift Initializers" on by default.

rdar://148285972
2025-04-10 05:55:05 -07:00
Meghana Gupta
4ec6f940bd Fix printing @lifetime(&arg) for accessors in swiftinterface files 2025-04-09 10:19:12 -07:00
Meghana Gupta
7a28b5f136 Silence diagnostic when @lifetime(borrow) is used on inout parameters in swiftinterface files only 2025-04-09 10:19:12 -07:00
Meghana Gupta
8e21190ae3 [NFC] Reorganize getDependenceKindFromDescriptor 2025-04-09 10:19:11 -07:00
Meghana Gupta
00bda986a9 Introduce InoutLifetimeDependence feature 2025-04-09 10:19:11 -07:00
Meghana Gupta
374ceb6a80 [NFC] Update diagnostic msg 2025-04-09 10:18:11 -07:00
Meghana Gupta
96aeea9f2b Rename ParsedLifetimeDependenceKind::Scope -> ParsedLifetimeDependenceKind::Borrow 2025-04-09 10:18:11 -07:00
Meghana Gupta
91ad1451ce Add support for @lifetime(&arg) 2025-04-09 10:18:11 -07:00
Meghana Gupta
aa3edb4323 [NFC] Replace calls of inferLifetimeDependenceKindFromType and isCompatibleOwnership to inferLifetimeDependenceKind 2025-04-09 10:18:08 -07:00
Andrew Trick
e88265de93 Merge pull request #80646 from atrick/62-infer-mutating
[6.2] Add a "lazy" lifetime inference for mutating interface methods
2025-04-09 03:46:24 -07:00
Allan Shortlidge
494e597c93 Merge pull request #80641 from tshortli/availability-domain-serialization-6.2
[6.2] Serialization: Encode custom availability domains
2025-04-08 22:15:49 -07:00
Hamish Knight
6db33fc83b Merge pull request #80642 from hamishknight/lifetime-variance-6.2
[6.2] [Sema] Ignore types with type variables in `filterEscapableLifetimeDependencies`
2025-04-09 03:24:58 +01:00
Andrew Trick
d86553a675 Add a "lazy" lifetime inference for mutating interface methods
When type checking a .swiftinterface file, Assume that a mutating methods does
not depend on its parameters.  This is unsafe but needed because some
MutableSpan APIs snuck into the standard library interface without specifying
dependencies.

Fixes rdar://148697444 error: a mutating method with a ~Escapable 'self' requires '@lifetime(self:
...)'

(cherry picked from commit a86fe4fa30)
2025-04-08 11:40:27 -07:00
Allan Shortlidge
38e56fcec0 ModuleInterface: Guard declarations that use the $CustomAvailability feature. 2025-04-08 10:35:33 -07:00
Allan Shortlidge
1cd636d9b3 Serialization: Encode custom availability domains.
When serializing `@available` attributes, if the attribute applies to a custom
domain include enough information to deserialize the reference to that domain.

Resolves rdar://138441265.
2025-04-08 10:35:32 -07:00
Hamish Knight
87f9dcb6f8 [Sema] Ignore types with type variables in filterEscapableLifetimeDependencies
If the type still has type variables, avoid trying to check if it's
escapable.

rdar://148749815
2025-04-08 17:25:11 +01:00
Allan Shortlidge
cb444b6229 Merge pull request #80567 from tshortli/module-import-visibility-fixes-6.2
[6.2] `MemberImportVisibility` bug fixes
2025-04-08 07:13:19 -07:00
Hamish Knight
e8c85fa34b Merge pull request #80599 from hamishknight/cap-req-6.2
[6.2] [Sema] Requestify PatternBindingDecl capture computation
2025-04-08 03:30:47 +01:00
Hamish Knight
ca76d7e7e5 Merge pull request #80597 from hamishknight/message-in-a-crash-log-6.2
[6.2] [Mangler] Include verification errors in the crash log
2025-04-08 02:04:43 +01:00
Hamish Knight
362a239b02 Merge pull request #80581 from hamishknight/mangle-less-6.2
[6.2] [Mangler] Avoid mangling local discriminator for attached macros
2025-04-07 18:58:30 +01:00
Hamish Knight
999169e7ae [Sema] Requestify PatternBindingDecl capture computation
Introduce `PatternBindingCaptureInfoRequest`, and kick it after
contextualizing a property initializer. This ensures it gets run
for stored properties added by macro expansions.

rdar://143429551
2025-04-07 17:29:36 +01:00
Hamish Knight
fd7c2595f2 [Basic] Introduce abortWithPrettyStackTraceMessage
Introduce a convenience for aborting while printing a given message
to a frame of the pretty stack trace. Use this in the existing places
where we're currently doing this.
2025-04-07 17:05:35 +01:00
Hamish Knight
e1a864d867 [Mangler] Avoid mangling local discriminator for attached macros
If we're using the macro-specific local discriminator, we need to
make sure we avoid mangling the regular local discriminator in
`appendDeclName`, since that could prematurely kick local discriminator
assignment before type-checking has finished.

rdar://143834482
2025-04-07 10:26:56 +01:00
Allan Shortlidge
324fa235b0 AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled.
Unlike in Swift, Obj-C allows method overrides to be declared in extensions
(categories), even outside of the module that defines the type that is being
extended. When MemberImportVisibility is enabled, these overrides must be
filtered out to prevent them from hijacking name lookup and causing the
compiler to insist that the module that defines the extension be imported.

Resolves rdar://145329988.
2025-04-06 09:52:58 -07:00
Joe Groff
81576a639f Canonicalize different spellings of the same integer generic parameter.
`Foo<256>`, `Foo<2_56>`, and `Foo<0x100>` are all canonically the same type.
Fixes rdar://144736386.
2025-04-04 10:40:15 -07:00
Augusto Noronha
cac0abbfde Merge pull request #80380 from augusto2112/fix-opaque
[DebugInfo] Use underlying type of global variables with opaque type
2025-04-03 15:39:11 -07:00
Hamish Knight
918d4b54cf Merge pull request #80461 from hamishknight/in-sequence
[ASTScope] Allow `try` in unfolded sequence to cover following elements
2025-04-03 20:23:51 +01:00
Doug Gregor
daf8d97616 Merge pull request #80484 from DougGregor/isolated-conformances-fix-and-docs
[SE-0470] Ensure that one cannot form an isolated conformance when Self: Sendable
2025-04-02 23:00:47 -07:00
Doug Gregor
1c5372858b [SE-0470] Ensure that one cannot form an isolated conformance when Self: Sendable
While here, fix some issues around implied isolated conformances (we
could get into an inconsistent state). Also provide an educational
note discussing isolated conformances and the kinds of errors one can
see when they are used from outside of their isolation domain.
2025-04-02 18:19:09 -07:00
Allan Shortlidge
5cd5f31c9c Sema: Fix a regression in -require-explicit-availability diagnostics.
The changes in https://github.com/swiftlang/swift/pull/80040 caused the
compiler to start diagnosing extensions containing only members that are
either `@_spi`, `@_alwaysEmitIntoClient`, or unavailable when the
`-require-explicit-availability` flag is passed. Extensions should not be
diagnosed when they only contain members that would not be diagnosed
themselves.

Resolves rdar://148275432.
2025-04-02 17:12:38 -07:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Konrad `ktoso` Malawski
d15f6c7413 Merge pull request #80459 from ktoso/wip-dontcrash-on-missing-type-when-detecting-distributed-adhoc-reqs 2025-04-03 07:27:37 +09:00
Artem Chikin
2e31e4692f Merge pull request #80414 from artemcm/RestorePriorCanImportBehaviour
[Explicit Module Builds] Switch versioned `canImport` to return `true` when encountering unversioned candidate
2025-04-02 09:02:56 -07:00