Skip to content

libstd: Remove "dual impls" from the language and enforce coherence rule... #4640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ with destructors.
#[forbid(deprecated_pattern)];

use cast;
use container::{Container, Mutable, Map, Set};
use io;
use libc::{size_t, uintptr_t};
use option::{None, Option, Some};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use cmp::Eq;
use hash::Hash;
use prelude::*;
use to_bytes::IterBytes;

/// Open addressing with linear probing.
Expand Down Expand Up @@ -498,6 +497,7 @@ pub mod linear {

#[test]
pub mod test {
use container::{Container, Mutable, Map, Set};
use option::{None, Some};
use hashmap::linear::LinearMap;
use hashmap::linear;
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub trait Num {
static pure fn from_int(n: int) -> self;
}

pub trait IntConvertible {
pure fn to_int(&self) -> int;
static pure fn from_int(n: int) -> self;
}

pub trait Zero {
static pure fn zero() -> self;
}
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ use either::{Either, Left, Right};
use kinds::Owned;
use libc;
use option;
use option::unwrap;
use option::{None, Option, Some, unwrap};
use pipes;
use ptr;
use prelude::*;
use private;
use task;
use vec;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
pub use container::{Container, Mutable, Map, Set};
pub use pipes::{GenericChan, GenericPort};

pub use num::Num;
pub use ptr::Ptr;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use libc;
use oldcomm;
use option;
use result::Result;
use pipes::{stream, Chan, Port};
use pipes::{stream, Chan, GenericChan, GenericPort, Port};
use pipes;
use prelude::*;
use ptr;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@
#[warn(deprecated_mode)];

use cast;
use container::Map;
use oldcomm;
use option;
use pipes::{Chan, Port};
use pipes::{Chan, GenericChan, GenericPort, Port};
use pipes;
use prelude::*;
use private;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use core::to_bytes::IterBytes;
use core::uint;
use core::vec;
use std::map::HashMap;
use std::serialize::Encodable;
use std::{ebml, map};
use std;
use syntax::ast::*;
Expand Down
23 changes: 13 additions & 10 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
use core::prelude::*;

use middle::ty;
use middle::ty::{FnTyBase, FnMeta, FnSig};
use middle::ty::{FnTyBase, FnMeta, FnSig, arg, creader_cache_key, field};
use middle::ty::{substs};

use core::io;
use core::str;
Expand Down Expand Up @@ -174,9 +175,11 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs {
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
st.pos = st.pos + 1u;

return {self_r: self_r,
self_ty: self_ty,
tps: params};
return substs {
self_r: self_r,
self_ty: self_ty,
tps: params
};
}

fn parse_bound_region(st: @pstate) -> ty::bound_region {
Expand Down Expand Up @@ -308,7 +311,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
let mut fields: ~[ty::field] = ~[];
while peek(st) != ']' {
let name = st.tcx.sess.ident_of(parse_str(st, '='));
fields.push({ident: name, mt: parse_mt(st, conv)});
fields.push(ty::field { ident: name, mt: parse_mt(st, conv) });
}
st.pos = st.pos + 1u;
return ty::mk_rec(st.tcx, fields);
Expand Down Expand Up @@ -336,12 +339,13 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
assert (next(st) == ':');
let len = parse_hex(st);
assert (next(st) == '#');
match st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
let key = creader_cache_key { cnum: st.crate, pos: pos, len: len };
match st.tcx.rcache.find(key) {
Some(tt) => return tt,
None => {
let ps = @{pos: pos ,.. copy *st};
let tt = parse_ty(ps, conv);
st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
st.tcx.rcache.insert(key, tt);
return tt;
}
}
Expand Down Expand Up @@ -424,8 +428,7 @@ fn parse_onceness(c: char) -> ast::Onceness {
}

fn parse_arg(st: @pstate, conv: conv_did) -> ty::arg {
{mode: parse_mode(st),
ty: parse_ty(st, conv)}
ty::arg { mode: parse_mode(st), ty: parse_ty(st, conv) }
}

fn parse_mode(st: @pstate) -> ast::mode {
Expand All @@ -449,7 +452,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
let mut inputs: ~[ty::arg] = ~[];
while peek(st) != ']' {
let mode = parse_mode(st);
inputs.push({mode: mode, ty: parse_ty(st, conv)});
inputs.push(ty::arg { mode: mode, ty: parse_ty(st, conv) });
}
st.pos += 1u; // eat the ']'
let ret_ty = parse_ty(st, conv);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

use core::prelude::*;

use middle::ty::{Vid, param_ty};
use middle::ty;
use middle::ty::Vid;

use core::io::WriterUtil;
use core::io;
Expand Down Expand Up @@ -312,7 +312,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
w.write_char('F');
w.write_uint(id.to_uint());
}
ty::ty_param({idx: id, def_id: did}) => {
ty::ty_param(param_ty {idx: id, def_id: did}) => {
w.write_char('p');
w.write_str((cx.ds)(did));
w.write_char('|');
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use core::prelude::*;

use middle::borrowck::{Loan, bckerr, borrowck_ctxt, cmt, inherent_mutability};
use middle::borrowck::{req_maps, save_and_restore};
use middle::borrowck::{req_maps, root_map_key, save_and_restore};
use middle::mem_categorization::{cat_arg, cat_binding, cat_comp, cat_deref};
use middle::mem_categorization::{cat_local, cat_rvalue, cat_self};
use middle::mem_categorization::{cat_special, gc_ptr, loan_path, lp_arg};
Expand Down Expand Up @@ -396,7 +396,10 @@ impl check_loan_ctxt {

match ptr_kind {
gc_ptr(ast::m_mutbl) => {
let key = { id: base.id, derefs: deref_count };
let key = root_map_key {
id: base.id,
derefs: deref_count
};
self.bccx.write_guard_map.insert(key, ());
}
_ => {}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use core::prelude::*;

use middle::borrowck::preserve::{preserve_condition, pc_ok, pc_if_pure};
use middle::borrowck::{Loan, bckres, borrowck_ctxt, err_mutbl, req_maps};
use middle::borrowck::{Loan, bckerr, bckres, borrowck_ctxt, err_mutbl};
use middle::borrowck::{req_maps};
use middle::mem_categorization::{cat_binding, cat_discr, cmt, comp_variant};
use middle::mem_categorization::{mem_categorization_ctxt};
use middle::mem_categorization::{opt_deref_kind};
Expand Down Expand Up @@ -452,8 +453,7 @@ impl gather_loan_ctxt {
debug!("required is const or they are the same");
Ok(pc_ok)
} else {
let e = {cmt: cmt,
code: err_mutbl(req_mutbl)};
let e = bckerr { cmt: cmt, code: err_mutbl(req_mutbl) };
if req_mutbl == m_imm {
// if this is an @mut box, then it's generally OK to borrow as
// &imm; this will result in a write guard
Expand Down
15 changes: 9 additions & 6 deletions src/librustc/middle/borrowck/loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use core::prelude::*;

use middle::borrowck::{Loan, bckres, borrowck_ctxt, cmt, err_mutbl};
use middle::borrowck::{Loan, bckerr, bckres, borrowck_ctxt, cmt, err_mutbl};
use middle::borrowck::{err_out_of_scope};
use middle::mem_categorization::{cat_arg, cat_binding, cat_discr, cat_comp};
use middle::mem_categorization::{cat_deref, cat_discr, cat_local, cat_self};
Expand Down Expand Up @@ -72,8 +72,10 @@ impl LoanContext {
// We do not allow non-mutable data to be loaned
// out as mutable under any circumstances.
if cmt.mutbl != m_mutbl {
return Err({cmt:cmt,
code:err_mutbl(req_mutbl)});
return Err(bckerr {
cmt: cmt,
code: err_mutbl(req_mutbl)
});
}
}
m_const | m_imm => {
Expand All @@ -95,9 +97,10 @@ impl LoanContext {
} else {
// The loan being requested lives longer than the data
// being loaned out!
return Err({cmt:cmt,
code:err_out_of_scope(scope_ub,
self.scope_region)});
return Err(bckerr {
cmt: cmt,
code: err_out_of_scope(scope_ub, self.scope_region)
});
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ type root_map = HashMap<root_map_key, RootInfo>;
// if you have an expression `x.f` and x has type ~@T, we could add an
// entry {id:x, derefs:0} to refer to `x` itself, `{id:x, derefs:1}`
// to refer to the deref of the unique pointer, and so on.
type root_map_key = {id: ast::node_id, derefs: uint};
#[deriving_eq]
struct root_map_key {
id: ast::node_id,
derefs: uint
}

// set of ids of local vars / formal arguments that are modified / moved.
// this is used in trans for optimization purposes.
Expand Down Expand Up @@ -411,13 +415,10 @@ impl bckerr_code : cmp::Eq {

// Combination of an error code and the categorization of the expression
// that caused it
type bckerr = {cmt: cmt, code: bckerr_code};

impl bckerr : cmp::Eq {
pure fn eq(&self, other: &bckerr) -> bool {
(*self).cmt == (*other).cmt && (*self).code == (*other).code
}
pure fn ne(&self, other: &bckerr) -> bool { !(*self).eq(other) }
#[deriving_eq]
struct bckerr {
cmt: cmt,
code: bckerr_code
}

// shorthand for something that fails with `bckerr` or succeeds with `T`
Expand Down Expand Up @@ -446,15 +447,6 @@ fn save_and_restore<T:Copy,U>(save_and_restore_t: &mut T, f: fn() -> U) -> U {

/// Creates and returns a new root_map

impl root_map_key : cmp::Eq {
pure fn eq(&self, other: &root_map_key) -> bool {
(*self).id == (*other).id && (*self).derefs == (*other).derefs
}
pure fn ne(&self, other: &root_map_key) -> bool {
! ((*self) == (*other))
}
}

impl root_map_key : to_bytes::IterBytes {
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.id, &self.derefs, lsb0, f);
Expand Down Expand Up @@ -501,7 +493,7 @@ impl borrowck_ctxt {
}

fn cat_discr(cmt: cmt, match_id: ast::node_id) -> cmt {
return @{cat:cat_discr(cmt, match_id),.. *cmt};
return @cmt_ { cat: cat_discr(cmt, match_id),.. *cmt };
}

fn cat_pattern(cmt: cmt, pat: @ast::pat, op: fn(cmt, @ast::pat)) {
Expand Down
29 changes: 17 additions & 12 deletions src/librustc/middle/borrowck/preserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::prelude::*;
use middle::borrowck::{RootInfo, bckerr, bckerr_code, bckres, borrowck_ctxt};
use middle::borrowck::{cmt, err_mut_uniq, err_mut_variant};
use middle::borrowck::{err_out_of_root_scope, err_out_of_scope};
use middle::borrowck::{err_root_not_permitted};
use middle::borrowck::{err_root_not_permitted, root_map_key};
use middle::mem_categorization::{cat_arg, cat_binding, cat_comp, cat_deref};
use middle::mem_categorization::{cat_discr, cat_local, cat_self, cat_special};
use middle::mem_categorization::{cat_stack_upvar, comp_field, comp_index};
Expand Down Expand Up @@ -291,7 +291,7 @@ priv impl &preserve_ctxt {
Ok(pc_ok) => {
match cmt_base.mutbl {
m_mutbl | m_const => {
Ok(pc_if_pure({cmt:cmt, code:code}))
Ok(pc_if_pure(bckerr { cmt: cmt, code: code }))
}
m_imm => {
Ok(pc_ok)
Expand All @@ -318,8 +318,10 @@ priv impl &preserve_ctxt {
if self.bccx.is_subregion_of(self.scope_region, scope_ub) {
Ok(pc_ok)
} else {
Err({cmt:cmt, code:err_out_of_scope(scope_ub,
self.scope_region)})
Err(bckerr {
cmt:cmt,
code:err_out_of_scope(scope_ub, self.scope_region)
})
}
}

Expand All @@ -345,7 +347,7 @@ priv impl &preserve_ctxt {
// would be sort of pointless to avoid rooting the inner
// box by rooting an outer box, as it would just keep more
// memory live than necessary, so we set root_ub to none.
return Err({cmt:cmt, code:err_root_not_permitted});
return Err(bckerr { cmt: cmt, code: err_root_not_permitted });
}

let root_region = ty::re_scope(self.root_ub);
Expand All @@ -359,7 +361,7 @@ priv impl &preserve_ctxt {
derefs, scope_id, self.root_ub);
if self.bccx.is_subregion_of(self.scope_region, root_region) {
debug!("Elected to root");
let rk = {id: base.id, derefs: derefs};
let rk = root_map_key { id: base.id, derefs: derefs };
// This code could potentially lead cause boxes to be frozen
// for longer than necessarily at runtime. It prevents an
// ICE in trans; the fundamental problem is that it's hard
Expand Down Expand Up @@ -389,17 +391,20 @@ priv impl &preserve_ctxt {
return Ok(pc_ok);
} else {
debug!("Unable to root");
return Err({cmt:cmt,
code:err_out_of_root_scope(root_region,
self.scope_region)});
return Err(bckerr {
cmt: cmt,
code: err_out_of_root_scope(root_region,
self.scope_region)
});
}
}

// we won't be able to root long enough
_ => {
return Err({cmt:cmt,
code:err_out_of_root_scope(root_region,
self.scope_region)});
return Err(bckerr {
cmt:cmt,
code:err_out_of_root_scope(root_region, self.scope_region)
});
}

}
Expand Down
Loading