swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.56k stars 10.35k forks source link

[SR-10697] IRGen assertion failure when partially applying a generic function to a type whose conformance is not available locally #53094

Closed 83b09dda-53f5-4663-b44c-87fd2a9a8717 closed 4 years ago

83b09dda-53f5-4663-b44c-87fd2a9a8717 commented 5 years ago
Previous ID SR-10697
Radar rdar://problem/50853487
Original Reporter @marcrasi
Type Bug
Status Resolved
Resolution Done
Environment Ubuntu 18.04. I got the same results with a few different toolchains from swift.org: - 4.2.4 Release - 5.0.1 Release - May 12, 2019 Trunk Snapshot
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 2 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, IRGen | |Assignee | @aschwaighofer | |Priority | Medium | md5: a7f7e56e10c504d4e143b513579e52af

blocks:

relates to:

Issue Description:

protocol A {}

struct Wrapper<T> {}

extension Wrapper: A where T: A {}

func inner<T: A>(_ t: T) {}

func outer<T: A>(_ t: T) {
  let _: (Wrapper<T>) -> () = inner
}

Assertion failure while processing the `partial_apply` in `outer`. Reproducible only via swiftc sr-10697.swift, not via swift sr-10697.swift.

swift: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/swift/lib/IRGen/GenArchetype.cpp:245: llvm::Value *swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction &, swift::CanArchetypeType, swift::ProtocolDecl *): Assertion `rootWTable && "root witness table not bound in local context!"' failed.
Stack dump:
0.  Program arguments: /usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift -frontend -c -primary-file /usr/local/google/home/marcrasi/swift-base/build/Ninja-ReleaseAssert/swift-linux-x86_64/workspace/noadrepro.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name noadrepro -o /tmp/noadrepro-3b947f.o 
1.  Swift version 5.0-dev (LLVM 082dec2e22, Swift 87e1efd1a2)
2.  While emitting IR SIL function "@$s9noadrepro5outeryyxAA1ARzlF".
 for 'outer(_:)' (at /usr/local/google/home/marcrasi/swift-base/build/Ninja-ReleaseAssert/swift-linux-x86_64/workspace/noadrepro.swift:9:1)
 #&#8203;0 0x00000000044d6994 PrintStackTraceSignalHandler(void*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x44d6994)
 #&#8203;1 0x00000000044d45ee llvm::sys::RunSignalHandlers() (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x44d45ee)
 #&#8203;2 0x00000000044d6da8 SignalHandler(int) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x44d6da8)
 #&#8203;3 0x00007f139bd830c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)
 #&#8203;4 0x00007f139a2c9fcf gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x32fcf)
 #&#8203;5 0x00007f139a2cb3fa abort (/lib/x86_64-linux-gnu/libc.so.6+0x343fa)
 #&#8203;6 0x00007f139a2c2e37 (/lib/x86_64-linux-gnu/libc.so.6+0x2be37)
 #&#8203;7 0x00007f139a2c2ee2 (/lib/x86_64-linux-gnu/libc.so.6+0x2bee2)
 #&#8203;8 0x000000000059ef93 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x59ef93)
 #&#8203;9 0x0000000000660436 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x660436)
#&#8203;10 0x0000000000663c73 bool llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>::callback_fn<emitConditionalConformancesBuffer(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*)::$_15>(long, unsigned int, swift::CanType, swift::ProtocolDecl*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x663c73)
#&#8203;11 0x0000000000e1df01 swift::SILWitnessTable::enumerateWitnessTableConditionalConformances(swift::ProtocolConformance const*, llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0xe1df01)
#&#8203;12 0x0000000000663911 emitWitnessTableAccessorCall(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*, llvm::Value**) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x663911)
#&#8203;13 0x00000000006604a3 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6604a3)
#&#8203;14 0x000000000066108b swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::CanGenericSignature, swift::ModuleDecl&, swift::irgen::GenericRequirement, swift::SubstitutionMap) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x66108b)
#&#8203;15 0x00000000006662cd void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_21>(long, swift::irgen::GenericRequirement) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6662cd)
#&#8203;16 0x0000000000666381 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_11>(long, swift::irgen::GenericRequirement) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x666381)
#&#8203;17 0x0000000000658618 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x658618)
#&#8203;18 0x00000000006606cd swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6606cd)
#&#8203;19 0x000000000061b63c emitPartialApplicationForwarder(swift::irgen::IRGenModule&, llvm::Optional<swift::irgen::FunctionPointer> const&, bool, swift::irgen::Signature const&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::HeapLayout const*, llvm::ArrayRef<swift::ParameterConvention>) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x61b63c)
#&#8203;20 0x00000000006194cc swift::irgen::emitFunctionPartialApplication(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::FunctionPointer const&, llvm::Value*, swift::irgen::Explosion&, llvm::ArrayRef<swift::SILParameterInfo>, swift::SubstitutionMap, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::Explosion&, bool) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6194cc)
#&#8203;21 0x00000000006bc4d3 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6bc4d3)
#&#8203;22 0x00000000006abb05 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x6abb05)
#&#8203;23 0x00000000005dca8e swift::irgen::IRGenerator::emitGlobalTopLevel() (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x5dca8e)
#&#8203;24 0x000000000054ba83 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x54ba83)
#&#8203;25 0x000000000054c061 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x54c061)
#&#8203;26 0x00000000004d313e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x4d313e)
#&#8203;27 0x00000000004cee3e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x4cee3e)
#&#8203;28 0x0000000000473930 main (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x473930)
#&#8203;29 0x00007f139a2b72b1 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b1)
#&#8203;30 0x000000000047357a _start (/usr/local/google/home/marcrasi/Downloads/swift-toolchains/head-nightly-2019-05-12/swift-DEVELOPMENT-SNAPSHOT-2019-05-12-a-ubuntu18.04/usr/bin/swift+0x47357a)
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
dan-zheng commented 5 years ago

cc @belkadan: I'm pinging you because I noticed you edited the bug and added a rdar. 🙂
This bug is affecting the progress of the Swift for TensorFlow team: I wonder if an IRGen expert could please look into it? (maybe someone already is)

belkadan commented 5 years ago

This got filed yesterday. I don't think that's really enough time for anyone to look at it.

dan-zheng commented 4 years ago

Related issue from 2018: SR-7287. It's been fixed, but the exact fix was not pinpointed.

aschwaighofer commented 4 years ago

This should have been fixed by https://github.com/apple/swift/pull/30037 or https://github.com/apple/swift/pull/29912