Skip to content

Commit

Permalink
rustc: rename all occurences of "freevar" to "upvar".
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed May 5, 2019
1 parent 125dc60 commit 8d9f4a1
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/def.rs
Expand Up @@ -140,7 +140,7 @@ pub enum Res<Id = hir::HirId> {
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
Local(Id),
Upvar(Id, // `HirId` of closed over local
usize, // index in the `freevars` list of the closure
usize, // index in the `upvars` list of the closure
ast::NodeId), // expr node that creates the closure

// Macro namespace
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/mod.rs
Expand Up @@ -2476,19 +2476,19 @@ impl ForeignItemKind {
}
}

/// A free variable referred to in a function.
/// A variable captured by a closure.
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub struct Freevar<Id = HirId> {
/// The variable being accessed free.
pub struct Upvar<Id = HirId> {
/// The variable being captured.
pub res: Res<Id>,

// First span where it is accessed (there can be multiple).
pub span: Span
}

impl<Id: fmt::Debug + Copy> Freevar<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Freevar<R> {
Freevar {
impl<Id: fmt::Debug + Copy> Upvar<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Upvar<R> {
Upvar {
res: self.res.map_id(map),
span: self.span,
}
Expand All @@ -2497,12 +2497,12 @@ impl<Id: fmt::Debug + Copy> Freevar<Id> {
pub fn var_id(&self) -> Id {
match self.res {
Res::Local(id) | Res::Upvar(id, ..) => id,
_ => bug!("Freevar::var_id: bad res ({:?})", self.res)
_ => bug!("Upvar::var_id: bad res ({:?})", self.res)
}
}
}

pub type FreevarMap = NodeMap<Vec<Freevar<ast::NodeId>>>;
pub type UpvarMap = NodeMap<Vec<Upvar<ast::NodeId>>>;

pub type CaptureModeMap = NodeMap<CaptureClause>;

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Expand Up @@ -46,7 +46,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err.span_note(span,
"...so that pointer is not dereferenced outside its lifetime");
}
infer::FreeVariable(span, id) => {
infer::ClosureCapture(span, id) => {
err.span_note(span,
&format!("...so that captured variable `{}` does not outlive the \
enclosing closure",
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"the reference is only valid for ", sup, "");
err
}
infer::FreeVariable(span, id) => {
infer::ClosureCapture(span, id) => {
let mut err = struct_span_err!(self.tcx.sess,
span,
E0474,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/mod.rs
Expand Up @@ -264,8 +264,8 @@ pub enum SubregionOrigin<'tcx> {
/// Dereference of reference must be within its lifetime
DerefPointer(Span),

/// Closure bound must not outlive captured free variables
FreeVariable(Span, ast::NodeId),
/// Closure bound must not outlive captured variables
ClosureCapture(Span, ast::NodeId),

/// Index into slice must be within its lifetime
IndexSlice(Span),
Expand Down Expand Up @@ -1660,7 +1660,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
InfStackClosure(a) => a,
InvokeClosure(a) => a,
DerefPointer(a) => a,
FreeVariable(a, _) => a,
ClosureCapture(a, _) => a,
IndexSlice(a) => a,
RelateObjectBound(a) => a,
RelateParamBound(a, _) => a,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -931,32 +931,32 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
debug!("walk_captures({:?})", closure_expr);

let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
if let Some(freevars) = self.tcx().freevars(closure_def_id) {
for freevar in freevars.iter() {
let var_hir_id = freevar.var_id();
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
for upvar in upvars.iter() {
let var_hir_id = upvar.var_id();
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: closure_def_id.to_local(),
};
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
fn_decl_span,
freevar));
upvar));
match upvar_capture {
ty::UpvarCapture::ByValue => {
let mode = copy_or_move(&self.mc,
self.param_env,
&cmt_var,
CaptureMove);
self.delegate.consume(closure_expr.hir_id, freevar.span, &cmt_var, mode);
self.delegate.consume(closure_expr.hir_id, upvar.span, &cmt_var, mode);
}
ty::UpvarCapture::ByRef(upvar_borrow) => {
self.delegate.borrow(closure_expr.hir_id,
fn_decl_span,
&cmt_var,
upvar_borrow.region,
upvar_borrow.kind,
ClosureCapture(freevar.span));
ClosureCapture(upvar.span));
}
}
}
Expand All @@ -966,7 +966,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
fn cat_captured_var(&mut self,
closure_hir_id: hir::HirId,
closure_span: Span,
upvar: &hir::Freevar)
upvar: &hir::Upvar)
-> mc::McResult<mc::cmt_<'tcx>> {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/liveness.rs
Expand Up @@ -144,7 +144,7 @@ impl LiveNode {

#[derive(Copy, Clone, PartialEq, Debug)]
enum LiveNodeKind {
FreeVarNode(Span),
UpvarNode(Span),
ExprNode(Span),
VarDefNode(Span),
ExitNode
Expand All @@ -153,8 +153,8 @@ enum LiveNodeKind {
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_, '_, '_>) -> String {
let cm = tcx.sess.source_map();
match lnk {
FreeVarNode(s) => {
format!("Free var node [{}]", cm.span_to_string(s))
UpvarNode(s) => {
format!("Upvar node [{}]", cm.span_to_string(s))
}
ExprNode(s) => {
format!("Expr node [{}]", cm.span_to_string(s))
Expand Down Expand Up @@ -484,11 +484,11 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
// construction site.
let mut call_caps = Vec::new();
let closure_def_id = ir.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
if let Some(freevars) = ir.tcx.freevars(closure_def_id) {
call_caps.extend(freevars.iter().filter_map(|freevar| {
if let Res::Local(rv) = freevar.res {
let freevar_ln = ir.add_live_node(FreeVarNode(freevar.span));
Some(CaptureInfo { ln: freevar_ln, var_hid: rv })
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
call_caps.extend(upvars.iter().filter_map(|upvar| {
if let Res::Local(rv) = upvar.res {
let upvar_ln = ir.add_live_node(UpvarNode(upvar.span));
Some(CaptureInfo { ln: upvar_ln, var_hid: rv })
} else {
None
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/mod.rs
Expand Up @@ -2572,9 +2572,9 @@ impl<'tcx> Debug for Rvalue<'tcx> {
};
let mut struct_fmt = fmt.debug_struct(&name);

if let Some(freevars) = tcx.freevars(def_id) {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
if let Some(upvars) = tcx.upvars(def_id) {
for (upvar, place) in upvars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
struct_fmt.field(&var_name.as_str(), place);
}
}
Expand All @@ -2591,9 +2591,9 @@ impl<'tcx> Debug for Rvalue<'tcx> {
tcx.hir().span_by_hir_id(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);

if let Some(freevars) = tcx.freevars(def_id) {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
if let Some(upvars) = tcx.upvars(def_id) {
for (upvar, place) in upvars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
struct_fmt.field(&var_name.as_str(), place);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Expand Up @@ -824,7 +824,7 @@ rustc_queries! {
desc { "generating a postorder list of CrateNums" }
}

query freevars(_: DefId) -> Option<Lrc<Vec<hir::Freevar>>> {
query upvars(_: DefId) -> Option<Lrc<Vec<hir::Upvar>>> {
eval_always
}
query maybe_unused_trait_import(_: DefId) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Expand Up @@ -1071,10 +1071,10 @@ pub struct GlobalCtxt<'tcx> {

pub queries: query::Queries<'tcx>,

// Records the free variables referenced by every closure
// Records the captured variables referenced by every closure
// expression. Do not track deps for this, just recompute it from
// scratch every time.
freevars: FxHashMap<DefId, Lrc<Vec<hir::Freevar>>>,
upvars: FxHashMap<DefId, Lrc<Vec<hir::Upvar>>>,

maybe_unused_trait_imports: FxHashSet<DefId>,
maybe_unused_extern_crates: Vec<(DefId, Span)>,
Expand Down Expand Up @@ -1317,7 +1317,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}).collect();
(k, Lrc::new(exports))
}).collect(),
freevars: resolutions.freevars.into_iter().map(|(k, v)| {
upvars: resolutions.upvars.into_iter().map(|(k, v)| {
let vars: Vec<_> = v.into_iter().map(|e| {
e.map_id(|id| hir.node_to_hir_id(id))
}).collect();
Expand Down Expand Up @@ -3055,7 +3055,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(id, LOCAL_CRATE);
Lrc::new(middle::lang_items::collect(tcx))
};
providers.freevars = |tcx, id| tcx.gcx.freevars.get(&id).cloned();
providers.upvars = |tcx, id| tcx.gcx.upvars.get(&id).cloned();
providers.maybe_unused_trait_import = |tcx, id| {
tcx.maybe_unused_trait_imports.contains(&id)
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Expand Up @@ -8,7 +8,7 @@ pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::fold::TypeFoldable;

use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
use crate::hir::{map as hir_map, UpvarMap, GlobMap, TraitMap};
use crate::hir::Node;
use crate::hir::def::{Res, DefKind, CtorOf, CtorKind, ExportMap};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
Expand Down Expand Up @@ -122,7 +122,7 @@ mod sty;

#[derive(Clone)]
pub struct Resolutions {
pub freevars: FreevarMap,
pub upvars: UpvarMap,
pub trait_map: TraitMap,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/print/pretty.rs
Expand Up @@ -582,7 +582,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
let mut sep = " ";
for (freevar, upvar_ty) in self.tcx().freevars(did)
for (upvar, upvar_ty) in self.tcx().upvars(did)
.as_ref()
.map_or(&[][..], |v| &v[..])
.iter()
Expand All @@ -591,7 +591,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
p!(
write("{}{}:",
sep,
self.tcx().hir().name_by_hir_id(freevar.var_id())),
self.tcx().hir().name_by_hir_id(upvar.var_id())),
print(upvar_ty));
sep = ", ";
}
Expand Down Expand Up @@ -625,7 +625,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
}
let mut sep = " ";
for (freevar, upvar_ty) in self.tcx().freevars(did)
for (upvar, upvar_ty) in self.tcx().upvars(did)
.as_ref()
.map_or(&[][..], |v| &v[..])
.iter()
Expand All @@ -634,7 +634,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
p!(
write("{}{}:",
sep,
self.tcx().hir().name_by_hir_id(freevar.var_id())),
self.tcx().hir().name_by_hir_id(upvar.var_id())),
print(upvar_ty));
sep = ", ";
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/passes.rs
Expand Up @@ -180,7 +180,7 @@ impl ExpansionResult {
ExpansionResult {
defs: Steal::new(resolver.definitions),
resolutions: Steal::new(Resolutions {
freevars: resolver.freevars,
upvars: resolver.upvars,
export_map: resolver.export_map,
trait_map: resolver.trait_map,
glob_map: resolver.glob_map,
Expand All @@ -199,7 +199,7 @@ impl ExpansionResult {
ExpansionResult {
defs: Steal::new(resolver.definitions.clone()),
resolutions: Steal::new(Resolutions {
freevars: resolver.freevars.clone(),
upvars: resolver.upvars.clone(),
export_map: resolver.export_map.clone(),
trait_map: resolver.trait_map.clone(),
glob_map: resolver.glob_map.clone(),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/error_reporting.rs
Expand Up @@ -1814,12 +1814,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
ty::Array(ty, _) | ty::Slice(ty) =>
self.describe_field_from_ty(&ty, field, variant_index),
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
// `tcx.freevars(def_id)` returns an `Option`, which is `None` in case
// `tcx.upvars(def_id)` returns an `Option`, which is `None` in case
// the closure comes from another crate. But in that case we wouldn't
// be borrowck'ing it, so we can just unwrap:
let freevar = self.infcx.tcx.freevars(def_id).unwrap()[field.index()];
let upvar = self.infcx.tcx.upvars(def_id).unwrap()[field.index()];

self.infcx.tcx.hir().name_by_hir_id(freevar.var_id()).to_string()
self.infcx.tcx.hir().name_by_hir_id(upvar.var_id()).to_string()
}
_ => {
// Might need a revision when the fields in trait RFC is implemented
Expand Down Expand Up @@ -2609,7 +2609,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
if let hir::ExprKind::Closure(
.., args_span, _
) = expr {
for (v, place) in self.infcx.tcx.freevars(def_id)?.iter().zip(places) {
for (v, place) in self.infcx.tcx.upvars(def_id)?.iter().zip(places) {
match place {
Operand::Copy(place) |
Operand::Move(place) if target_place == place => {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -516,10 +516,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
}
};
let upvars = cx.tcx.freevars(def_id).iter()
.flat_map(|freevars| freevars.iter())
let upvars = cx.tcx.upvars(def_id).iter()
.flat_map(|upvars| upvars.iter())
.zip(substs.upvar_tys(def_id, cx.tcx))
.map(|(freevar, ty)| capture_freevar(cx, expr, freevar, ty))
.map(|(upvar, ty)| capture_upvar(cx, expr, upvar, ty))
.collect();
ExprKind::Closure {
closure_id: def_id,
Expand Down Expand Up @@ -1184,12 +1184,12 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
ExprKind::Deref { arg: ref_expr.to_ref() }
}

fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
closure_expr: &'tcx hir::Expr,
freevar: &hir::Freevar,
freevar_ty: Ty<'tcx>)
upvar: &hir::Upvar,
upvar_ty: Ty<'tcx>)
-> ExprRef<'tcx> {
let var_hir_id = freevar.var_id();
let var_hir_id = upvar.var_id();
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: cx.tcx.hir().local_def_id_from_hir_id(closure_expr.hir_id).to_local(),
Expand All @@ -1201,7 +1201,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
temp_lifetime,
ty: var_ty,
span: closure_expr.span,
kind: convert_var(cx, closure_expr, freevar.res),
kind: convert_var(cx, closure_expr, upvar.res),
};
match upvar_capture {
ty::UpvarCapture::ByValue => captured_var.to_ref(),
Expand All @@ -1213,7 +1213,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
};
Expr {
temp_lifetime,
ty: freevar_ty,
ty: upvar_ty,
span: closure_expr.span,
kind: ExprKind::Borrow {
borrow_kind,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/validity.rs
Expand Up @@ -170,7 +170,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
if def_id.is_local() {
let tables = self.ecx.tcx.typeck_tables_of(def_id);
if let Some(upvars) = tables.upvar_list.get(&def_id) {
// Sometimes the index is beyond the number of freevars (seen
// Sometimes the index is beyond the number of upvars (seen
// for a generator).
if let Some(upvar_id) = upvars.get(field) {
let var_hir_id = upvar_id.var_path.hir_id;
Expand Down

0 comments on commit 8d9f4a1

Please sign in to comment.