Commit Graph

2231 Commits

Author SHA1 Message Date
Holly Borla
032c511754 [ConstraintSystem] Add a PackElementOf constraint to delay mapping opened
element pattern types to pattern archetypes until after type variables are
resolved.
2022-10-24 19:46:44 -07:00
Pavel Yaskevich
927b846a8f Merge pull request #61672 from xedin/rdar-101412179
[CSSimplify] Diagnose contextual mismatch between fully resolved depe…
2022-10-24 19:36:51 -07:00
Holly Borla
5584752b3e [ConstraintSystem] Implement value parameter pack forwarding. 2022-10-22 13:41:48 -07:00
Slava Pestov
c34f8d3a0b Sema: Check AnyObject requirements of variadic generic functions 2022-10-22 01:17:13 -04:00
Slava Pestov
f3fcc44d17 Sema: Handle PackElement locator in repairFailures() 2022-10-21 22:17:38 -04:00
Slava Pestov
cbce4a52ca Sema: Support PackExpansionTypes in matchPackTypes() 2022-10-21 22:17:38 -04:00
Slava Pestov
7d0de80bfc Sema: Check requirements when calling a variadic generic function 2022-10-21 22:17:38 -04:00
Slava Pestov
46d5fa68f9 Sema: Introduce ConstraintKind::SubclassOf 2022-10-21 22:17:38 -04:00
Slava Pestov
c41341d98c Sema: Fix matchCallArguments() to allow empty pack type bindings
Thanks to @hborla for suggesting this fix.
2022-10-21 22:17:08 -04:00
Slava Pestov
68514b10b5 AST: Introduce ElementArchetypeType 2022-10-21 21:55:35 -04:00
Pavel Yaskevich
a796c45e4c [CSSimplify] Diagnose contextual mismatch between fully resolved dependent member types
If a constraint has fully resolved but incorrect (not simplifiable)
dependent member types, let's diagnose that as a contextual mismatch
instead of failing (which sometimes leads to a fallback diagnostic).

