Commit Graph

7976 Commits

Author SHA1 Message Date
Robin Kunde
71364d0d09 fix SR-3168: add fix-it for "'optional' can only be applied to protocol members" (#5717) 2016-11-11 14:00:45 +09:00
Ben Langmuir
40ff57decf Disable typo-correction after fatal errors
If we won't show the diagnostics anyway, don't go to the trouble of
performing the typo-corrections, which can be expensive.  This is really
helpful if there is a module import failure, which may cause many names
to fail to resolve and would otherwise trigger typo-correction.

rdar://problem/29003372
2016-11-10 14:23:21 -08:00
Doug Gregor
84d70a2284 Eliminate witness markers. NFC 2016-11-09 19:22:51 -08:00
Aleksey Gaponov
3419925ff1 [SR-2209] Fix access scope diagnostics for top-level declarations. 2016-11-09 21:18:37 +01:00
Doug Gregor
e2f8d4d9f9 Merge pull request #5687 from DougGregor/drop-witness-markers
Drop witness markers for 'uninteresting' dependent types
2016-11-08 18:43:41 -08:00
Doug Gregor
5f58b267df Use GenericSignature::getSubstitutions() in AttributeChecker::visitSpecializeAttr.
Rather than implement an ad hoc version of
GenericSignature::getSubstitutions(), walk the requirements enough to
check the validity of the @_specialize attribute and then use
GenericSignature::getSubstitutions() to actually form the resulting
substitutions.

One less place in the code where we depend on witness markers.
2016-11-08 17:17:49 -08:00
Doug Gregor
5cf38210f3 [Conformance checker] Add debug dumping for inferred type witnesses.
Debugging type witness inference is annoying; add some dumping code to
help with debugging.
2016-11-08 16:11:30 -08:00
Doug Gregor
08aa31d519 [Constraint solver] Slightly expand the "contextual conversion failure" check.
Expand the context conversion failure check used to fix
rdar://28909024 to cover the case where we have a single-argument
mismatch and there is a type parameter deduction as well.
2016-11-08 16:11:30 -08:00
Doug Gregor
3205b8a6c4 Fix ad hoc substitution lists to not include derived type substitutions. 2016-11-08 16:11:29 -08:00
Doug Gregor
e20464a02c [Constraint solver] Remove 'type member' constraint.
Only some fallback code in the for-each binding checking code was
using this constraint. Implement those checks more directly.
2016-11-06 23:14:15 -08:00
Doug Gregor
00c98efcd7 Revert "[Type checker] Recurse into statements when cleaning type variables."
This reverts commit 45db3e3b89.
2016-11-06 22:31:08 -08:00
Doug Gregor
f19c4af050 Revert "[Type checker] Recurse into statements when cleaning type variables, harder."
This reverts commit 01913beba0.
2016-11-06 22:30:54 -08:00
Doug Gregor
6ab5a2f538 Merge pull request #5659 from DougGregor/clear-stmt-type-vars-harder
[Type checker] Recurse into statements when cleaning type variables, …
2016-11-06 22:10:32 -08:00
Doug Gregor
01913beba0 [Type checker] Recurse into statements when cleaning type variables, harder.
Resolved crasher #28474, which is failing to crash reliably on CI. Just fix it.
2016-11-06 22:08:49 -08:00
Doug Gregor
040f44de72 Merge pull request #5658 from DougGregor/clear-stmt-type-vars
[Type checker] Recurse into statements when cleaning type variables.
2016-11-06 21:56:26 -08:00
Doug Gregor
45db3e3b89 [Type checker] Recurse into statements when cleaning type variables.
Resolves two crashes, one of which (28470) is affecting the buildbots
but not my local builds.
2016-11-06 21:53:53 -08:00
Dave Abrahams
c5f3079ead Merge pull request #5653 from practicalswift/american-english-analysis
[gardening] Use American English: "analyse" → "analyze", "analysing" → "analyzing"
2016-11-06 16:00:58 -08:00
Doug Gregor
8271c1a657 Merge pull request #5626 from DougGregor/dependent-type-variables
[Type checker] Use DependentMemberType instead of type variables for nested types.
2016-11-06 07:27:19 -08:00
practicalswift
f328070a2b [gardening] Use American English: "analysing" → "analyzing" 2016-11-06 14:14:22 +01:00
practicalswift
17503b0d85 [gardening] Use American English. 2016-11-06 10:12:04 +01:00
Doug Gregor
ba06709eca [Constraint solver] Dependent members don't "involve type variables".
The constraint solver tries not to solve for type variables that
"involve other type variables", which handles the case where we have
seen a constraint that mentions the type variable under consideration
as well as a different type variable, but in a constraint that we
cannot capture in a binding. Solving for such type variables too early
can lead to missed solutions, so we avoid it.

Tweak the logic for this computation to not consider type variables
mentioned within dependent member types (e.g., $T0.Iterator.Element),
because such types do not affect type inference at all, and therefore
shouldn't prevent solving for the type variable in question.
2016-11-05 23:20:28 -07:00
Doug Gregor
522cbf26fa [Constraint solver] Show potential bindings in debug output. 2016-11-05 23:20:28 -07:00
Doug Gregor
4a5402849b Remove the now-unnecessary "get member type" callback.
The ASTContext had a wacky "get member type" callback that actually
called back into the constraint system (!) to build member types. This
callback was obsoleted by the change that started representing nested
types as DependentMemberTypes.
2016-11-05 23:20:28 -07:00
Doug Gregor
f168e7270c [Type checker] Use DependentMemberType instead of type variables for nested types.
In the constraint solver, we've traditionally modeled nested type via
a "type member" constraint of the form

  $T1 = $T0.NameOfTypeMember

and treated $T1 as a type variable. While the solver did generally try
to avoid attempting bindings for $T1 (it would wait until $T0 was
bound, which solves the constraint), on occasion we would get weird
behavior because the solver did try to bind the type
variable.

With this commit, model nested types via DependentMemberType, the same
way we handle (e.g.) the nested type of a generic type parameter. This
solution maintains more information (e.g., we know specifically which
associated type we're referring to), fits in better with the type
system (we know how to deal with dependent members throughout the type
checker, AST, and so on), and is easier to reason able.

This change is a performance optimization for the type checker for a
few reasons. First, it reduces the number of type variables we need to
deal with significantly (we create half as many type variables while
type checking the standard library), and the solver scales poorly with
the number of type variables because it visits all of the
as-yet-unbound type variables at each solving step. Second, it
eliminates a number of redundant by-name lookups in cases where we
already know which associated type we want.

Overall, this change provides a 25% speedup when type-checking the
standard library.
2016-11-05 23:20:28 -07:00
Doug Gregor
245f995b5d [Constraint solver] Track the total number of type variables created.
The constraint solver scales poorly with the number of type variables,
so track it.
2016-11-05 23:20:27 -07:00
Rintaro Ishizaki
f4a9898142 [QoI] Improve "never used" diagnostics (#5638)
On 'let (x) = some', we should remove r-paren as well.
On 'let x: Int = some', we can't remove 'let' introducer.
2016-11-05 15:17:54 +09:00
Aleksey Gaponov
f51b2d12c4 [SR-2209] Make a real AccessScope class and use it in access checking.
1. Add new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of "ValueDecl::getFormalAccessScope".
3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag to distinguish "private" from "fileprivate"
scope for top-level DeclContext.
2016-11-04 12:42:38 +01:00
Slava Pestov
5e46f9c2d4 Sema: Allow extensions of nested generic types via generic typealiases 2016-11-03 23:07:42 -07:00
Slava Pestov
c7089ff000 Sema: Add support for extensions of nested generic types 2016-11-03 22:20:30 -07:00
Slava Pestov
5cee339ebf Sema: Tweak substMemberTypeWithBase() for nested generic types 2016-11-03 22:20:30 -07:00
Mark Lacey
f7d94d9ee8 Merge pull request #5627 from rudkx/fix-rdar28317710
Do not assume Set/Dictionary are always bound generic types.
2016-11-03 14:19:59 -07:00
Mark Lacey
8d8c258dda Merge pull request #5625 from rudkx/fix-rdar28387684
Fix crash in member lookup when base type contains type variables.
2016-11-03 13:07:48 -07:00
Mark Lacey
c7f448f972 Do not assume Set/Dictionary are always bound generic types.
In cases where we cannot infer the types they won't be, so we don't want
to just cast to BoundGenericType when we see these.

Fixes rdar://problem/28317710 and at least one dup (and I think a few
more).
2016-11-03 00:42:03 -07:00
Slava Pestov
6109440314 Merge pull request #5616 from slavapestov/generic-typealias-subst-fix
Sema: Fix crash when substitution into generic typealias fails
2016-11-02 21:31:27 -07:00
Mark Lacey
18c809d1d4 Fix crash in member lookup when base type contains type variables.
We were crashing during performTypoCorrection if the base type contained
type variables.

rdar://problem/28387684
2016-11-02 21:12:47 -07:00
swift-ci
4c96f64b64 Merge pull request #5624 from rudkx/leaky-type-variables 2016-11-02 18:31:40 -07:00
Graydon Hoare
9351843d7a Merge pull request #5588 from graydon/rdar-27397701-synthesized-get-set-typechecking-redux
Rdar 27397701 synthesized get set typechecking
2016-11-02 17:57:20 -07:00
Mark Lacey
3fd22c95fd Detect/prevent type variables from leaking across constraint systems.
It's possible some of the asserts will eventually migrate to something
like test-and-return, but at least for now let's ensure that we know
when this is happening.

This is not comprehensive. There are other places we are creating fresh
constraint systems and then creating constraints using type variables
from a pre-existing constraint systems.
2016-11-02 15:13:05 -07:00
Slava Pestov
f19ef79e4c Sema: Fix crash when substitution into generic typealias fails
Fixes <rdar://problem/29060933>.
2016-11-02 15:09:54 -07:00
John McCall
d123345689 Provide a frontend option to disable typo correction.
rdar://29003217
2016-11-02 14:08:56 -07:00
swift-ci
bfab9d607e Merge pull request #5608 from graydon/statistic-helpers 2016-11-02 12:14:26 -07:00
Graydon Hoare
3c551a773e [Compile perf] rdar://27397701 Typecheck synthetic accessors more lazily 2016-11-02 11:44:41 -07:00
Graydon Hoare
b3e5e805c1 [Compile perf] Add stats to TypeCheck{Type,Decl,Stmt}. 2016-11-02 10:01:36 -07:00
practicalswift
e9ff2b2374 [gardening] Fix recently introduced typos 2016-11-02 08:07:34 +01:00
Slava Pestov
4780b0bcdf AST: Introduce @_inlineable attribute
This attribute causes a function's body to be serialized, but unlike
@_transparent and @inline(__always), does not force it to be inlined.
2016-11-01 21:14:35 -07:00
Slava Pestov
f63dff16c7 AST: Don't allow @_transparent on extensions
Quiz: What does @_transparent on an extension actually *do*?

1) Make all members @_transparent?
2) Allow your members to be @_transparent?
3) Some other magical effect that has nothing to do with members?

