Commit Graph

4289 Commits

Author SHA1 Message Date
practicalswift
a5ae8a5423 [swiftc (21 vs. 5389)] Add crasher in swift::NewMangling::Mangler::appendIdentifier(...)
Add test case for crash triggered in `swift::NewMangling::Mangler::appendIdentifier(...)`.

Current number of unresolved compiler crashers: 21 (5389 resolved)

/cc @eeckstein - just wanted to let you know that this crasher caused an assertion failure for the assertion `!isDigit(ident[Pos]) && "first char of sub-string may not be a digit"` added on 2016-12-02 by you in commit 684092d7 :-)

Assertion failure in [`include/swift/Basic/ManglingUtils.h (line 187)`](https://github.com/apple/swift/blob/master/include/swift/Basic/ManglingUtils.h#L187):

```
Assertion `!isDigit(ident[Pos]) && "first char of sub-string may not be a digit"' failed.

When executing: void swift::NewMangling::mangleIdentifier(Mangler &, llvm::StringRef) [Mangler = swift::NewMangling::Mangler]
```

Assertion context:

```
      // Mangle the sub-string up to the next word substitution (or to the end
      // of the identifier - that's why we added the dummy-word).
      // The first thing: we add the encoded sub-string length.
      M.Buffer << (Repl.StringPos - Pos);
      assert(!isDigit(ident[Pos]) &&
             "first char of sub-string may not be a digit");
      do {
        // Update the start position of new added words, so that they refer to
        // the begin of the whole mangled Buffer.
        if (WordsInBuffer < M.Words.size() &&
            M.Words[WordsInBuffer].start == Pos) {
```
Stack trace:

```
0 0x0000000003512118 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/path/to/swift/bin/swift+0x3512118)
1 0x0000000003512856 SignalHandler(int) (/path/to/swift/bin/swift+0x3512856)
2 0x00007f97fd01b3e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113e0)
3 0x00007f97fb749428 gsignal /build/glibc-Qz8a69/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
4 0x00007f97fb74b02a abort /build/glibc-Qz8a69/glibc-2.23/stdlib/abort.c:91:0
5 0x00007f97fb741bd7 __assert_fail_base /build/glibc-Qz8a69/glibc-2.23/assert/assert.c:92:0
6 0x00007f97fb741c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
7 0x0000000000efb1ec void swift::NewMangling::mangleIdentifier<swift::NewMangling::Mangler>(swift::NewMangling::Mangler&, llvm::StringRef) (/path/to/swift/bin/swift+0xefb1ec)
8 0x0000000000efa72d swift::NewMangling::Mangler::appendIdentifier(llvm::StringRef) (/path/to/swift/bin/swift+0xefa72d)
9 0x0000000000dcef51 swift::NewMangling::ASTMangler::appendDeclName(swift::ValueDecl const*) (/path/to/swift/bin/swift+0xdcef51)
10 0x0000000000dcbbc6 swift::NewMangling::ASTMangler::appendEntity(swift::ValueDecl const*, llvm::StringRef, bool) (/path/to/swift/bin/swift+0xdcbbc6)
11 0x0000000000dccb0e swift::NewMangling::ASTMangler::mangleGlobalVariableFull[abi:cxx11](swift::VarDecl const*) (/path/to/swift/bin/swift+0xdccb0e)
12 0x00000000006694b5 swift::Lowering::SILGenModule::getSILGlobalVariable(swift::VarDecl*, swift::ForDefinition_t) (/path/to/swift/bin/swift+0x6694b5)
13 0x000000000063a3e5 swift::Lowering::SILGenFunction::emitInitializationForVarDecl(swift::VarDecl*) (/path/to/swift/bin/swift+0x63a3e5)
14 0x000000000063c0a1 swift::ASTVisitor<(anonymous namespace)::InitializationForPattern, void, void, void, std::unique_ptr<swift::Lowering::Initialization, std::default_delete<swift::Lowering::Initialization> >, void, void>::visit(swift::Pattern*) (/path/to/swift/bin/swift+0x63c0a1)
15 0x000000000063b164 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) (/path/to/swift/bin/swift+0x63b164)
16 0x000000000063b2dd swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) (/path/to/swift/bin/swift+0x63b2dd)
17 0x000000000061e0ac swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) (/path/to/swift/bin/swift+0x61e0ac)
18 0x000000000061e96b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) (/path/to/swift/bin/swift+0x61e96b)
19 0x000000000061f95b swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) (/path/to/swift/bin/swift+0x61f95b)
20 0x000000000061ffb5 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) (/path/to/swift/bin/swift+0x61ffb5)
21 0x000000000047e7a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/path/to/swift/bin/swift+0x47e7a5)
22 0x000000000043ade7 main (/path/to/swift/bin/swift+0x43ade7)
23 0x00007f97fb734830 __libc_start_main /build/glibc-Qz8a69/glibc-2.23/csu/../csu/libc-start.c:325:0
24 0x0000000000438229 _start (/path/to/swift/bin/swift+0x438229)
```
2017-01-04 13:12:11 +01:00
practicalswift
ab56a69a1f [swiftc (20 vs. 5389)] Add crasher in swift::GenericSignature::enumeratePairedRequirements
Add test case for crash triggered in `swift::GenericSignature::enumeratePairedRequirements`.

Current number of unresolved compiler crashers: 20 (5389 resolved)

Assertion failure in `llvm/include/llvm/ADT/Optional.h (line 138)`:

```
Assertion `hasVal' failed.

When executing: T &&llvm::Optional<swift::ProtocolConformanceRef>::operator*() && [T = swift::ProtocolConformanceRef]
```

Assertion context:

```
    return hasValue() ? getValue() : std::forward<U>(value);
  }

#if LLVM_HAS_RVALUE_REFERENCE_THIS
  T&& getValue() && { assert(hasVal); return std::move(*getPointer()); }
  T&& operator*() && { assert(hasVal); return std::move(*getPointer()); }

  template <typename U>
  T getValueOr(U &&value) && {
    return hasValue() ? std::move(getValue()) : std::forward<U>(value);
  }
```
Stack trace:

```
0 0x0000000003512118 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/path/to/swift/bin/swift+0x3512118)
1 0x0000000003512856 SignalHandler(int) (/path/to/swift/bin/swift+0x3512856)
2 0x00007f07b159e3e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113e0)
3 0x00007f07afccc428 gsignal /build/glibc-Qz8a69/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
4 0x00007f07afcce02a abort /build/glibc-Qz8a69/glibc-2.23/stdlib/abort.c:91:0
5 0x00007f07afcc4bd7 __assert_fail_base /build/glibc-Qz8a69/glibc-2.23/assert/assert.c:92:0
6 0x00007f07afcc4c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
7 0x0000000000e4ee90 bool llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>::callback_fn<swift::GenericSignature::getSubstitutions(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>, llvm::SmallVectorImpl<swift::Substitution>&) const::$_3>(long, swift::Type, llvm::ArrayRef<swift::Requirement>) (/path/to/swift/bin/swift+0xe4ee90)
8 0x0000000000e4da41 swift::GenericSignature::enumeratePairedRequirements(llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>) const (/path/to/swift/bin/swift+0xe4da41)
9 0x0000000000e4dd26 swift::GenericSignature::getSubstitutions(llvm::DenseMap<swift::SubstitutableType*, swift::Type, llvm::DenseMapInfo<swift::SubstitutableType*>, llvm::detail::DenseMapPair<swift::SubstitutableType*, swift::Type> > const&, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>, llvm::SmallVectorImpl<swift::Substitution>&) const (/path/to/swift/bin/swift+0xe4dd26)
10 0x0000000000c29986 swift::constraints::Solution::computeSubstitutions(swift::Type, swift::DeclContext*, swift::Type, swift::constraints::ConstraintLocator*, llvm::SmallVectorImpl<swift::Substitution>&) const (/path/to/swift/bin/swift+0xc29986)
11 0x0000000000c30c90 (anonymous namespace)::ExprRewriter::buildMemberRef(swift::Expr*, swift::Type, swift::SourceLoc, swift::ValueDecl*, swift::DeclNameLoc, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder, bool, swift::FunctionRefKind, swift::AccessSemantics, bool) (/path/to/swift/bin/swift+0xc30c90)
12 0x0000000000c41461 swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) (/path/to/swift/bin/swift+0xc41461)
13 0x0000000000c2f774 (anonymous namespace)::ExprRewriter::walkToExprPost(swift::Expr*) (/path/to/swift/bin/swift+0xc2f774)
14 0x0000000000c35021 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) (/path/to/swift/bin/swift+0xc35021)
15 0x0000000000e0c387 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) (/path/to/swift/bin/swift+0xe0c387)
16 0x0000000000e0ad1b swift::Expr::walk(swift::ASTWalker&) (/path/to/swift/bin/swift+0xe0ad1b)
17 0x0000000000c2c268 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) (/path/to/swift/bin/swift+0xc2c268)
18 0x0000000000cf5433 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) (/path/to/swift/bin/swift+0xcf5433)
19 0x0000000000c5a791 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*, bool) (/path/to/swift/bin/swift+0xc5a791)
20 0x0000000000c63c40 (anonymous namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*, swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, swift::OptionSet<TCCFlags, unsigned int>) (/path/to/swift/bin/swift+0xc63c40)
21 0x0000000000c70920 (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) (/path/to/swift/bin/swift+0xc70920)
22 0x0000000000c567a3 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) (/path/to/swift/bin/swift+0xc567a3)
23 0x0000000000c4ec2a swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) (/path/to/swift/bin/swift+0xc4ec2a)
24 0x0000000000c55ced swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) (/path/to/swift/bin/swift+0xc55ced)
25 0x0000000000cf1ed8 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) (/path/to/swift/bin/swift+0xcf1ed8)
26 0x0000000000cf539d swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) (/path/to/swift/bin/swift+0xcf539d)
27 0x0000000000c0cf9e swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) (/path/to/swift/bin/swift+0xc0cf9e)
28 0x0000000000c0c7c6 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) (/path/to/swift/bin/swift+0xc0c7c6)
29 0x0000000000c21c70 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) (/path/to/swift/bin/swift+0xc21c70)
30 0x0000000000996736 swift::CompilerInstance::performSema() (/path/to/swift/bin/swift+0x996736)
31 0x000000000047c5aa swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/path/to/swift/bin/swift+0x47c5aa)
32 0x000000000043ade7 main (/path/to/swift/bin/swift+0x43ade7)
33 0x00007f07afcb7830 __libc_start_main /build/glibc-Qz8a69/glibc-2.23/csu/../csu/libc-start.c:325:0
34 0x0000000000438229 _start (/path/to/swift/bin/swift+0x438229)
```
2017-01-04 12:49:45 +01:00
Slava Pestov
3cbc08cc4e AST/SIL: Fix problems if protocol requirement signature makes Self : P conformance implicit
Fixes assertion failures in SILGen and the optimizer with this
exotic setup:

