Commit Graph

9116 Commits

Author SHA1 Message Date
Slava Pestov
18082b1b3f Sema: Don't set "validation started" bit on typealiases in the ITC
This appears to do nothing except cause a crash.
2017-06-06 23:56:33 -07:00
Slava Pestov
9e1f60d751 Sema: Skip an invalid kind of nested type in name lookup 2017-06-06 23:56:31 -07:00
swift-ci
af2aca0165 Merge pull request #10092 from xedin/pointer-conversions 2017-06-06 23:14:05 -07:00
swift-ci
8fbee40f92 Merge pull request #10150 from CodaFi/sugar-booger 2017-06-06 22:49:14 -07:00
Beta
09c3f8f33b Rewrite sugared optional tuple patterns 2017-06-06 22:25:20 -07:00
Mark Lacey
ea4e3e58f9 Merge pull request #10147 from rudkx/fix-rdar32570734
[Constraint solver] Do not allow unavailable decls to be favored.
2017-06-06 15:11:06 -07:00
Mark Lacey
65e338ea4a [Constraint solver] Do not allow unavailable decls to be favored.
There is a short-circuiting hack in the constraint solver that speeds up
solving, but isn't generally sound. If we allow unavailable decls to be
considered "favored", this can fire and result in our choosing a
solution that involves the unavailable decl where other solutions exist.

Fixes rdar://problem/32570734.
2017-06-06 13:38:36 -07:00
Slava Pestov
56b61ba758 Sema: Don't build ErrorTypes in simplifyType()
Instead, just build a new dependent member type with the
simplified base type.
2017-06-06 00:35:13 -07:00
Slava Pestov
1bd91dee5c Sema: Fix crash with unbound generic types in patterns 2017-06-06 00:35:02 -07:00
Slava Pestov
e5becab4ac Sema: Fix crashes when applying solution with error types or unresolved types 2017-06-05 23:50:30 -07:00
Slava Pestov
433b7f276e Sema: Fix bug with name lookup from initializers 2017-06-05 23:11:53 -07:00
Jordan Rose
485ebefba7 Merge pull request #10083 from jrose-apple/nscoding-diags-take-2
Update and re-enable the diagnostics for unstable runtime names
2017-06-05 19:51:01 -07:00
Jordan Rose
5c1967397b Update and re-enable the diagnostics for unstable runtime names.
This time, the warnings only fire when the class in question directly
conforms to NSCoding. This avoids warning on cases where the user has
subclassed something like, oh, UIViewController, and has no intention
of writing it to a persistent file.

This also removes the warning for generic classes that conform to
NSCoding, for simplicity's sake. That means
'@NSKeyedArchiverEncodeNonGenericSubclassesOnly' is also being
removed.

Actually archiving a class with an unstable mangled name is still
considered problematic, but the compiler shouldn't emit diagnostics
unless it can be sure they are relevant.

rdar://problem/32314195
2017-06-05 17:32:26 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Mark Lacey
8d41f45cce [Constraint solver] Access type map from a couple more places. 2017-06-05 15:17:55 -07:00
Mark Lacey
2793d06bdf [Constraint solver] Fix up CSDiag.cpp to use the type map.
Update CSDiag.cpp to use the constraint system's type map instead of
directly reading types from expressions.

As with past commits, the type map is not really enabled yet since we
still write types directly into expressions in the constraint solver.
2017-06-03 17:27:20 -07:00
Pavel Yaskevich
3559047340 [ConstraintSolver] Unify value-to-pointer conversion scoring
Instead of having three different scores for - string, array, inout,
let's unify them under a single value-to-pointer score and use
it in appropriate places when simplifying restricted constraints.
2017-06-02 23:42:32 -07:00
swift-ci
904ef73489 Merge pull request #10062 from xedin/rdar-32431165 2017-06-02 19:44:00 -07:00
Pavel Yaskevich
2d8dca0266 [QoI] Improve diagnostic for raw representable argument mismatch
Covers some common situations when switching from literal types e.g.
string or int to more Swift Way of raw representable enum of choices.

