Commit Graph

21976 Commits

Author SHA1 Message Date
Erik Eckstein
f962d76362 GenericSpecializer: don't pre-specialize C++ reference type for AnyObject
Reference counting is not compatible.
Fixes a runtime crash if a C++ reference type is put into an Array.

https://github.com/swiftlang/swift/issues/83082
rdar://155919841
2025-07-16 21:30:36 +02:00
Meghana Gupta
8387b7db14 Update callers of getLoweredOwnership() and add a test 2025-07-16 11:34:14 -07:00
Meghana Gupta
c2836af597 Fix getLoweredOwnership() for setters of ~Escapable types 2025-07-16 10:47:02 -07:00
Anthony Latsis
90f9fce339 Merge pull request #82665 from swiftlang/jepa4
Bridging: Bridge some basic classes like `swift::SourceLoc` directly
2025-07-16 08:27:12 +01:00
Slava Pestov
de068cb130 Merge pull request #83070 from slavapestov/remove-redundant-functor
AST: Remove MakeAbstractConformanceForGenericType
2025-07-15 23:44:59 -04:00
Allan Shortlidge
fa267fefff Merge pull request #83051 from tshortli/diagnose-more-invalid-os-versions
Sema: Diagnose invalid platform versions in more places
2025-07-15 17:06:39 -07:00
Allan Shortlidge
99380bf00f Sema: Sometimes allow universally unavailable declarations to be referenced.
In implicit contexts that are universally unavailable, allow writable key paths
to be formed to properties with setters that are also marked as universally
unavailable. This fixes a regression from the previous commit where the code
synthesized for `@Observable` properties in universally unavailable classes was
rejected by the availability checker.
2025-07-15 14:08:57 -07:00
Anthony Latsis
5620abbad8 Bridging: Bridge swift::CharSourceRange directly 2025-07-15 21:34:48 +01:00
Slava Pestov
ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Anthony Latsis
9001ce4687 Bridging: Bridge swift::SourceRange directly 2025-07-15 21:33:28 +01:00
Anthony Latsis
6eb5d7d857 Bridging: Bridge swift::SourceLoc directly 2025-07-15 21:33:06 +01:00
Sina Mahdavi
03843475c1 Add -scanner-prefix-map-paths to the frontend 2025-07-15 10:46:50 -07:00
Gábor Horváth
761c50364c Merge pull request #83002 from Xazax-hun/guard-more-objc
[cxx-interop] Types exposed from ObjC modules should be behind a macro
2025-07-15 17:07:53 +01:00
fahadnayyar
a4eeae2a01 [cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag (#82488)
This patch re-enables diagnostics for unannotated C++ functions or
methods returning `SWIFT_SHARED_REFERENCE` types. These warnings now
fire only **once per source location**, even in the presence of multiple
template instantiations. This avoids diagnostic duplication that was a
key source of noise in the compilation of larger codebases.

These warnings were previously disabled starting in **Swift 6.2** via
[PR-#81411](https://github.com/swiftlang/swift/pull/81411) due to
concerns around false positives and excessive duplication in projects
adopting C++ interop. This patch addresses the duplication issue by
adding source-location-based caching, which ensures that a warning is
emitted only once per source location, even across template
instantiations with different types.

However, the false positive issue remains to be investigated and will be
addressed in a follow-up patch. Until that happens, the warnings are
gated behind a new experimental feature flag:
`WarnUnannotatedReturnOfCxxFrt`. This feature will be enabled by default
only after thorough qualification and testing on large C++ codebases.

rdar://154261051
2025-07-15 02:56:34 -07:00
Allan Shortlidge
d09e117dc0 AST: Canonicalize platform versions for @backDeployed attrs.
Also, diagnose invalid platform versions.

Part of rdar://155558161.
2025-07-14 16:40:16 -07:00
Allan Shortlidge
910989c2c2 AST: Store parsed version in OriginallyDefinedInAttr instead of canonical.
Canonicalize the version on-demand instead.

NFC, part of rdar://155558161.
2025-07-14 16:04:04 -07:00
Slava Pestov
deb80cd985 Merge pull request #83004 from slavapestov/fix-rdar155624135
AST: Change RequirementEnvironment::getRequirementToWitnessThunkSubs() to use contextual types
2025-07-11 21:11:49 -04:00
Anthony Latsis
06a5670c8f Basic: Untie swift::SourceLoc from llvm::SMLoc
Storing a `llvm::SMLoc` is a superfluous indirection, and getting rid of
it enables us to unconditionally import `SourceLoc` into Swift.
2025-07-11 18:48:42 +01:00
Slava Pestov
7bde868468 AST: Simplify RequirementEnvironment construction a bit more 2025-07-11 13:31:50 -04:00
Slava Pestov
03de964154 AST: Change RequirementEnvironment::getRequirementToWitnessThunkSubs() to use contextual types
In the provided test case, the generic signature of the
protocol requirement is

    <Self, T where Self == T.A, T: P2>

The conformance requirement `Self: P1` is derived from `T: P2`
and `Self.A: P1` in P1. So given a substitution map
`{ Self := X, T := T }` that replaces T with a concrete type X
and T with a type parameter T, there are two ways to recover a
substituted conformance for `Self: P1`:

- We can apply the substitution map to Self to get X, and look
  up conformance of X to P1, to get a concrete conformance.

- We can evaluate the conformance path `(T: P2)(Self.A: P1)`,
  to get an abstract conformance.

Both answers are correct, but SILGenModule::emitProtocolWitness()
was assuming it would always get a concrete conformance back.

This was the case until e3c8f423bc,
but then we started returning an abstract conformance. SILGen
would then mangle the protocol witness thunk in a way that was
not sufficiently unique, and as a result, we could miscompile
a program where two witness tables both hit this same scenario.

By using contextual types in the getRequirementToWitnessThunkSubs()
substitution map, we ensure that evaluating the conformance path
against the substitution map produces the same result as performing
the global lookup.

Also, to prevent this from happening again, add a check to SILGen
to guard against emitting two protocol witness thunks with the
same mangled name.

Unfortunately, this is done intentionally as part of some
backward deployment logic for coroutine accessors. There is a
hack to allow duplicate thunks with the same name in this case,
but this should be revisited some day.

Fixes rdar://problem/155624135..
2025-07-11 13:31:35 -04:00
Gabor Horvath
9b1b9b774b [cxx-interop] Types exposed from ObjC modules should be behind a macro
Functions or template instantiations with Obj-C types should always be
behind a macro to make sure the interop header compiles cleanly in C++.

rdar://152836730
2025-07-11 18:22:39 +01:00
Allan Shortlidge
302fa00a31 Merge pull request #82962 from tshortli/layout-prespecialization-feature 2025-07-10 21:28:36 -07:00
Allan Shortlidge
96d0450d62 Merge pull request #82940 from tshortli/silgen-custom-availability-domain-query
ClangImporter: Generate and call custom availability domain predicates
2025-07-10 13:16:14 -07:00
Allan Shortlidge
c6dad96492 Make LayoutPrespecialization a baseline feature instead of experimental.
Since LayoutPrespecialization has been enabled by default in all compiler
invocations for quite some time, it doesn't make sense for it to be treated as
experimental feature. Make it a baseline feature and remove all the
checks for it from the compiler.
2025-07-10 11:25:28 -07:00
Anthony Latsis
8cbf5a26e4 Bridging: Bridge swift::DeclBaseName directly 2025-07-10 17:58:13 +01:00
Anthony Latsis
0e0fbc4160 Bridging: Bridge swift::Identifier directly 2025-07-10 17:58:13 +01:00
Allan Shortlidge
3d722e1919 ClangImporter: Generate and call custom availability domain predicates.
When importing custom availability domains with dynamic predicates from Clang
modules, synthesize predicate functions for `if #available` queries and call
them when generating SIL.

Resolves rdar://138441312.
2025-07-10 08:15:01 -07:00
Slava Pestov
abd15af7a5 ASTVerifier: Dump expression in checkTrivialSubtype() 2025-07-09 22:16:14 -04:00
Slava Pestov
aa87afd2cb AST: Fix printing of BuiltinFixedArrayType 2025-07-09 22:16:14 -04:00
Slava Pestov
3c6b2a20a5 AST: Allocate BuiltinFixedArrayType in the solver arena if needed 2025-07-09 22:16:14 -04:00
Doug Gregor
d2afd8700e [SE-0466] Enable SendableProhibitsMainActorInference by default
This implements the SE-0466 amendment under discussion for all code
with default main-actor isolation.

Finalizes rdar://151029300.
2025-07-09 10:44:39 -07:00
Gábor Horváth
c33ce3f029 Merge pull request #82840 from Xazax-hun/unqualified-name-lookup-fix
[cxx-interop] Fix unqualified name lookup failure
2025-07-08 17:53:35 +01:00
Gabor Horvath
4de92656dd [cxx-interop] Fix unqualified name lookup failure
When MemberImportVisibility is enabled we failed to find certain base
methods from the extensions when said base methods are imported from
C++.

rdar://154887575
2025-07-08 12:41:01 +01:00
Slava Pestov
2a968251b0 Merge pull request #82854 from slavapestov/cache-invertible-conformances
AST: Cache isNoncopyable() and isEscapable() bits inside TypeBase
2025-07-08 07:20:17 -04:00
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
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
b91ed32698 AST: Cache isNoncopyable() and isEscapable() bits inside TypeBase 2025-07-07 17:57:32 -04: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
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
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
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
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
Alexis Laferrière
f101bfd969 Merge pull request #82697 from xymus/cdecl-misc
AST: Misc improvements to `@decl` enums: implicit names, code gen fix and more tests
2025-07-03 15:44:34 -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
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