The correct answer is 1), however a few places in the stdlib defined
a @_transparent extension and then proceeded to make some or all members
also @_transparent, and in a couple of places we defined a @_transparent
extension with no members at all.

To avoid cargo culting and confusion, remove the ability to make
@_transparent extensions altogether, and force usages to be explicit.
2016-11-01 21:14:09 -07:00
Mark Lacey
0471e10cb8 Merge pull request #5238 from xedin/SR-2164
SR-2164: Fix erroneous diagnostic when unable to infer generic parameter
2016-11-01 16:45:18 -07:00
Pavel Yaskevich
92b19fdb42 [Diagnostics] SR-2164: Fix erroneous diagnostic when unable to infer generic parameter
When trying to diagnose ambigiuty with constraint system check if any of the
unresolved type variables are related to generic parameters, and if so
try to diagnose a problem based on the number of constraints associated with
each of the unresolved generic parameters.

Number of constraints related to a particular generic parameter
is significant indicator of the problem, because if there are
no constraints associated with it, that means it can't ever be resolved,
such helps to diagnose situations like: struct S<A, B> { init(_ a: A) {}}
because type B would have no constraints associated with it.
2016-11-01 14:57:14 -07:00
Mark Lacey
93f9f8b696 Warn on string interpolation of optional lvalues.
We were only warning when the desugared type was an optional, without
first stripping off the lvalue-ness.

Resolves rdar://problem/27435494.
2016-11-01 14:43:01 -07:00
swift-ci
675f70e04f Merge pull request #5568 from DougGregor/allow-member-int-eq 2016-10-31 16:55:57 -07:00