Commit Graph

2958 Commits

Author SHA1 Message Date
Pavel Yaskevich 8299e40652 [CSSimplify] NFC: Clarify why recordTypeVariablesAsHoles isn't used to propagate holes to arguments/result 2026-06-01 16:25:31 -07:00
Pavel Yaskevich 201e76bfa6 [ConstraintSystem] Propagate a hole from function value to arguments/result
In diagnostic mode, propagate function value placeholder/hole to
arguments and result. This helps to avoid recording extraneous
fixes because generic parameters and leading-dot syntax arguments
cannot be inferred in this case.
2026-06-01 11:28:20 -07:00
Pavel Yaskevich 910b31af23 [ConstraintSystem] Increase base score of a missing member fix
Instead of penalizing argument positions, let's increase the base
score for missing member fixes to make them more competitive in
situations where besides missing member other overloads have other
issues as well.

Resolves: rdar://169736579
2026-06-01 11:28:20 -07:00
Pavel Yaskevich 5bfe50fe12 [ConstraintSystem] Increase impact of call to non-function value fix
With the current impact this fix shadows missing/extra argument
issues associated with overloads that can be called.
2026-06-01 11:28:20 -07:00
Pavel Yaskevich 029686eeec [CSSimplify] Skip disjunctions resolved to holes
If type variable that represents a type of a disjunction is
bound to a hole, consider disjunction to be solved. This
happens only when calls are completely broken.
2026-06-01 11:28:20 -07:00
Pavel Yaskevich 58678a67f8 [CSSimplify] Don't attempt overload choices of all call arguments are invalid
Short-circuit calls where all arguments are invalid, otherwise the
solver would end up producing a solution for every overload which
it cannot disambiguate which quickly turns into "too complex" situation.
2026-06-01 11:28:19 -07:00
Egor Zhdan 3b55b4ce16 Merge pull request #88683 from egorzhdan/egorzhdan/upcast
[cxx-interop] Import inheritance hierarchy of foreign reference types
2026-05-21 13:43:50 +01:00
Egor Zhdan 6c464579db [cxx-interop] Import inheritance hierarchy of foreign reference types
This teaches ClangImporter to represent a base class of a C++ foreign reference type as a Swift superclass if the base class is an FRT itself, and is a primary base class. Such base types are stored at offset zero within the derived type, which makes casting trivial.

This makes the following possible:
* casting an instance of derived FRT to base FRT explicitly with `as`
* passing an instance of derived FRT as a function parameter of type base FRT
* calling a method of base FRT on an instance of derived FRT without the compiler having to clone methods

Several constructs are not supported:
* downcasting, i.e. casting an instance of base FRT to derived FRT
* casting arrays/sets/dictionaries of FRTs
* casting to virtual bases

Support for casting to a base FRT that is not the primary base (not at offset zero) can be added in a follow-up change.

rdar://85881664 / resolves https://github.com/swiftlang/swift/issues/80231
2026-05-20 12:24:20 +01:00
Pavel Yaskevich fee4ce302f [CSSimplify] Don't penalize passing a nonisolated closure to nonisolated(nonsending) type
When a nonisolated/@concurrent closure is passed to a
nonisolated(nonsending) parameter the solver has to be conservative
and produce a conversion that could be dissolved by actor
isolation checker when it determines that nonisolated(nonsending)
could be assumed onto the closure direct (i.e. when there are no
isolated captures involved), so let's not increase a score unless
closure states it's isolation explicitly to avoid picking a subpar
solution.
2026-05-19 16:47:30 -07:00
Xi Ge 4f60cc6e6e Merge pull request #89057 from nkcsgexi/hidden-type 2026-05-13 06:38:57 -07:00
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Slava Pestov 6b84857d6f AST: Remove useDC parameter from getDynamicMemberLookupKind() 2026-05-08 15:46:20 -04:00
Slava Pestov 94cf639f8c Sema: Replace counted for loop with for loop over indices 2026-05-08 15:46:19 -04:00
Slava Pestov fa2448b4ff Sema: Migrate dynamic member lookup to use matchCallArguments() 2026-05-08 15:46:18 -04:00
Slava Pestov 2c62d6ed5d Sema: Add MatchCallArgumentResult::dump() 2026-05-08 15:46:18 -04:00
Slava Pestov b062b8a285 Convert SubscriptDecl @dynamicMemberLookup checking to request
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
2026-05-08 15:46:17 -04:00
Itai Ferber f448191d34 Support additional args in @dynamicMemberLookup subscripts
Adds support for `SubscriptDecl`s to fulfill `@dynamicMemberLookup`
requirements if they have additional arguments after `dynamicMember:` so
long as those arguments have default values, or are variadic.

