Commit Graph

2914 Commits

Author SHA1 Message Date
Elsa Keirouz a6c591bf0a use BorrowingSequenceProtocol when appropriate 2026-03-05 17:21:14 +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
Slava Pestov ccc59af184 Sema: Factor out getImpliedResultConversionKind() from matchTypes() 2026-02-24 21:34:38 -05:00
Slava Pestov d7ba0f1d51 Sema: Score unavailable Sendable conformances with SK_MissingSynthesizableConformance
Instead of SK_Unavailable.

This is so that test/Constraints/rdar139812024.swift will continue to
pass with an upcoming change. The problem was that in this test,
an unsound optimization meant that we would find a worse solution,
by not considering the better solution, according to our scoring
rules. The worse solution involved an unavailable conformance to
Sendable, while the better one used a missing synthesized one.

Note that this is only an issue in Swift 5 mode, where unavailable
Sendable conformance is a warning. Both are an error in Swift 6 mode,
so it doesn't matter which solution we pick there anyway.
2026-02-24 21:34:35 -05:00
Artem Chikin 2fb1b73644 Merge pull request #87006 from artemcm/LiteralExpressionIntegerGenerics
[Literal Expressions] Add support for literal expressions in integer generic parameter values
2026-02-24 19:09:35 +00: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
Aviva 23792f935c Merge pull request #87361 from a-viv-a/do-not-automatically-tuple-pack-arg
Avoid automatically making pack argument into tuple.
2026-02-23 16:54:04 -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 f0efc2350b Sema: Add temporary flags to turn generation of transitive conformance constraints on and off 2026-02-20 21:59:24 -05:00
Aviva Ruben 6d045e3b56 Avoid automatically making pack argument into tuple
Fixes #69245 by ensuring CSSimplify does not wrap PackExpansionType in a
tuple when it is the argument for a tuple parameter. This was causing a
crash. Also changes matchTypes to wrap such a pack expansion in a tuple
after diagnosing so we can infer more types. Adds a tailored diagnostic,
note, and fix-it to AllowInvalidPackExpansion for tuple containing pack
expansion parameters, that wraps with parens and names tuple parameter
instead of non-pack parameter.
2026-02-20 14:54:41 -08: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
Hamish Knight b864af5667 [CS] Delay Sendable conformance lookup for Sendable-dependent function
If we have a Sendable-dependent function type we don't yet know if it
conforms to Sendable, wait until the dependence is resolved.
2026-02-19 21:45:11 +00:00
Hamish Knight da89f0e530 [CS] Propagate Sendable-dependence into closures
Missed this in my original Sendable-dependence patch, the sendability
of a closure can be dependent if its contextual type is. I'm not
sure this case ever actually matters in practice, but it seems like we
ought to be consistent with the existing logic and not have the
behavior be dependent on whether the dependence is evaluated before or
after the closure is resolved.
2026-02-16 14:37:58 +00:00
Hamish Knight 021ece1c3e [CS] Replace errors with holes in requirements
Substitution failure may produce an ErrorType, replace with a hole to
avoid letting ErrorTypes into the constraint system.
2026-02-12 11:34:47 +00:00
Hamish Knight 4912cd52a7 [CS] Refuse to match error types
We ought to consider making this an assert, but for now let's bail
out of solving.
2026-02-12 11:34:47 +00:00
elsa af7069a10e Merge pull request #86811 from elsakeirouz/for-in-borrowing-support-no-stdlib-changes
ForEach support for Borrowing sequence

