Uploaded image for project: 'Swift'
  1. Swift
  2. SR-3541

Crash when calling method on generic base class with concrete subclass

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      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
      

        Attachments

          Activity

            People

            Assignee:
            slavapestov Slava Pestov
            Reporter:
            Doug Hill Doug Hill
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: