Commit Graph

990 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
28a66a23eb [CSSimplify] Delay binding metatype instance types if one side is type variable
While matching two metatypes where one side is a class (which could have
supertypes) and another is a type variable use `subtype` constraint to
delay binding types together because there is a real possibility that
there exists a superclass associated with yet free type variable which
would be a better match when attempted.

Resolves: rdar://problem/44816848
2018-11-27 14:36:46 -08:00
Pavel Yaskevich
cc780e3292 [ConstraintSystem] Make sure that @autoclosure argument detection works for subscripts/members
Currently logic in `matchCallArguments` could only detect argument
being an @autoclosure parameter for normal calls and operators.

This patch extends it to support subscripts and unresolved member calls.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
f9dae942f8 [CSFix] Add fix to track invalid @autoclosure forwarding 2018-11-21 12:17:25 -08:00
Mark Lacey
018498fb2f Merge pull request #16942 from bjhomer/bjhomer/optional-try-flattening
Flatten nested optionals resulting from try? and optional sub-expressions
2018-11-16 11:14:05 -08:00
Mark Lacey
a5d627844a Merge pull request #20618 from rudkx/favor-equality
[ConstraintSystem] When we have multiple conversions/fixes, make equa…
2018-11-16 06:27:42 -08:00
Mark Lacey
33b6e43efa [ConstraintSystem] When we have multiple conversions/fixes, make equality favored.
This allows us to skip attempting actual conversions.

This speeds up one of our slow test cases, and perturbs the output of
another test. In the latter case, we stop emitting conversions as part
of the non-semantic piece of the array_expr. The fact that we're not
putting conversions in on that path is something I've seen before in
other instances. I'll open a bug if I cannot find one for it, although
I believe it's entirely cosmetic in this case since we don't rely on
the conversion being there.
2018-11-15 17:38:22 -08:00
Dan Zheng
0d2787fb31 [NFC] Remove extraneous comment. (#20567) 2018-11-14 08:41:04 -05:00
Dan Zheng
eebccb7a09 Fix @dynamicMemberLookup for protocol/archetype types. (#20516)
- Enable `subscript(dynamicMember:)` as a requirement for
  `@dynamicMemberLookup` protocols.
- Add tests.
- Minor `@dynamicCallable`-related gardening.

Resolves SR-8077.
2018-11-13 18:13:33 -05:00
Dan Zheng
2863b6cc64 Gardening for @dynamicMemberLookup. (#20498)
* Gardening for `@dynamicMemberLookup`.

- Unify code style of `@dynamicMemberLookup` and `@dynamicCallable` implementations.
  - Use consistent variable names, diagnostic messages, doc comments, etc.
- Move `@dynamicMemberLookup` test to `test/attr` directory.
2018-11-11 21:54:19 -05:00
Pavel Yaskevich
ed84f18686 [AST] NFC: Remove a FIXME related to ParamDecl::IsAutoClosure field 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
6224d12fe6 [ConstraintSystem] Remove now redundant @autoclosure checking
There is one place which handles `@autoclosure` attribute
associated with parameters - `matchCallArguments`.
2018-11-10 11:59:28 -08:00
Pavel Yaskevich
f462521078 [ConstraintSystem] Refactor arg/param matching to handle autoclosures
Make sure that presence of `@autoclosure` attribute handled
in one place - `matchCallArguments`, which makes it possible
to remove the rest of (now redundant) autoclosure related
logic scattered throughout solver.
2018-11-10 11:59:28 -08:00
Dan Zheng
2a4e1b83fd Implement @dynamicCallable. (#20305)
* Implement dynamically callable types (`@dynamicCallable`).

- Implement dynamically callable types as proposed in SE-0216.
  - Dynamic calls are resolved based on call-site syntax.
  - Use the `withArguments:` method if it's defined and there are no
    keyword arguments.
  - Otherwise, use the `withKeywordArguments:` method.
- Support multiple `dynamicallyCall` methods.
  - This enables two scenarios:
    - Overloaded `dynamicallyCall` methods on a single
      `@dynamicCallable` type.
    - Multiple `dynamicallyCall` methods from a `@dynamicCallable`
      superclass or from `@dynamicCallable` protocols.
  - Add `DynamicCallableApplicableFunction` constraint. This, used with
    an overload set, is necessary to support multiple `dynamicallyCall`
    methods.
2018-11-09 09:49:14 -08:00
Pavel Yaskevich
66a79301b4 [CSDiagnostics] Diagnose contextual closure result mismatches via fixes
Let's keep track of type mismatch between type deduced
for the body of the closure vs. what is requested
contextually, it makes it much easier to diagnose
problems like:

```swift
func foo(_: () -> Int) {}
foo { "hello" }
```

Because we can pin-point problematic area of the source
when the rest of the system is consistent.

Resolves: rdar://problem/40537960
2018-11-07 14:28:50 -08:00
BJ Homer
1789d44d6c Don't consider fixups that won't do anything.
Since 'try?' no longer unconditionally adds a layer of optional, converting it
to 'try!' will no longer unconditionally remove a layer of optional. So let's not
suggest it. This leads to better diagnostics anyway.
2018-11-06 23:31:02 -07:00
Greg Titus
d20fdf5f82 Merge pull request #19920 from gregomni/8757
[Sema][QoI] Call out missing conformances in protocol witness candidates.
2018-10-22 16:39:51 -07:00