Commit Graph

2855 Commits

Author SHA1 Message Date
Hamish Knight
6dfff1ce9c [CS] Remove getImplicitValueConversionLocator & ImplicitConversion
These are now unused.
2025-11-15 19:26:46 +00:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Hamish Knight
ded97baea1 [CS] Handle packs in increaseScoreForGenericParamPointerConversion
Missed this in my original patch, handle pack parameters the same as
regular generic parameters, ensuring we don't prefer a pack overload
over a generic overload just because there are pointer conversions
involved. Note this doesn't fix the wider issue of rdar://122011759,
I'm planning on looking into that in a follow-up.
2025-11-10 14:26:25 +00:00
Hamish Knight
3b57a7cd91 [CS] Clean up some property wrapper logic
These methods can be simplified a bunch since the returned decl is
always the input decl and we can refactor the lambdas to just return
the auxiliary variable and have the type computation in the caller.
2025-11-04 00:56:01 +00:00
Joe Groff
e002d96ac9 Merge pull request #85169 from jckarter/builtin-generic-base-class
Add a BuiltinGenericType base class.
2025-10-31 12:45:58 -07:00
Slava Pestov
5ba8b1b774 Sema: Remove unnecessary level of indentation in matchTypes() 2025-10-30 13:39:21 -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
Joe Groff
cf5f7c8637 Add a BuiltinGenericType base class.
Builtin.FixedArray was introduced as the first generic builtin type, with
special case handling in all the various recursive visitors. Introduce
a base class, and move the handling to that base class, so it is easier
to introduce other generic builtins in the future.
2025-10-28 12:48:18 -07:00
Becca Royal-Gordon
60cc537f70 Improve module selector constraint solver diagnostics 2025-10-24 16:23:49 -07:00
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
Hamish Knight
f15fae4737 Merge pull request #84822 from hamishknight/just-a-phase
[CS] Remove `ConstraintSystemPhase`
2025-10-24 16:05:08 +01:00
Hamish Knight
8397a7a61d Merge pull request #84907 from hamishknight/fixed-point
[CS] Penalize implicit pointer conversions to generic parameter types
2025-10-24 15:56:07 +01: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
dc2392f597 [CS] Remove delaying logic for callAsFunction with trailing closure
It doesn't seem like this is necessary anymore.
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
77a59383f7 [CS] Penalize implicit pointer conversions to generic parameter types
We ought to consider outright banning these conversions if the
destination is a generic parameter type, but for now let's penalize
them such that we don't end up with ambiguities if you're doing an
implicit pointer conversion through an identity generic function.

rdar://161205293
2025-10-16 14:14:53 +01: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