Commit Graph

1783 Commits

Author SHA1 Message Date
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
CognitiveDisson 9bc81973e4 [Sema] Fix -debug-time-expression-type-checking producing no output 2026-03-25 18:28:50 +00:00
Doug Gregor 42719c8193 Merge pull request #88050 from DougGregor/async-without-concurrency
Diagnose use of `async` without the _Concurrency library
2026-03-24 03:08:41 -07:00
Doug Gregor 7be3469870 Diagnose use of async without the _Concurrency library
Code generation passes can crash if `async` is used without the
_Concurrency library present. Diagnose this in the type checker to
prevent us from going further.

Fixes issue #87068 / rdar://169919137
2026-03-23 21:37:23 -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
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 e7a94ee205 AST: Remove TypeBase::hasDependentMember()
I need to free up a bit.
2026-03-21 08:48:47 -04:00
Doug Gregor 20e65b713e Merge pull request #84474 from DougGregor/stdlib-swiftsourceinfo
Build and install .swiftsourceinfo files for the standard library + friends
2026-03-18 21:56:38 -07:00
Doug Gregor c72eab6be5 Introduce performance hints for untyped throws
Untyped throws requires a heap allocation and reference counting for
thrown errors, which can be unacceptable in very
performancce-constrained environments. Introduce a new subgroup of
performance hints, UntypedThrows, to report uses of untyped throws.

This resurrects the code we were using for diagnosing untyped throws
in Embedded Swift, repurposing it as a performance hint, which is more
appropriate.
2026-03-12 13:07:00 -07:00
Doug Gregor c261a1db0d Minor fixes to deal with the presence of .swiftsourceinfo for the Swift standard library 2026-03-11 10:58:04 -07:00
Doug Gregor 38c6ffbf0d [Embedded] Stop diagnosing untyped throws in embedded mode
It is plausible that we will introduce support for untyped throws in
Embedded Swift at some point, so don't diagnose its presence so
eagerly now. Instead, leave it until later in the pipeline when it's
actually used.

Fixes rdar://162071067, where we were getting entirely too many
warnings about this.
2026-03-11 10:52:20 -07:00
Slava Pestov 601e253fd8 Sema: Inline findResolvedMemberRef() into its only caller 2026-03-10 14:47:30 -04: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
Pavel Yaskevich 50c99da2f6 Merge pull request #87360 from xedin/typed-throws+closures
[ConstraintSystem] A few fixes for interaction between typed throws feature and closures
2026-02-23 06:57:43 -08:00
Slava Pestov 4f70388ee1 Sema: Incremental disjunction pruning 2026-02-20 19:30:35 -05:00
Pavel Yaskevich 105bdb8910 [ConstraintSystem] Propagate typed throws error type into throwing closures
In a typed throws context a throwing closure (as determined from the
body or an explicit `throws`) assumes an error type of the context that
is a subtype of `any Error`.

This is a carve out from `FullTypedThrows` feature that let's more
code that adopted typed throws to type-check without source compatibility
impact since without context a closure would still be using un-typed
throws and no additional inference of error type is done.
2026-02-20 09:14:51 -08:00
Slava Pestov 272f8fefeb Sema: Add flag to force a crash if salvage() found a valid solution 2026-02-13 08:18:26 -05:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Hamish Knight 0036130988 Revert "[CS] Add for loop compatibility hack for makeIterator/next ranking"
This reverts commit 7b729933f6.
2026-02-06 12:47:25 +00:00
Slava Pestov 9036602aa1 Sema: Split off BindingProducer.h/.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov 7cd06a5088 Sema: Split off TypeVariableType.h/.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov 061958f970 Sema: Eagerly filter out protocol extension operators
This optimizes for the case where we have a disjunction that contains an
operator defined in a protocol, and a protocol defined in a protocol
extension, and furthermore, the protocol extension operator's type is a
refinement of the protocol requirement operator's type.

In this case, there are three possibilities:

- Either the operator requirement is witnessed by a concrete operator
  in the conforming type, in which case the solution involving the
  protocol extension operator is going to be worse, so we can skip this
  choice.

- Otherwise, the protocol requirement operator is witnessed by the same
  protocol extension operator that we skipped, in which case we will find
  the same solution if we just pick the protocol requirement operator
  anyway.

- The only other possibility is that the protocol requirement operator
  is witnessed by a protocol extension operator, but also, a more
  refined protocol extension operator exists. However, it appears that in
  this case, solution ranking _also_ picks the solution involving the
  protocol requirement operator, as the new test case demonstrates.

Thus, we gain nothing by considering these protocol extension operators.
Skip them when forming the disjunction.
2026-02-03 16:34:09 -05:00
Hamish Knight 6453800b93 Merge pull request #85730 from hamishknight/wayfarer
[CS] Introduce Sendable-dependent functions
2026-01-29 19:42:37 +00:00
Hamish Knight 7b729933f6 [CS] Add for loop compatibility hack for makeIterator/next ranking
Still record overload choices for `makeIterator` and `next` when
solving a `ForEachElement` constraint. This maintains compatibility
with the previous behavior where we would solve these in the constraint
system, since the choices can affect ranking if e.g Collection's
default `makeIterator` is compared with a concrete `makeIterator`
overload. This is a complete hack though and we ought to rip this out
as soon as we can.

rdar://168840696
2026-01-27 23:30:43 +00:00
Pavel Yaskevich 956ffe08ca Merge pull request #86250 from AnirudhMathur12/fix-crash-85942
[ConstraintSystem] Fix crash when diagnosing missing args in KeyPath application
2026-01-27 07:25:23 -08:00
Hamish Knight a615b4cf02 [CS] Use Sendable dependence in adjustFunctionTypeForConcurrency
If the base captured type still has type variables when we bind the
member function type, form a Sendable dependent function type with
the base type. This will then be eliminated by TypeSimplifier once
all the type variables in the base type have been resolved.

This then allows us to remove the delaying logic from member lookup.
2026-01-27 11:06:54 +00:00
Hamish Knight 86b6acda0f [CS] NFC: Make TypeSimplifier a TypeTransform 2026-01-27 11:06:54 +00:00
Slava Pestov ee0f6dd681 Sema: Narrow down the skipProtocolSelfConstraint hack
We actually have to check this constraint, otherwise we accept invalid
code where we're referencing a protocol requirement with a concrete
base type which conditionally conforms to the protocol, but the
conditional requirements are unsatisfied.

However, we still need to skip it for AnyObject lookup, Distributed
Actors, and some weird edge case in conformance checking for isolated
conformances.

We should clean this up further later, but for now this closes a soundness
hole.

Fixes rdar://168129757.
2026-01-25 21:11:59 +00:00
Slava Pestov d860523944 Merge pull request #86760 from slavapestov/solver-shuffle
Sema: Add -solver-shuffle-disjunctions= and -solver-shuffle-choices= flags for debugging
2026-01-24 12:30:43 -05:00
Slava Pestov 30f1b0187a Sema: Add -solver-shuffle-disjunctions= and -solver-shuffle-choices= flags for debugging 2026-01-23 20:02:21 -05:00
Slava Pestov f3cfd65f3b Sema: Remove some dead code related to favoring 2026-01-23 20:02:21 -05:00
Hamish Knight 0a3d11722a [AST] Add flag to isRefutablePattern to determine IsPattern behavior
IsPattern coercions aren't properly implemented since they rely on
doing a runtime cast, which can fail for things like function subtyping.
Make clients choose what behavior they want. Unfortunately we need to
preserve the current behavior in places since it's relied upon for
things like exhaustivity checking. We ought to properly implement
coercion handling, then we should be able to remove this.
2026-01-23 15:17:28 +00:00
AnirudhMathur12 bf0e8835b6 [ConstraintSystem] Fix callee locator for KeyPath application components
Previously, `getCalleeLocator` handled `ComponentKind::Apply` by returning a locator for the current component index. This was incorrect because the callee for an application is the member being applied (the previous component), not the application itself.
This patch updates `getCalleeLocator` to use `componentElt->getIndex() - 1` for `Apply` and `UnresolvedApply` components. This ensures that the constraint system can correctly identify the callee when diagnosing argument mismatches in KeyPath expressions (e.g., `\.split(...)`), leading to correct diagnostics instead of fallback errors.

Removed null check
2026-01-23 02:27:53 +05:30
AnirudhMathur12 56cc7aeff1 [ConstraintSystem] Fix crash when diagnosing arguments in KeyPath application
The compiler previously crashed (Signal 11 or assertion failure) when diagnosing missing or mismatched arguments in KeyPath expressions (e.g., `\.split(separator: ",")`). This occurred because `getCalleeLocator` did not correctly identify the underlying function (callee) for a KeyPath application component.

This change updates `getCalleeLocator` to correctly resolve the callee to the preceding component (index - 1) in the KeyPath, as suggested during review.

Additionally, this change fixes a latent crash in `getFunctionArgApplyInfo` exposed by the locator fix. Previously, that function blindly cast the anchor to `CallExpr` when no overload was found. It now safely checks via `getAsExpr<CallExpr>` and returns `nullopt` if the anchor is a `KeyPathExpr`, preventing assertion failures.

Resolves: https://github.com/swiftlang/swift/issues/85942
2026-01-10 22:46:21 +05:30
AnirudhMathur12 0eb7804be6 [ConstraintSystem] Fix crash when diagnosing arguments in KeyPath application
The compiler previously crashed (Signal 11 or assertion failure) when diagnosing missing or mismatched arguments in KeyPath expressions (e.g., `\.split(separator: ",")`). This occurred because `getCalleeLocator` did not correctly identify the underlying function (callee) for a KeyPath application component.

Previously, `getCalleeLocator` failed to resolve the `Apply` component to its corresponding member. This caused `getFunctionArgApplyInfo` to fail when attempting to retrieve the argument list and overload choice, leading to a crash during diagnostic generation.

This change updates `getCalleeLocator` to specifically handle `KeyPathComponent::Apply` and `UnresolvedApply`. It now correctly resolves the callee to the *preceding* component (index - 1) in the KeyPath, ensuring the correct overload and argument list are retrieved without collisions.

