File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change 1
- //@ run-pass
1
+ //! This test verifies that mutually recursive functions implemented using CPS
2
+ //! are correctly handled by the compiler. Specifically, it checks that such recursive calls
3
+ //! execute without stack overflow, implying proper tail call optimization in a CPS context.
2
4
3
- fn checktrue ( rs : bool ) -> bool { assert ! ( rs ) ; return true ; }
5
+ //@ run-pass
4
6
5
- pub fn main ( ) { let k = checktrue; evenk ( 42 , k) ; oddk ( 45 , k) ; }
7
+ fn f ( x : isize , cont : fn ( isize ) ) {
8
+ if x == 0 {
9
+ cont ( 0 ) ;
10
+ } else {
11
+ g ( x - 1 , |y| cont ( y + 1 ) ) ;
12
+ }
13
+ }
6
14
7
- fn evenk ( n : isize , k : fn ( bool ) -> bool ) -> bool {
8
- println ! ( "evenk" ) ;
9
- println ! ( "{}" , n) ;
10
- if n == 0 { return k ( true ) ; } else { return oddk ( n - 1 , k) ; }
15
+ fn g ( x : isize , cont : fn ( isize ) ) {
16
+ if x == 0 {
17
+ cont ( 0 ) ;
18
+ } else {
19
+ f ( x - 1 , |y| cont ( y + 1 ) ) ;
20
+ }
11
21
}
12
22
13
- fn oddk ( n : isize , k : fn ( bool ) -> bool ) -> bool {
14
- println ! ( "oddk" ) ;
15
- println ! ( "{}" , n) ;
16
- if n == 0 { return k ( false ) ; } else { return evenk ( n - 1 , k) ; }
23
+ pub fn main ( ) {
24
+ f ( 100000 , |_x| { } ) ; // Test deep recursion
25
+ g ( 100000 , |_x| { } ) ; // Test deep recursion
17
26
}
You can’t perform that action at this time.
0 commit comments