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

[SR-13329] Crash in IRGen #55769

Closed
dabrahams opened this issue Jul 30, 2020 · 1 comment
Closed

[SR-13329] Crash in IRGen #55769

dabrahams opened this issue Jul 30, 2020 · 1 comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-13329
Radar None
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee None
Priority Medium

md5: d6dc021094a8ec7a86cfaf17399a7992

Issue Description:

Possibly related to SR-13328. Compile this:

public struct X<Element> {
  var value: Element
}

extension X: Differentiable where Element: Differentiable {}

extension X: AdditiveArithmetic, Equatable where Element: AdditiveArithmetic {
  public static var zero: Self { .init(value: .zero) }
  
  @differentiable(where Element: Differentiable)
  public static func + (lhs: X, rhs: X) -> X {
    .init(value: lhs.value + rhs.value)
  }

  @usableFromInline
  @derivative(of: +)
  static func vjp_plus(lhs: X, rhs: X) 
    -> (value: X, pullback: (TangentVector)->(TangentVector, TangentVector))
  where Element: Differentiable
  {
    (lhs + rhs, { x in (x, x) })
  }
  
  @differentiable(where Element: Differentiable)
  public static func - (lhs: X, rhs: X) -> X {
    return .init(value: lhs.value - rhs.value)
  }

  @usableFromInline
  @derivative(of: -)
  static func vjp_minus(lhs: X, rhs: X) 
    -> (value: X, pullback: (TangentVector)->(TangentVector, TangentVector))
  where Element: Differentiable
  {
    (lhs - rhs, { x in (x, .zero - x) })
  }

  @differentiable(where Element: Differentiable)
  public static func += (lhs: inout X, rhs: X) {
    lhs.value += rhs.value
  }

  @usableFromInline
  @derivative(of: +=)
  static func vjp_plusEquals(lhs: inout X, rhs: X) 
    -> (value: Void, pullback: (inout TangentVector)->(TangentVector))
  where Element: Differentiable
  {
    lhs += rhs
    return ((), { x in x })
  }
  
  @differentiable(where Element: Differentiable)
  public static func -= (lhs: inout X, rhs: X) {
    lhs.value -= rhs.value
  }

  @usableFromInline
  @derivative(of: -=)
  static func vjp_minusEquals(lhs: inout X, rhs: X) 
    -> (value: Void, pullback: (inout TangentVector)->(TangentVector))
  where Element: Differentiable
  {
    lhs -= rhs
    return ((), { x in .zero - x })
  }
}

