Skip to content

Split the type context into a global and a local (inference-only) one. #33425

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 23 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5122d5
rustc: Always refer to TyCtxt as tcx.
eddyb May 3, 2016
0907c19
infer: Use methods for creating an InferCtxt.
eddyb Mar 11, 2016
6e29099
infer: Turn normalize_associated_type into a method on TyCtxt.
eddyb Mar 11, 2016
8600a67
mem_categorization: freely_aliasable doesn't need to take TyCtxt.
eddyb Mar 11, 2016
e387e6c
typeck: merge CollectCtxt and collect::CollectCtxt.
eddyb Mar 11, 2016
ef2f5f6
typeck: Avoid passing &TyCtxt around where possible.
eddyb Mar 11, 2016
d7ee56e
typeck: Turn everything operating on FnCtxt into a method.
eddyb Mar 12, 2016
f8ea24e
rustc: Avoid free functions taking &TyCtxt and &InferCtxt.
eddyb Mar 16, 2016
8fc2c46
regionck: Use methods on RegionCtxt instead of free functions.
eddyb Mar 16, 2016
513d392
rustc: Replace &'a TyCtxt<'tcx> with a TyCtxt<'a, 'tcx> wrapper.
eddyb May 3, 2016
2fbbaf2
rustc: Use set recovery APIs in the TyCtxt interners.
eddyb Mar 23, 2016
166dbc3
rustc: Keep a reference to the interners in TyCtxt.
eddyb Apr 28, 2016
76affa5
rustc: Split 'tcx into 'gcx and 'tcx for InferCtxt and its users.
eddyb May 3, 2016
0053b44
rustc_typeck: Use Deref for FnCtxt, Inherited and InferCtxt fields an…
eddyb Mar 24, 2016
8a704f6
rustc: Remove the TyCtxt field from ParameterEnvironment.
eddyb Mar 25, 2016
12e56ea
rustc: Wrap users of InferCtxt in an anonymous scope.
eddyb Mar 25, 2016
f0b2b3c
rustc: Remove a redundant lifetime parameter from ExprUseVisitor.
eddyb Mar 25, 2016
8f72d81
rustc: Generalize a minimum set of functions over 'tcx != 'gcx.
eddyb Apr 29, 2016
2065216
rustc: More interning for data used in Ty<'tcx>.
eddyb Apr 29, 2016
3a30136
rustc: Remove the unnecessary ast_ty_to_ty_cache.
eddyb May 2, 2016
31a07b0
rustc_typeck: Generalize over 'tcx != 'gcx.
eddyb May 2, 2016
a1c170f
rustc: Split local type contexts interners from the global one.
eddyb May 11, 2016
42eb703
Fixup indentation after methodification.
eddyb May 11, 2016
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
Next Next commit
rustc_typeck: Generalize over 'tcx != 'gcx.
  • Loading branch information
eddyb committed May 11, 2016
commit 31a07b0ce662e95119a76cce8dcfc29d2055f738
2 changes: 1 addition & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,

// For region variables.
region_vars: RegionVarBindings<'a, 'tcx>,
region_vars: RegionVarBindings<'a, 'gcx, 'tcx>,

pub parameter_environment: ty::ParameterEnvironment<'gcx>,

Expand Down
28 changes: 15 additions & 13 deletions src/librustc/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ graphs will be printed. \n\
");
}

pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a, 'tcx>,
subject_node: ast::NodeId) {
pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
region_vars: &RegionVarBindings<'a, 'gcx, 'tcx>,
subject_node: ast::NodeId)
{
let tcx = region_vars.tcx;

if !region_vars.tcx.sess.opts.debugging_opts.print_region_graph {
Expand Down Expand Up @@ -118,8 +120,8 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
}
}

struct ConstraintGraph<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
graph_name: String,
map: &'a FnvHashMap<Constraint, SubregionOrigin<'tcx>>,
node_ids: FnvHashMap<Node, usize>,
Expand All @@ -138,11 +140,11 @@ enum Edge {
EnclScope(CodeExtent, CodeExtent),
}

impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
name: String,
map: &'a ConstraintMap<'tcx>)
-> ConstraintGraph<'a, 'tcx> {
-> ConstraintGraph<'a, 'gcx, 'tcx> {
let mut i = 0;
let mut node_ids = FnvHashMap();
{
Expand Down Expand Up @@ -173,7 +175,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
}
}