This allows exposing values like `#function`, `#fileID`, `#line`, etc.
to dynamic member lookup.
2026-05-08 15:46:17 -04:00
Slava Pestov e4f99cc3be Use SubscriptDecl interface for @dynamicMemberLookup checks
`SubscriptDecl` exposes eligibility for `@dynamicMemberLookup`
requirements directly, so the `TypeChecker` interface for these members
can be replaced.
2026-05-08 15:46:17 -04:00
Itai Ferber c191d4994c Cache SubscriptDecl @dynamicMemberLookup eligibility
`SubscriptDecl`s may get checked multiple times for eligibility in
fulfilling `@dynamicMemberLookup` requirements; since the checks are
non-trivial and the result doesn't change, this eligibility can be
cached in the decl's `Bits`.
2026-05-08 15:46:17 -04:00
Egor Zhdan 122bd990fd [cxx-interop] Do not crash on references to global non-copyable non-movable variables
C++ types that are non-copyable and non-movable are not imported into Swift.

Variables of such types are marked as invalid in Swift by ClangImporter, however, compilation still proceeds without emitting any errors, unless the user attempts to use the problematic type from Swift. This differs from pure-Swift where having invalid decls are not allowed.

This adjusts the typechecker to account for the fact that a declaration coming from Clang might be invalid and not diagnosed at the same time. Instead of crashing in SILGen, let's emit a typechecking error.

rdar://137880350
2026-05-05 16:36:18 +01:00
Konrad Malawski a6617f8801 rename isNonisolatedNonsendingCaller -> isNonisolatedNonsending 2026-04-28 09:21:46 -07:00
Konrad Malawski 2b8026dd94 rename isNonIsolatedCaller -> isNonisolatedNonsendingCaller 2026-04-28 09:21:46 -07:00
Pavel Yaskevich 5da31f9d32 [CSSimplify] Handle situations when generic argument mismatch happens in a synthesized argument
If the argument was synthesized by the solver, let's fail. This can
happen when a parameter type is optional and (currently) inference
would try both optional and non-optional bindings for the new
argument which cases a mismatch in one of the conversion cases.

Resolves: https://github.com/swiftlang/swift/issues/88456
Resolves: rdar://174723056
2026-04-15 16:14:05 -07:00
Kathy Gray 0a82ff3446 Merge pull request #88032 from kathygray-pl/MissingPropertyRevert
[diagnostics] Partial reversion of member lookup impact
2026-04-08 19:15:53 +01:00
Kathy Gray dca1ca55f6 [diagnostics] Partial reversion of member lookup impact
Changing the impact of member lookup diagnostic conflicted mismatched arguments
Reverting to avoid that ambiguity.
2026-04-07 11:39:34 +01:00
Pavel Yaskevich 13553fe86c Merge pull request #88071 from xedin/rdar-173193106
Revert "Merge pull request #86773 from aeu/61733-error-message-improvement-ii"
2026-03-25 07:06:20 -07:00
Pavel Yaskevich 2016b41de5 Revert "Merge pull request #86773 from aeu/61733-error-message-improvement-ii"
This reverts commit b8459a8dbc.
2026-03-24 09:31:04 -07:00
Pavel Yaskevich 561f6492d4 [CSSimplify] Don't transfer typed throws onto the closure
This is a partial revert of https://github.com/swiftlang/swift/pull/87360

The change attempted to infer a concrete thrown error type onto
the closure but that leads to incorrect solutions when closure is
passed as an argument to an overloaded declaration because the
solver doesn't check whether calls in the body do throw the
expected type even with `FullTypedThrows` feature enabled
and so the safest option is still to assume un-typed `throws`
unless typed throws comes from a concrete contextual type.

Resolves: rdar://173132715
2026-03-24 09:27:55 -07:00
Pavel Yaskevich 14cd8ff81d Merge pull request #88003 from xedin/penalize-typed-throws-erasure
[CSSimplify] Increase score when erasing typed throws into `throws`
2026-03-24 09:23:45 -07:00
Aidan Hall c4d32f901d Merge pull request #87281 from aidan-hall/lifedep-protocol-check
Require compatible lifetimes in protocol conformance checking and function type matching
2026-03-24 14:16:56 +00:00
Pavel Yaskevich c61ef13098 [CSSimplify] Increase score when erasing typed throws into throws
This erasure requires a function conversion and a heap allocation
so if there is an overload that adopted typed throws it should be
preferred over the one with regular `throws`.

Resolves: rdar://172779708
2026-03-23 15:34:40 -07:00
Hamish Knight 178a528fd5 Merge pull request #88013 from hamishknight/more-call-per-call
[CS] Better handle rewriting implicit `callAsFunction` call splitting
2026-03-23 18:15:41 +00:00
Aidan Hall 0659f07ab9 LifetimeDependence: Lifetime subtyping for type and witness matching
- rdar://169975618 ([nonescapable] Type conversion for function types with lifetime dependencies)
- rdar://160970376 ([nonescapable] [type checker] [source compat] protocol requirements should require matching methods signatures, including @lifetime)
2026-03-23 12:53:09 +00:00
Hamish Knight 54c0870a25 [CS] Better handle rewriting implicit callAsFunction call splitting
The previous logic was relying on doing `coerceCallArguments` with the
full argument list instead of only the non-trailing args, and wasn't
handling the non-shorthand-init case. Update the logic to fix-up the
apply during the pre-walk, ensuring it gets applied consistently.