to get this

Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2020-06-03-a.xctoolchain/usr/bin/swift -frontend -c -primary-file x.swift -target x86_64-apple-darwin19.6.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -target-sdk-version 10.15.6 -module-name x -o /var/folders/z0/4612twmx5wbfrsp0jxbcvwrm00qbwx/T/x-9c5fe6.o

  1. Swift version 5.3-dev (LLVM 37f84d51a3, Swift 91d4726)
  2. While evaluating request IRGenSourceFileRequest(IR Generation for file "x.swift")
  3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { IRGen Preparation } on SIL for x.x)
  4. While running pass fix typo in ASTWalker #62 SILModuleTransform "LoadableByAddress".
  5. While converting type 'X<τ_0_1>.TangentVector'
  6. While converting type 'τ_0_1.TangentVector'
    0 swift 0x0000000105e64b58 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
    1 swift 0x0000000105e63e15 llvm::sys::RunSignalHandlers() + 85
    2 swift 0x0000000105e65126 SignalHandler(int) + 262
    3 libsystem_platform.dylib 0x00007fff72d825fd _sigtramp + 29
    4 libsystem_platform.dylib 0x00007ffeedd9e270 _sigtramp + 18446744071478295696
    5 swift 0x00000001020ffd65 swift::irgen::TypeConverter::getTypeEntry(swift::CanType) + 533
    6 swift 0x00000001020ff844 swift::irgen::IRGenModule::getTypeInfo(swift::SILType) + 20
    7 swift 0x00000001020e5e5d swift::irgen::TypeConverter::convertStructType(swift::TypeBase*, swift::CanType, swift::StructDecl*) + 877
    8 swift 0x0000000102100d4c swift::irgen::TypeConverter::convertAnyNominalType(swift::CanType, swift::NominalTypeDecl*) + 828
    9 swift 0x000000010210035f swift::irgen::TypeConverter::convertType(swift::CanType) + 111
    10 swift 0x00000001020ffd65 swift::irgen::TypeConverter::getTypeEntry(swift::CanType) + 533
    11 swift 0x00000001020ff800 swift::irgen::IRGenModule::getTypeInfoForLowered(swift::CanType) + 16
    12 swift 0x0000000102159e54 isLargeLoadableType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 132
    13 swift 0x0000000102159519 LargeSILTypeMapper::getNewSILType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 377
    14 swift 0x0000000102159f10 LargeSILTypeMapper::getNewTupleType(swift::GenericEnvironment*, swift::irgen::IRGenModule&, swift::SILType const&, swift::SILType const&) + 144
    15 swift 0x000000010215945b LargeSILTypeMapper::getNewSILType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 187
    16 swift 0x000000010215925a LargeSILTypeMapper::shouldTransformResults(swift::GenericEnvironment*, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::IRGenModule&) + 314
    17 swift 0x0000000102158fca LargeSILTypeMapper::shouldTransformFunctionType(swift::GenericEnvironment*, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::IRGenModule&) + 266
    18 swift 0x00000001021594e6 LargeSILTypeMapper::getNewSILType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 326
    19 swift 0x0000000102159f10 LargeSILTypeMapper::getNewTupleType(swift::GenericEnvironment*, swift::irgen::IRGenModule&, swift::SILType const&, swift::SILType const&) + 144
    20 swift 0x000000010215945b LargeSILTypeMapper::getNewSILType(swift::GenericEnvironment*, swift::SILType, swift::irgen::IRGenModule&) + 187
    21 swift 0x000000010215925a LargeSILTypeMapper::shouldTransformResults(swift::GenericEnvironment*, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::IRGenModule&) + 314
    22 swift 0x0000000102161c4c (anonymous namespace)::LoadableStorageAllocation::allocateLoadableStorage() + 10860
    23 swift 0x000000010215aca3 (anonymous namespace)::LoadableByAddress::run() + 931
    24 swift 0x000000010244c848 swift::SILPassManager::runModulePass(unsigned int) + 728
    25 swift 0x000000010244deaa swift::SILPassManager::execute() + 394
    26 swift 0x00000001024495f8 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
    27 swift 0x0000000102449593 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 51
    28 swift 0x0000000102459f7d swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 29
    29 swift 0x000000010244f055 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 517
    30 swift 0x0000000102449721 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 65
    31 swift 0x000000010211085c performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::_1::unique_ptr<swift::SILModule, std::1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable*, llvm::StringSet<llvm::MallocAllocator>) + 1132
    32 swift 0x0000000102110eb0 swift::IRGenSourceFileRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 80
    33 swift 0x0000000102134a15 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 37
    34 swift 0x00000001021149d9 llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 473
    35 swift 0x0000000102110e0e swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::1::unique_ptr<swift::SILModule, std::1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable*, llvm::StringSet<llvm::MallocAllocator>) + 286
    36 swift 0x0000000101eca511 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*) + 2577
    37 swift 0x0000000101ebd69e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 14190
    38 swift 0x0000000101e5c89f main + 815
    39 libdyld.dylib 0x00007fff72b89cc9 start + 1
    40 libdyld.dylib 0x0000000000000010 start + 18446603338591462216
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@BradLarson
Copy link
Collaborator

This no longer reproduces on top-of-tree Swift, either in optimized or unoptimized builds, so I'm going to assume it has been addressed in the meantime.

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

2 participants