Commit Graph

2170 Commits

Author SHA1 Message Date
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
Alex Hoppen
57d504cbcd Merge pull request #60062 from ahoppen/pr/placeholder-for-errors
[CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
2022-07-20 14:15:43 +02:00
Alex Hoppen
f623440f01 [CS] Disfavor solutions that were unable to infer the variable type inside a named pattern
We need this to resolve a test failure in optional.swift.
2022-07-20 09:47:16 +02:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Pavel Yaskevich
b1930a89aa Merge pull request #60080 from xedin/rdar-88513939
[CSSimplify] Allow referencing typealias declarations via leading-dot…
2022-07-19 09:55:12 -07:00
Pavel Yaskevich
a35df66476 Merge pull request #60024 from xedin/rdar-96631324
[CSSimplify] Don't fix invalid r-value use for misplaced `&`
2022-07-19 09:15:00 -07:00
Pavel Yaskevich
12776182f0 [CSSimplify] Allow referencing typealias declarations via leading-dot syntax in generic context
Previously only static methods found on protocols were allowed but
it is reasonable to reference a typealias to perform an implicit call
to `.init` on its underlying type.

Resolves: rdar://88513939
2022-07-15 17:05:09 -07:00
John Holdsworth
d72b9a4d81 Cater for opening var existential followup. 2022-07-15 12:29:41 -07:00
John Holdsworth
6caf82705d Cater for case when existential to open is a "var". 2022-07-15 12:29:41 -07:00
Pavel Yaskevich
ff6112024e [CSSimplify] Don't fix invalid r-value use for misplaced &
When `&` is misplaced it creates r-value -> l-value mismatch
in the code which is just a consequence and shouldn't be diagnosed.

Resolves: rdar://96631324
2022-07-12 13:55:04 -07:00
Doug Gregor
db14ab140f Sink concurrency constraint fix behavior logic into "attempt" functions.
This is a cleaner pattern for the solver, thanks Pavel!
2022-07-08 13:33:14 -07:00
Doug Gregor
7436fb365a Rename CSFix::affectsSolutionScore() to impact(). 2022-07-08 13:03:12 -07:00