Commit Graph

1575 Commits

Author SHA1 Message Date
Slava Pestov
c7ab11f228 Sema: Fix crash in 'var' parameter migration 2017-01-03 23:40:44 -08:00
Slava Pestov
e6ada30291 Parse: Fix crash when alignment is too large 2017-01-03 23:40:44 -08:00
Slava Pestov
32ebe2db5a Parse: Don't crash if property with no declared type has addressors 2017-01-03 23:40:44 -08:00
Slava Pestov
8f96606cb2 Sema: Remove TupleToScalar conversion, which did nothing useful except crash
As far as I can tell there's no way to trigger this from valid code.
2017-01-03 23:00:07 -08:00
Slava Pestov
f19cbef54d Sema: Try harder not to perform lookups into tuple types 2017-01-03 23:00:07 -08:00
Slava Pestov
9f30532641 Sema: Fix closeExistential() in CSApply with invalid direct call of metatype
When we have a value 'p' of type 'P.Type' for some protocol 'P',
we require the user to write 'p.init()' rather than 'p()' to
construct an instance of a concrete type conforming to 'P'.

If they write 'p()', we suggest a fixit to insert '.init',
however if there is also a subsequent member access on the
result, for example 'p().foo', we would crash.

Another invalid case that used to crash is when you construct
a protocol metatype directly and then access a member of it,
eg. 'P().foo'.
2017-01-03 21:28:11 -08:00
Slava Pestov
2c7aae4128 Sema: 'Never'-returning functions can be represented in Objective-C
Fixes <https://bugs.swift.org/browse/SR-3203>.
2017-01-03 20:13:42 -08:00
Slava Pestov
88ecaad180 Merge pull request #6543 from slavapestov/small-silgen-fixes
Fixes for assorted SILGen bugs
2017-01-03 19:48:10 -08:00
Slava Pestov
7258861d73 Merge pull request #6515 from xedin/crasher-28588
[QoI] While merging equivalence classes don't forget to merge fixed types (if any).
2017-01-03 19:35:47 -08:00
Slava Pestov
a8da5b8d80 Merge pull request #6514 from xedin/SR_3506
[Diagnostics] When checking AssignExpr properly diagnose destination
2017-01-03 19:24:52 -08:00
Slava Pestov
dfed050794 Merge pull request #6505 from practicalswift/mark-as-fixed
Mark two disabled and previously non-deterministic crashers as fixed
2017-01-03 19:14:52 -08:00
Slava Pestov
5f9fe6fa2c SILGen: Fix crash with non-scalar casts requiring re-abstraction
This might only come up in invalid code, but for example
casting a function type to String would trigger it.
2017-01-03 19:05:41 -08:00
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
053ca89ba4 Merge pull request #6476 from practicalswift/swiftc-28595-typeincontext-isnull-no-contextual-type-set-yet
[swiftc (83 vs. 5325)] Add crasher in swift::TypeChecker::checkAutoClosureAttr
2017-01-03 18:57:48 -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
88a06fb541 Use annotation "REQUIRES: deterministic-behavior" 2016-12-29 10:45:41 +01: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
0936c51a96 [swiftc (83 vs. 5325)] Add crasher in swift::TypeChecker::checkAutoClosureAttr
Add test case for crash triggered in `swift::TypeChecker::checkAutoClosureAttr`.

Current number of unresolved compiler crashers: 83 (5325 resolved)

/cc @slavapestov - just wanted to let you know that this crasher caused an assertion failure for the assertion `!typeInContext.isNull() && "no contextual type set yet"` added on 2016-12-15 by you in commit 757f253a3 :-)

Assertion failure in [`include/swift/AST/Decl.h (line 4121)`](https://github.com/apple/swift/blob/master/include/swift/AST/Decl.h#L4121):

```
Assertion `!typeInContext.isNull() && "no contextual type set yet"' failed.

When executing: swift::Type swift::VarDecl::getType() const
```

Assertion context:

```
  }

  /// Get the type of the variable within its context. If the context is generic,
  /// this will use archetypes.
  Type getType() const {
    assert(!typeInContext.isNull() && "no contextual type set yet");
    return typeInContext;
  }

  /// Set the type of the variable within its context.
  void setType(Type t);
