Commit Graph

7976 Commits

Author SHA1 Message Date
Slava Pestov
0a179dbe2e Merge pull request #6492 from xedin/crasher-28505
[Diagnostics] Explicitly disallow solutions with unresolved types when diagnosing single expression closure bodies
2017-01-03 18:17:13 -08:00
Slava Pestov
822bb35946 Merge pull request #6497 from xedin/crasher-28497
[QoI] Ignore erroneous default literal types in lookup
2017-01-03 18:13:54 -08:00
Slava Pestov
bd53d2acd4 Merge pull request #6491 from xedin/crasher-28544
[TypeChecker] Fix isAnyHashableType to check type variables
2017-01-03 18:13:28 -08:00
Slava Pestov
87dd7221d0 Merge pull request #6489 from xedin/assign-crashers
[QoI] Allow computeAssignDestType to return UnresolvedType to facilitate diagnostics
2017-01-03 18:13:15 -08:00
Slava Pestov
b2941989dc Merge pull request #6539 from slavapestov/nested-type-lookup-derived-class
Sema: Fixes for generic typealiases and nested type lookup
2017-01-03 18:07:02 -08:00
Robert Widmann
9bb914a3a5 [SR-3523] Coercions that implicitly look through IUOs should not propagate
Force unwrapping the expression and propagating that type down to the
rest of the tree causes crashes when we go to request a different set
of protocols than we were expecting from it later.  Make this
transformation local to the apply instead.
2017-01-03 19:03:24 -07:00
Robert Widmann
adb862d40d [SR-3210] Closures aren't the only things that can implicitly capture variables
Capture checks were being elided inside of defer bodies because we
are using SourceLoc-based analyses on DeferStmt's, which generate
FuncDecls that have implicit bodies.  This resulted in a numberof
strange situations wherein declrefs could "time travel" backwards and be
captured before they were declared. Use the source location of
the defer's func's body to make sure we analyze them correctly.

This fix is brittle and should be replaced by ASTScope when such tech
becomes available.
2017-01-03 19:03:23 -07:00
Robert Widmann
3a4eb3f8ac Validate an assumption in 'lookupConstructors'
Invalid ASTs like the one in 28625 cause Parse to generate an AST that
looks a heck of a lot like a constructor call, however this makes no
sense as the type in question is a TupleType and lookup asserts in such
cases.  Guard against this so we don't crash diagnosing.
2017-01-03 19:03:23 -07:00
Robert Widmann
51dc142fca [28419] Extend nested init-chaining diagnostics to defer statements
This used to cause SILGen to capture and subsequently load `self` as a
constant.  Then, when the super call was SILGen’d, it assumed that
`self` would be loaded Boxed.  Diagnose before hitting SILGen so we
don’t have to pollute Lowering with code that handles `self` in this
odd position.
2017-01-03 18:53:06 -07:00
Robert Widmann
e36b52c25d Resolve some compiler crashers
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in #6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
2017-01-03 18:53:06 -07:00
swift-ci
861f52cdaf Merge pull request #6540 from DougGregor/sil-box-deserialization 2017-01-03 17:46:27 -08:00
Slava Pestov
a598ed68e6 Sema: Fixes for generic typealiases and nested type lookup
This patch contains several intertwined changes:

- Remove some unnecessary complexity and duplication.

- Adds a new TypeChecker::lookupUnqualifiedType() which bypasses most of
  the logic in TypeChecker::lookupUnqualified(), such as the
  LookupResultBuilder. Use this when resolving unqualified references
  to types.

- Fixes for generic typealiases to better preserve the type parameters of
  the parent type, and clean up the logic for applying the inner generic
  arguments. Some uses of generic typealiases that used to crash now work,
  and those tests have been uncommented.

- Avoid an unnecessary desugaring of TypeAliasDecls which map directly
  to GenericTypeParamTypes. Once again this perturbs the source-stability
  test.

