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

Assertion failed: (genericSig && "Need a generic signature to resolve conformance") #73068

Open
fibrechannelscsi opened this issue Apr 16, 2024 · 0 comments
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@fibrechannelscsi
Copy link
Contributor

Description

The compiler crashes when compiling the code listed below in Debug mode.
The full assertion is:
Assertion failed: (genericSig && "Need a generic signature to resolve conformance"), function appendAnyProtocolConformance, file ASTMangler.cpp, line 4151.

Reproduction

This reproducer requires one public import: swift-collections. A sample Package.swift file is enclosed below.

import Foundation; import OrderedCollections; import _Differentiation
extension OrderedDictionary: Differentiable where Value: Differentiable {
    public typealias TangentVector = OrderedDictionary<Key, Value.TangentVector>
    public mutating func move(by direction: TangentVector) {}
}
extension OrderedDictionary: AdditiveArithmetic where Value: AdditiveArithmetic {
    public static func + (_ lhs: Self, _ rhs: Self) -> Self {fatalError()}
    public static func - (_ lhs: Self, _ rhs: Self) -> Self {fatalError()}
    public static var zero: Self { [:] }
}
struct A<I: Hashable, D: Differentiable>: Differentiable {
    var r: OrderedDictionary<I, OrderedDictionary<String, D>>
    @differentiable(reverse) mutating func i(x: I, v: OrderedDictionary<String, D>) {self.r[x] = v}
}

Package.swift:

import PackageDescription
let package = Package(
    name: "70000",
    dependencies: [.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0")],
    targets: [.executableTarget(name: "70000", dependencies: [.product(name: "Collections", package: "swift-collections")])]
)

Expected behavior

The compilation should succeed. Or, the compiler should produce an error message as to why the compilation cannot succeed.

Environment

This problem appears to have been around for a while: nightly toolchains from 2023-07-10a up to 2024-04-11a exhibit this issue.
M1 MacBook; Xcode 15.1.

Additional information

The full stack trace is shown below:

1.      Apple Swift version 6.0-dev (LLVM 40c342d107dc66e, Swift 22919a9039e20a1)
2.      Compiling with effective version 5.10
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for _0000)
4.      While running pass #466 SILModuleTransform "Differentiation".
5.      While processing // differentiability witness for A.i(x:v:)
sil_differentiability_witness [serialized] [reverse] [parameters 1 2] [results 0] <I, D where I : Hashable, D : Differentiable> @$s5_00001AV1i1x1vyx_18OrderedCollections0A10DictionaryVySSq_GtF : $@convention(method) <I, D where I : Hashable, D : Differentiable> (@in_guaranteed I, @guaranteed OrderedDictionary<String, D>, @inout A<I, D>) -> () {
}

 on SIL function "@$s5_00001AV1i1x1vyx_18OrderedCollections0A10DictionaryVySSq_GtF".
 for 'i(x:v:)' (at /Users/user/p/70000/Sources/main.swift:13:39)
6.      While generating VJP for SIL function "@$s5_00001AV1i1x1vyx_18OrderedCollections0A10DictionaryVySSq_GtF".
 for 'i(x:v:)' (at /Users/user/p/70000/Sources/main.swift:13:39)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001096d1098 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001096cf864 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001096d16e0 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018b5d9a24 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018b5a9cc0 pthread_kill + 288
