提交 dc486994 编写于 作者: P Patrick Walton

librustc: Remove newtype enums from librustc

上级 4faf63e4
......@@ -137,8 +137,8 @@
// if it detects an outstanding loan (that is, the addr is taken).
pub type last_use_map = HashMap<node_id, @mut ~[node_id]>;
enum Variable = uint;
enum LiveNode = uint;
struct Variable(uint);
struct LiveNode(uint);
impl cmp::Eq for Variable {
pure fn eq(&self, other: &Variable) -> bool { *(*self) == *(*other) }
......
......@@ -582,18 +582,20 @@ pub enum param_bound {
}
#[deriving_eq]
pub enum TyVid = uint;
pub struct TyVid(uint);
#[deriving_eq]
pub enum IntVid = uint;
pub struct IntVid(uint);
#[deriving_eq]
pub enum FloatVid = uint;
pub struct FloatVid(uint);
#[deriving_eq]
#[auto_encode]
#[auto_decode]
pub enum RegionVid = uint;
pub struct RegionVid {
id: uint
}
#[deriving_eq]
pub enum InferTy {
......@@ -687,11 +689,11 @@ impl ToStr for FloatVid {
}
impl Vid for RegionVid {
pure fn to_uint(&self) -> uint { **self }
pure fn to_uint(&self) -> uint { self.id }
}
impl ToStr for RegionVid {
pure fn to_str(&self) -> ~str { fmt!("%?", self) }
pure fn to_str(&self) -> ~str { fmt!("%?", self.id) }
}
impl ToStr for FnSig {
......
......@@ -84,7 +84,7 @@ fn foo<A>(a: A, b: A) { ... }
// Note: Coerce is not actually a combiner, in that it does not
// conform to the same interface, though it performs a similar
// function.
pub enum Coerce = CombineFields;
pub struct Coerce(CombineFields);
pub impl Coerce {
fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
......
......@@ -29,7 +29,7 @@
use std::list;
pub enum Glb = CombineFields; // "greatest lower bound" (common subtype)
pub struct Glb(CombineFields); // "greatest lower bound" (common subtype)
impl Combine for Glb {
fn infcx(&self) -> @mut InferCtxt { self.infcx }
......
......@@ -29,7 +29,7 @@
use syntax::ast::{Onceness, purity};
use syntax::codemap::span;
pub enum Lub = CombineFields; // least-upper-bound: common supertype
pub struct Lub(CombineFields); // least-upper-bound: common supertype
pub impl Lub {
fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }
......
......@@ -700,7 +700,7 @@ fn rollback_to(&mut self, snapshot: uint) {
match undo_item {
Snapshot => {}
AddVar(vid) => {
fail_unless!(self.var_spans.len() == *vid + 1);
fail_unless!(self.var_spans.len() == vid.to_uint() + 1);
self.var_spans.pop();
}
AddConstraint(ref constraint) => {
......@@ -720,7 +720,7 @@ fn num_vars(&mut self) -> uint {
fn new_region_var(&mut self, span: span) -> RegionVid {
let id = self.num_vars();
self.var_spans.push(span);
let vid = RegionVid(id);
let vid = RegionVid { id: id };
if self.in_snapshot() {
self.undo_log.push(AddVar(vid));
}
......@@ -863,15 +863,15 @@ fn glb_regions(&mut self,
}
fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, *rid);
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, rid.to_uint());
if self.values.is_empty() {
self.tcx.sess.span_bug(
self.var_spans[*rid],
self.var_spans[rid.to_uint()],
fmt!("Attempt to resolve region variable before values have \
been computed!"));
}
let v = self.values.with_ref(|values| values[*rid]);
let v = self.values.with_ref(|values| values[rid.to_uint()]);
match v {
Value(r) => r,
......@@ -886,13 +886,13 @@ fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
// should ultimately have some bounds.
self.tcx.sess.span_err(
self.var_spans[*rid],
fmt!("Unconstrained region variable #%u", *rid));
self.var_spans[rid.to_uint()],
fmt!("Unconstrained region variable #%u", rid.to_uint()));
// Touch of a hack: to suppress duplicate messages,
// replace the NoValue entry with ErrorValue.
let mut values = self.values.take();
values[*rid] = ErrorValue;
values[rid.to_uint()] = ErrorValue;
self.values.put_back(values);
re_static
}
......@@ -1049,7 +1049,7 @@ fn lub_concrete_regions(&mut self, +a: Region, +b: Region) -> Region {
(re_infer(ReVar(v_id)), _) | (_, re_infer(ReVar(v_id))) => {
self.tcx.sess.span_bug(
self.var_spans[*v_id],
self.var_spans[v_id.to_uint()],
fmt!("lub_concrete_regions invoked with \
non-concrete regions: %?, %?", a, b));
}
......@@ -1111,7 +1111,7 @@ fn glb_concrete_regions(&mut self,
(re_infer(ReVar(v_id)), _) |
(_, re_infer(ReVar(v_id))) => {
self.tcx.sess.span_bug(
self.var_spans[*v_id],
self.var_spans[v_id.to_uint()],
fmt!("glb_concrete_regions invoked with \
non-concrete regions: %?, %?", a, b));
}
......@@ -1275,8 +1275,8 @@ fn insert_edge(+graph: &mut Graph,
edge_idx: uint) {
let edge_dir = edge_dir as uint;
graph.edges[edge_idx].next_edge[edge_dir] =
graph.nodes[*node_id].head_edge[edge_dir];
graph.nodes[*node_id].head_edge[edge_dir] =
graph.nodes[node_id.to_uint()].head_edge[edge_dir];
graph.nodes[node_id.to_uint()].head_edge[edge_dir] =
edge_idx;
}
}
......@@ -1285,14 +1285,14 @@ fn expansion(&mut self, graph: &mut Graph) {
do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| {
match edge.constraint {
ConstrainRegSubVar(a_region, b_vid) => {
let b_node = &mut nodes[*b_vid];
let b_node = &mut nodes[b_vid.to_uint()];
self.expand_node(a_region, b_vid, b_node)
}
ConstrainVarSubVar(a_vid, b_vid) => {
match nodes[*a_vid].value {
match nodes[a_vid.to_uint()].value {
NoValue | ErrorValue => false,
Value(a_region) => {
let b_node = &mut nodes[*b_vid];
let b_node = &mut nodes[b_vid.to_uint()];
self.expand_node(a_region, b_vid, b_node)
}
}
......@@ -1349,16 +1349,16 @@ fn contraction(&mut self, graph: &mut Graph) {
false
}
ConstrainVarSubVar(a_vid, b_vid) => {
match nodes[*b_vid].value {
match nodes[b_vid.to_uint()].value {
NoValue | ErrorValue => false,
Value(b_region) => {
let a_node = &mut nodes[*a_vid];
let a_node = &mut nodes[a_vid.to_uint()];
self.contract_node(a_vid, a_node, b_region)
}
}
}
ConstrainVarSubReg(a_vid, b_region) => {
let a_node = &mut nodes[*a_vid];
let a_node = &mut nodes[a_vid.to_uint()];
self.contract_node(a_vid, a_node, b_region)
}
}
......@@ -1474,7 +1474,7 @@ fn extract_values_and_report_conflicts(
that is not used is not a problem, so if this rule
starts to create problems we'll have to revisit
this portion of the code and think hard about it. =) */
let node_vid = RegionVid(idx);
let node_vid = RegionVid { id: idx };
match node.classification {
Expanding => {
self.report_error_for_expanding_node(
......@@ -1525,7 +1525,7 @@ fn report_error_for_expanding_node(&mut self,
}
self.tcx.sess.span_err(
self.var_spans[*node_idx],
self.var_spans[node_idx.to_uint()],
fmt!("cannot infer an appropriate lifetime \
due to conflicting requirements"));
......@@ -1578,7 +1578,7 @@ fn report_error_for_contracting_node(&mut self,
}
self.tcx.sess.span_err(
self.var_spans[*node_idx],
self.var_spans[node_idx.to_uint()],
fmt!("cannot infer an appropriate lifetime \
due to conflicting requirements"));
......@@ -1616,7 +1616,7 @@ fn collect_concrete_regions(&mut self,
-> ~[SpannedRegion] {
let set = HashMap();
let mut stack = ~[orig_node_idx];
set.insert(*orig_node_idx, ());
set.insert(orig_node_idx.to_uint(), ());
let mut result = ~[];
while !vec::is_empty(stack) {
let node_idx = stack.pop();
......@@ -1627,7 +1627,7 @@ fn collect_concrete_regions(&mut self,
Incoming => from_vid,
Outgoing => to_vid
};
if set.insert(*vid, ()) {
if set.insert(vid.to_uint(), ()) {
stack.push(vid);
}
}
......@@ -1658,7 +1658,8 @@ fn each_edge(&mut self,
node_idx: RegionVid,
dir: Direction,
op: &fn(edge: &GraphEdge) -> bool) {
let mut edge_idx = graph.nodes[*node_idx].head_edge[dir as uint];
let mut edge_idx =
graph.nodes[node_idx.to_uint()].head_edge[dir as uint];
while edge_idx != uint::max_value {
let edge_ptr = &graph.edges[edge_idx];
if !op(edge_ptr) {
......
......@@ -29,7 +29,7 @@
use syntax::codemap::span;
pub enum Sub = CombineFields; // "subtype", "subregion" etc
pub struct Sub(CombineFields); // "subtype", "subregion" etc
impl Combine for Sub {
fn infcx(&self) -> @mut InferCtxt { self.infcx }
......
......@@ -74,7 +74,8 @@ fn named_region(&self, span: span, id: ast::ident)
}
}
pub enum type_rscope = Option<ty::region_variance>;
pub struct type_rscope(Option<ty::region_variance>);
impl type_rscope {
priv fn replacement(&self) -> ty::Region {
if self.is_some() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册