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-14227] [AutoDiff] SIL verification failed: method does not appear in the class's vtable #54721

Open
dan-zheng opened this issue Feb 28, 2020 · 1 comment
Assignees
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-14227
Radar None
Original Reporter @dan-zheng
Type Bug
Status In Progress
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee @dan-zheng
Priority Medium

md5: 6fcf38e9571d104b4dea6dc6c60f31ae

Issue Description:

public protocol TensorView {
    associatedtype Element
}
public protocol DifferentiableTensorView: TensorView & Differentiable where Self == TangentVector {}

public protocol PlatformAPI {
    @differentiable
    func abs<T>(_ x: T) -> T where T: DifferentiableTensorView, T.Element: Numeric
}
public class CpuService: PlatformAPI {
  @differentiable
  public func abs<T>(_ x: T) -> T where T: DifferentiableTensorView, T.Element: Numeric { x }
}

public final class Platform {
    public static var service: PlatformAPI = CpuService()
}

@differentiable(where T: DifferentiableTensorView)
public func abs<T: DifferentiableTensorView>(_ x: T) -> T where T.Element: Numeric {
  Platform.service.abs(x)
}
SIL verification failed: method does not appear in the class's vtable: VerifyClassMethodVisitor(member).Seen
Verifying instruction:
     %3 = load_borrow %2 : $*CpuService           // users: %6, %5, %4
->   %4 = class_method %3 : $CpuService, #CpuService.abs!1.jvp.SU.<Self, T where Self : PlatformAPI, T : DifferentiableTensorView, T.Element : Numeric> : <T where T : DifferentiableTensorView, T.Element : Numeric> (CpuService) -> (T) -> T, $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %5
     %5 = apply %4<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %7
In function:
// AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU
sil shared [transparent] [serialized] [thunk] [ossa] @AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU : $@convention(witness_method: PlatformAPI) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @in_guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) {
// %0                                             // user: %5
// %1                                             // user: %5
// %2                                             // user: %3
bb0(%0 : $*τ_0_0, %1 : $*τ_0_0, %2 : $*CpuService):
  %3 = load_borrow %2 : $*CpuService              // users: %6, %5, %4
  %4 = class_method %3 : $CpuService, #CpuService.abs!1.jvp.SU.<Self, T where Self : PlatformAPI, T : DifferentiableTensorView, T.Element : Numeric> : <T where T : DifferentiableTensorView, T.Element : Numeric> (CpuService) -> (T) -> T, $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %5
  %5 = apply %4<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : DifferentiableTensorView, τ_0_0.Element : Numeric> (@in_guaranteed τ_0_0, @guaranteed CpuService) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0) // user: %7
  end_borrow %3 : $CpuService                     // id: %6
  return %5 : $@callee_guaranteed (@in_guaranteed τ_0_0) -> @out τ_0_0 // id: %7
} // end sil function 'AD__$s3abs10CpuServiceCAA11PlatformAPIA2aDPAAyqd__qd__AA24DifferentiableTensorViewRd__Sj7ElementAA0gH0PRpd__lFTW_jvp_SU'  
@dan-zheng
Copy link
Collaborator Author

A minimized reproducer (thanks to Shadaj):

import _Differentiation

protocol DifferentiableBase {
    @differentiable func myFunc(_ input: Float) -> Float
}

class MyClass: DifferentiableBase {
    @differentiable
    public func myFunc(_ input: Float) -> Float {
        return input
    }
}
SIL verification failed: method does not appear in the class's vtable: VerifyClassMethodVisitor(member).Seen
Verifying instruction:
     %2 = load_borrow %1 : $*MyClass              // users: %8, %4, %3
->   %3 = class_method %2 : $MyClass, #MyClass.myFunc!jvp.SU.<Self where Self : DifferentiableBase> : (MyClass) -> (Float) -> Float, $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %4
     %4 = apply %3(%0, %2) : $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %5
In function:
// AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU
sil private [transparent] [thunk] [ossa] @AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU : $@convention(witness_method: DifferentiableBase) (Float, @in_guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
// %0                                             // user: %4
// %1                                             // user: %2
bb0(%0 : $Float, %1 : $*MyClass):
  %2 = load_borrow %1 : $*MyClass                 // users: %8, %4, %3
  %3 = class_method %2 : $MyClass, #MyClass.myFunc!jvp.SU.<Self where Self : DifferentiableBase> : (MyClass) -> (Float) -> Float, $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %4
  %4 = apply %3(%0, %2) : $@convention(method) (Float, @guaranteed MyClass) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %5
  (%5, %6) = destructure_tuple %4 : $(Float, @callee_guaranteed (Float) -> Float) // users: %7, %7
  %7 = tuple (%5 : $Float, %6 : $@callee_guaranteed (Float) -> Float) // user: %9
  end_borrow %2 : $MyClass                        // id: %8
  return %7 : $(Float, @callee_guaranteed (Float) -> Float) // id: %9
} // end sil function 'AD__$s4main7MyClassCAA18DifferentiableBaseA2aDP6myFuncyS2fFTW_jvp_SU'

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

1 participant