Skip to content

Commit 841ad94

Browse files
committed
Update UI tests
1 parent 0218840 commit 841ad94

11 files changed

+84
-114
lines changed

compiler/rustc_builtin_macros/messages.ftl

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ builtin_macros_assert_requires_expression = macro requires an expression as an a
7171
7272
builtin_macros_autodiff = autodiff must be applied to function
7373
builtin_macros_autodiff_missing_config = autodiff requires at least a name and mode
74-
builtin_macros_autodiff_mode = unknown Mode: `{$mode}`. Use `Forward` or `Reverse`
7574
builtin_macros_autodiff_mode_activity = {$act} can not be used in {$mode} Mode
7675
builtin_macros_autodiff_not_build = this rustc version does not support autodiff
7776
builtin_macros_autodiff_number_activities = expected {$expected} activities, but found {$found}

compiler/rustc_builtin_macros/src/autodiff.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mod llvm_enzyme {
8686
ecx: &mut ExtCtxt<'_>,
8787
meta_item: &ThinVec<MetaItemInner>,
8888
has_ret: bool,
89+
mode: DiffMode,
8990
) -> AutoDiffAttrs {
9091
let dcx = ecx.sess.dcx();
9192

@@ -145,7 +146,7 @@ mod llvm_enzyme {
145146
};
146147

147148
AutoDiffAttrs {
148-
mode: DiffMode::Error,
149+
mode,
149150
width,
150151
ret_activity: *ret_activity,
151152
input_activity: input_activity.to_vec(),
@@ -313,8 +314,7 @@ mod llvm_enzyme {
313314
ts.pop();
314315
let ts: TokenStream = TokenStream::from_iter(ts);
315316

316-
let mut x: AutoDiffAttrs = from_ast(ecx, &meta_item_vec, has_ret);
317-
x.mode = mode;
317+
let x: AutoDiffAttrs = from_ast(ecx, &meta_item_vec, has_ret, mode);
318318
if !x.is_active() {
319319
// We encountered an error, so we return the original item.
320320
// This allows us to potentially parse other attributes.

tests/ui/autodiff/autodiff_illegal.rs

+23-37
Original file line numberDiff line numberDiff line change
@@ -7,75 +7,75 @@
77

88
// Test that invalid ad macros give nice errors and don't ICE.
99

10-
use std::autodiff::autodiff;
10+
use std::autodiff::{autodiff_forward, autodiff_reverse};
1111

1212
// We can't use Duplicated on scalars
13-
#[autodiff(df1, Reverse, Duplicated)]
13+
#[autodiff_reverse(df1, Duplicated)]
1414
pub fn f1(x: f64) {
1515
//~^ ERROR Duplicated can not be used for this type
1616
unimplemented!()
1717
}
1818

1919
// Too many activities
20-
#[autodiff(df3, Reverse, Duplicated, Const)]
20+
#[autodiff_reverse(df3, Duplicated, Const)]
2121
pub fn f3(x: f64) {
2222
//~^^ ERROR expected 1 activities, but found 2
2323
unimplemented!()
2424
}
2525

2626
// To few activities
27-
#[autodiff(df4, Reverse)]
27+
#[autodiff_reverse(df4)]
2828
pub fn f4(x: f64) {
2929
//~^^ ERROR expected 1 activities, but found 0
3030
unimplemented!()
3131
}
3232

3333
// We can't use Dual in Reverse mode
34-
#[autodiff(df5, Reverse, Dual)]
34+
#[autodiff_reverse(df5, Dual)]
3535
pub fn f5(x: f64) {
3636
//~^^ ERROR Dual can not be used in Reverse Mode
3737
unimplemented!()
3838
}
3939

4040
// We can't use Duplicated in Forward mode
41-
#[autodiff(df6, Forward, Duplicated)]
41+
#[autodiff_forward(df6, Duplicated)]
4242
pub fn f6(x: f64) {
4343
//~^^ ERROR Duplicated can not be used in Forward Mode
4444
//~^^ ERROR Duplicated can not be used for this type
4545
unimplemented!()
4646
}
4747

4848
fn dummy() {
49-
#[autodiff(df7, Forward, Dual)]
49+
#[autodiff_forward(df7, Dual)]
5050
let mut x = 5;
5151
//~^ ERROR autodiff must be applied to function
5252

53-
#[autodiff(df7, Forward, Dual)]
53+
#[autodiff_forward(df7, Dual)]
5454
x = x + 3;
5555
//~^^ ERROR attributes on expressions are experimental [E0658]
5656
//~^^ ERROR autodiff must be applied to function
5757

58-
#[autodiff(df7, Forward, Dual)]
58+
#[autodiff_forward(df7, Dual)]
5959
let add_one_v2 = |x: u32| -> u32 { x + 1 };
6060
//~^ ERROR autodiff must be applied to function
6161
}
6262

6363
// Malformed, where args?
64-
#[autodiff]
64+
#[autodiff_forward]
6565
pub fn f7(x: f64) {
6666
//~^ ERROR autodiff requires at least a name and mode
6767
unimplemented!()
6868
}
6969

7070
// Malformed, where args?
71-
#[autodiff()]
71+
#[autodiff_forward()]
7272
pub fn f8(x: f64) {
7373
//~^ ERROR autodiff requires at least a name and mode
7474
unimplemented!()
7575
}
7676

7777
// Invalid attribute syntax
78-
#[autodiff = ""]
78+
#[autodiff_forward = ""]
7979
pub fn f9(x: f64) {
8080
//~^ ERROR autodiff requires at least a name and mode
8181
unimplemented!()
@@ -84,29 +84,15 @@ pub fn f9(x: f64) {
8484
fn fn_exists() {}
8585

8686
// We colide with an already existing function
87-
#[autodiff(fn_exists, Reverse, Active)]
87+
#[autodiff_reverse(fn_exists, Active)]
8888
pub fn f10(x: f64) {
8989
//~^^ ERROR the name `fn_exists` is defined multiple times [E0428]
9090
unimplemented!()
9191
}
9292

93-
// Malformed, missing a mode
94-
#[autodiff(df11)]
95-
pub fn f11() {
96-
//~^ ERROR autodiff requires at least a name and mode
97-
unimplemented!()
98-
}
99-
100-
// Invalid Mode
101-
#[autodiff(df12, Debug)]
102-
pub fn f12() {
103-
//~^^ ERROR unknown Mode: `Debug`. Use `Forward` or `Reverse`
104-
unimplemented!()
105-
}
106-
10793
// Invalid, please pick one Mode
10894
// or use two autodiff macros.
109-
#[autodiff(df13, Forward, Reverse)]
95+
#[autodiff_reverse(df13, Reverse)]
11096
pub fn f13() {
11197
//~^^ ERROR did not recognize Activity: `Reverse`
11298
unimplemented!()
@@ -117,7 +103,7 @@ struct Foo {}
117103
// We can't handle Active structs, because that would mean (in the general case), that we would
118104
// need to allocate and initialize arbitrary user types. We have Duplicated/Dual input args for
119105
// that. FIXME: Give a nicer error and suggest to the user to have a `&mut Foo` input instead.
120-
#[autodiff(df14, Reverse, Active, Active)]
106+
#[autodiff_reverse(df14, Active, Active)]
121107
fn f14(x: f32) -> Foo {
122108
unimplemented!()
123109
}
@@ -127,14 +113,14 @@ type MyFloat = f32;
127113
// We would like to support type alias to f32/f64 in argument type in the future,
128114
// but that requires us to implement our checks at a later stage
129115
// like THIR which has type information available.
130-
#[autodiff(df15, Reverse, Active, Active)]
116+
#[autodiff_reverse(df15, Active, Active)]
131117
fn f15(x: MyFloat) -> f32 {
132118
//~^^ ERROR failed to resolve: use of undeclared type `MyFloat` [E0433]
133119
unimplemented!()
134120
}
135121

136122
// We would like to support type alias to f32/f64 in return type in the future
137-
#[autodiff(df16, Reverse, Active, Active)]
123+
#[autodiff_reverse(df16, Active, Active)]
138124
fn f16(x: f32) -> MyFloat {
139125
unimplemented!()
140126
}
@@ -145,40 +131,40 @@ struct F64Trans {
145131
}
146132

147133
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in return type in the future
148-
#[autodiff(df17, Reverse, Active, Active)]
134+
#[autodiff_reverse(df17, Active, Active)]
149135
fn f17(x: f64) -> F64Trans {
150136
unimplemented!()
151137
}
152138

153139
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in argument type in the future
154-
#[autodiff(df18, Reverse, Active, Active)]
140+
#[autodiff_reverse(df18, Active, Active)]
155141
fn f18(x: F64Trans) -> f64 {
156142
//~^^ ERROR failed to resolve: use of undeclared type `F64Trans` [E0433]
157143
unimplemented!()
158144
}
159145

160146
// Invalid return activity
161-
#[autodiff(df19, Forward, Dual, Active)]
147+
#[autodiff_forward(df19, Dual, Active)]
162148
fn f19(x: f32) -> f32 {
163149
//~^^ ERROR invalid return activity Active in Forward Mode
164150
unimplemented!()
165151
}
166152

167-
#[autodiff(df20, Reverse, Active, Dual)]
153+
#[autodiff_reverse(df20, Active, Dual)]
168154
fn f20(x: f32) -> f32 {
169155
//~^^ ERROR invalid return activity Dual in Reverse Mode
170156
unimplemented!()
171157
}
172158

173159
// Duplicated cannot be used as return activity
174-
#[autodiff(df21, Reverse, Active, Duplicated)]
160+
#[autodiff_reverse(df21, Active, Duplicated)]
175161
fn f21(x: f32) -> f32 {
176162
//~^^ ERROR invalid return activity Duplicated in Reverse Mode
177163
unimplemented!()
178164
}
179165

180166
struct DoesNotImplDefault;
181-
#[autodiff(df22, Forward, Dual)]
167+
#[autodiff_forward(df22, Dual)]
182168
pub fn f22() -> DoesNotImplDefault {
183169
//~^^ ERROR the function or associated item `default` exists for tuple `(DoesNotImplDefault, DoesNotImplDefault)`, but its trait bounds were not satisfied
184170
unimplemented!()

tests/ui/autodiff/autodiff_illegal.stderr

+34-49
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: attributes on expressions are experimental
22
--> $DIR/autodiff_illegal.rs:53:5
33
|
4-
LL | #[autodiff(df7, Forward, Dual)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | #[autodiff_forward(df7, Dual)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
@@ -17,26 +17,26 @@ LL | pub fn f1(x: f64) {
1717
error: expected 1 activities, but found 2
1818
--> $DIR/autodiff_illegal.rs:20:1
1919
|
20-
LL | #[autodiff(df3, Reverse, Duplicated, Const)]
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
LL | #[autodiff_reverse(df3, Duplicated, Const)]
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222

2323
error: expected 1 activities, but found 0
2424
--> $DIR/autodiff_illegal.rs:27:1
2525
|
26-
LL | #[autodiff(df4, Reverse)]
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
26+
LL | #[autodiff_reverse(df4)]
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^
2828

2929
error: Dual can not be used in Reverse Mode
3030
--> $DIR/autodiff_illegal.rs:34:1
3131
|
32-
LL | #[autodiff(df5, Reverse, Dual)]
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | #[autodiff_reverse(df5, Dual)]
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

3535
error: Duplicated can not be used in Forward Mode
3636
--> $DIR/autodiff_illegal.rs:41:1
3737
|
38-
LL | #[autodiff(df6, Forward, Duplicated)]
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
LL | #[autodiff_forward(df6, Duplicated)]
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040

4141
error: Duplicated can not be used for this type
4242
--> $DIR/autodiff_illegal.rs:42:14
@@ -95,69 +95,54 @@ error[E0428]: the name `fn_exists` is defined multiple times
9595
LL | fn fn_exists() {}
9696
| -------------- previous definition of the value `fn_exists` here
9797
...
98-
LL | #[autodiff(fn_exists, Reverse, Active)]
99-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `fn_exists` redefined here
98+
LL | #[autodiff_reverse(fn_exists, Active)]
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `fn_exists` redefined here
100100
|
101101
= note: `fn_exists` must be defined only once in the value namespace of this module
102102

103-
error: autodiff requires at least a name and mode
104-
--> $DIR/autodiff_illegal.rs:95:1
105-
|
106-
LL | / pub fn f11() {
107-
LL | |
108-
LL | | unimplemented!()
109-
LL | | }
110-
| |_^
111-
112-
error: unknown Mode: `Debug`. Use `Forward` or `Reverse`
113-
--> $DIR/autodiff_illegal.rs:101:18
114-
|
115-
LL | #[autodiff(df12, Debug)]
116-
| ^^^^^
117-
118103
error: did not recognize Activity: `Reverse`
119-
--> $DIR/autodiff_illegal.rs:109:27
104+
--> $DIR/autodiff_illegal.rs:95:26
120105
|
121-
LL | #[autodiff(df13, Forward, Reverse)]
122-
| ^^^^^^^
106+
LL | #[autodiff_reverse(df13, Reverse)]
107+
| ^^^^^^^
123108

124109
error: invalid return activity Active in Forward Mode
125-
--> $DIR/autodiff_illegal.rs:161:1
110+
--> $DIR/autodiff_illegal.rs:147:1
126111
|
127-
LL | #[autodiff(df19, Forward, Dual, Active)]
128-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112+
LL | #[autodiff_forward(df19, Dual, Active)]
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129114

130115
error: invalid return activity Dual in Reverse Mode
131-
--> $DIR/autodiff_illegal.rs:167:1
116+
--> $DIR/autodiff_illegal.rs:153:1
132117
|
133-
LL | #[autodiff(df20, Reverse, Active, Dual)]
134-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118+
LL | #[autodiff_reverse(df20, Active, Dual)]
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135120

136121
error: invalid return activity Duplicated in Reverse Mode
137-
--> $DIR/autodiff_illegal.rs:174:1
122+
--> $DIR/autodiff_illegal.rs:160:1
138123
|
139-
LL | #[autodiff(df21, Reverse, Active, Duplicated)]
140-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
LL | #[autodiff_reverse(df21, Active, Duplicated)]
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141126

142127
error[E0433]: failed to resolve: use of undeclared type `MyFloat`
143-
--> $DIR/autodiff_illegal.rs:130:1
128+
--> $DIR/autodiff_illegal.rs:116:1
144129
|
145-
LL | #[autodiff(df15, Reverse, Active, Active)]
146-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `MyFloat`
130+
LL | #[autodiff_reverse(df15, Active, Active)]
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `MyFloat`
147132

148133
error[E0433]: failed to resolve: use of undeclared type `F64Trans`
149-
--> $DIR/autodiff_illegal.rs:154:1
134+
--> $DIR/autodiff_illegal.rs:140:1
150135
|
151-
LL | #[autodiff(df18, Reverse, Active, Active)]
152-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `F64Trans`
136+
LL | #[autodiff_reverse(df18, Active, Active)]
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `F64Trans`
153138

154139
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
140+
--> $DIR/autodiff_illegal.rs:167:1
156141
|
157142
LL | struct DoesNotImplDefault;
158143
| ------------------------- doesn't satisfy `DoesNotImplDefault: Default`
159-
LL | #[autodiff(df22, Forward, Dual)]
160-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item cannot be called on `(DoesNotImplDefault, DoesNotImplDefault)` due to unsatisfied trait bounds
144+
LL | #[autodiff_forward(df22, Dual)]
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item cannot be called on `(DoesNotImplDefault, DoesNotImplDefault)` due to unsatisfied trait bounds
161146
|
162147
= note: the following trait bounds were not satisfied:
163148
`DoesNotImplDefault: Default`
@@ -168,7 +153,7 @@ LL + #[derive(Default)]
168153
LL | struct DoesNotImplDefault;
169154
|
170155

171-
error: aborting due to 23 previous errors
156+
error: aborting due to 21 previous errors
172157

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

tests/ui/autodiff/auxiliary/my_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ use proc_macro::TokenStream;
33

44
#[proc_macro_attribute]
55
#[macro_use]
6-
pub fn autodiff(_attr: TokenStream, item: TokenStream) -> TokenStream {
6+
pub fn autodiff_forward(_attr: TokenStream, item: TokenStream) -> TokenStream {
77
item // identity proc-macro
88
}

0 commit comments

Comments
 (0)