Skip to content

Commit ce1f2cc

Browse files
committed
Auto merge of rust-lang#119889 - GuillaumeGomez:rollup-ah3dhya, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#119817 (Remove special-casing around `AliasKind::Opaque` when structurally resolving in new solver) - rust-lang#119819 (Check rust lints when an unknown lint is detected) - rust-lang#119872 (Give me a way to emit all the delayed bugs as errors (add `-Zeagerly-emit-delayed-bugs`)) - rust-lang#119877 (Add more information to `visit_projection_elem`) - rust-lang#119884 (Rename `--env` option flag to `--env-set`) - rust-lang#119885 (Revert rust-lang#113923) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 174e73a + dafbe17 commit ce1f2cc

File tree

65 files changed

+500
-354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+500
-354
lines changed

compiler/rustc_builtin_macros/src/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Option<Symbol> {
1818
if let Some(value) = cx.sess.opts.logical_env.get(var) {
1919
return Some(Symbol::intern(value));
2020
}
21-
// If the environment variable was not defined with the `--env` option, we try to retrieve it
21+
// If the environment variable was not defined with the `--env-set` option, we try to retrieve it
2222
// from rustc's environment.
2323
env::var(var).ok().as_deref().map(Symbol::intern)
2424
}

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn prepare_lto(
6060
};
6161