impl<'a, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'tcx> {
impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
type Node = Node;
type Edge = Edge;
fn graph_id(&self) -> dot::Id {
Expand Down Expand Up @@ -226,7 +228,7 @@ fn edge_to_nodes(e: &Edge) -> (Node, Node) {
}
}

impl<'a, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'tcx> {
impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
type Node = Node;
type Edge = Edge;
fn nodes(&self) -> dot::Nodes<Node> {
Expand Down Expand Up @@ -258,10 +260,10 @@ impl<'a, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'tcx> {

pub type ConstraintMap<'tcx> = FnvHashMap<Constraint, SubregionOrigin<'tcx>>;

fn dump_region_constraints_to<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
map: &ConstraintMap<'tcx>,
path: &str)
-> io::Result<()> {
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
map: &ConstraintMap<'tcx>,
path: &str)
-> io::Result<()> {
debug!("dump_region_constraints map (len: {}) path: {}",
map.len(),
path);
Expand Down
30 changes: 15 additions & 15 deletions src/librustc/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl SameRegions {

pub type CombineMap = FnvHashMap<TwoRegions, RegionVid>;

pub struct RegionVarBindings<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
var_origins: RefCell<Vec<RegionVariableOrigin>>,

// Constraints of the form `A <= B` introduced by the region
Expand Down Expand Up @@ -253,8 +253,8 @@ pub struct RegionSnapshot {
skolemization_count: u32,
}

impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> RegionVarBindings<'a, 'tcx> {
impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> RegionVarBindings<'a, 'gcx, 'tcx> {
RegionVarBindings {
tcx: tcx,
var_origins: RefCell::new(Vec::new()),
Expand Down Expand Up @@ -600,7 +600,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
origin: SubregionOrigin<'tcx>,
mut relate: F)
-> Region
where F: FnMut(&RegionVarBindings<'a, 'tcx>, Region, Region)
where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region, Region)
{
let vars = TwoRegions { a: a, b: b };
match self.combine_map(t).borrow().get(&vars) {
Expand Down Expand Up @@ -816,7 +816,7 @@ struct RegionAndOrigin<'tcx> {

type RegionGraph = graph::Graph<(), Constraint>;

impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
fn infer_variable_values(&self,
free_regions: &FreeRegionMap,
errors: &mut Vec<RegionResolutionError<'tcx>>,
Expand Down Expand Up @@ -1249,11 +1249,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
let WalkState {result, dup_found, ..} = state;
return (result, dup_found);

fn process_edges<'a, 'tcx>(this: &RegionVarBindings<'a, 'tcx>,
state: &mut WalkState<'tcx>,
graph: &RegionGraph,
source_vid: RegionVid,
dir: Direction) {
fn process_edges<'a, 'gcx, 'tcx>(this: &RegionVarBindings<'a, 'gcx, 'tcx>,
state: &mut WalkState<'tcx>,
graph: &RegionGraph,
source_vid: RegionVid,
dir: Direction) {
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);

let source_node_index = NodeIndex(source_vid.index as usize);
Expand Down Expand Up @@ -1362,16 +1362,16 @@ impl<'tcx> fmt::Display for GenericKind<'tcx> {
}
}

impl<'a, 'tcx> GenericKind<'tcx> {
pub fn to_ty(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
impl<'a, 'gcx, 'tcx> GenericKind<'tcx> {
pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
match *self {
GenericKind::Param(ref p) => p.to_ty(tcx),
GenericKind::Projection(ref p) => tcx.mk_projection(p.trait_ref.clone(), p.item_name),
}
}
}

impl<'a, 'tcx> VerifyBound {
impl<'a, 'gcx, 'tcx> VerifyBound {
fn for_each_region(&self, f: &mut FnMut(ty::Region)) {
match self {
&VerifyBound::AnyRegion(ref rs) |
Expand Down Expand Up @@ -1424,7 +1424,7 @@ impl<'a, 'tcx> VerifyBound {
}
}

fn is_met(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn is_met(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
free_regions: &FreeRegionMap,
var_values: &Vec<VarValue>,
min: ty::Region)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astconv_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ty::{Ty, TyCtxt};
use syntax::codemap::Span;
use hir as ast;

impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn prohibit_type_params(self, segments: &[ast::PathSegment]) {
for segment in segments {
for typ in segment.parameters.types() {
Expand Down
20 changes: 9 additions & 11 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ enum OverloadedCallType {
}

impl OverloadedCallType {
fn from_trait_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_id: DefId)
-> OverloadedCallType {
fn from_trait_id(tcx: TyCtxt, trait_id: DefId) -> OverloadedCallType {
for &(maybe_function_trait, overloaded_call_type) in &[
(tcx.lang_items.fn_once_trait(), FnOnceOverloadedCall),
(tcx.lang_items.fn_mut_trait(), FnMutOverloadedCall),
Expand All @@ -227,8 +226,7 @@ impl OverloadedCallType {
bug!("overloaded call didn't map to known function trait")
}

fn from_method_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, method_id: DefId)
-> OverloadedCallType {
fn from_method_id(tcx: TyCtxt, method_id: DefId) -> OverloadedCallType {
let method = tcx.impl_or_trait_item(method_id);
OverloadedCallType::from_trait_id(tcx, method.container().id())
}
Expand Down Expand Up @@ -271,9 +269,9 @@ enum PassArgs {
ByRef,
}

impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
pub fn new(delegate: &'a mut (Delegate<'tcx>+'a),
infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> Self
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self
{
ExprUseVisitor {
mc: mc::MemCategorizationContext::new(infcx),
Expand Down Expand Up @@ -305,7 +303,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
}
}

fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
self.mc.infcx.tcx
}

Expand Down Expand Up @@ -1184,10 +1182,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
}
}

fn copy_or_move<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
cmt: &mc::cmt<'tcx>,
move_reason: MoveReason)
-> ConsumeMode
fn copy_or_move<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
cmt: &mc::cmt<'tcx>,
move_reason: MoveReason)
-> ConsumeMode
{
if infcx.type_moves_by_default(cmt.ty, cmt.span) {
Move(move_reason)
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/free_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ impl FreeRegionMap {

/// Determines whether one region is a subregion of another. This is intended to run *after
/// inference* and sadly the logic is somewhat duplicated with the code in infer.rs.
pub fn is_subregion_of<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
sub_region: ty::Region,
super_region: ty::Region)
-> bool {
pub fn is_subregion_of(&self,
tcx: TyCtxt,
sub_region: ty::Region,
super_region: ty::Region)
-> bool {
let result = sub_region == super_region || {
match (sub_region, super_region) {
(ty::ReEmpty, _) |
Expand Down
30 changes: 12 additions & 18 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ impl MutabilityCategory {
ret
}

fn from_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: ast::NodeId)
-> MutabilityCategory {
fn from_local(tcx: TyCtxt, id: ast::NodeId) -> MutabilityCategory {
let ret = match tcx.map.get(id) {
ast_map::NodeLocal(p) => match p.node {
PatKind::Ident(bind_mode, _, _) => {
Expand Down Expand Up @@ -360,13 +358,13 @@ impl MutabilityCategory {
}
}

impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>)
-> MemCategorizationContext<'a, 'tcx, 'tcx> {
impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
MemCategorizationContext { infcx: infcx }
}

fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
self.infcx.tcx
}

Expand Down Expand Up @@ -1074,9 +1072,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
slice_pat: &hir::Pat)
-> McResult<(cmt<'tcx>, hir::Mutability, ty::Region)> {
let slice_ty = self.node_ty(slice_pat.id)?;
let (slice_mutbl, slice_r) = vec_slice_info(self.tcx(),
slice_pat,
slice_ty);
let (slice_mutbl, slice_r) = vec_slice_info(slice_pat, slice_ty);
let context = InteriorOffsetKind::Pattern;
let cmt_vec = self.deref_vec(slice_pat, vec_cmt, context)?;
let cmt_slice = self.cat_index(slice_pat, cmt_vec, context)?;
Expand All @@ -1085,14 +1081,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
/// In a pattern like [a, b, ..c], normally `c` has slice type, but if you have [a, b,
/// ..ref c], then the type of `ref c` will be `&&[]`, so to extract the slice details we
/// have to recurse through rptrs.
fn vec_slice_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pat: &hir::Pat,
slice_ty: Ty)
-> (hir::Mutability, ty::Region) {
fn vec_slice_info(pat: &hir::Pat, slice_ty: Ty)
-> (hir::Mutability, ty::Region) {
match slice_ty.sty {
ty::TyRef(r, ref mt) => match mt.ty.sty {
ty::TySlice(_) => (mt.mutbl, *r),
_ => vec_slice_info(tcx, pat, mt.ty),
_ => vec_slice_info(pat, mt.ty),
},

_ => {
Expand Down Expand Up @@ -1140,15 +1134,15 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
}

pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &hir::Pat, mut op: F) -> McResult<()>
where F: FnMut(&MemCategorizationContext<'a, 'tcx, 'tcx>, cmt<'tcx>, &hir::Pat),
where F: FnMut(&MemCategorizationContext<'a, 'gcx, 'tcx>, cmt<'tcx>, &hir::Pat),
{
self.cat_pattern_(cmt, pat, &mut op)
}

// FIXME(#19596) This is a workaround, but there should be a better way to do this
fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F)
-> McResult<()>
where F : FnMut(&MemCategorizationContext<'a, 'tcx, 'tcx>, cmt<'tcx>, &hir::Pat),
where F : FnMut(&MemCategorizationContext<'a, 'gcx, 'tcx>, cmt<'tcx>, &hir::Pat),
{
// Here, `cmt` is the categorization for the value being
// matched and pat is the pattern it is being matched against.
Expand Down Expand Up @@ -1466,7 +1460,7 @@ impl<'tcx> cmt_<'tcx> {
}


pub fn descriptive_string<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
pub fn descriptive_string(&self, tcx: TyCtxt) -> String {
match self.cat {
Categorization::StaticItem => {
"static item".to_string()
Expand Down
Loading