Commit Graph

2840 Commits

Author SHA1 Message Date
Becca Royal-Gordon
ffaa35810c Handle lookup into Builtin with module selector
Lookups like Builtin::Int64 were failing because BuiltinUnit rejected all unqualified lookups. Make it allow unqualified lookups with a module selector.
2025-10-24 16:23:48 -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
Becca Royal-Gordon
64d8b70942 Make DeclNameRef able to store a module selector
In this commit, this change affects certain diagnostics but doesn’t actually alter name lookup behavior yet.
2025-10-24 16:23:33 -07:00
Slava Pestov
1b6ac2c1d8 Sema: Clean up leading dot fix logic in simplifyConformsToConstraint()
Tests still pass without this code, including the tests I just
added in the previous commit.
2025-10-20 21:50:41 -04:00
Hamish Knight
1f5a0b4c88 [CS] Use simplifyType in isDependentMemberTypeWithBaseThatContainsUnresolvedPackExpansions
The pack expansion type variable may be a nested in the fixed type of
another type variable, and as such we unfortunately need to fully
`simplifyType` here.

rdar://162545380
2025-10-14 15:13:05 +01:00
Tim Kientzle
41f680cb93 Merge pull request #84826 from tbkka/tbkka-revert-revert-floatingpointdescription
Re-land new Floating-poing `debugDescription`
2025-10-12 20:19:12 -07:00
Tim Kientzle
4c0b58096e Make _InlineArray subject to the same optimizations as InlineArray 2025-10-10 14:06:14 -07:00
Slava Pestov
a8d896ab8f Sema: Don't reuse PreparedOverload from normal type checking in salvage()
We want to re-prepare our overloads, since now they will contain fixes.
2025-10-10 15:44:12 -04:00
Slava Pestov
036db6fb08 Sema: Only use PreparedOverload::Change::AddedBindConstraint if the locator didn't change
For a Bind constraint generated by a same-type requirement, we must
preserve the locator so we need to record it like any other kind of
constraint.

This fixes a diagnostic regression with -solver-enable-prepared-overloads.
2025-10-10 15:33:31 -04:00
Pavel Yaskevich
1d8536eed2 Merge pull request #84729 from xedin/rdar-161207705
[CSSimplify] Avoid simplifying dependent members until pack expansion…
2025-10-08 16:19:00 -07:00
Pavel Yaskevich
b0a2bd6578 Merge pull request #84715 from xedin/rdar-159401910
[Diagnostics] Fix a few issues with existential type mismatches
2025-10-07 09:39:36 -07:00
Pavel Yaskevich
c278717887 [CSSimplify] Avoid simplifying dependent members until pack expansions in the based are bound
Dependent members cannot be simplified if base type contains unresolved
pack expansion type variables because they don't give enough information
to substitution logic to form a correct type. For example:

```
protocol P { associatedtype V }
struct S<each T> : P { typealias V = (repeat (each T)?) }
```

If pack expansion is represented as `$T1` and its pattern is `$T2`, a
reference to `V` would get a type `S<Pack{$T}>.V` and simplified version
would be `Optional<Pack{$T1}>` instead of `Pack{repeat Optional<$T2>}`
because `$T1` is treated as a substitution for `each T` until bound.

Resolves: rdar://161207705
2025-10-07 00:20:51 -07:00
Pavel Yaskevich
15c56627b8 [CSSimplify] Remove all InstanceType at the end of a locator to diagnose mismatched existential conversion 2025-10-06 14:01:28 -07:00
Hamish Knight
d65f28984a [CS] Improve diagnostics for non-metatype type(of:) contextual type
Emit a custom diagnostic for this case, and handle holes.
2025-10-06 21:45:48 +01:00
Pavel Yaskevich
36fc1e6c43 [CSSimplify] Diagnose an attempt to match non-existential type to an existential one
Resolves: rdar://159401910
2025-10-06 09:51:34 -07:00
Pavel Yaskevich
af909078e5 [CSSimplify] Look through InstanceType while attempting to diagnose conformance failures
Matching existential types could introduce `InstanceType` element
at the end of the locator path, it's okay to look through them to
diagnose the underlying issue.
2025-10-05 23:57:09 -07:00
Hamish Knight
954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
Hamish Knight
f9a4386922 [CS] Remove some uses of hasUnresolvedType in the solver
These should be unreachable now.
2025-10-03 09:50:42 +01:00
Slava Pestov
2c6846f7cd Merge pull request #84501 from slavapestov/fix-rdar160389221
Sema: Workaround for broken existential opening behavior
2025-09-26 18:36:49 -04:00
Allan Shortlidge
2467b931a7 ConstraintSystem: Move key path type utilities to AST. 2025-09-25 07:13:17 -07:00
Slava Pestov
40948d7abd Sema: Workaround for broken existential opening behavior
This is a narrow workaround for a regression from
9e3d0e0a8c.

There is no reason to skip this logic for protocol extension
members, except that doing so happens to break existential
opening in an expression that involves a call to Array.init
elsewhere.

However there is an underlying issue here with existential opening,
which doesn't seem to work right in the presence of overloading.

The test case demonstrates the fixed problem, together with an
existing bug that points to the underlying problem.