```
Stack trace:

```
0 0x0000000003500d48 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/path/to/swift/bin/swift+0x3500d48)
1 0x0000000003501486 SignalHandler(int) (/path/to/swift/bin/swift+0x3501486)
2 0x00007f6d5d5143e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113e0)
3 0x00007f6d5bc42428 gsignal /build/glibc-Qz8a69/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
4 0x00007f6d5bc4402a abort /build/glibc-Qz8a69/glibc-2.23/stdlib/abort.c:91:0
5 0x00007f6d5bc3abd7 __assert_fail_base /build/glibc-Qz8a69/glibc-2.23/assert/assert.c:92:0
6 0x00007f6d5bc3ac82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
7 0x0000000000ce3665 swift::TypeChecker::checkAutoClosureAttr(swift::ParamDecl*, swift::AutoClosureAttr*) (/path/to/swift/bin/swift+0xce3665)
8 0x0000000000ce2e47 swift::TypeChecker::checkTypeModifyingDeclAttributes(swift::VarDecl*) (/path/to/swift/bin/swift+0xce2e47)
9 0x0000000000d325ba swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&) (/path/to/swift/bin/swift+0xd325ba)
10 0x0000000000d2c43a checkGenericFuncSignature(swift::TypeChecker&, swift::ArchetypeBuilder*, swift::AbstractFunctionDecl*, swift::GenericTypeResolver&) (/path/to/swift/bin/swift+0xd2c43a)
11 0x0000000000d2b79e swift::TypeChecker::validateGenericFuncSignature(swift::AbstractFunctionDecl*) (/path/to/swift/bin/swift+0xd2b79e)
12 0x0000000000d1615b (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) (/path/to/swift/bin/swift+0xd1615b)
13 0x0000000000d05c00 (anonymous namespace)::DeclChecker::visit(swift::Decl*) (/path/to/swift/bin/swift+0xd05c00)
14 0x0000000000d13bbb (anonymous namespace)::DeclChecker::visitProtocolDecl(swift::ProtocolDecl*) (/path/to/swift/bin/swift+0xd13bbb)
15 0x0000000000d05be0 (anonymous namespace)::DeclChecker::visit(swift::Decl*) (/path/to/swift/bin/swift+0xd05be0)
16 0x0000000000d059c3 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) (/path/to/swift/bin/swift+0xd059c3)
17 0x0000000000c1e1b5 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) (/path/to/swift/bin/swift+0xc1e1b5)
18 0x0000000000992086 swift::CompilerInstance::performSema() (/path/to/swift/bin/swift+0x992086)
19 0x000000000047c5aa swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/path/to/swift/bin/swift+0x47c5aa)
20 0x000000000043ade7 main (/path/to/swift/bin/swift+0x43ade7)
21 0x00007f6d5bc2d830 __libc_start_main /build/glibc-Qz8a69/glibc-2.23/csu/../csu/libc-start.c:325:0
22 0x0000000000438229 _start (/path/to/swift/bin/swift+0x438229)
```
2016-12-22 21:52:29 +01:00
practicalswift
9901be4c30 [swiftc (82 vs. 5325)] Add crasher in swift::Decl::walk(...)
Add test case for crash triggered in `swift::Decl::walk(...)`.

Current number of unresolved compiler crashers: 82 (5325 resolved)

Stack trace:

```
0 0x0000000003500d48 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/path/to/swift/bin/swift+0x3500d48)
1 0x0000000003501486 SignalHandler(int) (/path/to/swift/bin/swift+0x3501486)
2 0x00007f754ae433e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113e0)
3 0x00007f7549571428 gsignal /build/glibc-Qz8a69/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
4 0x00007f754957302a abort /build/glibc-Qz8a69/glibc-2.23/stdlib/abort.c:91:0
5 0x0000000000dfa284 (anonymous namespace)::Verifier::verifyChecked(swift::VarDecl*) (/path/to/swift/bin/swift+0xdfa284)
6 0x0000000000ded97e (anonymous namespace)::Verifier::walkToDeclPost(swift::Decl*) (/path/to/swift/bin/swift+0xded97e)
7 0x0000000000dfca39 (anonymous namespace)::Traversal::doIt(swift::Decl*) (/path/to/swift/bin/swift+0xdfca39)
8 0x0000000000e00977 (anonymous namespace)::Traversal::visit(swift::Pattern*) (/path/to/swift/bin/swift+0xe00977)
9 0x0000000000dfc754 (anonymous namespace)::Traversal::doIt(swift::Decl*) (/path/to/swift/bin/swift+0xdfc754)
10 0x0000000000e01594 (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) (/path/to/swift/bin/swift+0xe01594)
11 0x0000000000dfc44b (anonymous namespace)::Traversal::doIt(swift::Decl*) (/path/to/swift/bin/swift+0xdfc44b)
12 0x0000000000dfc354 swift::Decl::walk(swift::ASTWalker&) (/path/to/swift/bin/swift+0xdfc354)
13 0x0000000000e5546e swift::SourceFile::walk(swift::ASTWalker&) (/path/to/swift/bin/swift+0xe5546e)
14 0x0000000000de44e5 swift::verify(swift::SourceFile&) (/path/to/swift/bin/swift+0xde44e5)
15 0x0000000000c1e383 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) (/path/to/swift/bin/swift+0xc1e383)
16 0x0000000000992086 swift::CompilerInstance::performSema() (/path/to/swift/bin/swift+0x992086)
17 0x000000000047c5aa swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/path/to/swift/bin/swift+0x47c5aa)
18 0x000000000043ade7 main (/path/to/swift/bin/swift+0x43ade7)
19 0x00007f754955c830 __libc_start_main /build/glibc-Qz8a69/glibc-2.23/csu/../csu/libc-start.c:325:0
20 0x0000000000438229 _start (/path/to/swift/bin/swift+0x438229)
```
2016-12-22 21:01:39 +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