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
}
```
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
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.
`SubscriptDecl` exposes eligibility for `@dynamicMemberLookup`
requirements directly, so the `TypeChecker` interface for these members
can be replaced.
`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`.
C++ types that are non-copyable and non-movable are not imported into Swift.
Variables of such types are marked as invalid in Swift by ClangImporter, however, compilation still proceeds without emitting any errors, unless the user attempts to use the problematic type from Swift. This differs from pure-Swift where having invalid decls are not allowed.
This adjusts the typechecker to account for the fact that a declaration coming from Clang might be invalid and not diagnosed at the same time. Instead of crashing in SILGen, let's emit a typechecking error.
rdar://137880350
If the argument was synthesized by the solver, let's fail. This can
happen when a parameter type is optional and (currently) inference
would try both optional and non-optional bindings for the new
argument which cases a mismatch in one of the conversion cases.
Resolves: https://github.com/swiftlang/swift/issues/88456
Resolves: rdar://174723056
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
This erasure requires a function conversion and a heap allocation
so if there is an overload that adopted typed throws it should be
preferred over the one with regular `throws`.
Resolves: rdar://172779708
- 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)
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
These will be used internally by the type checker to represent bindings
that are the joins and meets of types involving type variables. They
will not appear anywhere outside of the bindings code---so you won't
see them in expressions, or matchTypes(), etc.
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.
If common result type optimization binds the type variable
representing the member chain result before we attempt an
overload from the corresponding disjunction, the
UnresolvedMemberChainBase constraint would fail.
The specific situation this would occur was when the extension
declared overloaded members with a concrete return type instead
of Self, and then this method was part of a chain:
extension P where Self == S {
func f(_: Int) -> S { ... }
func f(_: String) -> S { ... }
func g()
}
... foo(.f(3).g()) ...
The TestNoDoubleVoidClosureResultInference were actually not
exercising the code path they were supposed to because we
didn't check for that locator kind in getImpliedResultConversionKind().
Code with Protocol Composition parameters had not been taking into account
that a parameter would conform to all protocols in the composition on
member resolution and could fail to find a member for one protocol
on static lookups, resulting in a diagnostic that was incorrect even on
correct programs.
For example
```protocol P {
static var boo
}
protocol Q {
}
func t<T: P&Q>(x: T) { }
t(.boo)```
Diagnostic of Q does not have member boo
(Yes, other diagnostics are required in this code)
This occured because P and Q were considered one path at a time.
After the change, the P&Q path is considered together instead.
This replaces #87114, aligning the `BorrowingSequence` protocols and
related types to the Swift Evolution proposal, and without included
reparenting of `Sequence`.
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
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.
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
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.
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.