Resolves: rdar://problem/32431165, rdar://problem/31977537, rdar://problem/32432253
2017-06-02 18:22:23 -07:00
Dave Abrahams
3a7a30a822 Merge pull request #10059 from apple/utf16-small-character
[stdlib] Encode small Characters as UTF-16
2017-06-02 11:49:40 -07:00
Mark Lacey
567c9656f2 Merge pull request #10069 from rudkx/more-type-map-changes
[Constraint solver] More type map changes.
2017-06-02 10:42:46 -07:00
swift-ci
20f6664f96 Merge pull request #10070 from apple/objc-inference-warnings-cleanup 2017-06-02 09:11:51 -07:00
Doug Gregor
c96da6800a [Type checker] Warn deprecated @objc used to satisfy protocol requirements.
Warn about uses of declarations which have inferred @objc due to the
deprecated Swift 3 rules when the declarations are used to satisfy a
requirement of an @objc protocol. This covers cases where the @objc
cannot be inferred due to the conformance, e.g., when the declaration
itself is in a superclass but a subclass is stating the conformance.
Fixes rdar://problem/32431838.
2017-06-02 08:41:48 -07:00
Mark Lacey
d1a0b35447 [Constraint solver] More type map changes.
A few more changes to use the side map for expression types in the
constraint solver. Still not enabled.
2017-06-02 08:13:57 -07:00
Dave Abrahams
2778dc85ea Add and use _ExpressibleByBuiltinUTF16ExtendedGraphemeClusterLiteral 2017-06-02 07:01:03 -07:00
Slava Pestov
df1bedc6f8 Merge pull request #10061 from slavapestov/some-conditional-cf-casts-unconditionally-succeed
Some conditional CF casts unconditionally succeed
2017-06-01 23:50:29 -07:00
swift-ci
5d395d9ee4 Merge pull request #10049 from DougGregor/gsb-superclass 2017-06-01 23:07:42 -07:00
Doug Gregor
4fbb3ec611 [GSB] Resolve nested types by looking into superclass constraints.
This was previously handled very late, by the type checker, which led
to weird ordering dependencies and meant that we could end up with
well-formed code where the GSB was left with unresolved types. We want
such states to never exist, so make sure we can resolve everything in
the GSB.
2017-06-01 22:29:46 -07:00
Pavel Yaskevich
9a4255e4bf Merge pull request #9717 from xedin/rdar-32034560
[ConstraintSystem] Prevent `shrink` from solving "too complex" sub-expressions
2017-06-01 21:47:47 -07:00
Slava Pestov
b639f7fd83 Sema: Fix conditional downcasts from Swift types to CF types
Conditional and forced downcasts enter a constraint that almost
always succeeds; only when applying the solution do we evaluate
the feasability of the cast and determine if it always succeeds,
always fails, or conditionally succeeds. This changes how the
resulting AST is represented and can also emit diagnostics.

If the conditional cast is at this stage determined to always
succeed, we treat it as an unconditional cast, going through
ExprRewriter::coerceToType() to build the AST for the coercion.

However conditional cast constraints don't enter the same
restrictions into the solution as unconditional casts do, so
coerceToType() would fall over if casting a Swift type to a CF
type by first bridging the Swift type to Objective-C.

Get around this by checking for this case explicitly when
lowering a CoerceExpr.

It feels like there's a more fundamental issue here with how
casts are modeled in the constraint solver, but I'm not going
to try understanding that now.

Fixes <rdar://problem/32227571>.
2017-06-01 21:44:07 -07:00
Mark Lacey
5bcf8a9067 Merge pull request #10058 from rudkx/clear-opaque-expr-on-open-existential
[Constraint solver] Fix an issue with rewriting OpenExistentialExpr.
2017-06-01 20:54:20 -07:00
Mark Lacey
fb5ac6df02 [Constraint solver] Fix an issue with rewriting OpenExistentialExpr.
If we fail when doing a coercion while generating an OpenExistentialExpr
when applying a solution during type checking, make sure that the opaque
value on that OpenExistentialExpr is cleared.

We do not visit these during normal AST walks because they normally
appear in the subexpression held by the OpenExistentialExpr. In this
case, however, we replace that subexpression with an ErrorExpr which
means we will not visit the opaque value at all, so certain operations,
like setting the type on the opaque value, will never happen, and we can
run into problems later by code that assumes the type is set.

