Skip to content

Commit 1b3023e

Browse files
committed
Convert ty::ty_uniq to contain a mutable type
Issue #409
1 parent 4d088bd commit 1b3023e

File tree

9 files changed

+45
-29
lines changed

9 files changed

+45
-29
lines changed

src/comp/metadata/tydecode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
216216
ret ty::mk_param(st.tcx, parse_int(st) as uint, k);
217217
}
218218
'@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
219-
'~' { ret ty::mk_uniq(st.tcx, parse_ty(st, sd)); }
219+
'~' { ret ty::mk_uniq(st.tcx, parse_mt(st, sd)); }
220220
'*' { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
221221
'I' { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }
222222
'R' {

src/comp/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
123123
w.write_char(']');
124124
}
125125
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
126-
ty::ty_uniq(t) { w.write_char('~'); enc_ty(w, cx, t); }
126+
ty::ty_uniq(mt) { w.write_char('~'); enc_mt(w, cx, mt); }
127127
ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); }
128128
ty::ty_vec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
129129
ty::ty_rec(fields) {

src/comp/middle/alias.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,9 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
559559
}
560560
ret false;
561561
}
562-
ty::ty_box(mt) | ty::ty_ptr(mt) {
562+
ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) {
563563
ret helper(tcx, needle, mt.ty, get_mut(mut, mt));
564564
}
565-
ty::ty_uniq(t) { ret helper(tcx, needle, t, false); }
566565
ty::ty_rec(fields) {
567566
for f: ty::field in fields {
568567
if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) {
@@ -619,7 +618,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
619618
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
620619
ty::ty_obj(_) { 4u }
621620
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
622-
ty::ty_uniq(t) { 1u + score_ty(tcx, t) }
621+
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }
623622
ty::ty_tag(_, ts) | ty::ty_tup(ts) {
624623
let sum = 0u;
625624
for t in ts { sum += score_ty(tcx, t); }

src/comp/middle/mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
2323
t = mt.ty;
2424
}
2525
ty::ty_uniq(mt) {
26-
ds += [@{mut: false, kind: unbox, outer_t: t}];
26+
ds += [@{mut: mt.mut != imm, kind: unbox, outer_t: t}];
2727
}
2828
ty::ty_res(_, inner, tps) {
2929
ds += [@{mut: false, kind: unbox, outer_t: t}];

src/comp/middle/shape.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
370370
s += [shape_box];
371371
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
372372
}
373-
ty::ty_uniq(subt) {
373+
ty::ty_uniq(mt) {
374374
s += [shape_uniq];
375-
add_substr(s, shape_of(ccx, subt, ty_param_map));
375+
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
376376
}
377377
ty::ty_vec(mt) {
378378
s += [shape_vec];

src/comp/middle/trans.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
162162
let mt_ty = mt.ty;
163163
check non_ty_var(cx, mt_ty);
164164
T_ptr(T_box(type_of_inner(cx, sp, mt_ty))) }
165-
ty::ty_uniq(t) {
166-
check non_ty_var(cx, t);
167-
T_ptr(type_of_inner(cx, sp, t)) }
165+
ty::ty_uniq(mt) {
166+
let mt_ty = mt.ty;
167+
check non_ty_var(cx, mt_ty);
168+
T_ptr(type_of_inner(cx, sp, mt_ty)) }
168169
ty::ty_vec(mt) {
169170
let mt_ty = mt.ty;
170171
if ty::type_has_dynamic_size(cx.tcx, mt_ty) {
@@ -478,7 +479,9 @@ fn simplify_type(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
478479
fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
479480
alt ty::struct(ccx.tcx, typ) {
480481
ty::ty_box(_) { ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)); }
481-
ty::ty_uniq(_) { ret ty::mk_uniq(ccx.tcx, ty::mk_nil(ccx.tcx)); }
482+
ty::ty_uniq(_) {
483+
ret ty::mk_imm_uniq(ccx.tcx, ty::mk_nil(ccx.tcx));
484+
}
482485
ty::ty_fn(_, _, _, _, _) {
483486
ret ty::mk_tup(ccx.tcx,
484487
[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
@@ -1313,15 +1316,15 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
13131316
trans_non_gc_free(bcx, v)
13141317
} else { bcx }
13151318
}
1316-
ty::ty_uniq(content_t) {
1319+
ty::ty_uniq(content_mt) {
13171320
let free_cx = new_sub_block_ctxt(bcx, "uniq_free");
13181321
let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next");
13191322
let vptr = Load(bcx, v0);
13201323
let null_test = IsNull(bcx, vptr);
13211324
CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb);
13221325

13231326
let bcx = free_cx;
1324-
let bcx = drop_ty(bcx, vptr, content_t);
1327+
let bcx = drop_ty(bcx, vptr, content_mt.ty);
13251328
let bcx = trans_shared_free(bcx, vptr);
13261329
Store(bcx, C_null(val_ty(vptr)), v0);
13271330
Br(bcx, next_cx.llbb);

src/comp/middle/ty.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export mk_ctxt;
6565
export mk_float;
6666
export mk_fn;
6767
export mk_imm_box;
68+
export mk_imm_uniq;
6869
export mk_mut_ptr;
6970
export mk_int;
7071
export mk_str;
@@ -251,7 +252,7 @@ tag sty {
251252
ty_str;
252253
ty_tag(def_id, [t]);
253254
ty_box(mt);
254-
ty_uniq(t);
255+
ty_uniq(mt);
255256
ty_vec(mt);
256257
ty_ptr(mt);
257258
ty_rec([field]);
@@ -448,7 +449,7 @@ fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t<str>) -> @raw_t {
448449
for tt: t in tys { derive_flags_t(cx, has_params, has_vars, tt); }
449450
}
450451
ty_box(m) { derive_flags_mt(cx, has_params, has_vars, m); }
451-
ty_uniq(tt) { derive_flags_t(cx, has_params, has_vars, tt); }
452+
ty_uniq(m) { derive_flags_mt(cx, has_params, has_vars, m); }
452453
ty_vec(m) { derive_flags_mt(cx, has_params, has_vars, m); }
453454
ty_ptr(m) { derive_flags_mt(cx, has_params, has_vars, m); }
454455
ty_rec(flds) {
@@ -534,7 +535,11 @@ fn mk_tag(cx: ctxt, did: ast::def_id, tys: [t]) -> t {
534535

535536
fn mk_box(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_box(tm)); }
536537

537-
fn mk_uniq(cx: ctxt, typ: t) -> t { ret gen_ty(cx, ty_uniq(typ)); }
538+
fn mk_uniq(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_uniq(tm)); }
539+
540+
fn mk_imm_uniq(cx: ctxt, ty: t) -> t {
541+
ret mk_uniq(cx, {ty: ty, mut: ast::imm});
542+
}
538543

539544
fn mk_ptr(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_ptr(tm)); }
540545

@@ -643,7 +648,7 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
643648
ty_constr(sub, _) { walk_ty(cx, walker, sub); }
644649
ty_var(_) {/* no-op */ }
645650
ty_param(_, _) {/* no-op */ }
646-
ty_uniq(sub) { walk_ty(cx, walker, sub); }
651+
ty_uniq(tm) { walk_ty(cx, walker, tm.ty); }
647652
}
648653
walker(ty);
649654
}
@@ -678,7 +683,9 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
678683
ty_box(tm) {
679684
ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
680685
}
681-
ty_uniq(subty) { ty = mk_uniq(cx, fold_ty(cx, fld, subty)); }
686+
ty_uniq(tm) {
687+
ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
688+
}
682689
ty_ptr(tm) {
683690
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
684691
}
@@ -1420,7 +1427,7 @@ fn hash_type_structure(st: sty) -> uint {
14201427
for c: @type_constr in cs { h += h << 5u + hash_type_constr(h, c); }
14211428
ret h;
14221429
}
1423-
ty_uniq(t) { let h = 37u; h += h << 5u + hash_ty(t); ret h; }
1430+
ty_uniq(mt) { let h = 37u; h += h << 5u + hash_ty(mt.ty); ret h; }
14241431
}
14251432
}
14261433

@@ -2184,13 +2191,20 @@ mod unify {
21842191
_ { ret ures_err(terr_mismatch); }
21852192
}
21862193
}
2187-
ty::ty_uniq(expected_sub) {
2194+
ty::ty_uniq(expected_mt) {
21882195
alt struct(cx.tcx, actual) {
2189-
ty::ty_uniq(actual_sub) {
2190-
let result = unify_step(cx, expected_sub, actual_sub);
2196+
ty::ty_uniq(actual_mt) {
2197+
let mut = expected_mt.mut;
2198+
// FIXME (409) Write a test then uncomment
2199+
/*alt unify_mut(expected_mt.mut, actual_mt.mut) {
2200+
none. { ret ures_err(terr_box_mutability); }
2201+
some(m) { mut = m; }
2202+
}*/
2203+
let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
21912204
alt result {
2192-
ures_ok(result_sub) {
2193-
ret ures_ok(mk_uniq(cx.tcx, result_sub));
2205+
ures_ok(result_mt) {
2206+
let mt = {ty: result_mt, mut: mut};
2207+
ret ures_ok(mk_uniq(cx.tcx, mt));
21942208
}
21952209
_ { ret result; }
21962210
}

src/comp/middle/typeck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
286286
typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
287287
}
288288
ast::ty_uniq(mt) {
289-
typ = ty::mk_uniq(tcx, ast_ty_to_ty(tcx, getter, mt.ty));
289+
typ = ty::mk_uniq(tcx, ast_mt_to_mt(tcx, getter, mt));
290290
}
291291
ast::ty_vec(mt) {
292292
typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
@@ -1720,12 +1720,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
17201720
alt unop {
17211721
ast::box(mut) { oper_t = ty::mk_box(tcx, {ty: oper_t, mut: mut}); }
17221722
ast::uniq(mut) {
1723-
oper_t = ty::mk_uniq(tcx, oper_t);
1723+
oper_t = ty::mk_uniq(tcx, {ty: oper_t, mut: mut});
17241724
}
17251725
ast::deref. {
17261726
alt structure_of(fcx, expr.span, oper_t) {
17271727
ty::ty_box(inner) { oper_t = inner.ty; }
1728-
ty::ty_uniq(inner) { oper_t = inner; }
1728+
ty::ty_uniq(inner) { oper_t = inner.ty; }
17291729
ty::ty_res(_, inner, _) { oper_t = inner; }
17301730
ty::ty_tag(id, tps) {
17311731
let variants = ty::tag_variants(tcx, id);

src/comp/util/ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
101101
ty_char. { "char" }
102102
ty_str. { "str" }
103103
ty_box(tm) { "@" + mt_to_str(cx, tm) }
104-
ty_uniq(t) { "~" + ty_to_str(cx, t) }
104+
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
105105
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
106106
ty_type. { "type" }
107107
ty_rec(elems) {

0 commit comments

Comments
 (0)