rdar://170076966
2026-03-21 13:45:27 +00:00
Slava Pestov 3c2720b8bc AST: Introduce JoinType and MeetType singletons
These will be used internally by the type checker to represent bindings
that are the joins and meets of types involving type variables. They
will not appear anywhere outside of the bindings code---so you won't
see them in expressions, or matchTypes(), etc.
2026-03-21 08:48:47 -04:00
Alfonso Urdaneta b8459a8dbc Merge pull request #86773 from aeu/61733-error-message-improvement-ii
[Sema] Improve error message when attempting to pass `(some T)?` to `(any T)?`
2026-03-12 09:21:10 -07:00
elsa 70e82cf6f6 Merge pull request #87716 from elsakeirouz/add-borrowing-for-loop-tests
Fix BorrowingSequence availability check and add BorrowingForLoop tests
2026-03-11 12:41:46 +00:00
Slava Pestov 59adfcd02b Sema: Detect conflicting subtype bindings imposed on closure type variables
A type variable that represents the type of a closure can only be bound
to a function type, but this fact is not directly encoded in the
constraint system.

Check for the appearance of a non-sensical subtype binding on a closure
type variable in reduceBinding(), and promote the binding to exact as
soon as we detect this, since binding the type will always fail; we want
to fail as quickly as possible, before attempting any more disjunctions.

This is a generally good performance optimization, and it also addresses
a performance regression from "Sema: Filter bindings by considering
conformance constraints".

This also speeds up the expression from rdar://59008707, which also uses
Combine and is slow for similar reasons.
2026-03-10 14:51:19 -04:00
Slava Pestov 9d412de2c6 Sema: Fix leading dot member chains with common result type
If common result type optimization binds the type variable
representing the member chain result before we attempt an
overload from the corresponding disjunction, the
UnresolvedMemberChainBase constraint would fail.

The specific situation this would occur was when the extension
declared overloaded members with a concrete return type instead
of Self, and then this method was part of a chain:

    extension P where Self == S {
      func f(_: Int) -> S { ... }
      func f(_: String) -> S { ... }
      func g()
    }

    ... foo(.f(3).g()) ...
2026-03-10 14:47:30 -04:00
Slava Pestov c865f397a2 Sema: Add a case for unit tests
The TestNoDoubleVoidClosureResultInference were actually not
exercising the code path they were supposed to because we
didn't check for that locator kind in getImpliedResultConversionKind().
2026-03-10 14:47:28 -04:00
Kathy Gray 977bd44e78 Merge pull request #85951 from kathygray-pl/protocolComposition
[CS] Improve member resolution lookup when theres a ProtocolCompositionType
2026-03-09 11:19:44 +00:00
Elsa Keirouz a361191bef use the ForEachStmt's DeclContext when checking for protocol availability 2026-03-06 18:06:17 +00:00
Elsa Keirouz ecada1612a add availability check for BorrowingSequence 2026-03-05 17:21:14 +00:00
Elsa Keirouz a6c591bf0a use BorrowingSequenceProtocol when appropriate 2026-03-05 17:21:14 +00:00
Kathy Gray 14f6d17d39 [CS] Improve property member lookup in presence of ProtocolCompositionTypes
Code with Protocol Composition parameters had not been taking into account
that a parameter would conform to all protocols in the composition on
member resolution and could fail to find a member for one protocol
on static lookups, resulting in a diagnostic that was incorrect even on
correct programs.

For example
```protocol P {
 static var boo
}
protocol Q {
}
func t<T: P&Q>(x: T) { }
t(.boo)```

Diagnostic of Q does not have member boo

(Yes, other diagnostics are required in this code)

This occured because P and Q were considered one path at a time.
After the change, the P&Q path is considered together instead.
2026-03-05 16:55:57 +00:00
Nate Cook 856b205170 De-underscore the BorrowingSequence protocols (#87483)
This replaces #87114, aligning the `BorrowingSequence` protocols and
related types to the Swift Evolution proposal, and without included
reparenting of `Sequence`.
2026-03-04 07:13:20 -06:00
Pavel Yaskevich dcaf02215d Merge pull request #87575 from xedin/real-rdar-170475422
[Concurrency] InferSendableFromCaptures: Capturing non-`SendableMetatype` archetypes affects sendability of a reference
2026-03-03 06:13:58 -08:00
Slava Pestov a4e47070c3 Sema: Move some code to CSDisjunction.cpp
The argument label-based pruning is similar to the type-based pruning
that I added, and I'm going to try to consolidate the duplication
a bit.
2026-02-28 14:54:07 -05:00
Pavel Yaskevich ba9ae14775 [Concurrency] InferSendableFromCaptures: Capturing non-SendableMetatype archetypes affects sendability of a reference
If a partial application captures any non-`SendableMetatype` type parameter,
then it can call methods that are isolated to the current context and so the
function value cannot be `@Sendable`.

Resolves: rdar://170475422
2026-02-27 13:13:26 -08:00
Slava Pestov 9336f9860a Merge pull request #87159 from slavapestov/exact-bindings
Sema: Exact bindings
2026-02-27 11:54:32 -05:00