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-14298] [AutoDiff] SIL verification failed: non-contiguous lexical scope at -Onone #56657

Closed
porterchild opened this issue Mar 3, 2021 · 4 comments
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@porterchild
Copy link

Previous ID SR-14298
Radar rdar://problem/75032457
Original Reporter @porterchild
Type Bug
Status Resolved
Resolution Done
Environment

March 2 trunk development snapshot

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee pgp (JIRA)
Priority Medium

md5: 0ac9e4192078cd22013515dcfa95cd57

relates to:

  • SR-8114 [TensorFlow] Compilation without -O causes SIL verification failure
  • SR-14290 SIL verification fails when differentiating a function of [[Double]]

Issue Description:

This code crashes the compiler with error

SIL verification failed: Basic block contains a non-contiguous lexical scope at -Onone  
import _Differentiation

struct Thing<Val> {
    var value: Val
    
    @differentiable(where Val: Differentiable)
    init(value: Val) {
        self.value = value
    }
}

extension Thing: Differentiable where Val: Differentiable {}

@differentiable(where Value: Differentiable)
func getOccurrences<Value>(values: [Value]) -> [Thing<Value>] {
    var things: [Thing<Value>] = []
    for i in 0 ..< withoutDerivative(at: values.count) {
        let value = values[i]
        if true {
            things = things + [Thing<Value>(value: value)]
        }
    }
    return things
}

This only happens when compiling without -O

Also, I've got this error happening a different piece of code that doesn't involve differentiation, so it may not necessarily be autodiff-related.

SIL verification failed: Basic block contains a non-contiguous lexical scope at -Onone: DS == LastSeenScope Verifying instruction:    **%528** = destructure_struct %527 : $_AD__$s28NonContiguousLexicalScopeBug5ThingV14getOccurrences33_E3F95842A6EF6C7599ACA2F797783456LL6valuesSayAA10OccurencesAELLVyq_GGSayq_G_tF_bb10__PB__src_0_wrt_0_16_Differentiation14DifferentiableR_r0_l<τ_0_0, τ_0_1> // user: %539 ->   switch_enum %528 : $_AD__$s28NonContiguousLexicalScopeBug5ThingV14getOccurrences33_E3F95842A6EF6C7599ACA2F797783456LL6valuesSayAA10OccurencesAELLVyq_GGSayq_G_tF_bb10__Pred__src_0_wrt_0_16_Differentiation14DifferentiableR_r0_l<τ_0_0, τ_0_1>, case #_AD__$s28NonContiguousLexicalScopeBug5ThingV14getOccurrences33_E3F95842A6EF6C7599ACA2F797783456LL6valuesSayAA10OccurencesAELLVyq_GGSayq_G_tF_bb10__Pred__src_0_wrt_0_16_Differentiation14DifferentiableR_r0_l.bb8!enumelt: bb9 // id: %539 In function: // pullback of Thing.getOccurrences(values:) sil private [ossa] @$s28NonContiguousLexicalScopeBug5ThingV14getOccurrences33_E3F95842A6EF6C7599ACA2F797783456LL6valuesSayAA10OccurencesAELLVyq_GGSayq_G_tF16_Differentiation14DifferentiableR_r0_lTJpSUpSr : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Differentiable> (@guaranteed Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView, @guaranteed Builtin.NativeObject) -> @owned Array<τ_0_1.TangentVector>.DifferentiableView { // %0                                             // user: %161 // %1                                             // user: %147 bb0(%0 : @guaranteed $Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView, %1 : @guaranteed $Builtin.NativeObject):   %2 = alloc_stack $Occurences<τ_0_1>.TangentVector // users: %5, %446, %349, %348, %443, %442   %3 = metatype $@thin Occurences<τ_0_1>.TangentVector.Type // user: %5   // function_ref static Occurences<A>.TangentVector.zero.getter   %4 = function_ref @$s28NonContiguousLexicalScopeBug10Occurences33_E3F95842A6EF6C7599ACA2F797783456LLVAA16_Differentiation14DifferentiableRzlE13TangentVectorV4zeroAHyx_GvgZ : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@thin Occurences<τ_0_0>.TangentVector.Type) -> @out Occurences<τ_0_0>.TangentVector // user: %5   %5 = apply %4<τ_0_1>(%2, %3) : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@thin Occurences<τ_0_0>.TangentVector.Type) -> @out Occurences<τ_0_0>.TangentVector   %6 = tuple ()   %7 = alloc_stack $τ_0_1.TangentVector           // users: %347, %346, %243, %10   %8 = witness_method $τ_0_1.TangentVector, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %10   %9 = metatype $@thick τ_0_1.TangentVector.Type  // user: %10   %10 = apply %8<τ_0_1.TangentVector>(%7, %9) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0   %11 = alloc_stack $Occurences<τ_0_1>.TangentVector // users: %14, %345, %344, %242, %241, %240   %12 = metatype $@thin Occurences<τ_0_1>.TangentVector.Type // user: %14   // function_ref static Occurences<A>.TangentVector.zero.getter   %13 = function_ref @$s28NonContiguousLexicalScopeBug10Occurences33_E3F95842A6EF6C7599ACA2F797783456LLVAA16_Differentiation14DifferentiableRzlE13TangentVectorV4zeroAHyx_GvgZ : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@thin Occurences<τ_0_0>.TangentVector.Type) -> @out Occurences<τ_0_0>.TangentVector // user: %14   %14 = apply %13<τ_0_1>(%11, %12) : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@thin Occurences<τ_0_0>.TangentVector.Type) -> @out Occurences<τ_0_0>.TangentVector   %15 = tuple ()   %16 = alloc_stack $τ_0_1.TangentVector, let, name "value" // users: %343, %342, %193, %19   %17 = witness_method $τ_0_1.TangentVector, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %19   %18 = metatype $@thick τ_0_1.TangentVector.Type // user: %19   %19 = apply %17<τ_0_1.TangentVector>(%16, %18) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0   %20 = alloc_stack $Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView, var, name "occurrences" // users: %174, %24, %165, %341, %340   %21 = metatype $@thin Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView.Type // user: %23   // function_ref static Array.DifferentiableView<A>.zero.getter   %22 = function_ref @$sSa16_DifferentiationE18DifferentiableViewVAAs18AdditiveArithmeticRzAA0B0RzlE4zeroACyx_GvgZ : $@convention(method) <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> (@thin Array<τ_0_0>.DifferentiableView.Type) -> @owned Array<τ_0_0>.DifferentiableView // user: %23   %23 = apply %22<Occurences<τ_0_1>.TangentVector>(%21) : $@convention(method) <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> (@thin Array<τ_0_0>.DifferentiableView.Type) -> @owned Array<τ_0_0>.DifferentiableView // user: %24   store %23 to [init] %20 : $*Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView // id: %24   %25 = tuple ()   %26 = alloc_stack $τ_0_1.TangentVector, let, name "value" // users: %339, %338, %730, %707, %686, %29   %27 = witness_method $τ_0_1.TangentVector, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %29   %28 = metatype $@thick τ_0_1.TangentVector.Type // user: %29   %29 = apply %27<τ_0_1.TangentVector>(%26, %28) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0   %30 = alloc_stack $Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView, var, name "occurrences" // users: %731, %685, %689, %706, %710, %692, %713, %34, %337, %336, %729   %31 = metatype $@thin Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView.Type // user: %33   // function_ref static Array.DifferentiableView<A>.zero.getter   %32 = function_ref @$sSa16_DifferentiationE18DifferentiableViewVAAs18AdditiveArithmeticRzAA0B0RzlE4zeroACyx_GvgZ : $@convention(method) <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> (@thin Array<τ_0_0>.DifferentiableView.Type) -> @owned Array<τ_0_0>.DifferentiableView // user: %33   %33 = apply %32<Occurences<τ_0_1>.TangentVector>(%31) : $@convention(method) <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> (@thin Array<τ_0_0>.DifferentiableView.Type) -> @owned Array<τ_0_0>.DifferentiableView // user: %34   store %33 to [init] %30 : $*Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView // id: %34   %35 = tuple ()   %36 = alloc_stack $τ_0_1.TangentVector, let, name "value" // users: %335, %334, %707, %615, %39   %37 = witness_method $τ_0_1.TangentVector, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %39   %38 = metatype $@thick τ_0_1.TangentVector.Type // user: %39   %39 = apply %37<τ_0_1.TangentVector>(%36, %38) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0   %40 = alloc_stack $Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView, var, name "occurrences" // users: %614, %618, %624, %44, %333, %332   %41 = metatype $@thin Array<Occurences<τ_0_1>.TangentVector>.DifferentiableView.Type // user: %43   // function_ref static Array.DifferentiableView<A>.zero.getter   %42 = 

...
@porterchild
Copy link
Author

@rxwei

@typesanitizer
Copy link

@swift-ci create

@rxwei
Copy link
Member

rxwei commented Apr 21, 2021

#36974

@BradLarson
Copy link
Collaborator

@rxwei - A locally-built Linux toolchain incorporating PR #36974 does indeed appear to build the above just fine for -Onone, where it had failed before that. Thanks, pgp (JIRA User)!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants