Commit Graph

767 Commits

Author SHA1 Message Date
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
174fd14090 [CSDiagnostics] Diagnose invalid partial application of init delegation 2019-01-25 14:18:04 -08: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
Pavel Yaskevich
fe9376dd78 Merge pull request #22082 from xedin/move-weights-to-cs
[ConstraintSystem] Track AST depth information directly
2019-01-24 11:53:17 -08:00
Pavel Yaskevich
e604261805 [ConstraintSystem] Track AST depth information directly
Instead of storing information about expression depths in the
solver state (which gets recomputed for salvage) let's track
it directly in constraint system, which also gives solver
access to it when needed e.g. for fixes.
2019-01-23 18:44:53 -08:00
Pavel Yaskevich
49c40d92f6 [AST] Augment getDepthMap with information about parent expressions
Which is very useful for the solver because otherwise it'd have to
compute and store this information twice.
2019-01-23 18:21:07 -08:00
David Ungar
584c157796 WIP move info to KnownProtocols.def, unformatted 2019-01-17 11:15:58 -08:00
Slava Pestov
6f15193ac3 Merge pull request #21846 from slavapestov/bind-constraint-more
Sema: Use ConstraintKind::Bind where possible instead of ::Equal
2019-01-14 17:56:14 -05:00
Pavel Yaskevich
69c622fc06 Merge pull request #21783 from xedin/rdar-30933988
[AST] `Decl::is*AccessibleFrom` methods should respect access control…
2019-01-14 14:06:44 -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
33871548b3 Clean up TypeVariableType::Implementation::mustBeMaterializable(), etc 2019-01-12 14:10:11 -05:00
Pavel Yaskevich
5426e0df9e [AST] Decl::is*AccessibleFrom methods should respect access control flag
Otherwise integrated REPL and other tools like LLDB would produce
incorrect results or crash.

Resolves: rdar://problem/30933988
2019-01-11 17:30:10 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Slava Pestov
716ac81b3e AST: Cache protocol generic signature in GenericContext::getGenericSignature()
The generic signature of a protocol is simple enough that we can
build it directly when asked. However, be sure to cache it for
future use.
2019-01-08 22:58:12 -05:00
Pavel Yaskevich
91e97a0c8f [Diagnostics] Diagnose ambiguity resulting from subscript operator fix as a missing member
Since the rule is to prioritize names over types, let's diagnose
ambiguous solutions containing subscript operator fix as missing
member and list possible candidates to use.
2019-01-08 12:09:02 -08:00
Pavel Yaskevich
637692ccf8 [ConstraintSystem] NFC: Define {activate, deactivate}Constraint to make that logic reusable 2018-12-18 10:24:11 -08:00
Joe Groff
b701dc4f10 Merge pull request #21277 from jckarter/archetype-subclass-api
Push ArchetypeType's API down to subclasses.
2018-12-13 06:36:09 -08:00
Doug Gregor
aa506289a3 Merge pull request #21231 from DougGregor/simd-operator-type-check-perf-hack
[Constraint solver] De-prioritize SIMD operators.
2018-12-12 20:15:21 -08: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
Doug Gregor
052d4c196c [Type checker] Pull the null check into swift::isSIMDOperator(). 2018-12-11 16:39:10 -08:00
Doug Gregor
88d34a1c7c [Constraint solver] De-priority SIMD operators.
The new SIMD proposal introduced a number of new operators, the presence of
which causes more "expression too complex" failures. Route around the
problem by de-prioritizing those operators, visiting them only if no
other operator could be chosen. This should limit the type checker
performance cost of said operators to only those expressions that need
them OR that already failed to type-check.

Fixes rdar://problem/46541800.
2018-12-11 16:34:37 -08:00
Pavel Yaskevich
b429d5a28a [ConstraintSystem] Erase InOutExpr from member base
Diagnostics could introduce type-checked expressions into AST during
it's bottom up re-typechecking in attempt to find a problem.

To minimize number of AST permutations solver has to handle
let's just strip away implicit `InOutExpr` introduced by previous
successful type-checks, which is not really important anyway.

Resolves: rdar://problem/46459603
2018-12-10 23:23:22 -08:00
Pavel Yaskevich
694c89c090 [ConstraintSystem] Handle InOut base introduced by diagnostic re-typecheck
While trying to lookup member reference on some base type, handle
base being an `InOutType`, which could be a result of previous
sub-expression re-typechecks made by diagnostics.

Resolves: rdar://problem/45771997
2018-12-06 16:02:28 -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
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
bce1ba5f37 [AST] Remove @autoclosure flag from function type ExtInfo 2018-11-10 11:59:29 -08:00
Mark Lacey
72ba110e5b [ConstraintSystem] Rework new constraint stat as a FRONTEND_STATISTIC.
In the process, remove the old incrementScopeCounter SWIFT_FUNC_STAT.
2018-10-18 07:18:02 -07:00
Mark Lacey
cc0386b461 [ConstraintSystem] Add a new stat to be used for expression type checker performance testing.
This counts the number of leaf scopes we reach while solving the
constraint sytem, and is a much better measure of the growth of
unnecessary work than the total number of scopes opened.

