Skip to content

Commit 216d1a7

Browse files
committed
Sync from rust 21ff67d
2 parents 4748c53 + 9561346 commit 216d1a7

File tree

8 files changed

+51
-84
lines changed

8 files changed

+51
-84
lines changed

build_system/build_sysroot.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,35 @@ fn build_sysroot_for_triple(
161161
fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget {
162162
let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc);
163163

164-
let std_manifest_path = default_sysroot
165-
.join("lib")
166-
.join("rustlib")
167-
.join(format!("manifest-rust-std-{}", compiler.triple));
168-
169-
let libs = fs::read_to_string(std_manifest_path)
170-
.unwrap()
171-
.lines()
172-
.map(|entry| default_sysroot.join(entry.strip_prefix("file:").unwrap()))
173-
.collect();
174-
175-
SysrootTarget { triple: compiler.triple, libs }
164+
let mut target_libs = SysrootTarget { triple: compiler.triple, libs: vec![] };
165+
166+
for entry in fs::read_dir(
167+
default_sysroot.join("lib").join("rustlib").join(&target_libs.triple).join("lib"),
168+
)
169+
.unwrap()
170+
{
171+
let entry = entry.unwrap();
172+
if entry.file_type().unwrap().is_dir() {
173+
continue;
174+
}
175+
let file = entry.path();
176+
let file_name_str = file.file_name().unwrap().to_str().unwrap();
177+
if (file_name_str.contains("rustc_")
178+
&& !file_name_str.contains("rustc_std_workspace_")
179+
&& !file_name_str.contains("rustc_demangle")
180+
&& !file_name_str.contains("rustc_literal_escaper"))
181+
|| file_name_str.contains("chalk")
182+
|| file_name_str.contains("tracing")
183+
|| file_name_str.contains("regex")
184+
{
185+
// These are large crates that are part of the rustc-dev component and are not
186+
// necessary to run regular programs.
187+
continue;
188+
}
189+
target_libs.libs.push(file);
190+
}
191+
192+
target_libs
176193
}
177194

178195
fn build_clif_sysroot_for_triple(

src/allocator.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_ast::expand::allocator::{
66
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
77
};
88
use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents};
9-
use rustc_session::config::OomStrategy;
109
use rustc_symbol_mangling::mangle_internal_symbol;
1110

1211
use crate::prelude::*;
@@ -15,16 +14,11 @@ use crate::prelude::*;
1514
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
1615
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
1716
let methods = allocator_shim_contents(tcx, kind);
18-
codegen_inner(tcx, module, &methods, tcx.sess.opts.unstable_opts.oom);
17+
codegen_inner(tcx, module, &methods);
1918
true
2019
}
2120

