Skip to content

Commit 596d19e

Browse files
committed
Test the deque a bit. Give it a get-by-index method. Fix two uncovered state-calculation bugs --- one decently, the other with an ugly hack. Bug on the latter coming right up.
1 parent 8030757 commit 596d19e

File tree

7 files changed

+65
-8
lines changed

7 files changed

+65
-8
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
426426
lazy-and-or.rs \
427427
lazy-init.rs \
428428
lazychan.rs \
429+
lib-deque.rs \
429430
lib-rand.rs \
430431
linear-for-loop.rs \
431432
list.rs \

src/boot/me/semant.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,23 @@ let rec simplified_ty (t:Ast.ty) : Ast.ty =
10611061
| t -> t
10621062
;;
10631063

1064+
let rec innermost_box_ty (t:Ast.ty) : Ast.ty =
1065+
match strip_mutable_or_constrained_ty t with
1066+
Ast.TY_box t -> innermost_box_ty t
1067+
| _ -> t
1068+
;;
1069+
1070+
let simplified_ty_innermost_was_mutable (t:Ast.ty) : Ast.ty * bool =
1071+
let rec simplify_innermost t =
1072+
match t with
1073+
Ast.TY_mutable t -> (fst (simplify_innermost t), true)
1074+
| Ast.TY_constrained (t, _) -> simplify_innermost t
1075+
| _ -> (t, false)
1076+
in
1077+
let t = innermost_box_ty t in
1078+
simplify_innermost t
1079+
;;
1080+
10641081
let rec project_type
10651082
(base_ty:Ast.ty)
10661083
(comp:Ast.lval_component)

src/boot/me/trans.ml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ let trans_visitor
11031103
(t:Ast.ty)
11041104
(sz:int64)
11051105
(align:int64)
1106+
(force_stateful:bool)
11061107
: Il.operand =
11071108
trans_crate_rel_data_operand
11081109
(DATA_tydesc t)
@@ -1112,7 +1113,9 @@ let trans_visitor
11121113
let fix fixup =
11131114
fixup_rel_word tydesc_fixup fixup
11141115
in
1115-
let is_stateful = if type_has_state t then 1L else 0L in
1116+
let is_stateful =
1117+
if (force_stateful || type_has_state t) then 1L else 0L
1118+
in
11161119
log cx "tydesc for %a has sz=%Ld, align=%Ld, is_stateful=%Ld"
11171120
Ast.sprintf_ty t sz align is_stateful;
11181121
Asm.DEF
@@ -2343,11 +2346,15 @@ let trans_visitor
23432346
dst_cell dst_ty src_cell src_ty None
23442347

23452348

2346-
and get_dynamic_tydesc (idopt:node_id option) (t:Ast.ty) : Il.cell =
2349+
and get_dynamic_tydesc
2350+
(idopt:node_id option)
2351+
(t:Ast.ty)
2352+
(force_stateful:bool)
2353+
: Il.cell =
23472354
let td = next_vreg_cell Il.voidptr_t in
23482355
let root_desc =
23492356
Il.Cell (crate_rel_to_ptr
2350-
(get_static_tydesc idopt t 0L 0L)
2357+
(get_static_tydesc idopt t 0L 0L force_stateful)
23512358
(tydesc_rty abi))
23522359
in
23532360
let (t, param_descs) = linearize_ty_params t in
@@ -2378,15 +2385,17 @@ let trans_visitor
23782385

23792386
and get_tydesc (idopt:node_id option) (ty:Ast.ty) : Il.cell =
23802387
log cx "getting tydesc for %a" Ast.sprintf_ty ty;
2381-
match simplified_ty ty with
2388+
let (ty, mut) = simplified_ty_innermost_was_mutable ty in
2389+
match ty with
23822390
Ast.TY_param (idx, _) ->
23832391
(get_ty_param_in_current_frame idx)
23842392
| t when has_parametric_types t ->
2385-
(get_dynamic_tydesc idopt t)
2393+
(get_dynamic_tydesc idopt t mut)
23862394
| _ ->
23872395
(crate_rel_to_ptr (get_static_tydesc idopt ty
23882396
(ty_sz abi ty)
2389-
(ty_align abi ty))
2397+
(ty_align abi ty)
2398+
mut)
23902399
(tydesc_rty abi))
23912400

23922401
and box_rc_cell (cell:Il.cell) : Il.cell =

src/lib/deque.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type t[T] = obj {
1717

1818
fn peek_front() -> T;
1919
fn peek_back() -> T;
20+
21+
fn get(int i) -> T;
2022
};
2123

2224
fn create[T]() -> t[T] {
@@ -128,6 +130,11 @@ fn create[T]() -> t[T] {
128130
fn peek_back() -> T {
129131
ret get[T](elts, hi);
130132
}
133+
134+
fn get(int i) -> T {
135+
let uint idx = (lo + (i as uint)) % _vec.len[cell[T]](elts);
136+
ret get[T](elts, idx);
137+
}
131138
}
132139

133140
let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T](),

src/rt/rust_crate_cache.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ rust_crate_cache::get_type_desc(size_t size,
216216
"rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR,
217217
i, descs[i]);
218218
td->descs[i] = descs[i];
219+
td->is_stateful |= descs[i]->is_stateful;
219220
}
220221
adjust_disp(td->copy_glue_off, descs[0], td);
221222
adjust_disp(td->drop_glue_off, descs[0], td);

src/rt/rust_upcall.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,13 @@ extern "C" CDECL uintptr_t upcall_require_c_sym(rust_task *task,
499499
}
500500

501501
extern "C" CDECL type_desc *
502-
upcall_get_type_desc(rust_task *task, rust_crate const *curr_crate,
503-
size_t size, size_t align, size_t n_descs, type_desc const **descs) {
502+
upcall_get_type_desc(rust_task *task,
503+
rust_crate const *curr_crate,
504+
size_t size,
505+
size_t align,
506+
size_t n_descs,
507+
type_desc const **descs)
508+
{
504509
LOG_UPCALL_ENTRY(task);
505510
task->log(rust_log::UPCALL | rust_log::CACHE,
506511
"upcall get_type_desc with size=%" PRIdPTR

src/test/run-pass/lib-deque.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// -*- rust -*-
2+
3+
use std;
4+
import std.deque;
5+
6+
fn main() {
7+
let deque.t[int] d1 = deque.create[int]();
8+
check (d1.size() == 0u);
9+
d1.add_front(17);
10+
d1.add_front(42);
11+
d1.add_back(137);
12+
check (d1.size() == 3u);
13+
d1.add_back(137);
14+
check (d1.size() == 4u);
15+
/* FIXME (issue #133): We should check that the numbers come back
16+
* to us correctly once the deque stops zeroing them out. */
17+
}

0 commit comments

Comments
 (0)