Resolves: https://github.com/swiftlang/swift/issues/85942
2026-01-07 19:56:15 +05:30
AnirudhMathur12 874b9b9d28 [Constraints] Fix crash in getFunctionArgApplyInfo for KeyPath Apply components
Fix `getCalleeLocator` to correctly return the previous component
(the callee) for KeyPath Apply components, rather than the Apply
component itself. This allows `getFunctionArgApplyInfo` to properly
retrieve overload information and avoid crashing on invalid KeyPath
expressions.

Update test expectations to match errors from the new parser.
2026-01-03 00:48:48 +05:30
AnirudhMathur12 1077e09e52 Fix crash in missing argument diagnostics for KeyPath applications
The compiler previously crashed when diagnosing missing arguments in KeyPathExpr (e.g., \.split(separator: ",")). This occurred because getFunctionArgApplyInfo failed to handle KeyPathExpr anchors, and CSDiagnostics.cpp blindly unwrapped the result.
This change fixes the crash by:
 - Retrieving KeyPath Overloads: Updating ConstraintSystem::getFunctionArgApplyInfo to scan the locator path for the KeyPathComponent. This allows us to retrieve the correct argument list and overload choice (function type) when available.
 - Adding Safety Check: Updating MissingArgumentsFailure::diagnoseAsError to safely check if FunctionArgApplyInfo was successfully created before accessing it. This ensures graceful failure if the solver cannot determine the overload for the malformed component.
2026-01-02 04:50:50 +05:30
AnirudhMathur12 6b3b540f24 [ConstraintSystem] Fix crash when diagnosing missing args in KeyPath application
This patch fixes a compiler crash (Signal 11) where `getFunctionArgApplyInfo`
blindly cast an expression to `CallExpr` without verification, and
`CSDiagnostics` subsequently dereferenced a null result.

This occurred specifically when using a KeyPath expression (e.g. inside `.map`)
that had argument labels missing. The diagnostic logic triggered on the KeyPath
node, which is not a `CallExpr`, causing an assertion failure in debug builds
and a segfault in release builds.

Resolves: https://github.com/swiftlang/swift/issues/85942
2026-01-02 00:39:34 +05:30
Slava Pestov d795c185b5 Sema: Remove BindingSet::getConstraintSystem()
We shouldn't store a pointer to the ConstraintSystem inside every
BindingSet, but there are some annoying things to untangle before
we can do that.

As a starting point toward that, remove the getConstraintSystem()
getter so that at least we can't reach up to the ConstraintSystem
from the outside.
2025-12-13 21:16:44 -05:00
Slava Pestov 74fa1e7f5e Sema: BindingSet::Literals can just be a vector and not a map 2025-12-13 21:16:43 -05:00
Slava Pestov 6384c27e8e Sema: BindingSet::Defaults can just be a vector and not a map
The only place where we did a lookup, we also iterated over it anyway,
and all remaining usages are simplified by downgrading it to a vector.
2025-12-13 21:16:43 -05:00
Slava Pestov ca12185204 Merge pull request #85967 from slavapestov/dont-copy-that-floppy
Sema: Avoid copying BindingSets
2025-12-12 00:18:47 -05:00
Slava Pestov ba7df4013e Sema: Avoid copying BindingSets
They're stored inside the ConstraintGraphNode now, so returning a
`const BindingSet *` from within determineBestBindings() should
be safe.
2025-12-10 18:48:00 -05:00
Egor Zhdan f995144c1d Merge pull request #85906 from egorzhdan/egorzhdan/reland-cxx-string-cs
Reapply "[ConstraintSystem] C++ Interop: Binding a string literal to `std.string` shouldn't increase the score"
2025-12-10 21:04:15 +00:00
Egor Zhdan 84e7f82363 Reapply "[ConstraintSystem] C++ Interop: Binding a string literal to std.string shouldn't increase the score"
This reverts commit 6852bc9834.

In addition to the original change, this makes sure that C++ `std::string` and Swift `String` are given distinct score, in order to prevent ambiguity which was causing build failures in some projects.

rdar://158439395
2025-12-09 12:55:18 +00:00
Slava Pestov 8da3b62d7b Merge pull request #85293 from slavapestov/too-complex-source-loc
Sema: Fix source location bookkeeping for 'reasonable time' diagnostic
2025-12-07 01:26:04 -05:00
Slava Pestov d8cf185a13 Sema: Fix source location bookkeeping for 'reasonable time' diagnostic
We already had bookkeeping to track which statement in a multi-statement
closure we were looking at, but this was only used for the 'reasonable time'
diagnostic in the case that we hit the expression timer, which was almost
never hit, and is now off by default. The scope, memory, and trial limits
couldn't use this information, so they would always diagnose the entire
target being type checked.

Move it up from ExpressionTimer to ConstraintSystem, so that we get the
right source location there too. Also, factor out some code duplication
in BuilderTransform to ensure we get the same benefit for result builders
applied to function bodies too.
2025-12-06 20:31:08 -05:00
Slava Pestov d57a38be0a Sema: Fix latent bug due to unhandled cases in constraints::simplifyLocator() 2025-12-05 15:05:58 -05:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00