22-
fn codegen_inner(
23-
tcx: TyCtxt<'_>,
24-
module: &mut dyn Module,
25-
methods: &[AllocatorMethod],
26-
oom_strategy: OomStrategy,
27-
) {
21+
fn codegen_inner(tcx: TyCtxt<'_>, module: &mut dyn Module, methods: &[AllocatorMethod]) {
2822
let usize_ty = module.target_config().pointer_type();
2923

3024
for method in methods {
@@ -65,35 +59,6 @@ fn codegen_inner(
6559
);
6660
}
6761

68-
{
69-
let sig = Signature {
70-
call_conv: module.target_config().default_call_conv,
71-
params: vec![],
72-
returns: vec![AbiParam::new(types::I8)],
73-
};
74-
let func_id = module
75-
.declare_function(
76-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
77-
Linkage::Export,
78-
&sig,
79-
)
80-
.unwrap();
81-
let mut ctx = Context::new();
82-
ctx.func.signature = sig;
83-
{
84-
let mut func_ctx = FunctionBuilderContext::new();
85-
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
86-
87-
let block = bcx.create_block();
88-
bcx.switch_to_block(block);
89-
let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64);
90-
bcx.ins().return_(&[value]);
91-
bcx.seal_all_blocks();
92-
bcx.finalize();
93-
}
94-
module.define_function(func_id, &mut ctx).unwrap();
95-
}
96-
9762
{
9863
let sig = Signature {
9964
call_conv: module.target_config().default_call_conv,

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn compile_fn(
167167
context.clear();
168168
context.func = codegened_func.func;
169169

170-
#[cfg(any())] // This is never true
170+
#[cfg(false)]
171171
let _clif_guard = {
172172
use std::fmt::Write;
173173

src/debuginfo/line_info.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::path::{Component, Path};
66
use cranelift_codegen::MachSrcLoc;
77
use cranelift_codegen::binemit::CodeOffset;
88
use gimli::write::{FileId, FileInfo, LineProgram, LineString, LineStringTable};
9-
use rustc_span::{FileName, Pos, SourceFile, SourceFileAndLine, SourceFileHashAlgorithm, hygiene};
9+
use rustc_span::{
10+
FileName, Pos, RemapPathScopeComponents, SourceFile, SourceFileAndLine,
11+
SourceFileHashAlgorithm, hygiene,
12+
};
1013

1114
use crate::debuginfo::FunctionDebugContext;
1215
use crate::debuginfo::emit::address_for_func;
@@ -95,7 +98,7 @@ impl DebugContext {
9598
match &source_file.name {
9699
FileName::Real(path) => {
97100
let (dir_path, file_name) =
98-
split_path_dir_and_file(path.to_path(self.filename_display_preference));
101+
split_path_dir_and_file(path.path(RemapPathScopeComponents::DEBUGINFO));
99102
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
100103
let file_name = osstr_as_utf8_bytes(file_name);
101104

src/debuginfo/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::def::DefKind;
2121
use rustc_hir::def_id::DefIdMap;
2222
use rustc_session::Session;
2323
use rustc_session::config::DebugInfo;
24-
use rustc_span::{FileNameDisplayPreference, SourceFileHash, StableSourceFileId};
24+
use rustc_span::{RemapPathScopeComponents, SourceFileHash, StableSourceFileId};
2525
use rustc_target::callconv::FnAbi;
2626

2727
pub(crate) use self::emit::{DebugReloc, DebugRelocName};
@@ -44,7 +44,6 @@ pub(crate) struct DebugContext {
4444
namespace_map: DefIdMap<UnitEntryId>,
4545
array_size_type: Option<UnitEntryId>,
4646

47-
filename_display_preference: FileNameDisplayPreference,
4847
embed_source: bool,
4948
}
5049

@@ -102,18 +101,18 @@ impl DebugContext {
102101

103102
let mut dwarf = DwarfUnit::new(encoding);
104103

105-
use rustc_session::config::RemapPathScopeComponents;
106-
107-
let filename_display_preference =
108-
tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
109-
110104
let producer = producer(tcx.sess);
111-
let comp_dir =
112-
tcx.sess.opts.working_dir.to_string_lossy(filename_display_preference).to_string();
105+
let comp_dir = tcx
106+
.sess
107+
.source_map()
108+
.working_dir()
109+
.path(RemapPathScopeComponents::DEBUGINFO)
110+
.to_string_lossy();
113111

114112
let (name, file_info) = match tcx.sess.local_crate_source_file() {
115113
Some(path) => {
116-
let name = path.to_string_lossy(filename_display_preference).to_string();
114+
let name =
115+
path.path(RemapPathScopeComponents::DEBUGINFO).to_string_lossy().into_owned();
117116
(name, None)
118117
}
119118
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
@@ -137,7 +136,7 @@ impl DebugContext {
137136

138137
{
139138
let name = dwarf.strings.add(format!("{name}/@/{cgu_name}"));
140-
let comp_dir = dwarf.strings.add(comp_dir);
139+
let comp_dir = dwarf.strings.add(&*comp_dir);
141140

142141
let root = dwarf.unit.root();
143142
let root = dwarf.unit.get_mut(root);
@@ -180,7 +179,6 @@ impl DebugContext {
180179
stack_pointer_register,
181180
namespace_map: DefIdMap::default(),
182181
array_size_type,
183-
filename_display_preference,
184182
embed_source,
185183
})
186184
}

src/debuginfo/unwind.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ impl UnwindContext {
130130
return;
131131
}
132132

133-
let unwind_info = if let Some(unwind_info) =
133+
let Some(unwind_info) =
134134
context.compiled_code().unwrap().create_unwind_info(module.isa()).unwrap()
135-
{
136-
unwind_info
137-
} else {
135+
else {
138136
return;
139137
};
140138

src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_codegen_ssa::{CodegenResults, TargetConfig};
4747
use rustc_log::tracing::info;
4848
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4949
use rustc_session::Session;
50-
use rustc_session::config::{OutputFilenames, PrintKind, PrintRequest};
50+
use rustc_session::config::OutputFilenames;
5151
use rustc_span::{Symbol, sym};
5252
use rustc_target::spec::{Abi, Arch, Env, Os};
5353

@@ -160,16 +160,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
160160
}
161161
}
162162

163-
fn print(&self, req: &PrintRequest, out: &mut String, _sess: &Session) {
164-
match req.kind {
165-
// FIXME have a default impl that returns false
166-
PrintKind::BackendHasZstd => {
167-
out.push_str("false\n");
168-
}
169-
_ => {}
170-
}
171-
}
172-
173163
fn target_config(&self, sess: &Session) -> TargetConfig {
174164
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
175165
let target_features = match sess.target.arch {

src/optimize/peephole.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ pub(crate) fn maybe_known_branch_taken(
2929
arg: Value,
3030
test_zero: bool,
3131
) -> Option<bool> {
32-
let arg_inst = if let ValueDef::Result(arg_inst, 0) = bcx.func.dfg.value_def(arg) {
33-
arg_inst
34-
} else {
35-
return None;
36-
};
32+
let ValueDef::Result(arg_inst, 0) = bcx.func.dfg.value_def(arg) else { return None };
3733

3834
match bcx.func.dfg.insts[arg_inst] {
3935
InstructionData::UnaryImm { opcode: Opcode::Iconst, imm } => {

0 commit comments

Comments
 (0)