Skip to content

Commit 89d5d24

Browse files
committed
Rollup merge of rust-lang#22213 - eddyb:ty_open-case-closed, r=nikomatsakis
This type wasn't necessary, as there was no place using it and unsized types not wrapped in it, at the same time. r? @nikomatsakis
2 parents e711ac7 + 8659de0 commit 89d5d24

File tree

27 files changed

+184
-320
lines changed

27 files changed

+184
-320
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
153153
ty::ty_err => {
154154
mywrite!(w, "e");
155155
}
156-
ty::ty_open(_) => {
157-
cx.diag.handler().bug("unexpected type in enc_sty (ty_open)");
158-
}
159156
}
160157

161158
let end = w.tell().unwrap();

src/librustc/middle/fast_reject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
9393
None
9494
}
9595
}
96-
ty::ty_open(_) | ty::ty_infer(_) | ty::ty_err => None,
96+
ty::ty_infer(_) | ty::ty_err => None,
9797
}
9898
}
9999

src/librustc/middle/infer/freshen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
135135
t
136136
}
137137

138-
ty::ty_open(..) |
139138
ty::ty_bool |
140139
ty::ty_char |
141140
ty::ty_int(..) |

src/librustc/middle/traits/coherence.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
194194

195195
ty::ty_closure(..) |
196196
ty::ty_infer(..) |
197-
ty::ty_open(..) |
198197
ty::ty_err => {
199198
tcx.sess.bug(
200199
&format!("ty_is_local invoked on unexpected type: {}",

src/librustc/middle/traits/select.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,25 +1626,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16261626
Ok(AmbiguousBuiltin)
16271627
}
16281628

1629-
ty::ty_open(ty) => {
1630-
// these only crop up in trans, and represent an
1631-
// "opened" unsized/existential type (one that has
1632-
// been dereferenced)
1633-
match bound {
1634-
ty::BoundCopy => {
1635-
Ok(If(vec!(ty)))
1636-
}
1637-
1638-
ty::BoundSized => {
1639-
Err(Unimplemented)
1640-
}
1641-
1642-
ty::BoundSync |
1643-
ty::BoundSend => {
1644-
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
1645-
}
1646-
}
1647-
}
16481629
ty::ty_err => {
16491630
Ok(If(Vec::new()))
16501631
}

src/librustc/middle/ty.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl<'tcx> ctxt<'tcx> {
930930
sty_debug_print!(
931931
self,
932932
ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_trait,
933-
ty_struct, ty_closure, ty_tup, ty_param, ty_open, ty_infer, ty_projection);
933+
ty_struct, ty_closure, ty_tup, ty_param, ty_infer, ty_projection);
934934

935935
println!("Substs interner: #{}", self.substs_interner.borrow().len());
936936
println!("BareFnTy interner: #{}", self.bare_fn_interner.borrow().len());
@@ -1374,12 +1374,6 @@ pub enum sty<'tcx> {
13741374
ty_projection(ProjectionTy<'tcx>),
13751375
ty_param(ParamTy), // type parameter
13761376

1377-
ty_open(Ty<'tcx>), // A deref'ed fat pointer, i.e., a dynamically sized value
1378-
// and its size. Only ever used in trans. It is not necessary
1379-
// earlier since we don't need to distinguish a DST with its
1380-
// size (e.g., in a deref) vs a DST with the size elsewhere (
1381-
// e.g., in a field).
1382-
13831377
ty_infer(InferTy), // something used only during inference/typeck
13841378
ty_err, // Also only used during inference/typeck, to represent
13851379
// the type of an erroneous expression (helps cut down
@@ -2689,7 +2683,7 @@ impl FlagComputation {
26892683
self.add_bounds(bounds);
26902684
}
26912685

2692-
&ty_uniq(tt) | &ty_vec(tt, _) | &ty_open(tt) => {
2686+
&ty_uniq(tt) | &ty_vec(tt, _) => {
26932687
self.add_ty(tt)
26942688
}
26952689

@@ -2964,8 +2958,6 @@ pub fn mk_param_from_def<'tcx>(cx: &ctxt<'tcx>, def: &TypeParameterDef) -> Ty<'t
29642958
mk_param(cx, def.space, def.index, def.name)
29652959
}
29662960

2967-
pub fn mk_open<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_open(ty)) }
2968-
29692961
impl<'tcx> TyS<'tcx> {
29702962
/// Iterator that walks `self` and any types reachable from
29712963
/// `self`, in depth-first order. Note that just walks the types
@@ -3164,7 +3156,6 @@ pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
31643156
match ty.sty {
31653157
ty_vec(ty, _) => ty,
31663158
ty_str => mk_mach_uint(cx, ast::TyU8),
3167-
ty_open(ty) => sequence_element_type(cx, ty),
31683159
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
31693160
ty_to_string(cx, ty))),
31703161
}
@@ -3583,12 +3574,6 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
35833574
TC::All
35843575
}
35853576

