Skip to content

#26351 (Use TLS to store a type context for pretty-printing types) + #26147. #26412

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

Closed
wants to merge 51 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c14d86f
core: Split apart the global `core` feature
alexcrichton Jun 9, 2015
c44f539
alloc: Split apart the global `alloc` feature
alexcrichton Jun 9, 2015
d444d0c
collections: Split the `collections` feature
alexcrichton Jun 9, 2015
6895311
std: Split the `std_misc` feature
alexcrichton Jun 10, 2015
ce1a965
Fallout in tests and docs from feature renamings
alexcrichton Jun 10, 2015
02a8d5b
std: Deprecate the RandomAccessIterator trait
alexcrichton Jun 11, 2015
669d1cd
std: Deprecate iter::{Unfold, Iterate}
alexcrichton Jun 11, 2015
153de4c
std: Deprecate the copy_{,mut_}lifetime functions
alexcrichton Jun 11, 2015
c72e01e
std: Deprecate result::fold
alexcrichton Jun 11, 2015
f55c366
std: Deprecate the IntSliceExt trait
alexcrichton Jun 11, 2015
a05ed99
std: Remove two internal `str_internals` functions
alexcrichton Jun 11, 2015
8797c9e
std: Deprecate f{32,64}::consts::PI_2
alexcrichton Jun 11, 2015
cdb69e2
std: Stabilize the remaining wrapping_* functions
alexcrichton Jun 11, 2015
f85c4f6
std: Deprecate all permutation-related slice methods
alexcrichton Jun 11, 2015
68b628b
std: Deprecate Vec::from_raw_buf
alexcrichton Jun 11, 2015
c032d6f
std: Stabilize the sync_poison feature
alexcrichton Jun 11, 2015
f358087
std: Stabilize the `once_new` feature
alexcrichton Jun 11, 2015
17a1059
std: Stabilize the `iter_{once,empty}` features
alexcrichton Jun 11, 2015
2d389c1
std: Stabilize the `str_matches` feature
alexcrichton Jun 11, 2015
0d818b4
std: Deprecate the io::BufStream type
alexcrichton Jun 11, 2015
96cce02
std: Deprecate the `exit_status` feature
alexcrichton Jun 11, 2015
04f7eba
std: Deprecate the `future` feature
alexcrichton Jun 11, 2015
d645f8f
std: Deprecate the `scoped` feature
alexcrichton Jun 11, 2015
3346fb0
std: Deprecate the `thunk` module
alexcrichton Jun 11, 2015
aa931e9
std: Move free-functions to associated functions
alexcrichton Jun 11, 2015
b4a2823
More test fixes and fallout of stability changes
alexcrichton Jun 11, 2015
252ef28
std: Update stable since for `core::char`
alexcrichton Jun 11, 2015
edf9335
std: Hide some internal functions more aggressively
alexcrichton Jun 11, 2015
c9b40a3
std: Stabilize vec_map::Entry::or_insert{,_with}
alexcrichton Jun 11, 2015
913c227
Add comment about stabilizing CString::from_ptr
alexcrichton Jun 11, 2015
b637f6b
Fix the E0252 error message to use better names for things.
Jun 18, 2015
f451812
Auto merge of #26385 - nham:fix_25396, r=alexcrichton
bors Jun 18, 2015
ec33338
Fix libstd tests
alexcrichton Jun 12, 2015
9cc0b22
Auto merge of #26192 - alexcrichton:features-clean, r=aturon
bors Jun 18, 2015
ff8fee1
Auto merge of #26147 - arielb1:assoc-trans, r=nikomatsakis
bors Jun 18, 2015
2e997ef
rustc: remove ownership of tcx from trans' context.
eddyb Jun 13, 2015
84b49b2
rustc_resolve: don't require redundant arguments to resolve_crate.
eddyb Jun 13, 2015
bc383f6
rustc: enforce stack discipline on ty::ctxt.
eddyb Jun 14, 2015
4e0cb86
rustc: reduce ppaux's public footprint to 5 functions.
eddyb Jun 14, 2015
96ad4a4
rustc: use Repr and UserString instead of ppaux::ty_to_string.
eddyb Jun 15, 2015
6061707
rustc: leave only one free top-level function in ppaux, and private.
eddyb Jun 15, 2015
d8952e7
rustc: store the type context in TLS and allow safe access to it.
eddyb Jun 16, 2015
1f70a2e
rustc: allow "lifting" T<'a> to T<'tcx> if the value is part of ty::c…
eddyb Jun 16, 2015
a372755
rustc: use the TLS type context in Repr and UserString.
eddyb Jun 16, 2015
b510ea1
Clean up unused argument/variable warnings.
eddyb Jun 16, 2015
af7daa0
rustc: remove some unused UserString and Repr impls.
eddyb Jun 17, 2015
17e333d
Move AST Repr impls to Debug impls in libsyntax.
eddyb Jun 17, 2015
dfbc960
rustc: replace Repr/UserString impls with Debug/Display ones.
eddyb Jun 18, 2015
0b58fdf
rustc: remove Repr and UserString.
eddyb Jun 18, 2015
d914831
rustc: add more doc comments to ty::Lift and ty::with_ctxt.
eddyb Jun 18, 2015
6eed166
Remove extra fmt::Debug impl for VtableClosureData from #26147.
eddyb Jun 18, 2015
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: allow "lifting" T<'a> to T<'tcx> if the value is part of ty::c…
…txt<'tcx>.
  • Loading branch information
