forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursive-struct.rs
238 lines (201 loc) · 6.58 KB
/
recursive-struct.rs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// ignore-lldb
// ignore-gdb-version: 7.11.90 - 7.12.9
// compile-flags:-g
// gdb-command:run
// gdb-command:print stack_unique.value
// gdb-check:$1 = 0
// gdbg-command:print stack_unique.next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdbr-command:print stack_unique.next.val.value
// gdb-check:$2 = 1
// gdbg-command:print unique_unique->value
// gdbr-command:print unique_unique.value
// gdb-check:$3 = 2
// gdbg-command:print unique_unique->next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdbr-command:print unique_unique.next.val.value
// gdb-check:$4 = 3
// gdb-command:print vec_unique[0].value
// gdb-check:$5 = 6.5
// gdbg-command:print vec_unique[0].next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdbr-command:print vec_unique[0].next.val.value
// gdb-check:$6 = 7.5
// gdbg-command:print borrowed_unique->value
// gdbr-command:print borrowed_unique.value
// gdb-check:$7 = 8.5
// gdbg-command:print borrowed_unique->next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdbr-command:print borrowed_unique.next.val.value
// gdb-check:$8 = 9.5
// LONG CYCLE
// gdb-command:print long_cycle1.value
// gdb-check:$9 = 20
// gdbg-command:print long_cycle1.next->value
// gdbr-command:print long_cycle1.next.value
// gdb-check:$10 = 21
// gdbg-command:print long_cycle1.next->next->value
// gdbr-command:print long_cycle1.next.next.value
// gdb-check:$11 = 22
// gdbg-command:print long_cycle1.next->next->next->value
// gdbr-command:print long_cycle1.next.next.next.value
// gdb-check:$12 = 23
// gdb-command:print long_cycle2.value
// gdb-check:$13 = 24
// gdbg-command:print long_cycle2.next->value
// gdbr-command:print long_cycle2.next.value
// gdb-check:$14 = 25
// gdbg-command:print long_cycle2.next->next->value
// gdbr-command:print long_cycle2.next.next.value
// gdb-check:$15 = 26
// gdb-command:print long_cycle3.value
// gdb-check:$16 = 27
// gdbg-command:print long_cycle3.next->value
// gdbr-command:print long_cycle3.next.value
// gdb-check:$17 = 28
// gdb-command:print long_cycle4.value
// gdb-check:$18 = 29.5
// gdbg-command:print (*****long_cycle_w_anonymous_types).value
// gdbr-command:print long_cycle_w_anonymous_types.value
// gdb-check:$19 = 30
// gdbg-command:print (*****((*****long_cycle_w_anonymous_types).next.RUST$ENCODED$ENUM$0$Empty.val)).value
// gdbr-command:print long_cycle_w_anonymous_types.next.val.value
// gdb-check:$20 = 31
// gdb-command:continue
#![allow(unused_variables)]
#![feature(box_syntax)]
#![feature(omit_gdb_pretty_printer_section)]
#![omit_gdb_pretty_printer_section]
use self::Opt::{Empty, Val};
enum Opt<T> {
Empty,
Val { val: T }
}
struct UniqueNode<T> {
next: Opt<Box<UniqueNode<T>>>,
value: T
}
struct LongCycle1<T> {
next: Box<LongCycle2<T>>,
value: T,
}
struct LongCycle2<T> {
next: Box<LongCycle3<T>>,
value: T,
}
struct LongCycle3<T> {
next: Box<LongCycle4<T>>,
value: T,
}
struct LongCycle4<T> {
next: Option<Box<LongCycle1<T>>>,
value: T,
}
struct LongCycleWithAnonymousTypes {
next: Opt<Box<Box<Box<Box<Box<LongCycleWithAnonymousTypes>>>>>>,
value: usize,
}
// This test case makes sure that recursive structs are properly described. The Node structs are
// generic so that we can have a new type (that newly needs to be described) for the different
// cases. The potential problem with recursive types is that the DI generation algorithm gets
// trapped in an endless loop. To make sure, we actually test this in the different cases, we have
// to operate on a new type each time, otherwise we would just hit the DI cache for all but the
// first case.
// The different cases below (stack_*, unique_*, box_*, etc) are set up so that the type description
// algorithm will enter the type reference cycle that is created by a recursive definition from a
// different context each time.
// The "long cycle" cases are constructed to span a longer, indirect recursion cycle between types.
// The different locals will cause the DI algorithm to enter the type reference cycle at different
// points.
fn main() {
let stack_unique: UniqueNode<u16> = UniqueNode {
next: Val {
val: box UniqueNode {
next: Empty,
value: 1,
}
},
value: 0,
};
let unique_unique: Box<UniqueNode<u32>> = box UniqueNode {
next: Val {
val: box UniqueNode {
next: Empty,
value: 3,
}
},
value: 2,
};
let vec_unique: [UniqueNode<f32>; 1] = [UniqueNode {
next: Val {
val: box UniqueNode {
next: Empty,
value: 7.5,
}
},
value: 6.5,
}];
let borrowed_unique: &UniqueNode<f64> = &UniqueNode {
next: Val {
val: box UniqueNode {
next: Empty,
value: 9.5,
}
},
value: 8.5,
};
// LONG CYCLE
let long_cycle1: LongCycle1<u16> = LongCycle1 {
next: box LongCycle2 {
next: box LongCycle3 {
next: box LongCycle4 {
next: None,
value: 23,
},
value: 22,
},
value: 21
},
value: 20
};
let long_cycle2: LongCycle2<u32> = LongCycle2 {
next: box LongCycle3 {
next: box LongCycle4 {
next: None,
value: 26,
},
value: 25,
},
value: 24
};
let long_cycle3: LongCycle3<u64> = LongCycle3 {
next: box LongCycle4 {
next: None,
value: 28,
},
value: 27,
};
let long_cycle4: LongCycle4<f32> = LongCycle4 {
next: None,
value: 29.5,
};
// It's important that LongCycleWithAnonymousTypes is encountered only at the end of the
// `box` chain.
let long_cycle_w_anonymous_types = box box box box box LongCycleWithAnonymousTypes {
next: Val {
val: box box box box box LongCycleWithAnonymousTypes {
next: Empty,
value: 31,
}
},
value: 30
};
zzz(); // #break
}
fn zzz() {()}