protocol P {
  associatedtype T : Q
}

protocol Q {
  func requirement<U : P>(u: U) where U.T == Self
}

Here, we only have a U : P conformance, and not Self : Q,
because Self : Q is available as U.T : Q.

There were three problems here:

- The SIL verifier was too strict in verifying the generic signature.
  All that matters is we can get the Self parameter conformance, not
  that it's the first requirement, etc.

- GenericSignature::getSubstitutionMap() had a TODO concerning handling
  of same-type constraints -- this is the first test-case I've found
  that triggered the problem.

- GenericEnvironment::getSubstitutionMap() incorrectly ignored
  same-type constraints where one of the two types was a generic
  parameter.

Fixes <https://bugs.swift.org/browse/SR-3321>.
2017-01-04 02:28:55 -08:00
Slava Pestov
412559af79 Add test cases for a few bugs that seem to be fixed already
Cleaning out some old JIRAs, don't want these to regress...
2017-01-04 02:02:29 -08:00
Slava Pestov
18adb53226 Sema: Tighten up name lookup routines to not look through metatypes/lvalues/etc
Previously all of the following would strip off varying amounts of
MetatypeType, LValueType, InOutType, DynamicSelfType, etc:

- ConstraintSystem::performMemberLookup()
- ConstraintSystem::lookupMember()
- TypeChecker::lookupMember()
- DeclContext::lookupQualified()
- Type::getContextSubstitutions()

The problem is that the higher level methods that took a lookup type
would call the lower level methods, and post-process the result using
the given lookup type. Since different levels of sugar were stripped,
it made the code hard to reason about and opened up edge cases, eg
if a DynamicSelfType or InOutType appears where we didn't expect it.

Since filtering out static/instance and mutating/nonmutating members
is done at higher levels, there's no reason for these name lookup
operations to accept anything other than nominal types, existentials
and archetypes.

Make this so with assertions, and deal with the fallout.
2017-01-04 01:40:19 -08:00
Slava Pestov
584f47d025 Sema: Fix crashes in CSDiag
- TypeMatchVisitor doesn't like seeing ErrorTypes -- stop if we have one.

- Common logic for replacing type parameters and variables with
  UnresolvedType.

- Fix crash in coerceToType() if one of the two types has an UnresolvedType
  in it, but not at the top level.

Fixes one compiler_crasher and some regressions with upcoming patches.
2017-01-04 01:40:19 -08:00
Slava Pestov
0a7e1d5568 Sema: Fix crash in conformance checking
Yeah, the repro is really just "class A : RangeReplaceableCollection { }".
2017-01-04 01:27:41 -07:00
Slava Pestov
e4abdfc2bd AST: Model protocols nested inside other types
We might allow protocols inside non-generic class/struct/enum
declarations eventually; there's no conceptual difficulty, just
some IRGen and Serialization work that has to happen first.

Also, this fixes a crasher :-)
2017-01-04 00:10:29 -08:00
Slava Pestov
2b05dd9d85 AST: Remove error path that was causing crashes 2017-01-04 00:10:28 -08:00
Slava Pestov
b6d8bbb698 AST: Return abstract conformance for UnresolvedType
We "fake" a conformance of UnresolvedType to any protocol.
Instead of returning a concrete conformance, return an
abstract conformance. The concrete conformance had several
problems leading to further crashes:

- The DC was set to a module, not a type declaration context,
  since there is not type declaration context here.

- The conformance was marked complete even though it was missing
  inherited conformances.
2017-01-04 00:10:28 -08:00
Slava Pestov
cc2ae7b7d5 AST: Fix crash with invalid generic environment 2017-01-04 00:10:28 -08:00
Slava Pestov
a230bde7e7 AST: Clean up getDeclaredType() and friends 2017-01-03 23:40:47 -08:00
Slava Pestov
e455085d94 Sema: When opening an UnboundGenericType, don't put replacements in the same map
When inserting a new value, assert that there's no existing
value at that key, and to avoid the assert firing when
opening up UnboundGenericTypes, put those replacements in
their own map. We don't need them later.
2017-01-03 23:40:46 -08:00
Slava Pestov
469cccdef1 Sema: Avoid infinite recursion in associated type inference 2017-01-03 23:40:46 -08:00
Slava Pestov
d406c4d002 ASTVerifier: Don't check Override attribute if we haven't done early attribute validation
If the 'override' attribute appears on an invalid decl,
it is removed at the start of typeCheckDecl(). However if
the decl is nested inside a multi-statement closure which
is invalid for other reasons, we may have validated it
but not type checked it, in which case we don't want to
crash in the verifier.
2017-01-03 23:40:45 -08:00
Slava Pestov
2932aac03a AST: More accurate AbstractFunctionDecl::getImplicitSelfDecl()
Now, the following are both true or both false:

- AFD->getDeclContext()->isTypeContext()
- AFD->getImplicitSelfDecl() != nullptr

Also, if var->isSelfParameter() returns true, then it is also
the case that var == var->getDeclContext()->getImplicitSelfDecl().
2017-01-03 23:40:45 -08:00
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
16820526b8 This test requires Objective-C interop 2017-01-03 22:22:14 -08:00
Slava Pestov
9b03f9d18c SILGen: Fix reabstraction thunk emission when generic parameters are made non-canonical
In a generic signature like <T, U where T.A == U>, there is only
one primary archetype, 'T'. 'U' will not appear in SubstitutionMaps,
and the SubstitutionMap version of Type::subst() cannot handle an
interface type containing 'U'.

For interface types, there are two levels of canonicalization:

- The AST-level getCanonicalType() which strips away sugar

- The GenericSignature-level getCanonicalTypeInContext() which
  replaces each interface type in an equivalence class with a
  representative

SILFunctionTypes must be canonical with respect to a generic
signature.

