Skip to content

Commit 0374216

Browse files
committed
---
yaml --- r: 617 b: refs/heads/master c: 5e77e78 h: refs/heads/master i: 615: ca91f14 v: v3
1 parent d97317e commit 0374216

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1428b59a19610d838d7849c7ac518c40281fddd1
2+
refs/heads/master: 5e77e784f006e36c06252d9beccbd7893eddac73

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
425425
$(addprefix test/run-pass/, \
426426
arith-1.rs \
427427
acyclic-unwind.rs \
428+
alt-pattern-drop.rs \
428429
alt-pattern-simple.rs \
429430
alt-tag.rs \
430431
append-units.rs \

trunk/src/boot/me/trans.ml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,12 +4138,24 @@ let trans_visitor
41384138

41394139
let trans_arm arm : quad_idx =
41404140
let (pat, block) = arm.node in
4141-
(* Translates the pattern and returns the addresses of the branch
4142-
* instructions, which are taken if the match fails. *)
4143-
let rec trans_pat pat src_cell src_ty =
4141+
4142+
(* Translates the pattern and returns the following pair.
4143+
*
4144+
* fst: The addresses of the branch instructions that are taken if
4145+
* the match fails.
4146+
* snd: The (cell, slot) pairs of any slots bound and initialized
4147+
* in PAT_slot pattern leaves.
4148+
*)
4149+
let rec trans_pat
4150+
(pat:Ast.pat)
4151+
(src_cell:Il.cell)
4152+
(src_ty:Ast.ty)
4153+
: (quad_idx list) * ((Il.cell * Ast.slot) list) =
4154+
41444155
match pat with
41454156
Ast.PAT_lit lit ->
4146-
trans_compare_simple Il.JNE (trans_lit lit) (Il.Cell src_cell)
4157+
(trans_compare_simple Il.JNE (trans_lit lit) (Il.Cell src_cell),
4158+
[])
41474159

41484160
| Ast.PAT_tag (lval, pats) ->
41494161
let tag_name = tag_ctor_name_to_tag_name (lval_to_name lval) in
@@ -4173,16 +4185,19 @@ let trans_visitor
41734185

41744186
let tup_cell:Il.cell = get_variant_ptr union_cell tag_number in
41754187

4176-
let trans_elem_pat i elem_pat : quad_idx list =
4188+
let trans_elem_pat i elem_pat
4189+
: (quad_idx list) * ((Il.cell * Ast.slot) list) =
41774190
let elem_cell =
41784191
get_element_ptr_dyn_in_current_frame tup_cell i
41794192
in
41804193
let elem_ty = ty_tup.(i) in
41814194
trans_pat elem_pat elem_cell elem_ty
41824195
in
41834196

4184-
let elem_jumps = Array.mapi trans_elem_pat pats in
4185-
next_jumps @ (List.concat (Array.to_list elem_jumps))
4197+
let (elem_jumps, bindings) =
4198+
List.split (Array.to_list (Array.mapi trans_elem_pat pats))
4199+
in
4200+
(next_jumps @ (List.concat elem_jumps), List.concat bindings)
41864201

41874202
| Ast.PAT_slot (dst, _) ->
41884203
let dst_slot = get_slot cx dst.id in
@@ -4191,14 +4206,24 @@ let trans_visitor
41914206
(get_ty_params_of_current_frame())
41924207
CLONE_none dst_cell dst_slot
41934208
src_cell src_ty;
4194-
[] (* irrefutable *)
4209+
([], [(dst_cell, dst_slot)]) (* irrefutable *)
41954210

4196-
| Ast.PAT_wild -> [] (* irrefutable *)
4211+
| Ast.PAT_wild -> ([], []) (* irrefutable *)
41974212
in
41984213

41994214
let (lval_cell, lval_ty) = trans_lval at.Ast.alt_tag_lval in
4200-
let next_jumps = trans_pat pat lval_cell lval_ty in
4215+
let (next_jumps, bindings) = trans_pat pat lval_cell lval_ty in
42014216
trans_block block;
4217+
4218+
(* Drop any slots we initialized in the leaf slot bindings of
4219+
* this arm's pattern.
4220+
*
4221+
* FIXME: Is `None` really correct to pass as the curr_iso?
4222+
*)
4223+
List.iter
4224+
(fun (cell, slot) -> drop_slot_in_current_frame cell slot None)
4225+
bindings;
4226+
42024227
let last_jump = mark() in
42034228
emit (Il.jmp Il.JMP Il.CodeNone);
42044229
List.iter patch next_jumps;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// -*- rust -*-
2+
3+
use std;
4+
import std._str;
5+
6+
type t = tag(make_t(str), clam());
7+
8+
fn main() {
9+
let str s = "hi"; // ref up
10+
let t x = make_t(s); // ref up
11+
12+
alt (x) {
13+
case (make_t(y)) { log y; } // ref up and ref down
14+
case (_) { log "?"; }
15+
}
16+
17+
log _str.refcount(s);
18+
check (_str.refcount(s) == 2u);
19+
}

0 commit comments

Comments
 (0)