Skip to content

[SR-13168] SILGen: add SIL default witness table entries for default derivatives of protocol requirements #55610

@dan-zheng

Description

@dan-zheng
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions