Commit Graph

767 Commits

Author SHA1 Message Date
Pavel Yaskevich
0ecedfa5ea Revert "[ConstraintSystem] Make it possible to infer subtype bindings through argument conversions"
Reverts apple/swift#30006. It caused a regression that we'd like to address before re-landing:

```swift
struct X {
  var cgf: CGFloat
}

func test(x: X?) {
  let _ = (x?.cgf ?? 0) <= 0.5
}
```

This reverts commit 0a6b444b49.
This reverts commit ed255596a6.
This reverts commit 3e01160a2f.
This reverts commit 96297b7e39.

Resolves: rdar://problem/60185506
2020-03-07 20:16:56 -08:00
Pavel Yaskevich
7c19d1ccd1 [ConstraintSystem] Remove baseCS since CSDiag has been removed
There is no more sub-expression re-typechecking so no need to keep
parent constraint systems around.
2020-03-06 09:35:52 -08:00
Pavel Yaskevich
4c600843d6 [ConstraintSystem] Check availability as part of resolving overload choice
This is a follow up to changes related to contextual availability
(https://github.com/apple/swift/pull/29921) which increased score
for unavailable declarations only if they were overloaded but
overlooked a case of a single unavailable choice.

Resolve: rdar://problem/60047439
2020-03-05 00:35:47 -08:00
Holly Borla
fce8738ea8 [ConstraintSystem] Replace dependent member types with holes when the base type
doesn't conform to the associatedtype's protocol (only in diagnostic mode).

This allows the solver to find solutions for more cases involving requirement
failures for dependent member types without special cases across the solver
that check for dependent member types with no type variables.
2020-03-03 15:45:24 -08:00
Robert Widmann
d494cc8dcb Merge pull request #30109 from CodaFi/lies-more-lies-and-statistics
[Frontend] Clean Up Usage of UnifiedStatsReporter
2020-02-28 10:24:02 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Slava Pestov
019452f9af Sema: Diagnose unbound method references on 'super.'
This is something I noticed by inspection while working on
<https://bugs.swift.org/browse/SR-75>.

Inside a static method, 'self' is a metatype value, so
'self.instanceMethod' produces an unbound reference of type
(Self) -> (Args...) -> Results.

You might guess that 'super.instanceMethod' can similarly
be used to produce an unbound method reference that calls
the superclass method given any 'self' value, but unfortunately
it doesn't work.

Instead, 'super.instanceMethod' would produce the same
result as 'self.instanceMethod'. Maybe we can implement this
later, but for now, let's just diagnose the problem.

Note that partially-applied method references with 'super.'
-- namely, 'self.staticMethod' inside a static context, or
'self.instanceMethod' inside an instance context, continue
to work as before.

They have the type (Args...) -> Result; since the self value
has already been applied we don't hit the representational
issue.
2020-02-27 17:28:23 -05:00
Holly Borla
3cdc30ffeb [Sema] Support type erasure for dynamic replacement in function
builders.
2020-02-27 09:01:16 -08:00
Slava Pestov
90ee606de7 Sema: Refactor CSApply in preparation for curry thunks 2020-02-26 23:10:07 -05:00
Doug Gregor
cc8db01ba9 Merge pull request #30045 from DougGregor/function-builders-if-let
[Constraint system] Support if let / if case in function builders.
2020-02-25 16:24:09 -08:00
Doug Gregor
3f2f79a699 [Constraint system] Fold pattern variable binding into constraint gen.
Rather than re-walk the pattern to create type bindings for the variables
that show up in the pattern, assign types to each of the variables as part
of constraint generation for the pattern. Only do this in contexts
where we will need the types, e.g., function builders.
2020-02-25 08:51:56 -08:00
Pavel Yaskevich
0a6b444b49 [ConstraintSystem] Diagnose argument conflicts only for "representative" generic parameters
Consider following example:

```swift
struct MyType<TyA, TyB> {
  var a : TyA, b : TyB
}

typealias B<T1> = MyType<T1, T1>

_ = B(a: "foo", b: 42)
```

Here `T1` is equal to `TyA` and `TyB` so diagnostic about
conflicting arguments ('String' vs. 'Int') should only be
produced for "representative" `T1`.
2020-02-21 16:49:37 -08:00
Pavel Yaskevich
71753f3ca6 [ConstraintSystem] Rank contextually unavailable overloads lower than other choices (#29921)
Currently constraint solver is only capable of detecting universally unavailable
overloads but that's insufficient because it's still possible to pick a contextually
unavailable overload choice which could be better than e.g. generic overload, or
one with defaulted arguments, marked as disfavored etc.

Let's introduce `ConstraintSystem::isDeclUnavailable` which supports both universal
and contextual unavailability and allow constraint solver to rank all unavailable
overload choices lower than any other possible choice(s).

Resolves: rdar://problem/59056638
2020-02-19 13:13:53 -05:00
Hamish Knight
ed1d372887 [CS] Remove DiagnosedExprs 2020-02-19 07:43:59 -08:00
Pavel Yaskevich
2c92df4a6d [ConstraintSystem] Simplify diagnoseAmbiguityWithEphemeralPointers
Don't attempt to figure out what exactly is ambiguous, let
`diagnoseAmbiguity` take care of that. Simplify make sure
that only some of the solutions have fixes and these fixes
are all related to use of ephemeral pointers.
2020-02-18 15:06:13 -08:00
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -08:00
Pavel Yaskevich
b905113f5c [ConstraintSystem] Remove now completely obsolete CSDiag 2020-02-18 09:12:56 -08:00
Pavel Yaskevich
0c451bb2a9 [Diagnostics] Diagnose ambiguities related to ephemeral pointers
Diagnose ambiguity related to overloaded declarations where only
*some* of the overload choices have ephemeral pointer warnings/errors
associated with them. Such situations have be handled specifically
because ephemeral fixes do not affect the score.

If all of the overloads have ephemeral fixes associated with them
it's much easier to diagnose through notes associated with each fix.
2020-02-17 16:09:11 -08:00
Luciano Almeida
a32e3f4598 [docs] Updating TypeChecker.rst 2020-02-16 18:41:57 -03:00
Luciano Almeida
6c617f9718 [ConstraintSystem] Removing check related to ArgumentMismatch in CSDiag. 2020-02-16 16:51:41 -03:00
Puyan Lotfi
b707b7f0b3 Fixing build breaks for master-next against latest llvm.org.
There were changes due to the StringRef to std::string conversion, changes
in the Debug Info DIBuilder::createModule API, and a drop in the using for
PointerUnion4 since PointerUnion is now a variadic template and will do in its
place.
2020-02-13 14:12:21 -08:00
Pavel Yaskevich
355148dbe8 Merge pull request #29746 from hborla/ambiguity-with-fixes
[Diagnostics] Refactor diagnoseAmbiguityWithFixes.
2020-02-13 02:42:43 -08:00
Pavel Yaskevich
172c2003ea [Diagnostics] NFC: Add a comment about special handling of opaque result types 2020-02-13 00:54:51 -08:00
Pavel Yaskevich
b872bdfca1 [Diagnostics] Replace llvm::find_if with llvm::any_of in diagnoseAmbiguityWithFixes 2020-02-13 00:45:44 -08:00
Pavel Yaskevich
60a210b657 [ConstraintSystem] NFC: Fix a couple of typos in comments 2020-02-13 00:44:20 -08:00
Pavel Yaskevich
3f10bfa74e [Diagnostics] NFC: Rename diagnoseConflictingArguments into diagnoseConflictingGenericArguments 2020-02-12 18:17:10 -08:00
Pavel Yaskevich
af65c0e2f3 [Diagnostics] Prioritize contextual type mismatch other ambiguities 2020-02-12 17:55:32 -08:00
Pavel Yaskevich
5437622d2d [Diagnostics] Diagnose ambiguity with conflicting arguments to generic parameters
It's done by first retrieving all generic parameters from each solution,
filtering boundings into distrinct set and diagnosing any differences.

For example:

```swift
func foo<T>(_: T, _: T) {}
func bar(x: Int, y: Float) {
  foo(x, y)
}
```
2020-02-12 17:53:31 -08:00
Robert Widmann
054d7b9913 Merge pull request #29713 from CodaFi/unused-unwanted-unloved
[Gardening] Silence Some Warning Spew
2020-02-11 15:46:16 -08:00
Holly Borla
d1f6b3e2ef [Diagnostics] When diagnosing an ambiguous overload, don't mention "call"
if the expression is not a function application.
2020-02-11 14:53:27 -08:00
Holly Borla
1a628f3107 [Diagnostics] Simplify logic in diagnoseAmbiguityWithFixes for emitting
the ambiguity diagnostic by combining a few special errors into one.
2020-02-11 14:53:27 -08:00
Holly Borla
651c27b50b [Diagnostics] Add CSFix::diagnoseForAmbiguity for diagnosing common
fixes that appear in all solutions.
2020-02-11 14:53:27 -08:00
Holly Borla
54706ba79b [Diagnostics] Simplify diagnoseAmbiguityWithFixes by removing AmbiguityKind. 2020-02-11 14:53:27 -08:00
Holly Borla
607c298493 [Diagnostics] Refactor diagnoseAmbigutiyWithFixes to use the differences between
solutions in order to figure out the source of ambiguity.
2020-02-11 14:52:41 -08:00
Pavel Yaskevich
b3590c5f1d Merge pull request #29734 from LucianoPAlmeida/remove-diag-parameters-errors
[Diagnostics] Remove `FailureDiagnosis::diagnoseParameterErrors` from CSDiag
2020-02-11 01:32:31 -08:00
Luciano Almeida
46092aff3e [tests] Adjusting tests under type/opaque 2020-02-10 07:48:34 -03:00
Luciano Almeida
449ab7383f [ConstraintSystem] Disambiguate cases of argument/param mismatches involving generic functions 2020-02-09 21:19:01 -03:00
Doug Gregor
d70c055888 [Constraint system] Sink more init logic into SolutionApplicationTarget
More steps toward eliminating ExprTypeCheckListener.
2020-02-07 22:46:05 -08:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Doug Gregor
36366bc3e4 [Constraint solver] One SolutionApplicationTarget instance to rule them all.
Capture the peculiarities of contextual types vs. types used to generate
conversion constraints, as well as the behavior of “optional some” patterns
as used by if let / while let, within SolutionApplicationTarget. This allows
us to use a single target throughout setup / solving / application, rather
than mapping between two similar-but-disjoint targets.
2020-02-03 22:02:21 -08:00
Doug Gregor
9278fb8c22 [Constraint system] Eliminate TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType
We can compute this information based solely on the SolutionApplicationTarget,
so do it.
2020-02-02 23:41:24 -08:00
Doug Gregor
52da2d6c4c [Constraint system] Extend SolutionApplicationTarget with an init pattern.
Initializer expressions are always type checked against a pattern, so also
include the pattern in the solution application target and use that to
compute the contextual type from the pattern type.
2020-02-02 22:31:27 -08:00
Doug Gregor
3b761dcae1 [Constraint system] Add a SolutionApplicationTarget-based typeCheckExpression
Rework most of typeCheckExpression() to use SolutionApplicationTarget,
folding more information into that data structure and sinking more
expression-checking behavior down into the more general solver and
solution-application code.
2020-02-01 23:46:13 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
Doug Gregor
bfa6d7316d [Function builders] Fake Expr-based locators for now.
The right solution is to extend the notion of the "anchor" of a locator
to also cover statements (and TypeReprs, and Patterns, and more), so
this is a stop-gap.
2020-01-16 13:19:21 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Pavel Yaskevich
8269522f86 Merge pull request #28837 from xedin/rdar-56340587
[ConstraintSystem] Delay constraint generation for single-statement closure body
2020-01-16 00:29:11 -08:00