Skip to content

Commit de0fda9

Browse files
committed
Address review comments
- Add back `HirIdVec`, with a comment that it will soon be used. - Add back `*_region` functions, with a comment they may soon be used. - Remove `-Z borrowck_stats` completely. It didn't do anything. - Remove `make_nop` completely. - Add back `current_loc`, which is used by an out-of-tree tool. - Fix style nits - Remove `AtomicCell` with `cfg(parallel_compiler)` for consistency.
1 parent 441dc36 commit de0fda9

File tree

10 files changed

+154
-18
lines changed

10 files changed

+154
-18
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,74 @@ pub mod coverageinfo {
703703
kind: RegionKind::CodeRegion,
704704
}
705705
}
706+
707+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
708+
// support.
709+
#[allow(dead_code)]
710+
crate fn expansion_region(
711+
file_id: u32,
712+
expanded_file_id: u32,
713+
start_line: u32,
714+
start_col: u32,
715+
end_line: u32,
716+
end_col: u32,
717+
) -> Self {
718+
Self {
719+
counter: coverage_map::Counter::zero(),
720+
file_id,
721+
expanded_file_id,
722+
start_line,
723+
start_col,
724+
end_line,
725+
end_col,
726+
kind: RegionKind::ExpansionRegion,
727+
}
728+
}
729+
730+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
731+
// support.
732+
#[allow(dead_code)]
733+
crate fn skipped_region(
734+
file_id: u32,
735+
start_line: u32,
736+
start_col: u32,
737+
end_line: u32,
738+
end_col: u32,
739+
) -> Self {
740+
Self {
741+
counter: coverage_map::Counter::zero(),
742+
file_id,
743+
expanded_file_id: 0,
744+
start_line,
745+
start_col,
746+
end_line,
747+
end_col,
748+
kind: RegionKind::SkippedRegion,
749+
}
750+
}
751+
752+
// This function might be used in the future; the LLVM API is still evolving, as is coverage
753+
// support.
754+
#[allow(dead_code)]
755+
crate fn gap_region(
756+
counter: coverage_map::Counter,
757+
file_id: u32,
758+
start_line: u32,
759+
start_col: u32,
760+
end_line: u32,
761+
end_col: u32,
762+
) -> Self {
763+
Self {
764+
counter,
765+
file_id,
766+
expanded_file_id: 0,
767+
start_line,
768+
start_col,
769+
end_line,
770+
end_col: ((1 as u32) << 31) | end_col,
771+
kind: RegionKind::GapRegion,
772+
}
773+
}
706774
}
707775
}
708776

compiler/rustc_data_structures/src/sync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ cfg_if! {
236236

237237
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};
238238

239-
pub use crossbeam_utils::atomic::AtomicCell;
240-
241239
pub use std::sync::Arc as Lrc;
242240
pub use std::sync::Weak as Weak;
243241

compiler/rustc_driver/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
157157
self
158158
}
159159
/// Used by RLS.
160-
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self
161-
{
162-
self.emitter = emitter;
163-
self
160+
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self {
161+
self.emitter = emitter;
162+
self
164163
}
165164
/// Used by RLS.
166165
pub fn set_file_loader(

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ impl PrimTy {
22062206
Self::Str,
22072207
];
22082208

2209-
/// [`PrimTy::name`], but returns a &str instead of a symbol.
2209+
/// Like [`PrimTy::name`], but returns a &str instead of a symbol.
22102210
///
22112211
/// Used by rustdoc.
22122212
pub fn name_str(self) -> &'static str {

compiler/rustc_hir/src/hir_id.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
2+
use rustc_index::vec::IndexVec;
23
use std::fmt;
34

45
/// Uniquely identifies a node in the HIR of the current crate. It is
@@ -61,3 +62,70 @@ pub const CRATE_HIR_ID: HirId = HirId {
6162
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
6263
local_id: ItemLocalId::from_u32(0),
6364
};
65+
66+
/// N.B. This collection is currently unused, but will be used by #72015 and future PRs.
67+
#[derive(Clone, Default, Debug, Encodable, Decodable)]
68+
pub struct HirIdVec<T> {
69+
map: IndexVec<LocalDefId, IndexVec<ItemLocalId, T>>,
70+
}
71+
72+
impl<T> HirIdVec<T> {
73+
pub fn push_owner(&mut self, id: LocalDefId) {
74+
self.map.ensure_contains_elem(id, IndexVec::new);
75+
}
76+
77+
pub fn push(&mut self, id: HirId, value: T) {
78+
if id.local_id == ItemLocalId::from_u32(0) {
79+
self.push_owner(id.owner);
80+
}
81+
let submap = &mut self.map[id.owner];
82+
let _ret_id = submap.push(value);
83+
debug_assert_eq!(_ret_id, id.local_id);
84+
}
85+
86+
pub fn push_sparse(&mut self, id: HirId, value: T)
87+
where
88+
T: Default,
89+
{
90+
self.map.ensure_contains_elem(id.owner, IndexVec::new);
91+
let submap = &mut self.map[id.owner];
92+
let i = id.local_id.index();
93+
let len = submap.len();
94+
if i >= len {
95+
submap.extend(std::iter::repeat_with(T::default).take(i - len + 1));
96+
}
97+
submap[id.local_id] = value;
98+
}
99+
100+
pub fn get(&self, id: HirId) -> Option<&T> {
101+
self.map.get(id.owner)?.get(id.local_id)
102+
}
103+
104+
pub fn get_owner(&self, id: LocalDefId) -> &IndexVec<ItemLocalId, T> {
105+
&self.map[id]
106+
}
107+
108+
pub fn iter(&self) -> impl Iterator<Item = &T> {
109+
self.map.iter().flat_map(|la| la.iter())
110+
}
111+
112+
pub fn iter_enumerated(&self) -> impl Iterator<Item = (HirId, &T)> {
113+
self.map.iter_enumerated().flat_map(|(owner, la)| {
114+
la.iter_enumerated().map(move |(local_id, attr)| (HirId { owner, local_id }, attr))
115+
})
116+
}
117+
}
118+
119+
impl<T> std::ops::Index<HirId> for HirIdVec<T> {
120+
type Output = T;
121+
122+
fn index(&self, id: HirId) -> &T {
123+
&self.map[id.owner][id.local_id]
124+
}
125+
}
126+
127+
impl<T> std::ops::IndexMut<HirId> for HirIdVec<T> {
128+
fn index_mut(&mut self, id: HirId) -> &mut T {
129+
&mut self.map[id.owner][id.local_id]
130+
}
131+
}

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
146146
}
147147
}
148148

