diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-02-16 12:46:44 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-02-28 08:43:47 -0500 |
| commit | b3a482ca9b1622a2fd04d8338ac99f5df802b9e2 (patch) | |
| tree | 50277943f9c04546fde39f3d65fd2323ea691d63 /src/librustc_data_structures | |
| parent | e1cb9ba221e5cb0070ac82c6a234af11e4240680 (diff) | |
| download | rust-b3a482ca9b1622a2fd04d8338ac99f5df802b9e2.tar.gz rust-b3a482ca9b1622a2fd04d8338ac99f5df802b9e2.zip | |
move the `FreeRegionMap` into `TypeckTables`
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_data_structures/transitive_relation.rs | 33 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index cf6bf1cf1d4..3dce4398f3b 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -28,6 +28,7 @@ #![feature(shared)] #![feature(collections_range)] #![feature(collections_bound)] +#![cfg_attr(stage0,feature(field_init_shorthand))] #![feature(nonzero)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index e09e260afc8..2bce7faf08c 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -9,6 +9,7 @@ // except according to those terms. use bitvec::BitMatrix; +use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use std::cell::RefCell; use std::fmt::Debug; use std::mem; @@ -36,10 +37,10 @@ pub struct TransitiveRelation<T: Debug + PartialEq> { closure: RefCell<Option<BitMatrix>>, } -#[derive(Clone, PartialEq, PartialOrd)] +#[derive(Clone, PartialEq, PartialOrd, RustcEncodable, RustcDecodable)] struct Index(usize); -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)] struct Edge { source: Index, target: Index, @@ -54,6 +55,10 @@ impl<T: Debug + PartialEq> TransitiveRelation<T> { } } + pub fn is_empty(&self) -> bool { + self.edges.is_empty() + } + fn index(&self, a: &T) -> Option<Index> { self.elements.iter().position(|e| *e == *a).map(Index) } @@ -305,6 +310,30 @@ fn pare_down(candidates: &mut Vec<usize>, closure: &BitMatrix) { } } +impl<T> Encodable for TransitiveRelation<T> + where T: Encodable + Debug + PartialEq +{ + fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> { + s.emit_struct("TransitiveRelation", 2, |s| { + s.emit_struct_field("elements", 0, |s| self.elements.encode(s))?; + s.emit_struct_field("edges", 1, |s| self.edges.encode(s))?; + Ok(()) + }) + } +} + +impl<T> Decodable for TransitiveRelation<T> + where T: Decodable + Debug + PartialEq +{ + fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> { + d.read_struct("TransitiveRelation", 2, |d| { + let elements = d.read_struct_field("elements", 0, |d| Decodable::decode(d))?; + let edges = d.read_struct_field("edges", 1, |d| Decodable::decode(d))?; + Ok(TransitiveRelation { elements, edges, closure: RefCell::new(None) }) + }) + } +} + #[test] fn test_one_step() { let mut relation = TransitiveRelation::new(); |
