Commit Graph

46217 Commits

Author SHA1 Message Date
Pavel Yaskevich
dab6f3d12e Merge pull request #82807 from xedin/se-0487-implementation-adjustments
[AST/Sema] SE-0487: Adjust implementation based on the LSG feedback
2025-07-08 00:03:36 -07:00
Pavel Yaskevich
1c546e93fa Merge pull request #82857 from xedin/inheritActorContext-and-nonisolated-nonsending
[Concurrency] Prevent use of `nonisolated(nonsending)` and `@concurrent`
2025-07-08 00:03:23 -07:00
Doug Gregor
cee2aeadbb Merge pull request #82846 from DougGregor/isolated-conformance-to-sendablemetatype-proto-error
[SE-0470] Promote isolated-conformance-to-sendable-metatype protocol to an error
2025-07-07 21:06:47 -07:00
Slava Pestov
e67be5c683 Merge pull request #82690 from slavapestov/fix-rdar116938972
Sema: Improve the 'protocol method can't impose new requirements on Self' check
2025-07-07 23:25:58 -04:00
Pavel Yaskevich
e42ac61d9f [Concurrency] Prevent use of nonisolated(nonsending) and @concurrent on @_inheritActorContext parameters
`@_inheritActorContext` is a form of isolation which precludes
direct use of inference of `nonisolated(nonsending)` and `@concurrent`
just like other isolation attributes/modifiers would i.e. `isolated`
or `@isolated(any)`.
2025-07-07 17:13:28 -07:00
Artem Chikin
2c1b596c73 Merge pull request #82460 from artemcm/ScanDepsDiagnoseOnlyIncompatibleCandidates
[Dependency Scanning] Diagnose an error when only finding incompatible Swift binary modules
2025-07-07 16:28:16 -07:00
Egor Zhdan
569ca005e8 Merge pull request #82680 from swiftlang/egorzhdan/enable-c-frt
[cxx-interop] Enable foreign reference types in C interop
2025-07-07 19:42:06 +01:00
Doug Gregor
56e38b33b6 [SE-0470] Promote isolated-conformance-to-sendable-metatype protocol to error
Forming an isolated conformance to a SendableMetatype-inherting
protocol opens up a soundness hole any time the conformance is used.
Reword the recently-introduced diagnostic for this case and promote it
to an error (except when it's preconcurrency).

Fixes rdar://154808002.
2025-07-07 11:35:19 -07:00
Artem Chikin
8961d8da9a [Dependency Scanning] Diagnose an error when only finding incompatible Swift binary modules
When querying a Swift module, the scanner now also keeps track of all discovered candidate binary modules which are not compatible with current compilation.

- If a Swift dependency is successfully resolved to a compatible binary module or a textual interface, a warning is emitted for every incompatible binary Swift module discovered along the way.
- If a Swift dependency is not resolved, but incompatible module candidates were found, an error is emitted - while it is likely that the scan would fail downstream, it is also possible that an underlying Clang module dependency (with the same name) is successfuly resolved and the Swift lookup failure is ignored, which is still going to lead to failures most of the time if the client code assumes the presence of the Swift overlay module in this scenario.

This change refactors common error reporting by the scanner into a 'ModuleDependencyIssueReporter' class, which also keeps track of all diagnosed failed lookups to avoid repeating diagnostics.
2025-07-07 11:11:34 -07:00
Artem Chikin
b889976dc9 Merge pull request #82695 from artemcm/DepScanCycleShadow
[Dependency Scanning] Emit a note if a dependency cycle is between the source target and another Swift module with the same name
2025-07-07 10:52:14 -07:00
Slava Pestov
4dc0db31f9 Sema: Improve the 'protocol method can't impose new requirements on Self' check
This check had two problems. First, it would assert upon encountering
a layout requirement, due to an unimplemented code path.

A more fundamental issue is that the logic wasn't fully sound, because
it would miss certain cases, for example:

    protocol P {
      associatedtype A

      func run<B: Equatable>(_: B) where B == Self.A
    }

Here, the reduced type of `Self.A` is `B`, and at first glance, the
requirement `B: Equatable` appears to be fine. However, this
is actually a new requirement on `Self`, and the protocol be rejected.

Now that we can change the reduction order by assigning weights to
generic parameters, this check can be implemented in a better way,
by building a new generic signature first, where all generic
parameters introduced by the protocol method, like 'B' above, are
assigned a non-zero weight.

With this reduction order, any type that is equivalent to
a member type of `Self` will have a reduced type rooted in `Self`,
at which point the previous syntactic check becomes sound.

Since this may cause us to reject code we accepted previously,
the type checker now performs the check once: first on the original
signature, which may miss certain cases, and then again on the new
signature built with the weighted reduction order.

If the first check fails, we diagnose an error. If the second
check fails, we only diagnose a warning.

However, this warning will become an error soon, and it really
can cause compiler crashes and miscompiles to have a malformed
protocol like this.

Fixes rdar://116938972.
2025-07-07 12:23:58 -04:00
Allan Shortlidge
6e08b8980f SILGen: Refactor emission of availability checks.
Generalize SILGen for `if #available` checks by delegating the determination of
the query function and its arguments to `AvailabilityQuery`. Update SILGen for
`@backDeployed` thunks to use the same infrastructure.

NFC.
2025-07-06 19:44:53 -07:00
Allan Shortlidge
a4f59f9481 AST: Return @backDeployed attribute along with version from Decl query.
Also, introduce a convenience on `BackDeployedAttr` for getting its associated
`AvailabilityDomain`.

NFC.
2025-07-06 19:44:53 -07:00
Slava Pestov
27e65732b1 Merge pull request #82785 from slavapestov/fix-rdar154684522
RequirementMachine: Increase default type differences limit to 13000
2025-07-06 16:37:43 -04:00
Doug Gregor
2e27ff8734 Merge pull request #82814 from DougGregor/region-inference-dynamic-isolated-conformances
[SE-0470] Extend region analysis to account for isolated conformances
2025-07-06 09:24:17 -07:00
Slava Pestov
f8cf708753 RequirementMachine: Increase default type differences limit to 13000
Fixes rdar://154684522.
2025-07-06 11:22:47 -04:00
Meghana Gupta
61fc2e052a Merge pull request #82787 from meg-gupta/lifetimediag
Fix a lifetime dependence diagnostic
2025-07-04 21:11:45 -07:00
Pavel Yaskevich
0444d297b6 [AST/Sema] SE-0487: Remove @preEnumExtensibility attribute 2025-07-04 11:06:44 -07:00
Pavel Yaskevich
43eec8fede [AST/Sema] SE-0487: Expand @nonexhaustive attribute to support warn argument
The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility`
attriubte.
2025-07-04 10:20:25 -07:00
Alastair Houghton
57d056e1a3 Merge pull request #82457 from al45tair/external-executor-test-support
[Concurrency] Add functions to allow testing of external executors.
2025-07-04 09:52:57 +01:00
Doug Gregor
deec3e1cd5 [SE-0470] Warn about isolated conformance to SendableMetatype-inheriting protocol
An isolated conformance to a SendableMetatype-inheriting protocol
cannot actually be used in generic code, because the SendableMetatype
requirement itself prevents it. Warn about this case so folks aren't
surprised at runtime.

This is a part of issue #82550 / rdar://154437489.
2025-07-03 22:27:23 -07:00
Pavel Yaskevich
fe1ae75711 [AST/Sema] SE-0487: Rename @extensible into @nonexhaustive
This is an accepted spelling for the attribute. This commit
also renames the feature flag from `ExtensibleAttribute` to
`NonexhaustiveAttribute` to match the spelling of the attribute.
2025-07-03 17:50:05 -07:00
Meghana Gupta
6d0a6d2760 Fix a lifetime dependence diagnostic
`LifetimeDescriptor::getName()` can crash if the descriptor had a `self`.
Replace with `LifetimeDescriptor::getString()`
2025-07-03 15:20:23 -07:00
Saleem Abdulrasool
a2f5d2a746 Merge pull request #82699 from compnerd/feature
ClangImporter: remove Darwin alias workaround, introduce feature
2025-07-03 13:45:45 -07:00
Evan Wilde
576a3784b6 Merge pull request #82698 from etcwilde/ewilde/skip-unused-section-headers
RemoteInspection: Skip unused ELF section headers
2025-07-03 10:33:19 -07:00
Michael Gottesman
677b897ff6 Merge pull request #82555 from gottesmm/pr-b4de2f5d58d852cd3e9e606101e1b0ff42ce6092
[nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
2025-07-03 05:22:57 -07:00
Hamish Knight
31408fe5cb Merge pull request #82724 from hamishknight/diag-it 2025-07-03 09:23:44 +01:00
Hamish Knight
e2a8ace0ca Merge pull request #82721 from hamishknight/err-val 2025-07-03 09:23:24 +01:00
Slava Pestov
d27ce6465d Merge pull request #82726 from slavapestov/fix-sil-cloner-no-sub-map
SILCloner: Fix logic error when cloning without a substitution map
2025-07-02 23:55:18 -04:00
Mike Ash
2062b33e78 Merge pull request #82312 from mikeash/swift-retain-method-tail-call
[Runtime] Tail call swift_retain in ObjC retain implementation.
2025-07-02 22:06:28 -04:00
Michael Gottesman
010fa39f31 [rbi] Use interned StringRefs for diagnostics instead of SmallString<64>.
This makes the code easier to write and also prevents any lifetime issues from a
diagnostic outliving the SmallString due to diagnostic transactions.
2025-07-02 16:50:24 -07:00
Allan Shortlidge
ede7bdb5d7 Merge pull request #82671 from tshortli/zippered-miscompile-if-unavailable
SILGen: Fix `if #unavailable` mis-compile for zippered libraries
2025-07-02 16:05:51 -07:00
Michael Gottesman
14634b6847 [rbi] Begin tracking if a function argument is from a nonisolated(nonsending) parameter and adjust printing as appropriate.
Specifically in terms of printing, if NonisolatedNonsendingByDefault is enabled,
we print out things as nonisolated/task-isolated and @concurrent/@concurrent
task-isolated. If said feature is disabled, we print out things as
nonisolated(nonsending)/nonisolated(nonsending) task-isolated and
nonisolated/task-isolated. This ensures in the default case, diagnostics do not
change and we always print out things to match the expected meaning of
nonisolated depending on the mode.

I also updated the tests as appropriate/added some more tests/added to the
SendNonSendable education notes information about this.
2025-07-02 13:03:13 -07:00
Hamish Knight
dd28c531f1 Merge pull request #82648 from hamishknight/emplace
[Parse] Fix `isEditorPlaceholder` checks in the parser
2025-07-02 20:32:10 +01:00
Artem Chikin
c1d58adbb9 Merge pull request #82525 from benb/incremental-hash
Add incremental-file-hashing options to swift-driver
2025-07-02 12:20:12 -07:00
Michael Gottesman
4433ab8d81 [rbi] Thread through a SILFunction into print routines so we can access LangOpts.Features so we can change how we print based off of NonisolatedNonsendingByDefault.
We do not actually use this information yet though... This is just to ease
review.
2025-07-02 12:13:52 -07:00
Michael Gottesman
4ce4fc4f95 [rbi] Wrap use ActorIsolation::printForDiagnostics with our own SILIsolationInfo::printActorIsolationForDiagnostics.
I am doing this so that I can change how we emit the diagnostics just for
SendNonSendable depending on if NonisolatedNonsendingByDefault is enabled
without touching the rest of the compiler.

This does not actually change any of the actual output though.
2025-07-02 12:13:50 -07:00
Allan Shortlidge
59d74fa1c7 Sema: Diagnose opaque types that depend on availability of a custom domain.
Serialization and IRGen don't yet support opaque return types that would depend
on querying availability of a custom domain so we need to reject this code to
avoid mis-compiling it.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
4a76c04cf5 SILGen: Fix if #unavailable mis-compile for zippered libraries.
Inverted availability queries were mis-compiled for zippered libraries because
the code that emits calls to `isOSVersionAtLeastOrVariantVersionAtLeast()` was
not updated when the `if #unavailable` syntax was introduced (at that time
support for zippered libraries had not yet been upstreamed). The result of
these calls is now inverted when appropriate.

To make it easier to manage the growing complexity of supporting availability
queries, Sema now models the relevant information about an availability query
with the new `AvailabilityQuery` type. It encapsulates the domain for the
query, the result if it is known at compile time, and the version tuple
arguments to pass to a runtime invocation if applicable.

Resolves rdar://147929876.
2025-07-02 11:23:42 -07:00
Arnold Schwaighofer
0442c7c417 Merge pull request #82646 from aschwaighofer/wip_opt_remarks_wmo
Support LLVM optimization remarks in WMO mode
2025-07-02 10:40:35 -07:00
Hamish Knight
a18f72c29a Constify DiagnosticState::determineBehavior
Split out the state mutation into a new `updateFor`
function that we call for diagnostic emission, allowing
`DiagnosticTransaction::hasErrors` to query the behavior without
mutating any state.
2025-07-02 17:46:10 +01:00
Pavel Yaskevich
c677554d3a Merge pull request #82689 from xedin/rdar-154754939
[Concurency] Allow declarations with `@isolated(any)` parameters be m…
2025-07-02 09:33:05 -07:00
Slava Pestov
a1b008cba8 SILCloner: Fix logic error when cloning without a substitution map
If we have no substitution map, we still substitute types appearing
in the original function, because we need to remap any local
archetypes, which are always cloned.

However, the conformance lookup callback used for this substitution
was wrong. We should only do mapTypeOutOfContext() if we're going
to callSubstitutionMap::lookupConformance(), otherwise we form a
new abstract conformance with an interface type, and not a primary
archetype as expected.
2025-07-02 11:59:39 -04:00
Saleem Abdulrasool
c08372a91d ClangImporter: remove Darwin alias workaround, introduce feature
Introduce a feature flag to add the importing of macro aliases. Remove
the Darwin specific carve out.
2025-07-02 08:30:03 -07:00
Hamish Knight
1bd32a1a6b NFC: Constify GenericTypeParamDeclGetValueTypeRequest's parameter 2025-07-02 14:46:55 +01:00
Doug Gregor
46572f80a2 Merge pull request #82661 from DougGregor/back-deploy-main-actor-isolated-deinit
[SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-01 20:50:19 -07:00
Pavel Yaskevich
a522448e90 [Concurency] Allow declarations with @isolated(any) parameters be marked as @concurrent/nonisolated(nonsending)
It's shouldn't be possible to use these attributes directly on
the function type that is `@isolated(any)` as per SE-0461 proposal
but it shouldn't preclude declarations that have parameters with
`@isolated(any)` from using them.

Resolves: rdar://154754939
2025-07-01 15:07:23 -07:00
Evan Wilde
14d2088c75 FreeBSD: Skip unused ELF section headers
ELF section headers are allowed to be left uninitialized when the
section is empty and unused. LLD is a tad more aggressive about this.
The ELF reader in the Swift runtime was a bit aggressive about
converting the section headers to names and would not skip over these
unused sections headers resulting in crashes due to operating on
uninitialized memory in the `sh_name` field.

This patch teaches the ELF reader to skip over unused section header
table entries.
2025-07-01 14:25:52 -07:00
Artem Chikin
0d3def55df [Dependency Scanning] Emit a note if a dependency cycle is between the source target and another Swift module with the same name
The note will point the user to where the "other" module with the same name is located and mention whether it is an SDK module. This is nice to have in various circumstances where developers attempt to define a module with the same name as a Swift module that already exists on their search paths, for example in the SDK.
2025-07-01 13:38:45 -07:00
Joe Groff
1c75d3b740 Merge pull request #82323 from jckarter/addressable-for-dependencies-vw-flag
Add an "addressable for dependencies" flag to value witness flags.
2025-07-01 13:02:17 -07:00