Skip to content

Commit 984b567

Browse files
committed
librustc: De-@mut the variable counters in the inference context
1 parent 7ffba5c commit 984b567

File tree

1 file changed

+21
-14
lines changed
  • src/librustc/middle/typeck/infer

1 file changed

+21
-14
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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;
3839
use std::hashmap::HashMap;
3940
use std::result;
4041
use std::vec;
@@ -43,8 +44,8 @@ use syntax::ast;
4344
use syntax::codemap;
4445
use syntax::codemap::Span;
4546
use util::common::indent;
46-
use util::ppaux::{bound_region_to_str, ty_to_str, trait_ref_to_str, Repr,
47-
UserString};
47+
use util::ppaux::{bound_region_to_str, ty_to_str, trait_ref_to_str, Repr};
48+
use util::ppaux::{UserString};
4849

4950
pub mod doc;
5051
pub mod macros;
@@ -80,15 +81,15 @@ pub struct InferCtxt {
8081
// types that might instantiate a general type variable have an
8182
// order, represented by its upper and lower bounds.
8283
ty_var_bindings: ValsAndBindings<ty::TyVid, Bounds<ty::t>>,
83-
ty_var_counter: uint,
84+
ty_var_counter: Cell<uint>,
8485

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

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

9394
// For region variables.
9495
region_vars: RegionVarBindings,
@@ -260,13 +261,13 @@ pub fn new_infer_ctxt(tcx: ty::ctxt) -> @mut InferCtxt {
260261
tcx: tcx,
261262

262263
ty_var_bindings: new_ValsAndBindings(),
263-
ty_var_counter: 0,
264+
ty_var_counter: Cell::new(0),
264265

265266
int_var_bindings: new_ValsAndBindings(),
266-
int_var_counter: 0,
267+
int_var_counter: Cell::new(0),
267268

268269
float_var_bindings: new_ValsAndBindings(),
269-
float_var_counter: 0,
270+
float_var_counter: Cell::new(0),
270271

271272
region_vars: RegionVarBindings(tcx),
272273
}
@@ -599,8 +600,8 @@ fn next_simple_var<V:Clone,T:Clone>(counter: &mut uint,
599600

600601
impl InferCtxt {
601602
pub fn next_ty_var_id(&mut self) -> TyVid {
602-
let id = self.ty_var_counter;
603-
self.ty_var_counter += 1;
603+
let id = self.ty_var_counter.get();
604+
self.ty_var_counter.set(id + 1);
604605
{
605606
let vals = &mut self.ty_var_bindings.vals;
606607
vals.insert(id, Root(Bounds { lb: None, ub: None }, 0u));
@@ -617,17 +618,23 @@ impl InferCtxt {
617618
}
618619

619620
pub fn next_int_var_id(&mut self) -> IntVid {
620-
IntVid(next_simple_var(&mut self.int_var_counter,
621-
&mut self.int_var_bindings))
621+
let mut int_var_counter = self.int_var_counter.get();
622+
let result = IntVid(next_simple_var(&mut int_var_counter,
623+
&mut self.int_var_bindings));
624+
self.int_var_counter.set(int_var_counter);
625+
result
622626
}
623627

624628
pub fn next_int_var(&mut self) -> ty::t {
625629
ty::mk_int_var(self.tcx, self.next_int_var_id())
626630
}
627631

628632
pub fn next_float_var_id(&mut self) -> FloatVid {
629-
FloatVid(next_simple_var(&mut self.float_var_counter,
630-
&mut self.float_var_bindings))
633+
let mut float_var_counter = self.float_var_counter.get();
634+
let result = FloatVid(next_simple_var(&mut float_var_counter,
635+
&mut self.float_var_bindings));
636+
self.float_var_counter.set(float_var_counter);
637+
result
631638
}
632639

633640
pub fn next_float_var(&mut self) -> ty::t {

0 commit comments

Comments
 (0)