Skip to content

Commit e05c3b7

Browse files
committed
auto merge of #17978 : arielb1/rust/remaining-garbage, r=nikomatsakis
it seems to be some kind of leftover GC-related detritus
2 parents e2cd459 + 19faaf1 commit e05c3b7

File tree

9 files changed

+35
-133
lines changed

9 files changed

+35
-133
lines changed

src/librustc/middle/borrowck/check_loans.rs

-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
831831
return;
832832
}
833833

834-
mc::cat_discr(b, _) |
835834
mc::cat_deref(b, _, mc::OwnedPtr) => {
836835
assert_eq!(cmt.mutbl, mc::McInherited);
837836
cmt = b;

src/librustc/middle/borrowck/gather_loans/gather_moves.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
159159
}
160160
}
161161

162-
mc::cat_deref(ref b, _, mc::OwnedPtr) |
163-
mc::cat_discr(ref b, _) => {
162+
mc::cat_deref(ref b, _, mc::OwnedPtr) => {
164163
check_and_get_illegal_move_origin(bccx, b)
165164
}
166165
}

src/librustc/middle/borrowck/gather_loans/lifetime.rs

+1-58
Original file line numberDiff line numberDiff line change
@@ -84,62 +84,6 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
8484
mc::cat_interior(ref base, _) => { // L-Field
8585
self.check(base, discr_scope)
8686
}
87-
88-
mc::cat_discr(ref base, new_discr_scope) => {
89-
// Subtle: in a match, we must ensure that each binding
90-
// variable remains valid for the duration of the arm in
91-
// which it appears, presuming that this arm is taken.
92-
// But it is inconvenient in trans to root something just
93-
// for one arm. Therefore, we insert a cat_discr(),
94-
// basically a special kind of category that says "if this
95-
// value must be dynamically rooted, root it for the scope
96-
// `match_id`".
97-
//
98-
// As an example, consider this scenario:
99-
//
100-
// let mut x = @Some(3);
101-
// match *x { Some(y) {...} None {...} }
102-
//
103-
// Technically, the value `x` need only be rooted
104-
// in the `some` arm. However, we evaluate `x` in trans
105-
// before we know what arm will be taken, so we just
106-
// always root it for the duration of the match.
107-
//
108-
// As a second example, consider *this* scenario:
109-
//
110-
// let x = @@Some(3);
111-
// match x { @@Some(y) {...} @@None {...} }
112-
//
113-
// Here again, `x` need only be rooted in the `some` arm.
114-
// In this case, the value which needs to be rooted is
115-
// found only when checking which pattern matches: but
116-
// this check is done before entering the arm. Therefore,
117-
// even in this case we just choose to keep the value
118-
// rooted for the entire match. This means the value will be
119-
// rooted even if the none arm is taken. Oh well.
120-
//
121-
// At first, I tried to optimize the second case to only
122-
// root in one arm, but the result was suboptimal: first,
123-
// it interfered with the construction of phi nodes in the
124-
// arm, as we were adding code to root values before the
125-
// phi nodes were added. This could have been addressed
126-
// with a second basic block. However, the naive approach
127-
// also yielded suboptimal results for patterns like:
128-
//
129-
// let x = @@...;
130-
// match x { @@some_variant(y) | @@some_other_variant(y) =>
131-
//
132-
// The reason is that we would root the value once for
133-
// each pattern and not once per arm. This is also easily
134-
// fixed, but it's yet more code for what is really quite
135-
// the corner case.
136-
//
137-
// Nonetheless, if you decide to optimize this case in the
138-
// future, you need only adjust where the cat_discr()
139-
// node appears to draw the line between what will be rooted
140-
// in the *arm* vs the *match*.
141-
self.check(base, Some(new_discr_scope))
142-
}
14387
}
14488
}
14589

@@ -182,8 +126,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
182126
}
183127
mc::cat_downcast(ref cmt) |
184128
mc::cat_deref(ref cmt, _, mc::OwnedPtr) |
185-
mc::cat_interior(ref cmt, _) |
186-
mc::cat_discr(ref cmt, _) => {
129+
mc::cat_interior(ref cmt, _) => {
187130
self.scope(cmt)
188131
}
189132
}

src/librustc/middle/borrowck/gather_loans/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
213213
/*!
214214
* Guarantees that `addr_of(cmt)` will be valid for the duration of
215215
* `static_scope_r`, or reports an error. This may entail taking
216-
* out loans, which will be added to the `req_loan_map`. This can
217-
* also entail "rooting" GC'd pointers, which means ensuring
218-
* dynamically that they are not freed.
216+
* out loans, which will be added to the `req_loan_map`.
219217
*/
220218