3586-
ty_open(ty) => {
3587-
let result = tc_ty(cx, ty, cache);
3588-
assert!(!result.is_sized(cx));
3589-
result.unsafe_pointer() | TC::Nonsized
3590-
}
3591-
35923577
ty_infer(_) |
35933578
ty_err => {
35943579
cx.sess.bug("asked to compute contents of error type");
@@ -3747,7 +3732,7 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool {
37473732
ty_vec(_, None) => {
37483733
false
37493734
}
3750-
ty_uniq(typ) | ty_open(typ) => {
3735+
ty_uniq(typ) => {
37513736
type_requires(cx, seen, r_ty, typ)
37523737
}
37533738
ty_rptr(_, ref mt) => {
@@ -4106,14 +4091,6 @@ pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option<mt<'tcx>> {
41064091
}
41074092
}
41084093

4109-
pub fn close_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
4110-
match ty.sty {
4111-
ty_open(ty) => mk_rptr(cx, cx.mk_region(ReStatic), mt {ty: ty, mutbl:ast::MutImmutable}),
4112-
_ => cx.sess.bug(&format!("Trying to close a non-open type {}",
4113-
ty_to_string(cx, ty)))
4114-
}
4115-
}
4116-
41174094
pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
41184095
match ty.sty {
41194096
ty_uniq(ty) => ty,
@@ -4122,14 +4099,6 @@ pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
41224099
}
41234100
}
41244101

4125-
// Extract the unsized type in an open type (or just return ty if it is not open).
4126-
pub fn unopen_type<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
4127-
match ty.sty {
4128-
ty_open(ty) => ty,
4129-
_ => ty
4130-
}
4131-
}
4132-
41334102
// Returns the type of ty[i]
41344103
pub fn index<'tcx>(ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
41354104
match ty.sty {
@@ -4802,7 +4771,6 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
48024771
}
48034772
}
48044773
ty_err => "type error".to_string(),
4805-
ty_open(_) => "opened DST".to_string(),
48064774
}
48074775
}
48084776

@@ -6328,16 +6296,15 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
63286296
hash!(p.idx);
63296297
hash!(token::get_name(p.name));
63306298
}
6331-
ty_open(_) => byte!(22),
63326299
ty_infer(_) => unreachable!(),
6333-
ty_err => byte!(23),
6300+
ty_err => byte!(21),
63346301
ty_closure(d, r, _) => {
6335-
byte!(24);
6302+
byte!(22);
63366303
did(state, d);
63376304
region(state, *r);
63386305
}
63396306
ty_projection(ref data) => {
6340-
byte!(25);
6307+
byte!(23);
63416308
did(state, data.trait_ref.def_id);
63426309
hash!(token::get_name(data.item_name));
63436310
}
@@ -6666,7 +6633,6 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
66666633
ty_projection(_) |
66676634
ty_param(_) |
66686635
ty_infer(_) |
6669-
ty_open(_) |
66706636
ty_err => {
66716637
}
66726638
}