6262
let symbol_filter = &|&(ref name, info): &(String, SymbolExportInfo)| {
63-
if info.level.is_below_threshold(export_threshold) || info.used || info.used_compiler {
63+
if info.level.is_below_threshold(export_threshold) || info.used {
6464
Some(CString::new(name.as_str()).unwrap())
6565
} else {
6666
None

compiler/rustc_codegen_llvm/src/back/write.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ pub(crate) unsafe fn llvm_optimize(
569569
unroll_loops,
570570
config.vectorize_slp,
571571
config.vectorize_loop,
572+
config.no_builtins,
572573
config.emit_lifetime_markers,
573574
sanitizer_options.as_ref(),
574575
pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
@@ -677,14 +678,15 @@ pub(crate) unsafe fn codegen(
677678
unsafe fn with_codegen<'ll, F, R>(
678679
tm: &'ll llvm::TargetMachine,
679680
llmod: &'ll llvm::Module,
681+
no_builtins: bool,
680682
f: F,
681683
) -> R
682684
where
683685
F: FnOnce(&'ll mut PassManager<'ll>) -> R,
684686
{
685687
let cpm = llvm::LLVMCreatePassManager();
686688
llvm::LLVMAddAnalysisPasses(tm, cpm);
687-
llvm::LLVMRustAddLibraryInfo(cpm, llmod);
689+
llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins);
688690
f(cpm)
689691
}
690692

@@ -785,7 +787,7 @@ pub(crate) unsafe fn codegen(
785787
} else {
786788
llmod
787789
};
788-
with_codegen(tm, llmod, |cpm| {
790+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
789791
write_output_file(
790792
dcx,
791793
tm,
@@ -820,7 +822,7 @@ pub(crate) unsafe fn codegen(
820822
(_, SplitDwarfKind::Split) => Some(dwo_out.as_path()),
821823
};
822824

823-
with_codegen(tm, llmod, |cpm| {
825+
with_codegen(tm, llmod, config.no_builtins, |cpm| {
824826
write_output_file(
825827
dcx,
826828
tm,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2173,8 +2173,13 @@ extern "C" {
21732173
ArgsCstrBuff: *const c_char,
21742174
ArgsCstrBuffLen: usize,
21752175
) -> *mut TargetMachine;
2176+
21762177
pub fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);
2177-
pub fn LLVMRustAddLibraryInfo<'a>(PM: &PassManager<'a>, M: &'a Module);
2178+
pub fn LLVMRustAddLibraryInfo<'a>(
2179+
PM: &PassManager<'a>,
2180+
M: &'a Module,
2181+
DisableSimplifyLibCalls: bool,
2182+
);
21782183
pub fn LLVMRustWriteOutputFile<'a>(
21792184
T: &'a TargetMachine,
21802185
PM: &PassManager<'a>,
@@ -2196,6 +2201,7 @@ extern "C" {
21962201
UnrollLoops: bool,
21972202
SLPVectorize: bool,
21982203
LoopVectorize: bool,
2204+
DisableSimplifyLibCalls: bool,
21992205
EmitLifetimeMarkers: bool,
22002206
SanitizerOptions: Option<&SanitizerOptions>,
22012207
PGOGenPath: *const c_char,

compiler/rustc_codegen_ssa/src/back/link.rs

+34-12
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,8 @@ pub fn each_linked_rlib(
270270

271271
for &cnum in crates {
272272
match fmts.get(cnum.as_usize() - 1) {
273-
Some(&Linkage::NotLinked | &Linkage::Dynamic) => continue,
274-
Some(&Linkage::IncludedFromDylib) => {
275-
// We always link crate `compiler_builtins` statically. When enabling LTO, we include it as well.
276-
if info.compiler_builtins != Some(cnum) {
277-
continue;
278-
}
279-
}
280-
Some(&Linkage::Static) => {}
273+
Some(&Linkage::NotLinked | &Linkage::Dynamic | &Linkage::IncludedFromDylib) => continue,
274+
Some(_) => {}
281275
None => return Err(errors::LinkRlibError::MissingFormat),
282276
}
283277
let crate_name = info.crate_name[&cnum];
@@ -526,7 +520,8 @@ fn link_staticlib<'a>(
526520
&codegen_results.crate_info,
527521
Some(CrateType::Staticlib),
528522
&mut |cnum, path| {
529-
let lto = are_upstream_rust_objects_already_included(sess);
523+
let lto = are_upstream_rust_objects_already_included(sess)
524+
&& !ignored_for_lto(sess, &codegen_results.crate_info, cnum);
530525

531526
let native_libs = codegen_results.crate_info.native_libraries[&cnum].iter();
532527
let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, lib));
@@ -1277,6 +1272,24 @@ fn link_sanitizer_runtime(
12771272
}
12781273
}
12791274

1275+
/// Returns a boolean indicating whether the specified crate should be ignored
1276+
/// during LTO.
1277+
///
1278+
/// Crates ignored during LTO are not lumped together in the "massive object
1279+
/// file" that we create and are linked in their normal rlib states. See
1280+
/// comments below for what crates do not participate in LTO.
1281+
///
1282+
/// It's unusual for a crate to not participate in LTO. Typically only
1283+
/// compiler-specific and unstable crates have a reason to not participate in
1284+
/// LTO.
1285+
pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool {
1286+
// If our target enables builtin function lowering in LLVM then the
1287+
// crates providing these functions don't participate in LTO (e.g.
1288+
// no_builtins or compiler builtins crates).
1289+
!sess.target.no_builtins
1290+
&& (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
1291+
}
1292+
12801293
/// This functions tries to determine the appropriate linker (and corresponding LinkerFlavor) to use
12811294
pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
12821295
fn infer_from(
@@ -2742,6 +2755,10 @@ fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf {
27422755
// symbols). We must continue to include the rest of the rlib, however, as
27432756
// it may contain static native libraries which must be linked in.
27442757
//
2758+
// (*) Crates marked with `#![no_builtins]` don't participate in LTO and
2759+
// their bytecode wasn't included. The object files in those libraries must
2760+
// still be passed to the linker.
2761+
//
27452762
// Note, however, that if we're not doing LTO we can just pass the rlib
27462763
// blindly to the linker (fast) because it's fine if it's not actually
27472764
// included as we're at the end of the dependency chain.
@@ -2767,7 +2784,9 @@ fn add_static_crate<'a>(
27672784
cmd.link_rlib(&rlib_path);
27682785
};
27692786

2770-
if !are_upstream_rust_objects_already_included(sess) {
2787+
if !are_upstream_rust_objects_already_included(sess)
2788+
|| ignored_for_lto(sess, &codegen_results.crate_info, cnum)
2789+
{
27712790
link_upstream(cratepath);
27722791
return;
27732792
}
@@ -2781,6 +2800,8 @@ fn add_static_crate<'a>(
27812800
let canonical_name = name.replace('-', "_");
27822801
let upstream_rust_objects_already_included =
27832802
are_upstream_rust_objects_already_included(sess);
2803+
let is_builtins =
2804+
sess.target.no_builtins || !codegen_results.crate_info.is_no_builtins.contains(&cnum);
27842805

27852806
let mut archive = archive_builder_builder.new_archive_builder(sess);
27862807
if let Err(error) = archive.add_archive(
@@ -2797,8 +2818,9 @@ fn add_static_crate<'a>(
27972818

27982819
// If we're performing LTO and this is a rust-generated object
27992820
// file, then we don't need the object file as it's part of the
2800-
// LTO module.
2801-
if upstream_rust_objects_already_included && is_rust_object {
2821+
// LTO module. Note that `#![no_builtins]` is excluded from LTO,
2822+
// though, so we let that object file slide.
2823+
if upstream_rust_objects_already_included && is_rust_object && is_builtins {
28022824
return true;
28032825
}
28042826

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
5454
// export level, however, as they're just implementation details.
5555
// Down below we'll hardwire all of the symbols to the `Rust` export
5656
// level instead.
57-
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
58-
let special_runtime_crate = tcx.is_panic_runtime(LOCAL_CRATE) || is_compiler_builtins;
57+
let special_runtime_crate =
58+
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
5959

6060
let mut reachable_non_generics: DefIdMap<_> = tcx
6161
.reachable_set(())
@@ -105,21 +105,16 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
105105
}
106106
})
107107
.map(|def_id| {
108-
let codegen_attrs = tcx.codegen_fn_attrs(def_id.to_def_id());
109108
// We won't link right if this symbol is stripped during LTO.
110109
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;
111-
// We have to preserve the symbols of the built-in functions during LTO.
112-
let is_builtin_fn = is_compiler_builtins
113-
&& symbol_export_level(tcx, def_id.to_def_id())
114-
.is_below_threshold(SymbolExportLevel::C)
115-
&& codegen_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE);
116110
let used = name == "rust_eh_personality";
117111

118112
let export_level = if special_runtime_crate {
119113
SymbolExportLevel::Rust
120114
} else {
121115
symbol_export_level(tcx, def_id.to_def_id())
122116
};
117+
let codegen_attrs = tcx.codegen_fn_attrs(def_id.to_def_id());
123118
debug!(
124119
"EXPORTED SYMBOL (local): {} ({:?})",
125120
tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())),
@@ -139,7 +134,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
139134
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
140135
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
141136
|| used,
142-
used_compiler: is_builtin_fn,
143137
};
144138
(def_id.to_def_id(), info)
145139
})
@@ -152,7 +146,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
152146
level: SymbolExportLevel::C,
153147
kind: SymbolExportKind::Data,
154148
used: false,
155-
used_compiler: false,
156149
},
157150
);
158151
}
@@ -201,7 +194,6 @@ fn exported_symbols_provider_local(
201194
level: info.level,
202195
kind: SymbolExportKind::Text,
203196
used: info.used,
204-
used_compiler: false,
205197
},
206198
)
207199
})
@@ -218,7 +210,6 @@ fn exported_symbols_provider_local(
218210
level: SymbolExportLevel::C,
219211
kind: SymbolExportKind::Text,
220212
used: false,
221-
used_compiler: false,
222213
},
223214
));
224215
}
@@ -238,7 +229,6 @@ fn exported_symbols_provider_local(
238229
level: SymbolExportLevel::Rust,
239230
kind: SymbolExportKind::Text,
240231
used: false,
241-
used_compiler: false,
242232
},
243233
));
244234
}
@@ -251,7 +241,6 @@ fn exported_symbols_provider_local(
251241
level: SymbolExportLevel::Rust,
252242
kind: SymbolExportKind::Data,
253243
used: false,
254-
used_compiler: false,
255244
},
256245
))
257246
}
@@ -271,7 +260,6 @@ fn exported_symbols_provider_local(
271260
level: SymbolExportLevel::C,
272261
kind: SymbolExportKind::Data,
273262
used: false,
274-
used_compiler: false,
275263
},
276264
)
277265
}));
@@ -297,7 +285,6 @@ fn exported_symbols_provider_local(
297285
level: SymbolExportLevel::C,
298286
kind: SymbolExportKind::Data,
299287
used: false,
300-
used_compiler: false,
301288
},
302289
)
303290
}));
@@ -315,7 +302,6 @@ fn exported_symbols_provider_local(
315302
level: SymbolExportLevel::C,
316303
kind: SymbolExportKind::Data,
317304
used: true,
318-
used_compiler: false,
319305
},
320306
));
321307
}
@@ -356,7 +342,6 @@ fn exported_symbols_provider_local(
356342
level: SymbolExportLevel::Rust,
357343
kind: SymbolExportKind::Text,
358344
used: false,
359-
used_compiler: false,
360345
},
361346
));
362347
}
@@ -373,7 +358,6 @@ fn exported_symbols_provider_local(
373358
level: SymbolExportLevel::Rust,
374359
kind: SymbolExportKind::Text,
375360
used: false,
376-
used_compiler: false,
377361
},
378362
));
379363
}

