-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #44501 - nikomatsakis:issue-44137-non-query-data-in-tcx…
…, r=eddyb remove or encapsulate the remaining non-query data in tcx I wound up removing the existing cache around inhabitedness since it didn't seem to be adding much value. I reworked const rvalue promotion, but not that much (i.e., I did not split the computation into bits, as @eddyb had tossed out as a suggestion). But it's now demand driven, at least. cc @michaelwoerister -- see the `forbid_reads` change in last commit r? @eddyb -- since the trickiest of this PR is the work on const rvalue promotion cc #44137
- Loading branch information
Showing
25 changed files
with
438 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use ty::{self, Ty, TyCtxt}; | ||
use ty::fold::{TypeFolder, TypeFoldable}; | ||
|
||
pub(super) fn provide(providers: &mut ty::maps::Providers) { | ||
*providers = ty::maps::Providers { | ||
erase_regions_ty, | ||
..*providers | ||
}; | ||
} | ||
|
||
fn erase_regions_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { | ||
// NB: use `super_fold_with` here. If we used `fold_with`, it | ||
// could invoke the `erase_regions_ty` query recursively. | ||
ty.super_fold_with(&mut RegionEraserVisitor { tcx }) | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | ||
/// Returns an equivalent value with all free regions removed (note | ||
/// that late-bound regions remain, because they are important for | ||
/// subtyping, but they are anonymized and normalized as well).. | ||
pub fn erase_regions<T>(self, value: &T) -> T | ||
where T : TypeFoldable<'tcx> | ||
{ | ||
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self }); | ||
debug!("erase_regions({:?}) = {:?}", value, value1); | ||
value1 | ||
} | ||
} | ||
|
||
struct RegionEraserVisitor<'a, 'gcx: 'tcx, 'tcx: 'a> { | ||
tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionEraserVisitor<'a, 'gcx, 'tcx> { | ||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { | ||
self.tcx | ||
} | ||
|
||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { | ||
if let Some(ty_lifted) = self.tcx.lift_to_global(&ty) { | ||
self.tcx.erase_regions_ty(ty_lifted) | ||
} else { | ||
ty.super_fold_with(self) | ||
} | ||
} | ||
|
||
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> | ||
where T : TypeFoldable<'tcx> | ||
{ | ||
let u = self.tcx.anonymize_late_bound_regions(t); | ||
u.super_fold_with(self) | ||
} | ||
|
||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { | ||
// because late-bound regions affect subtyping, we can't | ||
// erase the bound/free distinction, but we can replace | ||
// all free regions with 'erased. | ||
// | ||
// Note that we *CAN* replace early-bound regions -- the | ||
// type system never "sees" those, they get substituted | ||
// away. In trans, they will always be erased to 'erased | ||
// whenever a substitution occurs. | ||
match *r { | ||
ty::ReLateBound(..) => r, | ||
_ => self.tcx.types.re_erased | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.