Skip to content

Commit f321b80

Browse files
committed
---
yaml --- r: 94619 b: refs/heads/try c: 3840d50 h: refs/heads/master i: 94617: 9724a33 94615: 6e8e0e7 v: v3
1 parent 41e0209 commit f321b80

File tree

3 files changed

+46
-34
lines changed

3 files changed

+46
-34
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: 984b567f9e5bb7153634bbdbc9661e8b8a6c8c63
5+
refs/heads/try: 3840d505168652cd4115b24613077ee9d571ff44
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/typeck/infer/mod.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use middle::typeck::infer::lub::Lub;
3535
use middle::typeck::infer::to_str::InferStr;
3636
use middle::typeck::infer::unify::{ValsAndBindings, Root};
3737
use middle::typeck::infer::error_reporting::ErrorReporting;
38-
use std::cell::Cell;
38+
use std::cell::{Cell, RefCell};
3939
use std::hashmap::HashMap;
4040
use std::result;
4141
use std::vec;
@@ -80,15 +80,17 @@ pub struct InferCtxt {
8080
// We instantiate ValsAndBindings with bounds<ty::t> because the
8181
// types that might instantiate a general type variable have an
8282
// order, represented by its upper and lower bounds.
83-
ty_var_bindings: ValsAndBindings<ty::TyVid, Bounds<ty::t>>,
83+
ty_var_bindings: RefCell<ValsAndBindings<ty::TyVid, Bounds<ty::t>>>,
8484
ty_var_counter: Cell<uint>,
8585

8686
// Map from integral variable to the kind of integer it represents
87-
int_var_bindings: ValsAndBindings<ty::IntVid, Option<IntVarValue>>,
87+
int_var_bindings: RefCell<ValsAndBindings<ty::IntVid,
88+
Option<IntVarValue>>>,
8889
int_var_counter: Cell<uint>,
8990

9091
// Map from floating variable to the kind of float it represents
91-
float_var_bindings: ValsAndBindings<ty::FloatVid, Option<ast::float_ty>>,
92+
float_var_bindings: RefCell<ValsAndBindings<ty::FloatVid,
93+
Option<ast::float_ty>>>,
9294
float_var_counter: Cell<uint>,
9395

9496
// For region variables.
@@ -260,13 +262,13 @@ pub fn new_infer_ctxt(tcx: ty::ctxt) -> @mut InferCtxt {
260262
@mut InferCtxt {
261263
tcx: tcx,
262264

263-
ty_var_bindings: new_ValsAndBindings(),
265+
ty_var_bindings: RefCell::new(new_ValsAndBindings()),
264266
ty_var_counter: Cell::new(0),
265267

266-
int_var_bindings: new_ValsAndBindings(),
268+
int_var_bindings: RefCell::new(new_ValsAndBindings()),
267269
int_var_counter: Cell::new(0),
268270

269-
float_var_bindings: new_ValsAndBindings(),
271+
float_var_bindings: RefCell::new(new_ValsAndBindings()),
270272
float_var_counter: Cell::new(0),
271273

272274
region_vars: RegionVarBindings(tcx),
@@ -522,25 +524,25 @@ impl InferCtxt {
522524
}
523525

524526
pub fn start_snapshot(&mut self) -> Snapshot {
527+
let ty_var_bindings = self.ty_var_bindings.borrow();
528+
let int_var_bindings = self.int_var_bindings.borrow();
529+
let float_var_bindings = self.float_var_bindings.borrow();
525530
Snapshot {
526-
ty_var_bindings_len:
527-
self.ty_var_bindings.bindings.len(),
528-
int_var_bindings_len:
529-
self.int_var_bindings.bindings.len(),
530-
float_var_bindings_len:
531-
self.float_var_bindings.bindings.len(),
532-
region_vars_snapshot:
533-
self.region_vars.start_snapshot(),
531+
ty_var_bindings_len: ty_var_bindings.get().bindings.len(),
532+
int_var_bindings_len: int_var_bindings.get().bindings.len(),
533+
float_var_bindings_len: float_var_bindings.get().bindings.len(),
534+
region_vars_snapshot: self.region_vars.start_snapshot(),
534535
}
535536
}
536537

537538
pub fn rollback_to(&mut self, snapshot: &Snapshot) {
538539
debug!("rollback!");
539-
rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len);
540-
541-
rollback_to(&mut self.int_var_bindings,
542-
snapshot.int_var_bindings_len);
543-
rollback_to(&mut self.float_var_bindings,
540+
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
541+
let mut int_var_bindings = self.int_var_bindings.borrow_mut();
542+
let mut float_var_bindings = self.float_var_bindings.borrow_mut();
543+
rollback_to(ty_var_bindings.get(), snapshot.ty_var_bindings_len);
544+
rollback_to(int_var_bindings.get(), snapshot.int_var_bindings_len);
545+
rollback_to(float_var_bindings.get(),
544546
snapshot.float_var_bindings_len);
545547

546548
self.region_vars.rollback_to(snapshot.region_vars_snapshot);
@@ -554,8 +556,10 @@ impl InferCtxt {
554556
indent(|| {
555557
let r = self.try(|| f());
556558

557-
self.ty_var_bindings.bindings.truncate(0);
558-
self.int_var_bindings.bindings.truncate(0);
559+
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
560+
let mut int_var_bindings = self.int_var_bindings.borrow_mut();
561+
ty_var_bindings.get().bindings.truncate(0);
562+
int_var_bindings.get().bindings.truncate(0);
559563
self.region_vars.commit();
560564
r
561565
})
@@ -603,7 +607,8 @@ impl InferCtxt {
603607
let id = self.ty_var_counter.get();
604608
self.ty_var_counter.set(id + 1);
605609
{
606-
let vals = &mut self.ty_var_bindings.vals;
610+
let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
611+
let vals = &mut ty_var_bindings.get().vals;
607612
vals.insert(id, Root(Bounds { lb: None, ub: None }, 0u));
608613
}
609614
return TyVid(id);
@@ -619,8 +624,9 @@ impl InferCtxt {
619624

620625
pub fn next_int_var_id(&mut self) -> IntVid {
621626
let mut int_var_counter = self.int_var_counter.get();
627+
let mut int_var_bindings = self.int_var_bindings.borrow_mut();
622628
let result = IntVid(next_simple_var(&mut int_var_counter,
623-
&mut self.int_var_bindings));
629+
int_var_bindings.get()));
624630
self.int_var_counter.set(int_var_counter);
625631
result
626632
}
@@ -631,8 +637,9 @@ impl InferCtxt {
631637

632638
pub fn next_float_var_id(&mut self) -> FloatVid {
633639
let mut float_var_counter = self.float_var_counter.get();
640+
let mut float_var_bindings = self.float_var_bindings.borrow_mut();
634641
let result = FloatVid(next_simple_var(&mut float_var_counter,
635-
&mut self.float_var_bindings));
642+
float_var_bindings.get()));
636643
self.float_var_counter.set(float_var_counter);
637644
result
638645
}

branches/try/src/librustc/middle/typeck/infer/unify.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use middle::ty;
1616
use middle::typeck::infer::{Bounds, uok, ures};
1717
use middle::typeck::infer::InferCtxt;
1818
use middle::typeck::infer::to_str::InferStr;
19+
use std::cell::RefCell;
1920
use syntax::ast;
2021

2122
#[deriving(Clone)]
@@ -37,7 +38,8 @@ pub struct Node<V, T> {
3738

3839
pub trait UnifyVid<T> {
3940
fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
40-
-> &'v mut ValsAndBindings<Self, T>;
41+
-> &'v mut RefCell<ValsAndBindings<Self,
42+
T>>;
4143
}
4244

4345
pub trait UnifyInferCtxtMethods {
@@ -74,7 +76,8 @@ impl UnifyInferCtxtMethods for InferCtxt {
7476

7577
let tcx = self.tcx;
7678
let vb = UnifyVid::appropriate_vals_and_bindings(self);
77-
return helper(tcx, vb, vid);
79+
let mut vb = vb.borrow_mut();
80+
return helper(tcx, vb.get(), vid);
7881

7982
fn helper<T:Clone, V:Clone+Eq+Vid>(
8083
tcx: ty::ctxt,
@@ -120,9 +123,10 @@ impl UnifyInferCtxtMethods for InferCtxt {
120123
vid.to_str(), new_v.inf_str(self));
121124

122125
let vb = UnifyVid::appropriate_vals_and_bindings(self);
123-
let old_v = (*vb.vals.get(&vid.to_uint())).clone();
124-
vb.bindings.push((vid.clone(), old_v));
125-
vb.vals.insert(vid.to_uint(), new_v);
126+
let mut vb = vb.borrow_mut();
127+
let old_v = (*vb.get().vals.get(&vid.to_uint())).clone();
128+
vb.get().bindings.push((vid.clone(), old_v));
129+
vb.get().vals.insert(vid.to_uint(), new_v);
126130
}
127131

128132
fn unify<T:Clone + InferStr,
@@ -275,14 +279,14 @@ impl InferCtxtMethods for InferCtxt {
275279

276280
impl UnifyVid<Bounds<ty::t>> for ty::TyVid {
277281
fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
278-
-> &'v mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> {
282+
-> &'v mut RefCell<ValsAndBindings<ty::TyVid, Bounds<ty::t>>> {
279283
return &mut infcx.ty_var_bindings;
280284
}
281285
}
282286

283287
impl UnifyVid<Option<IntVarValue>> for ty::IntVid {
284288
fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
285-
-> &'v mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> {
289+
-> &'v mut RefCell<ValsAndBindings<ty::IntVid, Option<IntVarValue>>> {
286290
return &mut infcx.int_var_bindings;
287291
}
288292
}
@@ -295,7 +299,8 @@ impl SimplyUnifiable for IntVarValue {
295299

296300
impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid {
297301
fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
298-
-> &'v mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> {
302+
-> &'v mut RefCell<ValsAndBindings<ty::FloatVid,
303+
Option<ast::float_ty>>> {
299304
return &mut infcx.float_var_bindings;
300305
}
301306
}

0 commit comments

Comments
 (0)