Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor self-info #5435

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply explicit self transformation before we enter check_fn
  • Loading branch information
nikomatsakis committed Mar 20, 2013
commit ad70c748c35958f8afdc70cf67054dd1968e4b78
53 changes: 17 additions & 36 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ pub mod method;
pub struct SelfInfo {
self_ty: ty::t,
self_id: ast::node_id,
def_id: ast::def_id,
explicit_self: ast::self_ty
span: span
}

/// Fields that are part of a `FnCtxt` which are inherited by
Expand Down Expand Up @@ -339,25 +338,6 @@ pub fn check_fn(ccx: @mut CrateCtxt,
}
};

// Update the SelfInfo to contain an accurate self type (taking
// into account explicit self).
let self_info = do self_info.chain_ref |self_info| {
// If the self type is sty_static, we don't have a self ty.
if self_info.explicit_self.node == ast::sty_static {
None
} else {
let in_scope_regions = fcx.in_scope_regions;
let self_region = in_scope_regions.find(ty::br_self);
let ty = method::transform_self_type_for_method(
fcx.tcx(),
self_region,
self_info.self_ty,
self_info.explicit_self.node,
TransformTypeNormally);
Some(SelfInfo { self_ty: ty,.. *self_info })
}
};

gather_locals(fcx, decl, body, arg_tys, self_info);
check_block(fcx, body);

Expand Down Expand Up @@ -495,20 +475,25 @@ pub fn check_fn(ccx: @mut CrateCtxt,

pub fn check_method(ccx: @mut CrateCtxt,
method: @ast::method,
self_ty: ty::t,
self_impl_def_id: ast::def_id) {
let self_info = SelfInfo {
self_ty: self_ty,
self_id: method.self_id,
def_id: self_impl_def_id,
explicit_self: method.self_ty
self_ty: ty::t)
{
let self_info = if method.self_ty.node == ast::sty_static {None} else {
let ty = method::transform_self_type_for_method(
ccx.tcx,
Some(ty::re_bound(ty::br_self)),
self_ty,
method.self_ty.node,
TransformTypeNormally);
Some(SelfInfo {self_ty: ty, self_id: method.self_id,
span: method.self_ty.span})
};

check_bare_fn(
ccx,
&method.decl,
&method.body,
method.id,
Some(self_info)
self_info
);
}

Expand Down Expand Up @@ -545,11 +530,7 @@ pub fn check_struct(ccx: @mut CrateCtxt,
let class_t = SelfInfo {
self_ty: self_ty,
self_id: dtor.node.self_id,
def_id: local_def(id),
explicit_self: spanned {
node: ast::sty_by_ref,
span: codemap::dummy_sp()
}
span: dtor.span,
};
// typecheck the dtor
let dtor_dec = ast_util::dtor_dec();
Expand Down Expand Up @@ -589,7 +570,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
*ccx.tcx.sess.str_of(it.ident), it.id, rp);
let self_ty = ccx.to_ty(&rscope::type_rscope(rp), ty);
for ms.each |m| {
check_method(ccx, *m, self_ty, local_def(it.id));
check_method(ccx, *m, self_ty);
}
}
ast::item_trait(_, _, ref trait_methods) => {
Expand All @@ -601,7 +582,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
}
provided(m) => {
let self_ty = ty::mk_self(ccx.tcx, local_def(it.id));
check_method(ccx, m, self_ty, local_def(it.id));
check_method(ccx, m, self_ty);
}
}
}
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/middle/typeck/check/regionmanip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,8 @@ pub fn replace_bound_regions_in_fn_sig(

let mut all_tys = ty::tys_in_fn_sig(fn_sig);

match self_info {
Some(SelfInfo {
explicit_self: codemap::spanned {
node: ast::sty_region(_, m),
// FIXME(#4846) ------^ Use this lifetime instead of self
_}, _}) => {
let region = ty::re_bound(ty::br_self);
let ty = ty::mk_rptr(tcx, region,
ty::mt { ty: ty::mk_nil(tcx), mutbl: m });
all_tys.push(ty);
}
_ => {}
for self_info.each |self_info| {
all_tys.push(self_info.self_ty);
}

for self_ty.each |t| { all_tys.push(*t) }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt,
let visit = mk_visitor();
(visit.visit_block)(blk, wbcx, visit);
for self_info.each |self_info| {
if self_info.explicit_self.node == ast::sty_static { break; }
resolve_type_vars_for_node(wbcx, self_info.explicit_self.span,
resolve_type_vars_for_node(wbcx,
self_info.span,
self_info.self_id);
}
for decl.inputs.each |arg| {
Expand Down