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-13168] SILGen: add SIL default witness table entries for default derivatives of protocol requirements #55610

Open
dan-zheng opened this issue Jul 7, 2020 · 2 comments
Labels
compiler The Swift compiler in itself

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-13168
Radar rdar://problem/69987700
Original Reporter @dan-zheng
Type Sub-task
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Sub-task
Assignee None
Priority Medium

md5: 06cd5fd689baa87628f642979fcf9761

Parent-Task:

  • SR-13166 Default derivative implementations for protocol requirements

Issue Description:

Resilient protocol default implementations are encoded in SIL default witness tables: https://github.com/apple/swift/blob/master/docs/SIL.rst#default-witness-tables.

Derivatives registered for protocol requirements should be lowered to entries in SIL default witness tables. SILDeclRef already has support for derivative functions (via SILDeclRef::derivativeFunctionIdentifier).

protocol P {
  static func +(lhs: Self, rhs: Self) -> Self
}

extension P where Self: Differentiable {
  @derivative(of: add)
  static func vjpAdd(lhs: Self, rhs: Self) -> (value: Self, pullback: (TangentVector) -> (TangentVector, TangentVector)) {
    return (lhs + rhs, { v in (v, v) }
  }
}

The default derivative P.vjpAdd should appear in a default witness table for P.

You can start implementing this by:

  • Finding existing SILGen logic for generating default witness tables. Add logic that finds derivatives registered for protocol requirements (@derivative) and emits default witness table entries for those derivatives.

  • You can test generated default witness tables via swiftc -emit-silgen.

@rxwei
Copy link
Member

rxwei commented Oct 6, 2020

@swift-ci create

@rxwei
Copy link
Member

rxwei commented Apr 3, 2021

This is only relevant for resilience.

@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
compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants