auto merge of #5051 : bstrie/rust/deimpself, r=pcwalton

With the exception of three places where explicit self ran into borrowing errors. Will try those again once borrowing is refined.
This commit is contained in:
bors 2013-02-22 10:24:43 -08:00
commit ba7a870660
26 changed files with 624 additions and 567 deletions

View File

@ -165,49 +165,49 @@ pub struct Session_ {
pub type Session = @Session_; pub type Session = @Session_;
pub impl Session { pub impl Session {
fn span_fatal(sp: span, msg: ~str) -> ! { fn span_fatal(&self, sp: span, msg: ~str) -> ! {
self.span_diagnostic.span_fatal(sp, msg) self.span_diagnostic.span_fatal(sp, msg)
} }
fn fatal(msg: ~str) -> ! { fn fatal(&self, msg: ~str) -> ! {
self.span_diagnostic.handler().fatal(msg) self.span_diagnostic.handler().fatal(msg)
} }
fn span_err(sp: span, msg: ~str) { fn span_err(&self, sp: span, msg: ~str) {
self.span_diagnostic.span_err(sp, msg) self.span_diagnostic.span_err(sp, msg)
} }
fn err(msg: ~str) { fn err(&self, msg: ~str) {
self.span_diagnostic.handler().err(msg) self.span_diagnostic.handler().err(msg)
} }
fn has_errors() -> bool { fn has_errors(&self) -> bool {
self.span_diagnostic.handler().has_errors() self.span_diagnostic.handler().has_errors()
} }
fn abort_if_errors() { fn abort_if_errors(&self) {
self.span_diagnostic.handler().abort_if_errors() self.span_diagnostic.handler().abort_if_errors()
} }
fn span_warn(sp: span, msg: ~str) { fn span_warn(&self, sp: span, msg: ~str) {
self.span_diagnostic.span_warn(sp, msg) self.span_diagnostic.span_warn(sp, msg)
} }
fn warn(msg: ~str) { fn warn(&self, msg: ~str) {
self.span_diagnostic.handler().warn(msg) self.span_diagnostic.handler().warn(msg)
} }
fn span_note(sp: span, msg: ~str) { fn span_note(&self, sp: span, msg: ~str) {
self.span_diagnostic.span_note(sp, msg) self.span_diagnostic.span_note(sp, msg)
} }
fn note(msg: ~str) { fn note(&self, msg: ~str) {
self.span_diagnostic.handler().note(msg) self.span_diagnostic.handler().note(msg)
} }
fn span_bug(sp: span, msg: ~str) -> ! { fn span_bug(&self, sp: span, msg: ~str) -> ! {
self.span_diagnostic.span_bug(sp, msg) self.span_diagnostic.span_bug(sp, msg)
} }
fn bug(msg: ~str) -> ! { fn bug(&self, msg: ~str) -> ! {
self.span_diagnostic.handler().bug(msg) self.span_diagnostic.handler().bug(msg)
} }
fn span_unimpl(sp: span, msg: ~str) -> ! { fn span_unimpl(&self, sp: span, msg: ~str) -> ! {
self.span_diagnostic.span_unimpl(sp, msg) self.span_diagnostic.span_unimpl(sp, msg)
} }
fn unimpl(msg: ~str) -> ! { fn unimpl(&self, msg: ~str) -> ! {
self.span_diagnostic.handler().unimpl(msg) self.span_diagnostic.handler().unimpl(msg)
} }
fn span_lint_level(level: lint::level, sp: span, +msg: ~str) { fn span_lint_level(&self, level: lint::level, sp: span, +msg: ~str) {
match level { match level {
lint::allow => { }, lint::allow => { },
lint::warn => self.span_warn(sp, msg), lint::warn => self.span_warn(sp, msg),
@ -216,7 +216,7 @@ pub impl Session {
} }
} }
} }
fn span_lint(lint_mode: lint::lint, fn span_lint(&self, lint_mode: lint::lint,
expr_id: ast::node_id, expr_id: ast::node_id,
item_id: ast::node_id, item_id: ast::node_id,
span: span, span: span,
@ -225,45 +225,55 @@ pub impl Session {
self.lint_settings, lint_mode, expr_id, item_id); self.lint_settings, lint_mode, expr_id, item_id);
self.span_lint_level(level, span, msg); self.span_lint_level(level, span, msg);
} }
fn next_node_id() -> ast::node_id { fn next_node_id(&self) -> ast::node_id {
return syntax::parse::next_node_id(self.parse_sess); return syntax::parse::next_node_id(self.parse_sess);
} }
fn diagnostic() -> diagnostic::span_handler { fn diagnostic(&self) -> diagnostic::span_handler {
self.span_diagnostic self.span_diagnostic
} }
fn debugging_opt(opt: uint) -> bool { fn debugging_opt(&self, opt: uint) -> bool {
(self.opts.debugging_opts & opt) != 0u (self.opts.debugging_opts & opt) != 0u
} }
// This exists to help with refactoring to eliminate impossible // This exists to help with refactoring to eliminate impossible
// cases later on // cases later on
fn impossible_case(sp: span, msg: &str) -> ! { fn impossible_case(&self, sp: span, msg: &str) -> ! {
self.span_bug(sp, fmt!("Impossible case reached: %s", msg)); self.span_bug(sp, fmt!("Impossible case reached: %s", msg));
} }
fn verbose() -> bool { self.debugging_opt(verbose) } fn verbose(&self) -> bool { self.debugging_opt(verbose) }
fn time_passes() -> bool { self.debugging_opt(time_passes) } fn time_passes(&self) -> bool { self.debugging_opt(time_passes) }
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) } fn count_llvm_insns(&self) -> bool {
fn count_type_sizes() -> bool { self.debugging_opt(count_type_sizes) } self.debugging_opt(count_llvm_insns)
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) } }
fn trans_stats() -> bool { self.debugging_opt(trans_stats) } fn count_type_sizes(&self) -> bool {
fn meta_stats() -> bool { self.debugging_opt(meta_stats) } self.debugging_opt(count_type_sizes)
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) } }
fn no_verify() -> bool { self.debugging_opt(no_verify) } fn time_llvm_passes(&self) -> bool {
fn trace() -> bool { self.debugging_opt(trace) } self.debugging_opt(time_llvm_passes)
fn coherence() -> bool { self.debugging_opt(coherence) } }
fn borrowck_stats() -> bool { self.debugging_opt(borrowck_stats) } fn trans_stats(&self) -> bool { self.debugging_opt(trans_stats) }
fn borrowck_note_pure() -> bool { self.debugging_opt(borrowck_note_pure) } fn meta_stats(&self) -> bool { self.debugging_opt(meta_stats) }
fn borrowck_note_loan() -> bool { self.debugging_opt(borrowck_note_loan) } fn no_asm_comments(&self) -> bool { self.debugging_opt(no_asm_comments) }
fn no_monomorphic_collapse() -> bool { fn no_verify(&self) -> bool { self.debugging_opt(no_verify) }
fn trace(&self) -> bool { self.debugging_opt(trace) }
fn coherence(&self) -> bool { self.debugging_opt(coherence) }
fn borrowck_stats(&self) -> bool { self.debugging_opt(borrowck_stats) }
fn borrowck_note_pure(&self) -> bool {
self.debugging_opt(borrowck_note_pure)
}
fn borrowck_note_loan(&self) -> bool {
self.debugging_opt(borrowck_note_loan)
}
fn no_monomorphic_collapse(&self) -> bool {
self.debugging_opt(no_monomorphic_collapse) self.debugging_opt(no_monomorphic_collapse)
} }
fn str_of(id: ast::ident) -> @~str { fn str_of(&self, id: ast::ident) -> @~str {
self.parse_sess.interner.get(id) self.parse_sess.interner.get(id)
} }
fn ident_of(+st: ~str) -> ast::ident { fn ident_of(&self, +st: ~str) -> ast::ident {
self.parse_sess.interner.intern(@st) self.parse_sess.interner.intern(@st)
} }
fn intr() -> @syntax::parse::token::ident_interner { fn intr(&self) -> @syntax::parse::token::ident_interner {
self.parse_sess.interner self.parse_sess.interner
} }
} }

View File

@ -29,10 +29,10 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
} }
pub trait FileSearch { pub trait FileSearch {
fn sysroot() -> Path; fn sysroot(&self) -> Path;
fn lib_search_paths() -> ~[Path]; fn lib_search_paths(&self) -> ~[Path];
fn get_target_lib_path() -> Path; fn get_target_lib_path(&self) -> Path;
fn get_target_lib_file_path(file: &Path) -> Path; fn get_target_lib_file_path(&self, file: &Path) -> Path;
} }
pub fn mk_filesearch(maybe_sysroot: Option<Path>, pub fn mk_filesearch(maybe_sysroot: Option<Path>,
@ -44,8 +44,8 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
target_triple: ~str target_triple: ~str
} }
impl FileSearch for FileSearchImpl { impl FileSearch for FileSearchImpl {
fn sysroot() -> Path { /*bad*/copy self.sysroot } fn sysroot(&self) -> Path { /*bad*/copy self.sysroot }
fn lib_search_paths() -> ~[Path] { fn lib_search_paths(&self) -> ~[Path] {
let mut paths = /*bad*/copy self.addl_lib_search_paths; let mut paths = /*bad*/copy self.addl_lib_search_paths;
paths.push( paths.push(
@ -61,10 +61,10 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
} }
paths paths
} }
fn get_target_lib_path() -> Path { fn get_target_lib_path(&self) -> Path {
make_target_lib_path(&self.sysroot, self.target_triple) make_target_lib_path(&self.sysroot, self.target_triple)
} }
fn get_target_lib_file_path(file: &Path) -> Path { fn get_target_lib_file_path(&self, file: &Path) -> Path {
self.get_target_lib_path().push_rel(file) self.get_target_lib_path().push_rel(file)
} }
} }

View File

@ -75,11 +75,11 @@ struct ExtendedDecodeContext {
} }
trait tr { trait tr {
fn tr(xcx: @ExtendedDecodeContext) -> Self; fn tr(&self, xcx: @ExtendedDecodeContext) -> Self;
} }
trait tr_intern { trait tr_intern {
fn tr_intern(xcx: @ExtendedDecodeContext) -> ast::def_id; fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id;
} }
// ______________________________________________________________________ // ______________________________________________________________________
@ -227,41 +227,41 @@ impl ExtendedDecodeContext {
} }
impl tr_intern for ast::def_id { impl tr_intern for ast::def_id {
fn tr_intern(xcx: @ExtendedDecodeContext) -> ast::def_id { fn tr_intern(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
xcx.tr_intern_def_id(self) xcx.tr_intern_def_id(*self)
} }
} }
impl tr for ast::def_id { impl tr for ast::def_id {
fn tr(xcx: @ExtendedDecodeContext) -> ast::def_id { fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
xcx.tr_def_id(self) xcx.tr_def_id(*self)
} }
} }
impl tr for span { impl tr for span {
fn tr(xcx: @ExtendedDecodeContext) -> span { fn tr(&self, xcx: @ExtendedDecodeContext) -> span {
xcx.tr_span(self) xcx.tr_span(*self)
} }
} }
trait def_id_encoder_helpers { trait def_id_encoder_helpers {
fn emit_def_id(did: ast::def_id); fn emit_def_id(&self, did: ast::def_id);
} }
impl<S:serialize::Encoder> def_id_encoder_helpers for S { impl<S:serialize::Encoder> def_id_encoder_helpers for S {
fn emit_def_id(did: ast::def_id) { fn emit_def_id(&self, did: ast::def_id) {
did.encode(&self) did.encode(self)
} }
} }
trait def_id_decoder_helpers { trait def_id_decoder_helpers {
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id; fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> ast::def_id;
} }
impl<D:serialize::Decoder> def_id_decoder_helpers for D { impl<D:serialize::Decoder> def_id_decoder_helpers for D {
fn read_def_id(xcx: @ExtendedDecodeContext) -> ast::def_id { fn read_def_id(&self, xcx: @ExtendedDecodeContext) -> ast::def_id {
let did: ast::def_id = Decodable::decode(&self); let did: ast::def_id = Decodable::decode(self);
did.tr(xcx) did.tr(xcx)
} }
} }
@ -405,8 +405,8 @@ fn decode_def(xcx: @ExtendedDecodeContext, doc: ebml::Doc) -> ast::def {
} }
impl tr for ast::def { impl tr for ast::def {
fn tr(xcx: @ExtendedDecodeContext) -> ast::def { fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def {
match self { match *self {
ast::def_fn(did, p) => { ast::def_fn(did.tr(xcx), p) } ast::def_fn(did, p) => { ast::def_fn(did.tr(xcx), p) }
ast::def_static_method(did, did2_opt, p) => { ast::def_static_method(did, did2_opt, p) => {
ast::def_static_method(did.tr(xcx), ast::def_static_method(did.tr(xcx),
@ -450,7 +450,7 @@ impl tr for ast::def {
// Encoding and decoding of adjustment information // Encoding and decoding of adjustment information
impl tr for ty::AutoAdjustment { impl tr for ty::AutoAdjustment {
fn tr(xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment { fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment {
ty::AutoAdjustment { ty::AutoAdjustment {
autoderefs: self.autoderefs, autoderefs: self.autoderefs,
autoref: self.autoref.map(|ar| ar.tr(xcx)), autoref: self.autoref.map(|ar| ar.tr(xcx)),
@ -459,7 +459,7 @@ impl tr for ty::AutoAdjustment {
} }
impl tr for ty::AutoRef { impl tr for ty::AutoRef {
fn tr(xcx: @ExtendedDecodeContext) -> ty::AutoRef { fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoRef {
ty::AutoRef { ty::AutoRef {
kind: self.kind, kind: self.kind,
region: self.region.tr(xcx), region: self.region.tr(xcx),
@ -469,21 +469,21 @@ impl tr for ty::AutoRef {
} }
impl tr for ty::Region { impl tr for ty::Region {
fn tr(xcx: @ExtendedDecodeContext) -> ty::Region { fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::Region {
match self { match *self {
ty::re_bound(br) => ty::re_bound(br.tr(xcx)), ty::re_bound(br) => ty::re_bound(br.tr(xcx)),
ty::re_free(id, br) => ty::re_free(xcx.tr_id(id), br.tr(xcx)), ty::re_free(id, br) => ty::re_free(xcx.tr_id(id), br.tr(xcx)),
ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)), ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)),
ty::re_static | ty::re_infer(*) => self, ty::re_static | ty::re_infer(*) => *self,
} }
} }
} }
impl tr for ty::bound_region { impl tr for ty::bound_region {
fn tr(xcx: @ExtendedDecodeContext) -> ty::bound_region { fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::bound_region {
match self { match *self {
ty::br_anon(_) | ty::br_named(_) | ty::br_self | ty::br_anon(_) | ty::br_named(_) | ty::br_self |
ty::br_fresh(_) => self, ty::br_fresh(_) => *self,
ty::br_cap_avoid(id, br) => ty::br_cap_avoid(xcx.tr_id(id), ty::br_cap_avoid(id, br) => ty::br_cap_avoid(xcx.tr_id(id),
@br.tr(xcx)) @br.tr(xcx))
} }
@ -498,18 +498,20 @@ fn encode_freevar_entry(ebml_w: writer::Encoder, fv: @freevar_entry) {
} }
trait ebml_decoder_helper { trait ebml_decoder_helper {
fn read_freevar_entry(xcx: @ExtendedDecodeContext) -> freevar_entry; fn read_freevar_entry(&self, xcx: @ExtendedDecodeContext)
-> freevar_entry;
} }
impl ebml_decoder_helper for reader::Decoder { impl ebml_decoder_helper for reader::Decoder {
fn read_freevar_entry(xcx: @ExtendedDecodeContext) -> freevar_entry { fn read_freevar_entry(&self, xcx: @ExtendedDecodeContext)
let fv: freevar_entry = Decodable::decode(&self); -> freevar_entry {
let fv: freevar_entry = Decodable::decode(self);
fv.tr(xcx) fv.tr(xcx)
} }
} }
impl tr for freevar_entry { impl tr for freevar_entry {
fn tr(xcx: @ExtendedDecodeContext) -> freevar_entry { fn tr(&self, xcx: @ExtendedDecodeContext) -> freevar_entry {
freevar_entry { freevar_entry {
def: self.def.tr(xcx), def: self.def.tr(xcx),
span: self.span.tr(xcx), span: self.span.tr(xcx),
@ -521,18 +523,20 @@ impl tr for freevar_entry {
// Encoding and decoding of CaptureVar information // Encoding and decoding of CaptureVar information
trait capture_var_helper { trait capture_var_helper {
fn read_capture_var(xcx: @ExtendedDecodeContext) -> moves::CaptureVar; fn read_capture_var(&self, xcx: @ExtendedDecodeContext)
-> moves::CaptureVar;
} }
impl capture_var_helper for reader::Decoder { impl capture_var_helper for reader::Decoder {
fn read_capture_var(xcx: @ExtendedDecodeContext) -> moves::CaptureVar { fn read_capture_var(&self, xcx: @ExtendedDecodeContext)
let cvar: moves::CaptureVar = Decodable::decode(&self); -> moves::CaptureVar {
let cvar: moves::CaptureVar = Decodable::decode(self);
cvar.tr(xcx) cvar.tr(xcx)
} }
} }
impl tr for moves::CaptureVar { impl tr for moves::CaptureVar {
fn tr(xcx: @ExtendedDecodeContext) -> moves::CaptureVar { fn tr(&self, xcx: @ExtendedDecodeContext) -> moves::CaptureVar {
moves::CaptureVar { moves::CaptureVar {
def: self.def.tr(xcx), def: self.def.tr(xcx),
span: self.span.tr(xcx), span: self.span.tr(xcx),
@ -545,7 +549,8 @@ impl tr for moves::CaptureVar {
// Encoding and decoding of method_map_entry // Encoding and decoding of method_map_entry
trait read_method_map_entry_helper { trait read_method_map_entry_helper {
fn read_method_map_entry(xcx: @ExtendedDecodeContext) -> method_map_entry; fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
-> method_map_entry;
} }
fn encode_method_map_entry(ecx: @e::EncodeContext, fn encode_method_map_entry(ecx: @e::EncodeContext,
@ -565,7 +570,7 @@ fn encode_method_map_entry(ecx: @e::EncodeContext,
} }
impl read_method_map_entry_helper for reader::Decoder { impl read_method_map_entry_helper for reader::Decoder {
fn read_method_map_entry(xcx: @ExtendedDecodeContext) fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
-> method_map_entry { -> method_map_entry {
do self.read_rec { do self.read_rec {
method_map_entry { method_map_entry {
@ -573,12 +578,12 @@ impl read_method_map_entry_helper for reader::Decoder {
self.read_arg(xcx) self.read_arg(xcx)
}), }),
explicit_self: self.read_field(~"explicit_self", 2u, || { explicit_self: self.read_field(~"explicit_self", 2u, || {
let self_type: ast::self_ty_ = Decodable::decode(&self); let self_type: ast::self_ty_ = Decodable::decode(self);
self_type self_type
}), }),
origin: self.read_field(~"origin", 1u, || { origin: self.read_field(~"origin", 1u, || {
let method_origin: method_origin = let method_origin: method_origin =
Decodable::decode(&self); Decodable::decode(self);
method_origin.tr(xcx) method_origin.tr(xcx)
}), }),
} }
@ -587,8 +592,8 @@ impl read_method_map_entry_helper for reader::Decoder {
} }
impl tr for method_origin { impl tr for method_origin {
fn tr(xcx: @ExtendedDecodeContext) -> method_origin { fn tr(&self, xcx: @ExtendedDecodeContext) -> method_origin {
match self { match *self {
typeck::method_static(did) => { typeck::method_static(did) => {
typeck::method_static(did.tr(xcx)) typeck::method_static(did.tr(xcx))
} }
@ -672,17 +677,19 @@ fn encode_vtable_origin(ecx: @e::EncodeContext,
} }
trait vtable_decoder_helpers { trait vtable_decoder_helpers {
fn read_vtable_res(xcx: @ExtendedDecodeContext) -> typeck::vtable_res; fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
fn read_vtable_origin(xcx: @ExtendedDecodeContext) -> typeck::vtable_res;
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin; -> typeck::vtable_origin;
} }
impl vtable_decoder_helpers for reader::Decoder { impl vtable_decoder_helpers for reader::Decoder {
fn read_vtable_res(xcx: @ExtendedDecodeContext) -> typeck::vtable_res { fn read_vtable_res(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_res {
@self.read_to_vec(|| self.read_vtable_origin(xcx) ) @self.read_to_vec(|| self.read_vtable_origin(xcx) )
} }
fn read_vtable_origin(xcx: @ExtendedDecodeContext) fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin { -> typeck::vtable_origin {
do self.read_enum(~"vtable_origin") { do self.read_enum(~"vtable_origin") {
do self.read_enum_variant |i| { do self.read_enum_variant |i| {
@ -736,6 +743,7 @@ trait get_ty_str_ctxt {
} }
impl get_ty_str_ctxt for @e::EncodeContext { impl get_ty_str_ctxt for @e::EncodeContext {
// IMPLICIT SELF WARNING: fix this!
fn ty_str_ctxt() -> @tyencode::ctxt { fn ty_str_ctxt() -> @tyencode::ctxt {
@tyencode::ctxt {diag: self.tcx.sess.diagnostic(), @tyencode::ctxt {diag: self.tcx.sess.diagnostic(),
ds: e::def_to_str, ds: e::def_to_str,
@ -746,46 +754,48 @@ impl get_ty_str_ctxt for @e::EncodeContext {
} }
trait ebml_writer_helpers { trait ebml_writer_helpers {
fn emit_arg(ecx: @e::EncodeContext, arg: ty::arg); fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg);
fn emit_ty(ecx: @e::EncodeContext, ty: ty::t); fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t);
fn emit_vstore(ecx: @e::EncodeContext, vstore: ty::vstore); fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore);
fn emit_tys(ecx: @e::EncodeContext, tys: ~[ty::t]); fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]);
fn emit_bounds(ecx: @e::EncodeContext, bs: ty::param_bounds); fn emit_bounds(&self, ecx: @e::EncodeContext, bs: ty::param_bounds);
fn emit_tpbt(ecx: @e::EncodeContext, tpbt: ty::ty_param_bounds_and_ty); fn emit_tpbt(&self, ecx: @e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
} }
impl ebml_writer_helpers for writer::Encoder { impl ebml_writer_helpers for writer::Encoder {
fn emit_ty(ecx: @e::EncodeContext, ty: ty::t) { fn emit_ty(&self, ecx: @e::EncodeContext, ty: ty::t) {
do self.emit_opaque { do self.emit_opaque {
e::write_type(ecx, self, ty) e::write_type(ecx, *self, ty)
} }
} }
fn emit_vstore(ecx: @e::EncodeContext, vstore: ty::vstore) { fn emit_vstore(&self, ecx: @e::EncodeContext, vstore: ty::vstore) {
do self.emit_opaque { do self.emit_opaque {
e::write_vstore(ecx, self, vstore) e::write_vstore(ecx, *self, vstore)
} }
} }
fn emit_arg(ecx: @e::EncodeContext, arg: ty::arg) { fn emit_arg(&self, ecx: @e::EncodeContext, arg: ty::arg) {
do self.emit_opaque { do self.emit_opaque {
tyencode::enc_arg(self.writer, ecx.ty_str_ctxt(), arg); tyencode::enc_arg(self.writer, ecx.ty_str_ctxt(), arg);
} }
} }
fn emit_tys(ecx: @e::EncodeContext, tys: ~[ty::t]) { fn emit_tys(&self, ecx: @e::EncodeContext, tys: ~[ty::t]) {
do self.emit_from_vec(tys) |ty| { do self.emit_from_vec(tys) |ty| {
self.emit_ty(ecx, *ty) self.emit_ty(ecx, *ty)
} }
} }
fn emit_bounds(ecx: @e::EncodeContext, bs: ty::param_bounds) { fn emit_bounds(&self, ecx: @e::EncodeContext, bs: ty::param_bounds) {
do self.emit_opaque { do self.emit_opaque {
tyencode::enc_bounds(self.writer, ecx.ty_str_ctxt(), bs) tyencode::enc_bounds(self.writer, ecx.ty_str_ctxt(), bs)
} }
} }
fn emit_tpbt(ecx: @e::EncodeContext, tpbt: ty::ty_param_bounds_and_ty) { fn emit_tpbt(&self, ecx: @e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty) {
do self.emit_rec { do self.emit_rec {
do self.emit_field(~"bounds", 0) { do self.emit_field(~"bounds", 0) {
do self.emit_from_vec(*tpbt.bounds) |bs| { do self.emit_from_vec(*tpbt.bounds) |bs| {
@ -793,7 +803,7 @@ impl ebml_writer_helpers for writer::Encoder {
} }
} }
do self.emit_field(~"region_param", 1u) { do self.emit_field(~"region_param", 1u) {
tpbt.region_param.encode(&self); tpbt.region_param.encode(self);
} }
do self.emit_field(~"ty", 2u) { do self.emit_field(~"ty", 2u) {
self.emit_ty(ecx, tpbt.ty); self.emit_ty(ecx, tpbt.ty);
@ -803,16 +813,16 @@ impl ebml_writer_helpers for writer::Encoder {
} }
trait write_tag_and_id { trait write_tag_and_id {
fn tag(tag_id: c::astencode_tag, f: fn()); fn tag(&self, tag_id: c::astencode_tag, f: fn());
fn id(id: ast::node_id); fn id(&self, id: ast::node_id);
} }
impl write_tag_and_id for writer::Encoder { impl write_tag_and_id for writer::Encoder {
fn tag(tag_id: c::astencode_tag, f: fn()) { fn tag(&self, tag_id: c::astencode_tag, f: fn()) {
do self.wr_tag(tag_id as uint) { f() } do self.wr_tag(tag_id as uint) { f() }
} }
fn id(id: ast::node_id) { fn id(&self, id: ast::node_id) {
self.wr_tagged_u64(c::tag_table_id as uint, id as u64) self.wr_tagged_u64(c::tag_table_id as uint, id as u64)
} }
} }
@ -981,31 +991,31 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
} }
trait doc_decoder_helpers { trait doc_decoder_helpers {
fn as_int() -> int; fn as_int(&self) -> int;
fn opt_child(tag: c::astencode_tag) -> Option<ebml::Doc>; fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc>;
} }
impl doc_decoder_helpers for ebml::Doc { impl doc_decoder_helpers for ebml::Doc {
fn as_int() -> int { reader::doc_as_u64(self) as int } fn as_int(&self) -> int { reader::doc_as_u64(*self) as int }
fn opt_child(tag: c::astencode_tag) -> Option<ebml::Doc> { fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc> {
reader::maybe_get_doc(self, tag as uint) reader::maybe_get_doc(*self, tag as uint)
} }
} }
trait ebml_decoder_decoder_helpers { trait ebml_decoder_decoder_helpers {
fn read_arg(xcx: @ExtendedDecodeContext) -> ty::arg; fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg;
fn read_ty(xcx: @ExtendedDecodeContext) -> ty::t; fn read_ty(&self, xcx: @ExtendedDecodeContext) -> ty::t;
fn read_tys(xcx: @ExtendedDecodeContext) -> ~[ty::t]; fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[ty::t];
fn read_bounds(xcx: @ExtendedDecodeContext) -> @~[ty::param_bound]; fn read_bounds(&self, xcx: @ExtendedDecodeContext) -> @~[ty::param_bound];
fn read_ty_param_bounds_and_ty(xcx: @ExtendedDecodeContext) fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty; -> ty::ty_param_bounds_and_ty;
fn convert_def_id(xcx: @ExtendedDecodeContext, fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
source: DefIdSource, source: DefIdSource,
did: ast::def_id) -> ast::def_id; did: ast::def_id) -> ast::def_id;
} }
impl ebml_decoder_decoder_helpers for reader::Decoder { impl ebml_decoder_decoder_helpers for reader::Decoder {
fn read_arg(xcx: @ExtendedDecodeContext) -> ty::arg { fn read_arg(&self, xcx: @ExtendedDecodeContext) -> ty::arg {
do self.read_opaque |doc| { do self.read_opaque |doc| {
tydecode::parse_arg_data( tydecode::parse_arg_data(
doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx, doc.data, xcx.dcx.cdata.cnum, doc.start, xcx.dcx.tcx,
@ -1013,7 +1023,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
} }
} }
fn read_ty(xcx: @ExtendedDecodeContext) -> ty::t { fn read_ty(&self, xcx: @ExtendedDecodeContext) -> ty::t {
// Note: regions types embed local node ids. In principle, we // Note: regions types embed local node ids. In principle, we
// should translate these node ids into the new decode // should translate these node ids into the new decode
// context. However, we do not bother, because region types // context. However, we do not bother, because region types
@ -1040,11 +1050,12 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
} }
} }
fn read_tys(xcx: @ExtendedDecodeContext) -> ~[ty::t] { fn read_tys(&self, xcx: @ExtendedDecodeContext) -> ~[ty::t] {
self.read_to_vec(|| self.read_ty(xcx) ) self.read_to_vec(|| self.read_ty(xcx) )
} }
fn read_bounds(xcx: @ExtendedDecodeContext) -> @~[ty::param_bound] { fn read_bounds(&self, xcx: @ExtendedDecodeContext)
-> @~[ty::param_bound] {
do self.read_opaque |doc| { do self.read_opaque |doc| {
tydecode::parse_bounds_data( tydecode::parse_bounds_data(
doc.data, doc.start, xcx.dcx.cdata.cnum, xcx.dcx.tcx, doc.data, doc.start, xcx.dcx.cdata.cnum, xcx.dcx.tcx,
@ -1052,7 +1063,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
} }
} }
fn read_ty_param_bounds_and_ty(xcx: @ExtendedDecodeContext) fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty -> ty::ty_param_bounds_and_ty
{ {
do self.read_rec { do self.read_rec {
@ -1061,7 +1072,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
@self.read_to_vec(|| self.read_bounds(xcx) ) @self.read_to_vec(|| self.read_bounds(xcx) )
}), }),
region_param: self.read_field(~"region_param", 1u, || { region_param: self.read_field(~"region_param", 1u, || {
Decodable::decode(&self) Decodable::decode(self)
}), }),
ty: self.read_field(~"ty", 2u, || { ty: self.read_field(~"ty", 2u, || {
self.read_ty(xcx) self.read_ty(xcx)
@ -1070,7 +1081,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
} }
} }
fn convert_def_id(xcx: @ExtendedDecodeContext, fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
source: tydecode::DefIdSource, source: tydecode::DefIdSource,
did: ast::def_id) -> ast::def_id { did: ast::def_id) -> ast::def_id {
/*! /*!
@ -1192,10 +1203,10 @@ fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
#[cfg(test)] #[cfg(test)]
trait fake_ext_ctxt { trait fake_ext_ctxt {
fn cfg() -> ast::crate_cfg; fn cfg(&self) -> ast::crate_cfg;
fn parse_sess() -> @mut parse::ParseSess; fn parse_sess(&self) -> @mut parse::ParseSess;
fn call_site() -> span; fn call_site(&self) -> span;
fn ident_of(+st: ~str) -> ast::ident; fn ident_of(&self, +st: ~str) -> ast::ident;
} }
#[cfg(test)] #[cfg(test)]
@ -1203,16 +1214,16 @@ type fake_session = @mut parse::ParseSess;
#[cfg(test)] #[cfg(test)]
impl fake_ext_ctxt for fake_session { impl fake_ext_ctxt for fake_session {
fn cfg() -> ast::crate_cfg { ~[] } fn cfg(&self) -> ast::crate_cfg { ~[] }
fn parse_sess() -> @mut parse::ParseSess { self } fn parse_sess(&self) -> @mut parse::ParseSess { *self }
fn call_site() -> span { fn call_site(&self) -> span {
codemap::span { codemap::span {
lo: codemap::BytePos(0), lo: codemap::BytePos(0),
hi: codemap::BytePos(0), hi: codemap::BytePos(0),
expn_info: None expn_info: None
} }
} }
fn ident_of(+st: ~str) -> ast::ident { fn ident_of(&self, +st: ~str) -> ast::ident {
self.interner.intern(@st) self.interner.intern(@st)
} }
} }

View File

@ -90,16 +90,16 @@ enum assignment_type {
} }
impl assignment_type { impl assignment_type {
fn checked_by_liveness() -> bool { fn checked_by_liveness(&self) -> bool {
// the liveness pass guarantees that immutable local variables // the liveness pass guarantees that immutable local variables
// are only assigned once; but it doesn't consider &mut // are only assigned once; but it doesn't consider &mut
match self { match *self {
at_straight_up => true, at_straight_up => true,
at_swap => true at_swap => true
} }
} }
fn ing_form(desc: ~str) -> ~str { fn ing_form(&self, desc: ~str) -> ~str {
match self { match *self {
at_straight_up => ~"assigning to " + desc, at_straight_up => ~"assigning to " + desc,
at_swap => ~"swapping to and from " + desc at_swap => ~"swapping to and from " + desc
} }

View File

@ -82,7 +82,7 @@ pub struct LanguageItems {
} }
pub impl LanguageItems { pub impl LanguageItems {
static pub fn new() -> LanguageItems { static pub fn new(&self) -> LanguageItems {
LanguageItems { LanguageItems {
items: [ None, ..34 ] items: [ None, ..34 ]
} }
@ -96,7 +96,7 @@ pub impl LanguageItems {
} }
} }
static pub fn item_name(index: uint) -> &static/str { static pub fn item_name(&self, index: uint) -> &static/str {
match index { match index {
0 => "const", 0 => "const",
1 => "copy", 1 => "copy",
@ -315,7 +315,7 @@ struct LanguageItemCollector {
} }
impl LanguageItemCollector { impl LanguageItemCollector {
fn match_and_collect_meta_item(item_def_id: def_id, fn match_and_collect_meta_item(&self, item_def_id: def_id,
meta_item: meta_item) { meta_item: meta_item) {
match meta_item.node { match meta_item.node {
meta_name_value(key, literal) => { meta_name_value(key, literal) => {
@ -330,7 +330,7 @@ impl LanguageItemCollector {
} }
} }
fn collect_item(item_index: uint, item_def_id: def_id) { fn collect_item(&self, item_index: uint, item_def_id: def_id) {
// Check for duplicates. // Check for duplicates.
match self.items.items[item_index] { match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => { Some(original_def_id) if original_def_id != item_def_id => {
@ -346,7 +346,8 @@ impl LanguageItemCollector {
self.items.items[item_index] = Some(item_def_id); self.items.items[item_index] = Some(item_def_id);
} }
fn match_and_collect_item(item_def_id: def_id, key: @~str, value: @~str) { fn match_and_collect_item(&self,
item_def_id: def_id, key: @~str, value: @~str) {
if *key != ~"lang" { if *key != ~"lang" {
return; // Didn't match. return; // Didn't match.
} }
@ -361,7 +362,7 @@ impl LanguageItemCollector {
} }
} }
fn collect_local_language_items() { fn collect_local_language_items(&self) {
let this = unsafe { ptr::addr_of(&self) }; let this = unsafe { ptr::addr_of(&self) };
visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor { visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor {
visit_item: |item| { visit_item: |item| {
@ -378,7 +379,7 @@ impl LanguageItemCollector {
})); }));
} }
fn collect_external_language_items() { fn collect_external_language_items(&self) {
let crate_store = self.session.cstore; let crate_store = self.session.cstore;
do iter_crate_data(crate_store) |crate_number, _crate_metadata| { do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
for each_lang_item(crate_store, crate_number) for each_lang_item(crate_store, crate_number)
@ -389,7 +390,7 @@ impl LanguageItemCollector {
} }
} }
fn check_completeness() { fn check_completeness(&self) {
for self.item_refs.each |&key, &item_ref| { for self.item_refs.each |&key, &item_ref| {
match self.items.items[item_ref] { match self.items.items[item_ref] {
None => { None => {
@ -402,7 +403,7 @@ impl LanguageItemCollector {
} }
} }
fn collect() { fn collect(&self) {
self.collect_local_language_items(); self.collect_local_language_items();
self.collect_external_language_items(); self.collect_external_language_items();
self.check_completeness(); self.check_completeness();

View File

@ -255,7 +255,7 @@ impl to_str::ToStr for Variable {
// assignment. And so forth. // assignment. And so forth.
impl LiveNode { impl LiveNode {
pure fn is_valid() -> bool { *self != uint::max_value } pure fn is_valid(&self) -> bool { **self != uint::max_value }
} }
fn invalid_node() -> LiveNode { LiveNode(uint::max_value) } fn invalid_node() -> LiveNode { LiveNode(uint::max_value) }
@ -699,7 +699,7 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
} }
impl Liveness { impl Liveness {
fn live_node(node_id: node_id, span: span) -> LiveNode { fn live_node(&self, node_id: node_id, span: span) -> LiveNode {
match self.ir.live_node_map.find(&node_id) { match self.ir.live_node_map.find(&node_id) {
Some(ln) => ln, Some(ln) => ln,
None => { None => {
@ -714,7 +714,7 @@ impl Liveness {
} }
} }
fn variable_from_path(expr: @expr) -> Option<Variable> { fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
match expr.node { match expr.node {
expr_path(_) => { expr_path(_) => {
let def = self.tcx.def_map.get(&expr.id); let def = self.tcx.def_map.get(&expr.id);
@ -726,11 +726,11 @@ impl Liveness {
} }
} }
fn variable(node_id: node_id, span: span) -> Variable { fn variable(&self, node_id: node_id, span: span) -> Variable {
self.ir.variable(node_id, span) self.ir.variable(node_id, span)
} }
fn variable_from_def_map(node_id: node_id, fn variable_from_def_map(&self, node_id: node_id,
span: span) -> Option<Variable> { span: span) -> Option<Variable> {
match self.tcx.def_map.find(&node_id) { match self.tcx.def_map.find(&node_id) {
Some(def) => { Some(def) => {
@ -745,7 +745,7 @@ impl Liveness {
} }
} }
fn pat_bindings(pat: @pat, f: fn(LiveNode, Variable, span)) { fn pat_bindings(&self, pat: @pat, f: fn(LiveNode, Variable, span)) {
let def_map = self.tcx.def_map; let def_map = self.tcx.def_map;
do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| { do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| {
let ln = self.live_node(p_id, sp); let ln = self.live_node(p_id, sp);
@ -754,7 +754,8 @@ impl Liveness {
} }
} }
fn arm_pats_bindings(pats: &[@pat], f: fn(LiveNode, Variable, span)) { fn arm_pats_bindings(&self,
pats: &[@pat], f: fn(LiveNode, Variable, span)) {
// only consider the first pattern; any later patterns must have // only consider the first pattern; any later patterns must have
// the same bindings, and we also consider the first pattern to be // the same bindings, and we also consider the first pattern to be
// the "authoratative" set of ids // the "authoratative" set of ids
@ -763,11 +764,11 @@ impl Liveness {
} }
} }
fn define_bindings_in_pat(pat: @pat, succ: LiveNode) -> LiveNode { fn define_bindings_in_pat(&self, pat: @pat, succ: LiveNode) -> LiveNode {
self.define_bindings_in_arm_pats([pat], succ) self.define_bindings_in_arm_pats([pat], succ)
} }
fn define_bindings_in_arm_pats(pats: &[@pat], fn define_bindings_in_arm_pats(&self, pats: &[@pat],
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
let mut succ = succ; let mut succ = succ;
do self.arm_pats_bindings(pats) |ln, var, _sp| { do self.arm_pats_bindings(pats) |ln, var, _sp| {
@ -778,11 +779,11 @@ impl Liveness {
succ succ
} }
fn idx(ln: LiveNode, var: Variable) -> uint { fn idx(&self, ln: LiveNode, var: Variable) -> uint {
*ln * self.ir.num_vars + *var *ln * self.ir.num_vars + *var
} }
fn live_on_entry(ln: LiveNode, var: Variable) fn live_on_entry(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
assert ln.is_valid(); assert ln.is_valid();
@ -793,18 +794,18 @@ impl Liveness {
/* /*
Is this variable live on entry to any of its successor nodes? Is this variable live on entry to any of its successor nodes?
*/ */
fn live_on_exit(ln: LiveNode, var: Variable) fn live_on_exit(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
self.live_on_entry(copy self.successors[*ln], var) self.live_on_entry(copy self.successors[*ln], var)
} }
fn used_on_entry(ln: LiveNode, var: Variable) -> bool { fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
assert ln.is_valid(); assert ln.is_valid();
self.users[self.idx(ln, var)].used self.users[self.idx(ln, var)].used
} }
fn assigned_on_entry(ln: LiveNode, var: Variable) fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
assert ln.is_valid(); assert ln.is_valid();
@ -812,13 +813,13 @@ impl Liveness {
if writer.is_valid() {Some(self.ir.lnk(writer))} else {None} if writer.is_valid() {Some(self.ir.lnk(writer))} else {None}
} }
fn assigned_on_exit(ln: LiveNode, var: Variable) fn assigned_on_exit(&self, ln: LiveNode, var: Variable)
-> Option<LiveNodeKind> { -> Option<LiveNodeKind> {
self.assigned_on_entry(copy self.successors[*ln], var) self.assigned_on_entry(copy self.successors[*ln], var)
} }
fn indices(ln: LiveNode, op: fn(uint)) { fn indices(&self, ln: LiveNode, op: fn(uint)) {
let node_base_idx = self.idx(ln, Variable(0)); let node_base_idx = self.idx(ln, Variable(0));
for uint::range(0, self.ir.num_vars) |var_idx| { for uint::range(0, self.ir.num_vars) |var_idx| {
op(node_base_idx + var_idx) op(node_base_idx + var_idx)
@ -834,7 +835,7 @@ impl Liveness {
} }
} }
fn write_vars(wr: io::Writer, fn write_vars(&self, wr: io::Writer,
ln: LiveNode, ln: LiveNode,
test: fn(uint) -> LiveNode) { test: fn(uint) -> LiveNode) {
let node_base_idx = self.idx(ln, Variable(0)); let node_base_idx = self.idx(ln, Variable(0));
@ -847,7 +848,7 @@ impl Liveness {
} }
} }
fn find_loop_scope(opt_label: Option<ident>, id: node_id, sp: span) fn find_loop_scope(&self, opt_label: Option<ident>, id: node_id, sp: span)
-> node_id { -> node_id {
match opt_label { match opt_label {
Some(_) => // Refers to a labeled loop. Use the results of resolve Some(_) => // Refers to a labeled loop. Use the results of resolve
@ -869,7 +870,7 @@ impl Liveness {
} }
} }
fn ln_str(ln: LiveNode) -> ~str { fn ln_str(&self, ln: LiveNode) -> ~str {
do io::with_str_writer |wr| { do io::with_str_writer |wr| {
wr.write_str(~"[ln("); wr.write_str(~"[ln(");
wr.write_uint(*ln); wr.write_uint(*ln);
@ -886,7 +887,7 @@ impl Liveness {
} }
} }
fn init_empty(ln: LiveNode, succ_ln: LiveNode) { fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) {
self.successors[*ln] = succ_ln; self.successors[*ln] = succ_ln;
// It is not necessary to initialize the // It is not necessary to initialize the
@ -899,7 +900,7 @@ impl Liveness {
// } // }
} }
fn init_from_succ(ln: LiveNode, succ_ln: LiveNode) { fn init_from_succ(&self, ln: LiveNode, succ_ln: LiveNode) {
// more efficient version of init_empty() / merge_from_succ() // more efficient version of init_empty() / merge_from_succ()
self.successors[*ln] = succ_ln; self.successors[*ln] = succ_ln;
self.indices2(ln, succ_ln, |idx, succ_idx| { self.indices2(ln, succ_ln, |idx, succ_idx| {
@ -909,7 +910,7 @@ impl Liveness {
self.ln_str(ln), self.ln_str(succ_ln)); self.ln_str(ln), self.ln_str(succ_ln));
} }
fn merge_from_succ(ln: LiveNode, succ_ln: LiveNode, fn merge_from_succ(&self, ln: LiveNode, succ_ln: LiveNode,
first_merge: bool) -> bool { first_merge: bool) -> bool {
if ln == succ_ln { return false; } if ln == succ_ln { return false; }
@ -943,7 +944,7 @@ impl Liveness {
// Indicates that a local variable was *defined*; we know that no // Indicates that a local variable was *defined*; we know that no
// uses of the variable can precede the definition (resolve checks // uses of the variable can precede the definition (resolve checks
// this) so we just clear out all the data. // this) so we just clear out all the data.
fn define(writer: LiveNode, var: Variable) { fn define(&self, writer: LiveNode, var: Variable) {
let idx = self.idx(writer, var); let idx = self.idx(writer, var);
self.users[idx].reader = invalid_node(); self.users[idx].reader = invalid_node();
self.users[idx].writer = invalid_node(); self.users[idx].writer = invalid_node();
@ -953,7 +954,7 @@ impl Liveness {
} }
// Either read, write, or both depending on the acc bitset // Either read, write, or both depending on the acc bitset
fn acc(ln: LiveNode, var: Variable, acc: uint) { fn acc(&self, ln: LiveNode, var: Variable, acc: uint) {
let idx = self.idx(ln, var); let idx = self.idx(ln, var);
let user = &mut self.users[idx]; let user = &mut self.users[idx];
@ -978,7 +979,7 @@ impl Liveness {
// _______________________________________________________________________ // _______________________________________________________________________
fn compute(decl: fn_decl, body: blk) -> LiveNode { fn compute(&self, decl: fn_decl, body: blk) -> LiveNode {
// if there is a `break` or `again` at the top level, then it's // if there is a `break` or `again` at the top level, then it's
// effectively a return---this only occurs in `for` loops, // effectively a return---this only occurs in `for` loops,
// where the body is really a closure. // where the body is really a closure.
@ -1003,7 +1004,8 @@ impl Liveness {
entry_ln entry_ln
} }
fn propagate_through_fn_block(decl: fn_decl, blk: blk) -> LiveNode { fn propagate_through_fn_block(&self, decl: fn_decl, blk: blk)
-> LiveNode {
// inputs passed by & mode should be considered live on exit: // inputs passed by & mode should be considered live on exit:
for decl.inputs.each |arg| { for decl.inputs.each |arg| {
match ty::resolved_mode(self.tcx, arg.mode) { match ty::resolved_mode(self.tcx, arg.mode) {
@ -1036,14 +1038,15 @@ impl Liveness {
self.propagate_through_block(blk, self.s.fallthrough_ln) self.propagate_through_block(blk, self.s.fallthrough_ln)
} }
fn propagate_through_block(blk: blk, succ: LiveNode) -> LiveNode { fn propagate_through_block(&self, blk: blk, succ: LiveNode) -> LiveNode {
let succ = self.propagate_through_opt_expr(blk.node.expr, succ); let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
do blk.node.stmts.foldr(succ) |stmt, succ| { do blk.node.stmts.foldr(succ) |stmt, succ| {
self.propagate_through_stmt(*stmt, succ) self.propagate_through_stmt(*stmt, succ)
} }
} }
fn propagate_through_stmt(stmt: @stmt, succ: LiveNode) -> LiveNode { fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode)
-> LiveNode {
match stmt.node { match stmt.node {
stmt_decl(decl, _) => { stmt_decl(decl, _) => {
return self.propagate_through_decl(decl, succ); return self.propagate_through_decl(decl, succ);
@ -1059,7 +1062,8 @@ impl Liveness {
} }
} }
fn propagate_through_decl(decl: @decl, succ: LiveNode) -> LiveNode { fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
-> LiveNode {
match /*bad*/copy decl.node { match /*bad*/copy decl.node {
decl_local(locals) => { decl_local(locals) => {
do locals.foldr(succ) |local, succ| { do locals.foldr(succ) |local, succ| {
@ -1072,7 +1076,8 @@ impl Liveness {
} }
} }
fn propagate_through_local(local: @local, succ: LiveNode) -> LiveNode { fn propagate_through_local(&self, local: @local, succ: LiveNode)
-> LiveNode {
// Note: we mark the variable as defined regardless of whether // Note: we mark the variable as defined regardless of whether
// there is an initializer. Initially I had thought to only mark // there is an initializer. Initially I had thought to only mark
// the live variable as defined if it was initialized, and then we // the live variable as defined if it was initialized, and then we
@ -1091,21 +1096,22 @@ impl Liveness {
self.define_bindings_in_pat(local.node.pat, succ) self.define_bindings_in_pat(local.node.pat, succ)
} }
fn propagate_through_exprs(exprs: ~[@expr], fn propagate_through_exprs(&self, exprs: ~[@expr],
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
do exprs.foldr(succ) |expr, succ| { do exprs.foldr(succ) |expr, succ| {
self.propagate_through_expr(*expr, succ) self.propagate_through_expr(*expr, succ)
} }
} }
fn propagate_through_opt_expr(opt_expr: Option<@expr>, fn propagate_through_opt_expr(&self, opt_expr: Option<@expr>,
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
do opt_expr.foldl(succ) |succ, expr| { do opt_expr.foldl(succ) |succ, expr| {
self.propagate_through_expr(*expr, *succ) self.propagate_through_expr(*expr, *succ)
} }
} }
fn propagate_through_expr(expr: @expr, succ: LiveNode) -> LiveNode { fn propagate_through_expr(&self, expr: @expr, succ: LiveNode)
-> LiveNode {
debug!("propagate_through_expr: %s", debug!("propagate_through_expr: %s",
expr_to_str(expr, self.tcx.sess.intr())); expr_to_str(expr, self.tcx.sess.intr()));
@ -1365,7 +1371,7 @@ impl Liveness {
} }
} }
fn propagate_through_lvalue_components(expr: @expr, fn propagate_through_lvalue_components(&self, expr: @expr,
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
// # Lvalues // # Lvalues
// //
@ -1424,7 +1430,7 @@ impl Liveness {
} }
// see comment on propagate_through_lvalue() // see comment on propagate_through_lvalue()
fn write_lvalue(expr: @expr, fn write_lvalue(&self, expr: @expr,
succ: LiveNode, succ: LiveNode,
acc: uint) -> LiveNode { acc: uint) -> LiveNode {
match expr.node { match expr.node {
@ -1438,7 +1444,8 @@ impl Liveness {
} }
} }
fn access_path(expr: @expr, succ: LiveNode, acc: uint) -> LiveNode { fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
-> LiveNode {
let def = self.tcx.def_map.get(&expr.id); let def = self.tcx.def_map.get(&expr.id);
match relevant_def(def) { match relevant_def(def) {
Some(nid) => { Some(nid) => {
@ -1454,7 +1461,7 @@ impl Liveness {
} }
} }
fn propagate_through_loop(expr: @expr, fn propagate_through_loop(&self, expr: @expr,
cond: Option<@expr>, cond: Option<@expr>,
body: blk, body: blk,
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
@ -1510,7 +1517,7 @@ impl Liveness {
cond_ln cond_ln
} }
fn with_loop_nodes<R>(loop_node_id: node_id, fn with_loop_nodes<R>(&self, loop_node_id: node_id,
break_ln: LiveNode, break_ln: LiveNode,
cont_ln: LiveNode, cont_ln: LiveNode,
f: fn() -> R) -> R { f: fn() -> R) -> R {
@ -1646,7 +1653,7 @@ enum ReadKind {
} }
impl @Liveness { impl @Liveness {
fn check_ret(id: node_id, sp: span, _fk: visit::fn_kind, fn check_ret(&self, id: node_id, sp: span, _fk: visit::fn_kind,
entry_ln: LiveNode) { entry_ln: LiveNode) {
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() { if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
// if no_ret_var is live, then we fall off the end of the // if no_ret_var is live, then we fall off the end of the
@ -1666,7 +1673,7 @@ impl @Liveness {
} }
} }
fn check_move_from_var(ln: LiveNode, fn check_move_from_var(&self, ln: LiveNode,
var: Variable, var: Variable,
move_expr: @expr) move_expr: @expr)
{ {
@ -1691,7 +1698,7 @@ impl @Liveness {
} }
} }
fn consider_last_use(expr: @expr, ln: LiveNode, var: Variable) { fn consider_last_use(&self, expr: @expr, ln: LiveNode, var: Variable) {
debug!("consider_last_use(expr.id=%?, ln=%s, var=%s)", debug!("consider_last_use(expr.id=%?, ln=%s, var=%s)",
expr.id, ln.to_str(), var.to_str()); expr.id, ln.to_str(), var.to_str());
@ -1701,7 +1708,7 @@ impl @Liveness {
} }
} }
fn check_lvalue(expr: @expr, vt: vt<@Liveness>) { fn check_lvalue(&self, expr: @expr, vt: vt<@Liveness>) {
match expr.node { match expr.node {
expr_path(_) => { expr_path(_) => {
match self.tcx.def_map.get(&expr.id) { match self.tcx.def_map.get(&expr.id) {
@ -1729,18 +1736,18 @@ impl @Liveness {
_ => { _ => {
// For other kinds of lvalues, no checks are required, // For other kinds of lvalues, no checks are required,
// and any embedded expressions are actually rvalues // and any embedded expressions are actually rvalues
visit::visit_expr(expr, self, vt); visit::visit_expr(expr, *self, vt);
} }
} }
} }
fn check_for_reassignments_in_pat(pat: @pat) { fn check_for_reassignments_in_pat(&self, pat: @pat) {
do self.pat_bindings(pat) |ln, var, sp| { do self.pat_bindings(pat) |ln, var, sp| {
self.check_for_reassignment(ln, var, sp); self.check_for_reassignment(ln, var, sp);
} }
} }
fn check_for_reassignment(ln: LiveNode, var: Variable, fn check_for_reassignment(&self, ln: LiveNode, var: Variable,
orig_span: span) { orig_span: span) {
match self.assigned_on_exit(ln, var) { match self.assigned_on_exit(ln, var) {
Some(ExprNode(span)) => { Some(ExprNode(span)) => {
@ -1761,7 +1768,7 @@ impl @Liveness {
} }
} }
fn report_illegal_move(lnk: LiveNodeKind, fn report_illegal_move(&self, lnk: LiveNodeKind,
var: Variable, var: Variable,
move_expr: @expr) move_expr: @expr)
{ {
@ -1827,7 +1834,7 @@ impl @Liveness {
}; };
} }
fn report_move_location(move_expr: @expr, fn report_move_location(&self, move_expr: @expr,
var: Variable, var: Variable,
expr_descr: &str, expr_descr: &str,
pronoun: &str) pronoun: &str)
@ -1842,7 +1849,7 @@ impl @Liveness {
ty_to_str(self.tcx, move_expr_ty))); ty_to_str(self.tcx, move_expr_ty)));
} }
fn report_illegal_read(chk_span: span, fn report_illegal_read(&self, chk_span: span,
lnk: LiveNodeKind, lnk: LiveNodeKind,
var: Variable, var: Variable,
rk: ReadKind) { rk: ReadKind) {
@ -1873,12 +1880,12 @@ impl @Liveness {
} }
} }
fn should_warn(var: Variable) -> Option<@~str> { fn should_warn(&self, var: Variable) -> Option<@~str> {
let name = self.ir.variable_name(var); let name = self.ir.variable_name(var);
if name[0] == ('_' as u8) { None } else { Some(name) } if name[0] == ('_' as u8) { None } else { Some(name) }
} }
fn warn_about_unused_args(decl: fn_decl, entry_ln: LiveNode) { fn warn_about_unused_args(&self, decl: fn_decl, entry_ln: LiveNode) {
for decl.inputs.each |arg| { for decl.inputs.each |arg| {
do pat_util::pat_bindings(self.tcx.def_map, arg.pat) do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|_bm, p_id, sp, _n| { |_bm, p_id, sp, _n| {
@ -1888,7 +1895,7 @@ impl @Liveness {
} }
} }
fn warn_about_unused_or_dead_vars_in_pat(pat: @pat) { fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) {
do self.pat_bindings(pat) |ln, var, sp| { do self.pat_bindings(pat) |ln, var, sp| {
if !self.warn_about_unused(sp, ln, var) { if !self.warn_about_unused(sp, ln, var) {
self.warn_about_dead_assign(sp, ln, var); self.warn_about_dead_assign(sp, ln, var);
@ -1896,7 +1903,8 @@ impl @Liveness {
} }
} }
fn warn_about_unused(sp: span, ln: LiveNode, var: Variable) -> bool { fn warn_about_unused(&self, sp: span, ln: LiveNode, var: Variable)
-> bool {
if !self.used_on_entry(ln, var) { if !self.used_on_entry(ln, var) {
for self.should_warn(var).each |name| { for self.should_warn(var).each |name| {
@ -1925,7 +1933,7 @@ impl @Liveness {
return false; return false;
} }
fn warn_about_dead_assign(sp: span, ln: LiveNode, var: Variable) { fn warn_about_dead_assign(&self, sp: span, ln: LiveNode, var: Variable) {
if self.live_on_exit(ln, var).is_none() { if self.live_on_exit(ln, var).is_none() {
for self.should_warn(var).each |name| { for self.should_warn(var).each |name| {
// FIXME(#3266)--make liveness warnings lintable // FIXME(#3266)--make liveness warnings lintable

View File

@ -277,27 +277,27 @@ pub fn cat_variant<N:ast_node>(
} }
pub trait ast_node { pub trait ast_node {
fn id() -> ast::node_id; fn id(&self) -> ast::node_id;
fn span() -> span; fn span(&self) -> span;
} }
pub impl ast_node for @ast::expr { pub impl ast_node for @ast::expr {
fn id() -> ast::node_id { self.id } fn id(&self) -> ast::node_id { self.id }
fn span() -> span { self.span } fn span(&self) -> span { self.span }
} }
pub impl ast_node for @ast::pat { pub impl ast_node for @ast::pat {
fn id() -> ast::node_id { self.id } fn id(&self) -> ast::node_id { self.id }
fn span() -> span { self.span } fn span(&self) -> span { self.span }
} }
pub trait get_type_for_node { pub trait get_type_for_node {
fn ty<N:ast_node>(node: N) -> ty::t; fn ty<N:ast_node>(&self, node: N) -> ty::t;
} }
pub impl get_type_for_node for ty::ctxt { pub impl get_type_for_node for ty::ctxt {
fn ty<N:ast_node>(node: N) -> ty::t { fn ty<N:ast_node>(&self, node: N) -> ty::t {
ty::node_id_to_type(self, node.id()) ty::node_id_to_type(*self, node.id())
} }
} }
@ -313,7 +313,7 @@ impl ToStr for MutabilityCategory {
} }
impl MutabilityCategory { impl MutabilityCategory {
static fn from_mutbl(m: ast::mutability) -> MutabilityCategory { static fn from_mutbl(&self, m: ast::mutability) -> MutabilityCategory {
match m { match m {
m_imm => McImmutable, m_imm => McImmutable,
m_const => McReadOnly, m_const => McReadOnly,

View File

@ -154,8 +154,8 @@ pub enum NamespaceResult {
} }
pub impl NamespaceResult { pub impl NamespaceResult {
pure fn is_unknown() -> bool { pure fn is_unknown(&self) -> bool {
match self { match *self {
UnknownResult => true, UnknownResult => true,
_ => false _ => false
} }
@ -206,11 +206,11 @@ pub enum ResolveResult<T> {
} }
pub impl<T> ResolveResult<T> { pub impl<T> ResolveResult<T> {
fn failed() -> bool { fn failed(&self) -> bool {
match self { Failed => true, _ => false } match *self { Failed => true, _ => false }
} }
fn indeterminate() -> bool { fn indeterminate(&self) -> bool {
match self { Indeterminate => true, _ => false } match *self { Indeterminate => true, _ => false }
} }
} }
@ -417,7 +417,7 @@ pub fn ImportResolution(privacy: Privacy,
} }
pub impl ImportResolution { pub impl ImportResolution {
fn target_for_namespace(namespace: Namespace) -> Option<Target> { fn target_for_namespace(&self, namespace: Namespace) -> Option<Target> {
match namespace { match namespace {
TypeNS => return copy self.type_target, TypeNS => return copy self.type_target,
ValueNS => return copy self.value_target ValueNS => return copy self.value_target
@ -503,7 +503,7 @@ pub fn Module(parent_link: ParentLink,
} }
pub impl Module { pub impl Module {
fn all_imports_resolved() -> bool { fn all_imports_resolved(&self) -> bool {
return self.imports.len() == self.resolved_import_count; return self.imports.len() == self.resolved_import_count;
} }
} }
@ -706,7 +706,7 @@ pub struct PrimitiveTypeTable {
} }
pub impl PrimitiveTypeTable { pub impl PrimitiveTypeTable {
fn intern(intr: @ident_interner, string: @~str, fn intern(&self, intr: @ident_interner, string: @~str,
primitive_type: prim_ty) { primitive_type: prim_ty) {
let ident = intr.intern(string); let ident = intr.intern(string);
self.primitive_types.insert(ident, primitive_type); self.primitive_types.insert(ident, primitive_type);

View File

@ -105,27 +105,27 @@ pub fn icx_popper(ccx: @CrateContext) -> icx_popper {
} }
pub trait get_insn_ctxt { pub trait get_insn_ctxt {
fn insn_ctxt(s: &str) -> icx_popper; fn insn_ctxt(&self, s: &str) -> icx_popper;
} }
pub impl get_insn_ctxt for @CrateContext { pub impl get_insn_ctxt for @CrateContext {
fn insn_ctxt(s: &str) -> icx_popper { fn insn_ctxt(&self, s: &str) -> icx_popper {
debug!("new insn_ctxt: %s", s); debug!("new insn_ctxt: %s", s);
if self.sess.count_llvm_insns() { if self.sess.count_llvm_insns() {
self.stats.llvm_insn_ctxt.push(str::from_slice(s)); self.stats.llvm_insn_ctxt.push(str::from_slice(s));
} }
icx_popper(self) icx_popper(*self)
} }
} }
pub impl get_insn_ctxt for block { pub impl get_insn_ctxt for block {
fn insn_ctxt(s: &str) -> icx_popper { fn insn_ctxt(&self, s: &str) -> icx_popper {
self.ccx().insn_ctxt(s) self.ccx().insn_ctxt(s)
} }
} }
pub impl get_insn_ctxt for fn_ctxt { pub impl get_insn_ctxt for fn_ctxt {
fn insn_ctxt(s: &str) -> icx_popper { fn insn_ctxt(&self, s: &str) -> icx_popper {
self.ccx.insn_ctxt(s) self.ccx.insn_ctxt(s)
} }
} }

View File

@ -131,7 +131,7 @@ pub impl EnvAction {
} }
pub impl EnvValue { pub impl EnvValue {
fn to_str(ccx: @CrateContext) -> ~str { fn to_str(&self, ccx: @CrateContext) -> ~str {
fmt!("%s(%s)", self.action.to_str(), self.datum.to_str(ccx)) fmt!("%s(%s)", self.action.to_str(), self.datum.to_str(ccx))
} }
} }

View File

@ -535,17 +535,17 @@ pub struct scope_info {
} }
pub trait get_node_info { pub trait get_node_info {
fn info() -> Option<NodeInfo>; fn info(&self) -> Option<NodeInfo>;
} }
pub impl get_node_info for @ast::expr { pub impl get_node_info for @ast::expr {
fn info() -> Option<NodeInfo> { fn info(&self) -> Option<NodeInfo> {
Some(NodeInfo { id: self.id, span: self.span }) Some(NodeInfo { id: self.id, span: self.span })
} }
} }
pub impl get_node_info for ast::blk { pub impl get_node_info for ast::blk {
fn info() -> Option<NodeInfo> { fn info(&self) -> Option<NodeInfo> {
Some(NodeInfo { id: self.node.id, span: self.span }) Some(NodeInfo { id: self.node.id, span: self.span })
} }
} }
@ -554,7 +554,7 @@ pub impl get_node_info for ast::blk {
pub type optional_boxed_ast_expr = Option<@ast::expr>; pub type optional_boxed_ast_expr = Option<@ast::expr>;
pub impl get_node_info for optional_boxed_ast_expr { pub impl get_node_info for optional_boxed_ast_expr {
fn info() -> Option<NodeInfo> { fn info(&self) -> Option<NodeInfo> {
self.chain_ref(|s| s.info()) self.chain_ref(|s| s.info())
} }
} }
@ -627,7 +627,7 @@ pub fn rslt(bcx: block, val: ValueRef) -> Result {
} }
pub impl Result { pub impl Result {
fn unpack(bcx: &mut block) -> ValueRef { fn unpack(&self, bcx: &mut block) -> ValueRef {
*bcx = self.bcx; *bcx = self.bcx;
return self.val; return self.val;
} }
@ -691,27 +691,27 @@ pub fn block_parent(cx: block) -> block {
// Accessors // Accessors
pub impl block { pub impl block {
pure fn ccx() -> @CrateContext { *self.fcx.ccx } pure fn ccx(&self) -> @CrateContext { *self.fcx.ccx }
pure fn tcx() -> ty::ctxt { self.fcx.ccx.tcx } pure fn tcx(&self) -> ty::ctxt { self.fcx.ccx.tcx }
pure fn sess() -> Session { self.fcx.ccx.sess } pure fn sess(&self) -> Session { self.fcx.ccx.sess }
fn node_id_to_str(id: ast::node_id) -> ~str { fn node_id_to_str(&self, id: ast::node_id) -> ~str {
ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr()) ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr())
} }
fn expr_to_str(e: @ast::expr) -> ~str { fn expr_to_str(&self, e: @ast::expr) -> ~str {
expr_repr(self.tcx(), e) expr_repr(self.tcx(), e)
} }
fn expr_is_lval(e: @ast::expr) -> bool { fn expr_is_lval(&self, e: @ast::expr) -> bool {
ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e) ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e)
} }
fn expr_kind(e: @ast::expr) -> ty::ExprKind { fn expr_kind(&self, e: @ast::expr) -> ty::ExprKind {
ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e) ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e)
} }
fn def(nid: ast::node_id) -> ast::def { fn def(&self, nid: ast::node_id) -> ast::def {
match self.tcx().def_map.find(&nid) { match self.tcx().def_map.find(&nid) {
Some(v) => v, Some(v) => v,
None => { None => {
@ -721,15 +721,15 @@ pub impl block {
} }
} }
fn val_str(val: ValueRef) -> @str { fn val_str(&self, val: ValueRef) -> @str {
val_str(self.ccx().tn, val) val_str(self.ccx().tn, val)
} }
fn llty_str(llty: TypeRef) -> @str { fn llty_str(&self, llty: TypeRef) -> @str {
ty_str(self.ccx().tn, llty) ty_str(self.ccx().tn, llty)
} }
fn ty_to_str(t: ty::t) -> ~str { fn ty_to_str(&self, t: ty::t) -> ~str {
ty_to_str(self.tcx(), t) ty_to_str(self.tcx(), t)
} }
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {

View File

@ -142,12 +142,12 @@ pub enum DatumMode {
} }
pub impl DatumMode { pub impl DatumMode {
fn is_by_ref() -> bool { fn is_by_ref(&self) -> bool {
match self { ByRef => true, ByValue => false } match *self { ByRef => true, ByValue => false }
} }
fn is_by_value() -> bool { fn is_by_value(&self) -> bool {
match self { ByRef => false, ByValue => true } match *self { ByRef => false, ByValue => true }
} }
} }
@ -216,7 +216,7 @@ pub fn appropriate_mode(ty: ty::t) -> DatumMode {
} }
pub impl Datum { pub impl Datum {
fn store_to(bcx: block, id: ast::node_id, fn store_to(&self, bcx: block, id: ast::node_id,
action: CopyAction, dst: ValueRef) -> block { action: CopyAction, dst: ValueRef) -> block {
/*! /*!
* *
@ -231,7 +231,7 @@ pub impl Datum {
} }
} }
fn store_to_dest(bcx: block, id: ast::node_id, fn store_to_dest(&self, bcx: block, id: ast::node_id,
dest: expr::Dest) -> block { dest: expr::Dest) -> block {
match dest { match dest {
expr::Ignore => { expr::Ignore => {
@ -243,7 +243,7 @@ pub impl Datum {
} }
} }
fn store_to_datum(bcx: block, id: ast::node_id, fn store_to_datum(&self, bcx: block, id: ast::node_id,
action: CopyAction, datum: Datum) -> block { action: CopyAction, datum: Datum) -> block {
debug!("store_to_datum(self=%s, action=%?, datum=%s)", debug!("store_to_datum(self=%s, action=%?, datum=%s)",
self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx())); self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx()));
@ -251,17 +251,20 @@ pub impl Datum {
self.store_to(bcx, id, action, datum.val) self.store_to(bcx, id, action, datum.val)
} }
fn move_to_datum(bcx: block, action: CopyAction, datum: Datum) -> block { fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
-> block {
assert datum.mode.is_by_ref(); assert datum.mode.is_by_ref();
self.move_to(bcx, action, datum.val) self.move_to(bcx, action, datum.val)
} }
fn copy_to_datum(bcx: block, action: CopyAction, datum: Datum) -> block { fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
-> block {
assert datum.mode.is_by_ref(); assert datum.mode.is_by_ref();
self.copy_to(bcx, action, datum.val) self.copy_to(bcx, action, datum.val)
} }
fn copy_to(bcx: block, action: CopyAction, dst: ValueRef) -> block { fn copy_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
-> block {
/*! /*!
* *
* Copies the value into `dst`, which should be a pointer to a * Copies the value into `dst`, which should be a pointer to a
@ -303,7 +306,7 @@ pub impl Datum {
} }
} }
fn copy_to_no_check(bcx: block, action: CopyAction, fn copy_to_no_check(&self, bcx: block, action: CopyAction,
dst: ValueRef) -> block dst: ValueRef) -> block
{ {
/*! /*!
@ -333,7 +336,8 @@ pub impl Datum {
// This works like copy_val, except that it deinitializes the source. // This works like copy_val, except that it deinitializes the source.
// Since it needs to zero out the source, src also needs to be an lval. // Since it needs to zero out the source, src also needs to be an lval.
// //
fn move_to(bcx: block, action: CopyAction, dst: ValueRef) -> block { fn move_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
-> block {
let _icx = bcx.insn_ctxt("move_to"); let _icx = bcx.insn_ctxt("move_to");
let mut bcx = bcx; let mut bcx = bcx;
@ -362,7 +366,7 @@ pub impl Datum {
return bcx; return bcx;
} }
fn add_clean(bcx: block) { fn add_clean(&self, bcx: block) {
/*! /*!
* *
* Schedules this datum for cleanup in `bcx`. The datum * Schedules this datum for cleanup in `bcx`. The datum
@ -379,7 +383,7 @@ pub impl Datum {
} }
} }
fn cancel_clean(bcx: block) { fn cancel_clean(&self, bcx: block) {
if ty::type_needs_drop(bcx.tcx(), self.ty) { if ty::type_needs_drop(bcx.tcx(), self.ty) {
match self.source { match self.source {
RevokeClean => { RevokeClean => {
@ -396,7 +400,7 @@ pub impl Datum {
} }
} }
fn to_str(ccx: &CrateContext) -> ~str { fn to_str(&self, ccx: &CrateContext) -> ~str {
fmt!("Datum { val=%s, ty=%s, mode=%?, source=%? }", fmt!("Datum { val=%s, ty=%s, mode=%?, source=%? }",
val_str(ccx.tn, self.val), val_str(ccx.tn, self.val),
ty_to_str(ccx.tcx, self.ty), ty_to_str(ccx.tcx, self.ty),
@ -404,7 +408,7 @@ pub impl Datum {
self.source) self.source)
} }
fn to_value_datum(bcx: block) -> Datum { fn to_value_datum(&self, bcx: block) -> Datum {
/*! /*!
* *
* Yields a by-ref form of this datum. This may involve * Yields a by-ref form of this datum. This may involve
@ -413,7 +417,7 @@ pub impl Datum {
* it will not live longer than the current datum. */ * it will not live longer than the current datum. */
match self.mode { match self.mode {
ByValue => self, ByValue => *self,
ByRef => { ByRef => {
Datum {val: self.to_value_llval(bcx), mode: ByValue, Datum {val: self.to_value_llval(bcx), mode: ByValue,
ty: self.ty, source: RevokeClean} ty: self.ty, source: RevokeClean}
@ -421,7 +425,7 @@ pub impl Datum {
} }
} }
fn to_value_llval(bcx: block) -> ValueRef { fn to_value_llval(&self, bcx: block) -> ValueRef {
/*! /*!
* *
* Yields the value itself. */ * Yields the value itself. */
@ -442,7 +446,7 @@ pub impl Datum {
} }
} }
fn to_ref_datum(bcx: block) -> Datum { fn to_ref_datum(&self, bcx: block) -> Datum {
/*! /*!
* *
* Yields a by-ref form of this datum. This may involve * Yields a by-ref form of this datum. This may involve
@ -451,7 +455,7 @@ pub impl Datum {
* it will not live longer than the current datum. */ * it will not live longer than the current datum. */
match self.mode { match self.mode {
ByRef => self, ByRef => *self,
ByValue => { ByValue => {
Datum {val: self.to_ref_llval(bcx), mode: ByRef, Datum {val: self.to_ref_llval(bcx), mode: ByRef,
ty: self.ty, source: RevokeClean} ty: self.ty, source: RevokeClean}
@ -459,7 +463,7 @@ pub impl Datum {
} }
} }
fn to_ref_llval(bcx: block) -> ValueRef { fn to_ref_llval(&self, bcx: block) -> ValueRef {
match self.mode { match self.mode {
ByRef => self.val, ByRef => self.val,
ByValue => { ByValue => {
@ -474,13 +478,13 @@ pub impl Datum {
} }
} }
fn appropriate_mode() -> DatumMode { fn appropriate_mode(&self) -> DatumMode {
/*! See the `appropriate_mode()` function */ /*! See the `appropriate_mode()` function */
appropriate_mode(self.ty) appropriate_mode(self.ty)
} }
fn to_appropriate_llval(bcx: block) -> ValueRef { fn to_appropriate_llval(&self, bcx: block) -> ValueRef {
/*! /*!
* *
* Yields an llvalue with the `appropriate_mode()`. */ * Yields an llvalue with the `appropriate_mode()`. */
@ -491,7 +495,7 @@ pub impl Datum {
} }
} }
fn to_appropriate_datum(bcx: block) -> Datum { fn to_appropriate_datum(&self, bcx: block) -> Datum {
/*! /*!
* *
* Yields a datum with the `appropriate_mode()`. */ * Yields a datum with the `appropriate_mode()`. */
@ -502,7 +506,7 @@ pub impl Datum {
} }
} }
fn GEPi(bcx: block, fn GEPi(&self, bcx: block,
ixs: &[uint], ixs: &[uint],
ty: ty::t, ty: ty::t,
source: DatumCleanup) source: DatumCleanup)
@ -516,7 +520,7 @@ pub impl Datum {
} }
} }
fn root(bcx: block, root_info: RootInfo) -> block { fn root(&self, bcx: block, root_info: RootInfo) -> block {
/*! /*!
* *
* In some cases, borrowck will decide that an @T/@[]/@str * In some cases, borrowck will decide that an @T/@[]/@str
@ -555,7 +559,7 @@ pub impl Datum {
} }
} }
fn perform_write_guard(bcx: block) -> block { fn perform_write_guard(&self, bcx: block) -> block {
// Create scratch space, but do not root it. // Create scratch space, but do not root it.
let llval = match self.mode { let llval = match self.mode {
ByValue => self.val, ByValue => self.val,
@ -569,7 +573,7 @@ pub impl Datum {
expr::Ignore) expr::Ignore)
} }
fn drop_val(bcx: block) -> block { fn drop_val(&self, bcx: block) -> block {
if !ty::type_needs_drop(bcx.tcx(), self.ty) { if !ty::type_needs_drop(bcx.tcx(), self.ty) {
return bcx; return bcx;
} }
@ -580,7 +584,7 @@ pub impl Datum {
}; };
} }
fn box_body(bcx: block) -> Datum { fn box_body(&self, bcx: block) -> Datum {
/*! /*!
* *
* This datum must represent an @T or ~T box. Returns a new * This datum must represent an @T or ~T box. Returns a new
@ -600,7 +604,7 @@ pub impl Datum {
Datum {val: body, ty: content_ty, mode: ByRef, source: ZeroMem} Datum {val: body, ty: content_ty, mode: ByRef, source: ZeroMem}
} }
fn to_rptr(bcx: block) -> Datum { fn to_rptr(&self, bcx: block) -> Datum {
//! //!
// //
// Returns a new datum of region-pointer type containing the // Returns a new datum of region-pointer type containing the
@ -618,7 +622,7 @@ pub impl Datum {
mode: ByValue, source: RevokeClean} mode: ByValue, source: RevokeClean}
} }
fn try_deref( fn try_deref(&self,
bcx: block, // block wherein to generate insn's bcx: block, // block wherein to generate insn's
expr_id: ast::node_id, // id of expr being deref'd expr_id: ast::node_id, // id of expr being deref'd
derefs: uint, // number of times deref'd already derefs: uint, // number of times deref'd already
@ -656,11 +660,11 @@ pub impl Datum {
if is_auto { // unsafe ptrs are not AUTO-derefable if is_auto { // unsafe ptrs are not AUTO-derefable
return (None, bcx); return (None, bcx);
} else { } else {
return (Some(deref_ptr(bcx, &self, mt.ty)), bcx); return (Some(deref_ptr(bcx, self, mt.ty)), bcx);
} }
} }
ty::ty_rptr(_, mt) => { ty::ty_rptr(_, mt) => {
return (Some(deref_ptr(bcx, &self, mt.ty)), bcx); return (Some(deref_ptr(bcx, self, mt.ty)), bcx);
} }
ty::ty_enum(did, ref substs) => { ty::ty_enum(did, ref substs) => {
// Check whether this enum is a newtype enum: // Check whether this enum is a newtype enum:
@ -695,7 +699,7 @@ pub impl Datum {
// code in place here to do the right // code in place here to do the right
// thing if this change ever goes through. // thing if this change ever goes through.
assert ty::type_is_immediate(ty); assert ty::type_is_immediate(ty);
(Some(Datum {ty: ty, ..self}), bcx) (Some(Datum {ty: ty, ..*self}), bcx)
} }
}; };
} }
@ -733,7 +737,7 @@ pub impl Datum {
// code in place here to do the right thing if this // code in place here to do the right thing if this
// change ever goes through. // change ever goes through.
assert ty::type_is_immediate(ty); assert ty::type_is_immediate(ty);
(Some(Datum {ty: ty, ..self}), bcx) (Some(Datum {ty: ty, ..*self}), bcx)
} }
} }
} }
@ -752,7 +756,7 @@ pub impl Datum {
} }
} }
fn deref(bcx: block, fn deref(&self, bcx: block,
expr: @ast::expr, // the expression whose value is being deref'd expr: @ast::expr, // the expression whose value is being deref'd
derefs: uint) derefs: uint)
-> DatumBlock { -> DatumBlock {
@ -765,7 +769,7 @@ pub impl Datum {
} }
} }
fn autoderef(bcx: block, fn autoderef(&self, bcx: block,
expr_id: ast::node_id, expr_id: ast::node_id,
max: uint) max: uint)
-> DatumBlock { -> DatumBlock {
@ -775,7 +779,7 @@ pub impl Datum {
expr_id, max, self.to_str(bcx.ccx())); expr_id, max, self.to_str(bcx.ccx()));
let _indenter = indenter(); let _indenter = indenter();
let mut datum = self; let mut datum = *self;
let mut derefs = 0u; let mut derefs = 0u;
let mut bcx = bcx; let mut bcx = bcx;
while derefs < max { while derefs < max {
@ -796,56 +800,56 @@ pub impl Datum {
DatumBlock { bcx: bcx, datum: datum } DatumBlock { bcx: bcx, datum: datum }
} }
fn get_base_and_len(bcx: block) -> (ValueRef, ValueRef) { fn get_base_and_len(&self, bcx: block) -> (ValueRef, ValueRef) {
tvec::get_base_and_len(bcx, self.to_appropriate_llval(bcx), self.ty) tvec::get_base_and_len(bcx, self.to_appropriate_llval(bcx), self.ty)
} }
fn to_result(bcx: block) -> common::Result { fn to_result(&self, bcx: block) -> common::Result {
rslt(bcx, self.to_appropriate_llval(bcx)) rslt(bcx, self.to_appropriate_llval(bcx))
} }
} }
pub impl DatumBlock { pub impl DatumBlock {
fn unpack(bcx: &mut block) -> Datum { fn unpack(&self, bcx: &mut block) -> Datum {
*bcx = self.bcx; *bcx = self.bcx;
return self.datum; return self.datum;
} }
fn assert_by_ref() -> DatumBlock { fn assert_by_ref(&self) -> DatumBlock {
assert self.datum.mode.is_by_ref(); assert self.datum.mode.is_by_ref();
self *self
} }
fn drop_val() -> block { fn drop_val(&self) -> block {
self.datum.drop_val(self.bcx) self.datum.drop_val(self.bcx)
} }
fn store_to(id: ast::node_id, action: CopyAction, fn store_to(&self, id: ast::node_id, action: CopyAction,
dst: ValueRef) -> block { dst: ValueRef) -> block {
self.datum.store_to(self.bcx, id, action, dst) self.datum.store_to(self.bcx, id, action, dst)
} }
fn copy_to(action: CopyAction, dst: ValueRef) -> block { fn copy_to(&self, action: CopyAction, dst: ValueRef) -> block {
self.datum.copy_to(self.bcx, action, dst) self.datum.copy_to(self.bcx, action, dst)
} }
fn move_to(action: CopyAction, dst: ValueRef) -> block { fn move_to(&self, action: CopyAction, dst: ValueRef) -> block {
self.datum.move_to(self.bcx, action, dst) self.datum.move_to(self.bcx, action, dst)
} }
fn to_value_llval() -> ValueRef { fn to_value_llval(&self) -> ValueRef {
self.datum.to_value_llval(self.bcx) self.datum.to_value_llval(self.bcx)
} }
fn to_result() -> common::Result { fn to_result(&self) -> common::Result {
rslt(self.bcx, self.datum.to_appropriate_llval(self.bcx)) rslt(self.bcx, self.datum.to_appropriate_llval(self.bcx))
} }
fn ccx() -> @CrateContext { fn ccx(&self) -> @CrateContext {
self.bcx.ccx() self.bcx.ccx()
} }
fn tcx() -> ty::ctxt { fn tcx(&self) -> ty::ctxt {
self.bcx.tcx() self.bcx.tcx()
} }

View File

@ -157,8 +157,8 @@ pub enum Dest {
} }
impl Dest { impl Dest {
fn to_str(ccx: @CrateContext) -> ~str { fn to_str(&self, ccx: @CrateContext) -> ~str {
match self { match *self {
SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)), SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)),
Ignore => ~"Ignore" Ignore => ~"Ignore"
} }

View File

@ -146,7 +146,7 @@ pub struct VecTypes {
} }
pub impl VecTypes { pub impl VecTypes {
fn to_str(ccx: @CrateContext) -> ~str { fn to_str(&self, ccx: @CrateContext) -> ~str {
fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}", fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}",
ty_to_str(ccx.tcx, self.vec_ty), ty_to_str(ccx.tcx, self.vec_ty),
ty_to_str(ccx.tcx, self.unit_ty), ty_to_str(ccx.tcx, self.unit_ty),

View File

@ -657,11 +657,11 @@ impl to_bytes::IterBytes for param_bound {
} }
pub trait Vid { pub trait Vid {
pure fn to_uint() -> uint; pure fn to_uint(&self) -> uint;
} }
pub impl Vid for TyVid { pub impl Vid for TyVid {
pure fn to_uint() -> uint { *self } pure fn to_uint(&self) -> uint { **self }
} }
pub impl ToStr for TyVid { pub impl ToStr for TyVid {
@ -669,7 +669,7 @@ pub impl ToStr for TyVid {
} }
pub impl Vid for IntVid { pub impl Vid for IntVid {
pure fn to_uint() -> uint { *self } pure fn to_uint(&self) -> uint { **self }
} }
pub impl ToStr for IntVid { pub impl ToStr for IntVid {
@ -677,7 +677,7 @@ pub impl ToStr for IntVid {
} }
pub impl Vid for FloatVid { pub impl Vid for FloatVid {
pure fn to_uint() -> uint { *self } pure fn to_uint(&self) -> uint { **self }
} }
pub impl ToStr for FloatVid { pub impl ToStr for FloatVid {
@ -685,7 +685,7 @@ pub impl ToStr for FloatVid {
} }
pub impl Vid for RegionVid { pub impl Vid for RegionVid {
pure fn to_uint() -> uint { *self } pure fn to_uint(&self) -> uint { **self }
} }
pub impl ToStr for RegionVid { pub impl ToStr for RegionVid {

View File

@ -660,19 +660,19 @@ pub impl FnCtxt {
} }
pub impl region_scope for @mut FnCtxt { pub impl region_scope for @mut FnCtxt {
pure fn anon_region(span: span) -> Result<ty::Region, ~str> { pure fn anon_region(&self, span: span) -> Result<ty::Region, ~str> {
// XXX: Unsafe to work around purity // XXX: Unsafe to work around purity
unsafe { unsafe {
result::Ok(self.infcx().next_region_var_nb(span)) result::Ok(self.infcx().next_region_var_nb(span))
} }
} }
pure fn self_region(_span: span) -> Result<ty::Region, ~str> { pure fn self_region(&self, _span: span) -> Result<ty::Region, ~str> {
// XXX: Unsafe to work around purity // XXX: Unsafe to work around purity
unsafe { unsafe {
self.search_in_scope_regions(ty::br_self) self.search_in_scope_regions(ty::br_self)
} }
} }
pure fn named_region(_span: span, id: ast::ident) pure fn named_region(&self, _span: span, id: ast::ident)
-> Result<ty::Region, ~str> { -> Result<ty::Region, ~str> {
// XXX: Unsafe to work around purity // XXX: Unsafe to work around purity
unsafe { unsafe {

View File

@ -197,6 +197,7 @@ pub struct CoherenceChecker {
} }
pub impl CoherenceChecker { pub impl CoherenceChecker {
// IMPLICIT SELF WARNING: fix this!
fn check_coherence(crate: @crate) { fn check_coherence(crate: @crate) {
// Check implementations and traits. This populates the tables // Check implementations and traits. This populates the tables
// containing the inherent methods and extension methods. It also // containing the inherent methods and extension methods. It also
@ -235,7 +236,8 @@ pub impl CoherenceChecker {
self.populate_destructor_table(); self.populate_destructor_table();
} }
fn check_implementation(item: @item, associated_traits: ~[@trait_ref]) { fn check_implementation(&self,
item: @item, associated_traits: ~[@trait_ref]) {
let self_type = self.crate_context.tcx.tcache.get( let self_type = self.crate_context.tcx.tcache.get(
&local_def(item.id)); &local_def(item.id));
@ -302,7 +304,8 @@ pub impl CoherenceChecker {
let implementation; let implementation;
match implementation_opt { match implementation_opt {
None => { None => {
implementation = self.create_impl_from_item(item); implementation =
self.create_impl_from_item(item);
} }
Some(copy existing_implementation) => { Some(copy existing_implementation) => {
implementation = existing_implementation; implementation = existing_implementation;
@ -321,7 +324,7 @@ pub impl CoherenceChecker {
// Creates default method IDs and performs type substitutions for an impl // Creates default method IDs and performs type substitutions for an impl
// and trait pair. Then, for each provided method in the trait, inserts a // and trait pair. Then, for each provided method in the trait, inserts a
// `ProvidedMethodInfo` instance into the `provided_method_sources` map. // `ProvidedMethodInfo` instance into the `provided_method_sources` map.
fn instantiate_default_methods(impl_id: ast::node_id, fn instantiate_default_methods(&self, impl_id: ast::node_id,
trait_did: ast::def_id) { trait_did: ast::def_id) {
for self.each_provided_trait_method(trait_did) |trait_method| { for self.each_provided_trait_method(trait_did) |trait_method| {
// Synthesize an ID. // Synthesize an ID.
@ -330,7 +333,8 @@ pub impl CoherenceChecker {
let new_did = local_def(new_id); let new_did = local_def(new_id);
// XXX: Perform substitutions. // XXX: Perform substitutions.
let new_polytype = ty::lookup_item_type(tcx, trait_method.def_id); let new_polytype = ty::lookup_item_type(tcx,
trait_method.def_id);
tcx.tcache.insert(new_did, new_polytype); tcx.tcache.insert(new_did, new_polytype);
// Pair the new synthesized ID up with the // Pair the new synthesized ID up with the
@ -380,7 +384,8 @@ pub impl CoherenceChecker {
} }
} }
fn add_inherent_method(base_def_id: def_id, implementation: @Impl) { fn add_inherent_method(&self,
base_def_id: def_id, implementation: @Impl) {
let implementation_list; let implementation_list;
match self.crate_context.coherence_info.inherent_methods match self.crate_context.coherence_info.inherent_methods
.find(&base_def_id) { .find(&base_def_id) {
@ -397,7 +402,7 @@ pub impl CoherenceChecker {
implementation_list.push(implementation); implementation_list.push(implementation);
} }
fn add_trait_method(trait_id: def_id, implementation: @Impl) { fn add_trait_method(&self, trait_id: def_id, implementation: @Impl) {
let implementation_list; let implementation_list;
match self.crate_context.coherence_info.extension_methods match self.crate_context.coherence_info.extension_methods
.find(&trait_id) { .find(&trait_id) {
@ -414,7 +419,7 @@ pub impl CoherenceChecker {
implementation_list.push(implementation); implementation_list.push(implementation);
} }
fn check_implementation_coherence() { fn check_implementation_coherence(&self) {
let coherence_info = &mut self.crate_context.coherence_info; let coherence_info = &mut self.crate_context.coherence_info;
let extension_methods = &coherence_info.extension_methods; let extension_methods = &coherence_info.extension_methods;
@ -423,7 +428,7 @@ pub impl CoherenceChecker {
} }
} }
fn check_implementation_coherence_of(trait_def_id: def_id) { fn check_implementation_coherence_of(&self, trait_def_id: def_id) {
// Unify pairs of polytypes. // Unify pairs of polytypes.
do self.iter_impls_of_trait(trait_def_id) |a| { do self.iter_impls_of_trait(trait_def_id) |a| {
@ -459,7 +464,8 @@ pub impl CoherenceChecker {
// Adds an impl of trait trait_t for self type self_t; that impl // Adds an impl of trait trait_t for self type self_t; that impl
// is the_impl // is the_impl
fn add_impl_for_trait(trait_t: def_id, self_t: t, the_impl: @Impl) { fn add_impl_for_trait(&self,
trait_t: def_id, self_t: t, the_impl: @Impl) {
debug!("Adding impl %? of %? for %s", debug!("Adding impl %? of %? for %s",
the_impl.did, trait_t, the_impl.did, trait_t,
ty_to_str(self.crate_context.tcx, self_t)); ty_to_str(self.crate_context.tcx, self_t));
@ -475,7 +481,7 @@ pub impl CoherenceChecker {
} }
} }
fn iter_impls_of_trait(trait_def_id: def_id, fn iter_impls_of_trait(&self, trait_def_id: def_id,
f: &fn(@Impl)) { f: &fn(@Impl)) {
let coherence_info = &mut self.crate_context.coherence_info; let coherence_info = &mut self.crate_context.coherence_info;
@ -491,7 +497,7 @@ pub impl CoherenceChecker {
} }
} }
fn each_provided_trait_method( fn each_provided_trait_method(&self,
trait_did: ast::def_id, trait_did: ast::def_id,
f: &fn(x: &ty::method) -> bool) { f: &fn(x: &ty::method) -> bool) {
// Make a list of all the names of the provided methods. // Make a list of all the names of the provided methods.
@ -511,7 +517,7 @@ pub impl CoherenceChecker {
} }
} }
fn polytypes_unify(polytype_a: ty_param_bounds_and_ty, fn polytypes_unify(&self, polytype_a: ty_param_bounds_and_ty,
polytype_b: ty_param_bounds_and_ty) polytype_b: ty_param_bounds_and_ty)
-> bool { -> bool {
let universally_quantified_a = let universally_quantified_a =
@ -527,7 +533,7 @@ pub impl CoherenceChecker {
// Converts a polytype to a monotype by replacing all parameters with // Converts a polytype to a monotype by replacing all parameters with
// type variables. Returns the monotype and the type variables created. // type variables. Returns the monotype and the type variables created.
fn universally_quantify_polytype(polytype: ty_param_bounds_and_ty) fn universally_quantify_polytype(&self, polytype: ty_param_bounds_and_ty)
-> UniversalQuantificationResult { -> UniversalQuantificationResult {
// NDM--this span is bogus. // NDM--this span is bogus.
let self_region = let self_region =
@ -558,7 +564,8 @@ pub impl CoherenceChecker {
} }
} }
fn can_unify_universally_quantified(a: &a/UniversalQuantificationResult, fn can_unify_universally_quantified(&self,
a: &a/UniversalQuantificationResult,
b: &a/UniversalQuantificationResult) b: &a/UniversalQuantificationResult)
-> bool { -> bool {
let mut might_unify = true; let mut might_unify = true;
@ -610,12 +617,13 @@ pub impl CoherenceChecker {
might_unify might_unify
} }
fn get_self_type_for_implementation(implementation: @Impl) fn get_self_type_for_implementation(&self, implementation: @Impl)
-> ty_param_bounds_and_ty { -> ty_param_bounds_and_ty {
return self.crate_context.tcx.tcache.get(&implementation.did); return self.crate_context.tcx.tcache.get(&implementation.did);
} }
// Privileged scope checking // Privileged scope checking
// IMPLICIT SELF WARNING: fix this!
fn check_privileged_scopes(crate: @crate) { fn check_privileged_scopes(crate: @crate) {
visit_crate(*crate, (), mk_vt(@Visitor { visit_crate(*crate, (), mk_vt(@Visitor {
visit_item: |item, _context, visitor| { visit_item: |item, _context, visitor| {
@ -699,7 +707,7 @@ pub impl CoherenceChecker {
})); }));
} }
fn trait_ref_to_trait_def_id(trait_ref: @trait_ref) -> def_id { fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
let def_map = self.crate_context.tcx.def_map; let def_map = self.crate_context.tcx.def_map;
let trait_def = def_map.get(&trait_ref.ref_id); let trait_def = def_map.get(&trait_ref.ref_id);
let trait_id = def_id_of_def(trait_def); let trait_id = def_id_of_def(trait_def);
@ -708,7 +716,7 @@ pub impl CoherenceChecker {
// This check doesn't really have anything to do with coherence. It's // This check doesn't really have anything to do with coherence. It's
// here for historical reasons // here for historical reasons
fn please_check_that_trait_methods_are_implemented( fn please_check_that_trait_methods_are_implemented(&self,
all_methods: &mut ~[@MethodInfo], all_methods: &mut ~[@MethodInfo],
trait_did: def_id, trait_did: def_id,
trait_ref_span: span) { trait_ref_span: span) {
@ -735,7 +743,7 @@ pub impl CoherenceChecker {
} }
// Converts an implementation in the AST to an Impl structure. // Converts an implementation in the AST to an Impl structure.
fn create_impl_from_item(item: @item) -> @Impl { fn create_impl_from_item(&self, item: @item) -> @Impl {
fn add_provided_methods(all_methods: &mut ~[@MethodInfo], fn add_provided_methods(all_methods: &mut ~[@MethodInfo],
all_provided_methods: ~[@ProvidedMethodInfo], all_provided_methods: ~[@ProvidedMethodInfo],
sess: driver::session::Session) { sess: driver::session::Session) {
@ -806,7 +814,7 @@ pub impl CoherenceChecker {
} }
} }
fn span_of_impl(implementation: @Impl) -> span { fn span_of_impl(&self, implementation: @Impl) -> span {
assert implementation.did.crate == local_crate; assert implementation.did.crate == local_crate;
match self.crate_context.tcx.items.find(&implementation.did.node) { match self.crate_context.tcx.items.find(&implementation.did.node) {
Some(node_item(item, _)) => { Some(node_item(item, _)) => {
@ -822,7 +830,7 @@ pub impl CoherenceChecker {
// External crate handling // External crate handling
fn add_impls_for_module(impls_seen: HashMap<def_id,()>, fn add_impls_for_module(&self, impls_seen: HashMap<def_id,()>,
crate_store: @mut CStore, crate_store: @mut CStore,
module_def_id: def_id) { module_def_id: def_id) {
let implementations = get_impls_for_mod(crate_store, let implementations = get_impls_for_mod(crate_store,
@ -907,7 +915,8 @@ pub impl CoherenceChecker {
} }
} }
fn add_default_methods_for_external_trait(trait_def_id: ast::def_id) { fn add_default_methods_for_external_trait(&self,
trait_def_id: ast::def_id) {
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
let pmm = tcx.provided_methods; let pmm = tcx.provided_methods;
@ -942,7 +951,7 @@ pub impl CoherenceChecker {
// Adds implementations and traits from external crates to the coherence // Adds implementations and traits from external crates to the coherence
// info. // info.
fn add_external_crates() { fn add_external_crates(&self) {
let impls_seen = HashMap(); let impls_seen = HashMap();
let crate_store = self.crate_context.tcx.sess.cstore; let crate_store = self.crate_context.tcx.sess.cstore;
@ -983,7 +992,7 @@ pub impl CoherenceChecker {
// Destructors // Destructors
// //
fn populate_destructor_table() { fn populate_destructor_table(&self) {
let coherence_info = &mut self.crate_context.coherence_info; let coherence_info = &mut self.crate_context.coherence_info;
let tcx = self.crate_context.tcx; let tcx = self.crate_context.tcx;
let drop_trait = tcx.lang_items.drop_trait(); let drop_trait = tcx.lang_items.drop_trait();

View File

@ -78,37 +78,38 @@ pub fn macros() {
} }
pub trait Combine { pub trait Combine {
fn infcx() -> @mut InferCtxt; fn infcx(&self) -> @mut InferCtxt;
fn tag() -> ~str; fn tag(&self) -> ~str;
fn a_is_expected() -> bool; fn a_is_expected(&self) -> bool;
fn span() -> span; fn span(&self) -> span;
fn sub() -> Sub; fn sub(&self) -> Sub;
fn lub() -> Lub; fn lub(&self) -> Lub;
fn glb() -> Glb; fn glb(&self) -> Glb;
fn mts(a: ty::mt, b: ty::mt) -> cres<ty::mt>; fn mts(&self, a: ty::mt, b: ty::mt) -> cres<ty::mt>;
fn contratys(a: ty::t, b: ty::t) -> cres<ty::t>; fn contratys(&self, a: ty::t, b: ty::t) -> cres<ty::t>;
fn tys(a: ty::t, b: ty::t) -> cres<ty::t>; fn tys(&self, a: ty::t, b: ty::t) -> cres<ty::t>;
fn tps(as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]>; fn tps(&self, as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]>;
fn self_tys(a: Option<ty::t>, b: Option<ty::t>) -> cres<Option<ty::t>>; fn self_tys(&self, a: Option<ty::t>, b: Option<ty::t>)
fn substs(did: ast::def_id, as_: &ty::substs, -> cres<Option<ty::t>>;
fn substs(&self, did: ast::def_id, as_: &ty::substs,
bs: &ty::substs) -> cres<ty::substs>; bs: &ty::substs) -> cres<ty::substs>;
fn bare_fn_tys(a: &ty::BareFnTy, fn bare_fn_tys(&self, a: &ty::BareFnTy,
b: &ty::BareFnTy) -> cres<ty::BareFnTy>; b: &ty::BareFnTy) -> cres<ty::BareFnTy>;
fn closure_tys(a: &ty::ClosureTy, fn closure_tys(&self, a: &ty::ClosureTy,
b: &ty::ClosureTy) -> cres<ty::ClosureTy>; b: &ty::ClosureTy) -> cres<ty::ClosureTy>;
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig>; fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig>;
fn flds(a: ty::field, b: ty::field) -> cres<ty::field>; fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field>;
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode>; fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode>;
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg>; fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg>;
fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil>; fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil>;
fn purities(a: purity, b: purity) -> cres<purity>; fn purities(&self, a: purity, b: purity) -> cres<purity>;
fn abis(a: ast::Abi, b: ast::Abi) -> cres<ast::Abi>; fn abis(&self, a: ast::Abi, b: ast::Abi) -> cres<ast::Abi>;
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness>; fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<Onceness>;
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region>; fn contraregions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region>;
fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region>; fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region>;
fn vstores(vk: ty::terr_vstore_kind, fn vstores(&self, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore>; a: ty::vstore, b: ty::vstore) -> cres<ty::vstore>;
} }

View File

@ -28,16 +28,16 @@ use std::list;
pub enum Glb = CombineFields; // "greatest lower bound" (common subtype) pub enum Glb = CombineFields; // "greatest lower bound" (common subtype)
pub impl Combine for Glb { pub impl Combine for Glb {
fn infcx() -> @mut InferCtxt { self.infcx } fn infcx(&self) -> @mut InferCtxt { self.infcx }
fn tag() -> ~str { ~"glb" } fn tag(&self) -> ~str { ~"glb" }
fn a_is_expected() -> bool { self.a_is_expected } fn a_is_expected(&self) -> bool { self.a_is_expected }
fn span() -> span { self.span } fn span(&self) -> span { self.span }
fn sub() -> Sub { Sub(*self) } fn sub(&self) -> Sub { Sub(**self) }
fn lub() -> Lub { Lub(*self) } fn lub(&self) -> Lub { Lub(**self) }
fn glb() -> Glb { Glb(*self) } fn glb(&self) -> Glb { Glb(**self) }
fn mts(a: ty::mt, b: ty::mt) -> cres<ty::mt> { fn mts(&self, a: ty::mt, b: ty::mt) -> cres<ty::mt> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
debug!("%s.mts(%s, %s)", debug!("%s.mts(%s, %s)",
@ -49,17 +49,17 @@ pub impl Combine for Glb {
// If one side or both is mut, then the GLB must use // If one side or both is mut, then the GLB must use
// the precise type from the mut side. // the precise type from the mut side.
(m_mutbl, m_const) => { (m_mutbl, m_const) => {
Sub(*self).tys(a.ty, b.ty).chain(|_t| { Sub(**self).tys(a.ty, b.ty).chain(|_t| {
Ok(ty::mt {ty: a.ty, mutbl: m_mutbl}) Ok(ty::mt {ty: a.ty, mutbl: m_mutbl})
}) })
} }
(m_const, m_mutbl) => { (m_const, m_mutbl) => {
Sub(*self).tys(b.ty, a.ty).chain(|_t| { Sub(**self).tys(b.ty, a.ty).chain(|_t| {
Ok(ty::mt {ty: b.ty, mutbl: m_mutbl}) Ok(ty::mt {ty: b.ty, mutbl: m_mutbl})
}) })
} }
(m_mutbl, m_mutbl) => { (m_mutbl, m_mutbl) => {
eq_tys(&self, a.ty, b.ty).then(|| { eq_tys(self, a.ty, b.ty).then(|| {
Ok(ty::mt {ty: a.ty, mutbl: m_mutbl}) Ok(ty::mt {ty: a.ty, mutbl: m_mutbl})
}) })
} }
@ -90,11 +90,11 @@ pub impl Combine for Glb {
} }
} }
fn contratys(a: ty::t, b: ty::t) -> cres<ty::t> { fn contratys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
Lub(*self).tys(a, b) Lub(**self).tys(a, b)
} }
fn purities(a: purity, b: purity) -> cres<purity> { fn purities(&self, a: purity, b: purity) -> cres<purity> {
match (a, b) { match (a, b) {
(pure_fn, _) | (_, pure_fn) => Ok(pure_fn), (pure_fn, _) | (_, pure_fn) => Ok(pure_fn),
(extern_fn, _) | (_, extern_fn) => Ok(extern_fn), (extern_fn, _) | (_, extern_fn) => Ok(extern_fn),
@ -103,14 +103,14 @@ pub impl Combine for Glb {
} }
} }
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness> { fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<Onceness> {
match (a, b) { match (a, b) {
(Many, _) | (_, Many) => Ok(Many), (Many, _) | (_, Many) => Ok(Many),
(Once, Once) => Ok(Once) (Once, Once) => Ok(Once)
} }
} }
fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region> {
debug!("%s.regions(%?, %?)", debug!("%s.regions(%?, %?)",
self.tag(), self.tag(),
a.inf_str(self.infcx), a.inf_str(self.infcx),
@ -121,34 +121,35 @@ pub impl Combine for Glb {
} }
} }
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn contraregions(&self, a: ty::Region, b: ty::Region)
Lub(*self).regions(a, b) -> cres<ty::Region> {
Lub(**self).regions(a, b)
} }
fn tys(a: ty::t, b: ty::t) -> cres<ty::t> { fn tys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
super_lattice_tys(&self, a, b) super_lattice_tys(self, a, b)
} }
// Traits please (FIXME: #2794): // Traits please (FIXME: #2794):
fn flds(a: ty::field, b: ty::field) -> cres<ty::field> { fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field> {
super_flds(&self, a, b) super_flds(self, a, b)
} }
fn vstores(vk: ty::terr_vstore_kind, fn vstores(&self, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> { a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
super_vstores(&self, vk, a, b) super_vstores(self, vk, a, b)
} }
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode> { fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> {
super_modes(&self, a, b) super_modes(self, a, b)
} }
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg> { fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
super_args(&self, a, b) super_args(self, a, b)
} }
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> { fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> {
// Note: this is a subtle algorithm. For a full explanation, // Note: this is a subtle algorithm. For a full explanation,
// please see the large comment in `region_inference.rs`. // please see the large comment in `region_inference.rs`.
@ -166,14 +167,14 @@ pub impl Combine for Glb {
let (a_with_fresh, a_isr) = let (a_with_fresh, a_isr) =
self.infcx.replace_bound_regions_with_fresh_regions( self.infcx.replace_bound_regions_with_fresh_regions(
self.span, a); self.span, a);
let a_vars = var_ids(&self, a_isr); let a_vars = var_ids(self, a_isr);
let (b_with_fresh, b_isr) = let (b_with_fresh, b_isr) =
self.infcx.replace_bound_regions_with_fresh_regions( self.infcx.replace_bound_regions_with_fresh_regions(
self.span, b); self.span, b);
let b_vars = var_ids(&self, b_isr); let b_vars = var_ids(self, b_isr);
// Collect constraints. // Collect constraints.
let sig0 = if_ok!(super_fn_sigs(&self, &a_with_fresh, &b_with_fresh)); let sig0 = if_ok!(super_fn_sigs(self, &a_with_fresh, &b_with_fresh));
debug!("sig0 = %s", sig0.inf_str(self.infcx)); debug!("sig0 = %s", sig0.inf_str(self.infcx));
// Generalize the regions appearing in fn_ty0 if possible // Generalize the regions appearing in fn_ty0 if possible
@ -182,7 +183,7 @@ pub impl Combine for Glb {
let sig1 = let sig1 =
self.infcx.fold_regions_in_sig( self.infcx.fold_regions_in_sig(
&sig0, &sig0,
|r, _in_fn| generalize_region(&self, snapshot, |r, _in_fn| generalize_region(self, snapshot,
new_vars, a_isr, a_vars, b_vars, new_vars, a_isr, a_vars, b_vars,
r)); r));
debug!("sig1 = %s", sig1.inf_str(self.infcx)); debug!("sig1 = %s", sig1.inf_str(self.infcx));
@ -267,36 +268,37 @@ pub impl Combine for Glb {
} }
} }
fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> { fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> {
super_sigils(&self, p1, p2) super_sigils(self, p1, p2)
} }
fn abis(p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> { fn abis(&self, p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> {
super_abis(&self, p1, p2) super_abis(self, p1, p2)
} }
fn bare_fn_tys(a: &ty::BareFnTy, fn bare_fn_tys(&self, a: &ty::BareFnTy,
b: &ty::BareFnTy) -> cres<ty::BareFnTy> { b: &ty::BareFnTy) -> cres<ty::BareFnTy> {
super_bare_fn_tys(&self, a, b) super_bare_fn_tys(self, a, b)
} }
fn closure_tys(a: &ty::ClosureTy, fn closure_tys(&self, a: &ty::ClosureTy,
b: &ty::ClosureTy) -> cres<ty::ClosureTy> { b: &ty::ClosureTy) -> cres<ty::ClosureTy> {
super_closure_tys(&self, a, b) super_closure_tys(self, a, b)
} }
fn substs(did: ast::def_id, fn substs(&self, did: ast::def_id,
as_: &ty::substs, as_: &ty::substs,
bs: &ty::substs) -> cres<ty::substs> { bs: &ty::substs) -> cres<ty::substs> {
super_substs(&self, did, as_, bs) super_substs(self, did, as_, bs)
} }
fn tps(as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> { fn tps(&self, as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> {
super_tps(&self, as_, bs) super_tps(self, as_, bs)
} }
fn self_tys(a: Option<ty::t>, b: Option<ty::t>) -> cres<Option<ty::t>> { fn self_tys(&self, a: Option<ty::t>, b: Option<ty::t>)
super_self_tys(&self, a, b) -> cres<Option<ty::t>> {
super_self_tys(self, a, b)
} }
} }

View File

@ -50,23 +50,27 @@ use middle::typeck::infer::to_str::InferStr;
use std::list; use std::list;
pub trait LatticeValue { pub trait LatticeValue {
static fn sub(cf: &CombineFields, a: &Self, b: &Self) -> ures; static fn sub(&self, cf: &CombineFields, a: &Self, b: &Self) -> ures;
static fn lub(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>; static fn lub(&self, cf: &CombineFields, a: &Self, b: &Self)
static fn glb(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>; -> cres<Self>;
static fn glb(&self, cf: &CombineFields, a: &Self, b: &Self)
-> cres<Self>;
} }
pub type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>; pub type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
pub impl LatticeValue for ty::t { pub impl LatticeValue for ty::t {
static fn sub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures { static fn sub(&self, cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures {
Sub(*cf).tys(*a, *b).to_ures() Sub(*cf).tys(*a, *b).to_ures()
} }
static fn lub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> cres<ty::t> { static fn lub(&self, cf: &CombineFields, a: &ty::t, b: &ty::t)
-> cres<ty::t> {
Lub(*cf).tys(*a, *b) Lub(*cf).tys(*a, *b)
} }
static fn glb(cf: &CombineFields, a: &ty::t, b: &ty::t) -> cres<ty::t> { static fn glb(&self, cf: &CombineFields, a: &ty::t, b: &ty::t)
-> cres<ty::t> {
Glb(*cf).tys(*a, *b) Glb(*cf).tys(*a, *b)
} }
} }
@ -292,39 +296,39 @@ pub impl CombineFields {
// for pairs of variables or for variables and values. // for pairs of variables or for variables and values.
pub trait LatticeDir { pub trait LatticeDir {
fn combine_fields() -> CombineFields; fn combine_fields(&self) -> CombineFields;
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T>; fn bnd<T:Copy>(&self, b: &Bounds<T>) -> Option<T>;
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T>; fn with_bnd<T:Copy>(&self, b: &Bounds<T>, +t: T) -> Bounds<T>;
} }
pub trait TyLatticeDir { pub trait TyLatticeDir {
fn ty_bot(t: ty::t) -> cres<ty::t>; fn ty_bot(&self, t: ty::t) -> cres<ty::t>;
} }
pub impl LatticeDir for Lub { pub impl LatticeDir for Lub {
fn combine_fields() -> CombineFields { *self } fn combine_fields(&self) -> CombineFields { **self }
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T> { b.ub } fn bnd<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { b.ub }
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T> { fn with_bnd<T:Copy>(&self, b: &Bounds<T>, +t: T) -> Bounds<T> {
Bounds { ub: Some(t), ..*b } Bounds { ub: Some(t), ..*b }
} }
} }
pub impl TyLatticeDir for Lub { pub impl TyLatticeDir for Lub {
fn ty_bot(t: ty::t) -> cres<ty::t> { fn ty_bot(&self, t: ty::t) -> cres<ty::t> {
Ok(t) Ok(t)
} }
} }
pub impl LatticeDir for Glb { pub impl LatticeDir for Glb {
fn combine_fields() -> CombineFields { *self } fn combine_fields(&self) -> CombineFields { **self }
fn bnd<T:Copy>(b: &Bounds<T>) -> Option<T> { b.lb } fn bnd<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { b.lb }
fn with_bnd<T:Copy>(b: &Bounds<T>, +t: T) -> Bounds<T> { fn with_bnd<T:Copy>(&self, b: &Bounds<T>, +t: T) -> Bounds<T> {
Bounds { lb: Some(t), ..*b } Bounds { lb: Some(t), ..*b }
} }
} }
pub impl TyLatticeDir for Glb { pub impl TyLatticeDir for Glb {
fn ty_bot(_t: ty::t) -> cres<ty::t> { fn ty_bot(&self, _t: ty::t) -> cres<ty::t> {
Ok(ty::mk_bot(self.infcx.tcx)) Ok(ty::mk_bot(self.infcx.tcx))
} }
} }

View File

@ -32,21 +32,22 @@ pub fn macros() {
pub enum Lub = CombineFields; // least-upper-bound: common supertype pub enum Lub = CombineFields; // least-upper-bound: common supertype
pub impl Lub { pub impl Lub {
fn bot_ty(b: ty::t) -> cres<ty::t> { Ok(b) } fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }
fn ty_bot(b: ty::t) -> cres<ty::t> { self.bot_ty(b) } // commutative fn ty_bot(&self, b: ty::t)
-> cres<ty::t> { self.bot_ty(b) } // commutative
} }
pub impl Combine for Lub { pub impl Combine for Lub {
fn infcx() -> @mut InferCtxt { self.infcx } fn infcx(&self) -> @mut InferCtxt { self.infcx }
fn tag() -> ~str { ~"lub" } fn tag(&self) -> ~str { ~"lub" }
fn a_is_expected() -> bool { self.a_is_expected } fn a_is_expected(&self) -> bool { self.a_is_expected }
fn span() -> span { self.span } fn span(&self) -> span { self.span }
fn sub() -> Sub { Sub(*self) } fn sub(&self) -> Sub { Sub(**self) }
fn lub() -> Lub { Lub(*self) } fn lub(&self) -> Lub { Lub(**self) }
fn glb() -> Glb { Glb(*self) } fn glb(&self) -> Glb { Glb(**self) }
fn mts(a: ty::mt, b: ty::mt) -> cres<ty::mt> { fn mts(&self, a: ty::mt, b: ty::mt) -> cres<ty::mt> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
debug!("%s.mts(%s, %s)", debug!("%s.mts(%s, %s)",
@ -67,7 +68,7 @@ pub impl Combine for Lub {
m_mutbl => { m_mutbl => {
self.infcx.try(|| { self.infcx.try(|| {
eq_tys(&self, a.ty, b.ty).then(|| { eq_tys(self, a.ty, b.ty).then(|| {
Ok(ty::mt {ty: a.ty, mutbl: m}) Ok(ty::mt {ty: a.ty, mutbl: m})
}) })
}).chain_err(|_e| { }).chain_err(|_e| {
@ -79,11 +80,11 @@ pub impl Combine for Lub {
} }
} }
fn contratys(a: ty::t, b: ty::t) -> cres<ty::t> { fn contratys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
Glb(*self).tys(a, b) Glb(**self).tys(a, b)
} }
fn purities(a: purity, b: purity) -> cres<purity> { fn purities(&self, a: purity, b: purity) -> cres<purity> {
match (a, b) { match (a, b) {
(unsafe_fn, _) | (_, unsafe_fn) => Ok(unsafe_fn), (unsafe_fn, _) | (_, unsafe_fn) => Ok(unsafe_fn),
(impure_fn, _) | (_, impure_fn) => Ok(impure_fn), (impure_fn, _) | (_, impure_fn) => Ok(impure_fn),
@ -92,18 +93,19 @@ pub impl Combine for Lub {
} }
} }
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness> { fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<Onceness> {
match (a, b) { match (a, b) {
(Once, _) | (_, Once) => Ok(Once), (Once, _) | (_, Once) => Ok(Once),
(Many, Many) => Ok(Many) (Many, Many) => Ok(Many)
} }
} }
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn contraregions(&self, a: ty::Region, b: ty::Region)
return Glb(*self).regions(a, b); -> cres<ty::Region> {
return Glb(**self).regions(a, b);
} }
fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region> {
debug!("%s.regions(%?, %?)", debug!("%s.regions(%?, %?)",
self.tag(), self.tag(),
a.inf_str(self.infcx), a.inf_str(self.infcx),
@ -114,7 +116,7 @@ pub impl Combine for Lub {
} }
} }
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> { fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> {
// Note: this is a subtle algorithm. For a full explanation, // Note: this is a subtle algorithm. For a full explanation,
// please see the large comment in `region_inference.rs`. // please see the large comment in `region_inference.rs`.
@ -133,7 +135,7 @@ pub impl Combine for Lub {
self.span, b); self.span, b);
// Collect constraints. // Collect constraints.
let sig0 = if_ok!(super_fn_sigs(&self, &a_with_fresh, &b_with_fresh)); let sig0 = if_ok!(super_fn_sigs(self, &a_with_fresh, &b_with_fresh));
debug!("sig0 = %s", sig0.inf_str(self.infcx)); debug!("sig0 = %s", sig0.inf_str(self.infcx));
// Generalize the regions appearing in sig0 if possible // Generalize the regions appearing in sig0 if possible
@ -142,7 +144,7 @@ pub impl Combine for Lub {
let sig1 = let sig1 =
self.infcx.fold_regions_in_sig( self.infcx.fold_regions_in_sig(
&sig0, &sig0,
|r, _in_fn| generalize_region(&self, snapshot, new_vars, |r, _in_fn| generalize_region(self, snapshot, new_vars,
a_isr, r)); a_isr, r));
return Ok(sig1); return Ok(sig1);
@ -191,58 +193,60 @@ pub impl Combine for Lub {
} }
} }
fn bare_fn_tys(a: &ty::BareFnTy, fn bare_fn_tys(&self, a: &ty::BareFnTy,
b: &ty::BareFnTy) -> cres<ty::BareFnTy> { b: &ty::BareFnTy) -> cres<ty::BareFnTy> {
super_bare_fn_tys(&self, a, b) super_bare_fn_tys(self, a, b)
} }
fn closure_tys(a: &ty::ClosureTy, fn closure_tys(&self, a: &ty::ClosureTy,
b: &ty::ClosureTy) -> cres<ty::ClosureTy> { b: &ty::ClosureTy) -> cres<ty::ClosureTy> {
super_closure_tys(&self, a, b) super_closure_tys(self, a, b)
} }
// Traits please (FIXME: #2794): // Traits please (FIXME: #2794):
fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> { fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil)
super_sigils(&self, p1, p2) -> cres<ast::Sigil> {
super_sigils(self, p1, p2)
} }
fn abis(p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> { fn abis(&self, p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> {
super_abis(&self, p1, p2) super_abis(self, p1, p2)
} }
fn tys(a: ty::t, b: ty::t) -> cres<ty::t> { fn tys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
super_lattice_tys(&self, a, b) super_lattice_tys(self, a, b)
} }
fn flds(a: ty::field, b: ty::field) -> cres<ty::field> { fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field> {
super_flds(&self, a, b) super_flds(self, a, b)
} }
fn vstores(vk: ty::terr_vstore_kind, fn vstores(&self, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> { a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
super_vstores(&self, vk, a, b) super_vstores(self, vk, a, b)
} }
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode> { fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> {
super_modes(&self, a, b) super_modes(self, a, b)
} }
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg> { fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
super_args(&self, a, b) super_args(self, a, b)
} }
fn substs(did: ast::def_id, fn substs(&self, did: ast::def_id,
as_: &ty::substs, as_: &ty::substs,
bs: &ty::substs) -> cres<ty::substs> { bs: &ty::substs) -> cres<ty::substs> {
super_substs(&self, did, as_, bs) super_substs(self, did, as_, bs)
} }
fn tps(as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> { fn tps(&self, as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> {
super_tps(&self, as_, bs) super_tps(self, as_, bs)
} }
fn self_tys(a: Option<ty::t>, b: Option<ty::t>) -> cres<Option<ty::t>> { fn self_tys(&self, a: Option<ty::t>, b: Option<ty::t>)
super_self_tys(&self, a, b) -> cres<Option<ty::t>> {
super_self_tys(self, a, b)
} }
} }

View File

@ -489,24 +489,24 @@ fn resolve_borrowings(cx: @mut InferCtxt) {
*/ */
trait then { trait then {
fn then<T:Copy>(f: fn() -> Result<T,ty::type_err>) fn then<T:Copy>(&self, f: fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err>; -> Result<T,ty::type_err>;
} }
impl then for ures { impl then for ures {
fn then<T:Copy>(f: fn() -> Result<T,ty::type_err>) fn then<T:Copy>(&self, f: fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err> { -> Result<T,ty::type_err> {
self.chain(|_i| f()) self.chain(|_i| f())
} }
} }
trait ToUres { trait ToUres {
fn to_ures() -> ures; fn to_ures(&self) -> ures;
} }
impl<T> ToUres for cres<T> { impl<T> ToUres for cres<T> {
fn to_ures() -> ures { fn to_ures(&self) -> ures {
match self { match *self {
Ok(ref _v) => Ok(()), Ok(ref _v) => Ok(()),
Err(ref e) => Err((*e)) Err(ref e) => Err((*e))
} }
@ -514,14 +514,14 @@ impl<T> ToUres for cres<T> {
} }
trait CresCompare<T> { trait CresCompare<T> {
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T>; fn compare(&self, t: T, f: fn() -> ty::type_err) -> cres<T>;
} }
impl<T:Copy + Eq> CresCompare<T> for cres<T> { impl<T:Copy + Eq> CresCompare<T> for cres<T> {
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T> { fn compare(&self, t: T, f: fn() -> ty::type_err) -> cres<T> {
do self.chain |s| { do self.chain |s| {
if s == t { if s == t {
self *self
} else { } else {
Err(f()) Err(f())
} }
@ -551,22 +551,22 @@ struct Snapshot {
} }
impl @mut InferCtxt { impl @mut InferCtxt {
fn combine_fields(a_is_expected: bool, fn combine_fields(&self, a_is_expected: bool,
span: span) -> CombineFields { span: span) -> CombineFields {
CombineFields {infcx: self, CombineFields {infcx: *self,
a_is_expected: a_is_expected, a_is_expected: a_is_expected,
span: span} span: span}
} }
fn sub(a_is_expected: bool, span: span) -> Sub { fn sub(&self, a_is_expected: bool, span: span) -> Sub {
Sub(self.combine_fields(a_is_expected, span)) Sub(self.combine_fields(a_is_expected, span))
} }
fn in_snapshot() -> bool { fn in_snapshot(&self) -> bool {
self.region_vars.in_snapshot() self.region_vars.in_snapshot()
} }
fn start_snapshot() -> Snapshot { fn start_snapshot(&self) -> Snapshot {
Snapshot { Snapshot {
ty_var_bindings_len: ty_var_bindings_len:
self.ty_var_bindings.bindings.len(), self.ty_var_bindings.bindings.len(),
@ -579,7 +579,7 @@ impl @mut InferCtxt {
} }
} }
fn rollback_to(snapshot: &Snapshot) { fn rollback_to(&self, snapshot: &Snapshot) {
debug!("rollback!"); debug!("rollback!");
rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len); rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len);
@ -643,7 +643,7 @@ fn next_simple_var<V:Copy,T:Copy>(
} }
impl @mut InferCtxt { impl @mut InferCtxt {
fn next_ty_var_id() -> TyVid { fn next_ty_var_id(&self) -> TyVid {
let id = self.ty_var_counter; let id = self.ty_var_counter;
self.ty_var_counter += 1; self.ty_var_counter += 1;
let vals = self.ty_var_bindings.vals; let vals = self.ty_var_bindings.vals;
@ -651,37 +651,37 @@ impl @mut InferCtxt {
return TyVid(id); return TyVid(id);
} }
fn next_ty_var() -> ty::t { fn next_ty_var(&self) -> ty::t {
ty::mk_var(self.tcx, self.next_ty_var_id()) ty::mk_var(self.tcx, self.next_ty_var_id())
} }
fn next_ty_vars(n: uint) -> ~[ty::t] { fn next_ty_vars(&self, n: uint) -> ~[ty::t] {
vec::from_fn(n, |_i| self.next_ty_var()) vec::from_fn(n, |_i| self.next_ty_var())
} }
fn next_int_var_id() -> IntVid { fn next_int_var_id(&self) -> IntVid {
IntVid(next_simple_var(&mut self.int_var_counter, IntVid(next_simple_var(&mut self.int_var_counter,
&mut self.int_var_bindings)) &mut self.int_var_bindings))
} }
fn next_int_var() -> ty::t { fn next_int_var(&self) -> ty::t {
ty::mk_int_var(self.tcx, self.next_int_var_id()) ty::mk_int_var(self.tcx, self.next_int_var_id())
} }
fn next_float_var_id() -> FloatVid { fn next_float_var_id(&self) -> FloatVid {
FloatVid(next_simple_var(&mut self.float_var_counter, FloatVid(next_simple_var(&mut self.float_var_counter,
&mut self.float_var_bindings)) &mut self.float_var_bindings))
} }
fn next_float_var() -> ty::t { fn next_float_var(&self) -> ty::t {
ty::mk_float_var(self.tcx, self.next_float_var_id()) ty::mk_float_var(self.tcx, self.next_float_var_id())
} }
fn next_region_var_nb(span: span) -> ty::Region { fn next_region_var_nb(&self, span: span) -> ty::Region {
ty::re_infer(ty::ReVar(self.region_vars.new_region_var(span))) ty::re_infer(ty::ReVar(self.region_vars.new_region_var(span)))
} }
fn next_region_var_with_lb(span: span, fn next_region_var_with_lb(&self, span: span,
lb_region: ty::Region) -> ty::Region { lb_region: ty::Region) -> ty::Region {
let region_var = self.next_region_var_nb(span); let region_var = self.next_region_var_nb(span);
@ -693,27 +693,28 @@ impl @mut InferCtxt {
return region_var; return region_var;
} }
fn next_region_var(span: span, scope_id: ast::node_id) -> ty::Region { fn next_region_var(&self, span: span, scope_id: ast::node_id)
-> ty::Region {
self.next_region_var_with_lb(span, ty::re_scope(scope_id)) self.next_region_var_with_lb(span, ty::re_scope(scope_id))
} }
fn resolve_regions() { fn resolve_regions(&self) {
self.region_vars.resolve_regions(); self.region_vars.resolve_regions();
} }
fn ty_to_str(t: ty::t) -> ~str { fn ty_to_str(&self, t: ty::t) -> ~str {
ty_to_str(self.tcx, ty_to_str(self.tcx,
self.resolve_type_vars_if_possible(t)) self.resolve_type_vars_if_possible(t))
} }
fn resolve_type_vars_if_possible(typ: ty::t) -> ty::t { fn resolve_type_vars_if_possible(&self, typ: ty::t) -> ty::t {
match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) { match resolve_type(*self, typ, resolve_nested_tvar | resolve_ivar) {
result::Ok(new_type) => new_type, result::Ok(new_type) => new_type,
result::Err(_) => typ result::Err(_) => typ
} }
} }
fn type_error_message(sp: span, mk_msg: fn(~str) -> ~str, fn type_error_message(&self, sp: span, mk_msg: fn(~str) -> ~str,
actual_ty: ty::t, err: Option<&ty::type_err>) { actual_ty: ty::t, err: Option<&ty::type_err>) {
let actual_ty = self.resolve_type_vars_if_possible(actual_ty); let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
@ -731,7 +732,7 @@ impl @mut InferCtxt {
ty::note_and_explain_type_err(self.tcx, *err)); ty::note_and_explain_type_err(self.tcx, *err));
} }
fn report_mismatched_types(sp: span, e: ty::t, a: ty::t, fn report_mismatched_types(&self, sp: span, e: ty::t, a: ty::t,
err: &ty::type_err) { err: &ty::type_err) {
// Don't report an error if expected is ty_err // Don't report an error if expected is ty_err
let resolved_expected = let resolved_expected =
@ -749,7 +750,7 @@ impl @mut InferCtxt {
self.type_error_message(sp, mk_msg, a, Some(err)); self.type_error_message(sp, mk_msg, a, Some(err));
} }
fn replace_bound_regions_with_fresh_regions( fn replace_bound_regions_with_fresh_regions(&self,
span: span, span: span,
fsig: &ty::FnSig) fsig: &ty::FnSig)
-> (ty::FnSig, isr_alist) { -> (ty::FnSig, isr_alist) {

View File

@ -33,30 +33,31 @@ pub fn macros() {
pub enum Sub = CombineFields; // "subtype", "subregion" etc pub enum Sub = CombineFields; // "subtype", "subregion" etc
pub impl Combine for Sub { pub impl Combine for Sub {
fn infcx() -> @mut InferCtxt { self.infcx } fn infcx(&self) -> @mut InferCtxt { self.infcx }
fn tag() -> ~str { ~"sub" } fn tag(&self) -> ~str { ~"sub" }
fn a_is_expected() -> bool { self.a_is_expected } fn a_is_expected(&self) -> bool { self.a_is_expected }
fn span() -> span { self.span } fn span(&self) -> span { self.span }
fn sub() -> Sub { Sub(*self) } fn sub(&self) -> Sub { Sub(**self) }
fn lub() -> Lub { Lub(*self) } fn lub(&self) -> Lub { Lub(**self) }
fn glb() -> Glb { Glb(*self) } fn glb(&self) -> Glb { Glb(**self) }
fn contratys(a: ty::t, b: ty::t) -> cres<ty::t> { fn contratys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
let opp = CombineFields { let opp = CombineFields {
a_is_expected: !self.a_is_expected,.. *self a_is_expected: !self.a_is_expected,.. **self
}; };
Sub(opp).tys(b, a) Sub(opp).tys(b, a)
} }
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn contraregions(&self, a: ty::Region, b: ty::Region)
-> cres<ty::Region> {
let opp = CombineFields { let opp = CombineFields {
a_is_expected: !self.a_is_expected,.. *self a_is_expected: !self.a_is_expected,.. **self
}; };
Sub(opp).regions(b, a) Sub(opp).regions(b, a)
} }
fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region> { fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region> {
debug!("%s.regions(%s, %s)", debug!("%s.regions(%s, %s)",
self.tag(), self.tag(),
a.inf_str(self.infcx), a.inf_str(self.infcx),
@ -69,7 +70,7 @@ pub impl Combine for Sub {
} }
} }
fn mts(a: ty::mt, b: ty::mt) -> cres<ty::mt> { fn mts(&self, a: ty::mt, b: ty::mt) -> cres<ty::mt> {
debug!("mts(%s <: %s)", a.inf_str(self.infcx), b.inf_str(self.infcx)); debug!("mts(%s <: %s)", a.inf_str(self.infcx), b.inf_str(self.infcx));
if a.mutbl != b.mutbl && b.mutbl != m_const { if a.mutbl != b.mutbl && b.mutbl != m_const {
@ -80,7 +81,7 @@ pub impl Combine for Sub {
m_mutbl => { m_mutbl => {
// If supertype is mut, subtype must match exactly // If supertype is mut, subtype must match exactly
// (i.e., invariant if mut): // (i.e., invariant if mut):
eq_tys(&self, a.ty, b.ty).then(|| Ok(a) ) eq_tys(self, a.ty, b.ty).then(|| Ok(a) )
} }
m_imm | m_const => { m_imm | m_const => {
// Otherwise we can be covariant: // Otherwise we can be covariant:
@ -89,19 +90,19 @@ pub impl Combine for Sub {
} }
} }
fn purities(a: purity, b: purity) -> cres<purity> { fn purities(&self, a: purity, b: purity) -> cres<purity> {
self.lub().purities(a, b).compare(b, || { self.lub().purities(a, b).compare(b, || {
ty::terr_purity_mismatch(expected_found(&self, a, b)) ty::terr_purity_mismatch(expected_found(self, a, b))
}) })
} }
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness> { fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<Onceness> {
self.lub().oncenesses(a, b).compare(b, || { self.lub().oncenesses(a, b).compare(b, || {
ty::terr_onceness_mismatch(expected_found(&self, a, b)) ty::terr_onceness_mismatch(expected_found(self, a, b))
}) })
} }
fn tys(a: ty::t, b: ty::t) -> cres<ty::t> { fn tys(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
debug!("%s.tys(%s, %s)", self.tag(), debug!("%s.tys(%s, %s)", self.tag(),
a.inf_str(self.infcx), b.inf_str(self.infcx)); a.inf_str(self.infcx), b.inf_str(self.infcx));
if a == b { return Ok(a); } if a == b { return Ok(a); }
@ -125,16 +126,16 @@ pub impl Combine for Sub {
} }
(_, &ty::ty_bot) => { (_, &ty::ty_bot) => {
Err(ty::terr_sorts(expected_found(&self, a, b))) Err(ty::terr_sorts(expected_found(self, a, b)))
} }
_ => { _ => {
super_tys(&self, a, b) super_tys(self, a, b)
} }
} }
} }
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> { fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> {
debug!("fn_sigs(a=%s, b=%s)", debug!("fn_sigs(a=%s, b=%s)",
a.inf_str(self.infcx), b.inf_str(self.infcx)); a.inf_str(self.infcx), b.inf_str(self.infcx));
let _indenter = indenter(); let _indenter = indenter();
@ -175,7 +176,7 @@ pub impl Combine for Sub {
debug!("b_sig=%s", b_sig.inf_str(self.infcx)); debug!("b_sig=%s", b_sig.inf_str(self.infcx));
// Compare types now that bound regions have been replaced. // Compare types now that bound regions have been replaced.
let sig = if_ok!(super_fn_sigs(&self, &a_sig, &b_sig)); let sig = if_ok!(super_fn_sigs(self, &a_sig, &b_sig));
// Presuming type comparison succeeds, we need to check // Presuming type comparison succeeds, we need to check
// that the skolemized regions do not "leak". // that the skolemized regions do not "leak".
@ -212,53 +213,54 @@ pub impl Combine for Sub {
// Traits please (FIXME: #2794): // Traits please (FIXME: #2794):
fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> { fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil> {
super_sigils(&self, p1, p2) super_sigils(self, p1, p2)
} }
fn abis(p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> { fn abis(&self, p1: ast::Abi, p2: ast::Abi) -> cres<ast::Abi> {
super_abis(&self, p1, p2) super_abis(self, p1, p2)
} }
fn flds(a: ty::field, b: ty::field) -> cres<ty::field> { fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field> {
super_flds(&self, a, b) super_flds(self, a, b)
} }
fn bare_fn_tys(a: &ty::BareFnTy, fn bare_fn_tys(&self, a: &ty::BareFnTy,
b: &ty::BareFnTy) -> cres<ty::BareFnTy> { b: &ty::BareFnTy) -> cres<ty::BareFnTy> {
super_bare_fn_tys(&self, a, b) super_bare_fn_tys(self, a, b)
} }
fn closure_tys(a: &ty::ClosureTy, fn closure_tys(&self, a: &ty::ClosureTy,
b: &ty::ClosureTy) -> cres<ty::ClosureTy> { b: &ty::ClosureTy) -> cres<ty::ClosureTy> {
super_closure_tys(&self, a, b) super_closure_tys(self, a, b)
} }
fn vstores(vk: ty::terr_vstore_kind, fn vstores(&self, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> { a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
super_vstores(&self, vk, a, b) super_vstores(self, vk, a, b)
} }
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode> { fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> {
super_modes(&self, a, b) super_modes(self, a, b)
} }
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg> { fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
super_args(&self, a, b) super_args(self, a, b)
} }
fn substs(did: ast::def_id, fn substs(&self, did: ast::def_id,
as_: &ty::substs, as_: &ty::substs,
bs: &ty::substs) -> cres<ty::substs> { bs: &ty::substs) -> cres<ty::substs> {
super_substs(&self, did, as_, bs) super_substs(self, did, as_, bs)
} }
fn tps(as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> { fn tps(&self, as_: &[ty::t], bs: &[ty::t]) -> cres<~[ty::t]> {
super_tps(&self, as_, bs) super_tps(self, as_, bs)
} }
fn self_tys(a: Option<ty::t>, b: Option<ty::t>) -> cres<Option<ty::t>> { fn self_tys(&self, a: Option<ty::t>, b: Option<ty::t>)
super_self_tys(&self, a, b) -> cres<Option<ty::t>> {
super_self_tys(self, a, b)
} }
} }

View File

@ -38,7 +38,7 @@ pub struct Node<V, T> {
} }
pub trait UnifyVid<T> { pub trait UnifyVid<T> {
static fn appropriate_vals_and_bindings(infcx: &v/mut InferCtxt) static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt)
-> &v/mut ValsAndBindings<Self, T>; -> &v/mut ValsAndBindings<Self, T>;
} }
@ -147,7 +147,7 @@ pub impl InferCtxt {
// doesn't have a subtyping relationship we need to worry about. // doesn't have a subtyping relationship we need to worry about.
pub trait SimplyUnifiable { pub trait SimplyUnifiable {
static fn to_type_err(expected_found<Self>) -> ty::type_err; static fn to_type_err(&self, expected_found<Self>) -> ty::type_err;
} }
pub fn mk_err<T:SimplyUnifiable>(+a_is_expected: bool, pub fn mk_err<T:SimplyUnifiable>(+a_is_expected: bool,
@ -238,35 +238,35 @@ pub impl InferCtxt {
// ______________________________________________________________________ // ______________________________________________________________________
pub impl UnifyVid<Bounds<ty::t>> for ty::TyVid { pub impl UnifyVid<Bounds<ty::t>> for ty::TyVid {
static fn appropriate_vals_and_bindings(infcx: &v/mut InferCtxt) static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt)
-> &v/mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> { -> &v/mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> {
return &mut infcx.ty_var_bindings; return &mut infcx.ty_var_bindings;
} }
} }
pub impl UnifyVid<Option<IntVarValue>> for ty::IntVid { pub impl UnifyVid<Option<IntVarValue>> for ty::IntVid {
static fn appropriate_vals_and_bindings(infcx: &v/mut InferCtxt) static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt)
-> &v/mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> { -> &v/mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> {
return &mut infcx.int_var_bindings; return &mut infcx.int_var_bindings;
} }
} }
pub impl SimplyUnifiable for IntVarValue { pub impl SimplyUnifiable for IntVarValue {
static fn to_type_err(err: expected_found<IntVarValue>) static fn to_type_err(&self, err: expected_found<IntVarValue>)
-> ty::type_err { -> ty::type_err {
return ty::terr_int_mismatch(err); return ty::terr_int_mismatch(err);
} }
} }
pub impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid { pub impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid {
static fn appropriate_vals_and_bindings(infcx: &v/mut InferCtxt) static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt)
-> &v/mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> { -> &v/mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> {
return &mut infcx.float_var_bindings; return &mut infcx.float_var_bindings;
} }
} }
pub impl SimplyUnifiable for ast::float_ty { pub impl SimplyUnifiable for ast::float_ty {
static fn to_type_err(err: expected_found<ast::float_ty>) static fn to_type_err(&self, err: expected_found<ast::float_ty>)
-> ty::type_err { -> ty::type_err {
return ty::terr_float_mismatch(err); return ty::terr_float_mismatch(err);
} }

View File

@ -172,8 +172,8 @@ pub enum vtable_origin {
} }
pub impl vtable_origin { pub impl vtable_origin {
fn to_str(tcx: ty::ctxt) -> ~str { fn to_str(&self, tcx: ty::ctxt) -> ~str {
match self { match *self {
vtable_static(def_id, ref tys, ref vtable_res) => { vtable_static(def_id, ref tys, ref vtable_res) => {
fmt!("vtable_static(%?:%s, %?, %?)", fmt!("vtable_static(%?:%s, %?, %?)",
def_id, ty::item_path_str(tcx, def_id), def_id, ty::item_path_str(tcx, def_id),
@ -279,17 +279,17 @@ pub fn require_same_types(
pub type isr_alist = @List<(ty::bound_region, ty::Region)>; pub type isr_alist = @List<(ty::bound_region, ty::Region)>;
trait get_and_find_region { trait get_and_find_region {
fn get(br: ty::bound_region) -> ty::Region; fn get(&self, br: ty::bound_region) -> ty::Region;
fn find(br: ty::bound_region) -> Option<ty::Region>; fn find(&self, br: ty::bound_region) -> Option<ty::Region>;
} }
impl get_and_find_region for isr_alist { impl get_and_find_region for isr_alist {
fn get(br: ty::bound_region) -> ty::Region { fn get(&self, br: ty::bound_region) -> ty::Region {
self.find(br).get() self.find(br).get()
} }
fn find(br: ty::bound_region) -> Option<ty::Region> { fn find(&self, br: ty::bound_region) -> Option<ty::Region> {
for list::each(self) |isr| { for list::each(*self) |isr| {
let (isr_br, isr_r) = *isr; let (isr_br, isr_r) = *isr;
if isr_br == br { return Some(isr_r); } if isr_br == br { return Some(isr_r); }
} }

View File

@ -19,21 +19,21 @@ use syntax::codemap::span;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
pub trait region_scope { pub trait region_scope {
pure fn anon_region(span: span) -> Result<ty::Region, ~str>; pure fn anon_region(&self, span: span) -> Result<ty::Region, ~str>;
pure fn self_region(span: span) -> Result<ty::Region, ~str>; pure fn self_region(&self, span: span) -> Result<ty::Region, ~str>;
pure fn named_region(span: span, id: ast::ident) pure fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, ~str>; -> Result<ty::Region, ~str>;
} }
pub enum empty_rscope { empty_rscope } pub enum empty_rscope { empty_rscope }
pub impl region_scope for empty_rscope { pub impl region_scope for empty_rscope {
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> { pure fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
result::Ok(ty::re_static) result::Ok(ty::re_static)
} }
pure fn self_region(_span: span) -> Result<ty::Region, ~str> { pure fn self_region(&self, _span: span) -> Result<ty::Region, ~str> {
result::Err(~"only the static region is allowed here") result::Err(~"only the static region is allowed here")
} }
pure fn named_region(_span: span, _id: ast::ident) pure fn named_region(&self, _span: span, _id: ast::ident)
-> Result<ty::Region, ~str> { -> Result<ty::Region, ~str> {
result::Err(~"only the static region is allowed here") result::Err(~"only the static region is allowed here")
} }
@ -41,17 +41,17 @@ pub impl region_scope for empty_rscope {
pub enum type_rscope = Option<ty::region_variance>; pub enum type_rscope = Option<ty::region_variance>;
pub impl region_scope for type_rscope { pub impl region_scope for type_rscope {
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> { pure fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
match *self { match **self {
Some(_) => result::Ok(ty::re_bound(ty::br_self)), Some(_) => result::Ok(ty::re_bound(ty::br_self)),
None => result::Err(~"to use region types here, the containing \ None => result::Err(~"to use region types here, the containing \
type must be declared with a region bound") type must be declared with a region bound")
} }
} }
pure fn self_region(span: span) -> Result<ty::Region, ~str> { pure fn self_region(&self, span: span) -> Result<ty::Region, ~str> {
self.anon_region(span) self.anon_region(span)
} }
pure fn named_region(span: span, id: ast::ident) pure fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, ~str> { -> Result<ty::Region, ~str> {
do empty_rscope.named_region(span, id).chain_err |_e| { do empty_rscope.named_region(span, id).chain_err |_e| {
result::Err(~"named regions other than `self` are not \ result::Err(~"named regions other than `self` are not \
@ -75,13 +75,13 @@ pub fn in_anon_rscope<RS:region_scope + Copy + Durable>(self: RS,
@anon_rscope {anon: r, base: self as region_scope} @anon_rscope {anon: r, base: self as region_scope}
} }
pub impl region_scope for @anon_rscope { pub impl region_scope for @anon_rscope {
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> { pure fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
result::Ok(self.anon) result::Ok(self.anon)
} }
pure fn self_region(span: span) -> Result<ty::Region, ~str> { pure fn self_region(&self, span: span) -> Result<ty::Region, ~str> {
self.base.self_region(span) self.base.self_region(span)
} }
pure fn named_region(span: span, id: ast::ident) pure fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, ~str> { -> Result<ty::Region, ~str> {
self.base.named_region(span, id) self.base.named_region(span, id)
} }
@ -98,7 +98,7 @@ pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(self: RS)
@mut binding_rscope { base: base, anon_bindings: 0 } @mut binding_rscope { base: base, anon_bindings: 0 }
} }
pub impl region_scope for @mut binding_rscope { pub impl region_scope for @mut binding_rscope {
pure fn anon_region(_span: span) -> Result<ty::Region, ~str> { pure fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
// XXX: Unsafe to work around purity // XXX: Unsafe to work around purity
unsafe { unsafe {
let idx = self.anon_bindings; let idx = self.anon_bindings;
@ -106,10 +106,10 @@ pub impl region_scope for @mut binding_rscope {
result::Ok(ty::re_bound(ty::br_anon(idx))) result::Ok(ty::re_bound(ty::br_anon(idx)))
} }
} }
pure fn self_region(span: span) -> Result<ty::Region, ~str> { pure fn self_region(&self, span: span) -> Result<ty::Region, ~str> {
self.base.self_region(span) self.base.self_region(span)
} }
pure fn named_region(span: span, id: ast::ident) pure fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, ~str> { -> Result<ty::Region, ~str> {
do self.base.named_region(span, id).chain_err |_e| { do self.base.named_region(span, id).chain_err |_e| {
result::Ok(ty::re_bound(ty::br_named(id))) result::Ok(ty::re_bound(ty::br_named(id)))