Fixes rdar://160389221.
2025-09-24 18:01:24 -04:00
Hamish Knight
3141b5a8cd [AST] NFC: Introduce PrintOptions::forDebugging 2025-09-21 23:19:06 +01:00
Hamish Knight
801cd646ad Merge pull request #84390 from hamishknight/out-of-place
[Sema] Reject placeholders in type resolution for param and result types
2025-09-19 23:19:48 +01:00
Hamish Knight
0b3747d7c4 Revert "[CS] Record fix when encountering decl reference with placeholder type"
This reverts commit 8102e39f39.
2025-09-19 14:22:39 +01:00
Slava Pestov
2deb5ff0a5 Sema: Add -solver-{enable,disable}-prepared-overloads frontend flags 2025-09-18 15:05:43 -04:00
Slava Pestov
a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Slava Pestov
c344d6b0eb Sema: Rename getTypeOf{Member,}ReferenceImpl() to Pre() and factor out Post() versions 2025-09-18 11:31:59 -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
8102e39f39 [CS] Record fix when encountering decl reference with placeholder type
We allow placeholder types in interface types in certain cases to allow
better recovery since we can suggest the inferred type as a replacement.
When referencing those decls though we need to make sure we record a fix
since we cannot form a valid solution with them.
2025-09-17 20:51:06 +01:00
Hamish Knight
cdf0bfbaf7 [CS] Remove a couple uses of recordAnyTypeVarAsPotentialHole
It's not actually clear these are necessary anymore, and in one case
it actually makes a diagnostic worse.
2025-09-17 16:11:53 +01:00
Pavel Yaskevich
ac27f53c04 [CSSimplify] Fix key path to function conversion to check key path requirements
`KeyPath` types now have conformance requirements placed on their
`Root` and `Value` types which need to be checked even when there
is a key path to function conversion involved, otherwise the solver
would be accepting invalid code.

Note that without function conversion the requirements come from
a type opened during assignment - https://github.com/swiftlang/swift/pull/80081/files.

Resolves: https://github.com/swiftlang/swift/issues/84150
2025-09-15 00:35:19 -07:00
Hamish Knight
71d825dcb8 [CS] NFC: Remove CTP_ForEachStmt 2025-09-05 22:20:28 +01:00
Hamish Knight
1b0eed22be [CS] Better propagate holes from contextual types
Eagerly bind invalid type references to holes and propagate contextual
type holes in `repairFailures`. This avoids some unnecessary diagnostics
in cases where we have an invalid contextual type.
2025-08-29 15:04:20 +01:00
Slava Pestov
9e3d0e0a8c Sema: Move weird ConstructorDecl hack from getEffectiveOverloadType() to simplifyAppliedOverloadsImpl() 2025-08-27 15:34:26 -04:00
Pavel Yaskevich
29b04f4a63 [CSSimplify] SE-0324: Use correct conversion when converting array types
If the argument type is an array and it's passed to an imported declaration
that accepts a raw pointer, the solver should use an "array-to-c-pointer"
conversion instead of the one for pointers.

Resolves: rdar://158629300
2025-08-21 15:38:17 -07:00
Hamish Knight
4423399fce [CS] Use apply component locator for verifyThatArgumentIsHashable
For a method key path use the locator for the apply itself rather
than the member, ensuring we handle invalid cases where the apply is
the first component, and providing more accurate location info.
2025-08-15 21:30:22 +01:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
Pavel Yaskevich
387b4ff2d3 [CSSimplify] Skip member access on existential checks if base is existential only due to marker protocols
If the base type is composed with marker protocol(s) i.e.
`<<Type>> & Sendable`, let's skip this check because such
compositions are always opened and simplified down to a
superclass bound post-Sema.

Resolves: rdar://148782046
2025-08-04 17:00:48 -07:00
Hamish Knight
fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Pavel Yaskevich
94e28b63d7 [Concurrency] InferSendableFromCaptures: Rework check to delay lookup
The current implementation of the check accounts only for the overload
choices present in the initial lookup but for some situations, like
bridged or optional base types, `performMemberLookup` uses a secondary
lookup as well, results of which are ignored.

Let's fold the check into `addChoice` instead and set the the flag there
to make sure that all of the choices are considered.

Resolves: rdar://143586718
2025-07-21 10:33:46 -07:00
Slava Pestov
b39d3aee57 Sema: Special-case recording of Bind constraint in PreparedOverload 2025-07-11 19:57:29 -04:00
Slava Pestov
6e212de774 Sema: Lazily build prepared overload when simplifying BindOverload constraint 2025-07-11 19:57:29 -04:00
Slava Pestov
9a8f3baa06 Sema: Add room for a PreparedOverload to BindOverload constraint 2025-07-10 19:53:19 -04:00
Slava Pestov
f7a552385c Sema: PreparedOverload => PreparedOverloadBuilder 2025-07-10 19:53:18 -04:00
Slava Pestov
0ab6d53fff Sema: Implement matchTypes() for BuiltinFixedArrayType 2025-07-09 22:16:13 -04:00
Slava Pestov
751edee921 Sema: Rework PreparedOverload to store a list of changes 2025-07-09 15:00:10 -04:00
Slava Pestov
2a0b11a22e Sema: Collect property wrappers in PreparedOverload 2025-07-09 15:00:03 -04:00
Slava Pestov
426c7a3fdf Sema: Collect constraints in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
543793564e Sema: Record opened type variables in PreparedOverload 2025-07-09 15:00:02 -04:00