It seems reasonable to just clear these out in cases like this since
they are not reachable by any normal means.
2017-06-01 20:18:29 -07:00
Jordan Rose
63bc717963 Error when one associated type is constrained to another. (#10053)
(...is constrained to be a subtype of another)

Previously the compiler would just mark the entry in the inheritance
clause invalid and move on without emitting any errors; in certain
circumstances in no-asserts builds this could actually lead to
everything working "correctly" if all conforming types happened to
pick the same concrete type for both associated types. In Swift 4 this
can actually be enforced with a same-type requirement, which will
guarantee that the two associated types are the same even in generic
contexts.

This fix avoids assertions and crashes, but the diagnostic is still
incorrect, and in the simple case of the inheritance clause it's
redundant. Doing something better and possibly even downgrading it to
a warning in Swift 3 mode is tracked by rdar://problem/32409449.

Initial patch by Slava, fixed up by me.
2017-06-01 19:45:34 -07:00
Pavel Yaskevich
5998cd645f [ConstraintSolver] Penalize conversions from String to UnsafePointer
There are possible situations when we find solutions with String
and String -> UnsafePointer conversions at the same time for
expressions with default string literals. In order to disambiguite
such situations let's prefer solutions without String -> UnsafePointer
conversions if possible.
2017-06-01 14:43:43 -07:00
Pavel Yaskevich
1bc7a1edb9 [ConstraintSolver] Skip generic overloads only if non-generic choices produce higher score solutions
Restrict skipping of the generic overloads only to the situations
when non-generic solution doesn't have any restrictions/fixes, because
there is a possibility that generic overload could produce a better
solution.

Resolves: rdar://problem/32204609.
2017-06-01 14:43:43 -07:00
Pavel Yaskevich
f09d2ad397 [ConstraintSolver] Forbid forming solutions with free generic type parameters
`FreeTypeVariableBinding::GenericParameters` mode allowed to bind
all free type variables with fresh generic parameter types, which
is incorrect (at least) if there are multiple generic solutions
present, because such parameters couldn't be compared.

This mode was used for code completion, which is now switched to use
`FreeTypeVariableBinding::UnresolvedType` instead.
2017-06-01 14:05:05 -07:00
Doug Gregor
899e68ef09 [GSB] Generalize potential archetype from "typealias" to all concrete types.
Potential archetypes can resolve to either an associated type or a
typealias. Generalize the latter to "any concrete type", both because
the current implementation is unnecessarily narrow (typealiases aren't
actually special in this regard) and to get us closer to handling
lookups via superclass constraints when resolving these types.
2017-06-01 13:52:39 -07:00
Pavel Yaskevich
c5f73c369f Merge pull request #10026 from xedin/rdar-32432145
[Diagnostics] Suggest removing anonymous closure parameters if none are expected
2017-06-01 00:17:55 -07:00
Pavel Yaskevich
b755960e82 [Diagnostics] Suggest removing anonymous closure parameters if none are expected
If the contextual closure type expects no parameters but N
parameters where used and all of the them are anonymous, let's
suggest removing them.

Resolves: rdar://problem/32432145
2017-05-31 23:59:34 -07:00
Slava Pestov
6526d513c0 Sema: Remove the 'extraFunctionAttrs' hack 2017-05-31 17:31:37 -07:00
Slava Pestov
2119ab2782 Sema: A call of a closure literal is noescape
We cannot model a type variable bound to the ExtInfo of a function
type in the constraint solver, which means we have a hard time
propagating noescape-ness in some cases.

Fixes <rdar://problem/31910280> and <rdar://problem/32409133>.
2017-05-31 17:31:36 -07:00
Robert Widmann
9acac0764f Merge pull request #9997 from CodaFi/measure-twice-cut-once
Add a size heuristic to the Space Engine
2017-05-31 15:44:28 -07:00
Robert Widmann
bffa22a5c9 Add a size heuristic to the Space Engine
<rdar://32480026>

This is a particularly tricky tradeoff to have to make here.  On the one
hand, we want diagnostics about incomplete patterns to provide as much
information as possible.  On the other, pattern matrices grow
quasi-factorially in the size of the argument.  That is, an enum with 10
cases that is switched on as a 2-tuple/argument list creates a total
subspace covering of size 100.  For sufficiently large inputs, this can
DOS the Swift compiler.

It is simply not useful to present more than about 100 notes to the
user, nor is it useful to waste an enormous amount of time trying to
compute these subspaces for the limited information the diagnostic will
provide.  Instead, short circuit if the size of the enum is above some
arbitrary threshold (currently 128) and just offer to add a 'default'.

Notably, this change is not *technically* source compatible in that it
ignores the new '@_downgrade_exhaustivity_check'. However to hit up
against this heuristic would require the user to be switching over four
DispatchTimeIntervals in a quadruple or using an equivalently-sized
enormous enum case.  At which point we're hitting on the very reason
this heuristic exists.

There are definitely other, more informative, paths that we can take
here.  GHC, for example, seems to run a highly limited form of space
subtraction when the input space is too large, and simply reports the
top 3 missing cases along with some ellipses.  For now, I just want to
cut off this hang in the compiler.
2017-05-31 14:07:07 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Pavel Yaskevich
fea7bcf232 [ConstraintSystem] Prevent shrink from solving "too complex" sub-expressions
Add additional checking for complexity of the shrinking candidate
given the number of the expressions solved so far and total number
of disjunctions present. This allows us to bail quicker in complex
expression cases which, at the very least, produces an error instead
of being "stuck" in solver for a long time.

Resolves: rdar://problem/32034560
2017-05-31 13:54:43 -07:00
Mark Lacey
fdc55395f2 Merge pull request #9928 from rudkx/type-map
[Constraint solver] More type map updates.
2017-05-31 09:07:53 -07:00
Alex Hoppen
930ffdacff Remove implicit conversion from DeclBaseName to Identifier
This conversion just existed to aid migration from Identifier to
DeclBaseName and is no longer needed. It will technically not even be
correct once special names are introduced.
2017-05-31 16:02:00 +02:00
Alex Hoppen
ece660fad8 Remove getName from ValueDecl
Push the getName method from ValueDecl down to only those types that are
guaranteed to have a name that is backed by an identifier and that will
not be special.
2017-05-31 16:00:47 +02:00
Alex Hoppen
faa1720c48 [Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with
DeclBaseNames so that the implicit conversion from DeclBaseName to
Identifier is no longer needed.

Adjust the call side of diagnostics which don't have to deal with
special names to pass an Identifier to the diagnostic.
2017-05-31 15:58:46 +02:00
Mark Lacey
12926eb667 [Constraint solver] More type map updates.
More updates to read and write types from a side table in the constraint
solver and only write back into expressions when we've finished type
checking an expression.

We still write directly into expressions, and will continue to do so
until all of the code has been updated.
2017-05-31 00:36:09 -07:00