5  libsystem_c.dylib        0x000000018b4b5a40 abort + 180
6  libsystem_c.dylib        0x000000018b4b4d30 err + 0
7  swift-frontend           0x0000000109ba7da8 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::GenericSignature, swift::CanType, swift::ProtocolConformanceRef) (.cold.6) + 0
8  swift-frontend           0x000000010586ae30 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::GenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 672
9  swift-frontend           0x0000000105865c5c swift::Mangle::ASTMangler::appendConcreteProtocolConformance(swift::ProtocolConformance const*, swift::GenericSignature) + 432
10 swift-frontend           0x000000010586572c swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::SubstitutionMap, swift::GenericSignature) + 116
11 swift-frontend           0x00000001058622d8 swift::Mangle::ASTMangler::appendRetroactiveConformances(swift::Type, swift::GenericSignature) + 180
12 swift-frontend           0x000000010585cd14 swift::Mangle::ASTMangler::appendType(swift::Type, swift::GenericSignature, swift::ValueDecl const*) + 2716
13 swift-frontend           0x00000001058639c4 swift::Mangle::ASTMangler::appendImplFunctionType(swift::SILFunctionType*, swift::GenericSignature, swift::ValueDecl const*) + 2976
14 swift-frontend           0x000000010585e2cc swift::Mangle::ASTMangler::mangleReabstractionThunkHelper(swift::CanTypeWrapper<swift::SILFunctionType>, swift::Type, swift::Type, swift::Type, swift::Type, swift::ModuleDecl*) + 160
15 swift-frontend           0x0000000104a5f568 swift::autodiff::getOrCreateReabstractionThunk(swift::SILOptFunctionBuilder&, swift::SILModule&, swift::SILLocation, swift::SILFunction*, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>) + 752
16 swift-frontend           0x0000000104a610b8 swift::autodiff::reabstractFunction(swift::SILBuilder&, swift::SILOptFunctionBuilder&, swift::SILLocation, swift::SILValue, swift::CanTypeWrapper<swift::SILFunctionType>, std::__1::function<swift::SubstitutionMap (swift::SubstitutionMap)>) + 188
17 swift-frontend           0x0000000104a70e60 swift::autodiff::VJPCloner::Implementation::visitApplyInst(swift::ApplyInst*) + 3420
18 swift-frontend           0x0000000104a6877c swift::SILCloner<swift::autodiff::VJPCloner::Implementation>::visitBlocksDepthFirst(swift::SILBasicBlock*) + 380
19 swift-frontend           0x0000000104a67bf4 swift::SILCloner<swift::autodiff::VJPCloner::Implementation>::cloneFunctionBody(swift::SILFunction*, swift::SILBasicBlock*, llvm::ArrayRef<swift::SILValue>, bool) + 236
20 swift-frontend           0x0000000104a673b4 swift::autodiff::VJPCloner::Implementation::run() + 920
21 swift-frontend           0x0000000104a67c54 swift::autodiff::VJPCloner::run() + 24
22 swift-frontend           0x0000000104bc1b88 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 6028
23 swift-frontend           0x0000000104bbfa0c (anonymous namespace)::Differentiation::run() + 1060
24 swift-frontend           0x0000000104c62ec4 swift::SILPassManager::runModulePass(unsigned int) + 856
25 swift-frontend           0x0000000104c65268 swift::SILPassManager::execute() + 624
26 swift-frontend           0x0000000104c5fc44 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
27 swift-frontend           0x0000000104c5fbc4 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
28 swift-frontend           0x0000000104c9b2f4 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
29 swift-frontend           0x0000000104c7b7dc swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
30 swift-frontend           0x0000000104c5fe20 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
31 swift-frontend           0x0000000104c7dcc0 swift::runSILDiagnosticPasses(swift::SILModule&) + 192
32 swift-frontend           0x00000001044c28ec swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68
33 swift-frontend           0x0000000104287968 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 796
34 swift-frontend           0x000000010428707c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
35 swift-frontend           0x00000001042982b4 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
36 swift-frontend           0x000000010428968c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
37 swift-frontend           0x00000001042885f8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
38 swift-frontend           0x00000001040a4448 swift::mainEntry(int, char const**) + 3096
39 dyld                     0x000000018b2290e0 start + 2360

Note that this issue may be similar to others that already exist, for example, this one
#68689
Unlike 68689, however, this does not require a secondary internal Package.

@fibrechannelscsi fibrechannelscsi added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 16, 2024
@hborla hborla added generics Feature: generic declarations and types and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@slavapestov slavapestov added AutoDiff and removed generics Feature: generic declarations and types labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants