-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathside_effects.swift
42 lines (35 loc) · 1.25 KB
/
side_effects.swift
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
// RUN: %target-swift-frontend -emit-sil -verify %s
func simpleStoreLoad(x: Float) -> Float {
var y = x
y = x + 1
// expected-note @+1 {{expression is not differentiable}}
return y
}
// expected-error @+1 {{function is not differentiable}}
let _: @autodiff (Float) -> Float = simpleStoreLoad(x:)
var global: Float = 10
// Test differentiation of write to non-useful global variable.
let _: @autodiff (Float) -> Float = { x in
global = x
return x * x
}
// Test differentiation of write to non-useful local variable.
let _: @autodiff (Float) -> Float = { x in
var local = x // expected-warning {{initialization of variable 'local' was never used}}
return x + x
}
// Test differentiation of write to useful global variable.
// expected-error @+1 {{function is not differentiable}}
let _: @autodiff (Float) -> Float = { x in
global = x
// expected-note @+1 {{expression is not differentiable}}
return global + x
}
// Test differentiation of write to useful local variable.
// expected-error @+1 {{function is not differentiable}}
let _: @autodiff (Float) -> Float = { x in
var local = x // expected-warning {{variable 'local' was never mutated}}
// expected-note @+1 {{expression is not differentiable}}
return local + x
}
// TODO: Add file checks.