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

Compiler crash in extension with same-type constraint

    XMLWordPrintable

    Details

      Description

      The following code crashes the compiler on master (regression from 3.0.2). The issue seems to be with the lookup for the return type of A.doSomething (Coordinate.Stride); using a concrete return-type (such as Int) or replacing the constraint with a conformance constraint ("where Coordinate: SignedInteger", for instance) does not crash.

      That's as far as I got with my investigation. I think it's related to the TODO in GenericSignature::getSubstitutionMap, but I'm not really familiar with substitution maps so somebody else is probably better-placed to resolve it.

      protocol A {
        associatedtype Coordinate: Strideable
        func doSomething(_: Range<Coordinate>) -> Coordinate.Stride
      }
      
      extension A where Coordinate == Int {
        func extensionFunc(_ range: Range<Coordinate>) {
          _ = doSomething(range)
        }
      }
      

      Crash details:

      0  swift                    0x00000001122eb0e6 SignalHandler(int) + 454
      1  libsystem_platform.dylib 0x00007fffc5e18bba _sigtramp + 26
      2  swift                    0x000000010fc27ca8 swift::TypeBase::getCanonicalType() + 24
      3  swift                    0x000000010f76e105 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 277
      4  swift                    0x000000010f76db3e swift::CanType swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit<>(swift::CanType) + 94
      5  swift                    0x000000010f768095 (anonymous namespace)::SILTypeSubstituter::visitSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 277
      6  swift                    0x000000010f76852f swift::SILFunctionType::substGenericArgs(swift::SILModule&, llvm::ArrayRef<swift::Substitution>) + 191
      7  swift                    0x000000010f390a1f (anonymous namespace)::Callee::getAtUncurryLevel(swift::Lowering::SILGenFunction&, unsigned int) const + 3247
      8  swift                    0x000000010f38cb76 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1078
      9  swift                    0x000000010f38c223 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 51
      10 swift                    0x000000010f3d5905 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 85
      11 swift                    0x000000010f3d42f6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 470
      12 swift                    0x000000010f3d8685 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 11733
      13 swift                    0x000000010f3d42f6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 470
      14 swift                    0x000000010f4276dd swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 653
      15 swift                    0x000000010f427445 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
      16 swift                    0x000000010f3e8ffe swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 462
      17 swift                    0x000000010f386c28 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 216
      18 swift                    0x000000010f37d3c0 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 640
      19 swift                    0x000000010f42dba0 swift::ASTVisitor<SILGenExtension, void, void, void, void, void, void>::visit(swift::Decl*) + 208
      20 swift                    0x000000010f42cf2b SILGenExtension::emitExtension(swift::ExtensionDecl*) + 59
      21 swift                    0x000000010f42cee5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
      22 swift                    0x000000010f3836cb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 747
      23 swift                    0x000000010f384755 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1029
      24 swift                    0x000000010f384ba6 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool, bool) + 38
      25 swift                    0x000000010f1bffdc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 12188
      26 swift                    0x000000010f178771 main + 3025
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: