Skip to content

Commit e52c76c

Browse files
committed
Graceful error for wrong number of activities
Blessed tests
1 parent 2205455 commit e52c76c

File tree

3 files changed

+84
-70
lines changed

3 files changed

+84
-70
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1987,9 +1987,9 @@ dependencies = [
19871987

19881988
[[package]]
19891989
name = "jsonpath-rust"
1990-
version = "1.0.0"
1990+
version = "1.0.1"
19911991
source = "registry+https://github.com/rust-lang/crates.io-index"
1992-
checksum = "9b0231bb404a6cd6c8f0ab41b907049063a089fc02aa7636cc5cd9a4d87364c9"
1992+
checksum = "6a37c2c87b8d16e788ce359660fead0ea5f4ed29ff400d55be74a4e01d1817d9"
19931993
dependencies = [
19941994
"pest",
19951995
"pest_derive",

tests/ui/autodiff/autodiff_illegal.rs

+40-32
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ pub fn f4(x: f64) {
3030
unimplemented!()
3131
}
3232

33+
34+
#[autodiff(df5, Forward, Dual, Dual)]
35+
fn f5(x: f32, y: f32) -> f32 {
36+
//~^^ ERROR expected 3 activities, but found 2
37+
x + y
38+
}
39+
40+
3341
// We can't use Dual in Reverse mode
34-
#[autodiff(df5, Reverse, Dual)]
35-
pub fn f5(x: f64) {
42+
#[autodiff(df6, Reverse, Dual)]
43+
pub fn f6(x: f64) {
3644
//~^^ ERROR Dual can not be used in Reverse Mode
3745
unimplemented!()
3846
}
3947

4048
// We can't use Duplicated in Forward mode
41-
#[autodiff(df6, Forward, Duplicated)]
42-
pub fn f6(x: f64) {
49+
#[autodiff(df7, Forward, Duplicated)]
50+
pub fn f7(x: f64) {
4351
//~^^ ERROR Duplicated can not be used in Forward Mode
4452
//~^^ ERROR Duplicated can not be used for this type
4553
unimplemented!()
@@ -62,21 +70,21 @@ fn dummy() {
6270

6371
// Malformed, where args?
6472
#[autodiff]
65-
pub fn f7(x: f64) {
73+
pub fn f8(x: f64) {
6674
//~^ ERROR autodiff requires at least a name and mode
6775
unimplemented!()
6876
}
6977

7078
// Malformed, where args?
7179
#[autodiff()]
72-
pub fn f8(x: f64) {
80+
pub fn f9(x: f64) {
7381
//~^ ERROR autodiff requires at least a name and mode
7482
unimplemented!()
7583
}
7684

7785
// Invalid attribute syntax
7886
#[autodiff = ""]
79-
pub fn f9(x: f64) {
87+
pub fn f10(x: f64) {
8088
//~^ ERROR autodiff requires at least a name and mode
8189
unimplemented!()
8290
}
@@ -85,29 +93,29 @@ fn fn_exists() {}
8593

8694
// We colide with an already existing function
8795
#[autodiff(fn_exists, Reverse, Active)]
88-
pub fn f10(x: f64) {
96+
pub fn f11(x: f64) {
8997
//~^^ ERROR the name `fn_exists` is defined multiple times [E0428]
9098
unimplemented!()
9199
}
92100

93101
// Malformed, missing a mode
94-
#[autodiff(df11)]
95-
pub fn f11() {
102+
#[autodiff(df12)]
103+
pub fn f12() {
96104
//~^ ERROR autodiff requires at least a name and mode
97105
unimplemented!()
98106
}
99107

100108
// Invalid Mode
101-
#[autodiff(df12, Debug)]
102-
pub fn f12() {
109+
#[autodiff(df13, Debug)]
110+
pub fn f13() {
103111
//~^^ ERROR unknown Mode: `Debug`. Use `Forward` or `Reverse`
104112
unimplemented!()
105113
}
106114

107115
// Invalid, please pick one Mode
108116
// or use two autodiff macros.
109-
#[autodiff(df13, Forward, Reverse)]
110-
pub fn f13() {
117+
#[autodiff(df14, Forward, Reverse)]
118+
pub fn f14() {
111119
//~^^ ERROR did not recognize Activity: `Reverse`
112120
unimplemented!()
113121
}
@@ -117,8 +125,8 @@ struct Foo {}
117125
// We can't handle Active structs, because that would mean (in the general case), that we would
118126
// need to allocate and initialize arbitrary user types. We have Duplicated/Dual input args for
119127
// that. FIXME: Give a nicer error and suggest to the user to have a `&mut Foo` input instead.
120-
#[autodiff(df14, Reverse, Active, Active)]
121-
fn f14(x: f32) -> Foo {
128+
#[autodiff(df15, Reverse, Active, Active)]
129+
fn f15(x: f32) -> Foo {
122130
unimplemented!()
123131
}
124132

@@ -127,15 +135,15 @@ type MyFloat = f32;
127135
// We would like to support type alias to f32/f64 in argument type in the future,
128136
// but that requires us to implement our checks at a later stage
129137
// like THIR which has type information available.
130-
#[autodiff(df15, Reverse, Active, Active)]
131-
fn f15(x: MyFloat) -> f32 {
138+
#[autodiff(df16, Reverse, Active, Active)]
139+
fn f16(x: MyFloat) -> f32 {
132140
//~^^ ERROR failed to resolve: use of undeclared type `MyFloat` [E0433]
133141
unimplemented!()
134142
}
135143

136144
// We would like to support type alias to f32/f64 in return type in the future
137-
#[autodiff(df16, Reverse, Active, Active)]
138-
fn f16(x: f32) -> MyFloat {
145+
#[autodiff(df17, Reverse, Active, Active)]
146+
fn f17(x: f32) -> MyFloat {
139147
unimplemented!()
140148
}
141149

@@ -145,41 +153,41 @@ struct F64Trans {
145153
}
146154

147155
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in return type in the future
148-
#[autodiff(df17, Reverse, Active, Active)]
149-
fn f17(x: f64) -> F64Trans {
156+
#[autodiff(df18, Reverse, Active, Active)]
157+
fn f18(x: f64) -> F64Trans {
150158
unimplemented!()
151159
}
152160

153161
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in argument type in the future
154-
#[autodiff(df18, Reverse, Active, Active)]
155-
fn f18(x: F64Trans) -> f64 {
162+
#[autodiff(df19, Reverse, Active, Active)]
163+
fn f19(x: F64Trans) -> f64 {
156164
//~^^ ERROR failed to resolve: use of undeclared type `F64Trans` [E0433]
157165
unimplemented!()
158166
}
159167

160168
// Invalid return activity
161-
#[autodiff(df19, Forward, Dual, Active)]
162-
fn f19(x: f32) -> f32 {
169+
#[autodiff(df20, Forward, Dual, Active)]
170+
fn f20(x: f32) -> f32 {
163171
//~^^ ERROR invalid return activity Active in Forward Mode
164172
unimplemented!()
165173
}
166174

167-
#[autodiff(df20, Reverse, Active, Dual)]
168-
fn f20(x: f32) -> f32 {
175+
#[autodiff(df21, Reverse, Active, Dual)]
176+
fn f21(x: f32) -> f32 {
169177
//~^^ ERROR invalid return activity Dual in Reverse Mode
170178
unimplemented!()
171179
}
172180

173181
// Duplicated cannot be used as return activity
174-
#[autodiff(df21, Reverse, Active, Duplicated)]
175-
fn f21(x: f32) -> f32 {
182+
#[autodiff(df22, Reverse, Active, Duplicated)]
183+
fn f22(x: f32) -> f32 {
176184
//~^^ ERROR invalid return activity Duplicated in Reverse Mode
177185
unimplemented!()
178186
}
179187

180188
struct DoesNotImplDefault;
181-
#[autodiff(df22, Forward, Dual)]
182-
pub fn f22() -> DoesNotImplDefault {
189+
#[autodiff(df23, Forward, Dual)]
190+
pub fn f23() -> DoesNotImplDefault {
183191
//~^^ ERROR the function or associated item `default` exists for tuple `(DoesNotImplDefault, DoesNotImplDefault)`, but its trait bounds were not satisfied
184192
unimplemented!()
185193
}
+42-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/autodiff_illegal.rs:53:5
2+
--> $DIR/autodiff_illegal.rs:61:5
33
|
44
LL | #[autodiff(df7, Forward, Dual)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,71 +26,77 @@ error: expected 1 activities, but found 0
2626
LL | #[autodiff(df4, Reverse)]
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2828

29-
error: Dual can not be used in Reverse Mode
29+
error: expected 3 activities, but found 2
3030
--> $DIR/autodiff_illegal.rs:34:1
3131
|
32-
LL | #[autodiff(df5, Reverse, Dual)]
32+
LL | #[autodiff(df5, Forward, Dual, Dual)]
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
error: Dual can not be used in Reverse Mode
36+
--> $DIR/autodiff_illegal.rs:42:1
37+
|
38+
LL | #[autodiff(df6, Reverse, Dual)]
3339
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3440

3541
error: Duplicated can not be used in Forward Mode
36-
--> $DIR/autodiff_illegal.rs:41:1
42+
--> $DIR/autodiff_illegal.rs:49:1
3743
|
38-
LL | #[autodiff(df6, Forward, Duplicated)]
44+
LL | #[autodiff(df7, Forward, Duplicated)]
3945
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4046

4147
error: Duplicated can not be used for this type
42-
--> $DIR/autodiff_illegal.rs:42:14
48+
--> $DIR/autodiff_illegal.rs:50:14
4349
|
44-
LL | pub fn f6(x: f64) {
50+
LL | pub fn f7(x: f64) {
4551
| ^^^
4652

4753
error: autodiff must be applied to function
48-
--> $DIR/autodiff_illegal.rs:50:5
54+
--> $DIR/autodiff_illegal.rs:58:5
4955
|
5056
LL | let mut x = 5;
5157
| ^^^^^^^^^^^^^^
5258

5359
error: autodiff must be applied to function
54-
--> $DIR/autodiff_illegal.rs:54:5
60+
--> $DIR/autodiff_illegal.rs:62:5
5561
|
5662
LL | x = x + 3;
5763
| ^
5864

5965
error: autodiff must be applied to function
60-
--> $DIR/autodiff_illegal.rs:59:5
66+
--> $DIR/autodiff_illegal.rs:67:5
6167
|
6268
LL | let add_one_v2 = |x: u32| -> u32 { x + 1 };
6369
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6470

6571
error: autodiff requires at least a name and mode
66-
--> $DIR/autodiff_illegal.rs:65:1
72+
--> $DIR/autodiff_illegal.rs:73:1
6773
|
68-
LL | / pub fn f7(x: f64) {
74+
LL | / pub fn f8(x: f64) {
6975
LL | |
7076
LL | | unimplemented!()
7177
LL | | }
7278
| |_^
7379

7480
error: autodiff requires at least a name and mode
75-
--> $DIR/autodiff_illegal.rs:72:1
81+
--> $DIR/autodiff_illegal.rs:80:1
7682
|
77-
LL | / pub fn f8(x: f64) {
83+
LL | / pub fn f9(x: f64) {
7884
LL | |
7985
LL | | unimplemented!()
8086
LL | | }
8187
| |_^
8288

8389
error: autodiff requires at least a name and mode
84-
--> $DIR/autodiff_illegal.rs:79:1
90+
--> $DIR/autodiff_illegal.rs:87:1
8591
|
86-
LL | / pub fn f9(x: f64) {
92+
LL | / pub fn f10(x: f64) {
8793
LL | |
8894
LL | | unimplemented!()
8995
LL | | }
9096
| |_^
9197

9298
error[E0428]: the name `fn_exists` is defined multiple times
93-
--> $DIR/autodiff_illegal.rs:87:1
99+
--> $DIR/autodiff_illegal.rs:95:1
94100
|
95101
LL | fn fn_exists() {}
96102
| -------------- previous definition of the value `fn_exists` here
@@ -101,62 +107,62 @@ LL | #[autodiff(fn_exists, Reverse, Active)]
101107
= note: `fn_exists` must be defined only once in the value namespace of this module
102108

103109
error: autodiff requires at least a name and mode
104-
--> $DIR/autodiff_illegal.rs:95:1
110+
--> $DIR/autodiff_illegal.rs:103:1
105111
|
106-
LL | / pub fn f11() {
112+
LL | / pub fn f12() {
107113
LL | |
108114
LL | | unimplemented!()
109115
LL | | }
110116
| |_^
111117

112118
error: unknown Mode: `Debug`. Use `Forward` or `Reverse`
113-
--> $DIR/autodiff_illegal.rs:101:18
119+
--> $DIR/autodiff_illegal.rs:109:18
114120
|
115-
LL | #[autodiff(df12, Debug)]
121+
LL | #[autodiff(df13, Debug)]
116122
| ^^^^^
117123

118124
error: did not recognize Activity: `Reverse`
119-
--> $DIR/autodiff_illegal.rs:109:27
125+
--> $DIR/autodiff_illegal.rs:117:27
120126
|
121-
LL | #[autodiff(df13, Forward, Reverse)]
127+
LL | #[autodiff(df14, Forward, Reverse)]
122128
| ^^^^^^^
123129

124130
error: invalid return activity Active in Forward Mode
125-
--> $DIR/autodiff_illegal.rs:161:1
131+
--> $DIR/autodiff_illegal.rs:169:1
126132
|
127-
LL | #[autodiff(df19, Forward, Dual, Active)]
133+
LL | #[autodiff(df20, Forward, Dual, Active)]
128134
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129135

130136
error: invalid return activity Dual in Reverse Mode
131-
--> $DIR/autodiff_illegal.rs:167:1
137+
--> $DIR/autodiff_illegal.rs:175:1
132138
|
133-
LL | #[autodiff(df20, Reverse, Active, Dual)]
139+
LL | #[autodiff(df21, Reverse, Active, Dual)]
134140
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135141

136142
error: invalid return activity Duplicated in Reverse Mode
137-
--> $DIR/autodiff_illegal.rs:174:1
143+
--> $DIR/autodiff_illegal.rs:182:1
138144
|
139-
LL | #[autodiff(df21, Reverse, Active, Duplicated)]
145+
LL | #[autodiff(df22, Reverse, Active, Duplicated)]
140146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141147

142148
error[E0433]: failed to resolve: use of undeclared type `MyFloat`
143-
--> $DIR/autodiff_illegal.rs:130:1
149+
--> $DIR/autodiff_illegal.rs:138:1
144150
|
145-
LL | #[autodiff(df15, Reverse, Active, Active)]
151+
LL | #[autodiff(df16, Reverse, Active, Active)]
146152
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `MyFloat`
147153

148154
error[E0433]: failed to resolve: use of undeclared type `F64Trans`
149-
--> $DIR/autodiff_illegal.rs:154:1
155+
--> $DIR/autodiff_illegal.rs:162:1
150156
|
151-
LL | #[autodiff(df18, Reverse, Active, Active)]
157+
LL | #[autodiff(df19, Reverse, Active, Active)]
152158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `F64Trans`
153159

154160
error[E0599]: the function or associated item `default` exists for tuple `(DoesNotImplDefault, DoesNotImplDefault)`, but its trait bounds were not satisfied
155-
--> $DIR/autodiff_illegal.rs:181:1
161+
--> $DIR/autodiff_illegal.rs:189:1
156162
|
157163
LL | struct DoesNotImplDefault;
158164
| ------------------------- doesn't satisfy `DoesNotImplDefault: Default`
159-
LL | #[autodiff(df22, Forward, Dual)]
165+
LL | #[autodiff(df23, Forward, Dual)]
160166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item cannot be called on `(DoesNotImplDefault, DoesNotImplDefault)` due to unsatisfied trait bounds
161167
|
162168
= note: the following trait bounds were not satisfied:
@@ -168,7 +174,7 @@ LL + #[derive(Default)]
168174
LL | struct DoesNotImplDefault;
169175
|
170176

171-
error: aborting due to 23 previous errors
177+
error: aborting due to 24 previous errors
172178

173179
Some errors have detailed explanations: E0428, E0433, E0599, E0658.
174180
For more information about an error, try `rustc --explain E0428`.

0 commit comments

Comments
 (0)