Skip to content

Commit b18854f

Browse files
committed
moved the tests to new dir
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
1 parent 7f4bcb5 commit b18854f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+359
-23
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//@ needs-enzyme
2+
3+
#![feature(autodiff)]
4+
//@ pretty-mode:expanded
5+
//@ pretty-compare-only
6+
//@ pp-exact:autodiff_illegal.pp
7+
8+
// Test that invalid ad macros give nice errors and don't ICE.
9+
10+
use std::autodiff::{autodiff_forward, autodiff_reverse};
11+
12+
// We can't use Duplicated on scalars
13+
#[autodiff_reverse(df1, Duplicated)]
14+
pub fn f1(x: f64) {
15+
//~^ ERROR Duplicated can not be used for this type
16+
unimplemented!()
17+
}
18+
19+
// Too many activities
20+
#[autodiff_reverse(df3, Duplicated, Const)]
21+
pub fn f3(x: f64) {
22+
//~^^ ERROR expected 1 activities, but found 2
23+
unimplemented!()
24+
}
25+
26+
// To few activities
27+
#[autodiff_reverse(df4)]
28+
pub fn f4(x: f64) {
29+
//~^^ ERROR expected 1 activities, but found 0
30+
unimplemented!()
31+
}
32+
33+
// We can't use Dual in Reverse mode
34+
#[autodiff_reverse(df5, Dual)]
35+
pub fn f5(x: f64) {
36+
//~^^ ERROR Dual can not be used in Reverse Mode
37+
unimplemented!()
38+
}
39+
40+
// We can't use Duplicated in Forward mode
41+
#[autodiff_forward(df6, Duplicated)]
42+
pub fn f6(x: f64) {
43+
//~^^ ERROR Duplicated can not be used in Forward Mode
44+
//~^^ ERROR Duplicated can not be used for this type
45+
unimplemented!()
46+
}
47+
48+
fn dummy() {
49+
#[autodiff_forward(df7, Dual)]
50+
let mut x = 5;
51+
//~^ ERROR autodiff must be applied to function
52+
53+
#[autodiff_forward(df7, Dual)]
54+
x = x + 3;
55+
//~^^ ERROR attributes on expressions are experimental [E0658]
56+
//~^^ ERROR autodiff must be applied to function
57+
58+
#[autodiff_forward(df7, Dual)]
59+
let add_one_v2 = |x: u32| -> u32 { x + 1 };
60+
//~^ ERROR autodiff must be applied to function
61+
}
62+
63+
// Malformed, where args?
64+
#[autodiff_forward]
65+
pub fn f7(x: f64) {
66+
//~^ ERROR autodiff requires at least a name and mode
67+
unimplemented!()
68+
}
69+
70+
// Malformed, where args?
71+
#[autodiff_forward()]
72+
pub fn f8(x: f64) {
73+
//~^ ERROR autodiff requires at least a name and mode
74+
unimplemented!()
75+
}
76+
77+
// Invalid attribute syntax
78+
#[autodiff_forward = ""]
79+
pub fn f9(x: f64) {
80+
//~^ ERROR autodiff requires at least a name and mode
81+
unimplemented!()
82+
}
83+
84+
fn fn_exists() {}
85+
86+
// We colide with an already existing function
87+
#[autodiff_reverse(fn_exists, Active)]
88+
pub fn f10(x: f64) {
89+
//~^^ ERROR the name `fn_exists` is defined multiple times [E0428]
90+
unimplemented!()
91+
}
92+
93+
// Invalid, please pick one Mode
94+
// or use two autodiff macros.
95+
#[autodiff_reverse(df13, Reverse)]
96+
pub fn f13() {
97+
//~^^ ERROR did not recognize Activity: `Reverse`
98+
unimplemented!()
99+
}
100+
101+
struct Foo {}
102+
103+
// We can't handle Active structs, because that would mean (in the general case), that we would
104+
// need to allocate and initialize arbitrary user types. We have Duplicated/Dual input args for
105+
// that. FIXME: Give a nicer error and suggest to the user to have a `&mut Foo` input instead.
106+
#[autodiff_reverse(df14, Active, Active)]
107+
fn f14(x: f32) -> Foo {
108+
unimplemented!()
109+
}
110+
111+
type MyFloat = f32;
112+
113+
// We would like to support type alias to f32/f64 in argument type in the future,
114+
// but that requires us to implement our checks at a later stage
115+
// like THIR which has type information available.
116+
#[autodiff_reverse(df15, Active, Active)]
117+
fn f15(x: MyFloat) -> f32 {
118+
//~^^ ERROR failed to resolve: use of undeclared type `MyFloat` [E0433]
119+
unimplemented!()
120+
}
121+
122+
// We would like to support type alias to f32/f64 in return type in the future
123+
#[autodiff_reverse(df16, Active, Active)]
124+
fn f16(x: f32) -> MyFloat {
125+
unimplemented!()
126+
}
127+
128+
#[repr(transparent)]
129+
struct F64Trans {
130+
inner: f64,
131+
}
132+
133+
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in return type in the future
134+
#[autodiff_reverse(df17, Active, Active)]
135+
fn f17(x: f64) -> F64Trans {
136+
unimplemented!()
137+
}
138+
139+
// We would like to support `#[repr(transparent)]` f32/f64 wrapper in argument type in the future
140+
#[autodiff_reverse(df18, Active, Active)]
141+
fn f18(x: F64Trans) -> f64 {
142+
//~^^ ERROR failed to resolve: use of undeclared type `F64Trans` [E0433]
143+
unimplemented!()
144+
}
145+
146+
// Invalid return activity
147+
#[autodiff_forward(df19, Dual, Active)]
148+
fn f19(x: f32) -> f32 {
149+
//~^^ ERROR invalid return activity Active in Forward Mode
150+
unimplemented!()
151+
}
152+
153+
#[autodiff_reverse(df20, Active, Dual)]
154+
fn f20(x: f32) -> f32 {
155+
//~^^ ERROR invalid return activity Dual in Reverse Mode
156+
unimplemented!()
157+
}
158+
159+
// Duplicated cannot be used as return activity
160+
#[autodiff_reverse(df21, Active, Duplicated)]
161+
fn f21(x: f32) -> f32 {
162+
//~^^ ERROR invalid return activity Duplicated in Reverse Mode
163+
unimplemented!()
164+
}
165+
166+
struct DoesNotImplDefault;
167+
#[autodiff_forward(df22, Dual)]
168+
pub fn f22() -> DoesNotImplDefault {
169+
//~^^ ERROR the function or associated item `default` exists for tuple `(DoesNotImplDefault, DoesNotImplDefault)`, but its trait bounds were not satisfied
170+
unimplemented!()
171+
}
172+
173+
fn main() {}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
error[E0658]: attributes on expressions are experimental
2+
--> $DIR/autodiff_illegal.rs:53:5
3+
|
4+
LL | #[autodiff_forward(df7, Dual)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
8+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: Duplicated can not be used for this type
12+
--> $DIR/autodiff_illegal.rs:14:14
13+
|
14+
LL | pub fn f1(x: f64) {
15+
| ^^^
16+
17+
error: expected 1 activities, but found 2
18+
--> $DIR/autodiff_illegal.rs:20:1
19+
|
20+
LL | #[autodiff_reverse(df3, Duplicated, Const)]
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
error: expected 1 activities, but found 0
24+
--> $DIR/autodiff_illegal.rs:27:1
25+
|
26+
LL | #[autodiff_reverse(df4)]
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^
28+
29+
error: Dual can not be used in Reverse Mode
30+
--> $DIR/autodiff_illegal.rs:34:1
31+
|
32+
LL | #[autodiff_reverse(df5, Dual)]
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
error: Duplicated can not be used in Forward Mode
36+
--> $DIR/autodiff_illegal.rs:41:1
37+
|
38+
LL | #[autodiff_forward(df6, Duplicated)]
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
41+
error: Duplicated can not be used for this type
42+
--> $DIR/autodiff_illegal.rs:42:14
43+
|
44+
LL | pub fn f6(x: f64) {
45+
| ^^^
46+
47+
error: autodiff must be applied to function
48+
--> $DIR/autodiff_illegal.rs:50:5
49+
|
50+
LL | let mut x = 5;
51+
| ^^^^^^^^^^^^^^
52+
53+
error: autodiff must be applied to function
54+
--> $DIR/autodiff_illegal.rs:54:5
55+
|
56+
LL | x = x + 3;
57+
| ^
58+
59+
error: autodiff must be applied to function
60+
--> $DIR/autodiff_illegal.rs:59:5
61+
|
62+
LL | let add_one_v2 = |x: u32| -> u32 { x + 1 };
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
65+
error: autodiff requires at least a name and mode
66+
--> $DIR/autodiff_illegal.rs:65:1
67+
|
68+
LL | / pub fn f7(x: f64) {
69+
LL | |
70+
LL | | unimplemented!()
71+
LL | | }
72+
| |_^
73+
74+
error: autodiff requires at least a name and mode
75+
--> $DIR/autodiff_illegal.rs:72:1
76+
|
77+
LL | / pub fn f8(x: f64) {
78+
LL | |
79+
LL | | unimplemented!()
80+
LL | | }
81+
| |_^
82+
83+
error: autodiff requires at least a name and mode
84+
--> $DIR/autodiff_illegal.rs:79:1
85+
|
86+
LL | / pub fn f9(x: f64) {
87+
LL | |
88+
LL | | unimplemented!()
89+
LL | | }
90+
| |_^
91+
92+
error[E0428]: the name `fn_exists` is defined multiple times
93+
--> $DIR/autodiff_illegal.rs:87:1
94+
|
95+
LL | fn fn_exists() {}
96+
| -------------- previous definition of the value `fn_exists` here
97+
...
98+
LL | #[autodiff_reverse(fn_exists, Active)]
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `fn_exists` redefined here
100+
|
101+
= note: `fn_exists` must be defined only once in the value namespace of this module
102+
103+
error: did not recognize Activity: `Reverse`
104+
--> $DIR/autodiff_illegal.rs:95:26
105+
|
106+
LL | #[autodiff_reverse(df13, Reverse)]
107+
| ^^^^^^^
108+
109+
error: invalid return activity Active in Forward Mode
110+
--> $DIR/autodiff_illegal.rs:147:1
111+
|
112+
LL | #[autodiff_forward(df19, Dual, Active)]
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
115+
error: invalid return activity Dual in Reverse Mode
116+
--> $DIR/autodiff_illegal.rs:153:1
117+
|
118+
LL | #[autodiff_reverse(df20, Active, Dual)]
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
121+
error: invalid return activity Duplicated in Reverse Mode
122+
--> $DIR/autodiff_illegal.rs:160:1
123+
|
124+
LL | #[autodiff_reverse(df21, Active, Duplicated)]
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126+
127+
error[E0433]: failed to resolve: use of undeclared type `MyFloat`
128+
--> $DIR/autodiff_illegal.rs:116:1
129+
|
130+
LL | #[autodiff_reverse(df15, Active, Active)]
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `MyFloat`
132+
133+
error[E0433]: failed to resolve: use of undeclared type `F64Trans`
134+
--> $DIR/autodiff_illegal.rs:140:1
135+
|
136+
LL | #[autodiff_reverse(df18, Active, Active)]
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `F64Trans`
138+
139+
error[E0599]: the function or associated item `default` exists for tuple `(DoesNotImplDefault, DoesNotImplDefault)`, but its trait bounds were not satisfied
140+
--> $DIR/autodiff_illegal.rs:167:1
141+
|
142+
LL | struct DoesNotImplDefault;
143+
| ------------------------- doesn't satisfy `DoesNotImplDefault: Default`
144+
LL | #[autodiff_forward(df22, Dual)]
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item cannot be called on `(DoesNotImplDefault, DoesNotImplDefault)` due to unsatisfied trait bounds
146+
|
147+
= note: the following trait bounds were not satisfied:
148+
`DoesNotImplDefault: Default`
149+
which is required by `(DoesNotImplDefault, DoesNotImplDefault): Default`
150+
help: consider annotating `DoesNotImplDefault` with `#[derive(Default)]`
151+
|
152+
LL + #[derive(Default)]
153+
LL | struct DoesNotImplDefault;
154+
|
155+
156+
error: aborting due to 21 previous errors
157+
158+
Some errors have detailed explanations: E0428, E0433, E0599, E0658.
159+
For more information about an error, try `rustc --explain E0428`.

tests/ui/autodiff/box.rs renamed to tests/ui/autodiff/type-trees/type-anyalsis/box.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
//@ needs-enzyme
55
//@ normalize-stderr: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
66
//@ normalize-stderr: "%[0-9]+" -> "%X"
7+
//@ normalize-stderr: "!nonnull ![0-9]+" -> "!nonnull !N"
8+
//@ normalize-stderr: "!align ![0-9]+" -> "!align !N"
79
//@ normalize-stdout: "!(dbg|noundef) ![0-9]+" -> "!$1 !N"
810
//@ normalize-stdout: "%[0-9]+" -> "%X"
11+
//@ normalize-stdout: "!nonnull ![0-9]+" -> "!nonnull !N"
12+
//@ normalize-stdout: "!align ![0-9]+" -> "!align !N"
913

1014
#![feature(autodiff)]
1115

0 commit comments

Comments
 (0)