Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2733] Crash compiling function that returns Self, possibly involving generics #45337

Closed
tjw opened this issue Sep 22, 2016 · 8 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@tjw
Copy link
Contributor

tjw commented Sep 22, 2016

Previous ID SR-2733
Radar rdar://problem/28437884
Original Reporter @tjw
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Mac OS X 10.11.6
Xcode 8.1 beta 1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 90653eb2a55d81c8403c17c44e1f16d2

is duplicated by:

  • SR-1683 "TYPE MISMATCH" abort trying to match return type to Self

Issue Description:

This code crashes Xcode 8.1 beta 1's Swift compiler (but it works fine in Xcode 8.0 GM).

For whatever reason, this only happens when run inside Xcode. If the 8.1b1 swift is run from the command line `xcrun swift main.swift`, it works fine. So this may be something about the extra module generation or whatever arguments passed by Xcode.

open class Base {
    required public init() { }
}

public class Runtime {
    public func makeInstance<T: Base>(ofClass cls: T.Type) throws -> T {
        return cls.init()
    }
}

open class Sub : Base {
    public static func before(_ runtime: Runtime) throws -> Self {
        return try runtime.makeInstance(ofClass: self)
    }
}
TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT expression at [/Users/bungi/Source/Staff/bungi/Radar/Swift/SelfReturnFromGeneric/main.swift:21:20 - line:21:54] RangeText="runtime.makeInstance(ofClass: self)"
  argument value:   %1 = argument of bb0 : $@thick Sub.Type         // user: %3
  parameter type: @thick Self.Type
0  swift                    0x000000010d1f130b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010d1f0556 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010d1f1a5f SignalHandler(int) + 383
3  libsystem_platform.dylib 0x00007fff9fc5d52a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff60c72ac5 _sigtramp + 3238090165
5  swift                    0x000000010d1f17ae abort + 14
6  swift                    0x000000010a6ced59 swift::Lowering::SILGenFunction::emitApply(swift::SILLocation, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::Substitution>, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ApplyOptions, llvm::Optional<swift::SILFunctionTypeRepresentation>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::Lowering::SGFContext) + 5049
7  swift                    0x000000010a6d2046 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 6902
8  swift                    0x000000010a6d0053 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 51
9  swift                    0x000000010a718195 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 85
10 swift                    0x000000010a719d98 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 7256
11 swift                    0x000000010a713283 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 35
12 swift                    0x000000010a76d297 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 903
13 swift                    0x000000010a76a8d0 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 816
14 swift                    0x000000010a76a750 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 432
15 swift                    0x000000010a76a595 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
16 swift                    0x000000010a72bb6a swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 362
17 swift                    0x000000010a6cac38 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 216
18 swift                    0x000000010a6c1489 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 617
19 swift                    0x000000010a76fc66 (anonymous namespace)::SILGenType::emitType() + 934
20 swift                    0x000000010a76f83e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
21 swift                    0x000000010a6c757b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 715
22 swift                    0x000000010a6c8475 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 949
23 swift                    0x000000010a6c8995 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 117
24 swift                    0x000000010a533222 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7458
25 swift                    0x000000010a4f2320 main + 2544
26 libdyld.dylib            0x00007fff9e86a5ad start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/bungi/Source/Staff/bungi/Radar/Swift/SelfReturnFromGeneric/main.swift -target x86_64-apple-macosx10.11 -enable-objc-interop -sdk /Applications/Xcode-8.1-b1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Products/Debug -F /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Products/Debug -enable-testing -g -module-cache-path /Users/bungi/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/SelfReturnFromGeneric-generated-files.hmap -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/SelfReturnFromGeneric-own-target-headers.hmap -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/SelfReturnFromGeneric-all-target-headers.hmap -Xcc -iquote -Xcc /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/SelfReturnFromGeneric-project-headers.hmap -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Products/Debug/include -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/DerivedSources/x86_64 -Xcc -I/Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/bungi/Source/Staff/bungi/Radar/Swift/SelfReturnFromGeneric -emit-module-doc-path /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name SelfReturnFromGeneric -emit-module-path /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main.swiftdeps -o /Users/bungi/Library/Developer/Xcode/DerivedData/SelfReturnFromGeneric-fvijhycwrbrkzqbfbiruqzyqnzzx/Build/Intermediates/SelfReturnFromGeneric.build/Debug/SelfReturnFromGeneric.build/Objects-normal/x86_64/main.o 
1.  While emitting SIL for 'before' at /Users/bungi/Source/Staff/bungi/Radar/Swift/SelfReturnFromGeneric/main.swift:20:12
@belkadan
Copy link
Contributor

It crashes for me with a debug compiler on master, so I'm not sure why your command-line case is passing. Regardless, we should definitely take a look at a regression in Xcode 8.1!

@tjw
Copy link
Contributor Author

tjw commented Sep 23, 2016

This is crashing for me now on 8.0 final. I don't know if it is a side effect of installing 8.1b1 on this Mac or whether the regression was between 8.0 GM and 8.0 final (hopefully not or whether something else is going on. But at least, you're able to reproduce it too)

@belkadan
Copy link
Contributor

@slavapestov, this is that thing you were talking about where we pass Self as a generic argument. Do you remember what changed in this area?

@belkadan
Copy link
Contributor

@tjw, are you sure this was a change between GM and final and not between 8b6 and 8GM?

@tjw
Copy link
Contributor Author

tjw commented Sep 23, 2016

Argh... it looks like I had Xcode set up on this Mac to use a snapshot from 8-18. Clearing that and it now works in 8.1 b1. Sorry for the regression false alarm! (though it sounds like it's broken on master from Jordan's comment above).

... now to go file an Xcode feature request to make it more clear when building with a snapshot, since I've messed this up twice now.

@slavapestov
Copy link
Member

So it's broken on master but not in any release? I'll take a look when I have a chance.

@belkadan
Copy link
Contributor

My hypothesis is that it fails with assertions / the verifier on, but happens to do the right thing.

@slavapestov
Copy link
Member

#6543

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants