Skip to content

Commit 95f0688

Browse files
committed
Sync from rust 73641cd
2 parents ddaa745 + 0167838 commit 95f0688

File tree

5 files changed

+40
-85
lines changed

5 files changed

+40
-85
lines changed

src/archive.rs

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::fs::File;
66
use std::io::{self, Read, Seek};
77
use std::path::{Path, PathBuf};
88

9-
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
10-
use rustc_codegen_ssa::METADATA_FILENAME;
9+
use rustc_codegen_ssa::back::archive::ArchiveBuilder;
1110
use rustc_session::Session;
1211

1312
use object::read::archive::ArchiveFile;
@@ -22,7 +21,6 @@ enum ArchiveEntry {
2221
pub(crate) struct ArArchiveBuilder<'a> {
2322
sess: &'a Session,
2423
dst: PathBuf,
25-
lib_search_paths: Vec<PathBuf>,
2624
use_gnu_style_archive: bool,
2725
no_builtin_ranlib: bool,
2826

@@ -34,8 +32,6 @@ pub(crate) struct ArArchiveBuilder<'a> {
3432

3533
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
3634
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
37-
use rustc_codegen_ssa::back::link::archive_search_paths;
38-
3935
let (src_archives, entries) = if let Some(input) = input {
4036
let read_cache = ReadCache::new(File::open(input).unwrap());
4137
let archive = ArchiveFile::parse(&read_cache).unwrap();
@@ -57,7 +53,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
5753
ArArchiveBuilder {
5854
sess,
5955
dst: output.to_path_buf(),
60-
lib_search_paths: archive_search_paths(sess),
6156
use_gnu_style_archive: sess.target.archive_format == "gnu",
6257
// FIXME fix builtin ranlib on macOS
6358
no_builtin_ranlib: sess.target.is_like_osx,
@@ -87,40 +82,29 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
8782
));
8883
}
8984

90-
fn add_native_library(&mut self, name: rustc_span::symbol::Symbol, verbatim: bool) {
91-
let location = find_library(name, verbatim, &self.lib_search_paths, self.sess);
92-
self.add_archive(location.clone(), |_| false).unwrap_or_else(|e| {
93-
panic!("failed to add native library {}: {}", location.to_string_lossy(), e);
94-
});
95-
}
96-
97-
fn add_rlib(
98-
&mut self,
99-
rlib: &Path,
100-
name: &str,
101-
lto: bool,
102-
skip_objects: bool,
103-
) -> io::Result<()> {
104-
self.add_archive(rlib.to_owned(), move |fname: &str| {
105-
// Ignore metadata files, no matter the name.
106-
if fname == METADATA_FILENAME {
107-
return true;
108-
}
85+
fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()>
86+
where
87+
F: FnMut(&str) -> bool + 'static,
88+
{
89+
let read_cache = ReadCache::new(std::fs::File::open(&archive_path)?);
90+
let archive = ArchiveFile::parse(&read_cache).unwrap();
91+
let archive_index = self.src_archives.len();
10992

110-
// Don't include Rust objects if LTO is enabled
111-
if lto && fname.starts_with(name) && fname.ends_with(".o") {
112-
return true;
93+
for entry in archive.members() {
94+
let entry = entry.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
95+
let file_name = String::from_utf8(entry.name().to_vec())
96+
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
97+
if !skip(&file_name) {
98+
self.entries.push((
99+
file_name.into_bytes(),
100+
ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() },
101+
));
113102
}
103+
}
114104

115-
// Otherwise if this is *not* a rust object and we're skipping
116-
// objects then skip this file
117-
if skip_objects && (!fname.starts_with(name) || !fname.ends_with(".o")) {
118-
return true;
119-
}
105+
self.src_archives.push(read_cache.into_inner());
106+
Ok(())
120107

121-
// ok, don't skip this
122-
false
123-
})
124108
}
125109

126110
fn update_symbols(&mut self) {}
@@ -265,29 +249,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
265249
bug!("injecting dll imports is not supported");
266250
}
267251
}
268-
269-
impl<'a> ArArchiveBuilder<'a> {
270-
fn add_archive<F>(&mut self, archive_path: PathBuf, mut skip: F) -> io::Result<()>
271-
where
272-
F: FnMut(&str) -> bool,
273-
{
274-
let read_cache = ReadCache::new(std::fs::File::open(&archive_path)?);
275-
let archive = ArchiveFile::parse(&read_cache).unwrap();
276-
let archive_index = self.src_archives.len();
277-
278-
for entry in archive.members() {
279-
let entry = entry.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
280-
let file_name = String::from_utf8(entry.name().to_vec())
281-
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
282-
if !skip(&file_name) {
283-
self.entries.push((
284-
file_name.into_bytes(),
285-
ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() },
286-
));
287-
}
288-
}
289-
290-
self.src_archives.push(read_cache.into_inner());
291-
Ok(())
292-
}
293-
}

