Commit Graph

1583 Commits

Author SHA1 Message Date
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
Slava Pestov ca72d2d276 Sema: Remove unused TypeOperation cases 2026-03-17 13:41:19 -04:00
Elsa Keirouz a6c591bf0a use BorrowingSequenceProtocol when appropriate 2026-03-05 17:21:14 +00:00
Michael Gottesman 0252de2b13 [sema] Honor explicit global actor isolation for async closures in constraint solver
Previously, we were emitting an unknown pattern error in code like:

```
@MainActor
class MainActorIsolatedKlass {
  init() {
    Task.detached { @MainActor in
      _ = self
      for try await x in E.seq {
      }
    }
  }
}

enum E {
  static var seq: some AsyncSequence<Float, Error> {
    AsyncThrowingStream(Float.self) { $0.finish() }
  }
}
```

The issue was that the closure was considered non-Sendable despite being
@MainActor due to the `try await` in it. Investigation revealed an
inconsistency between the constraint solver and getClosureIsolation:

1. In the constraint solver, we were only honoring explicit global actor
   isolation for non-async functions, which caused us to not infer that
   the closure should have been Sendable despite the try await.

2. Later getClosureIsolation did the correct thing and we labeled the
   closure as having global actor isolation, but that did not impact the
   actual type of the closure being Sendable at the SIL level.

The result was a non-Sendable main actor isolated closure.

This commit removes the restriction that prevented honoring explicit
global actor isolation for async closures, making the constraint solver
consistent with getClosureIsolation.

rdar://169803154
2026-03-04 09:34:18 -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
Pavel Yaskevich 56a181c2e5 [CSGen] Remove contextual throws propagation into a closure
This now happens in `resolveClosure` for all contextual types.
2026-02-20 09:14:56 -08:00
Hamish Knight 41524f9591 Merge pull request #87253 from hamishknight/completion 2026-02-19 09:02:58 +00:00
Becca Royal-Gordon 31f99c2f55 Ignore generic context when module selector used
Normally, an unbound reference to a generic type within its own context is automatically bound to the identity generic arguments:

```
struct G<T> {
    typealias TA = G    // as if you wrote G<T>
}
```

Module selectors normally disable this kind of contextual behavior; make sure that this is not an exception.

To pipe the information needed to do this through the constraint solver, we extend FunctionRefInfo to remember whether a module selector was used.
2026-02-17 18:21:37 -08:00
Hamish Knight fef50940a4 [Sema] Requestify TypeChecker::checkObjCKeyPathExpr 2026-02-16 11:18:49 +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 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 78e9329184 Sema: Move OpenUnboundGenericType to CSGen.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
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
elsa 5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +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 f7c21941b8 [AST] ForEachStmt: rename sequence getter/setter 2026-01-23 15:17:29 +00:00
Elsa Keirouz d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +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
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Hamish Knight 1923037502 [CS] Invalidate unresolved variables in ExprPatterns early
Make sure we invalidate when we initially visit the ExprPattern to
ensure that we don't run into issues when generating constraints for
a `where` clause before the constraints for the ExprPattern. We ought
to change the constraint generation there to use a conjunction to
ensure that the pattern is solved before the `where` clause, but I
want to keep this as a quick low risk fix that we can cherry-pick. I'll
switch it to a conjunction in a follow-up.
2025-11-17 13:07:36 +00:00
Hamish Knight 2c0ac69433 [CS] Add conversion for ErrorExpr's original expr
Make sure we don't produce unnecessary diagnostics while still allowing
things like cursor info to work. No test change since it's covered by
the next commit.
2025-11-17 13:07:36 +00:00
Hamish Knight 61a5ae8e01 [CS] Eagerly bind hole in recordInvalidNode
We know this is where the issue is so we can immediately bind to a hole,
ensuring we don't produce unnecessary downstream diagnostics from
things we can't infer.
2025-11-16 11:47:21 +00:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov 2ba29d3806 Merge pull request #85183 from slavapestov/fix-issue-85034
Sema: Don't coerce subexpression of 'try' to rvalue
2025-10-29 07:20:27 -04:00
Slava Pestov 8fd7a1db86 Sema: Fix CSGen for ForceTryExpr 2025-10-28 19:56:32 -04:00
Becca Royal-Gordon 393965090e Merge pull request #34556 from beccadax/mod-squad-2
[SE-0491] Implement lookup and diagnostics for module selectors (MyMod::someName)
2025-10-28 16:00:26 -07:00
Hamish Knight 62f0926d25 [CS] Invalidate nested unresolved VarDecls when ignoring completion argument
Make sure we set types for any nested VarDecls in UnresolvedPatternExprs
to ensure we don't crash when attempting to solve the body.
2025-10-26 12:33:29 +00:00
Becca Royal-Gordon 42fdd1d30c Improve module selector macro diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon 7bf14de2e6 Handle module selectors with local vars right 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon b35aaef526 Handle module selectors in macro lookups 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon e662993a08 [NFC] Audit some DeclName➡️DeclNameRef conversions
Adds comments explaining why these conversions aren’t lossy.
2025-10-24 16:23:33 -07:00
Hamish Knight 0a1905acba [CS] Only use unsolved applicable fn for @dynamicMemberLookup cases
This works around the fact that existential opening does not currently
work correctly in cases where the argument isn't resolved before the
applicable fn is solved.
2025-10-19 13:14:00 +01:00
Hamish Knight bb877ce3c0 [CS] Remove ConstraintSystemPhase 2025-10-19 13:14:00 +01:00
Hamish Knight f1823786b6 [CS] Re-order subscript constraint generation
Add the application constraint before the member constraint, which
allows us to get rid of the special-cased delaying logic for dynamic
member subscripts. The diagnostic change here is due to the fact that
we no longer have a simplified type for the result in CSGen, which
would also be the case if we had a disjunction for the member.
2025-10-19 13:14:00 +01:00
Hamish Knight 73710e3eef [AST] Introduce Decl::addAttribute
Introduce a convenience entrypoint that also calls `attachToDecl` on
the attribute, and migrate all existing uses of `getAttrs().add` onto
it.
2025-10-16 11:21:54 +01:00
Tim Kientzle 4c0b58096e Make _InlineArray subject to the same optimizations as InlineArray 2025-10-10 14:06:14 -07:00
Hamish Knight 2c0ea134a9 [Sema] Remove some hasError checks for typeCheckPattern
These shouldn't be necessary anymore, we should be able to handle
ErrorType patterns.
2025-09-28 15:13:55 +01:00
Slava Pestov 9dea72579a Sema: Record ASTNode type changes in PreparedOverload
Also, move some methods from ConstraintSystem.h to ConstraintSystem.cpp.
2025-09-18 14:54:16 -04:00
Slava Pestov a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Hamish Knight deab5f7970 Merge pull request #84280 from hamishknight/csapply-cleanup
Reapply: [Sema] Remove some unreachable code from CSApply
2025-09-18 14:25:51 +01:00
Hamish Knight 9f5a754b77 [Sema] Ban placeholders in typed throws
This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
2025-09-17 20:41:20 +01:00
Hamish Knight a7c0460877 [CS] Record IgnoreInvalidASTNode for invalid key path component
And ensure we don't end up with invalid key paths in CSApply.
2025-09-17 16:11:53 +01:00
Hamish Knight be1f82e36b [CS] Avoid emitting duplicate note for generic argument diagnostic
Since we can run CSGen multiple times, we need to guard the emission
of the note on whether the TypeRepr was already marked invalid (i.e
whether we already emitted a diagnostic for it).
2025-09-15 11:48:56 +01:00
Hamish Knight b7519fabe6 [CS] Add IgnoreInvalidASTNode fix for invalid generic argument
Make sure we record a fix here to ensure we don't try to do CSApply
with holes.
2025-09-15 11:48:56 +01:00
Hamish Knight ef7d69631b [CS] Avoid unnecessary type variables when opening ErrorTypes
Produce the holes directly.
2025-08-30 16:05:01 +01:00
Hamish Knight 28772234bc [CS] Allow contextual types with errors
Previously we would skip type-checking the result expression of a
`return` or the initialization expression of a binding if the contextual
type had an error, but that misses out on useful diagnostics and
prevents code completion and cursor info from working. Change the logic
such that we open ErrorTypes as holes and continue to type-check.
2025-08-29 15:04:20 +01:00