Skip to content

Refactor ty_str to use a ~(str) representation. #13819

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

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 2 additions & 19 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,6 @@ pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx:
parse_substs(&mut st, conv)
}

fn parse_vstore(st: &mut PState, conv: conv_did) -> ty::Vstore {
assert_eq!(next(st), '/');

let c = peek(st);
if '0' <= c && c <= '9' {
let n = parse_uint(st);
assert_eq!(next(st), '|');
return ty::VstoreFixed(n);
}

match next(st) {
'~' => ty::VstoreUniq,
'&' => ty::VstoreSlice(parse_region(st, conv)),
c => st.tcx.sess.bug(format!("parse_vstore(): bad input '{}'", c))
}
}

fn parse_size(st: &mut PState) -> Option<uint> {
assert_eq!(next(st), '/');

Expand Down Expand Up @@ -361,8 +344,8 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_vec(st.tcx, mt, sz);
}
'v' => {
let v = parse_vstore(st, |x,y| conv(x,y));
return ty::mk_str(st.tcx, v);
let sz = parse_size(st);
return ty::mk_str(st.tcx, sz);
}
'T' => {
assert_eq!(next(st), '[');
Expand Down
23 changes: 6 additions & 17 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ fn enc_bound_region(w: &mut MemWriter, cx: &ctxt, br: ty::BoundRegion) {
}
}

pub fn enc_vstore(w: &mut MemWriter, cx: &ctxt,
v: ty::Vstore,
enc_mut: |&mut MemWriter|) {
mywrite!(w, "/");
match v {
ty::VstoreFixed(u) => mywrite!(w, "{}|", u),
ty::VstoreUniq => mywrite!(w, "~"),
ty::VstoreSlice(r) => {
mywrite!(w, "&");
enc_region(w, cx, r);
enc_mut(w);
}
}
}

pub fn enc_trait_ref(w: &mut MemWriter, cx: &ctxt, s: &ty::TraitRef) {
mywrite!(w, "{}|", (cx.ds)(s.def_id));
enc_substs(w, cx, &s.substs);
Expand Down Expand Up @@ -275,9 +260,13 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
None => mywrite!(w, "|"),
}
}
ty::ty_str(v) => {
ty::ty_str(sz) => {
mywrite!(w, "v");
enc_vstore(w, cx, v, |_| {});
mywrite!(w, "/");
match sz {
Some(n) => mywrite!(w, "{}|", n),
None => mywrite!(w, "|"),
}
}
ty::ty_closure(ref f) => {
mywrite!(w, "f");
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
ty::ty_struct(..) => check_matrix_for_wild(cx, m),
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty: ty, ..}) => match ty::get(ty).sty {
ty::ty_vec(_, None) => ctor_for_slice(m),
ty::ty_str(None) => Some(single),
_ => check_matrix_for_wild(cx, m),
},
ty::ty_enum(eid, _) => {
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ impl<'a> EffectCheckVisitor<'a> {
debug!("effect: checking index with base type {}",
ppaux::ty_to_str(self.tcx, base_type));
match ty::get(base_type).sty {
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
ty::ty_str(None) => {
self.tcx.sess.span_err(e.span,
"modification of string types is not allowed");
}
_ => {}
},
ty::ty_str(..) => {
self.tcx.sess.span_err(e.span,
"modification of string types is not allowed");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
ty::ty_box(_) => {
n_box += 1;
}
ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
ty::ty_uniq(_) |
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_closure(~ty::ClosureTy { store: ty::UniqTraitStore, .. }) => {
n_uniq += 1;
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
match ty::get(t).sty {
ty::ty_uniq(_) |
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
Some(deref_ptr(OwnedPtr))
}
Expand All @@ -188,7 +187,6 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
Some(deref_ptr(BorrowedPtr(kind, r)))
}

ty::ty_str(ty::VstoreSlice(r)) |
ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(r, _), ..}) => {
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
}
Expand All @@ -207,7 +205,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
}

ty::ty_vec(_, Some(_)) |
ty::ty_str(ty::VstoreFixed(_)) => {
ty::ty_str(Some(_)) => {
Some(deref_interior(InteriorElement(element_kind(t))))
}

Expand Down Expand Up @@ -1306,6 +1304,7 @@ fn element_kind(t: ty::t) -> ElementKind {
ty::ty_rptr(_, ty::mt{ty:ty, ..}) |
ty::ty_uniq(ty) => match ty::get(ty).sty {
ty::ty_vec(_, None) => VecElement,
ty::ty_str(None) => StrElement,
_ => OtherElement
},
ty::ty_vec(..) => VecElement,
Expand Down
67 changes: 39 additions & 28 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,40 +1293,51 @@ fn compare_values<'a>(
rhs: ValueRef,
rhs_t: ty::t)
-> Result<'a> {
fn compare_str<'a>(cx: &'a Block<'a>,
lhs: ValueRef,
rhs: ValueRef,
rhs_t: ty::t)
-> Result<'a> {
let did = langcall(cx, None,
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
StrEqFnLangItem);
let result = callee::trans_lang_call(cx, did, [lhs, rhs], None);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}