149-
pub(crate) struct Instantiate {}
149+
pub(crate) struct Instantiate;
150150

151151
pub(crate) struct Delegate;
152152

@@ -222,7 +222,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
222222
// Hack: we only need this so that `types_escaping_snapshot`
223223
// can see what has been unified; see the Delegate impl for
224224
// more details.
225-
self.undo_log.push(Instantiate {});
225+
self.undo_log.push(Instantiate);
226226
}
227227

228228
/// Creates a new type variable.

compiler/rustc_interface/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ fn test_debugging_options_tracking_hash() {
471471
untracked!(ast_json, true);
472472
untracked!(ast_json_noexpand, true);
473473
untracked!(borrowck, String::from("other"));
474-
untracked!(borrowck_stats, true);
475474
untracked!(deduplicate_diagnostics, true);
476475
untracked!(dep_tasks, true);
477476
untracked!(dont_buffer_diagnostics, true);

compiler/rustc_mir/src/interpret/eval_context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ impl<'mir, 'tcx, Tag> Frame<'mir, 'tcx, Tag> {
226226
}
227227

228228
impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> {
229+
/// Get the current location within the Frame.
230+
///
231+
/// If this is `Err`, we are not currently executing any particular statement in
232+
/// this frame (can happen e.g. during frame initialization, and during unwinding on
233+
/// frames without cleanup code).
234+
/// We basically abuse `Result` as `Either`.
235+
///
236+
/// Used by priroda.
237+
pub fn current_loc(&self) -> Result<mir::Location, Span> {
238+
self.loc
239+
}
240+
229241
/// Return the `SourceInfo` of the current instruction.
230242
pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
231243
self.loc.ok().map(|loc| self.body.source_info(loc))

compiler/rustc_mir/src/util/patch.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub struct MirPatch<'tcx> {
1313
new_locals: Vec<LocalDecl<'tcx>>,
1414
resume_block: BasicBlock,
1515
next_local: usize,
16-
make_nop: Vec<Location>,
1716
}
1817

1918
impl<'tcx> MirPatch<'tcx> {
@@ -25,7 +24,6 @@ impl<'tcx> MirPatch<'tcx> {
2524
new_locals: vec![],
2625
next_local: body.local_decls.len(),
2726
resume_block: START_BLOCK,
28-
make_nop: vec![],
2927
};
3028

3129
// make sure the MIR we create has a resume block. It is
@@ -118,10 +116,6 @@ impl<'tcx> MirPatch<'tcx> {
118116
}
119117

120118
pub fn apply(self, body: &mut Body<'tcx>) {
121-
debug!("MirPatch: make nops at: {:?}", self.make_nop);
122-
for loc in self.make_nop {
123-
body.make_statement_nop(loc);
124-
}
125119
debug!(
126120
"MirPatch: {:?} new temps, starting from index {}: {:?}",
127121
self.new_locals.len(),

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
906906
(default: no)"),
907907
borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
908908
"select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"),
909-
borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
910-
"gather borrowck statistics (default: no)"),
911909
cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
912910
"the codegen unit partitioning strategy to use"),
913911
chalk: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)