src/librustc/middle/ty_fold.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,6 @@ pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
626626
ty::ty_vec(typ, sz) => {
627627
ty::ty_vec(typ.fold_with(this), sz)
628628
}
629-
ty::ty_open(typ) => {
630-
ty::ty_open(typ.fold_with(this))
631-
}
632629
ty::ty_enum(tid, ref substs) => {
633630
let substs = substs.fold_with(this);
634631
ty::ty_enum(tid, this.tcx().mk_substs(substs))

src/librustc/middle/ty_walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'tcx> TypeWalker<'tcx> {
2828
ty::ty_bool | ty::ty_char | ty::ty_int(_) | ty::ty_uint(_) | ty::ty_float(_) |
2929
ty::ty_str | ty::ty_infer(_) | ty::ty_param(_) | ty::ty_err => {
3030
}
31-
ty::ty_uniq(ty) | ty::ty_vec(ty, _) | ty::ty_open(ty) => {
31+
ty::ty_uniq(ty) | ty::ty_vec(ty, _) => {
3232
self.stack.push(ty);
3333
}
3434
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use middle::ty::{ReSkolemized, ReVar, BrEnv};
2020
use middle::ty::{mt, Ty, ParamTy};
2121
use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum};
2222
use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn};
23-
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open};
23+
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup};
2424
use middle::ty::{ty_closure};
2525
use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
2626
use middle::ty;
@@ -369,8 +369,6 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
369369
buf.push_str(&mt_to_string(cx, tm));
370370
buf
371371
}
372-
ty_open(typ) =>
373-
format!("opened<{}>", ty_to_string(cx, typ)),
374372
ty_tup(ref elems) => {
375373
let strs = elems
376374
.iter()

src/librustc_trans/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ fn bind_subslice_pat(bcx: Block,
678678
}
679679

680680
fn extract_vec_elems<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
681-
left_ty: Ty,
681+
left_ty: Ty<'tcx>,
682682
before: uint,
683683
after: uint,
684684
val: ValueRef)

src/librustc_trans/trans/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, st: &Struct<'tcx>,
699699
st.fields.iter().filter(|&ty| !dst || type_is_sized(cx.tcx(), *ty))
700700
.map(|&ty| type_of::sizing_type_of(cx, ty)).collect()
701701
} else {
702-
st.fields.iter().map(|&ty| type_of::type_of(cx, ty)).collect()
702+
st.fields.iter().map(|&ty| type_of::in_memory_type_of(cx, ty)).collect()
703703
}
704704
}
705705

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,7 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
676676
let val = if common::type_is_sized(cx.tcx(), field_ty) {
677677
llfld_a
678678
} else {
679-
let boxed_ty = ty::mk_open(cx.tcx(), field_ty);
680-
let scratch = datum::rvalue_scratch_datum(cx, boxed_ty, "__fat_ptr_iter");
679+
let scratch = datum::rvalue_scratch_datum(cx, field_ty, "__fat_ptr_iter");
681680
Store(cx, llfld_a, GEPi(cx, scratch.val, &[0, abi::FAT_PTR_ADDR]));
682681
Store(cx, info.unwrap(), GEPi(cx, scratch.val, &[0, abi::FAT_PTR_EXTRA]));
683682
scratch.val

src/librustc_trans/trans/common.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,16 @@ pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T
120120
// Is the type's representation size known at compile time?
121121
pub fn type_is_sized<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
122122
let param_env = ty::empty_parameter_environment(tcx);
123-
ty::type_is_sized(&param_env, DUMMY_SP, ty)
124-
}
125-
126-
pub fn lltype_is_sized<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
127-
match ty.sty {
128-
ty::ty_open(_) => true,
129-
_ => type_is_sized(cx, ty),
123+
// FIXME(#4287) This can cause errors due to polymorphic recursion,
124+
// a better span should be provided, if available.
125+
let err_count = tcx.sess.err_count();
126+
let is_sized = ty::type_is_sized(&param_env, DUMMY_SP, ty);
127+
// Those errors aren't fatal, but an incorrect result can later
128+
// trip over asserts in both rustc's trans and LLVM.
129+
if err_count < tcx.sess.err_count() {
130+
tcx.sess.abort_if_errors();
130131
}
132+
is_sized
131133
}
132134

133135
pub fn type_is_fat_ptr<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
@@ -211,9 +213,7 @@ pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<
211213
}
212214
}
213215

214-
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>,
215-
ty: Ty<'tcx>)
216-
-> bool {
216+
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
217217
ty::type_contents(cx, ty).needs_drop(cx)
218218
}
219219

