diff --git a/Makefile.in b/Makefile.in index ca82f296022..fa4c327f061 100644 --- a/Makefile.in +++ b/Makefile.in @@ -208,7 +208,6 @@ CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std) CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra) CFG_LIBRUSTC_$(1) :=$(call CFG_LIB_NAME_$(1),rustc) CFG_LIBSYNTAX_$(1) :=$(call CFG_LIB_NAME_$(1),syntax) -CFG_LIBFUZZER_$(1) :=$(call CFG_LIB_NAME_$(1),fuzzer) CFG_LIBRUSTPKG_$(1) :=$(call CFG_LIB_NAME_$(1),rustpkg) CFG_LIBRUSTDOC_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc) CFG_LIBRUSTI_$(1) :=$(call CFG_LIB_NAME_$(1),rusti) @@ -218,7 +217,6 @@ EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra) STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std) LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc) LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax) -LIBFUZZER_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),fuzzer) LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg) LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc) LIBRUSTI_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rusti) @@ -227,7 +225,6 @@ EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra) STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std) LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc) LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax) -LIBFUZZER_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),fuzzer) LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg) LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc) LIBRUSTI_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rusti) @@ -402,12 +399,10 @@ SREQ$(1)_T_$(2)_H_$(3) = \ # Prerequisites for a working stageN compiler and libraries, for a specific target CSREQ$(1)_T_$(2)_H_$(3) = \ $$(TSREQ$(1)_T_$(2)_H_$(3)) \ - $$(HBIN$(1)_H_$(3))/fuzzer$$(X_$(3)) \ $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \ $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \ $$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \ $$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \ - $$(HLIB$(1)_H_$(3))/$(CFG_LIBFUZZER_$(3)) \ $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \ $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \ $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTI_$(3)) \ @@ -416,7 +411,6 @@ CSREQ$(1)_T_$(2)_H_$(3) = \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2)) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \ - $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBFUZZER_$(2)) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTI_$(2)) \ diff --git a/mk/clean.mk b/mk/clean.mk index 9a074b29d8b..23efbb3ee15 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -63,13 +63,11 @@ define CLEAN_HOST_STAGE_N clean$(1)_H_$(2): $(Q)rm -f $$(HBIN$(1)_H_$(2))/rustc$(X_$(2)) - $(Q)rm -f $$(HBIN$(1)_H_$(2))/fuzzer$(X_$(2)) $(Q)rm -f $$(HBIN$(1)_H_$(2))/rustpkg$(X_$(2)) $(Q)rm -f $$(HBIN$(1)_H_$(2))/serializer$(X_$(2)) $(Q)rm -f $$(HBIN$(1)_H_$(2))/rustdoc$(X_$(2)) $(Q)rm -f $$(HBIN$(1)_H_$(2))/rusti$(X_$(2)) $(Q)rm -f $$(HBIN$(1)_H_$(2))/rust$(X_$(2)) - $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBFUZZER_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBRUSTPKG_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBRUSTDOC_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_RUNTIME_$(2)) @@ -83,7 +81,6 @@ clean$(1)_H_$(2): $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(EXTRALIB_GLOB_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTC_GLOB_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBSYNTAX_GLOB_$(2)) - $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBFUZZER_GLOB_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTPKG_GLOB_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTDOC_GLOB_$(2)) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTI_GLOB_$(2)) @@ -101,13 +98,11 @@ define CLEAN_TARGET_STAGE_N clean$(1)_T_$(2)_H_$(3): $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$(X_$(2)) - $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/fuzzer$(X_$(2)) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustpkg$(X_$(2)) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/serializer$(X_$(2)) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustdoc$(X_$(2)) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rusti$(X_$(2)) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rust$(X_$(2)) - $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBFUZZER_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) @@ -121,7 +116,6 @@ clean$(1)_T_$(2)_H_$(3): $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(EXTRALIB_GLOB_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTC_GLOB_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBSYNTAX_GLOB_$(2)) - $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBFUZZER_GLOB_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTPKG_GLOB_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTDOC_GLOB_$(2)) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTI_GLOB_$(2)) diff --git a/mk/dist.mk b/mk/dist.mk index 96f35031de9..912b692a247 100644 --- a/mk/dist.mk +++ b/mk/dist.mk @@ -32,7 +32,6 @@ PKG_FILES := \ librustc \ compiletest \ etc \ - libfuzzer \ libextra \ libstd \ libsyntax \ diff --git a/mk/pp.mk b/mk/pp.mk index 0a24d9e8797..f86bbb7f281 100644 --- a/mk/pp.mk +++ b/mk/pp.mk @@ -17,7 +17,6 @@ else $(wildcard $(addprefix $(S)src/rustc/,*.rs */*.rs */*/*.rs)) \ $(wildcard $(S)src/test/*/*.rs \ $(S)src/test/*/*/*.rs) \ - $(wildcard $(S)src/fuzzer/*.rs) \ $(wildcard $(S)src/rustpkg/*.rs) \ $(wildcard $(S)src/rusti/*.rs) \ $(wildcard $(S)src/rust/*.rs) diff --git a/mk/tools.mk b/mk/tools.mk index 018da2a6401..8319d8d4e48 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -11,9 +11,6 @@ # Rules for non-core tools built with the compiler, both for target # and host architectures -FUZZER_LIB := $(S)src/libfuzzer/fuzzer.rc -FUZZER_INPUTS := $(wildcard $(addprefix $(S)src/libfuzzer/, *.rs)) - # The test runner that runs the cfail/rfail/rpass and bxench tests COMPILETEST_CRATE := $(S)src/compiletest/compiletest.rc COMPILETEST_INPUTS := $(wildcard $(S)src/compiletest/*rs) @@ -38,21 +35,6 @@ RUST_INPUTS := $(wildcard $(S)src/librust/*.rs) # have tools that need to built for other targets. define TOOLS_STAGE_N_TARGET -$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBFUZZER_$(4)): \ - $$(FUZZER_LIB) $$(FUZZER_INPUTS) \ - $$(TSREQ$(1)_T_$(4)_H_$(3)) \ - $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_STDLIB_$(4)) \ - $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_EXTRALIB_$(4)) \ - $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTC_$(4)) - @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ - -$$(TBIN$(1)_T_$(4)_H_$(3))/fuzzer$$(X_$(4)): \ - $$(DRIVER_CRATE) \ - $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBFUZZER_$(4)) - @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(4)_H_$(3)) --cfg fuzzer -o $$@ $$< - $$(TBIN$(1)_T_$(4)_H_$(3))/compiletest$$(X_$(4)): \ $$(COMPILETEST_CRATE) $$(COMPILETEST_INPUTS) \ $$(TSREQ$(1)_T_$(4)_H_$(3)) \ @@ -128,27 +110,6 @@ endef define TOOLS_STAGE_N_HOST - -# Promote the stageN target to stageN+1 host -# FIXME: Shouldn't need to depend on host/librustc.so once -# rpath is working -$$(HLIB$(2)_H_$(4))/$(CFG_LIBFUZZER_$(4)): \ - $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBFUZZER_$(4)) \ - $$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTC_$(4)) \ - $$(HSREQ$(2)_H_$(4)) - @$$(call E, cp: $$@) - $$(Q)cp $$< $$@ - $$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBFUZZER_GLOB_$(4)) \ - $$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBFUZZER_DSYM_GLOB_$(4))) \ - $$(HLIB$(2)_H_$(4)) - -$$(HBIN$(2)_H_$(4))/fuzzer$$(X_$(4)): \ - $$(TBIN$(1)_T_$(4)_H_$(3))/fuzzer$$(X_$(4)) \ - $$(HLIB$(2)_H_$(4))/$(CFG_LIBFUZZER_$(4)) \ - $$(HSREQ$(2)_H_$(4)) - @$$(call E, cp: $$@) - $$(Q)cp $$< $$@ - $$(HBIN$(2)_H_$(4))/compiletest$$(X_$(4)): \ $$(TBIN$(1)_T_$(4)_H_$(3))/compiletest$$(X_$(4)) \ $$(HSREQ$(2)_H_$(4)) diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 97e01d1bcdc..ccedd3adbaa 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -16,9 +16,6 @@ extern mod core(name = "std", vers = "0.7-pre"); #[cfg(rustpkg)] extern mod this(name = "rustpkg"); -#[cfg(fuzzer)] -extern mod this(name = "fuzzer"); - #[cfg(rustdoc)] extern mod this(name = "rustdoc"); diff --git a/src/libfuzzer/ast_match.rs b/src/libfuzzer/ast_match.rs deleted file mode 100644 index 7d623919ff9..00000000000 --- a/src/libfuzzer/ast_match.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::prelude::*; - -use vec; - -fn vec_equal(v: ~[T], - u: ~[T], - element_equality_test: @fn(&&T, &&T) -> bool) -> - bool { - let Lv = v.len(); - if Lv != u.len() { return false; } - let i = 0u; - while i < Lv { - if !element_equality_test(v[i], u[i]) { return false; } - i += 1u; - } - return true; -} - -fn builtin_equal(&&a: T, &&b: T) -> bool { return a == b; } -fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; } - -fn main() { - assert!((builtin_equal(5, 5))); - assert!((!builtin_equal(5, 4))); - assert!((!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _)))); - assert!((!vec_equal(~[5, 5], ~[5], builtin_equal_int))); - assert!((!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int))); - assert!((!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int))); - assert!((vec_equal(~[5, 5], ~[5, 5], builtin_equal_int))); - - error!("Pass"); -} diff --git a/src/libfuzzer/cycles.rs b/src/libfuzzer/cycles.rs deleted file mode 100644 index 2256325fa43..00000000000 --- a/src/libfuzzer/cycles.rs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use core::prelude::*; - -use extra; -use extra::rand; -use uint::range; - -// random uint less than n -fn under(r : rand::rng, n : uint) -> uint { - assert!(n != 0u); r.next() as uint % n -} - -// random choice from a vec -fn choice(r : rand::rng, v : ~[const T]) -> T { - assert!(v.len() != 0u); v[under(r, v.len())] -} - -// k in n chance of being true -fn likelihood(r : rand::rng, k : uint, n : uint) -> bool { under(r, n) < k } - - -static iters : uint = 1000u; -static vlen : uint = 100u; - -enum maybe_pointy { - none, - p(@pointy) -} - -type pointy = { - mut a : maybe_pointy, - mut b : ~maybe_pointy, - mut c : @maybe_pointy, - - mut f : @fn()->(), - mut g : ~fn()->(), - - mut m : ~[maybe_pointy], - mut n : ~[maybe_pointy], - mut o : {x : int, y : maybe_pointy} -}; -// To add: objects; traits; anything type-parameterized? - -fn empty_pointy() -> @pointy { - return @{ - mut a : none, - mut b : ~none, - mut c : @none, - - mut f : || {}, - mut g : || {}, - - mut m : ~[], - mut n : ~[], - mut o : {x : 0, y : none} - } -} - -fn nopP(_x : @pointy) { } -fn nop(_x: T) { } - -fn test_cycles(r : rand::rng, k: uint, n: uint) -{ - let mut v : ~[@pointy] = ~[]; - - // Create a graph with no edges - range(0u, vlen) {|_i| - v.push(empty_pointy()); - } - - // Fill in the graph with random edges, with density k/n - range(0u, vlen) {|i| - if (likelihood(r, k, n)) { v[i].a = p(choice(r, v)); } - if (likelihood(r, k, n)) { v[i].b = ~p(choice(r, v)); } - if (likelihood(r, k, n)) { v[i].c = @p(choice(r, v)); } - - if (likelihood(r, k, n)) { v[i].f = bind nopP(choice(r, v)); } - //if (false) { v[i].g = bind (|_: @pointy| { })( - // choice(r, v)); } - // https://github.com/mozilla/rust/issues/1899 - - if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; } - if (likelihood(r, k, n)) { v[i].n.push(mut p(choice(r, v))); } - if (likelihood(r, k, n)) { v[i].o = {x: 0, y: p(choice(r, v))}; } - } - - // Drop refs one at a time - range(0u, vlen) {|i| - v[i] = empty_pointy() - } -} - -fn main() -{ - let r = rand::rng(); - range(0u, iters) {|i| - test_cycles(r, i, iters); - } -} diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc deleted file mode 100644 index 4e2103fcd70..00000000000 --- a/src/libfuzzer/fuzzer.rc +++ /dev/null @@ -1,713 +0,0 @@ -// Copyright 2012-2013 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#[link(name = "fuzzer", - vers = "0.7-pre", - uuid = "d6418797-2736-4833-bd82-d3c684b7c1b0", - url = "https://github.com/mozilla/rust/tree/master/src/libfuzzer")]; - -#[comment = "The Rust fuzzer library"]; -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[allow(non_camel_case_types)]; - -#[no_std]; - -extern mod std(name = "std", vers = "0.7-pre"); -extern mod extra(name = "extra", vers = "0.7-pre"); - -extern mod syntax(vers = "0.7-pre"); - -use std::prelude::*; - -use std::int; -use std::io; -use std::option; -use std::os; -use std::result; -use std::run; -use std::str; -use std::uint; - -use syntax::diagnostic; -use syntax::parse::token::ident_interner; -use syntax::parse::token; -use syntax::parse; -use syntax::print::pprust; -use syntax::{ast, fold, visit, codemap}; - -#[deriving(Eq)] -pub enum test_mode { tm_converge, tm_run, } - -pub struct Context { mode: test_mode } // + rng - -pub fn write_file(filename: &Path, content: &str) { - result::get(&io::file_writer(filename, [io::Create, io::Truncate])) - .write_str(content); -} - -pub fn contains(haystack: &str, needle: &str) -> bool { - haystack.contains(needle) -} - -pub fn find_rust_files(files: &mut ~[Path], path: &Path) { - if path.filetype() == Some(~".rs") && !contains(path.to_str(), "utf8") { - // ignoring "utf8" tests because something is broken - files.push(path.clone()); - } else if os::path_is_dir(path) - && !contains(path.to_str(), "compile-fail") - && !contains(path.to_str(), "build") { - for os::list_dir_path(path).each |p| { - find_rust_files(&mut *files, *p); - } - } -} - - -pub fn common_exprs() -> ~[@ast::expr] { - fn dse(e: ast::expr_) -> @ast::expr { - @ast::expr { - id: 0, - node: e, - span: codemap::dummy_sp(), - } - } - - fn dsl(l: ast::lit_) -> ast::lit { - codemap::spanned { node: l, span: codemap::dummy_sp() } - } - - ~[dse(ast::expr_break(option::None)), - dse(ast::expr_again(option::None)), - dse(ast::expr_ret(option::None)), - dse(ast::expr_lit(@dsl(ast::lit_nil))), - dse(ast::expr_lit(@dsl(ast::lit_bool(false)))), - dse(ast::expr_lit(@dsl(ast::lit_bool(true)))), - dse(ast::expr_unary(-1, ast::box(ast::m_imm), - dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))), - dse(ast::expr_unary(-1, ast::uniq(ast::m_imm), - dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))) - ] -} - -pub fn safe_to_steal_expr(e: @ast::expr, tm: test_mode) -> bool { - safe_to_use_expr(e, tm) -} - -pub fn safe_to_use_expr(e: @ast::expr, tm: test_mode) -> bool { - match tm { - tm_converge => { - match e.node { - // If the fuzzer moves a block-ending-in-semicolon into callee - // position, the pretty-printer can't preserve this even by - // parenthesizing!! See email to marijn. - ast::expr_if(*) | ast::expr_block(*) - | ast::expr_match(*) | ast::expr_while(*) => { false } - - // https://github.com/mozilla/rust/issues/929 - ast::expr_cast(*) | ast::expr_binary(*) | ast::expr_assign(*) | - ast::expr_assign_op(*) => { false } - - ast::expr_ret(option::None) => { false } - - // https://github.com/mozilla/rust/issues/953 - //ast::expr_fail(option::Some(_)) => { false } - - // https://github.com/mozilla/rust/issues/928 - //ast::expr_cast(_, _) { false } - - // https://github.com/mozilla/rust/issues/1458 - ast::expr_call(*) => { false } - - _ => { true } - } - } - tm_run => { true } - } -} - -pub fn safe_to_steal_ty(t: @ast::Ty, tm: test_mode) -> bool { - // Restrictions happen to be the same. - safe_to_replace_ty(&t.node, tm) -} - -// Not type-parameterized: https://github.com/mozilla/rust/issues/898 (FIXED) -pub fn stash_expr_if(c: @fn(@ast::expr, test_mode)->bool, - es: @mut ~[@ast::expr], - e: @ast::expr, - tm: test_mode) { - if c(e, tm) { - *es = *es + [e]; - } else { - /* now my indices are wrong :( */ - } -} - -pub fn stash_ty_if(c: @fn(@ast::Ty, test_mode) -> bool, - es: @mut ~[@ast::Ty], - e: @ast::Ty, - tm: test_mode) { - if c(e, tm) { - es.push(e); - } else { - /* now my indices are wrong :( */ - } -} - -pub struct StolenStuff { - exprs: ~[@ast::expr], - tys: ~[@ast::Ty] -} - -pub fn steal(crate: @ast::crate, tm: test_mode) -> StolenStuff { - let exprs = @mut ~[]; - let tys = @mut ~[]; - let v = visit::mk_simple_visitor(@visit::SimpleVisitor { - visit_expr: |a| stash_expr_if(safe_to_steal_expr, exprs, a, tm), - visit_ty: |a| stash_ty_if(safe_to_steal_ty, tys, a, tm), - .. *visit::default_simple_visitor() - }); - visit::visit_crate(crate, ((), v)); - StolenStuff { - exprs: (*exprs).clone(), - tys: (*tys).clone(), - } -} - - -pub fn safe_to_replace_expr(e: &ast::expr_, _tm: test_mode) -> bool { - match *e { - // https://github.com/mozilla/rust/issues/652 - ast::expr_if(*) => false, - ast::expr_block(_) => false, - - // expr_call is also missing a constraint - ast::expr_fn_block(*) => false, - - _ => true, - } -} - -pub fn safe_to_replace_ty(t: &ast::ty_, _tm: test_mode) -> bool { - match *t { - ast::ty_infer => { false } // always implicit, always top level - ast::ty_bot => { false } // in source, can only appear - // as the out type of a function - ast::ty_mac(_) => { false } - _ => { true } - } -} - -// Replace the |i|th expr (in fold order) of |crate| with |newexpr|. -pub fn replace_expr_in_crate(crate: @ast::crate, - i: uint, - newexpr: @ast::expr, - tm: test_mode) - -> @ast::crate { - let j: @mut uint = @mut 0u; - fn fold_expr_rep(j_: @mut uint, - i_: uint, - newexpr_: &ast::expr_, - original: &ast::expr_, - fld: @fold::ast_fold, - tm_: test_mode) - -> ast::expr_ { - *j_ += 1; - if i_ + 1 == *j_ && safe_to_replace_expr(original, tm_) { - copy *newexpr_ - } else { - fold::noop_fold_expr(original, fld) - } - } - let afp = @fold::AstFoldFns { - fold_expr: fold::wrap(|a,b| { - fold_expr_rep(j, i, &newexpr.node, a, b, tm) - }), - .. *fold::default_ast_fold() - }; - let af = fold::make_fold(afp); - let crate2: @ast::crate = @af.fold_crate(crate); - crate2 -} - - -// Replace the |i|th ty (in fold order) of |crate| with |newty|. -pub fn replace_ty_in_crate(crate: @ast::crate, - i: uint, - newty: @ast::Ty, - tm: test_mode) - -> @ast::crate { - let j: @mut uint = @mut 0u; - fn fold_ty_rep(j_: @mut uint, - i_: uint, - newty_: &ast::ty_, - original: &ast::ty_, - fld: @fold::ast_fold, - tm_: test_mode) - -> ast::ty_ { - *j_ += 1; - if i_ + 1 == *j_ && safe_to_replace_ty(original, tm_) { - copy *newty_ - } else { - fold::noop_fold_ty(original, fld) - } - } - let afp = @fold::AstFoldFns { - fold_ty: fold::wrap(|a,b| fold_ty_rep(j, i, &newty.node, a, b, tm)), - .. *fold::default_ast_fold() - }; - let af = fold::make_fold(afp); - let crate2: @ast::crate = @af.fold_crate(crate); - crate2 -} - -pub fn under(n: uint, it: &fn(uint)) { - let mut i: uint = 0u; - while i < n { it(i); i += 1u; } -} - -pub fn as_str(f: @fn(x: @io::Writer)) -> ~str { - io::with_str_writer(f) -} - -pub fn check_variants_of_ast(crate: @ast::crate, - codemap: @codemap::CodeMap, - filename: &Path, - cx: Context) { - let stolen = steal(crate, cx.mode); - let extra_exprs = do common_exprs().filtered |&a| { - safe_to_use_expr(a, cx.mode) - }; - check_variants_T(crate, - codemap, - filename, - ~"expr", - extra_exprs + stolen.exprs, - pprust::expr_to_str, - replace_expr_in_crate, - cx); - check_variants_T(crate, - codemap, - filename, - ~"ty", - stolen.tys, - pprust::ty_to_str, - replace_ty_in_crate, - cx); -} - -pub fn check_variants_T(crate: @ast::crate, - codemap: @codemap::CodeMap, - filename: &Path, - thing_label: ~str, - things: &[T], - stringifier: @fn(T, @ident_interner) -> ~str, - replacer: @fn(@ast::crate, - uint, - T, - test_mode) - -> @ast::crate, - cx: Context) { - error!("%s contains %u %s objects", filename.to_str(), - things.len(), thing_label); - - // Assuming we're not generating any token_trees - let intr = syntax::parse::token::mk_fake_ident_interner(); - - let L = things.len(); - - if L < 100 { - do under(uint::min(L, 20)) |i| { - error!("Replacing... #%?", uint::to_str(i)); - let fname = str::to_owned(filename.to_str()); - do under(uint::min(L, 30)) |j| { - let fname = fname.to_str(); - error!("With... %?", stringifier(things[j], intr)); - let crate2 = replacer(crate, i, things[j], cx.mode); - // It would be best to test the *crate* for stability, but - // testing the string for stability is easier and ok for now. - let handler = diagnostic::mk_handler(None); - let str3 = do io::with_str_reader("") |rdr| { - let fname = fname.to_str(); - let string = do as_str |a| { - let span_handler = - diagnostic::mk_span_handler(handler, codemap); - pprust::print_crate(codemap, - intr, - span_handler, - crate2, - fname.to_managed(), - rdr, - a, - pprust::no_ann(), - false) - }; - string.to_managed() - }; - match cx.mode { - tm_converge => check_roundtrip_convergence(str3, 1), - tm_run => { - let file_label = fmt!("rusttmp/%s_%s_%u_%u", - last_part(filename.to_str()), - thing_label, - i, - j); - let safe_to_run = !(content_is_dangerous_to_run(str3) - || has_raw_pointers(crate2)); - check_whole_compiler(str3, - &Path(file_label), - safe_to_run); - } - } - } - } - } -} - -pub fn last_part(filename: ~str) -> ~str { - let ix = filename.rfind('/').get(); - filename.slice(ix + 1u, filename.len() - 3u).to_owned() -} - -pub enum happiness { - passed, - cleanly_rejected(~str), - known_bug(~str), - failed(~str), -} - -// We'd find more bugs if we could take an AST here, but -// - that would find many "false positives" or unimportant bugs -// - that would be tricky, requiring use of tasks or serialization -// or randomness. -// This seems to find plenty of bugs as it is :) -pub fn check_whole_compiler(code: &str, - suggested_filename_prefix: &Path, - allow_running: bool) { - let filename = &suggested_filename_prefix.with_filetype("rs"); - write_file(filename, code); - - let compile_result = check_compiling(filename); - - let run_result = match (compile_result, allow_running) { - (passed, true) => { check_running(suggested_filename_prefix) } - (h, _) => { h } - }; - - match run_result { - passed | cleanly_rejected(_) | known_bug(_) => { - removeIfExists(suggested_filename_prefix); - removeIfExists(&suggested_filename_prefix.with_filetype("rs")); - removeDirIfExists(&suggested_filename_prefix.with_filetype("dSYM")); - } - failed(s) => { - error!("check_whole_compiler failure: %?", s); - error!("Saved as: %?", filename.to_str()); - } - } -} - -pub fn removeIfExists(filename: &Path) { - // So sketchy! - assert!(!contains(filename.to_str(), " ")); - run::process_status("bash", [~"-c", ~"rm " + filename.to_str()]); -} - -pub fn removeDirIfExists(filename: &Path) { - // So sketchy! - assert!(!contains(filename.to_str(), " ")); - run::process_status("bash", [~"-c", ~"rm -r " + filename.to_str()]); -} - -pub fn check_running(exe_filename: &Path) -> happiness { - let p = run::process_output( - "/Users/jruderman/scripts/timed_run_rust_program.py", - [exe_filename.to_str()]); - let comb = str::from_bytes(p.output) + "\n" + str::from_bytes(p.error); - if comb.len() > 1u { - error!("comb comb comb: %?", comb); - } - - if contains(comb, "Assertion failed:") { - failed(~"C++ assertion failure") - } else if contains(comb, "leaked memory in rust main loop") { - // might also use exit code 134 - //failed("Leaked") - known_bug(~"https://github.com/mozilla/rust/issues/910") - } else if contains(comb, "src/rt/") { - failed(~"Mentioned src/rt/") - } else if contains(comb, "malloc") { - failed(~"Mentioned malloc") - } else { - match p.status { - 0 => { passed } - 100 => { cleanly_rejected(~"running: explicit fail") } - 101 | 247 => { cleanly_rejected(~"running: timed out") } - 245 | 246 | 138 | 252 => { - known_bug(~"https://github.com/mozilla/rust/issues/1466") - } - 136 | 248 => { - known_bug( - ~"SIGFPE - https://github.com/mozilla/rust/issues/944") - } - rc => { - failed(~"Rust program ran but exited with status " + - int::to_str(rc)) - } - } - } -} - -pub fn check_compiling(filename: &Path) -> happiness { - let p = run::process_output( - "/Users/jruderman/code/rust/build/x86_64-apple-darwin/stage1/bin/rustc", - [filename.to_str()]); - - let out = str::from_bytes(p.output); - let err = str::from_bytes(p.error); - - //error!("Status: %d", p.status); - if p.status == 0 { - passed - } else if !err.is_empty() { - if err.contains("error:") { - cleanly_rejected(~"rejected with span_error") - } else { - error!("Stderr: %?", err); - failed(~"Unfamiliar error message") - } - } else if out.contains("Assertion") && out.contains("failed") { - error!("Stdout: %?", out); - failed(~"Looks like an llvm assertion failure") - } else if out.contains("internal compiler error unimplemented") { - known_bug(~"Something unimplemented") - } else if out.contains("internal compiler error") { - error!("Stdout: %?", out); - failed(~"internal compiler error") - - } else { - error!("%?", p.status); - error!("!Stdout: %?", out); - failed(~"What happened?") - } -} - - -pub fn parse_and_print(code: @str) -> @str { - let filename = Path("tmp.rs"); - let sess = parse::new_parse_sess(option::None); - write_file(&filename, code); - let crate = parse::parse_crate_from_source_str(filename.to_str().to_managed(), - code, - ~[], - sess); - do io::with_str_reader(code) |rdr| { - let filename = filename.to_str(); - do as_str |a| { - pprust::print_crate(sess.cm, - // Assuming there are no token_trees - token::mk_fake_ident_interner(), - copy sess.span_diagnostic, - crate, - filename.to_managed(), - rdr, - a, - pprust::no_ann(), - false) - }.to_managed() - } -} - -pub fn has_raw_pointers(c: @ast::crate) -> bool { - let has_rp = @mut false; - fn visit_ty(flag: @mut bool, t: @ast::Ty) { - match t.node { - ast::ty_ptr(_) => { *flag = true; } - _ => { } - } - } - let v = - visit::mk_simple_visitor(@visit::SimpleVisitor { - visit_ty: |a| visit_ty(has_rp, a), - .. *visit::default_simple_visitor()}); - visit::visit_crate(c, ((), v)); - return *has_rp; -} - -pub fn content_is_dangerous_to_run(code: &str) -> bool { - let dangerous_patterns = - ~[~"xfail-test", - ~"import", // espeically fs, run - ~"extern", - ~"unsafe", - ~"log"]; // python --> rust pipe deadlock? - - for dangerous_patterns.each |p| { if contains(code, *p) { return true; } } - return false; -} - -pub fn content_is_dangerous_to_compile(code: &str) -> bool { - let dangerous_patterns = - ~[~"xfail-test"]; - - for dangerous_patterns.each |p| { if contains(code, *p) { return true; } } - return false; -} - -pub fn content_might_not_converge(code: &str) -> bool { - let confusing_patterns = - ~[~"xfail-test", - ~"xfail-pretty", - ~"self", // crazy rules enforced by parser not typechecker? - ~"spawn", // precedence issues? - ~"bind", // precedence issues? - ~" be ", // don't want to replace its child with a non-call: - // "Non-call expression in tail call" - ~"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850 - ]; - - for confusing_patterns.each |p| { if contains(code, *p) { return true; } } - return false; -} - -pub fn file_might_not_converge(filename: &Path) -> bool { - let confusing_files = ~[ - ~"expr-alt.rs", // pretty-printing "(a = b) = c" - // vs "a = b = c" and wrapping - ~"block-arg-in-ternary.rs", // wrapping - ~"move-3-unique.rs", // 0 becomes (0), but both seem reasonable. wtf? - ~"move-3.rs" // 0 becomes (0), but both seem reasonable. wtf? - ]; - - - for confusing_files.each |f| { - if contains(filename.to_str(), *f) { - return true; - } - } - - return false; -} - -pub fn check_roundtrip_convergence(code: @str, maxIters: uint) { - let mut i = 0u; - let mut newv = code; - let mut oldv = code; - - while i < maxIters { - oldv = newv; - if content_might_not_converge(oldv) { return; } - newv = parse_and_print(oldv); - if oldv == newv { break; } - i += 1u; - } - - if oldv == newv { - error!("Converged after %u iterations", i); - } else { - error!("Did not converge after %u iterations!", i); - write_file(&Path("round-trip-a.rs"), oldv); - write_file(&Path("round-trip-b.rs"), newv); - run::process_status("diff", [~"-w", ~"-u", ~"round-trip-a.rs", ~"round-trip-b.rs"]); - fail!("Mismatch"); - } -} - -pub fn check_convergence(files: &[Path]) { - error!("pp convergence tests: %u files", files.len()); - for files.each |file| { - if !file_might_not_converge(file) { - let s = result::get(&io::read_whole_file_str(file)).to_managed(); - if !content_might_not_converge(s) { - error!("pp converge: %s", file.to_str()); - // Change from 7u to 2u once - // https://github.com/mozilla/rust/issues/850 is fixed - check_roundtrip_convergence(s, 7u); - } - } - } -} - -pub fn check_variants(files: &[Path], cx: Context) { - for files.each |file| { - if cx.mode == tm_converge && - file_might_not_converge(file) { - error!("Skipping convergence test based on\ - file_might_not_converge"); - loop; - } - - let s = result::get(&io::read_whole_file_str(file)).to_managed(); - if s.contains_char('#') { - loop; // Macros are confusing - } - if cx.mode == tm_converge && content_might_not_converge(s) { - loop; - } - if cx.mode == tm_run && content_is_dangerous_to_compile(s) { - loop; - } - - let file_str = file.to_str(); - - error!("check_variants: %?", file_str); - let sess = parse::new_parse_sess(None); - let crate = parse::parse_crate_from_source_str(file_str.to_managed(), - s, - ~[], - sess); - io::with_str_reader(s, |rdr| { - let file_str = file_str.to_str(); - error!("%s", - as_str(|a| { - pprust::print_crate( - sess.cm, - // Assuming no token_trees - token::mk_fake_ident_interner(), - copy sess.span_diagnostic, - crate, - file_str.to_managed(), - rdr, - a, - pprust::no_ann(), - false) - })) - }); - check_variants_of_ast(crate, sess.cm, file, cx); - } -} - -pub fn main() { - let args = os::args(); - if args.len() != 2u { - error!("usage: %s ", args[0]); - return; - } - let mut files = ~[]; - let root = Path(args[1]); - - find_rust_files(&mut files, &root); - error!("== check_convergence =="); - check_convergence(files); - error!("== check_variants: converge =="); - check_variants(files, Context { mode: tm_converge }); - error!("== check_variants: run =="); - check_variants(files, Context { mode: tm_run }); - - error!("Fuzzer done"); -} - -// For bootstrapping purposes... -pub mod core { - pub use std::cmp; - pub use std::sys; -} diff --git a/src/libfuzzer/ivec_fuzz.rs b/src/libfuzzer/ivec_fuzz.rs deleted file mode 100644 index 8f019a14eed..00000000000 --- a/src/libfuzzer/ivec_fuzz.rs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/* - -Idea: provide functions for 'exhaustive' and 'random' modification of vecs. - - two functions, "return all edits" and "return a random edit" = move- - leaning toward this model or two functions, "return the number of - possible edits" and "return edit #n" - -It would be nice if this could be data-driven, so the two functions -could share information: - type vec_modifier = rec(fn ( v, uint i) -> ~[T] fun, uint lo, uint di); - const ~[vec_modifier] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...]/~; -But that gives me "error: internal compiler error unimplemented consts -that's not a plain literal". -https://github.com/graydon/rust/issues/570 - -vec_edits is not an iter because iters might go away. - -*/ - -use std::prelude::*; - -use vec::slice; -use vec::len; - -fn vec_omit(v: ~[T], i: uint) -> ~[T] { - slice(v, 0u, i) + slice(v, i + 1u, len(v)) -} -fn vec_dup(v: ~[T], i: uint) -> ~[T] { - slice(v, 0u, i) + [v[i]] + slice(v, i, len(v)) -} -fn vec_swadj(v: ~[T], i: uint) -> ~[T] { - slice(v, 0u, i) + [v[i + 1u], v[i]] + slice(v, i + 2u, len(v)) -} -fn vec_prefix(v: ~[T], i: uint) -> ~[T] { slice(v, 0u, i) } -fn vec_suffix(v: ~[T], i: uint) -> ~[T] { slice(v, i, len(v)) } - -fn vec_poke(v: ~[T], i: uint, x: T) -> ~[T] { - slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v)) -} -fn vec_insert(v: ~[T], i: uint, x: T) -> ~[T] { - slice(v, 0u, i) + ~[x] + slice(v, i, len(v)) -} - -// Iterates over 0...length, skipping the specified number on each side. -fn ix(skip_low: uint, skip_high: uint, length: uint, it: block(uint)) { - let i: uint = skip_low; - while i + skip_high <= length { it(i); i += 1u; } -} - -// Returns a bunch of modified versions of v, some of which introduce -// new elements (borrowed from xs). -fn vec_edits(v: ~[T], xs: ~[T]) -> ~[~[T]] { - let edits: ~[~[T]] = ~[]; - let Lv: uint = len(v); - - if Lv != 1u { - // When Lv == 1u, this is redundant with omit. - edits.push(~[]); - } - if Lv >= 3u { - // When Lv == 2u, this is redundant with swap. - edits.push(vec::reversed(v)); - } - ix(0u, 1u, Lv) {|i| edits += ~[vec_omit(v, i)]; } - ix(0u, 1u, Lv) {|i| edits += ~[vec_dup(v, i)]; } - ix(0u, 2u, Lv) {|i| edits += ~[vec_swadj(v, i)]; } - ix(1u, 2u, Lv) {|i| edits += ~[vec_prefix(v, i)]; } - ix(2u, 1u, Lv) {|i| edits += ~[vec_suffix(v, i)]; } - - ix(0u, 1u, len(xs)) {|j| - ix(0u, 1u, Lv) {|i| - edits.push(vec_poke(v, i, xs[j])); - } - ix(0u, 0u, Lv) {|i| - edits.push(vec_insert(v, i, xs[j])); - } - } - - edits -} - -// Would be nice if this were built in: -// https://github.com/graydon/rust/issues/424 -fn vec_to_str(v: ~[int]) -> str { - let i = 0u; - let s = "["; - while i < len(v) { - s += int::str(v[i]); - if i + 1u < len(v) { s += ", "; } - i += 1u; - } - return s + "]"; -} - -fn show_edits(a: ~[int], xs: ~[int]) { - log(error, "=== Edits of " + vec_to_str(a) + " ==="); - let b = vec_edits(a, xs); - ix(0u, 1u, len(b)) {|i| log(error, vec_to_str(b[i])); } -} - -fn demo_edits() { - let xs = ~[7, 8]; - show_edits(~[], xs); - show_edits(~[1], xs); - show_edits(~[1, 2], xs); - show_edits(~[1, 2, 3], xs); - show_edits(~[1, 2, 3, 4], xs); -} - -fn main() { demo_edits(); } diff --git a/src/libfuzzer/rand_util.rs b/src/libfuzzer/rand_util.rs deleted file mode 100644 index abc6b1cfc0a..00000000000 --- a/src/libfuzzer/rand_util.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::prelude::*; -use extra::rand; - -// random uint less than n -fn under(r : rand::rng, n : uint) -> uint { - assert!(n != 0u); r.next() as uint % n -} - -// random choice from a vec -fn choice(r : rand::rng, v : ~[T]) -> T { - assert!(v.len() != 0u); v[under(r, v.len())] -} - -// 1 in n chance of being true -fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u } - -// shuffle a vec in place -fn shuffle(r : rand::rng, &v : ~[T]) { - let i = v.len(); - while i >= 2u { - // Loop invariant: elements with index >= i have been locked in place. - i -= 1u; - vec::swap(v, i, under(r, i + 1u)); // Lock element i in place. - } -} - -// create a shuffled copy of a vec -fn shuffled(r : rand::rng, v : ~[T]) -> ~[T] { - let w = vec::to_mut(v); - shuffle(r, w); - vec::from_mut(w) // Shouldn't this happen automatically? -} - -// sample from a population without replacement -//fn sample(r : rand::rng, pop : ~[T], k : uint) -> ~[T] { fail!() } - -// Two ways to make a weighted choice. -// * weighted_choice is O(number of choices) time -// * weighted_vec is O(total weight) space -type weighted = { weight: uint, item: T }; -fn weighted_choice(r : rand::rng, v : ~[weighted]) -> T { - assert!(v.len() != 0u); - let total = 0u; - for {weight: weight, item: _} in v { - total += weight; - } - assert!(total >= 0u); - let chosen = under(r, total); - let so_far = 0u; - for {weight: weight, item: item} in v { - so_far += weight; - if so_far > chosen { - return item; - } - } - std::unreachable(); -} - -fn weighted_vec(v : ~[weighted]) -> ~[T] { - let r = ~[]; - for {weight: weight, item: item} in v { - let i = 0u; - while i < weight { - r.push(item); - i += 1u; - } - } - r -} - -fn main() -{ - let r = rand::mk_rng(); - - log(error, under(r, 5u)); - log(error, choice(r, ~[10, 20, 30])); - log(error, if unlikely(r, 5u) { "unlikely" } else { "likely" }); - - let mut a = ~[1, 2, 3]; - shuffle(r, a); - log(error, a); - - let i = 0u; - let v = ~[ - {weight:1u, item:"low"}, - {weight:8u, item:"middle"}, - {weight:1u, item:"high"} - ]; - let w = weighted_vec(v); - - while i < 1000u { - log(error, "Immed: " + weighted_choice(r, v)); - log(error, "Fast: " + choice(r, w)); - i += 1u; - } -}