There were two tests where I had a difficult time getting scale-test
to fit the curve even after adjusting some of the parameters, so I've
left those to use the old stat for now.
2018-10-17 07:26:18 -07:00
Pavel Yaskevich
59899a7911 [ConstraintSystem] Make sure that system is returned into its original state after solving
Currently (with or w/o failures) constraint system is not returned
back to its original state after solving, because constraints from
initial "active" list are not returned to the system. To fix that
let's allocate "initial" scope which captures state right before
solving begins, and add "active" list to the solver state to capture
information about "active" constraints at the time of its creation.

This is follow-up to https://github.com/apple/swift/pull/19873
2018-10-15 16:33:57 -07:00
gregomni
dec2f455a8 More thorough retry of constraints which may succeed now that fixes are allowed. 2018-10-14 09:34:43 -07:00
gregomni
b7df1ca1df Re-try a failingConstraint during salvage now that attemptFixes is turned on. This enables better missing conforms-to diagnoses. 2018-10-13 20:06:19 -07:00
Slava Pestov
2d4b25960d Sema: Type variables for opened generic parameters store the generic parameter type and not an archetype
There's no need to instantiate archetypes in the generic environment
of the declaration being opened.

A couple of diagnostics changed. They were already misleading, and the
new diagnostics, while different, are not any more misleading than
before.
2018-09-27 20:49:23 -07:00
Slava Pestov
f2868dfaac Sema: Don't load unnecessary lazy generic environment in bindArchetypesFromContext() 2018-09-26 23:26:07 -07:00
Slava Pestov
858f4b9562 Sema: Remove AssociatedType constraint locator element kind 2018-09-26 23:26:07 -07:00
gregomni
6deb401cc6 Previously we were sharing a single type variable for a param of a closure's function type and it's paramDecl's type inside the closure itself. With inout parameters this caused vardecls of inout type and some hacks to deal with them.
Instead, create two TVs and constrain them appropriately.
2018-09-23 17:41:18 -07:00
Pavel Yaskevich
baceb68f85 [ConstraintSystem] Rename solveIteratively to solve and start using it
Remove solution filtering from new iterative `solve` method, and
replace all usages of `solveRec` with it.
2018-09-15 20:56:47 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Slava Pestov
83cc9755ed Sema: Refactor matchFunctionTypes() to walk parameter lists directly
This lets us remove a variety of ParenType-preserving hacks.
2018-09-10 12:30:47 -07:00
Pavel Yaskevich
d560b36c5c [ConstraintSystem] NFC: Move allowFreeTypeVariableBindings into SolverState
Currently `allowFreeTypeVariableBindings` flag has to be passed all
the way down from top-level `solve` call to `finalize` that forms
(partial and complete) solutions. Instead of doing that, let's just
make it a part of the solver state, which is already present
throughout whole solver run.
2018-08-31 19:51:11 -07:00
Slava Pestov
765b8844cf Sema: Move removeArgumentLabels() to a method on TypeBase 2018-08-28 14:40:56 -07:00
Pavel Yaskevich
c69097f027 Merge pull request #18980 from xedin/move-salvage-to-cs
[ConstraintSystem] Move `salvage` and related logic away from `CSDiag`
2018-08-25 14:09:48 -07:00
Pavel Yaskevich
7dda51bb81 [Diagnostics] Transform tryDiagnoseTrailingClosureAmbiguity into a failure 2018-08-25 00:19:41 -07:00
Pavel Yaskevich
ea62075766 [ConstraintSystem] NFC: Move diagnoseAmbiguity methods from CSDiag to ConstraintSystem` 2018-08-24 23:18:49 -07:00
Pavel Yaskevich
4692e30c0a [ConstraintSystem] NFC: Move salvage from CSDiag to ConstraintSystem 2018-08-24 17:37:24 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Doug Gregor
0eaa00a470 [Type checker] Separate type resolution from the TypeChecker instance. 2018-08-20 22:18:43 -07:00
Doug Gregor
2756377367 [Type checker] Separate more functionality from the TypeChecker instance.
Use the usual bag of tricks to eliminating dependence on the
TypeChecker instance: static functions, LazyResolver callbacks, and
emitting diagnostics on decls/ASTContext.
2018-08-20 21:39:44 -07:00
Doug Gregor
7fa4f1df54 Merge pull request #18859 from DougGregor/type-resolution-stage
[Type Checker] Add TypeResolution(Stage) to describe type computations.
2018-08-20 18:44:31 -07:00