Skip to content

Commit 5eeb567

Browse files
committed
Auto merge of #61601 - Centril:rollup-uegbsns, r=Centril
Rollup of 5 pull requests Successful merges: - #61376 (Add Bound::cloned()) - #61554 (Change visit api) - #61559 (Make visitors iterate) - #61585 (Update .mailmap with my name) - #61591 (Update .mailmap) Failed merges: r? @ghost
2 parents 8b36867 + 9e97970 commit 5eeb567

File tree

9 files changed

+174
-117
lines changed

9 files changed

+174
-117
lines changed

.mailmap

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Chris Thorn <[email protected]> Chris Thorn <[email protected]>
5656
Chris Vittal <[email protected]> Christopher Vittal <[email protected]>
5757
5858
59+
5960
6061
Clinton Ryan <[email protected]>
6162
Corey Richardson <[email protected]> Elaine "See More" Nemo <[email protected]>
@@ -139,6 +140,7 @@ Kang Seonghoon <[email protected]> <[email protected]>
139140
140141
Kevin Butler <[email protected]>
141142
Kyeongwoon Lee <[email protected]>
143+
Laurențiu Nicola <[email protected]>
142144
Lee Jeffery <[email protected]> Lee Jeffery <[email protected]>
143145
Lee Wondong <[email protected]>
144146
Lennart Kudling <[email protected]>

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#![feature(arbitrary_self_types)]
7171
#![feature(asm)]
7272
#![feature(associated_type_defaults)]
73+
#![feature(bound_cloned)]
7374
#![feature(cfg_target_has_atomic)]
7475
#![feature(concat_idents)]
7576
#![feature(const_fn)]

src/libcore/ops/range.rs

+23
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,29 @@ pub enum Bound<T> {
696696
Unbounded,
697697
}
698698

699+
impl<T: Clone> Bound<&T> {
700+
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
701+
///
702+
/// # Examples
703+
///
704+
/// ```
705+
/// #![feature(bound_cloned)]
706+
/// use std::ops::Bound::*;
707+
/// use std::ops::RangeBounds;
708+
///
709+
/// assert_eq!((1..12).start_bound(), Included(&1));
710+
/// assert_eq!((1..12).start_bound().cloned(), Included(1));
711+
/// ```
712+
#[unstable(feature = "bound_cloned", issue = "61356")]
713+
pub fn cloned(self) -> Bound<T> {
714+
match self {
715+
Bound::Unbounded => Bound::Unbounded,
716+
Bound::Included(x) => Bound::Included(x.clone()),
717+
Bound::Excluded(x) => Bound::Excluded(x.clone()),
718+
}
719+
}
720+
}
721+
699722
#[stable(feature = "collections_range", since = "1.28.0")]
700723
/// `RangeBounds` is implemented by Rust's built-in range types, produced
701724
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(bound_cloned)]
12
#![feature(box_syntax)]
23
#![feature(cell_update)]
34
#![feature(core_private_bignum)]

src/libcore/tests/ops.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive};
1+
use core::ops::{Bound, Range, RangeFull, RangeFrom, RangeTo, RangeInclusive};
22

33
// Test the Range structs without the syntactic sugar.
44

@@ -82,3 +82,18 @@ fn test_range_is_empty() {
8282
assert!( (NAN ..= EPSILON).is_empty());
8383
assert!( (NAN ..= NAN).is_empty());
8484
}
85+
86+
#[test]
87+
fn test_bound_cloned_unbounded() {
88+
assert_eq!(Bound::<&u32>::Unbounded.cloned(), Bound::Unbounded);
89+
}
90+
91+
#[test]
92+
fn test_bound_cloned_included() {
93+
assert_eq!(Bound::Included(&3).cloned(), Bound::Included(3));
94+
}
95+
96+
#[test]
97+
fn test_bound_cloned_excluded() {
98+
assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3));
99+
}

src/librustc/mir/visit.rs

+31-27
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ macro_rules! make_mir_visitor {
151151
self.super_place(place, context, location);
152152
}
153153

154-
fn visit_projection(&mut self,
155-
place: & $($mutability)? Projection<'tcx>,
154+
fn visit_place_base(&mut self,
155+
place_base: & $($mutability)? PlaceBase<'tcx>,
156156
context: PlaceContext,
157157
location: Location) {
158-
self.super_projection(place, context, location);
158+
self.super_place_base(place_base, context, location);
159159
}
160160

161-
fn visit_projection_elem(&mut self,
162-
place: & $($mutability)? PlaceElem<'tcx>,
163-
location: Location) {
164-
self.super_projection_elem(place, location);
161+
fn visit_projection(&mut self,
162+
place: & $($mutability)? Projection<'tcx>,
163+
location: Location) {
164+
self.super_projection(place, location);
165165
}
166166

167167
fn visit_constant(&mut self,
@@ -676,36 +676,40 @@ macro_rules! make_mir_visitor {
676676
context: PlaceContext,
677677
location: Location) {
678678
match place {
679-
Place::Base(PlaceBase::Local(local)) => {
680-
self.visit_local(local, context, location);
681-
}
682-
Place::Base(PlaceBase::Static(box Static { kind: _, ty })) => {
683-
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
679+
Place::Base(place_base) => {
680+
self.visit_place_base(place_base, context, location);
684681
}
685682
Place::Projection(proj) => {
686-
self.visit_projection(proj, context, location);
683+
let context = if context.is_mutating_use() {
684+
PlaceContext::MutatingUse(MutatingUseContext::Projection)
685+
} else {
686+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
687+
};
688+
689+
self.visit_place(& $($mutability)? proj.base, context, location);
690+
self.visit_projection(proj, location);
687691
}
688692
}
689693
}
690694

691-
fn super_projection(&mut self,
692-
proj: & $($mutability)? Projection<'tcx>,
695+
fn super_place_base(&mut self,
696+
place_base: & $($mutability)? PlaceBase<'tcx>,
693697
context: PlaceContext,
694698
location: Location) {
695-
let Projection { base, elem } = proj;
696-
let context = if context.is_mutating_use() {
697-
PlaceContext::MutatingUse(MutatingUseContext::Projection)
698-
} else {
699-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
700-
};
701-
self.visit_place(base, context, location);
702-
self.visit_projection_elem(elem, location);
699+
match place_base {
700+
PlaceBase::Local(local) => {
701+
self.visit_local(local, context, location);
702+
}
703+
PlaceBase::Static(box Static { kind: _, ty }) => {
704+
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
705+
}
706+
}
703707
}
704708

705-
fn super_projection_elem(&mut self,
706-
proj: & $($mutability)? PlaceElem<'tcx>,
707-
location: Location) {
708-
match proj {
709+
fn super_projection(&mut self,
710+
proj: & $($mutability)? Projection<'tcx>,
711+
location: Location) {
712+
match & $($mutability)? proj.elem {
709713
ProjectionElem::Deref => {
710714
}
711715
ProjectionElem::Subslice { from: _, to: _ } => {

src/librustc_codegen_ssa/mir/analyze.rs

+48-37
Original file line numberDiff line numberDiff line change
@@ -154,51 +154,62 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
154154
context: PlaceContext,
155155
location: Location) {
156156
debug!("visit_place(place={:?}, context={:?})", place, context);
157+
let mut context = context;
157158
let cx = self.fx.cx;
158159

159-
if let mir::Place::Projection(ref proj) = *place {
160-
// Allow uses of projections that are ZSTs or from scalar fields.
161-
let is_consume = match context {
162-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
163-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) => true,
164-
_ => false
165-
};
166-
if is_consume {
167-
let base_ty = proj.base.ty(self.fx.mir, cx.tcx());
168-
let base_ty = self.fx.monomorphize(&base_ty);
169-
170-
// ZSTs don't require any actual memory access.
171-
let elem_ty = base_ty
172-
.projection_ty(cx.tcx(), &proj.elem)
173-
.ty;
174-
let elem_ty = self.fx.monomorphize(&elem_ty);
175-
if cx.layout_of(elem_ty).is_zst() {
176-
return;
177-
}
178-
179-
if let mir::ProjectionElem::Field(..) = proj.elem {
180-
let layout = cx.layout_of(base_ty.ty);
181-
if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) {
182-
// Recurse with the same context, instead of `Projection`,
183-
// potentially stopping at non-operand projections,
184-
// which would trigger `not_ssa` on locals.
185-
self.visit_place(&proj.base, context, location);
160+
place.iterate(|place_base, place_projections| {
161+
for proj in place_projections {
162+
// Allow uses of projections that are ZSTs or from scalar fields.
163+
let is_consume = match context {
164+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
165+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) => true,
166+
_ => false
167+
};
168+
if is_consume {
169+
let base_ty = proj.base.ty(self.fx.mir, cx.tcx());
170+
let base_ty = self.fx.monomorphize(&base_ty);
171+
172+
// ZSTs don't require any actual memory access.
173+
let elem_ty = base_ty
174+
.projection_ty(cx.tcx(), &proj.elem)
175+
.ty;
176+
let elem_ty = self.fx.monomorphize(&elem_ty);
177+
if cx.layout_of(elem_ty).is_zst() {
186178
return;
187179
}
180+
181+
if let mir::ProjectionElem::Field(..) = proj.elem {
182+
let layout = cx.layout_of(base_ty.ty);
183+
if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) {
184+
// Recurse with the same context, instead of `Projection`,
185+
// potentially stopping at non-operand projections,
186+
// which would trigger `not_ssa` on locals.
187+
continue;
188+
}
189+
}
188190
}
189-
}
190191

191-
// A deref projection only reads the pointer, never needs the place.
192-
if let mir::ProjectionElem::Deref = proj.elem {
193-
return self.visit_place(
194-
&proj.base,
195-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
196-
location
197-
);
192+
// A deref projection only reads the pointer, never needs the place.
193+
if let mir::ProjectionElem::Deref = proj.elem {
194+
return self.visit_place(
195+
&proj.base,
196+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
197+
location
198+
);
199+
}
200+
201+
context = if context.is_mutating_use() {
202+
PlaceContext::MutatingUse(MutatingUseContext::Projection)
203+
} else {
204+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
205+
};
198206
}
199-
}
200207

201-
self.super_place(place, context, location);
208+
// Default base visit behavior
209+
if let mir::PlaceBase::Local(local) = place_base {
210+
self.visit_local(local, context, location);
211+
}
212+
});
202213
}
203214

204215
fn visit_local(&mut self,

src/librustc_mir/monomorphize/collector.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance};
185185
use rustc::ty::print::obsolete::DefPathBasedNames;
186186
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
187187
use rustc::session::config::EntryFnType;
188-
use rustc::mir::{self, Location, Place, PlaceBase, Promoted, Static, StaticKind};
188+
use rustc::mir::{self, Location, PlaceBase, Promoted, Static, StaticKind};
189189
use rustc::mir::visit::Visitor as MirVisitor;
190190
use rustc::mir::mono::{MonoItem, InstantiationMode};
191191
use rustc::mir::interpret::{Scalar, GlobalId, GlobalAlloc, ErrorHandled};
@@ -655,14 +655,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
655655
self.super_terminator_kind(kind, location);
656656
}
657657

658-
fn visit_place(&mut self,
659-
place: &mir::Place<'tcx>,
660-
context: mir::visit::PlaceContext,
661-
location: Location) {
662-
match place {
663-
Place::Base(
664-
PlaceBase::Static(box Static{ kind:StaticKind::Static(def_id), .. })
665-
) => {
658+
fn visit_place_base(&mut self,
659+
place_base: &mir::PlaceBase<'tcx>,
660+
_context: mir::visit::PlaceContext,
661+
location: Location) {
662+
match place_base {
663+
PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), .. }) => {
666664
debug!("visiting static {:?} @ {:?}", def_id, location);
667665

668666
let tcx = self.tcx;
@@ -671,10 +669,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
671669
self.output.push(MonoItem::Static(*def_id));
672670
}
673671
}
674-
_ => {}
672+
PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }) => {
673+
// FIXME: should we handle promoteds here instead of eagerly in collect_neighbours?
674+
}
675+
PlaceBase::Local(_) => {
676+
// Locals have no relevance for collector
677+
}
675678
}
676-
677-
self.super_place(place, context, location);
678679
}
679680
}
680681

0 commit comments

Comments
 (0)