- When looking up a nested type of a base class with a derived class base,
  always use the base class as the parent of the nested type. This fixes
  a recent regression where in some cases we were using the wrong parent.

Fixes <rdar://problem/29782186>.
2017-01-03 16:57:42 -08:00
Slava Pestov
cd4a1ebd1e Merge pull request #6536 from slavapestov/fix-objc-inference-regression
Sema: Fix recent regression where generic parameters were considered …
2017-01-03 16:01:15 -08:00
Slava Pestov
f130bb1975 Sema: Fix recent regression where generic parameters were considered to be representable in @objc
This would cause IRGen crashes since it had no way to emit type metadata
in this case.

Fixes <rdar://problem/29782437>.
2017-01-03 15:37:53 -08:00
Doug Gregor
2706904bf6 [SIL Box types] Handle box types with layouts with non-parameter requirements.
The handling of SIL box types in both deserialization and in the SIL
parser assumed that the number of substitutions in the box type would
be equivalent to the number of generic parameters. This assumption is
incorrect when the generic signature adds requirements to an
associated type.

Fixes rdar://problem/29740594.
2017-01-03 14:02:48 -08:00
Jordan Rose
4fbd3e6f29 Don't check availability for compound TypeReprs in Swift 3 mode.
Same as previous, but for availability. Again, it would be great
to get some follow-up work to make these into warnings instead of
just silencing them, but restoring source compatibility is the
first priority.

Rest of rdar://problem/29782505.
2017-01-03 13:14:23 -08:00
Jordan Rose
6dbcfc9f49 Don't check access for compound TypeReprs in Swift 3 mode.
Swift 3 just looked at what types we ended up with, not what types
we had to traverse to get there. Preserve this behavior for source
compatibility. (We ought to be able to warn, at least, but for now
getting source compatibility back is most important.)

Part of rdar://problem/29782505.
2017-01-03 13:14:23 -08:00
Doug Gregor
a2027957d8 [Type checker] Fix a use-after-free due to StringRefs stored in DiagnosticArguments.
DiagnosticArguments store a StringRef, rather than a
std::string. Passing a temporary string when creating a diagnostic,
and then holding on to the InFlightDiagnostic, means that the
StringRef will maintain a reference to a destroyed temporary string.