let _icx = push_ctxt("compare_values");
if ty::type_is_scalar(rhs_t) {
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
return rslt(rs.bcx, rs.val);
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
return rslt(rs.bcx, rs.val);
}

match ty::get(rhs_t).sty {
ty::ty_str(ty::VstoreUniq) => {
let scratch_lhs = alloca(cx, val_ty(lhs), "__lhs");
Store(cx, lhs, scratch_lhs);
let scratch_rhs = alloca(cx, val_ty(rhs), "__rhs");
Store(cx, rhs, scratch_rhs);
let did = langcall(cx, None,
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
UniqStrEqFnLangItem);
let result = callee::trans_lang_call(cx, did, [scratch_lhs, scratch_rhs], None);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
ty::ty_str(_) => {
let did = langcall(cx, None,
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
StrEqFnLangItem);
let result = callee::trans_lang_call(cx, did, [lhs, rhs], None);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
ty::ty_uniq(t) => match ty::get(t).sty {
ty::ty_str(None) => {
let scratch_lhs = alloca(cx, val_ty(lhs), "__lhs");
Store(cx, lhs, scratch_lhs);
let scratch_rhs = alloca(cx, val_ty(rhs), "__rhs");
Store(cx, rhs, scratch_rhs);
let did = langcall(cx, None,
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
UniqStrEqFnLangItem);
let result = callee::trans_lang_call(cx, did, [scratch_lhs, scratch_rhs], None);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
}
_ => {
cx.sess().bug("only scalars and strings supported in compare_values");
}
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
},
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
ty::ty_str(None) => compare_str(cx, lhs, rhs, rhs_t),
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
},
ty::ty_str(Some(_)) => compare_str(cx, lhs, rhs, rhs_t),
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,10 @@ impl Case {
self.tys.iter().position(|&ty| {
match ty::get(ty).sty {
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
ty::ty_vec(_, None) => false,
ty::ty_vec(_, None) | ty::ty_str(None)=> false,
_ => true,
},
ty::ty_uniq(..) | ty::ty_box(..) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_bare_fn(..) => true,
// Is that everything? Would closures or slices qualify?
_ => false
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
// `~` pointer return values never alias because ownership is transferred
// FIXME #6750 ~Trait cannot be directly marked as
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_str(ty::VstoreUniq) => {
ty::ty_uniq(..) // | ty::ty_trait(_, _, ty::UniqTraitStore, _, _)
=> {
unsafe {
llvm::LLVMAddReturnAttribute(llfn, lib::llvm::NoAliasAttribute as c_uint);
}
Expand Down Expand Up @@ -261,7 +261,6 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
// FIXME #6750 ~Trait cannot be directly marked as
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
unsafe {
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
Expand Down Expand Up @@ -665,7 +664,7 @@ pub fn iter_structural_ty<'r,
}
})
}
ty::ty_str(ty::VstoreFixed(n)) => {
ty::ty_str(Some(n)) => {
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
let (base, len) = tvec::get_fixed_base_and_byte_len(cx, av, unit_ty, n);
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,10 @@ pub fn trans_call_inner<'a>(
match ty::get(ret_ty).sty {
// `~` pointer return values never alias because ownership
// is transferred
ty::ty_uniq(..) => {
attrs.push((0, NoAliasAttribute));
}
ty::ty_uniq(ty) => match ty::get(ty).sty {
ty::ty_str(None) => {}
_ => attrs.push((0, NoAliasAttribute)),
},
_ => {}
}

Expand Down
20 changes: 13 additions & 7 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
let dv = match ty::get(t).sty {
ty::ty_ptr(mt) | ty::ty_rptr(_, mt) => {
match ty::get(mt.ty).sty {
ty::ty_vec(_, None) => cx.sess().bug("unexpected slice"),
ty::ty_vec(_, None) | ty::ty_str(None) => cx.sess().bug("unexpected slice"),
_ => const_deref_ptr(cx, v),
}
}
Expand Down Expand Up @@ -432,13 +432,9 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
"index is not an integer-constant expression")
};
let (arr, len) = match ty::get(bt).sty {
ty::ty_str(ty::VstoreSlice(..)) => {
let e1 = const_get_elt(cx, bv, [0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, [1]))
},
ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)),
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
ty::ty_vec(_, None) => {
ty::ty_vec(_, None) | ty::ty_str(None) => {
let e1 = const_get_elt(cx, bv, [0]);
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, [1]))
},
Expand All @@ -451,7 +447,17 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,

let len = llvm::LLVMConstIntGetZExtValue(len) as u64;
let len = match ty::get(bt).sty {
ty::ty_str(..) => {assert!(len > 0); len - 1},
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
ty::ty_str(None) => {
assert!(len > 0);
len - 1
}
_ => len
},
ty::ty_str(Some(_)) => {
assert!(len > 0);
len - 1
},
_ => len
};
if iv >= len {
Expand Down
Loading