Commit Graph

566 Commits

Author SHA1 Message Date
Slava Pestov
ad01c1e929 SILGen: Implement missing function conversions from tuples to Any
Fixes <https://bugs.swift.org/browse/SR-3267> and
<rdar://problem/22465834>.
2017-01-03 19:05:40 -08:00
Slava Pestov
eb78182afb Merge pull request #6510 from xedin/crasher-28592
[QoI] Fix recursive propagation of materializability to look through optional types
2017-01-03 18:58:16 -08:00
Slava Pestov
5da7e10434 Merge pull request #6481 from xedin/diagnose-closure-return
[Diagnostics] Type-check return of the multi-statement closure without applying solutions
2017-01-03 18:55:27 -08:00
Slava Pestov
4cb5aef3f7 Merge pull request #6511 from xedin/crasher-28586
[QoI] Fix computeAssignDestType to mark lvalue enforcement type variable as materializable
2017-01-03 18:53:55 -08:00
Slava Pestov
00c1947b43 Merge pull request #6501 from xedin/crasher-28520
[QoI] Don't walk into erroneous apply expressions while validating top level code
2017-01-03 18:51:00 -08:00
Slava Pestov
d1b1361321 Merge pull request #6504 from CodaFi/crash-AAAAAHHH
Resolve some compiler crashers
2017-01-03 18:37:53 -08:00
Pavel Yaskevich
fb3515382c [Diagnostics] When checking AssignExpr properly diagnose destination
Currently if destination is unresolved instead of trying to re-typecheck
it again and diagnose structural problems which led to such outcome, it
gets completely ignored in favor of trying to type-check source without
contextual type. That leads to missed diagnostic opportunities, which
results in problems on AST verification and SIL generation stages, and
generally missleading errors e.g. `.x = 0`.

Resolves: SR-3506.
2017-01-03 18:22:33 -08:00
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
Robert Widmann
c20e012b66 [28396] Remove an assert that is too strict.
Recursive references of computed properties are allowed, but warned
about.  Closures `var`s built like the one in 28396 should crash at
runtime, not crash the compiler.
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
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
practicalswift
a26254b955 Mark as fixed. 2016-12-29 10:42:02 +01:00
practicalswift
5022c25ebb Mark as fixed. 2016-12-29 10:40:50 +01: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
3a61fba6e5 [Diagnostics] Mark all closure result type-checking related crashers as fixed 2016-12-24 03:34:47 -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
f5f7064eb9 [gardening] Remove asserts from fixed crashers. 2016-12-21 21:17:06 +01:00
Slava Pestov
1cb656314b Sema: Fix crash with unresolved 'is' pattern 2016-12-21 14:20:28 -05:00
Slava Pestov
dc3af8fc99 Sema: Don't re-typecheck multi-statement closures in lazy var initializer
Normally you have to declare a type if the lazy property
initializer is a multi-statement closure, but if the user
forgets we don't want to crash.
2016-12-21 14:20:28 -05:00
Slava Pestov
c0d506c82c Sema: Fix CSDiag's save/restore logic for decls with no type 2016-12-21 14:20:27 -05:00
Slava Pestov
f0f1c60a53 Sema: Fix crash with invalid @objc operators
The corner case of all corner cases.
2016-12-21 14:20:27 -05:00
Slava Pestov
09dd5fec84 Sema: Small fixes 2016-12-21 14:20:27 -05:00
Slava Pestov
978941f1d5 Sema: More consistent logic for non-requirement protocol members 2016-12-21 14:20:27 -05:00
Slava Pestov
3f7a72eb84 Sema: Clean up diagnostic logic when deriving RawRepresentable conformance on enums 2016-12-21 14:20:26 -05:00
Slava Pestov
7fed7b49ed Sema: Maintain invariant that invalid FuncDecls always have an ErrorType
Otherwise, overload resolution and CSDiag disagree on what a viable
candidate is, so we can end up in a situation where the OverloadDeclRefExpr
has a concrete type that doesn't match the argument list in an ApplyExpr,
which causes a crash in CSDiag.
2016-12-21 14:20:26 -05:00
practicalswift
8ee628fb14 Merge pull request #6408 from practicalswift/gardening-20161220
[gardening] Remove "REQUIRES: asserts". Correct Swift URL. Typos. Headers. PEP-8.
2016-12-20 18:47:42 +01:00
practicalswift
213716fb96 [gardening] Remove "REQUIRES: asserts" from fixed crashers 2016-12-20 10:06:14 +01:00
Slava Pestov
5640339439 Sema: Map types out of context when resolving inheritance clause in ITC 2016-12-19 18:49:57 -08:00
Slava Pestov
303f4bd19e Sema: resolveTypeInContext() checks all parent contexts first 2016-12-19 18:49:57 -08:00
Slava Pestov
ed19f2cbe9 AST: Fix gatherAllSubstitutions() for recent change to not adopt archetypes from context
This could lead to verifier failures on invalid nesting of
generic types in generic functions.
2016-12-19 18:49:57 -08:00
Slava Pestov
bb839c5fef Sema: Remove a couple of workarounds 2016-12-19 01:38:23 -08:00
Slava Pestov
4ed17f0f63 AST: Add a new 'isBeingValidated' flag to replace a couple of other flags
Previously, validateDecl() would check if the declaration had an
interface type and use that as an indication not to proceed.