src/common.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_index::vec::IndexVec;
2+
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers};
23
use rustc_middle::ty::SymbolName;
34
use rustc_target::abi::call::FnAbi;
45
use rustc_target::abi::{Integer, Primitive};
@@ -256,12 +257,12 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
256257
pub(crate) inline_asm_index: u32,
257258
}
258259

259-
impl<'tcx> LayoutOf<'tcx> for FunctionCx<'_, '_, 'tcx> {
260-
type Ty = Ty<'tcx>;
261-
type TyAndLayout = TyAndLayout<'tcx>;
260+
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
261+
type LayoutOfResult = TyAndLayout<'tcx>;
262262

263-
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
264-
RevealAllLayoutCx(self.tcx).layout_of(ty)
263+
#[inline]
264+
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
265+
RevealAllLayoutCx(self.tcx).handle_layout_err(err, span, ty)
265266
}
266267
}
267268

@@ -364,19 +365,16 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
364365

365366
pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
366367

367-
impl<'tcx> LayoutOf<'tcx> for RevealAllLayoutCx<'tcx> {
368-
type Ty = Ty<'tcx>;
369-
type TyAndLayout = TyAndLayout<'tcx>;
368+
impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
369+
type LayoutOfResult = TyAndLayout<'tcx>;
370370

371-
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
372-
assert!(!ty.still_further_specializable());
373-
self.0.layout_of(ParamEnv::reveal_all().and(&ty)).unwrap_or_else(|e| {
374-
if let layout::LayoutError::SizeOverflow(_) = e {
375-
self.0.sess.fatal(&e.to_string())
376-
} else {
377-
bug!("failed to get layout for `{}`: {}", ty, e)
378-
}
379-
})
371+
#[inline]
372+
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
373+
if let layout::LayoutError::SizeOverflow(_) = err {
374+
self.0.sess.span_fatal(span, &err.to_string())
375+
} else {
376+
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
377+
}
380378
}
381379
}
382380

src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> DebugContext<'tcx> {
6767
rustc_interface::util::version_str().unwrap_or("unknown version"),
6868
cranelift_codegen::VERSION,
6969
);
70-
let comp_dir = tcx.sess.opts.working_dir.to_string_lossy(false).into_owned();
70+
let comp_dir = tcx.sess.opts.working_dir.to_string_lossy(FileNameDisplayPreference::Remapped).into_owned();
7171
let (name, file_info) = match tcx.sess.local_crate_source_file.clone() {
7272
Some(path) => {
7373
let name = path.to_string_lossy().into_owned();

src/driver/aot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ fn reuse_workproduct_for_cgu(
8080
cgu: &CodegenUnit<'_>,
8181
work_products: &mut FxHashMap<WorkProductId, WorkProduct>,
8282
) -> CompiledModule {
83-
let incr_comp_session_dir = tcx.sess.incr_comp_session_dir();
8483
let mut object = None;
8584
let work_product = cgu.work_product(tcx);
8685
if let Some(saved_file) = &work_product.saved_file {
8786
let obj_out =
8887
tcx.output_filenames(()).temp_path(OutputType::Object, Some(&cgu.name().as_str()));
8988
object = Some(obj_out.clone());
90-
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
89+
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file);
9190
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
9291
tcx.sess.err(&format!(
9392
"unable to copy {} to {}: {}",

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ mod vtable;
7474
mod prelude {
7575
pub(crate) use std::convert::{TryFrom, TryInto};
7676

77-
pub(crate) use rustc_span::Span;
77+
pub(crate) use rustc_span::{Span, FileNameDisplayPreference};
7878

7979
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
8080
pub(crate) use rustc_middle::bug;
8181
pub(crate) use rustc_middle::mir::{self, *};
82-
pub(crate) use rustc_middle::ty::layout::{self, TyAndLayout};
82+
pub(crate) use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout};
8383
pub(crate) use rustc_middle::ty::{
8484
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut,
8585
TypeFoldable, UintTy,
8686
};
87-
pub(crate) use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx};
87+
pub(crate) use rustc_target::abi::{Abi, Scalar, Size, VariantIdx};
8888

8989
pub(crate) use rustc_data_structures::fx::FxHashMap;
9090

0 commit comments

Comments
 (0)