Commit Graph

1765 Commits

Author SHA1 Message Date
Pavel Yaskevich 0ea0b8e27b [ConstraintSystem] Adjust recording of "fixed" requirements to avoid conflicts
Currently it's possible to have a type conflict between different
requirements deduced as the same type which leads to incorrect
diagnostics. To mitigate that let's adjust how "fixed" requirements
are stored - instead of using resolved type for the left-hand side,
let's use originating generic parameter type.
2020-06-25 13:40:15 -07:00
Pavel Yaskevich c4f4ce1e5d [ConstraintSystem] Record substitutions from opened unbound generic types
Substitutions are already recorded for other situations like
member references, this was just slipped under the radar.
2020-06-24 16:00:12 -07:00
Pavel Yaskevich 92271e9ce5 [ConstraintSystem] Rework handling of object literal expressions
Instead of special casing argument-to-parameter matching for
object literal expressions, let's allow constraint system to
lookup a witness initializer and apply it to the given set
of arguments.

This also simplifies constraint application because
`coerceCallArguments` could be used to form type-checked
argument expression.
2020-06-22 10:15:08 -07:00
Pavel Yaskevich 16862e50a5 Merge pull request #31713 from xedin/no-ranking-with-ambiguous-with-fixes
[ConstraintSystem] Overhaul ambiguity diagnostics
2020-06-16 12:55:14 -07:00
Pavel Yaskevich 73667cdc7e [Diagnostics] Use Id_MatchOperator to check whether given operator is pattern match 2020-06-15 11:57:48 -07:00
Suyash Srijan 15643777df [CS] Update splice logic in simplifyLocator to handle situations where the index expression isn't a tuple or paren expression (#32356) 2020-06-13 03:28:57 +01:00
Pavel Yaskevich f854cc666c [ConstraintSystem] Attach candidate notes either to decl (if it has valid loc) or AST node 2020-06-12 14:59:50 -07:00
Pavel Yaskevich 13b4fcc5e7 [Diagnostics] Diagnose ambiguity related to contextual type specifically 2020-06-12 11:47:04 -07:00
Pavel Yaskevich 7bbf9fe279 [Diagnostics] If aggregate fix consists of identical fixes diagnose it specially
If aggregate fix (based on callee locator) differs only in picked
overload choices, let's diagnose that via `diagnoseForAmbiguity`
associated with a particular fix kind all solutions share, that
would produce a tailored diagnostic instead of the most general one.
2020-06-12 11:47:04 -07:00
Pavel Yaskevich b9aa70bc4f [ConstraintSystem] NFC/Debug: Log solutions before attempting to diagnose ambiguity with fixes 2020-06-12 11:47:04 -07:00
Pavel Yaskevich 9067ed23ca [ConstraintSystem] Specialize diagnostic for ~= to talk about expression pattern use 2020-06-12 11:47:04 -07:00
Pavel Yaskevich cf3f52c94d [ConstraintSystem] NFC: Leave notes on the algorithm used by diagnoseAmbiguityWithFixes 2020-06-12 11:46:41 -07:00
Pavel Yaskevich 7d3f5e3775 [ConstraintSystem] Overhaul ambiguity diagnostics
Refactor `diagnoseAmbiguityWithFixes` as follows:

- Aggregate all of the available fixes based on callee locator;
- For each ambiguous overload match aggregated fixes and diagnose;
- Discard all of the fixes which have been already considered
  as part of overload diagnostics;
- Diagnose remaining (uniqued based on kind + locator) fixes
  iff they appear in all of the solutions.
