Skip to content

rustc: remove the use of Gc in middle::def::Def. #17259

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

Merged
merged 6 commits into from
Sep 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lint;
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use metadata::creader;
use middle::{trans, freevars, stability, kind, ty, typeck, reachable};
use middle::{trans, stability, kind, ty, typeck, reachable};
use middle::dependency_format;
use middle;
use plugin::load::Plugins;
Expand Down Expand Up @@ -378,11 +378,13 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
middle::lang_items::collect_language_items(krate, &sess));

let middle::resolve::CrateMap {
def_map: def_map,
exp_map2: exp_map2,
trait_map: trait_map,
external_exports: external_exports,
last_private_map: last_private_map
def_map,
freevars,
capture_mode_map,
exp_map2,
trait_map,
external_exports,
last_private_map
} =
time(time_passes, "resolution", (), |_|
middle::resolve::resolve_crate(&sess, &lang_items, krate));
Expand All @@ -401,10 +403,6 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
plugin::build::find_plugin_registrar(
sess.diagnostic(), krate)));

let (freevars, capture_modes) =
time(time_passes, "freevar finding", (), |_|
freevars::annotate_freevars(&def_map, krate));

let region_map = time(time_passes, "region resolution", (), |_|
middle::region::resolve_crate(&sess, krate));

Expand All @@ -423,7 +421,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
named_region_map,
ast_map,
freevars,
capture_modes,
capture_mode_map,
region_map,
lang_items,
stability_index);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This API is completely unstable and subject to change.
html_root_url = "http://doc.rust-lang.org/master/")]

#![allow(deprecated)]
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote)]
#![feature(macro_rules, globs, struct_variant, quote)]
#![feature(default_type_params, phase, unsafe_destructor)]

