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-12887] Differentiation transform: debug scope error for VJPEmitter-generated function #55334

Closed
dan-zheng opened this issue May 27, 2020 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-12887
Radar None
Original Reporter @dan-zheng
Type Bug
Status Closed
Resolution Done
Environment

Depends on SR-12886 (alloc_stack [dynamic_lifetime] cloning) fix in https://github.com/apple/swift/pull/32031/commits/6f5d4ccd3da998c1ab1addcd5b0039ddcf3ee768.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @dan-zheng
Priority Medium

md5: d0dcf67e4ff40651e95783289bd4f86d

relates to:

  • SR-12886 SIL memory ownership error for differentiation transform + definite initialization

Issue Description:

import _Differentiation

enum Enum {
  case a
}

struct Tensor<T>: Differentiable {
  @noDerivative var x: T
  @noDerivative var optional: Int?

  init(_ x: T, _ e: Enum) {
    self.x = x
    switch e {
      case .a: optional = 1
    }
  }

  // Definite initialization triggers for this initializer.
  @differentiable
  init(_ x: T, _ other: Self) {
    self = Self(x, Enum.a)
  }
}
$ swift crash.swift
SIL verification failed: Basic block contains a non-contiguous lexical scope at -Onone: DS == LastSeenScope
Verifying instruction:
     %25 = builtin "trunc_Int2_Int1"(%24 : $Builtin.Int2) : $Builtin.Int1 // user: %27
->   cond_br %25, bb1, bb2                        // id: %27
In function:
// AD__$s5crash6TensorVyACyxGx_ADtcfC__vjp_src_0_wrt_1_l
sil hidden [ossa] @AD__$s5crash6TensorVyACyxGx_ADtcfC__vjp_src_0_wrt_1_l : $@convention(method) <τ_0_0> (@in τ_0_0, @in Tensor<τ_0_0>, @thin Tensor<τ_0_0>.Type) -> (@out Tensor<τ_0_0>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <Tensor<τ_0_0>.TangentVector, Tensor<τ_0_0>.TangentVector>) {
// %0                                             // user: %61
// %1                                             // users: %63, %17, %8
// %2                                             // users: %62, %9
bb0(%0 : $*Tensor<τ_0_0>, %1 : $*τ_0_0, %2 : $*Tensor<τ_0_0>, %3 : $@thin Tensor<τ_0_0>.Type):
  %4 = alloc_stack $Builtin.Int2                  // users: %67, %57, %39, %24, %7
  %5 = alloc_stack [dynamic_lifetime] $Tensor<τ_0_0>, var, name "self" // users: %65, %64, %61, %46, %29, %23, %12
  %6 = integer_literal $Builtin.Int2, 0           // user: %7
  store %6 to [trivial] %4 : $*Builtin.Int2       // id: %7
  debug_value_addr %1 : $*τ_0_0, let, name "x", argno 1 // id: %8
  debug_value_addr %2 : $*Tensor<τ_0_0>, let, name "other", argno 2 // id: %9
  // function_ref variable initialization expression of Tensor.optional
  %10 = function_ref @$s5crash6TensorV8optionalSiSgvpfi : $@convention(thin) <τ_0_0> () -> Optional<Int> // user: %11
  %11 = apply %10<τ_0_0>() : $@convention(thin) <τ_0_0> () -> Optional<Int> // user: %13
  %12 = struct_element_addr %5 : $*Tensor<τ_0_0>, #Tensor.optional // user: %13
  store %11 to [trivial] %12 : $*Optional<Int>    // id: %13
  %14 = alloc_stack $Tensor<τ_0_0>               // users: %60, %58, %21
  %15 = metatype $@thin Tensor<τ_0_0>.Type       // user: %21
  %16 = alloc_stack $τ_0_0                       // users: %22, %21, %17
  copy_addr %1 to [initialization] %16 : $*τ_0_0 // id: %17
  %18 = metatype $@thin Enum.Type
  %19 = enum $Enum, #Enum.a!enumelt               // user: %21
  // function_ref Tensor.init(_:_:)
  %20 = function_ref @$s5crash6TensorVyACyxGx_AA4EnumOtcfC : $@convention(method) <τ_0_0> (@in τ_0_0, Enum, @thin Tensor<τ_0_0>.Type) -> @out Tensor<τ_0_0> // user: %21
  %21 = apply %20<τ_0_0>(%14, %16, %19, %15) : $@convention(method) <τ_0_0> (@in τ_0_0, Enum, @thin Tensor<τ_0_0>.Type) -> @out Tensor<τ_0_0>
  dealloc_stack %16 : $*τ_0_0                    // id: %22
  %23 = begin_access [modify] [static] %5 : $*Tensor<τ_0_0> // users: %59, %58
  %24 = load [trivial] %4 : $*Builtin.Int2        // user: %25
  %25 = builtin "trunc_Int2_Int1"(%24 : $Builtin.Int2) : $Builtin.Int1 // user: %27
  %26 = struct $_AD__$s5crash6TensorVyACyxGx_ADtcfC_bb0__PB__src_0_wrt_1_l<τ_0_0> () // users: %34, %28
  cond_br %25, bb1, bb2                           // id: %27

The debug scope issue is related to the VJP-generated pullback struct struct instruction:

%26 = struct $_AD__$s5crash6TensorVyACyxGx_ADtcfC_bb0__PB__src_0_wrt_1_l<τ_0_0> ()
@dan-zheng
Copy link
Collaborator Author

Fixed in #32031

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

2 participants