Commit Graph

2562 Commits

Author SHA1 Message Date
Allan Shortlidge 10e9c44de8 CSApply: Honor a pattern binding's explicit type annotation in its interface.
When applying a constraint system solution to a pattern binding initialization,
the type stamped onto the pattern was derived from the initializer expression
rather than from the type the solver assigned to the pattern itself. When an
explicit annotation and the initializer share a canonical type but differ in
sugar, coercing the initializer to the annotation type is a no-op that leaves
the initializer's own sugar in place, so the pattern and the VarDecl printed
into the .swiftinterface ended up with the initializer's sugar instead of the
written annotation.

This is mostly cosmetic, but it turns into a correctness problem when the
initializer's sugar names a typealias that isn't visible at the interface's
access level. For example, a public stored property annotated with a public
alias but initialized from an expression of an internal alias would print the
internal alias in the interface, producing a declaration that references a type
the interface can't see and breaking interface verification.

For typed patterns, use the pattern's solved type instead of the type derived
from the init. Assuming type checking is successful, the two types must share a
canonical type so this change only affects the printed sugar.

A better fix would be to unconditionally use the pattern's solved type,
regardless of whether the pattern is typed or not. Doing so causes some
regressions elsewhere, though, because the constraint solver does not currently
preserve typealias sugar on constructors everywhere it ought to. Using the
solved type for other kinds of patterns can therefore end up causing desugared
types to show up in more places where they aren't desirable.

Resolves rdar://178091149.
2026-06-04 10:50:07 -07:00
Pavel Yaskevich 9511b90c17 Merge pull request #89444 from xedin/rdar-173455896
[AST] ParameterListInfo: Construct info for fully substituted declaration references
2026-05-29 07:20:08 -07:00
Pavel Yaskevich 85eed01fb9 [CSApply] Set correct callee for calls routed through key path dynamic member subscript
Instead of pointing at the subscript itself such calls should
have an empty callee because call happens on a value returned
from subscript invocation and it's not necesserily related to
the member looked up dynamically.
2026-05-28 09:31:12 -07:00
Slava Pestov a8d28b8c93 Sema: Better output when invalid types leak into solution 2026-05-27 23:07:51 -04:00
Pavel Yaskevich 02c4ef5e10 [AST] ParameterListInfo: Construct info for fully substituted declaration references
This is important during CSApply because fully resolved function
type of a variadic generic declaration reference doesn't necessary
match arity of the parameter list and requires special handling.
For example, parameters inferred to be empty packs are going to be
removed from the type and multi-parameter substitutions are going
to be flattened.

Resolves: https://github.com/swiftlang/swift/issues/88146
Resolves: rdar://173455896
2026-05-26 13:53:17 -07: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
Allan Shortlidge 75ee444a94 Sema: Add source loc to implicit CGFloat/Double conversion.
This ensures MemberImportVisibility diagnostics about missing imports of
CoreFoundation for `CGFloat.init(_:)` get a source location.

Resolves rdar://177380270.
2026-05-19 14:50:32 -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 97d6221295 Sema: Remove redundant call to setType() 2026-05-08 15:46:19 -04:00
Slava Pestov 2caba51bc0 Sema: Remove unused variable from buildArgumentListForDynamicMemberLookupSubscript() 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
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
Ben Cohen c9c9000b20 MiscDiagnostics: handle implicit callee in fixItEncloseTrailingClosure (#88860)
When a CallExpr's callee is implicit (e.g. `callAsFunction`),
`fn->getEndLoc()` collapses to the call site's location, so the
bare-trailing-closure path could compute `lastLoc` at or past the
closure's start. The resulting `fixItReplaceChars(lastLoc,
closureRange.Start, ...)` produced a degenerate SourceRange that crashed
the Swift-syntax-aware diagnostic renderer when constructing
`Range<AbsolutePosition>`. Detect that case and fall back to a plain
insertion at the closure's start.

fixes rdar://170779809
2026-05-07 05:51:55 -07:00
Konrad Malawski 3beefe5bd8 Rename CallerIsolationInheriting -> NonisolatedNonsending 2026-04-28 09:21: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 aa38700de6 [CS] Assert correct number of args in coerceCallArguments
We were previously getting away with passing an argument list with
more arguments than were being bound by parameters.
2026-03-21 13:45:27 +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
Hamish Knight c065d18d6f [CS] Remove a bit of unnecessary logic from finishApply
We already have the callee locator and callee computed.
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
Slava Pestov c197635ad9 AST: Factor out ASTContext::get{CGFloat,Double}InitDecl() from CSApply.cpp
Also, since the mock SDK's implementation of CGFloat is wrong,
update some existing tests to use the real SDK instead. This
exposed a few instances where the behavior was not as intended;
I added FIXME comments explaining what's going on.
2026-03-20 15:56:32 -04:00
Pavel Yaskevich 25dbbd3db2 Merge pull request #87778 from xedin/rdar-171146729
[CSApply] Don't use special isolation erasure for global-actor to `@i…
2026-03-11 13:10:25 -07:00
Pavel Yaskevich 5097a86b88 [CSApply] Don't use special isolation erasure for global-actor to @isolated(any) conversions
Regular `FunctionConversionExpr` handles that correctly and
`ActorIsolationErasureExpr` should only be used for cases when
the resulting type is `nonisolated`.

Resolves: rdar://171146729
2026-03-10 20:21:17 -07:00
Slava Pestov 601e253fd8 Sema: Inline findResolvedMemberRef() into its only caller 2026-03-10 14:47:30 -04: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
Aidan Hall 978baeaf14 Merge pull request #87085 from aidan-hall/closure-lifetimes
Basic support for closures with lifetime dependencies
2026-02-10 22:03:08 +00:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Aidan Hall d000346824 LifetimeDependence: Inference for closure expressions
This allows us to coerce closure expressions to function types with lifetime
dependencies.

Since captures are added to the parameter list when lowering closures to SIL
functions, we also need to update the result index when lowering their lifetime
dependencies.
2026-02-10 11:23:58 +00:00
Kavon Farvardin ae77ba81e3 Merge pull request #87013 from kavon/revert-84789
Back out #84789 after additional testing
2026-02-06 02:58:00 -08:00
Kavon Farvardin d5f9a1eeeb Revert "Merge pull request #84789 from nickolas-pohilets/mpokhylets/fix-82618"
This reverts commit b633bd37ac, reversing
changes made to b27bb64b03.
2026-02-05 11:34:59 -08:00
Pavel Yaskevich 613f4eafa2 [Concurrency] Fix thunk emission for function types with isolated parameters
This is important for things like instance methods of actors in
particular because otherwise it won't be possible to compute a
correct isolation for the thunk.

This fix enables fully unapplied references to actor-isolated
instance methods and other functions with isolated parameters.

Resolves: rdar://148395744
2026-01-30 14:55:42 -08:00
Hamish Knight 1bff51d40d [AST] NFC: Introduce isAtLeastFutureMajorLanguageMode
And use it for clients checking for the next future major language mode.
2026-01-27 23:30:43 +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
Mykola Pokhylets 551a2cec6c Using ClosureExpr instead of ConversionPair in CollectionUpcastConversionExpr 2026-01-20 14:49:56 +01:00
Slava Pestov 6c1978ef9e Sema: Fix edge case where we form curry thunk for immediately-called constructor 2025-12-19 10:49:12 -05: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 019520b25f Merge pull request #85740 from hamishknight/out-of-place
Rework emission of EditorPlaceholderExprs
2025-12-02 23:25:40 +00:00
Hamish Knight 3861d58175 [CS] Remove CTP_CannotFail
This is now unused.
2025-11-30 11:12:39 +00:00
Hamish Knight ae82b29e35 Rework emission of EditorPlaceholderExprs
Rather than synthesizing a semantic expression to emit, add a compiler
intrinsic to the stdlib that is simple enough to just SILGen the
emission.
2025-11-30 11:12:39 +00:00
Hamish Knight ae2a18b3c8 [CS] Remove a use of typeCheckExpression in CSApply
We can just use `coerceToType` here.
2025-11-30 11:03:03 +00:00
Hamish Knight 9a31ef029c [CS] NFC: Remove CTP_ComposedPropertyWrapper
This has been unused since we added a custom `AllowWrappedValueMismatch`
fix.
2025-11-16 18:31:55 +00:00
Hamish Knight 6abfea9312 [CS] NFC: Remove CTP_CalleeResult
This has been unused since the removal of CSDiag.
2025-11-16 18:29:37 +00:00
Slava Pestov 64f2d1acce AST: Rename mapConformanceOutOfContext() => mapConformanceOutOfEnvironment(), mapReplacementTypesOutOfContext() => subs.mapReplacementTypesOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Pavel Yaskevich 8e9048aeba [CSApply] NFC: Unify transform for expressions with a single sub-expression
Copy, Borrow, {Any, Optional}Try, VarargExpansion expressions
have to perform the same transformation - resolve the type and
use it to coerce their sub-expression. This change introduces a
single method to do just that instead of copying the same code
around.
2025-10-30 08:48:19 -07:00
Pavel Yaskevich 66ad2a97b9 [CSApply] NFC: Simplify solution application to try expressions
Since `try!` now forces l-value -> r-value conversion during
CSGen, let's simplify solution application to `try` expressions
by coercing sub-expression to a type of a `try` itself which
would introduce all necessary loads.
2025-10-30 00:02:44 -07:00
Hamish Knight 6a7bf6fef5 Merge pull request #85188 from hamishknight/tuple-trouble
[CS] Upgrade a couple of tuple warnings to error for future lang mode
2025-10-29 23:34:22 +00:00