eddyb committed Jun 18, 2015
commit 1f70a2e370e2c0d69403ccadc6b55caee27a73c1
122 changes: 122 additions & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,128 @@ impl<'tcx> ctxt<'tcx> {
pub fn free_region_map(&self, id: NodeId) -> FreeRegionMap {
self.free_region_maps.borrow()[&id].clone()
}

pub fn lift<T: Lift<'tcx>>(&self, value: &T) -> Option<T::Lifted> {
value.lift_to_tcx(self)
}
}

/// A trait implemented for all X<'a> types which can be safely and
/// efficiently converted to X<'tcx> as long as they are part of the
/// provided ty::ctxt<'tcx>.
/// This can be done, for example, for Ty<'tcx> or &'tcx Substs<'tcx>
/// by looking them up in their respective interners.
pub trait Lift<'tcx> {
type Lifted;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Self::Lifted>;
}

impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
type Lifted = (A::Lifted, B::Lifted);
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
}
}

impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
type Lifted = Vec<T::Lifted>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Self::Lifted> {
let mut result = Vec::with_capacity(self.len());
for x in self {
if let Some(value) = tcx.lift(x) {
result.push(value);
} else {
return None;
}
}
Some(result)
}
}

impl<'tcx> Lift<'tcx> for Region {
type Lifted = Self;
fn lift_to_tcx(&self, _: &ctxt<'tcx>) -> Option<Region> {
Some(*self)
}
}

impl<'a, 'tcx> Lift<'tcx> for Ty<'a> {
type Lifted = Ty<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Ty<'tcx>> {
if let Some(&ty) = tcx.interner.borrow().get(&self.sty) {
if *self as *const _ == ty as *const _ {
return Some(ty);
}
}
None
}
}

impl<'a, 'tcx> Lift<'tcx> for &'a Substs<'a> {
type Lifted = &'tcx Substs<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<&'tcx Substs<'tcx>> {
if let Some(&substs) = tcx.substs_interner.borrow().get(*self) {
if *self as *const _ == substs as *const _ {
return Some(substs);
}
}
None
}
}

impl<'a, 'tcx> Lift<'tcx> for TraitRef<'a> {
type Lifted = TraitRef<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<TraitRef<'tcx>> {
tcx.lift(&self.substs).map(|substs| TraitRef {
def_id: self.def_id,
substs: substs
})
}
}

impl<'a, 'tcx> Lift<'tcx> for TraitPredicate<'a> {
type Lifted = TraitPredicate<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<TraitPredicate<'tcx>> {
tcx.lift(&self.trait_ref).map(|trait_ref| TraitPredicate {
trait_ref: trait_ref
})
}
}

impl<'a, 'tcx> Lift<'tcx> for EquatePredicate<'a> {
type Lifted = EquatePredicate<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<EquatePredicate<'tcx>> {
tcx.lift(&(self.0, self.1)).map(|(a, b)| EquatePredicate(a, b))
}
}

impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for OutlivesPredicate<A, B> {
type Lifted = OutlivesPredicate<A::Lifted, B::Lifted>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&(self.0, self.1)).map(|(a, b)| OutlivesPredicate(a, b))
}
}

impl<'a, 'tcx> Lift<'tcx> for ProjectionPredicate<'a> {
type Lifted = ProjectionPredicate<'tcx>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<ProjectionPredicate<'tcx>> {
tcx.lift(&(self.projection_ty.trait_ref, self.ty)).map(|(trait_ref, ty)| {
ProjectionPredicate {
projection_ty: ProjectionTy {
trait_ref: trait_ref,
item_name: self.projection_ty.item_name
},
ty: ty
}
})
}
}

impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Binder<T> {
type Lifted = Binder<T::Lifted>;
fn lift_to_tcx(&self, tcx: &ctxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.0).map(|x| Binder(x))
}
}

pub mod tls {
Expand Down