Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c282c1c

Browse files
Use OnceCell instead of Once
1 parent 9f82785 commit c282c1c

File tree

39 files changed

+118
-102
lines changed

39 files changed

+118
-102
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,9 @@ name = "once_cell"
23272327
version = "1.1.0"
23282328
source = "registry+https://github.com/rust-lang/crates.io-index"
23292329
checksum = "d6a04cb71e910d0034815600180f62a95bf6e67942d7ab52a166a68c7d7e9cd0"
2330+
dependencies = [
2331+
"parking_lot 0.9.0",
2332+
]
23302333

23312334
[[package]]
23322335
name = "opaque-debug"

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn lower_crate<'a, 'hir>(
269269
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");
270270

271271
LoweringContext {
272-
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),
272+
crate_root: sess.parse_sess.injected_crate_name.get().copied(),
273273
sess,
274274
resolver,
275275
nt_to_tokenstream,

src/librustc_codegen_llvm/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub unsafe fn create_module(
174174
llvm::LLVMRustSetModulePICLevel(llmod);
175175
// PIE is potentially more effective than PIC, but can only be used in executables.
176176
// If all our outputs are executables, then we can relax PIC to PIE.
177-
if sess.crate_types.get().iter().all(|ty| *ty == CrateType::Executable) {
177+
if sess.crate_types().iter().all(|ty| *ty == CrateType::Executable) {
178178
llvm::LLVMRustSetModulePIELevel(llmod);
179179
}
180180
}

src/librustc_codegen_ssa/back/link.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
5353
) {
5454
let _timer = sess.timer("link_binary");
5555
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
56-
for &crate_type in sess.crate_types.borrow().iter() {
56+
for &crate_type in sess.crate_types().iter() {
5757
// Ignore executable crates if we have -Z no-codegen, as they will error.
5858
if (sess.opts.debugging_opts.no_codegen || !sess.opts.output_types.should_codegen())
5959
&& !output_metadata
@@ -875,11 +875,8 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
875875

876876
// If we're only producing artifacts that are archives, no need to preserve
877877
// the objects as they're losslessly contained inside the archives.
878-
let output_linked = sess
879-
.crate_types
880-
.borrow()
881-
.iter()
882-
.any(|&x| x != CrateType::Rlib && x != CrateType::Staticlib);
878+
let output_linked =
879+
sess.crate_types().iter().any(|&x| x != CrateType::Rlib && x != CrateType::Staticlib);
883880
if !output_linked {
884881
return false;
885882
}

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl LinkerInfo {
4444
LinkerInfo {
4545
exports: tcx
4646
.sess
47-
.crate_types
48-
.borrow()
47+
.crate_types()
4948
.iter()
5049
.map(|&c| (c, exported_symbols(tcx, c)))
5150
.collect(),

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::{SymbolName, TyCtxt};
1818
use rustc_session::config::{CrateType, Sanitizer};
1919

2020
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
21-
crates_export_threshold(&tcx.sess.crate_types.borrow())
21+
crates_export_threshold(&tcx.sess.crate_types())
2222
}
2323

2424
fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel {
@@ -212,7 +212,7 @@ fn exported_symbols_provider_local(
212212
}));
213213
}
214214

215-
if tcx.sess.crate_types.borrow().contains(&CrateType::Dylib) {
215+
if tcx.sess.crate_types().contains(&CrateType::Dylib) {
216216
let symbol_name = metadata_symbol_name(tcx);
217217
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
218218

src/librustc_codegen_ssa/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub struct CompiledModules {
382382

383383
fn need_bitcode_in_object(sess: &Session) -> bool {
384384
let requested_for_rlib = sess.opts.cg.embed_bitcode
385-
&& sess.crate_types.borrow().contains(&CrateType::Rlib)
385+
&& sess.crate_types().contains(&CrateType::Rlib)
386386
&& sess.opts.output_types.contains_key(&OutputType::Exe);
387387
let forced_by_target = sess.target.target.options.forces_embed_bitcode;
388388
requested_for_rlib || forced_by_target
@@ -991,7 +991,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
991991
};
992992
let cgcx = CodegenContext::<B> {
993993
backend: backend.clone(),
994-
crate_types: sess.crate_types.borrow().clone(),
994+
crate_types: sess.crate_types().to_vec(),
995995
each_linked_rlib_for_lto,
996996
lto: sess.lto(),
997997
no_landing_pads: sess.panic_strategy() == PanicStrategy::Abort,
@@ -1812,7 +1812,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
18121812
);
18131813

18141814
tcx.sess.target.target.options.is_like_msvc &&
1815-
tcx.sess.crate_types.borrow().iter().any(|ct| *ct == CrateType::Rlib) &&
1815+
tcx.sess.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
18161816
// ThinLTO can't handle this workaround in all cases, so we don't
18171817
// emit the `__imp_` symbols. Instead we make them unnecessary by disallowing
18181818
// dynamic linking when linker plugin LTO is enabled.

src/librustc_codegen_ssa/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguR
948948
match compute_per_cgu_lto_type(
949949
&tcx.sess.lto(),
950950
&tcx.sess.opts,
951-
&tcx.sess.crate_types.borrow(),
951+
&tcx.sess.crate_types(),
952952
ModuleKind::Regular,
953953
) {
954954
ComputedLtoType::No => CguReuse::PostLto,

src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl RustcDefaultCalls {
586586
if let Input::File(file) = compiler.input() {
587587
// FIXME: #![crate_type] and #![crate_name] support not implemented yet
588588
let attrs = vec![];
589-
sess.crate_types.set(collect_crate_types(sess, &attrs));
589+
sess.init_crate_types(collect_crate_types(sess, &attrs));
590590
let outputs = compiler.build_output_filenames(&sess, &attrs);
591591
let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| {
592592
sess.fatal(&format!("failed to read rlink file: {}", err));

src/librustc_driver/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub fn print_after_parsing(
396396
annotation.pp_ann(),
397397
false,
398398
parse.edition,
399-
parse.injected_crate_name.try_get().is_some(),
399+
parse.injected_crate_name.get().is_some(),
400400
)
401401
})
402402
} else {
@@ -438,7 +438,7 @@ pub fn print_after_hir_lowering<'tcx>(
438438
annotation.pp_ann(),
439439
true,
440440
parse.edition,
441-
parse.injected_crate_name.try_get().is_some(),
441+
parse.injected_crate_name.get().is_some(),
442442
)
443443
})
444444
}

0 commit comments

Comments
 (0)