Commit Graph

22727 Commits

Author SHA1 Message Date
Anton Korobeynikov
595abee2c1 First cut of parameter pack differentiation 2025-07-25 15:15:56 -07:00
Slava Pestov
bb4f61e97b Merge pull request #83141 from slavapestov/fix-rdar82992151
Sema: Improve the infinite opaque return type check
2025-07-19 09:30:17 -04:00
Allan Shortlidge
5d98ca63c7 Merge pull request #83168 from tshortli/custom-availability-domain-fix-its
AST/Sema: Generalize availability fix-its to support custom availability domains
2025-07-18 21:45:57 -07:00
Slava Pestov
4eaa7e3b47 AST: Add -max-substitution-count= and -max-substitution-depth= frontend flags 2025-07-18 20:03:03 -04:00
Slava Pestov
8d05d79fad AST: Cache substituted substitution maps inside the InFlightSubstitution
A substitution map contains conformances, and a conformance can contain
a substitution map. This will always be a DAG, but not a tree, and to
avoid exponential blowup in certain edge cases, let's cache the work to
avoid visiting the same substitution map repeatedly, if multiple
conformances refer to the same substitution map.
2025-07-18 20:03:03 -04:00
Slava Pestov
103428fe80 AST: More robust recursion check for opaque types with infinite underlying types
Tracking seen declarations and substitution maps only detects the
situation where the opaque type's underlying type contains itself
with the same substitution map. However, it is also possible to
recurse with a different substitution map.

In general termination is undecidable with a problem like this,
so instead of trying to catch cycles, just impose a termination
limit.

This converts a stack overflow into an assertion, which is still
not ideal; we should really diagnose something instead. But this
is a first step.
2025-07-18 20:03:03 -04:00
Slava Pestov
7a0ff5ccb6 AST: Add SubstitutionMap::DumpStyle::NoConformances and use it by default for opaque types 2025-07-18 19:12:34 -04:00
Slava Pestov
ef0164dcbd AST: Small cleanup for InFlightSubstitution 2025-07-18 19:12:33 -04:00
Artem Chikin
8682ed3a74 Merge pull request #82934 from artemcm/DepScanExplicitInput
[Dependency Scanning] Consider `-swift-module-file` inputs when looking for dependencies
2025-07-18 15:30:12 -07:00
Allan Shortlidge
034c62cf01 AST: Generalize availability fix-its to support custom availability domains.
Resolves rdar://156118254.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
aeb5a46d9e AST: Emit warnings for redundant availability checks in custom domains. 2025-07-18 13:27:08 -07:00
Allan Shortlidge
a3fbe3d530 AST: Introduce queries on Decl for active @available attrs.
Use these queries to replace some duplicated code. Also, move the
`attr_inlinable_available.swift` test to the `Availability` sub-directory since
the test has more to do with availability checking than it has to do
specifically with the `@inlinable` attr.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
6b29700554 Merge pull request #83162 from tshortli/misc-availability-cleanups
Miscellaneous availability cleanups
2025-07-18 12:03:46 -07:00
Artem Chikin
bd14089551 Warn on multiple '-swift-module-file' options 2025-07-18 10:05:55 -07:00
Artem Chikin
e08b78226c [Dependency Scanning] Consider '-swift-module-file' inputs when looking for dependencies
Previously this flag was only used to pass explicit dependencies to compilation tasks. This change adds support for the dependency scanner to also consider these inputs when resolving dependencies.

Resolves https://github.com/swiftlang/swift-driver/issues/1951
2025-07-18 09:48:02 -07:00
Susana Monteiro
0337f7e64a Merge pull request #83067 from susmonteiro/rename-virtual-methods
[cxx-interop] Adding swift_name attributes to virtual methods overrides
2025-07-18 11:57:46 +01:00
Allan Shortlidge
634f28176e AST: Move parentDeclForInferredAvailability() to Decl.
NFC.
2025-07-17 18:59:14 -07:00
Allan Shortlidge
4a7e76775a AST: Add llvm::raw_ostream conveniences for availability constructs.
Make it easier to debug availability by printing to output streams like
`llvm::errs()`.

NFC.
2025-07-17 18:59:01 -07:00
Gábor Horváth
4b9ef8c53c Merge pull request #83130 from Xazax-hun/objc-configurable-from-frontend
[cxx-interop] Configure requires ObjC from frontend option
2025-07-18 02:29:48 +01:00
Allan Shortlidge
d0929b67ce AST: Remove AvailabilityInference::isAvailableAsSPI().
It has been replaced by `Decl::isAvailableAsSPI()`.

NFC.
2025-07-17 14:14:21 -07:00
Gabor Horvath
4b64abdc45 [cxx-interop] Configure requires ObjC from frontend option
We sometimes don't have the information in the modulemaps whether a
module requires ObjC or not. This info is useful for reverse interop.
This PR introduces a frontend flag to have a comma separated list of
modules that we should import as if they had "requires ObjC" in their
modulemaps.
2025-07-17 21:29:50 +01:00
Steven Wu
fbfc7a6f71 Merge pull request #82745 from sina-mahdavi/sina-mahdavi/new-scanner-prefix-map-option
Add `-scanner-prefix-map-paths` to the frontend
2025-07-17 11:35:06 -07:00
susmonteiro
585ca5e2da [cxx-interop] Adding swift_name attributes to virtual methods overrides 2025-07-17 16:23:32 +01:00
Allan Shortlidge
59b136ccc4 Merge pull request #83054 from tshortli/unavailable-setters-require-read-only-key-paths
ConstraintSystem: Make key paths for properties with unavailable setters read-only
2025-07-16 21:31:41 -07:00
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
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
Konrad `ktoso` Malawski
9cc555c567 Merge pull request #83053 from ktoso/pick-better-class-sendable-diagnostic
[Concurrency] add fixit to add final to non-sendable class -> Sendable
2025-07-15 17:23:30 +09:00
Konrad 'ktoso' Malawski
03774d245a fix some tests due to diagnostic rewording 2025-07-15 11:16:13 +09:00
Konrad 'ktoso' Malawski
f52f445358 [Concurrency] add fixit to add final to non-sendable class -> Sendable
The previous message was just suggesting unchecked Sendable, but instead
we should be suggesting to add final to the class. We also don't
outright suggest using unchecked Sendable -- following
https://github.com/swiftlang/swift/pull/81738 precedent.

Resolves rdar://155790695
2025-07-15 10:42:25 +09: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
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
Pavel Yaskevich
020596918d Merge pull request #82961 from gottesmm/pr-b3685ba26b885701787f7b6087dc7d9d873aa500
[rbi] Teach SendNonSendable how to more aggressively suppress sending errors around obfuscated Sendable functions
2025-07-11 10:15:21 -07: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
Michael Gottesman
ea4d0440f4 Revert "[Concurrency] Prevent use of nonisolated(nonsending) and @concurrent on @_inheritActorContext parameters"
This reverts commit e032f33cfb.
2025-07-10 11:15:00 -07:00
Anthony Latsis
8cbf5a26e4 Bridging: Bridge swift::DeclBaseName directly 2025-07-10 17:58:13 +01:00