Commit Graph

1056 Commits

Author SHA1 Message Date
Pavel Yaskevich
502e88deff [CSSimplify] Tuple splat should account for single dependent member parameters
12a65fffee restricted tuple splat
to a single tuple or type variable parameter, but it has to
support dependent member types as well because they could be
resolved to `Void` (or empty tuple).

Resolves: rdar://problem/48443263
2019-02-27 12:20:11 -08:00
Pavel Yaskevich
9d4116d46e [CSSimplify] NFC: Extract isSingleTupleParam and missing arguments fix from matchFunctionTypes 2019-02-26 18:50:49 -08:00
Pavel Yaskevich
c664ac0ed7 [CSSimplify] While attempting to synthesize missing arguments account for "implode" case
In situations like this:

```swift
func foo(_: (Int, Int) -> Void) {}
foo { $0.0 + $0.1 }
```

Parameters are expected to be a single tuple by mistake, to account
for that solver can generate N new arguments and bind a single existing
argument to tuple formed from them.
2019-02-26 12:03:18 -08:00
Pavel Yaskevich
1c54c5a08b [ConstraintLocator] Add special locator for synthesized arguments 2019-02-25 17:07:26 -08:00
Pavel Yaskevich
0b12c664b0 [ConstraintSystem] Fix missing arguments
While trying to match function types, detect and fix any missing
arguments (by introducing type variables), such arguments would
get type information from corresponding parameters and aid in
producing solutions which are much easier to diagnose.
2019-02-25 17:07:26 -08:00
Pavel Yaskevich
12a65fffee [CSSimplify] Further Restrict tuple splat behavior
`isSingleParam` used to return `true` regardless of type of
the identified single parameter, but splat only makes sense
if such type is a tuple or a type variable which could later
be resolved to tuple. Otherwise it makes it hard to diagnose
missing arguments.
2019-02-25 17:07:26 -08:00
Joe Groff
bb67cf815c Merge pull request #21355 from technicated/tuple-keypaths-2
Tuple KeyPaths
2019-02-25 12:56:05 -08:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Pavel Yaskevich
3c9d62093f Merge pull request #22797 from xedin/diag-relabel-in-members
[Diagnostics] Improve argument labeling diagnostics
2019-02-22 00:25:36 -08:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Slava Pestov
6d19f7e0f4 Sema: Fix inconsistent behavior with SE-0110-related compatibility hack
Back when SE-0110 was implemented we decided that passing a function value
taking multiple parameters would be allowed where a function value taking
a single tuple argument was expected.

Due to quirks in the old function type representation, the "splat" in the
other direction sometimes worked too. When we redid the function type
representation we added a simulation of the old quirk for -swift-version 4
mode.

However this simulation was itself problematic because it only worked when
the function value being passed was a non-overloaded declaration reference.

Slightly broaden the hack to the overloaded case, to prevent user
confusion when adding or removing overloads.
2019-02-21 09:57:03 -05:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Pavel Yaskevich
70b5bce791 [CSFix] Use fully qualified locators for requirement failures
Would help to diagnose failures where requirement comes from
contextual type, also simplifies logic around requirement fixes
to some degree.
2019-02-18 12:03:46 -08:00
technicated
d7324b977e Added more tests
Testing SILGen & IRGen tuple keypath generation
Added tuple element type check in SILVerifier
2019-02-18 10:19:42 +01:00
Andrea Tomarelli
ede47cafbd Partial AST & Sema implementation of TKP 2019-02-18 09:04:42 +01:00
Pavel Yaskevich
4f0f090e36 [CSDiagnostics] Use generic signature to retrieve failing requirement 2019-02-14 12:18:17 -08:00
Pavel Yaskevich
0d0c132ecd [Sema] NFC: Add accessors to check whether locator is type or conditional requirement 2019-02-08 15:04:44 -08:00
Pavel Yaskevich
6fd1600534 [ConstraintSystem] Diagnose conditional requirement failures via fixes
Extend existing `RequirementFailure` functionality to support
conditional requirement failures. Such fixes are introduced
only if the parent type requirement has been matched successfully.

Resolves: rdar://problem/47871590
2019-02-08 11:16:54 -08:00
Pavel Yaskevich
f2abfc547a [ConstraintSystem] Add requirement kind to conditional conformance requirement locator 2019-02-07 13:51:20 -08:00
Pavel Yaskevich
1d8cee9cb4 [ConstraintSystem] Detect invalid initializer references early
Currently invalid initializer references are detected and
diagnosed in solution application phase, but that's too
late because solver wouldn't have required information while
attempting to determine the best solution, which might result
in viable solutions being ignored in favour of incorrect ones e.g.

```swift
protocol P {
  init(value: Int)
}

class C {
  init(value: Int, _: String = "") {}
}

func make<T: P & C>(type: T.Type) -> T {
  return T.init(value: 0)
}
```

In this example `init` on `C` would be preferred since it
comes from the concrete type, but reference itself is invalid
because it's an attempt to construct class object using
metatype value via non-required initalizer.

Situations like these should be recognized early and invalid
use like in case of `C.init` should be ranked lower or diagnosed
if that is the only possible solution.