For testing purposes, this commit includes _BorrowingSequence and _BorrowingIterator protocols, with conformance for Span and InlineArray.
2026-02-12 10:08:24 +00:00
Elsa Keirouz 3b0e6d9e41 update BorrowingSequence identifier and protocol definitions to use temporary naming
This commit should be reverted once the protocol lands.
2026-02-11 16:02:26 +00:00
Elsa Keirouz 2a0bc57763 [AST] desugar ForEachStmt for BorrowingSequence protocol 2026-02-11 16:02:25 +00: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 7cd06a5088 Sema: Split off TypeVariableType.h/.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov 2e60d29973 Sema: Add -solver-{disable,enable}-performance-hacks flags 2026-02-03 16:34:10 -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
Hamish Knight f7ebf08a19 Merge pull request #86802 from hamishknight/add-comments
[Sema] NFC: Add a couple of comments
2026-01-27 16:51:37 +00: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 030cd7a472 [Sema] NFC: Add a couple of comments 2026-01-26 21:46:00 +00:00
Joe Groff 0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08: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
elsa 5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Slava Pestov f3cfd65f3b Sema: Remove some dead code related to favoring 2026-01-23 20:02:21 -05:00
Joe Groff bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Hamish Knight d3270fdf1e [CS] Remove ValueWitness constraint
The specialized type-checking for `for` loops was the only client of
this, it's now unused.
2026-01-23 15:17:30 +00:00
Hamish Knight de91fd77ec [CS] Remove some now-unnecessary for loop logic
We no longer need to track the `ForEachStmtInfo` in the
`SyntacticElementTarget`, and we can remove the special diagnostic
logic for `next` and `makeIterator` since those are type-checked
separately now.
2026-01-23 15:17:29 +00:00
Elsa Keirouz 075fa2a8f1 [CS] introduce ForEachElement constraint 2026-01-23 15:17:28 +00:00
Elsa Keirouz 27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Pavel Yaskevich a33ec97216 [ConstraintSystem] Remove old performance hacks from the solver
The hacks have been disabled for a while now, so it's time to
completely remove them in favor of CSOptimizer.
2026-01-21 11:53:19 -08:00
Pavel Yaskevich b1ccdc30c4 [CSSimplify] Match root/value of a key path even when superclass check fails
This helps to propagate types bi-directionally and avoid extraneous
failures related to generic parameter inference when the real issue
is mutability or type erasure.
2025-12-18 16:39:16 -08:00
Kathy Gray 472937e57d Merge pull request #85591 from kathygray-pl/kathy/diagnosticProperty
[Diagnostics] Increase possibility for missed property diagnostic
2025-12-12 16:09:12 +00:00
Chris Williams fe0191c62c [CSSimplify] Parameter pack wrapping logic incorrectly considers tuple LValueTypes to not be tuples (#85962)
In #65125 (and beyond) `matchTypes`, has logic to attempt to wrap an
incoming parameter in a tuple under certain conditions that might help
with type expansion.

In the case the incoming type was backed by a `var`, it would be wrapped
by an `LValueType` then be subsequently mis-diagnosed as not-a-tuple.

More details in #85924 , this this is also the cause of (and fix for)
#85837 as well...
2025-12-11 22:29:42 -08:00
Kathy Gray fde49b8847 Diagnostics : Increase possibility for missed property diagnostic
Impact for an unknown property access was frequently higher than other options
on ambiguous selections, by 3 to 5 points, causing fix selections that were
farther away and frequently noted to be in accurate. This commit lowers the
impact to be in a similar range to other fixes and this causes property accesses
to be selected more proprotionaly.

In the existing test suite, this changed the diagnostic only in the case of
protocol composition, which was also discovered to be a flawed binding lookup.

Tests added for the property lookup, tests updated for protocol composition
(Including correcting a likely error in a test specification)
2025-12-11 16:08:22 +00:00
Pavel Yaskevich 1f887202e1 [Diagnostics] Don't attempt to synthesize arguments when destructuring a single tuple argument results in an overrun
If arguments are represented by a single tuple it's possible
that the issue is not about missing parameters but instead
about tuple destructuring. Fix `fixMissingArguments` to check for
overruns after destructuring and stop if that produces more
arguments then parameters because such situations are better
diagnosed as a general conversion failure rather than a missing
argument(s) problem.

Resolves: rdar://159408715
2025-12-09 16:52:41 -08:00
Anthony Latsis 153dd02cd8 Merge pull request #85833 from swiftlang/jepa-main
[NFC] "SwiftVersion" → "LanguageMode" in `DiagnosticEngine::warnUntilSwiftVersion`, etc.
2025-12-05 09:34:30 +00:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Hamish Knight 3861d58175 [CS] Remove CTP_CannotFail
This is now unused.
2025-11-30 11:12:39 +00:00
Hamish Knight 4992c7ab8b Merge pull request #85538 from hamishknight/binding-fixes
[Sema] A couple of binding-related crasher fixes
2025-11-18 19:48:25 +00:00