Dodge the issue locally by moving the string out to its own variable
with a longer lifetime, because only this diagnostic seems to
be affected. We should fix this architecturally later.
2017-01-03 11:02:36 -08:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Jacob Bandes-Storch
25cb143b8e [CSGen] handle ForceValueExpr in LinkedExprAnalyzer
The default behavior was looking *through* the ForceValueExpr, so in this test case the LinkedExprAnalyzer thought it was dealing with Optional<Double> rather than Double. Resolves SR-1122.
2017-01-01 02:36:51 -08:00
Robert Widmann
bde054aa75 [DiagnosticsQoI] Look through argument tuples when diagnosing conversion failures
This gives us much better diagnostics around things like
escaping-mismatched function parameters which would previously skip
this and produce bogus invalid conversion errors between “identical”
types.
2016-12-31 20:32:41 -07:00
Pavel Yaskevich
fac59ce4ee [Diagnostics] Improve diagnostics of self assignment of the anonymous closure parameters 2016-12-31 19:00:30 -08:00
Pavel Yaskevich
d37e93d3c2 [QoI] While merging equivalence classes don't forget to merge fixed types (if any)
Otherwise merging of the representative equivalence classes leaves constraint
system and graph disconnected, which might leave to incorrect solutions.
2016-12-31 01:29:04 -08:00
Pavel Yaskevich
130e5fb9df [QoI] Fix computeAssignDestType to mark lvalue enforcement type variable as materializable
Marking such type variable as "must be materializable" is going to explicitly
enforce the notion that assignment destination type can only be materializable
and situations like source expression is InOutExpr are incorrect.
2016-12-30 02:47:52 -08:00
Pavel Yaskevich
8c4b8715c6 [QoI] Fix recursive propagation of materializability to look through optional types
If T0 must be materializable and it's bound to T1, when matching T0 to
possibly optinal T1, look through optinality when setting materializability of the binding.
2016-12-29 22:55:12 -08:00
Pavel Yaskevich
b236244a4b [QoI] Don't try to type-check closure return statement if it involves unresolved parameters
If return expression uses closure parameters, which have/are
type variables, such means that we won't be be able to
type-check result correctly and, unfornutately,
we are going to leak type variables from the parent
constraint system through declaration types.
2016-12-28 02:15:11 -08:00
Pavel Yaskevich
db27ccff65 [QoI] Don't walk into erroneous apply expressions while validating top level code
In `checkTopLevelErrorHandling` if apply expression did not type-check,
don't attempt walking inside of it. This accounts for the fact that we don't
erase types without type variables to enable better code complication,
so DeclRefExpr(s) or ApplyExpr with DeclRefExpr as function contained
inside would have their types preserved, which makes classification
incorrect.
2016-12-27 21:29:23 -08:00
Pavel Yaskevich
4cc33978e0 [QoI] Ignore erroneous default literal types in lookup
There might be erroneous typealiases present which re-define literal types,
so when trying to type-check something that supposed to confirm to erroneous
redeclaration by default, ignore it.
2016-12-27 03:37:35 -08:00
Pavel Yaskevich
951395c5c5 [Diagnostics] Explicitly disallow solutions with unresolved types when diagnosing single expression closure bodies
When running diagnostics for single expression closures,
explicitly disallow to produce solutions with unresolved type variables,
because there is no auxiliary logic which would handle that and it's
better to allow failure diagnosis to run directly on the closure body.
2016-12-26 04:26:37 -08:00
Pavel Yaskevich
dab14d3759 [TypeChecker] Fix isAnyHashableType to check type variables
Currently isAnyHashableType method validates only structs but
it doesn't account for situation when type is represented via type
variable with type already fixed to AnyHashable, that results in
infinite loop in the solver because restriction [hashable-to-
anyhashable] is going to add new type variable recursively.
2016-12-26 01:16:56 -08:00
Pavel Yaskevich
047f7e092f [QoI] Allow computeAssignDestType to return UnresolvedType to facilitate diagnostics
Instead of returning empty type when RValue destination of the assignment
could not be determined, let's return it unresolved directly instead and
let it be handled by coerceToType, which is going to produce special expression
(UnresolvedTypeConversionExpression) which facilitates better diagnostics.
2016-12-24 18:05:07 -08:00
Pavel Yaskevich
f42fa362d1 [Diagnostics] Type-check return of the multi-statement closure without apply solutions
Obtain type of the result expression without applying solutions,
because otherwise this might result in leaking of type variables,
since we are not reseting result statement and if expression is
sucessfully type-checked its type cleanup is going to be disabled
(we are allowing unresolved types), and as a side-effect it might
also be transformed e.g. OverloadedDeclRefExpr -> DeclRefExpr.
2016-12-23 00:02:09 -08:00
practicalswift
d5046a6c4c [gardening] Make sure argument names in comments match the actual parameter names 2016-12-23 08:34:12 +01:00
Joe Groff
0c9297862f Sema: Handle type-checking for withoutActuallyEscaping.
withoutActuallyEscaping has a signature like `<T..., U, V, W> (@nonescaping (T...) throws<U> -> V, (@escaping (T...) throws<U> -> V) -> W) -> W, but our type system for functions unfortunately isn't quite that expressive yet, so we need to special-case it. Set up the necessary type system when resolving an overload set to reference withoutActuallyEscaping, and if a type check succeeds, build a MakeTemporarilyEscapableExpr to represent it in the type-checked AST.
2016-12-22 17:51:26 -08:00
Joe Groff
1889fde228 Resolve type(of:) by overload resolution rather than parse hackery.
`type(of:)` has behavior whose type isn't directly representable in Swift's type system, since it produces both concrete and existential metatypes. In Swift 3 we put in a parser hack to turn `type(of: <expr>)` into a DynamicTypeExpr, but this effectively made `type(of:)` a reserved name. It's a bit more principled to put `Swift.type(of:)` on the same level as other declarations, even with its special-case type system behavior, and we can do this by special-casing the type system we produce during overload resolution if `Swift.type(of:)` shows up in an overload set. This also lays groundwork for handling other declarations we want to ostensibly behave like normal declarations but with otherwise inexpressible types, viz. `withoutActuallyEscaping` from SE-0110.
2016-12-22 16:28:31 -08:00
Slava Pestov
ea547ca8e7 Merge pull request #6454 from rintaro/sema-cleanup-resolvepattern-callexpr
[NFC][TypeChecker] Simplify ResolvePattern::visitCallExpr()
2016-12-22 15:28:52 -05:00
Slava Pestov
f3f2cb233d AST: Refactor TypeBase::adjustSuperclassMemberDeclType() to use new SubstitutionMap::getOverrideSubstitutions() 2016-12-22 14:33:01 -05:00
Slava Pestov
ac7a3030e3 Sema: Fix inheritance of designated initializers with default arguments in generic context
We were dropping the substitutions required to call the default
argument generator on the floor, when the correct solution is to
remap them to substitutions in terms of the base class signature.

Fixes <rdar://problem/29721571>.
2016-12-22 14:33:01 -05:00
Slava Pestov
caa7045ae5 AST: Remove unnecessary ModuleDecl parameter from GenericSignature::getSubstitutions() 2016-12-22 14:33:00 -05:00
Doug Gregor
f7b5d9d69e [Type checker] Allow bridging conversions to more-optional types.
The prior formulation of bridging conversions allowed conversion to
more-optional types, e.g., converting an "NSDate" to "Date?", which
was broken by my recent refactoring in this area. Allow bridging
conversions to more-optional types by introducing extra optional
injections at the end.

Fixes rdar://problem/29780527.
2016-12-22 10:02:41 -08:00
swift-ci
323495f212 Merge pull request #6455 from modocache/ast 2016-12-22 06:15:44 -08:00
Slava Pestov
5df43ee871 Sema: Fix a warning 2016-12-22 06:39:43 -05:00
Brian Gesiak
52be53b141 [Sema] Remove obsolete comments
These two comments were added in 2013 and 2012, respectively, most
likely referring to a large patch of code below them. That code was
subsequently deleted in 2014 (0e00f513d).

Remove the obsolete comments, since the performance improvements they
describe can no longer be found in the same file.
2016-12-21 22:06:31 -05:00
Rintaro Ishizaki
49ea5e8b0b [TypeChecker] Simplify ResolvePattern::visitCallExpr(). NFC 2016-12-22 11:03:55 +09:00
Rintaro Ishizaki
808c05c6b1 Merge pull request #6381 from rintaro/sema-pattern-specialized-call
[TypeChecker] Don't convert specialzed call into EnumElement pattern
2016-12-22 11:02:48 +09:00
Doug Gregor
8afeadc5ee Merge pull request #6309 from DougGregor/as-coercions-bridging
[Type checker] Clean up as/as!/as?/is casting
2016-12-21 15:53:18 -08:00
Jordan Rose
32206a5523 Merge pull request #6332 from mxswd/pc-macro
Added a new AST Walker that instruments the AST to provide callbacks that simulate a program counter
2016-12-21 15:35:48 -08:00
practicalswift
d88c188d47 Merge pull request #6443 from practicalswift/argument-names
[gardening] Make sure argument names in comments match the actual parameter names
2016-12-21 23:25:29 +01:00
Maxwell Swadling
bcd6ee9f8d Moved ErrorFinder and ErrorGatherer to .cpp file 2016-12-21 14:23:37 -08:00
Maxwell Swadling
dffa8ec488 Removed implementation of doTypeCheck from header 2016-12-21 14:00:38 -08:00