#![allow(unknown_features)] // NOTE: Remove after next snapshot
Expand Down Expand Up @@ -93,7 +93,6 @@ pub mod middle {
pub mod effect;
pub mod entry;
pub mod expr_use_visitor;
pub mod freevars;
pub mod graph;
pub mod intrinsicck;
pub mod kind;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,7 @@ impl LintPass for NonSnakeCase {
match &p.node {
&ast::PatIdent(_, ref path1, _) => {
match cx.tcx.def_map.borrow().find(&p.id) {
Some(&def::DefLocal(_, _)) | Some(&def::DefBinding(_, _)) |
Some(&def::DefArg(_, _)) => {
Some(&def::DefLocal(_)) => {
self.check_snake_case(cx, "variable", path1.node, p.span);
}
_ => {}
Expand Down
37 changes: 16 additions & 21 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ use driver::session::Session;
use metadata::decoder;
use middle::def;
use metadata::encoder as e;
use middle::freevars::{CaptureMode, freevar_entry};
use middle::freevars;
use middle::region;
use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
use metadata::tydecode::{RegionParameter};
use metadata::tyencode;
use middle::mem_categorization::Typer;
use middle::subst;
use middle::subst::VecPerParamSpace;
use middle::typeck::{MethodCall, MethodCallee, MethodOrigin};
Expand All @@ -42,7 +41,6 @@ use syntax;
use libc;
use std::io::Seek;
use std::mem;
use std::gc::GC;
use std::rc::Rc;

use rbml::io::SeekableMemWriter;
Expand Down Expand Up @@ -462,8 +460,7 @@ impl tr for def::Def {
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) }
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
def::DefArg(nid, b) => { def::DefArg(dcx.tr_id(nid), b) }
def::DefLocal(nid, b) => { def::DefLocal(dcx.tr_id(nid), b) }
def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) }
def::DefVariant(e_did, v_did, is_s) => {
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
},
Expand All @@ -472,11 +469,9 @@ impl tr for def::Def {
def::DefAssociatedTy(did) => def::DefAssociatedTy(did.tr(dcx)),
def::DefPrimTy(p) => def::DefPrimTy(p),
def::DefTyParam(s, did, v) => def::DefTyParam(s, did.tr(dcx), v),
def::DefBinding(nid, bm) => def::DefBinding(dcx.tr_id(nid), bm),
def::DefUse(did) => def::DefUse(did.tr(dcx)),
def::DefUpvar(nid1, def, nid2, nid3) => {
def::DefUpvar(nid1, nid2, nid3) => {
def::DefUpvar(dcx.tr_id(nid1),
box(GC) (*def).tr(dcx),
dcx.tr_id(nid2),
dcx.tr_id(nid3))
}
Expand Down Expand Up @@ -541,36 +536,36 @@ impl tr for ty::TraitStore {
// ______________________________________________________________________
// Encoding and decoding of freevar information

fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &freevar_entry) {
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &ty::Freevar) {
(*fv).encode(rbml_w).unwrap();
}

fn encode_capture_mode(rbml_w: &mut Encoder, cm: CaptureMode) {
fn encode_capture_mode(rbml_w: &mut Encoder, cm: ast::CaptureClause) {
cm.encode(rbml_w).unwrap();
}

trait rbml_decoder_helper {
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
-> freevar_entry;
fn read_capture_mode(&mut self) -> CaptureMode;
-> ty::Freevar;
fn read_capture_mode(&mut self) -> ast::CaptureClause;
}

impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
-> freevar_entry {
let fv: freevar_entry = Decodable::decode(self).unwrap();
-> ty::Freevar {
let fv: ty::Freevar = Decodable::decode(self).unwrap();
fv.tr(dcx)
}

fn read_capture_mode(&mut self) -> CaptureMode {
let cm: CaptureMode = Decodable::decode(self).unwrap();
fn read_capture_mode(&mut self) -> ast::CaptureClause {
let cm: ast::CaptureClause = Decodable::decode(self).unwrap();
cm
}
}

impl tr for freevar_entry {
fn tr(&self, dcx: &DecodeContext) -> freevar_entry {
freevar_entry {
impl tr for ty::Freevar {
fn tr(&self, dcx: &DecodeContext) -> ty::Freevar {
ty::Freevar {
def: self.def.tr(dcx),
span: self.span.tr(dcx),
}
Expand Down Expand Up @@ -1292,8 +1287,8 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
});

for freevar in fv.iter() {
match freevars::get_capture_mode(tcx, id) {
freevars::CaptureByRef => {
match tcx.capture_mode(id) {
ast::CaptureByRef => {
rbml_w.tag(c::tag_table_upvar_borrow_map, |rbml_w| {
rbml_w.id(id);
rbml_w.tag(c::tag_table_val, |rbml_w| {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
true
}

pub fn is_local_variable_or_arg(&self, cmt: mc::cmt) -> bool {
fn is_local_variable_or_arg(&self, cmt: mc::cmt) -> bool {
match cmt.cat {
mc::cat_local(_) | mc::cat_arg(_) => true,
mc::cat_local(_) => true,
_ => false
}
}
Expand Down Expand Up @@ -775,7 +775,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
debug!("mark_variable_as_used_mut(cmt={})", cmt.repr(this.tcx()));
match cmt.cat.clone() {
mc::cat_copied_upvar(mc::CopiedUpvar { upvar_id: id, .. }) |
mc::cat_local(id) | mc::cat_arg(id) => {
mc::cat_local(id) => {
this.tcx().used_mut_nodes.borrow_mut().insert(id);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/borrowck/gather_loans/gather_moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt,
}

mc::cat_rvalue(..) |
mc::cat_local(..) |
mc::cat_arg(..) => {
mc::cat_local(..) => {
None
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
mc::cat_rvalue(..) |
mc::cat_copied_upvar(..) | // L-Local
mc::cat_local(..) | // L-Local
mc::cat_arg(..) | // L-Local
mc::cat_upvar(..) |
mc::cat_deref(_, _, mc::BorrowedPtr(..)) | // L-Deref-Borrowed
mc::cat_deref(_, _, mc::Implicit(..)) |
Expand Down Expand Up @@ -174,8 +173,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
mc::cat_static_item => {
ty::ReStatic
}
mc::cat_local(local_id) |
mc::cat_arg(local_id) => {
mc::cat_local(local_id) => {
ty::ReScope(self.bccx.tcx.region_maps.var_scope(local_id))
}
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
Safe
}

mc::cat_local(local_id) |
mc::cat_arg(local_id) => {
mc::cat_local(local_id) => {
// R-Variable, locally declared
let lp = Rc::new(LpVar(local_id));
SafeIf(lp.clone(), vec![lp])
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ pub fn opt_loan_path(cmt: &mc::cmt) -> Option<Rc<LoanPath>> {
None
}

mc::cat_local(id) |
mc::cat_arg(id) => {
mc::cat_local(id) => {
Some(Rc::new(LpVar(id)))
}

Expand Down
18 changes: 6 additions & 12 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use middle::subst::ParamSpace;
use syntax::ast;
use syntax::ast_util::local_def;

use std::gc::Gc;

#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Def {
DefFn(ast::DefId, ast::FnStyle),
Expand All @@ -22,20 +20,18 @@ pub enum Def {
DefMod(ast::DefId),
DefForeignMod(ast::DefId),
DefStatic(ast::DefId, bool /* is_mutbl */),
DefArg(ast::NodeId, ast::BindingMode),
DefLocal(ast::NodeId, ast::BindingMode),
DefLocal(ast::NodeId),
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
DefTy(ast::DefId, bool /* is_enum */),
DefAssociatedTy(ast::DefId),
DefTrait(ast::DefId),
DefPrimTy(ast::PrimTy),
DefTyParam(ParamSpace, ast::DefId, uint),
DefBinding(ast::NodeId, ast::BindingMode),
DefUse(ast::DefId),
DefUpvar(ast::NodeId, // id of closed over var
Gc<Def>, // closed over def
DefUpvar(ast::NodeId, // id of closed over local
ast::NodeId, // expr node that creates the closure
ast::NodeId), // id for the block/body of the closure expr
ast::NodeId), // block node for the closest enclosing proc
// or unboxed closure, DUMMY_NODE_ID otherwise

/// Note that if it's a tuple struct's definition, the node id of the ast::DefId
/// may either refer to the item definition's id or the StructDef.ctor_id.
Expand Down Expand Up @@ -68,11 +64,9 @@ impl Def {
DefMethod(id, _) => {
id
}
DefArg(id, _) |
DefLocal(id, _) |
DefLocal(id) |
DefSelfTy(id) |
DefUpvar(id, _, _, _) |
DefBinding(id, _) |
DefUpvar(id, _, _) |
DefRegion(id) |
DefTyParamBinder(id) |
DefLabel(id) => {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use middle::mem_categorization as mc;
use middle::def;
use middle::freevars;
use middle::mem_categorization::Typer;
use middle::pat_util;
use middle::ty;
use middle::typeck::{MethodCall, MethodObject, MethodOrigin, MethodParam};
Expand Down Expand Up @@ -911,12 +911,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
debug!("walk_captures({})", closure_expr.repr(self.tcx()));

let tcx = self.typer.tcx();
freevars::with_freevars(tcx, closure_expr.id, |freevars| {
match freevars::get_capture_mode(self.tcx(), closure_expr.id) {
freevars::CaptureByRef => {
ty::with_freevars(tcx, closure_expr.id, |freevars| {
match self.tcx().capture_mode(closure_expr.id) {
ast::CaptureByRef => {
self.walk_by_ref_captures(closure_expr, freevars);
}
freevars::CaptureByValue => {
ast::CaptureByValue => {
self.walk_by_value_captures(closure_expr, freevars);
}
}
Expand All @@ -925,7 +925,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {

fn walk_by_ref_captures(&mut self,
closure_expr: &ast::Expr,
freevars: &[freevars::freevar_entry]) {
freevars: &[ty::Freevar]) {
for freevar in freevars.iter() {
let id_var = freevar.def.def_id().node;
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
Expand All @@ -950,7 +950,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {

fn walk_by_value_captures(&mut self,
closure_expr: &ast::Expr,
freevars: &[freevars::freevar_entry]) {
freevars: &[ty::Freevar]) {
for freevar in freevars.iter() {
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
closure_expr.span,
Expand Down
Loading