src/librustc_trans/trans/consts.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
146146
(const_deref_ptr(cx, v), mt.ty)
147147
} else {
148148
// Derefing a fat pointer does not change the representation,
149-
// just the type to ty_open.
150-
(v, ty::mk_open(cx.tcx(), mt.ty))
149+
// just the type to the unsized contents.
150+
(v, mt.ty)
151151
}
152152
}
153153
None => {
@@ -290,15 +290,7 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
290290
// an optimisation, it is necessary for mutable vectors to
291291
// work properly.
292292
ty = match ty::deref(ty, true) {
293-
Some(mt) => {
294-
if type_is_sized(cx.tcx(), mt.ty) {
295-
mt.ty
296-
} else {
297-
// Derefing a fat pointer does not change the representation,
298-
// just the type to ty_open.
299-
ty::mk_open(cx.tcx(), mt.ty)
300-
}
301-
}
293+
Some(mt) => mt.ty,
302294
None => {
303295
cx.sess().bug(&format!("unexpected dereferenceable type {}",
304296
ty_to_string(cx.tcx(), ty)))
@@ -319,11 +311,12 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
319311
llconst = addr_of(cx, llconst, "autoref", e.id);
320312
}
321313
Some(box ty::AutoUnsize(ref k)) => {
322-
let unsized_ty = ty::unsize_ty(cx.tcx(), ty, k, e.span);
323314
let info = expr::unsized_info(cx, k, e.id, ty, param_substs,
324315
|t| ty::mk_imm_rptr(cx.tcx(), cx.tcx().mk_region(ty::ReStatic), t));
325316

326-
let base = ptrcast(llconst, type_of::type_of(cx, unsized_ty).ptr_to());
317+
let unsized_ty = ty::unsize_ty(cx.tcx(), ty, k, e.span);
318+
let ptr_ty = type_of::in_memory_type_of(cx, unsized_ty).ptr_to();
319+
let base = ptrcast(llconst, ptr_ty);
327320
let prev_const = cx.const_unsized().borrow_mut()
328321
.insert(base, llconst);
329322
assert!(prev_const.is_none() || prev_const == Some(llconst));
@@ -477,16 +470,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
477470
};
478471
let (arr, len) = match bt.sty {
479472
ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)),
480-
ty::ty_open(ty) => match ty.sty {
481-
ty::ty_vec(_, None) | ty::ty_str => {
482-
let e1 = const_get_elt(cx, bv, &[0]);
483-
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
484-
},
485-
_ => cx.sess().span_bug(base.span,
486-
&format!("index-expr base must be a vector \
487-
or string type, found {}",
488-
ty_to_string(cx.tcx(), bt)))
489-
},
473+
ty::ty_vec(_, None) | ty::ty_str => {
474+
let e1 = const_get_elt(cx, bv, &[0]);
475+
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
476+
}
490477
ty::ty_rptr(_, mt) => match mt.ty.sty {
491478
ty::ty_vec(_, Some(u)) => {
492479
(const_deref_ptr(cx, bv), C_uint(cx, u))

src/librustc_trans/trans/datum.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,6 @@ impl<'tcx> Datum<'tcx, Expr> {
492492
-> DatumBlock<'blk, 'tcx, Lvalue> {
493493
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));
494494

495-
assert!(lltype_is_sized(bcx.tcx(), self.ty),
496-
"Trying to convert unsized value to lval");
497495
self.match_kind(
498496
|l| DatumBlock::new(bcx, l),
499497
|r| {
@@ -549,15 +547,10 @@ impl<'tcx> Datum<'tcx, Lvalue> {
549547
-> Datum<'tcx, Lvalue> where
550548
F: FnOnce(ValueRef) -> ValueRef,
551549
{
552-
let val = match self.ty.sty {
553-
_ if type_is_sized(bcx.tcx(), self.ty) => gep(self.val),
554-
ty::ty_open(_) => {
555-
let base = Load(bcx, expr::get_dataptr(bcx, self.val));
556-
gep(base)
557-
}
558-
_ => bcx.tcx().sess.bug(
559-
&format!("Unexpected unsized type in get_element: {}",
560-
bcx.ty_to_string(self.ty)))
550+
let val = if type_is_sized(bcx.tcx(), self.ty) {
551+
gep(self.val)
552+
} else {
553+
gep(Load(bcx, expr::get_dataptr(bcx, self.val)))
561554
};
562555
Datum {
563556
val: val,
@@ -566,7 +559,8 @@ impl<'tcx> Datum<'tcx, Lvalue> {
566559
}
567560
}
568561

569-
pub fn get_vec_base_and_len(&self, bcx: Block) -> (ValueRef, ValueRef) {
562+
pub fn get_vec_base_and_len<'blk>(&self, bcx: Block<'blk, 'tcx>)
563+
-> (ValueRef, ValueRef) {
570564
//! Converts a vector into the slice pair.
571565
572566
tvec::get_base_and_len(bcx, self.val, self.ty)

0 commit comments

Comments
 (0)