File: mangling.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (47 lines) | stat: -rw-r--r-- 4,886 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// RUN: %target-swift-frontend -emit-sil -enable-experimental-forward-mode-differentiation -module-name=mangling -verify %s | %FileCheck %s

import _Differentiation

@differentiable(reverse)
func foo(_ x: Float) -> Float { x }

// CHECK-LABEL: sil_differentiability_witness hidden [reverse] [parameters 0] [results 0] @$s8mangling3fooyS2fF : $@convention(thin) (Float) -> Float {
// CHECK:  jvp: @$s8mangling3fooyS2fFTJfSpSr : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// CHECK:  vjp: @$s8mangling3fooyS2fFTJrSpSr : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)

@differentiable(reverse)
func generic<T: Differentiable>(_ x: T) -> T { x }

// CHECK-LABEL: sil_differentiability_witness hidden [reverse] [parameters 0] [results 0] <T where T : Differentiable> @$s8mangling7genericyxx16_Differentiation14DifferentiableRzlF : $@convention(thin) <T where T : Differentiable> (@in_guaranteed T) -> @out T {
// CHECK:  jvp: @$s8mangling7genericyxx16_Differentiation14DifferentiableRzlFAcDRzlTJfSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector>)
// CHECK:  vjp: @$s8mangling7genericyxx16_Differentiation14DifferentiableRzlFAcDRzlTJrSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector>)

@differentiable(reverse where T: Differentiable)
func genericConstrained<T>(_ x: T) -> T { x }

// CHECK-LABEL: sil_differentiability_witness hidden [reverse] [parameters 0] [results 0] <T where T : Differentiable> @$s8mangling18genericConstrainedyxxlF : $@convention(thin) <T> (@in_guaranteed T) -> @out T {
// CHECK:  jvp: @$s8mangling18genericConstrainedyxxlF16_Differentiation14DifferentiableRzlTJfSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector>)
// CHECK:  vjp: @$s8mangling18genericConstrainedyxxlF16_Differentiation14DifferentiableRzlTJrSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0) -> (@out τ_0_0, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector>)

class Class: Differentiable {
  @differentiable(reverse, wrt: (self, x))
  @differentiable(reverse, wrt: x)
  func f(_ x: Float) -> Float { x }
}

// CHECK-LABEL: sil_differentiability_witness hidden [reverse] [parameters 0] [results 0] @$s8mangling5ClassC1fyS2fF : $@convention(method) (Float, @guaranteed Class) -> Float {
// CHECK:  jvp: @$s8mangling5ClassC1fyS2fFTJfSUpSr : $@convention(method) (Float, @guaranteed Class) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// CHECK:  vjp: @$s8mangling5ClassC1fyS2fFTJrSUpSr : $@convention(method) (Float, @guaranteed Class) -> (Float, @owned @callee_guaranteed (Float) -> Float)

func test<C: Class>(_ c: C, _ x: Float) {
  _ = gradient(at: c, x) { c, x in c.f(x) }
  _ = gradient(at: x) { x in c.f(x) }
}

// CHECK-LABEL: sil_differentiability_witness private [reverse] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Class> @$s8mangling4testyyx_SftAA5ClassCRbzlFS2fcfU0_ : $@convention(thin) <C where C : Class> (Float, @guaranteed C) -> Float {
// CHECK:  jvp: @$s8mangling4testyyx_SftAA5ClassCRbzlFS2fcfU0_ADRbzlTJfSUpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Class> (Float, @guaranteed τ_0_0) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// CHECK:  vjp: @$s8mangling4testyyx_SftAA5ClassCRbzlFS2fcfU0_ADRbzlTJrSUpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Class> (Float, @guaranteed τ_0_0) -> (Float, @owned @callee_guaranteed (Float) -> Float)

// CHECK-LABEL: sil_differentiability_witness private [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Class> @$s8mangling4testyyx_SftAA5ClassCRbzlFSfx_SftcfU_ : $@convention(thin) <C where C : Class> (@guaranteed C, Float) -> Float {
// CHECK:  jvp: @$s8mangling4testyyx_SftAA5ClassCRbzlFSfx_SftcfU_ADRbzlTJfSSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Class> (@guaranteed τ_0_0, Float) -> (Float, @owned @callee_guaranteed @substituted <τ_0_0> (@guaranteed τ_0_0, Float) -> Float for <τ_0_0.TangentVector>)
// CHECK:  vjp: @$s8mangling4testyyx_SftAA5ClassCRbzlFSfx_SftcfU_ADRbzlTJrSSpSr : $@convention(thin) <τ_0_0 where τ_0_0 : Class> (@guaranteed τ_0_0, Float) -> (Float, @owned @callee_guaranteed @substituted <τ_0_0> (Float) -> (τ_0_0, Float) for <τ_0_0.TangentVector>)