Commit Graph

1737 Commits

Author SHA1 Message Date
Slava Pestov 2c62d6ed5d Sema: Add MatchCallArgumentResult::dump() 2026-05-08 15:46:18 -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
Slava Pestov 6db1fd00e9 Sema: Don't record bogus trail changes in salvage()
In salvage(), there is a point where we're done solving, but we haven't
yet torn down ConstraintSystem::solverState, so the trail is still
active.

It was possible to cause a change to be recorded, because of the
path compression we do in TypeVariableType::getRepresentative().

We have a similar situation where we don't want to do path compression
when we're looking up a type variable's representative in the middle
of undo(). Generalize the existing UndoActive flag to Closed, and set
it after solving in salvage() as well.

While we're here, clean up an existing place where we would check
isUndoActive() to not do that anymore, so now getRepresentative() is
the only place that checks the state of the trail.

A better cleanup would be to try to refactor or eliminate SolverState
entirely, but this fix is pretty clean.

Note that the test cases are somewhat random because the exact scenario
is hard to trigger; you need to set up an invalid expression where the
type variables are set up in just the right way so that path compression
kicks in.

- Fixes rdar://152143989.
- Fixes https://github.com/swiftlang/swift/issues/81801.
- Fixes https://github.com/swiftlang/swift/issues/84884.
2026-05-06 11:51:40 -04:00
Pavel Yaskevich 4201e579be Merge pull request #88162 from CognitiveDisson/feat/scope-based-expression-type-checking-warnings
[Sema] Add scope-based analogues of -warn-long-expression-type-checking
2026-05-04 06:35:35 -07:00
CognitiveDisson 1d8432121f Rename ExpressionTimer to ComplexityTracker and pass thresholds in ctor 2026-04-30 13:43:49 +01:00
CognitiveDisson 575e69f90e [Sema] Add scope-based analogues of -warn-long-expression-type-checking 2026-04-23 10:46:03 +01:00
Pavel Yaskevich 974346026f [ConstraintSystem] NFC: Extract logic to detect whether function is generic only over thrown type 2026-03-31 13:34:54 -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
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 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 8a92cdaabc Sema: Refactor processing of BindingSet::Defaults in BindingProducer
Convert them into PotentialBindings earlier. Should be NFC.
2026-03-10 14:47:31 -04:00
Slava Pestov 601e253fd8 Sema: Inline findResolvedMemberRef() into its only caller 2026-03-10 14:47:30 -04:00
Slava Pestov 1f440f9a60 Sema: Turn subsumeBinding() into a method on BindingSet 2026-03-10 14:47:28 -04:00
Slava Pestov 9e3d18eb9f Sema: Recompute BindingSets when we begin salvage
In addition to the generation number, it is important to
recompute bindings when the constraint system transitions
from not doing salvage to salvage.

This fixes diagnostic regressions with an upcoming commit.
2026-03-10 14:47:28 -04:00
Slava Pestov bf125742aa Sema: A bit of extra debug info 2026-03-10 14:47:28 -04:00
Slava Pestov bd0c1212e2 Sema: Factor out reduceBinding() from BindingSet::addBinding() 2026-03-10 10:12:59 -04:00
Slava Pestov 7491ac8240 Sema: Teach Subtyping.cpp about tuples 2026-03-10 10:12:58 -04:00
Slava Pestov 266ac2cffb Sema: Bring back BindingSet::Protocols 2026-03-10 10:12:58 -04:00
Slava Pestov e44f9eda97 Sema: Introduce BindingSet::isConflicting() 2026-03-10 10:12:58 -04:00
Slava Pestov bd83717764 Sema: BindingSet::Bindings can be a SmallVector
We already iterate over all existing bindings when adding a new
binding, so using a DenseSet offers no benefit.
2026-03-10 10:12:58 -04:00
Slava Pestov 525902a234 Same: Cache getEffectiveOverloadType() inside the BindOverload constraint 2026-03-10 10:12:57 -04:00
Slava Pestov 2763ec3a2c Sema: Remove unused allowMembers parameter from getEffectiveOverloadType() 2026-03-10 10:12:57 -04:00
Saleem Abdulrasool f81aa70e75 Basic, Sema: adjust for LLDB (NFC)
LLDB defines `lldb::private::swift::` which causes ambiguity for
lookups. Use aliases and fully qualified names to avoid the ambiguity.
This fixes some errors with building on Windows with the GNU driver.
2026-03-04 19:17:26 -08:00
Pavel Yaskevich e6339b32e3 [ConstraintSystem] NFC: Print potential throw sites associated with a solution 2026-03-03 14:15:33 -08: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 8e271c3c5a Sema: Move getApplicableFnConstraint() from CSOptimizer.cpp to CSDisjunction.cpp 2026-02-28 14:54:07 -05:00
Slava Pestov 7a717654c7 Sema: Inline collectDisjunctions() into its only caller 2026-02-28 14:54:07 -05:00
Slava Pestov 6466a84a8d Sema: Split off Solution.h from ConstraintSystem.h 2026-02-28 14:54:07 -05:00
Slava Pestov d665a4c545 Sema: Factor out ConflictReason overload of simple_display() 2026-02-28 14:54:06 -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
Slava Pestov 5aabf9662b Sema: Remove TypeVariableType::Implementation::isSubscriptResultType() 2026-02-24 21:34:38 -05:00
Slava Pestov 2f92ab8f4d Sema: Remove BindingSet::isDelayedByDisjunction() 2026-02-24 21:34:38 -05:00
Slava Pestov ccc59af184 Sema: Factor out getImpliedResultConversionKind() from matchTypes() 2026-02-24 21:34:38 -05:00
Slava Pestov bea34b654f Sema: Try to guess lvalue-ness of type variable in binding inference
The result of this analysis will be used to rewrite 'subtypes of T'
into 'exact @lvalue T', fixing a soundness hole.
2026-02-24 21:34:37 -05:00
Slava Pestov b823d090ad Sema: Track LValueObject constraints in PotentialBindings
We would do stuff in the case where the type variable appeared on
the right, but just drop the constraint if the type variable was
on the left. In the latter case, record it in the new
PotentialBindings::LValuesOf vector.
2026-02-24 21:34:37 -05:00
Slava Pestov c2dab20402 Sema: Factor out isDelayedByDisjunction() from favoredOverDisjunction() 2026-02-24 21:34:37 -05:00
Slava Pestov d225b623dd Sema: Simplify a bit of logic in light of the previous change 2026-02-24 21:34:37 -05:00
Slava Pestov 07d56569ee Sema: Change PotentialBinding equality 2026-02-24 21:34:36 -05:00
Slava Pestov ccd0f5387a Sema: Separate AllowedBindingKind::Fallback from Exact
These cases were using Exact incorrectly.
2026-02-24 21:34:36 -05:00
Slava Pestov c2cf86e644 Sema: Inline BindingSet::isViable(PotentialBinding) into addBinding() 2026-02-24 21:34:35 -05:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Slava Pestov cfb1bacb92 Sema: Track BindingSet dirty state 2026-02-20 21:59:23 -05:00
Slava Pestov ef9ef052cf Sema: Add BindingSet::operator!= for debugging 2026-02-20 19:34:03 -05:00
Slava Pestov 434b68b354 Sema: Add PotentialBindings::GenerationNumber 2026-02-20 19:32:36 -05:00
Slava Pestov 26c274a48d Sema: Remove unused variable 2026-02-20 19:30:35 -05:00
Slava Pestov 4f70388ee1 Sema: Incremental disjunction pruning 2026-02-20 19:30:35 -05:00