Skip to content

Remove ty_open. #22213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
ty::ty_err => {
mywrite!(w, "e");
}
ty::ty_open(_) => {
cx.diag.handler().bug("unexpected type in enc_sty (ty_open)");
}
}

let end = w.tell().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
None
}
}
ty::ty_open(_) | ty::ty_infer(_) | ty::ty_err => None,
ty::ty_infer(_) | ty::ty_err => None,
}
}

1 change: 0 additions & 1 deletion src/librustc/middle/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
t
}

ty::ty_open(..) |
ty::ty_bool |
ty::ty_char |
ty::ty_int(..) |
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {

ty::ty_closure(..) |
ty::ty_infer(..) |
ty::ty_open(..) |
ty::ty_err => {
tcx.sess.bug(
&format!("ty_is_local invoked on unexpected type: {}",
Expand Down
19 changes: 0 additions & 19 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,25 +1626,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Ok(AmbiguousBuiltin)
}

ty::ty_open(ty) => {
// these only crop up in trans, and represent an
// "opened" unsized/existential type (one that has
// been dereferenced)
match bound {
ty::BoundCopy => {
Ok(If(vec!(ty)))
}

ty::BoundSized => {
Err(Unimplemented)
}

ty::BoundSync |
ty::BoundSend => {
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
}
}
}
ty::ty_err => {
Ok(If(Vec::new()))
}
Expand Down
46 changes: 6 additions & 40 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ impl<'tcx> ctxt<'tcx> {
sty_debug_print!(
self,
ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_trait,
ty_struct, ty_closure, ty_tup, ty_param, ty_open, ty_infer, ty_projection);
ty_struct, ty_closure, ty_tup, ty_param, ty_infer, ty_projection);

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

ty_open(Ty<'tcx>), // A deref'ed fat pointer, i.e., a dynamically sized value
// and its size. Only ever used in trans. It is not necessary
// earlier since we don't need to distinguish a DST with its
// size (e.g., in a deref) vs a DST with the size elsewhere (
// e.g., in a field).

ty_infer(InferTy), // something used only during inference/typeck
ty_err, // Also only used during inference/typeck, to represent
// the type of an erroneous expression (helps cut down
Expand Down Expand Up @@ -2689,7 +2683,7 @@ impl FlagComputation {
self.add_bounds(bounds);
}

&ty_uniq(tt) | &ty_vec(tt, _) | &ty_open(tt) => {
&ty_uniq(tt) | &ty_vec(tt, _) => {
self.add_ty(tt)
}

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

pub fn mk_open<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_open(ty)) }

impl<'tcx> TyS<'tcx> {
/// Iterator that walks `self` and any types reachable from
/// `self`, in depth-first order. Note that just walks the types
Expand Down Expand Up @@ -3164,7 +3156,6 @@ pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
ty_vec(ty, _) => ty,
ty_str => mk_mach_uint(cx, ast::TyU8),
ty_open(ty) => sequence_element_type(cx, ty),
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
ty_to_string(cx, ty))),
}
Expand Down Expand Up @@ -3583,12 +3574,6 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
TC::All
}

ty_open(ty) => {
let result = tc_ty(cx, ty, cache);
assert!(!result.is_sized(cx));
result.unsafe_pointer() | TC::Nonsized
}

ty_infer(_) |
ty_err => {
cx.sess.bug("asked to compute contents of error type");
Expand Down Expand Up @@ -3747,7 +3732,7 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool {
ty_vec(_, None) => {
false
}
ty_uniq(typ) | ty_open(typ) => {
ty_uniq(typ) => {
type_requires(cx, seen, r_ty, typ)
}
ty_rptr(_, ref mt) => {
Expand Down Expand Up @@ -4106,14 +4091,6 @@ pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option<mt<'tcx>> {
}
}

pub fn close_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
ty_open(ty) => mk_rptr(cx, cx.mk_region(ReStatic), mt {ty: ty, mutbl:ast::MutImmutable}),
_ => cx.sess.bug(&format!("Trying to close a non-open type {}",
ty_to_string(cx, ty)))
}
}

pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
ty_uniq(ty) => ty,
Expand All @@ -4122,14 +4099,6 @@ pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
}
}

// Extract the unsized type in an open type (or just return ty if it is not open).
pub fn unopen_type<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
ty_open(ty) => ty,
_ => ty
}
}

