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

Ensure we are adding T : Differentiable conformance from protocol conditional conformance #77446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

asl
Copy link
Contributor

@asl asl commented Nov 7, 2024

Fixes #75711

protocol conditional conformance.

Fixes #75711
@asl
Copy link
Contributor Author

asl commented Nov 7, 2024

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Nov 7, 2024

Tagging @rxwei @JaapWijnen

// generic signature. Update witness substitution map generic signature to
// have them as well.
if (auto *derivativeId = witness.getDerivativeFunctionIdentifier())
witnessSubs = SubstitutionMap::get(derivativeId->getDerivativeGenericSignature(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the correct witnessSubs be computed in Sema? See lib/AST/RequirementEnvironment.cpp

Copy link
Contributor Author

@asl asl Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be calculated correctly there:
<τ_0_0 where τ_0_0 : Differentiable> is a witness generic thunk signature and the corresponding requirement-to-witness substitution map is:

(substitution_map generic_signature=<Self where Self : P>
  (substitution Self ->
    (bound_generic_struct_type decl="main.(file)[email protected]:3:8"
      (generic_type_param_type depth=0 index=0 param_kind=type)))
  (conformance type="Self"
    (normal_conformance type="Wrapper<T>" protocol="P"
      (assoc_type req="T" type="T")
      (assoc_conformance type="Self" proto="Copyable"
        (builtin_conformance type="Wrapper<T>" protocol="Copyable"))
      (assoc_conformance type="Self" proto="Escapable"
        (builtin_conformance type="Wrapper<T>" protocol="Escapable"))
      (assoc_conformance type="Self.T" proto="Differentiable"
        (abstract_conformance protocol="Differentiable"))
      (requirement "T" conforms_to "Differentiable"))))

However, witnessSubs here is:

(substitution_map generic_signature=<T where T : Copyable, T : Escapable>
  (substitution T ->
    (primary_archetype_type address=0x15c9d8c18 conforms_to="_Differentiation.(file).Differentiable" name="\xCF\x84_0_0"
      (interface_type=generic_type_param_type depth=0 index=0 param_kind=type)))
  (conformance type="T"
    (abstract_conformance protocol="Copyable"))
  (conformance type="T"
    (abstract_conformance protocol="Escapable")))

So T : Differentiable comes from conditional conformance via substitution and is not part of generic signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavapestov So, what do you think about this? Should we change the calculation somehow? For now I just made it conditional for autodiff and only adding T : Differentiable requirement. W/o this we are unable to calculate derivative function type in protocol conformance as we need to have corresponding associated types etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavapestov Any further suggestions here?

@kovdan01
Copy link
Contributor

kovdan01 commented Dec 26, 2024

@asl It looks like that the following case is related to the issue which is supposed to be fixed by the PR. With this patch applied, we still have an issue described below.

Consider the following (with forgotten where Self : Differentiable, commented out in the code snippet below):

protocol AdditiveArithmetic: Equatable /*where Self : Differentiable*/{
  @differentiable(reverse, wrt: (lhs, rhs))
  static func +(lhs: Self, rhs: Self) -> Self
}

struct Foo: AdditiveArithmetic {
  static func +(lhs: Self, rhs: Self) -> Self {
    lhs
  }
}

When compiling, we get the following crash (see under spoiler).

error: compile command failed due to signal 6 (use -v to see invocation)
                                                                                                                                                                                                                                                                
getReducedTypeParameter() was called
       with <τ_0_0 where τ_0_0 : AdditiveArithmetic>,
       and τ_0_0.TangentVector.
                                                                                                                                                                                                                                                                
This type parameter's reduced term is τ_0_0.[Differentiable:TangentVector].
                                                                                                                                                                                                                                                                
This is not a valid term, because τ_0_0 does not have a member type named [Differentiable:TangentVector].
                                                                                                                                                                                                                                                                
This usually indicates the caller passed the wrong type or generic signature to getReducedType().
                                                                                                                                                                                                                                                                
Requirement machine for <τ_0_0 where τ_0_0 : AdditiveArithmetic>
Rewrite system: {
- [AdditiveArithmetic].[AdditiveArithmetic] => [AdditiveArithmetic] [permanent]
- [AdditiveArithmetic].[Equatable] => [AdditiveArithmetic] [explicit]
- [AdditiveArithmetic].[Copyable] => [AdditiveArithmetic] [explicit]
- [AdditiveArithmetic].[Escapable] => [AdditiveArithmetic] [explicit]
- [Equatable].[Equatable] => [Equatable] [permanent]
- [Equatable].[Copyable] => [Equatable] [explicit]
- [Equatable].[Escapable] => [Equatable] [explicit]
- [Copyable].[Copyable] => [Copyable] [permanent]
- [Escapable].[Escapable] => [Escapable] [permanent]
- τ_0_0.[AdditiveArithmetic] => τ_0_0 [explicit]
- τ_0_0.[Equatable] => τ_0_0
- τ_0_0.[Copyable] => τ_0_0
- τ_0_0.[Escapable] => τ_0_0
}
Property map: {
  [AdditiveArithmetic] => { conforms_to: [AdditiveArithmetic Equatable Copyable Escapable] }
  [Equatable] => { conforms_to: [Equatable Copyable Escapable] }
  [Copyable] => { conforms_to: [Copyable] }
  [Escapable] => { conforms_to: [Escapable] }
  τ_0_0 => { conforms_to: [AdditiveArithmetic Equatable Copyable Escapable] }
}
Conformance paths: {
}
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift-frontend -frontend -c -primary-file 32.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -empty-abi-descr
iptor -resource-dir /path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift -module-name main -in-process-plugin-server-path /path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift
/host/libSwiftInProcPluginServer.so -plugin-path /path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift/host/plugins -plugin-path /path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/loc
al/lib/swift/host/plugins -o /tmp/TemporaryDirectory.IuRRrR/32-1.o
1.      Swift version 6.2-dev (LLVM 9f6c3d784782c34, Swift 311f449eb52d9a5)
2.      Compiling with effective version 5.10
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "32.swift")
4.      While generating SIL witness table protocol conformance Foo: AdditiveArithmetic at 'Foo' (at 32.swift:15:1)
5.      While computing canonical type for  type '@convention(thin) <Self where Self : AdditiveArithmetic> (τ_0_0.Type) -> (τ_0_0, τ_0_0) -> (τ_0_0, (τ_0_0.TangentVector, τ_0_0.TangentVector) -> τ_0_0.TangentVector)'
 #0 0x00000c8a4ca3acf8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /path/to/swift/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00000c8a4ca38e20 llvm::sys::RunSignalHandlers() /path/to/swift/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00000c8a4ca3b378 SignalHandler(int) /path/to/swift/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x000060905964c1d0 (/usr/lib/libc.so.6+0x3d1d0)
 #4 0x00006090596a53f4 __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76
 #5 0x000060905964c120 raise /usr/src/debug/glibc/glibc/signal/../sysdeps/posix/raise.c:27:6
 #6 0x00006090596334c3 abort /usr/src/debug/glibc/glibc/stdlib/abort.c:81:7
 #7 0x00000c8a475ee53b llvm::SmallVectorTemplateCommon<swift::rewriting::Symbol, void>::operator[](unsigned long) /path/to/swift/llvm-project/llvm/include/llvm/ADT/SmallVector.h:305:5
 #8 0x00000c8a475ee53b swift::rewriting::MutableTerm::operator[](unsigned long) /path/to/swift/swift/lib/AST/RequirementMachine/Term.h:192:12
 #9 0x00000c8a475ee53b swift::rewriting::RequirementMachine::getReducedTypeParameter(swift::CanType, llvm::ArrayRef<swift::GenericTypeParamType*>) const /path/to/swift/swift/lib/AST/RequirementMachine/GenericSignatureQueries.cpp:451:54
#10 0x00000c8a475f0f2f swift::rewriting::RequirementMachine::getReducedType(swift::Type, llvm::ArrayRef<swift::GenericTypeParamType*>) const::$_0::operator()(swift::Type) const /path/to/swift/swift/lib/AST/RequirementMachine/GenericSignatu
reQueries.cpp:0:12
#11 0x00000c8a475f0f2f std::optional<swift::Type> llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>::callback_fn<swift::rewriting::RequirementMachine::getReducedType(swift::Type, llvm::ArrayRef<swift::GenericTypeParamType*>) const::$_0>(lon
g, swift::TypeBase*) /path/to/swift/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#12 0x00000c8a476904d1 std::_Optional_base_impl<swift::Type, std::_Optional_base<swift::Type, true, true>>::_M_is_engaged() const /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:469:58
#13 0x00000c8a476904d1 std::optional<swift::Type>::operator bool() const /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:983:22
#14 0x00000c8a476904d1 swift::TypeTransform<swift::Type::transformRec(llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>) const::Transform>::doIt(swift::Type, swift::TypePosition) /path/to/swift/swift/include/swift/AST/TypeT
ransform.h:98:29
#15 0x00000c8a47690734 swift::TypeTransform<swift::Type::transformRec(llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>) const::Transform>::doIt(swift::Type, swift::TypePosition) /path/to/swift/swift/include/swift/AST/TypeT
ransform.h:777:26
#16 0x00000c8a47690dd5 swift::Type::operator bool() const /path/to/swift/swift/include/swift/AST/Type.h:245:47
#17 0x00000c8a47690dd5 swift::TypeTransform<swift::Type::transformRec(llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>) const::Transform>::doIt(swift::Type, swift::TypePosition) /path/to/swift/swift/include/swift/AST/TypeT
ransform.h:699:14
#18 0x00000c8a47691bd2 swift::TypeTransform<swift::Type::transformRec(llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>) const::Transform>::doIt(swift::Type, swift::TypePosition) /path/to/swift/swift/include/swift/AST/TypeT
ransform.h:0:23
#19 0x00000c8a476825c3 swift::Type::transformRec(llvm::function_ref<std::optional<swift::Type> (swift::TypeBase*)>) const /path/to/swift/swift/lib/AST/Type.cpp:4154:3
#20 0x00000c8a475ee825 swift::rewriting::RequirementMachine::getReducedType(swift::Type, llvm::ArrayRef<swift::GenericTypeParamType*>) const /path/to/swift/swift/lib/AST/RequirementMachine/GenericSignatureQueries.cpp:480:3
#21 0x00000c8a47526420 swift::Type::operator->() const /path/to/swift/swift/include/swift/AST/Type.h:241:5
#22 0x00000c8a47526420 swift::GenericSignatureImpl::getReducedType(swift::Type) const /path/to/swift/swift/lib/AST/GenericSignature.cpp:520:10
#23 0x00000c8a47687dfe swift::TypeBase::getReducedType(swift::GenericSignature) /path/to/swift/swift/lib/AST/Type.cpp:1865:14
#24 0x00000c8a47687dfe swift::TypeBase::computeCanonicalType() /path/to/swift/swift/lib/AST/Type.cpp:1752:42
#25 0x00000c8a46a88bca llvm::isa_impl_cl<swift::AnyFunctionType, swift::TypeBase const*>::doit(swift::TypeBase const*) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:109:5
#26 0x00000c8a46a88bca llvm::isa_impl_wrap<swift::AnyFunctionType, swift::TypeBase const*, swift::TypeBase const*>::doit(swift::TypeBase const* const&) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:137:12
#27 0x00000c8a46a88bca llvm::isa_impl_wrap<swift::AnyFunctionType, swift::TypeBase const* const, swift::TypeBase const*>::doit(swift::TypeBase const* const&) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:127:12
#28 0x00000c8a46a88bca llvm::CastIsPossible<swift::AnyFunctionType, swift::TypeBase const*, void>::isPossible(swift::TypeBase const* const&) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:255:12
#29 0x00000c8a46a88bca llvm::CastInfo<swift::AnyFunctionType, swift::TypeBase* const, void>::isPossible(swift::TypeBase* const&) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:509:12
#30 0x00000c8a46a88bca bool llvm::isa<swift::AnyFunctionType, swift::TypeBase*>(swift::TypeBase* const&) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:549:10
#31 0x00000c8a46a88bca decltype(auto) llvm::cast<swift::AnyFunctionType, swift::TypeBase>(swift::TypeBase*) /path/to/swift/llvm-project/llvm/include/llvm/Support/Casting.h:578:3
#32 0x00000c8a46a88bca swift::CanTypeWrapper<swift::AnyFunctionType> swift::cast<swift::AnyFunctionType>(swift::CanType) /path/to/swift/swift/include/swift/AST/Type.h:620:28
#33 0x00000c8a46a88bca swift::Lowering::TypeConverter::makeConstantInterfaceType(swift::SILDeclRef) /path/to/swift/swift/lib/SIL/IR/TypeLowering.cpp:4119:12
#34 0x00000c8a469e86eb swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) /path/to/swift/swift/lib/SIL/IR/SILFunctionType.cpp:4162:30
#35 0x00000c8a4604410e swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::SerializedKind_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:717:13
#36 0x00000c8a4604857d (anonymous namespace)::SILGenConformance::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:652:34
#37 0x00000c8a4604857d (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Witness) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:488:17
#38 0x00000c8a46047ee7 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:0:0
#39 0x00000c8a46048148 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::addAutoDiffDerivativeMethodsIfRequired(swift::AbstractFunctionDecl*, swift::SILDeclRef::Kind) /path/to/swift/swift/include/swift/SIL/SILWitnessVisitor.h:184:19
#40 0x00000c8a4604755a swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitFuncDecl(swift::FuncDecl*) /path/to/swift/swift/include/swift/SIL/SILWitnessVisitor.h:156:5
#41 0x00000c8a4604755a swift::ASTVisitor<(anonymous namespace)::SILGenConformance, void, void, void, void, void, void>::visit(swift::Decl*) /path/to/swift/swift/include/swift/AST/DeclNodes.def:178:5
#42 0x00000c8a4604755a swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) /path/to/swift/swift/include/swift/SIL/SILWitnessVisitor.h:111:22
#43 0x00000c8a46043e6e (anonymous namespace)::SILGenConformance::addConditionalRequirements() /path/to/swift/swift/lib/SILGen/SILGenType.cpp:683:9
#44 0x00000c8a46043e6e (anonymous namespace)::SILGenConformance::emit() /path/to/swift/swift/lib/SILGen/SILGenType.cpp:551:5
#45 0x00000c8a46043e6e swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:706:66
#46 0x00000c8a46046b95 (anonymous namespace)::SILGenType::emitType() /path/to/swift/swift/lib/SILGen/SILGenType.cpp:0:19
#47 0x00000c8a46046398 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) /path/to/swift/swift/lib/SILGen/SILGenType.cpp:1320:1
#48 0x00000c8a45f242f3 swift::Lowering::SILGenModule::visit(swift::Decl*) /path/to/swift/swift/lib/SILGen/SILGen.cpp:0:15
#49 0x00000c8a45f242f3 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) /path/to/swift/swift/lib/SILGen/SILGen.cpp:2100:5
#50 0x00000c8a45f24a34 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const /path/to/swift/swift/lib/SILGen/SILGen.cpp:0:11
#51 0x00000c8a4602e5a8 std::_Optional_payload_base<llvm::SmallVector<swift::SymbolSource, 1u>>::_M_reset() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:313:12
#52 0x00000c8a4602e5a8 std::_Optional_payload<llvm::SmallVector<swift::SymbolSource, 1u>, false, false, false>::~_Optional_payload() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:437:57
#53 0x00000c8a4602e5a8 std::_Optional_base<llvm::SmallVector<swift::SymbolSource, 1u>, false, false>::~_Optional_base() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:508:12
#54 0x00000c8a4602e5a8 swift::ASTLoweringDescriptor::~ASTLoweringDescriptor() /path/to/swift/swift/include/swift/AST/SILGenRequests.h:50:8
#55 0x00000c8a4602e5a8 std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::callDerived<0ul>(swift::Evaluator&, std::integer_sequence<unsigned long, 0ul>) const /path/to/swift/swift/include/swift/AST/SimpleRequest.h:287:5
#56 0x00000c8a4602e5a8 swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) /path/to/swift/swift/include/swift/AST/SimpleRequest.h:311:20
#57 0x00000c8a45f29b5c swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) /path/to/swift/swift/include/swift/AST/Evaluator.h:349:14
#58 0x00000c8a45f25352 std::_Optional_payload_base<llvm::SmallVector<swift::SymbolSource, 1u>>::_M_reset() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:313:12
#59 0x00000c8a45f25352 std::_Optional_payload<llvm::SmallVector<swift::SymbolSource, 1u>, false, false, false>::~_Optional_payload() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:437:57
#60 0x00000c8a45f25352 std::_Optional_base<llvm::SmallVector<swift::SymbolSource, 1u>, false, false>::~_Optional_base() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/optional:508:12
#61 0x00000c8a45f25352 swift::ASTLoweringDescriptor::~ASTLoweringDescriptor() /path/to/swift/swift/include/swift/AST/SILGenRequests.h:50:8
#62 0x00000c8a45f25352 std::_Head_base<0ul, swift::ASTLoweringDescriptor, false>::~_Head_base() /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/tuple:196:12
#63 0x00000c8a45f25352 swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::~SimpleRequest() /path/to/swift/swift/include/swift/AST/SimpleRequest.h:272:7
#64 0x00000c8a45f25352 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) /path/to/swift/swift/lib/SILGen/SILGen.cpp:2272:3
#65 0x00000c8a4575c768 std::_Tuple_impl<0ul, swift::SILModule*, std::default_delete<swift::SILModule>>::_Tuple_impl(std::_Tuple_impl<0ul, swift::SILModule*, std::default_delete<swift::SILModule>>&&) /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/tuple:326:7
#66 0x00000c8a4575c768 std::tuple<swift::SILModule*, std::default_delete<swift::SILModule>>::tuple(std::tuple<swift::SILModule*, std::default_delete<swift::SILModule>>&&) /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/tuple:2132:17
#67 0x00000c8a4575c768 std::__uniq_ptr_impl<swift::SILModule, std::default_delete<swift::SILModule>>::__uniq_ptr_impl(std::__uniq_ptr_impl<swift::SILModule, std::default_delete<swift::SILModule>>&&) /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:179:9
#68 0x00000c8a4575c768 std::__uniq_ptr_data<swift::SILModule, std::default_delete<swift::SILModule>, true, true>::__uniq_ptr_data(std::__uniq_ptr_data<swift::SILModule, std::default_delete<swift::SILModule>, true, true>&&) /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:236:7
#69 0x00000c8a4575c768 std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>::unique_ptr(std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>&&) /sbin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:360:7
#70 0x00000c8a4575c768 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) /path/to/swift/swift/lib/FrontendTool/FrontendTool.cpp:747:57
#71 0x00000c8a4576d72a withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) /path/to/swift/swift/lib/FrontendTool/FrontendTool.cpp:1155:25
#72 0x00000c8a4575f7a6 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) /path/to/swift/swift/lib/FrontendTool/FrontendTool.cpp:0:12
#73 0x00000c8a4575f7a6 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) /path/to/swift/swift/lib/FrontendTool/FrontendTool.cpp:1368:19
#74 0x00000c8a4575e968 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) /path/to/swift/swift/lib/FrontendTool/FrontendTool.cpp:0:19
#75 0x00000c8a454fc40e run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) /path/to/swift/swift/lib/DriverTool/driver.cpp:0:0
#76 0x00000c8a454fc40e swift::mainEntry(int, char const**) /path/to/swift/swift/lib/DriverTool/driver.cpp:530:10
#77 0x0000609059634e08 __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#78 0x0000609059634ecc call_init /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:128:20
#79 0x0000609059634ecc __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:347:5
#80 0x00000c8a454fb3c5 _start (/path/to/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift-frontend+0xcb83c5)

If we uncomment where Self : Differentiable, the code compiles w/o issues.

While it looks like that we should emit an error if conditional conformance is missing, we definitely do not want to crash. The error should probably look like the following (autodiff_attr_result_not_differentiable:

error: can only differentiate functions with results that conform to 'Differentiable', but 'Foo' does not conform to 'Differentiable'

@asl
Copy link
Contributor Author

asl commented Dec 26, 2024

@asl It looks like that the following case is related to the issue which is supposed to be fixed by the PR. With this patch applied, we still have an issue described below.

@kovdan01 I believe your example is different than the code from the PR: there is no T : Differentiable conformance in the context to bring in. So, it's a case of missed diagnostics at least

@kovdan01
Copy link
Contributor

@asl It looks like that the following case is related to the issue which is supposed to be fixed by the PR. With this patch applied, we still have an issue described below.

@kovdan01 I believe your example is different than the code from the PR: there is no T : Differentiable conformance in the context to bring in. So, it's a case of missed diagnostics at least

@asl Thanks for clarification. I thought it might be related because the crash stack dump looks similar to the one being fixed by this PR.

The issue does not seem to be reported before, so created an issue #78370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid type parameter in getReducedType()
3 participants