221219
debug!("guarantee_valid(borrow_id={}, cmt={}, \

src/librustc/middle/borrowck/gather_loans/restrictions.rs

+28-49
Original file line numberDiff line numberDiff line change
@@ -96,46 +96,27 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
9696
self.extend(result, cmt.mutbl, LpInterior(i))
9797
}
9898

99-
mc::cat_deref(cmt_base, _, pk @ mc::OwnedPtr) => {
100-
// R-Deref-Send-Pointer
101-
//
102-
// When we borrow the interior of an owned pointer, we
103-
// cannot permit the base to be mutated, because that
104-
// would cause the unique pointer to be freed.
105-
//
106-
// Eventually we should make these non-special and
107-
// just rely on Deref<T> implementation.
108-
let result = self.restrict(cmt_base);
109-
self.extend(result, cmt.mutbl, LpDeref(pk))
110-
}
11199

112100
mc::cat_static_item(..) => {
113101
Safe
114102
}
115103

116-
mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::ImmBorrow, lt)) |
117-
mc::cat_deref(cmt_base, _, mc::Implicit(ty::ImmBorrow, lt)) => {
118-
// R-Deref-Imm-Borrowed
119-
if !self.bccx.is_subregion_of(self.loan_region, lt) {
120-
self.bccx.report(
121-
BckError {
122-
span: self.span,
123-
cause: self.cause,
124-
cmt: cmt_base,
125-
code: err_borrowed_pointer_too_short(
126-
self.loan_region, lt)});
127-
return Safe;
128-
}
129-
Safe
130-
}
131-
132104
mc::cat_deref(cmt_base, _, pk) => {
133105
match pk {
134-
mc::BorrowedPtr(ty::MutBorrow, lt) |
135-
mc::BorrowedPtr(ty::UniqueImmBorrow, lt) |
136-
mc::Implicit(ty::MutBorrow, lt) |
137-
mc::Implicit(ty::UniqueImmBorrow, lt) => {
138-
// R-Deref-Mut-Borrowed
106+
mc::OwnedPtr => {
107+
// R-Deref-Send-Pointer
108+
//
109+
// When we borrow the interior of an owned pointer, we
110+
// cannot permit the base to be mutated, because that
111+
// would cause the unique pointer to be freed.
112+
//
113+
// Eventually we should make these non-special and
114+
// just rely on Deref<T> implementation.
115+
let result = self.restrict(cmt_base);
116+
self.extend(result, cmt.mutbl, LpDeref(pk))
117+
}
118+
mc::Implicit(bk, lt) | mc::BorrowedPtr(bk, lt) => {
119+
// R-Deref-[Mut-]Borrowed
139120
if !self.bccx.is_subregion_of(self.loan_region, lt) {
140121
self.bccx.report(
141122
BckError {
@@ -147,25 +128,23 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
147128
return Safe;
148129
}
149130

150-
let result = self.restrict(cmt_base);
151-
self.extend(result, cmt.mutbl, LpDeref(pk))
152-
}
153-
mc::UnsafePtr(..) => {
154-
// We are very trusting when working with unsafe
155-
// pointers.
156-
Safe
157-
}
158-
_ => {
159-
self.bccx.tcx.sess.span_bug(self.span,
160-
"unhandled memcat in \
161-
cat_deref")
131+
match bk {
132+
ty::ImmBorrow => Safe,
133+
ty::MutBorrow | ty::UniqueImmBorrow => {
134+
// R-Deref-Mut-Borrowed
135+
//
136+
// The referent can be aliased after the
137+
// references lifetime ends (by a newly-unfrozen
138+
// borrow).
139+
let result = self.restrict(cmt_base);
140+
self.extend(result, cmt.mutbl, LpDeref(pk))
141+
}
142+
}
162143
}
144+
// Borrowck is not relevant for unsafe pointers
145+
mc::UnsafePtr(..) => Safe
163146
}
164147
}
165-
166-
mc::cat_discr(cmt_base, _) => {
167-
self.restrict(cmt_base)
168-
}
169148
}
170149
}
171150

src/librustc/middle/borrowck/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
379379
})
380380
}
381381

382-
mc::cat_downcast(ref cmt_base) |
383-
mc::cat_discr(ref cmt_base, _) => {
382+
mc::cat_downcast(ref cmt_base) => {
384383
opt_loan_path(cmt_base)
385384
}
386385
}

