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-3541] Crash when calling method on generic base class with concrete subclass #46129

Closed
swift-ci opened this issue Jan 4, 2017 · 6 comments
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

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 4, 2017

Previous ID SR-3541
Radar None
Original Reporter Doug Hill (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9

System Version: OS X 10.11.6 (15G1212)
Kernel Version: Darwin 15.6.0
Boot Mode: Normal
Secure Virtual Memory: Enabled
System Integrity Protection: Enabled

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

md5: c2f1fd613921369a915bb796c648e430

Issue Description:

// ==================================
// Reporting
// ==================================
// An interface for a generic reporting class.
// Just allows writing to some unknown backend.
protocol Reporting
{
    func write(outputText: String)
}

/*!
    A reporter class that writes its output to the console log via NSLog
    Adopts the Reporting protocol
*/
public class ConsoleLogReporter : Reporting
{
    public func write(outputText: String)
    {
        // NSLog("%@", outputText)
    }
}

// ==================================
// Streaming
// ==================================
//
protocol Streaming
{
    associatedtype keyType
    associatedtype valueType
    func write(key: keyType, value: valueType )
}

class StreamingC<keyType, valueType> : Streaming
{
    func write(key: keyType, value: valueType )
    {
        print("This method needs to be implemented by subclasses.")
    }
}

// ==================================
// TupleStreamer
// ==================================
//
class TupleStreamer : StreamingC<Int, (Int, Int)>
{
    var tupleArray: [(Int,(Int, Int))]

    func write( tuple: (Int,(Int,Int)) )
    {
        let (key, value) = tuple
        self.write(key, value:value)
    }

    override func write(key: Int, value: (Int, Int) )
    {
        tupleArray.append( (key, value) )
    }

    override init()
    {
        tupleArray = []
    }
}

class MapReduce<InputKeyType, InputValueType, OutputKeyType, OutputValueType>
{
    /*
    Applications can use the Reporter to report progress, set application-level
    status messages and update Counters, or just indicate that they are alive.
    */
    typealias reporterType = Reporting

    /*
    Maps are the individual tasks that transform input records into intermediate records.
    The transformed intermediate records do not need to be of the same type as the input records.
    A given input pair may map to zero or many output pairs.
    Output pairs do not need to be of the same types as input pairs.
    */
    typealias mapperType = (inputKey:InputKeyType, inputValue:InputValueType) -> (OutputKeyType, OutputValueType)
    //(OutputKeyType, OutputValueType)

    /*
    Output pairs are collected with calls to collect.
    */
    typealias collectorType = (outputKey:OutputKeyType, outputValue:OutputValueType, Stream: StreamingC<OutputKeyType, OutputValueType>? ) -> StreamingC<OutputKeyType, OutputValueType>

    /*
    Perform local aggregation of the intermediate outputs, which helps to
    cut down the amount of data transferred from the Mapper to the Reducer.
    */
    typealias combinerType = (Stream: StreamingC<OutputKeyType, OutputValueType> ) -> StreamingC<OutputKeyType, OutputValueType>

    /*
    All intermediate values associated with a given output key are subsequently grouped and
    passed to the Reducer(s) to determine the final output
    */
    typealias reducerType = ( key: OutputKeyType, value: OutputValueType, reporter: Reporting) -> Bool

    typealias inputFormatType = [(Int,Int)]

    typealias recordReaderFunc = ( inputData: inputFormatType ) -> (InputKeyType, InputValueType)

    var inputKey: InputKeyType
    var inputValue: InputValueType

    var mapFunc: mapperType
    var reduceFunc: reducerType
    var reporter: reporterType = ConsoleLogReporter()
    var collectorFunc: collectorType

    init( inReporter: Reporting )
    {
        self.reporter = inReporter
    }
}

func TestMR()
{
    typealias inputKeyType = Int
    typealias inputValueType = [(Int, Int)]
    
    typealias outputKeyType = Int
    typealias outputValueType = (Int,Int)

    let values : inputValueType = [ (13, 10), (14, 10), (11, 09), (16, 15), (14, 13), (15, 13), (13, 09), (13, 09) ]

    let mr = MapReduce<inputKeyType, inputValueType, outputKeyType, outputValueType> (
            inReporter: ConsoleLogReporter()
        )
}

Here is the compiler output:

CompileSwift normal x86_64 /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/MapReduce.swift
    cd /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/MapReduce.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/main.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/ViewController.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/AppDelegate.swift -target x86_64-apple-ios9.3 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -I /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator -F /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/dhill/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-generated-files.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-own-target-headers.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-all-target-headers.hmap -Xcc -iquote -Xcc /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-project-headers.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/DerivedSources/x86_64 -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift -emit-module-doc-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce~partial.swiftdoc -Onone -module-name MapReduceSwift -emit-module-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce~partial.swiftmodule -serialize-diagnostics-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.dia -emit-dependencies-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.d -emit-reference-dependencies-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.swiftdeps -o /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.o

0  swift                    0x00000001060fa66b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x00000001060f9956 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x00000001060faccf SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff8bc1b52a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fb2bb0355d8 _sigtramp + 792830152
5  swift                    0x000000010403de65 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 261
6  swift                    0x000000010403d22d (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 205
7  swift                    0x000000010403c952 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<std::__1::pair<swift::Lowering::LValue, swift::SILLocation> >&, llvm::Optional<swift::ForeignErrorConvention> const&) && + 306
8  swift                    0x000000010403055a (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3418
9  swift                    0x000000010402f15a swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 58
10 swift                    0x000000010405fc77 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 87
11 swift                    0x000000010405ee16 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 390
12 swift                    0x000000010409fcce swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 3614
13 swift                    0x000000010409eea5 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
14 swift                    0x000000010406e53f swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 303
15 swift                    0x00000001040243e1 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1057
16 swift                    0x00000001040a3fe8 (anonymous namespace)::SILGenType::emitType() + 1192
17 swift                    0x00000001040a3ace swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
18 swift                    0x0000000104028b9b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 731
19 swift                    0x00000001040296e9 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 793
20 swift                    0x0000000104029b53 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 115
21 swift                    0x0000000103e4d343 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 12627
22 swift                    0x0000000103e4968d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
23 swift                    0x0000000103e450ac main + 1932
24 libdyld.dylib            0x00007fff92b395ad start + 1
25 libdyld.dylib            0x000000000000003d start + 1833724561
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/MapReduce.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/main.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/ViewController.swift /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/AppDelegate.swift -target x86_64-apple-ios9.3 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -I /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator -F /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/dhill/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-generated-files.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-own-target-headers.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-all-target-headers.hmap -Xcc -iquote -Xcc /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/MapReduceSwift-project-headers.hmap -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/DerivedSources/x86_64 -Xcc -I/Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift -emit-module-doc-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce~partial.swiftdoc -Onone -module-name MapReduceSwift -emit-module-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce~partial.swiftmodule -serialize-diagnostics-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.dia -emit-dependencies-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.d -emit-reference-dependencies-path /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.swiftdeps -o /Users/dhill/Library/Developer/Xcode/DerivedData/MapReduceSwift-amqpcwrrxhdjoidlyrbxqclncupd/Build/Intermediates/MapReduceSwift.build/Debug-iphonesimulator/MapReduceSwift.build/Objects-normal/x86_64/MapReduce.o 
1.  While emitting SIL for 'write' at /Users/dhill/Projects/Anaplan/Mobile/MapReduceSwift/MapReduceSwift/MapReduce.swift:61:5
@huonw
Copy link
Mannequin

huonw mannequin commented Jan 5, 2017

Based on an automatic reduction by creduce, this seems to be caused by the tuple arguments:

class StreamingC<valueType> {
    func write(value: valueType) {}
}
class TupleStreamer : StreamingC<(Int, Int)> {
    func write() {
        write(value: (0, 0))
    }
    override func write(value: (Int, Int)) {}
}
Assertion failed: (count <= Params.size()), function claimParams, file /Users/huon/swift6/swift/lib/SILGen/SILGenApply.cpp, line 3982.

Changing either or both of the `Int`s to `()` results in two exciting new assertions too:

# (Int, ()) and ((), Int)
Assertion failed: (!destType || destType.getObjectType() == SGF.SGM.Types.getLoweredType(origFormalType, substFormalType).getObjectType()), function materialize, file /Users/huon/swift6/swift/lib/SILGen/ArgumentSource.cpp, line 163.
# ((), ())
Assertion failed: (Params.empty() && "didn't consume all the parameters"), function ~ParamLowering, file /Users/huon/swift6/swift/lib/SILGen/SILGenApply.cpp, line 4007.

@jtbandes
Copy link
Collaborator

jtbandes commented Jan 5, 2017

This crashes because TypeConverter::getConstantOverrideType returns

(sil_function_type type=@convention(method) (@in (Int, Int), @guaranteed Bar) -> ())

when it's looking at the overridden method, and

(sil_function_type type=@convention(method) (Int, Int, @guaranteed Bar) -> ())

when it's looking at the same method if it isn't an override. But in both cases, getFlattenedValueCount sees the substituted argument type as a TupleType and returns 2, so claimParams() ends up trying to consume 2 params.

@slavapestov
Copy link
Member

#8091

@belkadan
Copy link
Contributor

Please don't mark bugs as resolved until the PR is merged!

@slavapestov
Copy link
Member

Do you think there's any reason the PR won't get merged?

@belkadan
Copy link
Contributor

To me, "resolved" is the state where the originator can verify your fix. That's not really true (without undue burden) until the corresponding PR is merged.

@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

5 participants