compiler/rustc_codegen_ssa/src/back/write.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,23 @@ impl ModuleConfig {
148148

149149
let emit_obj = if !should_emit_obj {
150150
EmitObj::None
151-
} else if sess.target.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled() {
151+
} else if sess.target.obj_is_bitcode
152+
|| (sess.opts.cg.linker_plugin_lto.enabled() && !no_builtins)
153+
{
152154
// This case is selected if the target uses objects as bitcode, or
153155
// if linker plugin LTO is enabled. In the linker plugin LTO case
154156
// the assumption is that the final link-step will read the bitcode
155157
// and convert it to object code. This may be done by either the
156158
// native linker or rustc itself.
159+
//
160+
// Note, however, that the linker-plugin-lto requested here is
161+
// explicitly ignored for `#![no_builtins]` crates. These crates are
162+
// specifically ignored by rustc's LTO passes and wouldn't work if
163+
// loaded into the linker. These crates define symbols that LLVM
164+
// lowers intrinsics to, and these symbol dependencies aren't known
165+
// until after codegen. As a result any crate marked
166+
// `#![no_builtins]` is assumed to not participate in LTO and
167+
// instead goes on to generate object code.
157168
EmitObj::Bitcode
158169
} else if need_bitcode_in_object(tcx) {
159170
EmitObj::ObjectCode(BitcodeSection::Full)
@@ -1023,6 +1034,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
10231034

10241035
let mut each_linked_rlib_for_lto = Vec::new();
10251036
drop(link::each_linked_rlib(crate_info, None, &mut |cnum, path| {
1037+
if link::ignored_for_lto(sess, crate_info, cnum) {
1038+
return;
1039+
}
10261040
each_linked_rlib_for_lto.push((cnum, path.to_path_buf()));
10271041
}));
10281042

compiler/rustc_codegen_ssa/src/base.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ impl CrateInfo {
859859
local_crate_name,
860860
compiler_builtins,
861861
profiler_runtime: None,
862+
is_no_builtins: Default::default(),
862863
native_libraries: Default::default(),
863864
used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(),
864865
crate_name: Default::default(),
@@ -885,14 +886,19 @@ impl CrateInfo {
885886
if tcx.is_profiler_runtime(cnum) {
886887
info.profiler_runtime = Some(cnum);
887888
}
889+
if tcx.is_no_builtins(cnum) {
890+
info.is_no_builtins.insert(cnum);
891+
}
888892
}
889893

890894
// Handle circular dependencies in the standard library.
891895
// See comment before `add_linked_symbol_object` function for the details.
892896
// If global LTO is enabled then almost everything (*) is glued into a single object file,
893897
// so this logic is not necessary and can cause issues on some targets (due to weak lang
894898
// item symbols being "privatized" to that object file), so we disable it.
895-
// (*) Native libs are not glued, and we assume that they cannot define weak lang items.
899+
// (*) Native libs, and `#[compiler_builtins]` and `#[no_builtins]` crates are not glued,
900+
// and we assume that they cannot define weak lang items. This is not currently enforced
901+
// by the compiler, but that's ok because all this stuff is unstable anyway.
896902
let target = &tcx.sess.target;
897903
if !are_upstream_rust_objects_already_included(tcx.sess) {
898904
let missing_weak_lang_items: FxHashSet<Symbol> = info

compiler/rustc_codegen_ssa/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern crate tracing;
2525
extern crate rustc_middle;
2626

2727
use rustc_ast as ast;
28-
use rustc_data_structures::fx::FxHashMap;
28+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2929
use rustc_data_structures::sync::Lrc;
3030
use rustc_hir::def_id::CrateNum;
3131
use rustc_middle::dep_graph::WorkProduct;
@@ -158,6 +158,7 @@ pub struct CrateInfo {
158158
pub local_crate_name: Symbol,
159159
pub compiler_builtins: Option<CrateNum>,
160160
pub profiler_runtime: Option<CrateNum>,
161+
pub is_no_builtins: FxHashSet<CrateNum>,
161162
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
162163
pub crate_name: FxHashMap<CrateNum, Symbol>,
163164
pub used_libraries: Vec<NativeLib>,

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8585
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8686
fn annotation_type_for_level(level: Level) -> AnnotationType {
8787
match level {
88-
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error => AnnotationType::Error,
88+
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
8989
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9090
Level::Note | Level::OnceNote => AnnotationType::Note,
9191
Level::Help | Level::OnceHelp => AnnotationType::Help,

0 commit comments

Comments
 (0)