// Returns the type of ty[i]
pub fn index<'tcx>(ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
match ty.sty {
Expand Down Expand Up @@ -4802,7 +4771,6 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
}
}
ty_err => "type error".to_string(),
ty_open(_) => "opened DST".to_string(),
}
}

Expand Down Expand Up @@ -6328,16 +6296,15 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
hash!(p.idx);
hash!(token::get_name(p.name));
}
ty_open(_) => byte!(22),
ty_infer(_) => unreachable!(),
ty_err => byte!(23),
ty_err => byte!(21),
ty_closure(d, r, _) => {
byte!(24);
byte!(22);
did(state, d);
region(state, *r);
}
ty_projection(ref data) => {
byte!(25);
byte!(23);
did(state, data.trait_ref.def_id);
hash!(token::get_name(data.item_name));
}
Expand Down Expand Up @@ -6666,7 +6633,6 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
ty_projection(_) |
ty_param(_) |
ty_infer(_) |
ty_open(_) |
ty_err => {
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/ty_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,6 @@ pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
ty::ty_vec(typ, sz) => {
ty::ty_vec(typ.fold_with(this), sz)
}
ty::ty_open(typ) => {
ty::ty_open(typ.fold_with(this))
}
ty::ty_enum(tid, ref substs) => {
let substs = substs.fold_with(this);
ty::ty_enum(tid, this.tcx().mk_substs(substs))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'tcx> TypeWalker<'tcx> {
ty::ty_bool | ty::ty_char | ty::ty_int(_) | ty::ty_uint(_) | ty::ty_float(_) |
ty::ty_str | ty::ty_infer(_) | ty::ty_param(_) | ty::ty_err => {
}
ty::ty_uniq(ty) | ty::ty_vec(ty, _) | ty::ty_open(ty) => {
ty::ty_uniq(ty) | ty::ty_vec(ty, _) => {
self.stack.push(ty);
}
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use middle::ty::{ReSkolemized, ReVar, BrEnv};
use middle::ty::{mt, Ty, ParamTy};
use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum};
use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn};
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open};
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup};
use middle::ty::{ty_closure};
use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
use middle::ty;
Expand Down Expand Up @@ -369,8 +369,6 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
buf.push_str(&mt_to_string(cx, tm));
buf
}
ty_open(typ) =>
format!("opened<{}>", ty_to_string(cx, typ)),
ty_tup(ref elems) => {
let strs = elems
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ fn bind_subslice_pat(bcx: Block,
}

fn extract_vec_elems<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
left_ty: Ty,
left_ty: Ty<'tcx>,
before: uint,
after: uint,
val: ValueRef)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, st: &Struct<'tcx>,
st.fields.iter().filter(|&ty| !dst || type_is_sized(cx.tcx(), *ty))
.map(|&ty| type_of::sizing_type_of(cx, ty)).collect()
} else {
st.fields.iter().map(|&ty| type_of::type_of(cx, ty)).collect()
st.fields.iter().map(|&ty| type_of::in_memory_type_of(cx, ty)).collect()
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,7 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
let val = if common::type_is_sized(cx.tcx(), field_ty) {
llfld_a
} else {
let boxed_ty = ty::mk_open(cx.tcx(), field_ty);
let scratch = datum::rvalue_scratch_datum(cx, boxed_ty, "__fat_ptr_iter");
let scratch = datum::rvalue_scratch_datum(cx, field_ty, "__fat_ptr_iter");
Store(cx, llfld_a, GEPi(cx, scratch.val, &[0, abi::FAT_PTR_ADDR]));
Store(cx, info.unwrap(), GEPi(cx, scratch.val, &[0, abi::FAT_PTR_EXTRA]));
scratch.val
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_trans/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T
// Is the type's representation size known at compile time?
pub fn type_is_sized<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
let param_env = ty::empty_parameter_environment(tcx);
ty::type_is_sized(&param_env, DUMMY_SP, ty)
}

pub fn lltype_is_sized<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
match ty.sty {
ty::ty_open(_) => true,
_ => type_is_sized(cx, ty),
// FIXME(#4287) This can cause errors due to polymorphic recursion,
// a better span should be provided, if available.
let err_count = tcx.sess.err_count();
let is_sized = ty::type_is_sized(&param_env, DUMMY_SP, ty);
// Those errors aren't fatal, but an incorrect result can later
// trip over asserts in both rustc's trans and LLVM.
if err_count < tcx.sess.err_count() {
tcx.sess.abort_if_errors();
}
is_sized
}

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

pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>,
ty: Ty<'tcx>)
-> bool {
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
ty::type_contents(cx, ty).needs_drop(cx)
}

Expand Down
33 changes: 10 additions & 23 deletions src/librustc_trans/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
(const_deref_ptr(cx, v), mt.ty)
} else {
// Derefing a fat pointer does not change the representation,
// just the type to ty_open.
(v, ty::mk_open(cx.tcx(), mt.ty))
// just the type to the unsized contents.
(v, mt.ty)
}
}
None => {
Expand Down Expand Up @@ -290,15 +290,7 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
// an optimisation, it is necessary for mutable vectors to
// work properly.
ty = match ty::deref(ty, true) {
Some(mt) => {
if type_is_sized(cx.tcx(), mt.ty) {
mt.ty
} else {
// Derefing a fat pointer does not change the representation,
// just the type to ty_open.
ty::mk_open(cx.tcx(), mt.ty)
}
}
Some(mt) => mt.ty,
None => {
cx.sess().bug(&format!("unexpected dereferenceable type {}",
ty_to_string(cx.tcx(), ty)))
Expand All @@ -319,11 +311,12 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
llconst = addr_of(cx, llconst, "autoref", e.id);
}
Some(box ty::AutoUnsize(ref k)) => {
let unsized_ty = ty::unsize_ty(cx.tcx(), ty, k, e.span);
let info = expr::unsized_info(cx, k, e.id, ty, param_substs,
|t| ty::mk_imm_rptr(cx.tcx(), cx.tcx().mk_region(ty::ReStatic), t));

let base = ptrcast(llconst, type_of::type_of(cx, unsized_ty).ptr_to());
let unsized_ty = ty::unsize_ty(cx.tcx(), ty, k, e.span);
let ptr_ty = type_of::in_memory_type_of(cx, unsized_ty).ptr_to();
let base = ptrcast(llconst, ptr_ty);
let prev_const = cx.const_unsized().borrow_mut()
.insert(base, llconst);
assert!(prev_const.is_none() || prev_const == Some(llconst));
Expand Down Expand Up @@ -477,16 +470,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
};
let (arr, len) = match bt.sty {
ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)),
ty::ty_open(ty) => match ty.sty {
ty::ty_vec(_, None) | ty::ty_str => {
let e1 = const_get_elt(cx, bv, &[0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
},
_ => cx.sess().span_bug(base.span,
&format!("index-expr base must be a vector \
or string type, found {}",
ty_to_string(cx.tcx(), bt)))
},
ty::ty_vec(_, None) | ty::ty_str => {
let e1 = const_get_elt(cx, bv, &[0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
}
ty::ty_rptr(_, mt) => match mt.ty.sty {
ty::ty_vec(_, Some(u)) => {
(const_deref_ptr(cx, bv), C_uint(cx, u))
Expand Down
18 changes: 6 additions & 12 deletions src/librustc_trans/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ impl<'tcx> Datum<'tcx, Expr> {
-> DatumBlock<'blk, 'tcx, Lvalue> {
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));

assert!(lltype_is_sized(bcx.tcx(), self.ty),
"Trying to convert unsized value to lval");
self.match_kind(
|l| DatumBlock::new(bcx, l),
|r| {
Expand Down Expand Up @@ -549,15 +547,10 @@ impl<'tcx> Datum<'tcx, Lvalue> {
-> Datum<'tcx, Lvalue> where
F: FnOnce(ValueRef) -> ValueRef,
{
let val = match self.ty.sty {
_ if type_is_sized(bcx.tcx(), self.ty) => gep(self.val),
ty::ty_open(_) => {
let base = Load(bcx, expr::get_dataptr(bcx, self.val));
gep(base)
}
_ => bcx.tcx().sess.bug(
&format!("Unexpected unsized type in get_element: {}",
bcx.ty_to_string(self.ty)))
let val = if type_is_sized(bcx.tcx(), self.ty) {
gep(self.val)
} else {
gep(Load(bcx, expr::get_dataptr(bcx, self.val)))
};
Datum {
val: val,
Expand All @@ -566,7 +559,8 @@ impl<'tcx> Datum<'tcx, Lvalue> {
}
}

pub fn get_vec_base_and_len(&self, bcx: Block) -> (ValueRef, ValueRef) {
pub fn get_vec_base_and_len<'blk>(&self, bcx: Block<'blk, 'tcx>)
-> (ValueRef, ValueRef) {
//! Converts a vector into the slice pair.

tvec::get_base_and_len(bcx, self.val, self.ty)
Expand Down
Loading