Resolves: rdar://problem/47787705
2019-02-05 10:25:36 -08:00
Pavel Yaskevich
462cb1ffb1 Merge pull request #22124 from xedin/diagnose-partial-applies
[CSDiagnostics] Diagnose invalid partial application
2019-01-28 10:44:56 -08:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Pavel Yaskevich
b4fb25f66d Merge pull request #22050 from theblixguy/fix/SR-9201
[Diag] Fix incorrect diagnostic when unwrapping double optional
2019-01-25 23:07:09 -08:00
Suyash Srijan
614f72f85d [cs] use simplifyLocatorToAnchor and revert changes to some test diagnostic messages 2019-01-26 00:29:46 +00:00
Suyash Srijan
8845fcbbfe [cs] use anchor from locator when creating a ForceOptional fix 2019-01-25 21:41:05 +00:00
Suyash Srijan
6a0a1dec05 [cs] use anchor instead of locator, etc 2019-01-25 21:36:07 +00:00
Pavel Yaskevich
7d830cee8b [ConstraintSystem] Add a fix to detect invalid partial application
Currently supported only partial applications of instance methods
marked as `mutating`.
2019-01-25 13:29:11 -08:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
Pavel Yaskevich
57a9d3fc6d [ConstraintSystem] Warning fixes shouldn't affect solution ranking 2019-01-21 01:07:56 -08:00
Slava Pestov
e99607c421 Sema: Use ConstraintKind::Bind where possible instead of ::Equal
Solving Bind is a little easier than Equal. The only remaining uses of Equal
are in the .member syntax and keypaths; if we can refactor those, we might be
able to simplify LValue handling in the type checker in general.
2019-01-14 14:55:16 -05:00
Slava Pestov
52c1c8caaf Sema: Clean up solving BindParam constraint
- Avoid creating an unnecessary type variable
- Even if both sides are type variables we can solve them if the LHS cannot
  bind to an InOut or the RHS cannot bind to an LValue; in this case the two
  types are identical and we can merge them
2019-01-12 18:03:01 -05:00
Slava Pestov
353b4cc4c4 Sema: Solve Bind constraints involving to two variables of different lvalue-ness
The restriction here only applies to Equal constraints.

Fixes <rdar://problem/45511838>, <https://bugs.swift.org/browse/SR-9068>.
2019-01-12 18:03:01 -05:00
Slava Pestov
33871548b3 Clean up TypeVariableType::Implementation::mustBeMaterializable(), etc 2019-01-12 14:10:11 -05:00
Pavel Yaskevich
6791ef3624 Merge pull request #21756 from xedin/rdar-36989788
[Diagnostics] Diagnose missing members via fixes
2019-01-10 10:36:17 -08:00
Slava Pestov
4dfbd8f2cc Sema: Remove some unreachable LValueType checks 2019-01-10 08:44:18 -05:00
Slava Pestov
1026968616 Sema: Remove ConversionRestrictionKind::TupleToTuple 2019-01-10 08:44:18 -05:00
Slava Pestov
28343c9480 Sema: Remove ConversionRestrictionKind::LValueToRValue 2019-01-10 08:44:18 -05:00
Slava Pestov
dab4616bc1 Sema: simplifyRestrictedConstraintImpl() can't form unsolved constraints 2019-01-10 08:44:18 -05:00
Slava Pestov
515ffe9761 Sema: Don't try to solve conversions where one side is a type variable 2019-01-10 08:44:18 -05:00
Pavel Yaskevich
60fb2bf94e [CSFix] Try to fix missing member by defining it based on use
If lookup couldn't find anything matching given name, let's try to
fake its presence based on how member is being used. This is going
to help (potentially) type-check whole expression and diagnose the
problem precisely.
2019-01-09 14:35:27 -08:00
Pavel Yaskevich
f032b9c57c [CSFix] Attempt to replace .subscript(...) with subscript operator
If there are no members named "subscript" available, let's try to
replace it with subscript operator with might be what was intended.
2019-01-08 12:06:40 -08:00
Slava Pestov
c5cdd709ba Sema: SE-0110 tuple splatting should not implode argument list with varargs
Fixes <https://bugs.swift.org/browse/SR-9470>.
2018-12-16 01:02:56 -05:00
Slava Pestov
2f61230627 Sema: Remove vestigial rvalue varargs code path 2018-12-16 01:02:56 -05:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Joe Groff
20a2f3ea9f Merge pull request #21244 from jckarter/archetype-subclasses
Split subclasses out of ArchetypeType.
2018-12-12 11:49:48 -08:00
Joe Groff
f1648a1b3e Split subclasses out of ArchetypeType.
Context archetypes and opened existential archetypes differ in a number of details, and this simplifies the overlapping storage of the kind-specific fields. This should be NFC; for now, this doesn't change the interface of ArchetypeType, but should allow some refinements of how the special handling of certain archetypes are handled.
2018-12-12 08:55:56 -08:00
Pavel Yaskevich
f086d41094 [CSFix] Call a function/member which is incorrectly used as a property
If the base type for the member lookup is a function, let's try to
use its result type as a base instead, maybe there is just a call
missing.
2018-12-11 16:58:43 -08:00
Pavel Yaskevich
a093691114 Merge pull request #21043 from xedin/rdar-40537782
[CSDiagnostics] Diagnose invalid optional unwrap via fixes
2018-12-05 16:06:05 -08:00
Pavel Yaskevich
e043e2b2b3 [CSFix] Add a fix to remove invalid optional unwrap
If the base type is not optional, trying to unwrap it is
incorrect. Introduce a fix to make it look like base was
an optional type which leads solver to move forward
towards possible solution.
2018-12-04 18:40:04 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00