However for functions we can only set an interface type after
checking the generic signature, so a recursive call to validateDecl()
on a function would "steal" the outer call and complete validation.

For generic types, this meant we could have a declaration with a
valid interface type but no generic signature.

Both cases were problematic, so narrow workarounds were put in
place with additional new flags. This made the code harder to
reason about.

This patch consolidates the flags and establishes new invariants:

- If validateDecl() returns and the declaration has no interface
  type and the isBeingValidated() flag is not set, it means one
  of the parent contexts is being validated by an outer recursive
  call.

- If validateDecl() returns and the declaration has the
  isBeingValidated() flag set, it may or may not have an interface
  type. In this case, the declaration itself is being validated
  by an outer recursive call.

- If validateDecl() returns and the declaration has an interface
  type and the isBeingValidated() flag is not set, it means the
  declaration and all of its parent contexts are fully validated
  and ready for use.

In general, we still want name lookup to find things that have an
interface type but are not in a valid generic context, so for this
reason nominal types and associated types get an interface type as
early as possible.

Most other code only wants to see fully formed decls, so a new
hasValidSignature() method returns true iff the interface type is
set and the isBeingValidated() flag is not set.

For example, while resolving a type, we can resolve an unqualified
reference to a nominal type without a valid signature. However, when
applying generic parameters, the hasValidSignature() flag is used
to ensure we error out instead of crashing if the generic signature
has not yet been formed.
2016-12-19 01:38:23 -08:00
Slava Pestov
45ef0f5dfb Sema: Generic types cannot witness associated type requirements
Until recently we didn't allow nested generic types at all.
In Swift 3, generic typealiases were added, and we forgot to
guard against them in witness matching, leading to a crash if
a generic typealias witnesses an associated type requirement.

Now that nested generic nominals are allowed too, add a check.

The diagnostic is not very good, but I'll revisit this later.
2016-12-18 22:34:16 -08:00
Slava Pestov
86d3828ea0 Sema: Don't recurse into validateDecl() when adding Objective-C bridgeable conformances
This catches another case where resolveType() could cause infinite
recursion. No test case, but this prevents crashers from regressing
with a subsequent patch.
2016-12-18 22:34:15 -08:00
Pavel Yaskevich
38165e266c [QoI] Strip BindOptionalExpr from assignment that discards target
Right before generating constraints for the new system,
check if there are any BindOptionalExpr in the tree which
wrap DiscardAssignmentExpr, such situation corresponds to syntax
like - `_? = <value>`, since it doesn't really make
sense to have optional assignment to discarded LValue which can
never be optional, we can remove BOE from the tree and avoid
generating any of the uncessary constraints.
2016-12-18 14:28:27 -08:00
Slava Pestov
88b54dcf51 AST: More consistent behavior of Type::subst() with missing substitutions
When SubstFlags::UseErrorTypes was on, we would return error types
if we couldn't resolve a nested type, but a missing primary parameter
would always remain unsubstituted in the result.

Now, replace primary parameters with error types also if they're
missing.
2016-12-17 16:28:19 -08:00
practicalswift
8fbcb94369 [gardening] Mark as crashing only under OS X 2016-12-17 22:33:09 +01:00
practicalswift
d02b5c5a38 [gardening] Remove "REQUIRES: no_asan" since crash case is marked fixed.
If it turns out that this crasher still needs "REQUIRES: no_asan" then it
isn't fixed and should be moved back to validation-test/compiler_crashers/
and marked with "not --crash" + "REQUIRES: asan" :-)
2016-12-17 22:33:09 +01:00
practicalswift
fe7c70f735 [gardening] Rename crasher to achieve consistent naming 2016-12-17 22:33:09 +01:00
practicalswift
8250854c21 [gardening] Re-enable fixed crasher 27618-swift-modulefile-getimportedmodules.swift 2016-12-17 22:33:09 +01:00