Resolves: rdar://101412179
2022-10-21 22:28:31 +01:00
Slava Pestov
4e70f4fb19 Sema: Simplify matching logic for PackExpansionType 2022-10-17 23:23:09 -04:00
Slava Pestov
7e9995b1bc Sema: Use ParamPackMatcher in matchFunctionTypes() 2022-10-16 21:37:25 -04:00
Slava Pestov
9d16b821a8 AST: Move Sema's TuplePackMatcher to AST
I'm also going to use it in TypeMatcher, for the Requirement Machine's
same-type requirement desugaring.
2022-10-16 21:37:25 -04:00
Slava Pestov
bbaee236c2 Sema: Preliminary support for matching tuple types containing pack expansion types 2022-10-16 21:37:24 -04:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Dylan Perry
a29686f349 Issue-60730: Addressing the situation where we were saying that (any … (#61191)
* Issue-60730: Addressing the situation where we were saying that (any P)? does not conform to P, instead we should offer the Force Optional error messaging

* Issue-60730: Removing assigned of AllowArgumentMismatch fix that would get thrown away if we fall into ForceOptional fix

* Issue-60730: Removing file that was accidentally changed

* Issue-60730: Updating to use simplifyConformsToConstraint - and to clean up code per comments

* Issue-60730: Updating to pass protocoDecl instead of type2 to simplifyConformsToConstraint

* Issue-60730: Updating to pass protocoDecl instead of type2 to simplifyConformsToConstraint

* Issue-60730: Updating to not pass 1 to recordFix, where that is the default value

* Issue-60730: Adding in test to validate that the fix works as expected

* Issue-60730: Cleaning up test based on PR Comments

* Issue-60730: Correcting typo in test

* Issue-60730: Adding additional test cases for layers of optionals and for non-conforming argument

* Issue-60730: Updating test to include fixme(diagnostics) for multilpe layers of force unwrap
2022-10-10 08:56:19 -03:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Doug Gregor
761b0aa98c Allow existential opening for parameters of optional type. 2022-09-27 13:08:36 -07:00
Pavel Yaskevich
1a47a95617 [CSSimplify] ValueWitness: open existential base before checking conformance 2022-09-14 15:47:12 -07:00
Pavel Yaskevich
c610e2bd9c [CSSimplify] Member ref decays into value witness for next in for-in
Reference to `$geneator.next` in for-in loop context needs to be
treated as a reference to a witness of `IteratorProtocol#next`
requirement, otherwise it could lead to problems with retroactive
conformances.
2022-09-14 11:35:27 -07:00
Pavel Yaskevich
c798a7fb72 [CSSimplify] Member ref decays into value witness for makeIterator in for-in
Reference to `makeIterator` in for-in loop context needs to be
treated as a reference to a witness of `Sequence#makeIterator`
requirement, otherwise it could lead to problems with retroactive
conformances.
2022-09-14 11:35:27 -07:00
Pavel Yaskevich
e39a81f351 [CSSimplify] Adjust value witness constraint to record witness declaration 2022-09-14 11:35:27 -07:00
Pavel Yaskevich
164fa9c45d Revert "[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint"
This reverts commit ef0523fe29.
2022-09-14 11:35:27 -07:00
Slava Pestov
67d3ede5c7 Sema: Teach the solver to find members of tuples 2022-09-10 00:26:42 -04:00
Slava Pestov
c1b8690401 AST: Introduce special Builtin.TheTupleType singleton 2022-09-10 00:26:42 -04:00
Slava Pestov
79ed990728 AST: Replace TupleTypeRepr's ellipsis with PackExpansionTypeRepr 2022-09-07 12:35:54 -04:00
Pavel Yaskevich
b2233ee4c6 Merge pull request #60883 from xedin/rdar-99352676
[ConstraintSystem] Teach `init` ref validation about implicit conversions
2022-08-31 17:57:42 -07:00
Pavel Yaskevich
4571c26f10 [ConstraintSystem] Teach init ref validation about implicit conversions
Implicit conversion used to erase path for contextual type conversions
but it does so no longer, this means that invalid initializer reference
check needs to know about existence of implicit conversions that are
not reflected in the AST until solution is applied.

Resolves: rdar://99352676
2022-08-31 12:21:16 -07:00
Pavel Yaskevich
e5d26627db [CSSimplify] Replace locatorEndsWith with isLastElement accessor 2022-08-31 12:12:16 -07:00
Pavel Yaskevich
9399451edf [ConstraintSystem] Fix result builder discovery in leading-dot syntax calls
Leading-dot syntax allows implicitly unwrapping result type to form
a base type of the call, `getOpenedResultBuilderTypeFor` needs to
account for that.

Resolves: https://github.com/apple/swift/issues/60586
2022-08-31 11:00:54 -07:00
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Slava Pestov
7a16b0275b AST: Allow one-element tuple types to be constructed
These will never appear in the source language, but can arise
after substitution when the original type is a tuple type with
a pack expansion type.

Two examples:
- original type: (Int, T...), substitution T := {}
- original type: (T...), substitution T := {Int}

We need to model these correctly to maintain invariants.

Callers that previously used to rely on TupleType::get()
returning a ParenType now explicitly check for the one-element
case instead.
2022-08-23 11:12:00 -04:00
Slava Pestov
e8dc19a70b Sema: Stop calling getAllConformances() on protocols 2022-08-23 00:03:37 -04:00
Pavel Yaskevich
4d039686fd [CSSimplify] Failure to bind type variable to invalid dependent member makes it a hole
If the failure is not reflected in constraint system it would let
the solver to form a _valid_ solution as if the constraint between
the type variable and the unresolved dependent member type never
existed.

Resolves: https://github.com/apple/swift/issues/60649
2022-08-19 11:39:40 -07:00
Amritpan Kaur
fd41a39294 [ConstraintSystem] Refactor solver state depth to its own function for easier indent editing in future. 2022-08-10 13:29:02 -07:00
Slava Pestov
11eb11833f Sema: Fix deep equality matching for parameterized protocol types
Fixes rdar://problem/98356057.
2022-08-09 23:45:39 -04:00
Pavel Yaskevich
b39302a585 Merge pull request #60203 from xedin/rdar-96997534
[CSGen] Allow `_` pattern to be a hole
2022-08-08 10:14:18 -07:00
Pavel Yaskevich
5ee5a22cf1 [TypeChecker] NFC: Add a dedicated method to get outermost attached wrapper
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
2022-08-04 17:30:02 -07:00
Pavel Yaskevich
61a850dfc3 [CSFix] Improve missing .rawValue fix in ambiguity conditions 2022-08-03 15:50:33 -07:00
Pavel Yaskevich
ac89df5c12 [CSFix] Generalize a fix for unresolved pattern decl
The fix should support both named (i.e. `test(a)` and "any" patterns
i.e. `test(_)`.
2022-08-03 15:50:33 -07:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Hamish Knight
6e51841d14 [AST] Enforce that composeTuple drops parameter flags
Callers may either assert that the parameter flags
are empty, or ask for them to be dropped.
2022-08-02 13:56:31 +01:00
Hamish Knight
1bf954c61f [CS] Better diagnose inout argument in tuple construction
Previously we relied on `TupleTypeElt::getType`
returning an `InOutType` to fail the tuple type
matching logic. Instead, add logic to reject any
inout arguments up-front with a more specific
diagnostic.

Also, while we're here, strip the `_const`
parameter flag, as it's not something that needs
to be considered for tuple construction.
2022-08-02 13:56:30 +01:00
Hamish Knight
4915513387 [CS] Filter out uncallable vars when simplifying applied overloads
This improves diagnostics as we can now consider
functions that don't line up exactly with the
argument list if no other viable candidates exist.
2022-07-26 12:51:53 +01:00
Hamish Knight
fe7c1f4b9b Refactor callable lookup
Move off `Type` based requests and onto `Decl`
based requests, utilizing name lookup's
`extractDirectlyReferencedNominalTypes` utility.
This allows us to better cache the results, and
avoids the need to guard against type variable
inputs when deciding whether or not to cache.
2022-07-25 22:03:55 +01:00
Hamish Knight
13fe88cc57 [AST] Rename isCallableNominalType -> isCallAsFunctionType
Make it explicit that we're checking for
`callAsFunction` instead of `dynamicallyCall`.
2022-07-25 22:03:55 +01:00