rustc: Implement and enforce instance coherence
This commit is contained in:
parent
b5729bd600
commit
db020ab63c
111 changed files with 1746 additions and 526 deletions
|
|
@ -6,7 +6,12 @@ import list;
|
|||
import list::{list, cons, nil};
|
||||
|
||||
type chunk = {data: ~[u8], mut fill: uint};
|
||||
type arena = {mut chunks: @list<@chunk>};
|
||||
|
||||
type arena_ = {mut chunks: @list<@chunk>};
|
||||
|
||||
enum arena {
|
||||
arena_(arena_)
|
||||
}
|
||||
|
||||
fn chunk(size: uint) -> @chunk {
|
||||
let mut v = ~[];
|
||||
|
|
@ -15,7 +20,7 @@ fn chunk(size: uint) -> @chunk {
|
|||
}
|
||||
|
||||
fn arena_with_size(initial_size: uint) -> arena {
|
||||
ret {mut chunks: @cons(chunk(initial_size), @nil)};
|
||||
ret arena_({mut chunks: @cons(chunk(initial_size), @nil)});
|
||||
}
|
||||
|
||||
fn arena() -> arena {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,11 @@ fn doc_as_i32(d: doc) -> i32 { doc_as_u32(d) as i32 }
|
|||
fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 }
|
||||
|
||||
// ebml writing
|
||||
type writer = {writer: io::writer, mut size_positions: ~[uint]};
|
||||
type writer_ = {writer: io::writer, mut size_positions: ~[uint]};
|
||||
|
||||
enum writer {
|
||||
writer_(writer_)
|
||||
}
|
||||
|
||||
fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
|
||||
alt size {
|
||||
|
|
@ -187,7 +191,7 @@ fn write_vuint(w: io::writer, n: uint) {
|
|||
|
||||
fn writer(w: io::writer) -> writer {
|
||||
let size_positions: ~[uint] = ~[];
|
||||
ret {writer: w, mut size_positions: size_positions};
|
||||
ret writer_({writer: w, mut size_positions: size_positions});
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
|
|
@ -311,9 +315,12 @@ enum ebml_serializer_tag {
|
|||
es_label // Used only when debugging
|
||||
}
|
||||
|
||||
impl serializer of serialization::serializer for ebml::writer {
|
||||
fn emit_nil() {}
|
||||
trait serializer_priv {
|
||||
fn _emit_tagged_uint(t: ebml_serializer_tag, v: uint);
|
||||
fn _emit_label(label: ~str);
|
||||
}
|
||||
|
||||
impl serializer of serializer_priv for ebml::writer {
|
||||
// used internally to emit things like the vector length and so on
|
||||
fn _emit_tagged_uint(t: ebml_serializer_tag, v: uint) {
|
||||
assert v <= 0xFFFF_FFFF_u;
|
||||
|
|
@ -329,6 +336,10 @@ impl serializer of serialization::serializer for ebml::writer {
|
|||
// try and check failures more quickly.
|
||||
if debug { self.wr_tagged_str(es_label as uint, label) }
|
||||
}
|
||||
}
|
||||
|
||||
impl serializer of serialization::serializer for ebml::writer {
|
||||
fn emit_nil() {}
|
||||
|
||||
fn emit_uint(v: uint) { self.wr_tagged_u64(es_uint as uint, v as u64); }
|
||||
fn emit_u64(v: u64) { self.wr_tagged_u64(es_u64 as uint, v); }
|
||||
|
|
@ -383,14 +394,18 @@ impl serializer of serialization::serializer for ebml::writer {
|
|||
fn emit_tup_elt(_idx: uint, f: fn()) { f() }
|
||||
}
|
||||
|
||||
type ebml_deserializer = {mut parent: ebml::doc,
|
||||
mut pos: uint};
|
||||
type ebml_deserializer_ = {mut parent: ebml::doc,
|
||||
mut pos: uint};
|
||||
|
||||
fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer {
|
||||
{mut parent: d, mut pos: d.start}
|
||||
enum ebml_deserializer {
|
||||
ebml_deserializer_(ebml_deserializer_)
|
||||
}
|
||||
|
||||
impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer {
|
||||
ebml_deserializer_({mut parent: d, mut pos: d.start})
|
||||
}
|
||||
|
||||
impl deserializer_priv for ebml_deserializer {
|
||||
fn _check_label(lbl: ~str) {
|
||||
if self.pos < self.parent.end {
|
||||
let {tag: r_tag, doc: r_doc} =
|
||||
|
|
@ -443,7 +458,9 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
|
|||
#debug["_next_uint exp_tag=%? result=%?", exp_tag, r];
|
||||
ret r as uint;
|
||||
}
|
||||
}
|
||||
|
||||
impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
fn read_nil() -> () { () }
|
||||
|
||||
fn read_u64() -> u64 { ebml::doc_as_u64(self.next_doc(es_u64)) }
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import io;
|
|||
import io::{reader_util, writer_util};
|
||||
import map;
|
||||
import map::hashmap;
|
||||
import map::map;
|
||||
import core::vec::extensions;
|
||||
|
||||
export json;
|
||||
|
|
@ -114,13 +115,17 @@ fn to_str(j: json) -> ~str {
|
|||
io::with_str_writer(|wr| to_writer(wr, j))
|
||||
}
|
||||
|
||||
type parser = {
|
||||
type parser_ = {
|
||||
rdr: io::reader,
|
||||
mut ch: char,
|
||||
mut line: uint,
|
||||
mut col: uint,
|
||||
};
|
||||
|
||||
enum parser {
|
||||
parser_(parser_)
|
||||
}
|
||||
|
||||
impl parser for parser {
|
||||
fn eof() -> bool { self.ch == -1 as char }
|
||||
|
||||
|
|
@ -463,12 +468,12 @@ impl parser for parser {
|
|||
|
||||
/// Deserializes a json value from an io::reader
|
||||
fn from_reader(rdr: io::reader) -> result<json, error> {
|
||||
let parser = {
|
||||
let parser = parser_({
|
||||
rdr: rdr,
|
||||
mut ch: rdr.read_char(),
|
||||
mut line: 1u,
|
||||
mut col: 1u,
|
||||
};
|
||||
});
|
||||
|
||||
parser.parse()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,13 +92,19 @@ mod chained {
|
|||
absent
|
||||
}
|
||||
|
||||
type t<K, V> = @{
|
||||
type hashmap__<K, V> = {
|
||||
mut count: uint,
|
||||
mut chains: ~[mut chain<K,V>],
|
||||
hasher: hashfn<K>,
|
||||
eqer: eqfn<K>
|
||||
};
|
||||
|
||||
enum hashmap_<K, V> {
|
||||
hashmap_(@hashmap__<K, V>)
|
||||
}
|
||||
|
||||
type t<K, V> = hashmap_<K, V>;
|
||||
|
||||
enum search_result<K, V> {
|
||||
not_found,
|
||||
found_first(uint, @entry<K,V>),
|
||||
|
|
@ -284,10 +290,10 @@ mod chained {
|
|||
}
|
||||
|
||||
fn mk<K, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> t<K,V> {
|
||||
let slf: t<K, V> = @{mut count: 0u,
|
||||
mut chains: chains(initial_capacity),
|
||||
hasher: hasher,
|
||||
eqer: eqer};
|
||||
let slf: t<K, V> = hashmap_(@{mut count: 0u,
|
||||
mut chains: chains(initial_capacity),
|
||||
hasher: hasher,
|
||||
eqer: eqer});
|
||||
slf
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,12 @@ mod v4 {
|
|||
// the simple, old style numberic representation of
|
||||
// ipv4
|
||||
type ipv4_rep = { a: u8, b: u8, c: u8, d:u8 };
|
||||
impl x for ipv4_rep {
|
||||
|
||||
trait as_unsafe_u32 {
|
||||
unsafe fn as_u32() -> u32;
|
||||
}
|
||||
|
||||
impl x of as_unsafe_u32 for ipv4_rep {
|
||||
// this is pretty dastardly, i know
|
||||
unsafe fn as_u32() -> u32 {
|
||||
*((ptr::addr_of(self)) as *u32)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import future::extensions;
|
|||
import result::*;
|
||||
import libc::size_t;
|
||||
import str::extensions;
|
||||
import io::{reader, writer};
|
||||
|
||||
// tcp interfaces
|
||||
export tcp_socket;
|
||||
|
|
|
|||
|
|
@ -101,13 +101,21 @@ fn read_to_vec<D: deserializer, T: copy>(d: D, f: fn() -> T) -> ~[T] {
|
|||
}
|
||||
}
|
||||
|
||||
impl serializer_helpers<S: serializer> for S {
|
||||
trait serializer_helpers {
|
||||
fn emit_from_vec<T>(v: ~[T], f: fn(T));
|
||||
}
|
||||
|
||||
impl serializer_helpers<S: serializer> of serializer_helpers for S {
|
||||
fn emit_from_vec<T>(v: ~[T], f: fn(T)) {
|
||||
emit_from_vec(self, v, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl deserializer_helpers<D: deserializer> for D {
|
||||
trait deserializer_helpers {
|
||||
fn read_to_vec<T: copy>(f: fn() -> T) -> ~[T];
|
||||
}
|
||||
|
||||
impl deserializer_helpers<D: deserializer> of deserializer_helpers for D {
|
||||
fn read_to_vec<T: copy>(f: fn() -> T) -> ~[T] {
|
||||
read_to_vec(self, f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,19 @@
|
|||
import core::option;
|
||||
import core::option::{some, none};
|
||||
import dvec::{dvec, extensions};
|
||||
import map::map;
|
||||
|
||||
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
|
||||
// requires this to be.
|
||||
type smallintmap<T: copy> = @{v: dvec<option<T>>};
|
||||
type smallintmap_<T: copy> = {v: dvec<option<T>>};
|
||||
|
||||
enum smallintmap<T:copy> {
|
||||
smallintmap_(@smallintmap_<T>)
|
||||
}
|
||||
|
||||
/// Create a smallintmap
|
||||
fn mk<T: copy>() -> smallintmap<T> {
|
||||
ret @{v: dvec()};
|
||||
ret smallintmap_(@{v: dvec()});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ fn tzset() {
|
|||
rustrt::rust_tzset();
|
||||
}
|
||||
|
||||
type tm = {
|
||||
type tm_ = {
|
||||
tm_sec: i32, // seconds after the minute ~[0-60]
|
||||
tm_min: i32, // minutes after the hour ~[0-59]
|
||||
tm_hour: i32, // hours after midnight ~[0-23]
|
||||
|
|
@ -80,8 +80,12 @@ type tm = {
|
|||
tm_nsec: i32, // nanoseconds
|
||||
};
|
||||
|
||||
enum tm {
|
||||
tm_(tm_)
|
||||
}
|
||||
|
||||
fn empty_tm() -> tm {
|
||||
{
|
||||
tm_({
|
||||
tm_sec: 0_i32,
|
||||
tm_min: 0_i32,
|
||||
tm_hour: 0_i32,
|
||||
|
|
@ -94,7 +98,7 @@ fn empty_tm() -> tm {
|
|||
tm_gmtoff: 0_i32,
|
||||
tm_zone: ~"",
|
||||
tm_nsec: 0_i32,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the specified time in UTC
|
||||
|
|
@ -563,7 +567,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
|
|||
}
|
||||
|
||||
if pos == len && rdr.eof() {
|
||||
ok({
|
||||
ok(tm_({
|
||||
tm_sec: tm.tm_sec,
|
||||
tm_min: tm.tm_min,
|
||||
tm_hour: tm.tm_hour,
|
||||
|
|
@ -576,7 +580,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
|
|||
tm_gmtoff: tm.tm_gmtoff,
|
||||
tm_zone: tm.tm_zone,
|
||||
tm_nsec: tm.tm_nsec,
|
||||
})
|
||||
}))
|
||||
} else { result }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue