Skip to content

Commit dc6db14

Browse files
committed
Auto merge of #61210 - Centril:rollup-ofr6h5b, r=Centril
Rollup of 4 pull requests Successful merges: - #61077 (Don't arena-allocate static symbols.) - #61102 (Move path for iterate) - #61120 (Make eval_place iterate instead of recurse) - #61205 (docs: fix typo #61197) Failed merges: r? @ghost
2 parents 566f3d7 + e9933ee commit dc6db14

File tree

4 files changed

+109
-111
lines changed

4 files changed

+109
-111
lines changed

src/doc/rustdoc/src/the-doc-attribute.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ mod bar {
202202
Now we'll have a `Re-exports` line, and `Bar` will not link to anywhere.
203203

204204
One special case: In Rust 2018 and later, if you `pub use` one of your dependencies, `rustdoc` will
205-
not eagerly inline it as a module unless you add `#[doc(inline)}`.
205+
not eagerly inline it as a module unless you add `#[doc(inline)]`.
206206

207207
## `#[doc(hidden)]`
208208

src/librustc_mir/dataflow/move_paths/builder.rs

+73-68
Original file line numberDiff line numberDiff line change
@@ -95,82 +95,87 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
9595
-> Result<MovePathIndex, MoveError<'tcx>>
9696
{
9797
debug!("lookup({:?})", place);
98-
match *place {
99-
Place::Base(PlaceBase::Local(local)) => Ok(self.builder.data.rev_lookup.locals[local]),
100-
Place::Base(PlaceBase::Static(..)) => {
101-
Err(MoveError::cannot_move_out_of(self.loc, Static))
102-
}
103-
Place::Projection(ref proj) => {
104-
self.move_path_for_projection(place, proj)
98+
place.iterate(|place_base, place_projection| {
99+
let mut base = match place_base {
100+
PlaceBase::Local(local) => self.builder.data.rev_lookup.locals[*local],
101+
PlaceBase::Static(..) => {
102+
return Err(MoveError::cannot_move_out_of(self.loc, Static));
103+
}
104+
};
105+
106+
for proj in place_projection {
107+
let mir = self.builder.mir;
108+
let tcx = self.builder.tcx;
109+
let place_ty = proj.base.ty(mir, tcx).ty;
110+
match place_ty.sty {
111+
ty::Ref(..) | ty::RawPtr(..) =>
112+
return Err(MoveError::cannot_move_out_of(
113+
self.loc,
114+
BorrowedContent {
115+
target_place: Place::Projection(Box::new(proj.clone())),
116+
})),
117+
ty::Adt(adt, _) if adt.has_dtor(tcx) && !adt.is_box() =>
118+
return Err(MoveError::cannot_move_out_of(self.loc,
119+
InteriorOfTypeWithDestructor {
120+
container_ty: place_ty
121+
})),
122+
// move out of union - always move the entire union
123+
ty::Adt(adt, _) if adt.is_union() =>
124+
return Err(MoveError::UnionMove { path: base }),
125+
ty::Slice(_) =>
126+
return Err(MoveError::cannot_move_out_of(
127+
self.loc,
128+
InteriorOfSliceOrArray {
129+
ty: place_ty, is_index: match proj.elem {
130+
ProjectionElem::Index(..) => true,
131+
_ => false
132+
},
133+
})),
134+
ty::Array(..) => match proj.elem {
135+
ProjectionElem::Index(..) =>
136+
return Err(MoveError::cannot_move_out_of(
137+
self.loc,
138+
InteriorOfSliceOrArray {
139+
ty: place_ty, is_index: true
140+
})),
141+
_ => {
142+
// FIXME: still badly broken
143+
}
144+
},
145+
_ => {}
146+
};
147+
148+
base = match self
149+
.builder
150+
.data
151+
.rev_lookup
152+
.projections
153+
.entry((base, proj.elem.lift()))
154+
{
155+
Entry::Occupied(ent) => *ent.get(),
156+
Entry::Vacant(ent) => {
157+
let path = MoveDataBuilder::new_move_path(
158+
&mut self.builder.data.move_paths,
159+
&mut self.builder.data.path_map,
160+
&mut self.builder.data.init_path_map,
161+
Some(base),
162+
Place::Projection(Box::new(proj.clone())),
163+
);
164+
ent.insert(path);
165+
path
166+
}
167+
};
105168
}
106-
}
169+
170+
Ok(base)
171+
})
107172
}
108173

109174
fn create_move_path(&mut self, place: &Place<'tcx>) {
110175
// This is an non-moving access (such as an overwrite or
111176
// drop), so this not being a valid move path is OK.
112177
let _ = self.move_path_for(place);
113178
}
114-
115-
fn move_path_for_projection(&mut self,
116-
place: &Place<'tcx>,
117-
proj: &Projection<'tcx>)
118-
-> Result<MovePathIndex, MoveError<'tcx>>
119-
{
120-
let base = self.move_path_for(&proj.base)?;
121-
let mir = self.builder.mir;
122-
let tcx = self.builder.tcx;
123-
let place_ty = proj.base.ty(mir, tcx).ty;
124-
match place_ty.sty {
125-
ty::Ref(..) | ty::RawPtr(..) =>
126-
return Err(MoveError::cannot_move_out_of(
127-
self.loc,
128-
BorrowedContent { target_place: place.clone() })),
129-
ty::Adt(adt, _) if adt.has_dtor(tcx) && !adt.is_box() =>
130-
return Err(MoveError::cannot_move_out_of(self.loc,
131-
InteriorOfTypeWithDestructor {
132-
container_ty: place_ty
133-
})),
134-
// move out of union - always move the entire union
135-
ty::Adt(adt, _) if adt.is_union() =>
136-
return Err(MoveError::UnionMove { path: base }),
137-
ty::Slice(_) =>
138-
return Err(MoveError::cannot_move_out_of(
139-
self.loc,
140-
InteriorOfSliceOrArray {
141-
ty: place_ty, is_index: match proj.elem {
142-
ProjectionElem::Index(..) => true,
143-
_ => false
144-
},
145-
})),
146-
ty::Array(..) => match proj.elem {
147-
ProjectionElem::Index(..) =>
148-
return Err(MoveError::cannot_move_out_of(
149-
self.loc,
150-
InteriorOfSliceOrArray {
151-
ty: place_ty, is_index: true
152-
})),
153-
_ => {
154-
// FIXME: still badly broken
155-
}
156-
},
157-
_ => {}
158-
};
159-
match self.builder.data.rev_lookup.projections.entry((base, proj.elem.lift())) {
160-
Entry::Occupied(ent) => Ok(*ent.get()),
161-
Entry::Vacant(ent) => {
162-
let path = MoveDataBuilder::new_move_path(
163-
&mut self.builder.data.move_paths,
164-
&mut self.builder.data.path_map,
165-
&mut self.builder.data.init_path_map,
166-
Some(base),
167-
place.clone()
168-
);
169-
ent.insert(path);
170-
Ok(path)
171-
}
172-
}
173-
}
174179
}
175180

176181
impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {

src/librustc_mir/interpret/place.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -607,42 +607,42 @@ where
607607
/// place; for reading, a more efficient alternative is `eval_place_for_read`.
608608
pub fn eval_place(
609609
&mut self,
610-
mir_place: &mir::Place<'tcx>
610+
mir_place: &mir::Place<'tcx>,
611611
) -> EvalResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
612-
use rustc::mir::Place::*;
613612
use rustc::mir::PlaceBase;
614-
let place = match mir_place {
615-
Base(PlaceBase::Local(mir::RETURN_PLACE)) => match self.frame().return_place {
616-
Some(return_place) =>
617-
// We use our layout to verify our assumption; caller will validate
618-
// their layout on return.
619-
PlaceTy {
620-
place: *return_place,
621-
layout: self.layout_of(self.monomorphize(self.frame().mir.return_ty())?)?,
613+
614+
mir_place.iterate(|place_base, place_projection| {
615+
let mut place = match place_base {
616+
PlaceBase::Local(mir::RETURN_PLACE) => match self.frame().return_place {
617+
Some(return_place) => {
618+
// We use our layout to verify our assumption; caller will validate
619+
// their layout on return.
620+
PlaceTy {
621+
place: *return_place,
622+
layout: self
623+
.layout_of(self.monomorphize(self.frame().mir.return_ty())?)?,
624+
}
625+
}
626+
None => return err!(InvalidNullPointerUsage),
627+
},
628+
PlaceBase::Local(local) => PlaceTy {
629+
// This works even for dead/uninitialized locals; we check further when writing
630+
place: Place::Local {
631+
frame: self.cur_frame(),
632+
local: *local,
622633
},
623-
None => return err!(InvalidNullPointerUsage),
624-
},
625-
Base(PlaceBase::Local(local)) => PlaceTy {
626-
// This works even for dead/uninitialized locals; we check further when writing
627-
place: Place::Local {
628-
frame: self.cur_frame(),
629-
local: *local,
634+
layout: self.layout_of_local(self.frame(), *local, None)?,
630635
},
631-
layout: self.layout_of_local(self.frame(), *local, None)?,
632-
},
633-
634-
Projection(proj) => {
635-
let place = self.eval_place(&proj.base)?;
636-
self.place_projection(place, &proj.elem)?
637-
}
636+
PlaceBase::Static(place_static) => self.eval_static_to_mplace(place_static)?.into(),
637+
};
638638

639-
Base(PlaceBase::Static(place_static)) => {
640-
self.eval_static_to_mplace(place_static)?.into()
639+
for proj in place_projection {
640+
place = self.place_projection(place, &proj.elem)?
641641
}
642-
};
643642

644-
self.dump_place(place.place);
645-
Ok(place)
643+
self.dump_place(place.place);
644+
Ok(place)
645+
})
646646
}
647647

648648
/// Write a scalar to a place

src/libsyntax_pos/symbol.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -866,20 +866,13 @@ pub struct Interner {
866866
}
867867

868868
impl Interner {
869-
fn prefill(init: &[&str]) -> Self {
870-
let mut this = Interner::default();
871-
this.names.reserve(init.len());
872-
this.strings.reserve(init.len());
873-
874-
// We can't allocate empty strings in the arena, so handle this here.
875-
assert!(kw::Invalid.as_u32() == 0 && init[0].is_empty());
876-
this.names.insert("", kw::Invalid);
877-
this.strings.push("");
878-
879-
for string in &init[1..] {
880-
this.intern(string);
869+
fn prefill(init: &[&'static str]) -> Self {
870+
let symbols = (0 .. init.len() as u32).map(Symbol::new);
871+
Interner {
872+
strings: init.to_vec(),
873+
names: init.iter().copied().zip(symbols).collect(),
874+
..Default::default()
881875
}
882-
this
883876
}
884877

885878
pub fn intern(&mut self, string: &str) -> Symbol {

0 commit comments

Comments
 (0)