mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 12:43:36 +00:00
rustc: Remove io_error usage
This commit is contained in:
parent
b211b00d21
commit
5e8ba7252a
@ -17,6 +17,7 @@ use lib::llvm::{ArchiveRef, llvm};
|
||||
|
||||
use std::cast;
|
||||
use std::io::fs;
|
||||
use std::io;
|
||||
use std::libc;
|
||||
use std::os;
|
||||
use std::run::{ProcessOptions, Process, ProcessOutput};
|
||||
@ -50,9 +51,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
|
||||
Some(p) => { debug!("inside {}", p.display()); }
|
||||
None => {}
|
||||
}
|
||||
let mut opt_prog = Process::new(ar, args.as_slice(), opts);
|
||||
match opt_prog {
|
||||
Some(ref mut prog) => {
|
||||
match Process::new(ar, args.as_slice(), opts) {
|
||||
Ok(mut prog) => {
|
||||
let o = prog.finish_with_output();
|
||||
if !o.status.success() {
|
||||
sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
|
||||
@ -63,8 +63,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
|
||||
}
|
||||
o
|
||||
},
|
||||
None => {
|
||||
sess.err(format!("could not exec `{}`", ar));
|
||||
Err(e) => {
|
||||
sess.err(format!("could not exec `{}`: {}", ar, e));
|
||||
sess.abort_if_errors();
|
||||
fail!("rustc::back::archive::run_ar() should not reach this point");
|
||||
}
|
||||
@ -94,7 +94,7 @@ impl Archive {
|
||||
let archive = os::make_absolute(&self.dst);
|
||||
run_ar(self.sess, "x", Some(loc.path()), [&archive,
|
||||
&Path::new(file)]);
|
||||
fs::File::open(&loc.path().join(file)).read_to_end()
|
||||
fs::File::open(&loc.path().join(file)).read_to_end().unwrap()
|
||||
} else {
|
||||
run_ar(self.sess, "p", None, [&self.dst, &Path::new(file)]).output
|
||||
}
|
||||
@ -102,9 +102,9 @@ impl Archive {
|
||||
|
||||
/// Adds all of the contents of a native library to this archive. This will
|
||||
/// search in the relevant locations for a library named `name`.
|
||||
pub fn add_native_library(&mut self, name: &str) {
|
||||
pub fn add_native_library(&mut self, name: &str) -> io::IoResult<()> {
|
||||
let location = self.find_library(name);
|
||||
self.add_archive(&location, name, []);
|
||||
self.add_archive(&location, name, [])
|
||||
}
|
||||
|
||||
/// Adds all of the contents of the rlib at the specified path to this
|
||||
@ -112,14 +112,15 @@ impl Archive {
|
||||
///
|
||||
/// This ignores adding the bytecode from the rlib, and if LTO is enabled
|
||||
/// then the object file also isn't added.
|
||||
pub fn add_rlib(&mut self, rlib: &Path, name: &str, lto: bool) {
|
||||
pub fn add_rlib(&mut self, rlib: &Path, name: &str,
|
||||
lto: bool) -> io::IoResult<()> {
|
||||
let object = format!("{}.o", name);
|
||||
let bytecode = format!("{}.bc", name);
|
||||
let mut ignore = ~[METADATA_FILENAME, bytecode.as_slice()];
|
||||
if lto {
|
||||
ignore.push(object.as_slice());
|
||||
}
|
||||
self.add_archive(rlib, name, ignore);
|
||||
self.add_archive(rlib, name, ignore)
|
||||
}
|
||||
|
||||
/// Adds an arbitrary file to this archive
|
||||
@ -144,7 +145,8 @@ impl Archive {
|
||||
str::from_utf8(output.output).unwrap().lines().map(|s| s.to_owned()).collect()
|
||||
}
|
||||
|
||||
fn add_archive(&mut self, archive: &Path, name: &str, skip: &[&str]) {
|
||||
fn add_archive(&mut self, archive: &Path, name: &str,
|
||||
skip: &[&str]) -> io::IoResult<()> {
|
||||
let loc = TempDir::new("rsar").unwrap();
|
||||
|
||||
// First, extract the contents of the archive to a temporary directory
|
||||
@ -159,7 +161,7 @@ impl Archive {
|
||||
// We skip any files explicitly desired for skipping, and we also skip
|
||||
// all SYMDEF files as these are just magical placeholders which get
|
||||
// re-created when we make a new archive anyway.
|
||||
let files = fs::readdir(loc.path());
|
||||
let files = if_ok!(fs::readdir(loc.path()));
|
||||
let mut inputs = ~[];
|
||||
for file in files.iter() {
|
||||
let filename = file.filename_str().unwrap();
|
||||
@ -168,7 +170,7 @@ impl Archive {
|
||||
|
||||
let filename = format!("r-{}-{}", name, filename);
|
||||
let new_filename = file.with_filename(filename);
|
||||
fs::rename(file, &new_filename);
|
||||
if_ok!(fs::rename(file, &new_filename));
|
||||
inputs.push(new_filename);
|
||||
}
|
||||
|
||||
@ -176,6 +178,7 @@ impl Archive {
|
||||
let mut args = ~[&self.dst];
|
||||
args.extend(&mut inputs.iter());
|
||||
run_ar(self.sess, "r", None, args.as_slice());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn find_library(&self, name: &str) -> Path {
|
||||
|
@ -100,7 +100,6 @@ pub mod write {
|
||||
use util::common::time;
|
||||
|
||||
use std::c_str::ToCStr;
|
||||
use std::io;
|
||||
use std::libc::{c_uint, c_int};
|
||||
use std::path::Path;
|
||||
use std::run;
|
||||
@ -297,12 +296,8 @@ pub mod write {
|
||||
assembly.as_str().unwrap().to_owned()];
|
||||
|
||||
debug!("{} '{}'", cc, args.connect("' '"));
|
||||
let opt_prog = {
|
||||
let _guard = io::ignore_io_error();
|
||||
run::process_output(cc, args)
|
||||
};
|
||||
match opt_prog {
|
||||
Some(prog) => {
|
||||
match run::process_output(cc, args) {
|
||||
Ok(prog) => {
|
||||
if !prog.status.success() {
|
||||
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
|
||||
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
|
||||
@ -310,8 +305,8 @@ pub mod write {
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
},
|
||||
None => {
|
||||
sess.err(format!("could not exec the linker `{}`", cc));
|
||||
Err(e) => {
|
||||
sess.err(format!("could not exec the linker `{}`: {}", cc, e));
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
@ -768,6 +763,15 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
|
||||
}
|
||||
}
|
||||
|
||||
fn remove(sess: Session, path: &Path) {
|
||||
match fs::unlink(path) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
sess.err(format!("failed to remove {}: {}", path.display(), e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform the linkage portion of the compilation phase. This will generate all
|
||||
/// of the requested outputs for this compilation session.
|
||||
pub fn link_binary(sess: Session,
|
||||
@ -785,17 +789,15 @@ pub fn link_binary(sess: Session,
|
||||
|
||||
// Remove the temporary object file and metadata if we aren't saving temps
|
||||
if !sess.opts.save_temps {
|
||||
fs::unlink(obj_filename);
|
||||
fs::unlink(&obj_filename.with_extension("metadata.o"));
|
||||
remove(sess, obj_filename);
|
||||
remove(sess, &obj_filename.with_extension("metadata.o"));
|
||||
}
|
||||
|
||||
out_filenames
|
||||
}
|
||||
|
||||
fn is_writeable(p: &Path) -> bool {
|
||||
use std::io;
|
||||
|
||||
match io::result(|| p.stat()) {
|
||||
match p.stat() {
|
||||
Err(..) => true,
|
||||
Ok(m) => m.perm & io::UserWrite == io::UserWrite
|
||||
}
|
||||
@ -884,7 +886,7 @@ fn link_rlib(sess: Session,
|
||||
for &(ref l, kind) in used_libraries.get().iter() {
|
||||
match kind {
|
||||
cstore::NativeStatic => {
|
||||
a.add_native_library(l.as_slice());
|
||||
a.add_native_library(l.as_slice()).unwrap();
|
||||
}
|
||||
cstore::NativeFramework | cstore::NativeUnknown => {}
|
||||
}
|
||||
@ -919,16 +921,23 @@ fn link_rlib(sess: Session,
|
||||
// the same filename for metadata (stomping over one another)
|
||||
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
|
||||
let metadata = tmpdir.path().join(METADATA_FILENAME);
|
||||
fs::File::create(&metadata).write(trans.metadata);
|
||||
match fs::File::create(&metadata).write(trans.metadata) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
sess.err(format!("failed to write {}: {}",
|
||||
metadata.display(), e));
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
a.add_file(&metadata, false);
|
||||
fs::unlink(&metadata);
|
||||
remove(sess, &metadata);
|
||||
|
||||
// For LTO purposes, the bytecode of this library is also inserted
|
||||
// into the archive.
|
||||
let bc = obj_filename.with_extension("bc");
|
||||
a.add_file(&bc, false);
|
||||
if !sess.opts.save_temps {
|
||||
fs::unlink(&bc);
|
||||
remove(sess, &bc);
|
||||
}
|
||||
|
||||
// After adding all files to the archive, we need to update the
|
||||
@ -959,7 +968,7 @@ fn link_rlib(sess: Session,
|
||||
// metadata file).
|
||||
fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
|
||||
let mut a = link_rlib(sess, None, obj_filename, out_filename);
|
||||
a.add_native_library("morestack");
|
||||
a.add_native_library("morestack").unwrap();
|
||||
|
||||
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
|
||||
for &(cnum, ref path) in crates.iter() {
|
||||
@ -970,7 +979,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
|
||||
continue
|
||||
}
|
||||
};
|
||||
a.add_rlib(&p, name, sess.lto());
|
||||
a.add_rlib(&p, name, sess.lto()).unwrap();
|
||||
let native_libs = csearch::get_native_libraries(sess.cstore, cnum);
|
||||
for &(kind, ref lib) in native_libs.iter() {
|
||||
let name = match kind {
|
||||
@ -1004,14 +1013,10 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
|
||||
|
||||
// Invoke the system linker
|
||||
debug!("{} {}", cc_prog, cc_args.connect(" "));
|
||||
let opt_prog = {
|
||||
let _guard = io::ignore_io_error();
|
||||
time(sess.time_passes(), "running linker", (), |()|
|
||||
run::process_output(cc_prog, cc_args))
|
||||
};
|
||||
|
||||
match opt_prog {
|
||||
Some(prog) => {
|
||||
let prog = time(sess.time_passes(), "running linker", (), |()|
|
||||
run::process_output(cc_prog, cc_args));
|
||||
match prog {
|
||||
Ok(prog) => {
|
||||
if !prog.status.success() {
|
||||
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
|
||||
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
|
||||
@ -1019,8 +1024,8 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
},
|
||||
None => {
|
||||
sess.err(format!("could not exec the linker `{}`", cc_prog));
|
||||
Err(e) => {
|
||||
sess.err(format!("could not exec the linker `{}`: {}", cc_prog, e));
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
@ -1030,8 +1035,14 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
|
||||
// the symbols
|
||||
if sess.targ_cfg.os == abi::OsMacos && sess.opts.debuginfo {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
run::process_status("dsymutil",
|
||||
[out_filename.as_str().unwrap().to_owned()]);
|
||||
match run::process_status("dsymutil",
|
||||
[out_filename.as_str().unwrap().to_owned()]) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
sess.err(format!("failed to run dsymutil: {}", e));
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1225,7 +1236,16 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
|
||||
time(sess.time_passes(), format!("altering {}.rlib", name),
|
||||
(), |()| {
|
||||
let dst = tmpdir.join(cratepath.filename().unwrap());
|
||||
fs::copy(&cratepath, &dst);
|
||||
match fs::copy(&cratepath, &dst) {
|
||||
Ok(..) => {}
|
||||
Err(e) => {
|
||||
sess.err(format!("failed to copy {} to {}: {}",
|
||||
cratepath.display(),
|
||||
dst.display(),
|
||||
e));
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
let dst_str = dst.as_str().unwrap().to_owned();
|
||||
let mut archive = Archive::open(sess, dst);
|
||||
archive.remove_file(format!("{}.o", name));
|
||||
|
@ -399,7 +399,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
|
||||
|
||||
// Remove assembly source, unless --save-temps was specified
|
||||
if !sess.opts.save_temps {
|
||||
fs::unlink(&asm_filename);
|
||||
fs::unlink(&asm_filename).unwrap();
|
||||
}
|
||||
} else {
|
||||
time(sess.time_passes(), "LLVM passes", (), |_|
|
||||
@ -455,33 +455,39 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames, crate: &ast::Crate)
|
||||
fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames,
|
||||
crate: &ast::Crate) -> io::IoResult<()>
|
||||
{
|
||||
let lm = link::build_link_meta(sess, crate.attrs, &outputs.obj_filename,
|
||||
&mut ::util::sha2::Sha256::new());
|
||||
&mut ::util::sha2::Sha256::new());
|
||||
|
||||
let sess_outputs = sess.outputs.borrow();
|
||||
let out_filenames = sess_outputs.get().iter()
|
||||
.map(|&output| link::filename_for_input(&sess, output, &lm, &outputs.out_filename))
|
||||
.map(|&output| link::filename_for_input(&sess, output, &lm,
|
||||
&outputs.out_filename))
|
||||
.to_owned_vec();
|
||||
|
||||
// Write out dependency rules to the dep-info file if requested with --dep-info
|
||||
// Write out dependency rules to the dep-info file if requested with
|
||||
// --dep-info
|
||||
let deps_filename = match sess.opts.write_dependency_info {
|
||||
// Use filename from --dep-file argument if given
|
||||
(true, Some(ref filename)) => filename.clone(),
|
||||
// Use default filename: crate source filename with extension replaced by ".d"
|
||||
// Use default filename: crate source filename with extension replaced
|
||||
// by ".d"
|
||||
(true, None) => match *input {
|
||||
FileInput(ref input_path) => {
|
||||
let filestem = input_path.filestem().expect("input file must have stem");
|
||||
let filename = out_filenames[0].dir_path().join(filestem).with_extension("d");
|
||||
filename
|
||||
let filestem = input_path.filestem().expect("input file must \
|
||||
have stem");
|
||||
let filename = out_filenames[0].dir_path().join(filestem);
|
||||
filename.with_extension("d")
|
||||
},
|
||||
StrInput(..) => {
|
||||
sess.warn("can not write --dep-info without a filename when compiling stdin.");
|
||||
return;
|
||||
sess.warn("can not write --dep-info without a filename \
|
||||
when compiling stdin.");
|
||||
return Ok(());
|
||||
},
|
||||
},
|
||||
_ => return,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
// Build a list of files used to compile the output and
|
||||
@ -499,11 +505,12 @@ fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames, crate
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let mut file = io::File::create(&deps_filename);
|
||||
let mut file = if_ok!(io::File::create(&deps_filename));
|
||||
for path in out_filenames.iter() {
|
||||
write!(&mut file as &mut Writer,
|
||||
"{}: {}\n\n", path.display(), files.connect(" "));
|
||||
if_ok!(write!(&mut file as &mut Writer,
|
||||
"{}: {}\n\n", path.display(), files.connect(" ")));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
|
||||
@ -521,7 +528,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
|
||||
let outputs = build_output_filenames(input, outdir, output,
|
||||
expanded_crate.attrs, sess);
|
||||
|
||||
write_out_deps(sess, input, outputs, &expanded_crate);
|
||||
write_out_deps(sess, input, outputs, &expanded_crate).unwrap();
|
||||
|
||||
if stop_after_phase_2(sess) { return; }
|
||||
|
||||
@ -541,32 +548,33 @@ struct IdentifiedAnnotation {
|
||||
}
|
||||
|
||||
impl pprust::PpAnn for IdentifiedAnnotation {
|
||||
fn pre(&self, node: pprust::AnnNode) {
|
||||
fn pre(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
match node {
|
||||
pprust::NodeExpr(s, _) => pprust::popen(s),
|
||||
_ => ()
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
fn post(&self, node: pprust::AnnNode) {
|
||||
fn post(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
match node {
|
||||
pprust::NodeItem(s, item) => {
|
||||
pp::space(&mut s.s);
|
||||
pprust::synth_comment(s, item.id.to_str());
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, item.id.to_str()));
|
||||
}
|
||||
pprust::NodeBlock(s, blk) => {
|
||||
pp::space(&mut s.s);
|
||||
pprust::synth_comment(s, ~"block " + blk.id.to_str());
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, ~"block " + blk.id.to_str()));
|
||||
}
|
||||
pprust::NodeExpr(s, expr) => {
|
||||
pp::space(&mut s.s);
|
||||
pprust::synth_comment(s, expr.id.to_str());
|
||||
pprust::pclose(s);
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, expr.id.to_str()));
|
||||
if_ok!(pprust::pclose(s));
|
||||
}
|
||||
pprust::NodePat(s, pat) => {
|
||||
pp::space(&mut s.s);
|
||||
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, ~"pat " + pat.id.to_str()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -575,24 +583,26 @@ struct TypedAnnotation {
|
||||
}
|
||||
|
||||
impl pprust::PpAnn for TypedAnnotation {
|
||||
fn pre(&self, node: pprust::AnnNode) {
|
||||
fn pre(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
match node {
|
||||
pprust::NodeExpr(s, _) => pprust::popen(s),
|
||||
_ => ()
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
fn post(&self, node: pprust::AnnNode) {
|
||||
fn post(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
let tcx = self.analysis.ty_cx;
|
||||
match node {
|
||||
pprust::NodeExpr(s, expr) => {
|
||||
pp::space(&mut s.s);
|
||||
pp::word(&mut s.s, "as");
|
||||
pp::space(&mut s.s);
|
||||
pp::word(&mut s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
|
||||
pprust::pclose(s);
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pp::word(&mut s.s, "as"));
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pp::word(&mut s.s,
|
||||
ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))));
|
||||
if_ok!(pprust::pclose(s));
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,7 +648,7 @@ pub fn pretty_print_input(sess: Session,
|
||||
&mut rdr,
|
||||
~stdout as ~io::Writer,
|
||||
annotation,
|
||||
is_expanded);
|
||||
is_expanded).unwrap();
|
||||
}
|
||||
|
||||
pub fn get_os(triple: &str) -> Option<abi::Os> {
|
||||
@ -1167,10 +1177,11 @@ pub fn early_error(emitter: &diagnostic::Emitter, msg: &str) -> ! {
|
||||
fail!(diagnostic::FatalError);
|
||||
}
|
||||
|
||||
pub fn list_metadata(sess: Session, path: &Path, out: &mut io::Writer) {
|
||||
pub fn list_metadata(sess: Session, path: &Path,
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
metadata::loader::list_file_metadata(
|
||||
token::get_ident_interner(),
|
||||
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
|
||||
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -54,6 +54,11 @@ use syntax::diagnostic::Emitter;
|
||||
use syntax::diagnostic;
|
||||
use syntax::parse;
|
||||
|
||||
#[cfg(stage0)]
|
||||
macro_rules! if_ok (
|
||||
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
|
||||
)
|
||||
|
||||
pub mod middle {
|
||||
pub mod trans;
|
||||
pub mod ty;
|
||||
@ -267,7 +272,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
||||
d::FileInput(ref ifile) => {
|
||||
let mut stdout = io::stdout();
|
||||
d::list_metadata(sess, &(*ifile),
|
||||
&mut stdout as &mut io::Writer);
|
||||
&mut stdout as &mut io::Writer).unwrap();
|
||||
}
|
||||
d::StrInput(_) => {
|
||||
d::early_error(demitter, "can not list metadata for stdin");
|
||||
|
@ -1111,15 +1111,15 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] {
|
||||
}
|
||||
|
||||
fn list_crate_attributes(intr: @IdentInterner, md: ebml::Doc, hash: &str,
|
||||
out: &mut io::Writer) {
|
||||
write!(out, "=Crate Attributes ({})=\n", hash);
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
if_ok!(write!(out, "=Crate Attributes ({})=\n", hash));
|
||||
|
||||
let r = get_attributes(md);
|
||||
for attr in r.iter() {
|
||||
write!(out, "{}\n", pprust::attribute_to_str(attr, intr));
|
||||
if_ok!(write!(out, "{}\n", pprust::attribute_to_str(attr, intr)));
|
||||
}
|
||||
|
||||
write!(out, "\n\n");
|
||||
write!(out, "\n\n")
|
||||
}
|
||||
|
||||
pub fn get_crate_attributes(data: &[u8]) -> ~[ast::Attribute] {
|
||||
@ -1154,8 +1154,8 @@ pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] {
|
||||
return deps;
|
||||
}
|
||||
|
||||
fn list_crate_deps(data: &[u8], out: &mut io::Writer) {
|
||||
write!(out, "=External Dependencies=\n");
|
||||
fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||
if_ok!(write!(out, "=External Dependencies=\n"));
|
||||
|
||||
let r = get_crate_deps(data);
|
||||
for dep in r.iter() {
|
||||
@ -1168,7 +1168,8 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) {
|
||||
dep.vers);
|
||||
}
|
||||
|
||||
write!(out, "\n");
|
||||
if_ok!(write!(out, "\n"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(data: &[u8]) -> ~str {
|
||||
@ -1186,11 +1187,11 @@ pub fn get_crate_vers(data: &[u8]) -> ~str {
|
||||
}
|
||||
|
||||
pub fn list_crate_metadata(intr: @IdentInterner, bytes: &[u8],
|
||||
out: &mut io::Writer) {
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
let hash = get_crate_hash(bytes);
|
||||
let md = reader::Doc(bytes);
|
||||
list_crate_attributes(intr, md, hash, out);
|
||||
list_crate_deps(bytes, out);
|
||||
if_ok!(list_crate_attributes(intr, md, hash, out));
|
||||
list_crate_deps(bytes, out)
|
||||
}
|
||||
|
||||
// Translates a def_id from an external crate to a def_id for the current
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
// Metadata encoding
|
||||
|
||||
#[allow(unused_must_use)]; // everything is just a MemWriter, can't fail
|
||||
|
||||
use metadata::common::*;
|
||||
use metadata::cstore;
|
||||
@ -350,7 +351,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: variant.node.id as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
@ -668,10 +669,10 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::Explic
|
||||
|
||||
// Encode the base self type.
|
||||
match explicit_self {
|
||||
SelfStatic => ebml_w.writer.write(&[ 's' as u8 ]),
|
||||
SelfValue => ebml_w.writer.write(&[ 'v' as u8 ]),
|
||||
SelfBox => ebml_w.writer.write(&[ '@' as u8 ]),
|
||||
SelfUniq => ebml_w.writer.write(&[ '~' as u8 ]),
|
||||
SelfStatic => { ebml_w.writer.write(&[ 's' as u8 ]); }
|
||||
SelfValue => { ebml_w.writer.write(&[ 'v' as u8 ]); }
|
||||
SelfBox => { ebml_w.writer.write(&[ '@' as u8 ]); }
|
||||
SelfUniq => { ebml_w.writer.write(&[ '~' as u8 ]); }
|
||||
SelfRegion(_, m) => {
|
||||
// FIXME(#4846) encode custom lifetime
|
||||
ebml_w.writer.write(&['&' as u8]);
|
||||
@ -684,8 +685,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::Explic
|
||||
fn encode_mutability(ebml_w: &writer::Encoder,
|
||||
m: ast::Mutability) {
|
||||
match m {
|
||||
MutImmutable => ebml_w.writer.write(&[ 'i' as u8 ]),
|
||||
MutMutable => ebml_w.writer.write(&[ 'm' as u8 ]),
|
||||
MutImmutable => { ebml_w.writer.write(&[ 'i' as u8 ]); }
|
||||
MutMutable => { ebml_w.writer.write(&[ 'm' as u8 ]); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -726,12 +727,12 @@ fn encode_info_for_struct(ecx: &EncodeContext,
|
||||
};
|
||||
|
||||
let id = field.node.id;
|
||||
index.push(entry {val: id as i64, pos: ebml_w.writer.tell()});
|
||||
index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()});
|
||||
{
|
||||
let mut global_index = global_index.borrow_mut();
|
||||
global_index.get().push(entry {
|
||||
val: id as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
@ -758,7 +759,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: ctor_id as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -921,7 +922,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: item.id as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
let add_to_index: || = || add_to_index(item, ebml_w, index);
|
||||
@ -1157,7 +1158,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: m.def_id.node as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
encode_info_for_method(ecx,
|
||||
@ -1219,7 +1220,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: method_def_id.node as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1294,7 +1295,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: nitem.id as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1418,7 +1419,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
|
||||
let mut index = index.borrow_mut();
|
||||
index.get().push(entry {
|
||||
val: CRATE_NODE_ID as i64,
|
||||
pos: ebml_w.writer.tell(),
|
||||
pos: ebml_w.writer.tell().unwrap(),
|
||||
});
|
||||
}
|
||||
encode_info_for_mod(ecx,
|
||||
@ -1478,7 +1479,7 @@ fn encode_index<T:'static>(
|
||||
let mut bucket_locs = ~[];
|
||||
ebml_w.start_tag(tag_index_buckets);
|
||||
for bucket in buckets.iter() {
|
||||
bucket_locs.push(ebml_w.writer.tell());
|
||||
bucket_locs.push(ebml_w.writer.tell().unwrap());
|
||||
ebml_w.start_tag(tag_index_buckets_bucket);
|
||||
for elt in (**bucket).iter() {
|
||||
ebml_w.start_tag(tag_index_buckets_bucket_elt);
|
||||
@ -1895,58 +1896,58 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, crate: &Crate)
|
||||
|
||||
encode_hash(&mut ebml_w, ecx.link_meta.crate_hash);
|
||||
|
||||
let mut i = ebml_w.writer.tell();
|
||||
let mut i = ebml_w.writer.tell().unwrap();
|
||||
let crate_attrs = synthesize_crate_attrs(&ecx, crate);
|
||||
encode_attributes(&mut ebml_w, crate_attrs);
|
||||
ecx.stats.attr_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.attr_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_crate_deps(&ecx, &mut ebml_w, ecx.cstore);
|
||||
ecx.stats.dep_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.dep_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode the language items.
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_lang_items(&ecx, &mut ebml_w);
|
||||
ecx.stats.lang_item_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.lang_item_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode the native libraries used
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_native_libraries(&ecx, &mut ebml_w);
|
||||
ecx.stats.native_lib_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.native_lib_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode the macro registrar function
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_macro_registrar_fn(&ecx, &mut ebml_w);
|
||||
ecx.stats.macro_registrar_fn_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.macro_registrar_fn_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode macro definitions
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_macro_defs(&ecx, crate, &mut ebml_w);
|
||||
ecx.stats.macro_defs_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.macro_defs_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode the def IDs of impls, for coherence checking.
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_impls(&ecx, crate, &mut ebml_w);
|
||||
ecx.stats.impl_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.impl_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode miscellaneous info.
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
encode_misc_info(&ecx, crate, &mut ebml_w);
|
||||
ecx.stats.misc_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.misc_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
// Encode and index the items.
|
||||
ebml_w.start_tag(tag_items);
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
let items_index = encode_info_for_items(&ecx, &mut ebml_w, crate);
|
||||
ecx.stats.item_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.item_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
|
||||
i = ebml_w.writer.tell();
|
||||
i = ebml_w.writer.tell().unwrap();
|
||||
let items_buckets = create_index(items_index);
|
||||
encode_index(&mut ebml_w, items_buckets, write_i64);
|
||||
ecx.stats.index_bytes.set(ebml_w.writer.tell() - i);
|
||||
ecx.stats.index_bytes.set(ebml_w.writer.tell().unwrap() - i);
|
||||
ebml_w.end_tag();
|
||||
|
||||
ecx.stats.total_bytes.set(ebml_w.writer.tell());
|
||||
ecx.stats.total_bytes.set(ebml_w.writer.tell().unwrap());
|
||||
|
||||
if tcx.sess.meta_stats() {
|
||||
for e in ebml_w.writer.get_ref().iter() {
|
||||
|
@ -11,7 +11,6 @@
|
||||
use std::cell::RefCell;
|
||||
use std::option;
|
||||
use std::os;
|
||||
use std::io;
|
||||
use std::io::fs;
|
||||
use std::hashmap::HashSet;
|
||||
|
||||
@ -93,7 +92,7 @@ impl FileSearch {
|
||||
pub fn search(&self, pick: pick) {
|
||||
self.for_each_lib_search_path(|lib_search_path| {
|
||||
debug!("searching {}", lib_search_path.display());
|
||||
match io::result(|| fs::readdir(lib_search_path)) {
|
||||
match fs::readdir(lib_search_path) {
|
||||
Ok(files) => {
|
||||
let mut rslt = FileDoesntMatch;
|
||||
let is_rlib = |p: & &Path| {
|
||||
@ -163,8 +162,8 @@ pub fn get_or_default_sysroot() -> Path {
|
||||
// Follow symlinks. If the resolved path is relative, make it absolute.
|
||||
fn canonicalize(path: Option<Path>) -> Option<Path> {
|
||||
path.and_then(|mut path|
|
||||
match io::io_error::cond.trap(|_| ()).inside(|| fs::readlink(&path)) {
|
||||
Some(canon) => {
|
||||
match fs::readlink(&path) {
|
||||
Ok(canon) => {
|
||||
if canon.is_absolute() {
|
||||
Some(canon)
|
||||
} else {
|
||||
@ -172,7 +171,7 @@ pub fn get_or_default_sysroot() -> Path {
|
||||
Some(path.join(canon))
|
||||
}
|
||||
},
|
||||
None => Some(path),
|
||||
Err(..) => Some(path),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -381,13 +381,13 @@ pub fn read_meta_section_name(os: Os) -> &'static str {
|
||||
pub fn list_file_metadata(intr: @IdentInterner,
|
||||
os: Os,
|
||||
path: &Path,
|
||||
out: &mut io::Writer) {
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
match get_metadata_section(os, path) {
|
||||
option::Some(bytes) => decoder::list_crate_metadata(intr,
|
||||
bytes.as_slice(),
|
||||
out),
|
||||
option::None => {
|
||||
write!(out, "could not find metadata in {}.\n", path.display())
|
||||
write!(out, "could not find metadata in {}.\n", path.display())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
// Type encoding
|
||||
|
||||
#[allow(unused_must_use)]; // as with encoding, everything is a no-fail MemWriter
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::hashmap::HashMap;
|
||||
use std::io;
|
||||
@ -92,9 +94,9 @@ pub fn enc_ty(w: &mut MemWriter, cx: @ctxt, t: ty::t) {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
let pos = w.tell();
|
||||
let pos = w.tell().unwrap();
|
||||
enc_sty(w, cx, &ty::get(t).sty);
|
||||
let end = w.tell();
|
||||
let end = w.tell().unwrap();
|
||||
let len = end - pos;
|
||||
fn estimate_sz(u: u64) -> u64 {
|
||||
let mut n = u;
|
||||
|
@ -88,7 +88,7 @@ struct LoopScope<'a> {
|
||||
}
|
||||
|
||||
impl<O:DataFlowOperator> pprust::PpAnn for DataFlowContext<O> {
|
||||
fn pre(&self, node: pprust::AnnNode) {
|
||||
fn pre(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
let (ps, id) = match node {
|
||||
pprust::NodeExpr(ps, expr) => (ps, expr.id),
|
||||
pprust::NodeBlock(ps, blk) => (ps, blk.id),
|
||||
@ -117,9 +117,10 @@ impl<O:DataFlowOperator> pprust::PpAnn for DataFlowContext<O> {
|
||||
|
||||
let comment_str = format!("id {}: {}{}{}",
|
||||
id, entry_str, gens_str, kills_str);
|
||||
pprust::synth_comment(ps, comment_str);
|
||||
pp::space(&mut ps.s);
|
||||
if_ok!(pprust::synth_comment(ps, comment_str));
|
||||
if_ok!(pp::space(&mut ps.s));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -347,18 +348,20 @@ impl<O:DataFlowOperator+Clone+'static> DataFlowContext<O> {
|
||||
debug!("Dataflow result:");
|
||||
debug!("{}", {
|
||||
let this = @(*self).clone();
|
||||
this.pretty_print_to(~io::stderr() as ~io::Writer, blk);
|
||||
this.pretty_print_to(~io::stderr() as ~io::Writer, blk).unwrap();
|
||||
""
|
||||
});
|
||||
}
|
||||
|
||||
fn pretty_print_to(@self, wr: ~io::Writer, blk: &ast::Block) {
|
||||
fn pretty_print_to(@self, wr: ~io::Writer,
|
||||
blk: &ast::Block) -> io::IoResult<()> {
|
||||
let mut ps = pprust::rust_printer_annotated(wr, self.tcx.sess.intr(),
|
||||
self as @pprust::PpAnn);
|
||||
pprust::cbox(&mut ps, pprust::indent_unit);
|
||||
pprust::ibox(&mut ps, 0u);
|
||||
pprust::print_block(&mut ps, blk);
|
||||
pp::eof(&mut ps.s);
|
||||
if_ok!(pprust::cbox(&mut ps, pprust::indent_unit));
|
||||
if_ok!(pprust::ibox(&mut ps, 0u));
|
||||
if_ok!(pprust::print_block(&mut ps, blk));
|
||||
if_ok!(pp::eof(&mut ps.s));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -736,14 +736,15 @@ impl Liveness {
|
||||
pub fn write_vars(&self,
|
||||
wr: &mut io::Writer,
|
||||
ln: LiveNode,
|
||||
test: |uint| -> LiveNode) {
|
||||
test: |uint| -> LiveNode) -> io::IoResult<()> {
|
||||
let node_base_idx = self.idx(ln, Variable(0));
|
||||
for var_idx in range(0u, self.ir.num_vars.get()) {
|
||||
let idx = node_base_idx + var_idx;
|
||||
if test(idx).is_valid() {
|
||||
write!(wr, " {}", Variable(var_idx).to_str());
|
||||
if_ok!(write!(wr, " {}", Variable(var_idx).to_str()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn find_loop_scope(&self,
|
||||
@ -781,6 +782,7 @@ impl Liveness {
|
||||
*loop_scope.get().last().unwrap()
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
pub fn ln_str(&self, ln: LiveNode) -> ~str {
|
||||
let mut wr = io::MemWriter::new();
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user