2020-06-12 11:46:41 -07:00
Pavel Yaskevich a8885189ac [ConstraintSystem] Encapsulate a way to diagnose ambiguity for aggregate fixes 2020-06-12 11:46:41 -07:00
Pavel Yaskevich 6b52016607 [ConstraintSystem] Rank solutions based on overload choices only after fix diagnostics have failed
If there are multiple solutions with fixes, let's not try to rank
them based on overload choices because doing so would filter out
viable candidates.
2020-06-12 11:46:41 -07:00
Anthony Latsis f4f2101e9c [NFC] Sema: Internalize the use of UnboundGenericType in applyUnboundGenericArguments 2020-06-12 18:04:55 +03:00
Anthony Latsis 86b7e989e7 [NFC] CS: Give the type-transforming openUnboundGenericType method a more accurate name 2020-06-11 23:58:01 +03:00
Anthony Latsis cdc38dab31 Merge pull request #32309 from AnthonyLatsis/cs-openunbound-dead-param
[NFC] CS: Inline a parameter in openUnboundGenericType
2020-06-11 13:45:50 +03:00
Robert Widmann fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Anthony Latsis bd23534db6 [NFC] CS: Inline a parameter in openUnboundGenericType 2020-06-11 04:54:44 +03:00
Robert Widmann ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Anthony Latsis 4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Luciano Almeida 3e280b8e83 Merge pull request #32107 from LucianoPAlmeida/nfc-move-to-cpp
[NFC][ConstraintSystem] Move some inlined header methods to implementation file
2020-06-06 16:37:19 -03:00
Doug Gregor a4239370c8 [Constraint solver] Wire up "parents" of closure return statements. 2020-06-05 14:02:46 -07:00
Anthony Latsis 267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Anthony Latsis 9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Luciano Almeida c91211c3ad [ConstraintSystem] Inline static method calls into the closures 2020-05-31 17:07:25 -03:00
Luciano Almeida cc15c0b8dd [ConstraintSystem] Remove unnecessary check for decl and use getDeclOrNNull 2020-05-31 12:28:19 -03:00
Luciano Almeida a331ba0780 [ConstraintSystem] Abstract common logic for various get property wrappers get information 2020-05-30 13:26:30 -03:00
Luciano Almeida 042939e77e [ConstraintSystem] Move some property wrappers implementation form header to cpp file 2020-05-30 12:27:54 -03:00
Pavel Yaskevich 9737ce040c [ConstraintSystem] Add missing handling of Stmt * to getLoc 2020-05-29 17:20:27 -07:00
Holly Borla a97bbf9eee Merge pull request #31949 from hborla/property-wrapper-default-init
[Property Wrappers] Fix handling of properties that are default initialized via property wrapper
2020-05-21 18:01:42 -07:00
Pavel Yaskevich 28fa3ab9e9 Merge pull request #31848 from LucianoPAlmeida/SR-12827-keypath-hole
[SR-12827] [Diagnostics] Improve diagnostics keypath hole involving generic argument
2020-05-21 17:19:02 -07:00
Holly Borla fcc4befb21 [Property Wrappers] For properties that are implicitly default initialized
via property wrapper, mark the init call as implicit.
2020-05-21 14:30:41 -07:00
Luciano Almeida bbd6d53f3b [ConstraintSystem] Move implementation of isRepresentativeFor to cpp instead of inline in the header 2020-05-21 18:16:07 -03:00
Pavel Yaskevich ca3aa67713 Merge pull request #31867 from xedin/pinpoint-arg-attr-mismatches
[ConstraintSystem] Add a new locator element - `argument attribute`
2020-05-19 12:28:50 -07:00
Robert Widmann afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
Pavel Yaskevich 9347a091e1 [ConstraintSystem] Adjust getCalleeLocator and simplifyLocator to handle ArgumentAttribute
- `getCalleeLocator`, if given locator ends at `ArgumentAttribute`
  strip the last element which makes sure that produced locator
  always refers directly to argument-to-parameter conversion.

- `simplifyLocator`, always leave `ArgumentAttribute` in the path
  because it's useful for diagnostics.
2020-05-18 13:10:26 -07:00
Robert Widmann ea516bcbb3 Merge pull request #31760 from CodaFi/patternak
Remove The Parser Hack For If-Let
2020-05-13 18:10:35 -07:00
Robert Widmann 31242bc3da Remove The Parser Hack For If-Let
The parser used to rewrite

if let x: T

into

if let x: T?

This transformation is correct at face value, but relied on being able
to construct TypeReprs with bogus source locations. Instead of having
the parser kick semantic analysis into shape, let's perform this
reinterpretation when we resolve if-let patterns in statement
conditions.
2020-05-13 12:34:24 -07:00
Robert Widmann 2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
Hamish Knight dad8f13f6e [Sema] Eliminate a subscript AnyObject lookup ambiguity
Previously we would always consider an AnyObject
subscript lookup to be ambiguous if there was a
candidate in both a class and protocol, even if
the selectors and types matched. This was due to
the protocol's generic signature preventing the
signatures from being coalesced.

Tweak the logic to strip generic signatures when
comparing for AnyObject lookup, matching what we
do for @objc methods.

Resolves SR-8611.
Resolves rdar://43645564 & rdar://62906344.
2020-05-12 21:23:34 -07:00
Pavel Yaskevich f80726aff0 Merge pull request #31654 from xedin/rdar-62989214
[ConstraintSystem] Look through key path dynamic lookup nodes while s…
2020-05-08 09:40:34 -07:00
Pavel Yaskevich b99ccd38ad [ConstraintSystem] Look through key path dynamic lookup nodes while simplifying locators
Key path dynamic member lookup should be completely transparent
for simplification purposes, it's just a means to get to the current
overload choice.

Resolves: rdar://problem/62989214
2020-05-08 00:43:23 -07:00
Saleem Abdulrasool 09975d1253 sprinkle llvm_unreachable for covered switches (NFC)
Annotate the covered switches with `llvm_unreachable` to avoid the MSVC
warning which does not recognise the covered switches.  This allows us
to avoid a spew of warnings.
2020-05-07 11:05:35 -07:00
Pavel Yaskevich 2788747b12 Merge pull request #31479 from xedin/audit-use-of-cs-in-diags
[Diagnostics] Audit use of constraint system in diagnostics
2020-05-01 20:28:46 -07:00
Pavel Yaskevich b405f7c543 [Diagnostics] Avoid direct use of constraint system by MissingArgumentsFailure::isMisplacedMissingArgument 2020-05-01 12:45:48 -07:00
Robert Widmann 31d23303e1 [NFC] Strip all remaining TypeResolutionOptions parameters
Now that these are stored in the TypeResolution object itself, and all callers that mutate flags create a new resolution object, this data can be derived from the resolution itself.
2020-04-30 10:58:40 -07:00
Robert Widmann 4130170bf2 [NFC] Internalize TypeCheckerOptions in a TypeResolution Object
Add the appropriate assertions to ensure that the now-redundant options parameters are being kept in sync so they can be retracted.

The eventual goal is to have TypeResolution requestified.
2020-04-30 10:35:02 -07:00