When emitting re-abstraction thunks we could end up constructing
a SILFunctionType containing 'U', because we were calling
getCanonicalType() on the result of mapTypeOutOfContext().

Fix this by making sure to use getCanonicalTypeInContext() on
the result of mapTypeOutOfContext(), just as we do in capture
lowering.

Unfortunately I worry this problem will come up again in a
different form -- a more general fix would change
mapTypeOutOfContext() to always return "generic signature
canonical" types, and also fix SubstitutionMaps to understand
same type constraints better.

Fixes <https://bugs.swift.org/browse/SR-3326>.
2017-01-03 21:49:44 -08:00
Slava Pestov
9db06ee36d Sema: Fixes for handling of 'Self'-returning methods
Protocol methods returning optionals, metatypes and functions
returning 'Self' are now handled correctly in Sema when
accessed with a base of existential type, eg:

protocol Clonable {
  func maybeClone() -> Self?
  func cloneMetatype() -> Self.Type
  func getClonerFunc() -> () -> Self
}

let c: Clonable = ...
let _: Clonable = c.maybeClone()
let _: Clonable.Type = c.cloneMetatype()

Previously, we were unable to model this properly, for
several reasons:

- When opening the function type, we replaced the return
  value in openedFullType _unconditionally_ with the
  existential type. This was broken if the return type
  was not the 'Self' parameter, but rather an optional,
  metatype or function type involving the 'Self' parameter.

- It was also broken because we lost information; if the
  return type originally contained an existential, we had
  no way to draw the distinction. The 'hasArchetypeSelf()'
  method was a hint that the original type contained a
  type parameter, but it was inaccurate in some subtle cases.

- Since we performed this replacement on both the
  'openedFullType' and 'openedType', CSApply had to "undo"
  it to replace the existential type with the opened
  existential archetype. This is because while the formal
  type of the access returns the existential type, in
  reality it returns the opened type, and CSApply has to
  insert the correct ErasureExpr.

  This was also done unconditionally, but even if it were
  done more carefully, it would do the wrong thing because
  of the 'loss of information' above.

- There was something fishy going on when we were dealing
  with a constructor that was declared on the Optional type
  itself, as seen in the fixed type_checker_crasher.

- TypeBase::eraseOpenedExistential() would transform a
  MetatypeType of an opened existential into a MetatypeType
  of an existential, rather than an ExistentialMetatypeType
  of the existential type.

The new logic has the following improvements:

- When opening a function type, we replace the 'Self' type
  parameter with the existential type in 'openedType', but
  *not* 'openedFullType'. This simplifies CSApply, since it
  doesn't have to "undo" this transformation when figuring
  out what coercions to perform.

- We now only use replaceCovariantResultType() when working
  with Self-returning methods on *classes*, which have more
  severe restrictions than protocols. For protocols, we walk
  the type using Type::transform() and handle all the cases
  properly.

- Not really related to the above, but there was a whole
  pile of dead code here concerning associated type references.

Note that SILGen still needs support for function conversions
involving an existential erasure; in the above Clonable example,
Sema now models this properly but SILGen still crashes:

let _: () -> Clonable = c.getClonerFunc()

Fixes <rdar://problem/28048391>, progress on <rdar://problem/21391055>.
2017-01-03 21:49:00 -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
645d262f77 IRGen: Fix Clang type conversion for pointers to optionals of metatypes
Be sure to lower the payload type of UnsafeMutablePointer and friends
before converting them, because the Clang type converter expects
optionals to have lowered payloads already.

Also, remove the FunctionType path; with the above change AST-level
function types should no longer show up here.

Fixes <https://bugs.swift.org/browse/SR-2702>.
2017-01-03 21:27:28 -08:00
Slava Pestov
48c529bf3b Resolve SIL crasher which started passing at some point 2017-01-03 20:15:30 -08:00
Slava Pestov
8bfe205c52 AST: Make TypeBase::getSuperclass() return the superclass type when called on an UnboundGenericType
Fixes <https://bugs.swift.org/browse/SR-3137>.
2017-01-03 20:15:30 -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
4daf56b648 SILGen: Fix calls to literal constructors defined in protocol extensions
Fixes <https://bugs.swift.org/browse/SR-3173>.
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
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
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