@@ -21,29 +21,6 @@ import rustc::syntax::codemap;
21
21
import rustc:: syntax:: parse:: parser;
22
22
import rustc:: syntax:: print:: pprust;
23
23
24
- /*
25
- // Imports for "the rest of driver::compile_input"
26
- import driver = rustc::driver::rustc; // see https://github.com/graydon/rust/issues/624
27
- import rustc::back::link;
28
- import rustc::driver::rustc::time;
29
- import rustc::driver::session;
30
-
31
- import rustc::metadata::creader;
32
- import rustc::metadata::cstore;
33
- import rustc::syntax::parse::parser;
34
- import rustc::syntax::parse::token;
35
- import rustc::front;
36
- import rustc::front::attr;
37
- import rustc::middle;
38
- import rustc::middle::trans;
39
- import rustc::middle::resolve;
40
- import rustc::middle::ty;
41
- import rustc::middle::typeck;
42
- import rustc::middle::tstate::ck;
43
- import rustc::syntax::print::pp;
44
- import rustc::util::ppaux;
45
- import rustc::lib::llvm;
46
- */
47
24
48
25
fn read_whole_file ( filename : & str ) -> str {
49
26
str:: unsafe_from_bytes_ivec ( ioivec:: file_reader ( filename) . read_whole_stream ( ) )
@@ -53,6 +30,8 @@ fn write_file(filename: &str, content: &str) {
53
30
ioivec:: file_writer ( filename,
54
31
~[ ioivec:: create,
55
32
ioivec:: truncate] ) . write_str ( content) ;
33
+ // Work around https://github.com/graydon/rust/issues/726
34
+ std:: run:: run_program ( "chmod" , [ "644" , filename] ) ;
56
35
}
57
36
58
37
fn file_contains ( filename : & str , needle : & str ) -> bool {
@@ -71,7 +50,7 @@ fn find_rust_files(files: &mutable str[], path: str) {
71
50
} else { files += ~[ path] ; }
72
51
} else if ( fs:: file_is_dir ( path) && str:: find ( path, "compile-fail" ) == -1 )
73
52
{
74
- for p: str in fs:: list_dir ( path) { find_rust_files ( files, p) ; }
53
+ for p in fs:: list_dir ( path) { find_rust_files ( files, p) ; }
75
54
}
76
55
}
77
56
@@ -102,15 +81,10 @@ fn safe_to_steal(e: ast::expr_) -> bool {
102
81
ast:: expr_binary ( _, _, _) { false }
103
82
ast:: expr_assign ( _, _) { false }
104
83
ast:: expr_assign_op ( _, _, _) { false }
105
-
106
-
107
- // https://github.com/graydon/rust/issues/676
108
- ast:: expr_ret( option:: none. ) {
109
- false
110
- }
84
+ ast:: expr_fail( option:: none. ) { false /* https://github.com/graydon/rust/issues/764 */ }
85
+ ast:: expr_ret( option:: none. ) { false }
111
86
ast:: expr_put( option:: none. ) { false }
112
87
113
-
114
88
_ {
115
89
true
116
90
}
@@ -175,33 +149,50 @@ fn as_str(f: fn(ioivec::writer) ) -> str {
175
149
ret w. get_str ( ) ;
176
150
}
177
151
178
- /*
179
- fn pp_variants(&ast::crate crate, &codemap::codemap cmap, &str filename) {
180
- auto exprs = steal_exprs(crate);
181
- auto exprsL = ivec::len(exprs);
152
+ fn pp_variants ( crate : & ast:: crate , codemap : & codemap:: codemap , filename : & str ) {
153
+ let exprs = steal_exprs ( crate ) ;
154
+ let exprsL = ivec:: len ( exprs) ;
182
155
if ( exprsL < 100 u) {
183
- for each (uint i in under(uint::min(exprsL, 20u) )) {
156
+ for each i : uint in under ( uint:: min ( exprsL, 20 u) ) {
184
157
log_err "Replacing ... " + pprust::expr_to_str(@exprs.(i));
185
- for each (uint j in under(uint::min(exprsL, 5u) )) {
158
+ for each j: uint in under(uint::min(exprsL, 5u)) {
186
159
log_err " With ... " + pprust::expr_to_str(@exprs.(j));
187
- auto crate2 = @replace_expr_in_crate(crate, i, exprs.(j).node);
188
- check_roundtrip(crate2, cmap, filename + ".4.rs");
160
+ let crate2 = @replace_expr_in_crate(crate, i, exprs.(j).node);
161
+ // It would be best to test the *crate* for stability, but testing the
162
+ // string for stability is easier and ok for now.
163
+ let str3 = as_str(bind pprust::print_crate(codemap, crate2, filename,
164
+ ioivec::string_reader(" ") , _,
165
+ pprust:: no_ann( ) ) ) ;
166
+ // 1u would be sane here, but the pretty-printer currently has lots of whitespace and paren issues,
167
+ // and https://github.com/graydon/rust/issues/766 is hilarious.
168
+ check_roundtrip_convergence ( str3, 7 u) ;
189
169
}
190
170
}
191
171
}
192
172
}
193
- */
194
173
195
174
fn parse_and_print ( code : & str ) -> str {
196
- let filename = "" ;
175
+ let filename = "tmp.rs " ;
197
176
let codemap = codemap:: new_codemap ( ) ;
177
+ //write_file(filename, code);
198
178
let crate =
199
179
parser:: parse_crate_from_source_str ( filename, code, ~[ ] , codemap) ;
200
180
ret as_str( bind pprust:: print_crate ( codemap, crate , filename,
201
181
ioivec:: string_reader ( code) , _,
202
182
pprust:: no_ann ( ) ) ) ;
203
183
}
204
184
185
+ fn content_is_dangerous_to_modify ( code : & str ) -> bool {
186
+ let dangerous_patterns = [
187
+ "obj" , // not safe to steal; https://github.com/graydon/rust/issues/761
188
+ "#macro" , // not safe to steal things inside of it, because they have a special syntax
189
+ " be " // don't want to replace its child with a non-call: "Non-call expression in tail call"
190
+ ] ;
191
+
192
+ for p: str in dangerous_patterns { if contains ( code, p) { ret true ; } }
193
+ ret false;
194
+ }
195
+
205
196
fn content_is_confusing ( code : & str ) -> bool {
206
197
let // https://github.com/graydon/rust/issues/671
207
198
// https://github.com/graydon/rust/issues/669
@@ -212,14 +203,21 @@ fn content_is_confusing(code: &str) -> bool {
212
203
// more precedence issues?
213
204
confusing_patterns =
214
205
[ "#macro" , "][]" , "][mutable]" , "][mutable ]" , "self" , "spawn" ,
215
- "bind" ] ;
216
-
217
- for p: str in confusing_patterns { if contains ( code, p) { ret true ; } }
206
+ "bind" ,
207
+ "\n \n \n \n \n " , // https://github.com/graydon/rust/issues/759
208
+ " : " , // https://github.com/graydon/rust/issues/760
209
+ "if ret" ,
210
+ "alt ret" ,
211
+ "if fail" ,
212
+ "alt fail"
213
+ ] ;
214
+
215
+ for p: str in confusing_patterns { if contains ( code, p) { ret true ; } }
218
216
ret false;
219
217
}
220
218
221
219
fn file_is_confusing ( filename : & str ) -> bool {
222
- let
220
+ let
223
221
224
222
// https://github.com/graydon/rust/issues/674
225
223
@@ -231,49 +229,67 @@ fn file_is_confusing(filename: &str) -> bool {
231
229
// --pretty normal"???
232
230
confusing_files =
233
231
[ "block-expr-precedence.rs" , "nil-pattern.rs" ,
234
- "syntax-extension-fmt.rs" ] ;
232
+ "syntax-extension-fmt.rs" ,
233
+ "newtype.rs" // modifying it hits something like https://github.com/graydon/rust/issues/670
234
+ ] ;
235
235
236
- for f: str in confusing_files { if contains ( filename, f) { ret true ; } }
236
+ for f in confusing_files { if contains ( filename, f) { ret true ; } }
237
237
238
238
ret false;
239
239
}
240
240
241
- fn check_roundtrip_convergence ( code : & str ) {
241
+ fn check_roundtrip_convergence ( code : & str , maxIters : uint ) {
242
242
243
- let i = 0 ;
243
+ let i = 0 u ;
244
244
let new = code;
245
245
let old = code;
246
246
247
- while i < 10 {
247
+ while i < maxIters {
248
248
old = new;
249
+ if content_is_confusing ( old) { ret; }
249
250
new = parse_and_print ( old) ;
250
- if content_is_confusing ( new) { ret; }
251
- i += 1 ;
252
- log #fmt( "cycle %d" , i) ;
251
+ if old == new { break ; }
252
+ i += 1 u;
253
253
}
254
254
255
-
256
- if old != new {
255
+ if old == new {
256
+ log_err #fmt( "Converged after %u iterations" , i) ;
257
+ } else {
258
+ log_err #fmt( "Did not converge after %u iterations!" , i) ;
257
259
write_file ( "round-trip-a.rs" , old) ;
258
260
write_file ( "round-trip-b.rs" , new) ;
259
- std:: run:: run_program ( "kdiff3" ,
260
- [ "round-trip-a.rs" , "round-trip-b.rs" ] ) ;
261
+ std:: run:: run_program ( "diff" , [ "-w" , "-u" , "round-trip-a.rs" , "round-trip-b.rs" ] ) ;
261
262
fail "Mismatch" ;
262
263
}
263
264
}
265
+
264
266
fn check_convergence ( files : & str [ ] ) {
265
267
log_err #fmt( "pp convergence tests: %u files" , ivec:: len ( files) ) ;
266
- for file: str in files {
267
-
268
- log_err #fmt( "pp converge: %s" , file) ;
268
+ for file in files {
269
269
if !file_is_confusing ( file) {
270
270
let s = read_whole_file ( file) ;
271
- if !content_is_confusing ( s) { check_roundtrip_convergence ( s) ; }
271
+ if !content_is_confusing ( s) {
272
+ log_err #fmt( "pp converge: %s" , file) ;
273
+ // Change from 7u to 2u when https://github.com/graydon/rust/issues/759 is fixed
274
+ check_roundtrip_convergence ( s, 7 u) ;
275
+ }
272
276
}
277
+ }
278
+ }
273
279
274
- //pprust::print_crate(cm, crate, file, devnull(), pprust::no_ann());
275
- // Currently hits https://github.com/graydon/rust/issues/675
276
- //pp_variants(*crate, cm, file);
280
+ fn check_convergence_of_variants ( files : & str [ ] ) {
281
+ for file in files {
282
+ if !file_is_confusing ( file) {
283
+ let s = read_whole_file ( file) ;
284
+ if content_is_dangerous_to_modify ( s) || content_is_confusing ( s) { cont; }
285
+ log_err "check_convergence_of_variants: " + file;
286
+ let codemap = codemap:: new_codemap ( ) ;
287
+ let crate = parser:: parse_crate_from_source_str ( file, s, ~[ ] , codemap) ;
288
+ log_err as_str( bind pprust:: print_crate ( codemap, crate , file,
289
+ ioivec:: string_reader ( s) , _,
290
+ pprust:: no_ann ( ) ) ) ;
291
+ pp_variants ( * crate , codemap, file) ;
292
+ }
277
293
}
278
294
}
279
295
@@ -287,6 +303,7 @@ fn main(args: vec[str]) {
287
303
288
304
find_rust_files ( files, root) ;
289
305
check_convergence ( files) ;
306
+ check_convergence_of_variants ( files) ;
290
307
}
291
308
292
309
// Local Variables:
0 commit comments