src/librustc/middle/check_static.rs

-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ impl euv::Delegate for GlobalChecker {
269269
break
270270
}
271271
mc::cat_deref(ref cmt, _, _) |
272-
mc::cat_discr(ref cmt, _) |
273272
mc::cat_downcast(ref cmt) |
274273
mc::cat_interior(ref cmt, _) => cur = cmt,
275274

@@ -307,7 +306,6 @@ impl euv::Delegate for GlobalChecker {
307306
}
308307

309308
mc::cat_downcast(..) |
310-
mc::cat_discr(..) |
311309
mc::cat_upvar(..) => unreachable!(),
312310

313311
mc::cat_local(..) => {
@@ -331,4 +329,3 @@ impl euv::Delegate for GlobalChecker {
331329
_cmt: mc::cmt,
332330
_mode: euv::ConsumeMode) {}
333331
}
334-

src/librustc/middle/mem_categorization.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub enum categorization {
8787
cat_deref(cmt, uint, PointerKind), // deref of a ptr
8888
cat_interior(cmt, InteriorKind), // something interior: field, tuple, etc
8989
cat_downcast(cmt), // selects a particular enum variant (*1)
90-
cat_discr(cmt, ast::NodeId), // match discriminant (see preserve())
9190

9291
// (*1) downcast is only required if the enum has more than one variant
9392
}
@@ -1339,9 +1338,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
13391338
cat_upvar(ref var) => {
13401339
upvar_to_string(var, true)
13411340
}
1342-
cat_discr(ref cmt, _) => {
1343-
self.cmt_to_string(&**cmt)
1344-
}
13451341
cat_downcast(ref cmt) => {
13461342
self.cmt_to_string(&**cmt)
13471343
}
@@ -1379,7 +1375,6 @@ impl cmt_ {
13791375
Rc::new((*self).clone())
13801376
}
13811377
cat_downcast(ref b) |
1382-
cat_discr(ref b, _) |
13831378
cat_interior(ref b, _) |
13841379
cat_deref(ref b, _, OwnedPtr) => {
13851380
b.guarantor()
@@ -1404,8 +1399,7 @@ impl cmt_ {
14041399
cat_deref(ref b, _, Implicit(ty::UniqueImmBorrow, _)) |
14051400
cat_downcast(ref b) |
14061401
cat_deref(ref b, _, OwnedPtr) |
1407-
cat_interior(ref b, _) |
1408-
cat_discr(ref b, _) => {
1402+
cat_interior(ref b, _) => {
14091403
// Aliasability depends on base cmt
14101404
b.freely_aliasable(ctxt)
14111405
}
@@ -1490,9 +1484,6 @@ impl Repr for categorization {
14901484
cat_downcast(ref cmt) => {
14911485
format!("{}->(enum)", cmt.cat.repr(tcx))
14921486
}
1493-
cat_discr(ref cmt, _) => {
1494-
cmt.cat.repr(tcx)
1495-
}
14961487
}
14971488
}
14981489
}

src/librustc/middle/typeck/check/regionck.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,6 @@ fn link_region(rcx: &Rcx,
14941494
}
14951495
}
14961496

1497-
mc::cat_discr(cmt_base, _) |
14981497
mc::cat_downcast(cmt_base) |
14991498
mc::cat_deref(cmt_base, _, mc::OwnedPtr) |
15001499
mc::cat_interior(cmt_base, _) => {
@@ -1736,8 +1735,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx,
17361735
match cmt.cat.clone() {
17371736
mc::cat_deref(base, _, mc::OwnedPtr) |
17381737
mc::cat_interior(base, _) |
1739-
mc::cat_downcast(base) |
1740-
mc::cat_discr(base, _) => {
1738+
mc::cat_downcast(base) => {
17411739
// Interior or owned data is mutable if base is
17421740
// mutable, so iterate to the base.
17431741
cmt = base;
@@ -1788,8 +1786,7 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) {
17881786
match cmt.cat.clone() {
17891787
mc::cat_deref(base, _, mc::OwnedPtr) |
17901788
mc::cat_interior(base, _) |
1791-
mc::cat_downcast(base) |
1792-
mc::cat_discr(base, _) => {
1789+
mc::cat_downcast(base) => {
17931790
// Interior or owned data is unique if base is
17941791
// unique.
17951792
cmt = base;

0 commit comments

Comments
 (0)