Skip to content

Commit 581942d

Browse files
committed
---
yaml --- r: 5075 b: refs/heads/master c: 0470006 h: refs/heads/master i: 5073: dbd6218 5071: 93a88ab v: v3
1 parent 5744bb3 commit 581942d

File tree

2 files changed

+85
-84
lines changed

2 files changed

+85
-84
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 81b31429e48ec6ea8fd91679246d847ecf0fc762
2+
refs/heads/master: 04700066f38409df2ca05de98d6998c41cbd7ba0

trunk/src/fuzzer/fuzzer.rs

+84-83
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ import rustc::syntax::codemap;
2121
import rustc::syntax::parse::parser;
2222
import rustc::syntax::print::pprust;
2323

24-
fn write_file(filename: &str, content: &str) {
25-
io::file_writer(istr::from_estr(filename), [io::create, io::truncate]).write_str(istr::from_estr(content));
24+
fn write_file(filename: &istr, content: &istr) {
25+
io::file_writer(filename, [io::create, io::truncate]).write_str(content);
2626
// Work around https://github.com/graydon/rust/issues/726
27-
std::run::run_program(~"chmod", [~"644", istr::from_estr(filename)]);
27+
std::run::run_program(~"chmod", [~"644", filename]);
2828
}
2929

30-
fn file_contains(filename: &str, needle: &str) -> bool {
31-
let contents = istr::to_estr(io::read_whole_file_str(istr::from_estr(filename)));
32-
ret str::find(contents, needle) != -1;
30+
fn file_contains(filename: &istr, needle: &istr) -> bool {
31+
let contents = io::read_whole_file_str(filename);
32+
ret istr::find(contents, needle) != -1;
3333
}
3434

35-
fn contains(haystack: &str, needle: &str) -> bool {
36-
str::find(haystack, needle) != -1
35+
fn contains(haystack: &istr, needle: &istr) -> bool {
36+
istr::find(haystack, needle) != -1
3737
}
3838

39-
fn find_rust_files(files: &mutable [str], path: str) {
40-
if str::ends_with(path, ".rs") {
41-
if file_contains(path, "xfail-test") {
39+
fn find_rust_files(files: &mutable [istr], path: &istr) {
40+
if istr::ends_with(path, ~".rs") {
41+
if file_contains(path, ~"xfail-test") {
4242
//log_err "Skipping " + path + " because it is marked as xfail-test";
4343
} else { files += [path]; }
44-
} else if fs::file_is_dir(istr::from_estr(path))
45-
&& str::find(path, "compile-fail") == -1 {
46-
for p in fs::list_dir(istr::from_estr(path)) {
47-
find_rust_files(files, istr::to_estr(p));
44+
} else if fs::file_is_dir(path)
45+
&& istr::find(path, ~"compile-fail") == -1 {
46+
for p in fs::list_dir(path) {
47+
find_rust_files(files, p);
4848
}
4949
}
5050
}
@@ -151,14 +151,14 @@ iter under(n: uint) -> uint {
151151

152152
fn devnull() -> io::writer { std::io::string_writer().get_writer() }
153153

154-
fn as_str(f: fn(io::writer)) -> str {
154+
fn as_str(f: fn(io::writer)) -> istr {
155155
let w = std::io::string_writer();
156156
f(w.get_writer());
157-
ret istr::to_estr(w.get_str());
157+
ret w.get_str();
158158
}
159159

160160
fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap,
161-
filename: &str) {
161+
filename: &istr) {
162162
let exprs = steal_exprs(crate);
163163
let exprsL = vec::len(exprs);
164164
if exprsL < 100u {
@@ -171,7 +171,7 @@ fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap,
171171
// string for stability is easier and ok for now.
172172
let str3 =
173173
as_str(bind pprust::print_crate(codemap, crate2,
174-
istr::from_estr(filename),
174+
filename,
175175
io::string_reader(~""), _,
176176
pprust::no_ann()));
177177
// 1u would be sane here, but the pretty-printer currently has lots of whitespace and paren issues,
@@ -187,93 +187,93 @@ fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap,
187187
// - that would find many "false positives" or unimportant bugs
188188
// - that would be tricky, requiring use of tasks or serialization or randomness.
189189
// This seems to find plenty of bugs as it is :)
190-
fn check_whole_compiler(code: &str) {
191-
let filename = "test.rs";
190+
fn check_whole_compiler(code: &istr) {
191+
let filename = ~"test.rs";
192192
write_file(filename, code);
193193
let p =
194194
std::run::program_output(
195195
~"/Users/jruderman/code/rust/build/stage1/rustc",
196-
[~"-c", istr::from_estr(filename)]);
196+
[~"-c", filename]);
197197
198198
//log_err #ifmt("Status: %d", p.status);
199199
//log_err "Output: " + p.out;
200200
if p.err != ~"" {
201-
if contains(istr::to_estr(p.err), "argument of incompatible type") {
201+
if contains(p.err, ~"argument of incompatible type") {
202202
log_err "https://github.com/graydon/rust/issues/769";
203-
} else if contains(istr::to_estr(p.err),
204-
"Cannot create binary operator with two operands of differing type")
203+
} else if contains(p.err,
204+
~"Cannot create binary operator with two operands of differing type")
205205
{
206206
log_err "https://github.com/graydon/rust/issues/770";
207-
} else if contains(istr::to_estr(p.err), "May only branch on boolean predicates!") {
207+
} else if contains(p.err, ~"May only branch on boolean predicates!") {
208208
log_err "https://github.com/graydon/rust/issues/770 or https://github.com/graydon/rust/issues/776";
209-
} else if contains(istr::to_estr(p.err), "Invalid constantexpr cast!") &&
210-
contains(code, "!") {
209+
} else if contains(p.err, ~"Invalid constantexpr cast!") &&
210+
contains(code, ~"!") {
211211
log_err "https://github.com/graydon/rust/issues/777";
212-
} else if contains(istr::to_estr(p.err),
213-
"Both operands to ICmp instruction are not of the same type!")
214-
&& contains(code, "!") {
212+
} else if contains(p.err,
213+
~"Both operands to ICmp instruction are not of the same type!")
214+
&& contains(code, ~"!") {
215215
log_err "https://github.com/graydon/rust/issues/777 #issuecomment-1678487";
216-
} else if contains(istr::to_estr(p.err), "Ptr must be a pointer to Val type!") &&
217-
contains(code, "!") {
216+
} else if contains(p.err, ~"Ptr must be a pointer to Val type!") &&
217+
contains(code, ~"!") {
218218
log_err "https://github.com/graydon/rust/issues/779";
219-
} else if contains(istr::to_estr(p.err), "Calling a function with bad signature!") &&
220-
(contains(code, "iter") || contains(code, "range")) {
219+
} else if contains(p.err, ~"Calling a function with bad signature!") &&
220+
(contains(code, ~"iter") || contains(code, ~"range")) {
221221
log_err "https://github.com/graydon/rust/issues/771 - calling an iter fails";
222-
} else if contains(istr::to_estr(p.err), "Calling a function with a bad signature!")
223-
&& contains(code, "empty") {
222+
} else if contains(p.err, ~"Calling a function with a bad signature!")
223+
&& contains(code, ~"empty") {
224224
log_err "https://github.com/graydon/rust/issues/775 - possibly a modification of run-pass/import-glob-crate.rs";
225-
} else if contains(istr::to_estr(p.err), "Invalid type for pointer element!") &&
226-
contains(code, "put") {
225+
} else if contains(p.err, ~"Invalid type for pointer element!") &&
226+
contains(code, ~"put") {
227227
log_err "https://github.com/graydon/rust/issues/773 - put put ()";
228-
} else if contains(istr::to_estr(p.err), "pointer being freed was not allocated") &&
229-
contains(istr::to_estr(p.out), "Out of stack space, sorry") {
228+
} else if contains(p.err, ~"pointer being freed was not allocated") &&
229+
contains(p.out, ~"Out of stack space, sorry") {
230230
log_err "https://github.com/graydon/rust/issues/768 + https://github.com/graydon/rust/issues/778"
231231
} else {
232232
log_err ~"Stderr: " + p.err;
233233
fail "Unfamiliar error message";
234234
}
235-
} else if contains(istr::to_estr(p.out), "non-exhaustive match failure") &&
236-
contains(istr::to_estr(p.out), "alias.rs") {
235+
} else if contains(p.out, ~"non-exhaustive match failure") &&
236+
contains(p.out, ~"alias.rs") {
237237
log_err "https://github.com/graydon/rust/issues/772";
238-
} else if contains(istr::to_estr(p.out), "non-exhaustive match failure") &&
239-
contains(istr::to_estr(p.out), "trans.rs") && contains(code, "put") {
238+
} else if contains(p.out, ~"non-exhaustive match failure") &&
239+
contains(p.out, ~"trans.rs") && contains(code, ~"put") {
240240
log_err "https://github.com/graydon/rust/issues/774";
241-
} else if contains(istr::to_estr(p.out), "Out of stack space, sorry") {
241+
} else if contains(p.out, ~"Out of stack space, sorry") {
242242
log_err "Possibly a variant of https://github.com/graydon/rust/issues/768";
243243
} else if p.status == 256 {
244-
if !contains(istr::to_estr(p.out), "error:") {
244+
if !contains(p.out, ~"error:") {
245245
fail "Exited with status 256 without a span-error";
246246
}
247247
} else if p.status == 11 {
248248
log_err "What is this I don't even";
249249
} else if p.status != 0 { fail "Unfamiliar status code"; }
250250
}
251251

252-
fn parse_and_print(code: &str) -> str {
253-
let filename = "tmp.rs";
252+
fn parse_and_print(code: &istr) -> istr {
253+
let filename = ~"tmp.rs";
254254
let sess = @{cm: codemap::new_codemap(), mutable next_id: 0};
255255
//write_file(filename, code);
256256
let crate = parser::parse_crate_from_source_str(
257-
istr::from_estr(filename), istr::from_estr(code), [], sess);
257+
filename, code, [], sess);
258258
ret as_str(bind pprust::print_crate(sess.cm, crate,
259-
istr::from_estr(filename),
260-
io::string_reader(istr::from_estr(code)), _,
259+
filename,
260+
io::string_reader(code), _,
261261
pprust::no_ann()));
262262
}
263263

264-
fn content_is_dangerous_to_modify(code: &str) -> bool {
264+
fn content_is_dangerous_to_modify(code: &istr) -> bool {
265265
let dangerous_patterns =
266-
["obj", // not safe to steal; https://github.com/graydon/rust/issues/761
267-
"#macro", // not safe to steal things inside of it, because they have a special syntax
268-
"#", // strange representation of the arguments to #ifmt, for example
269-
" be ", // don't want to replace its child with a non-call: "Non-call expression in tail call"
270-
"@"]; // hangs when compiling: https://github.com/graydon/rust/issues/768
266+
[~"obj", // not safe to steal; https://github.com/graydon/rust/issues/761
267+
~"#macro", // not safe to steal things inside of it, because they have a special syntax
268+
~"#", // strange representation of the arguments to #ifmt, for example
269+
~" be ", // don't want to replace its child with a non-call: "Non-call expression in tail call"
270+
~"@"]; // hangs when compiling: https://github.com/graydon/rust/issues/768
271271

272-
for p: str in dangerous_patterns { if contains(code, p) { ret true; } }
272+
for p: istr in dangerous_patterns { if contains(code, p) { ret true; } }
273273
ret false;
274274
}
275275

276-
fn content_is_confusing(code: &str) ->
276+
fn content_is_confusing(code: &istr) ->
277277
bool { // https://github.com/graydon/rust/issues/671
278278
// https://github.com/graydon/rust/issues/669
279279
// https://github.com/graydon/rust/issues/669
@@ -283,16 +283,16 @@ fn content_is_confusing(code: &str) ->
283283
// more precedence issues?
284284

285285
let confusing_patterns =
286-
["#macro", "][]", "][mutable]", "][mutable ]", "self", "spawn",
287-
"bind", "\n\n\n\n\n", // https://github.com/graydon/rust/issues/759
288-
" : ", // https://github.com/graydon/rust/issues/760
289-
"if ret", "alt ret", "if fail", "alt fail"];
286+
[~"#macro", ~"][]", ~"][mutable]", ~"][mutable ]", ~"self", ~"spawn",
287+
~"bind", ~"\n\n\n\n\n", // https://github.com/graydon/rust/issues/759
288+
~" : ", // https://github.com/graydon/rust/issues/760
289+
~"if ret", ~"alt ret", ~"if fail", ~"alt fail"];
290290

291-
for p: str in confusing_patterns { if contains(code, p) { ret true; } }
291+
for p: istr in confusing_patterns { if contains(code, p) { ret true; } }
292292
ret false;
293293
}
294294

295-
fn file_is_confusing(filename: &str) -> bool {
295+
fn file_is_confusing(filename: &istr) -> bool {
296296

297297
// https://github.com/graydon/rust/issues/674
298298

@@ -303,16 +303,16 @@ fn file_is_confusing(filename: &str) -> bool {
303303
// which i can't reproduce using "rustc
304304
// --pretty normal"???
305305
let confusing_files =
306-
["block-expr-precedence.rs", "nil-pattern.rs",
307-
"syntax-extension-fmt.rs",
308-
"newtype.rs"]; // modifying it hits something like https://github.com/graydon/rust/issues/670
306+
[~"block-expr-precedence.rs", ~"nil-pattern.rs",
307+
~"syntax-extension-fmt.rs",
308+
~"newtype.rs"]; // modifying it hits something like https://github.com/graydon/rust/issues/670
309309

310310
for f in confusing_files { if contains(filename, f) { ret true; } }
311311

312312
ret false;
313313
}
314314

315-
fn check_roundtrip_convergence(code: &str, maxIters: uint) {
315+
fn check_roundtrip_convergence(code: &istr, maxIters: uint) {
316316

317317
let i = 0u;
318318
let new = code;
@@ -330,54 +330,55 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
330330
log_err #ifmt["Converged after %u iterations", i];
331331
} else {
332332
log_err #ifmt["Did not converge after %u iterations!", i];
333-
write_file("round-trip-a.rs", old);
334-
write_file("round-trip-b.rs", new);
333+
write_file(~"round-trip-a.rs", old);
334+
write_file(~"round-trip-b.rs", new);
335335
std::run::run_program(~"diff",
336336
[~"-w", ~"-u", ~"round-trip-a.rs",
337337
~"round-trip-b.rs"]);
338338
fail "Mismatch";
339339
}
340340
}
341341

342-
fn check_convergence(files: &[str]) {
342+
fn check_convergence(files: &[istr]) {
343343
log_err #ifmt["pp convergence tests: %u files", vec::len(files)];
344344
for file in files {
345345
if !file_is_confusing(file) {
346-
let s = istr::to_estr(io::read_whole_file_str(istr::from_estr(file)));
346+
let s = io::read_whole_file_str(file);
347347
if !content_is_confusing(s) {
348-
log_err #ifmt["pp converge: %s", istr::from_estr(file)];
348+
log_err #ifmt["pp converge: %s", file];
349349
// Change from 7u to 2u when https://github.com/graydon/rust/issues/759 is fixed
350350
check_roundtrip_convergence(s, 7u);
351351
}
352352
}
353353
}
354354
}
355355

356-
fn check_variants(files: &[str]) {
356+
fn check_variants(files: &[istr]) {
357357
for file in files {
358358
if !file_is_confusing(file) {
359-
let s = istr::to_estr(io::read_whole_file_str(istr::from_estr(file)));
359+
let s = io::read_whole_file_str(file);
360360
if content_is_dangerous_to_modify(s) || content_is_confusing(s) {
361361
cont;
362362
}
363-
log_err "check_variants: " + file;
363+
log_err ~"check_variants: " + file;
364364
let sess = @{cm: codemap::new_codemap(), mutable next_id: 0};
365365
let crate =
366366
parser::parse_crate_from_source_str(
367-
istr::from_estr(file),
368-
istr::from_estr(s), [], sess);
367+
file,
368+
s, [], sess);
369369
log_err as_str(bind pprust::print_crate(sess.cm, crate,
370-
istr::from_estr(file),
371-
io::string_reader(istr::from_estr(s)), _,
370+
file,
371+
io::string_reader(s), _,
372372
pprust::no_ann()));
373373
check_variants_of_ast(*crate, sess.cm, file);
374374
}
375375
}
376376
}
377377
378378
fn main(args: [str]) {
379+
let args = istr::from_estrs(args);
379380
if vec::len(args) != 2u {
380-
log_err #ifmt["usage: %s <testdir>", istr::from_estr(args[0])];
381+
log_err #ifmt["usage: %s <testdir>", args[0]];
381382
ret;
382383
}
383384
let files = [];

0 commit comments

Comments
 (0)