-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intern types, replace projections, Mini-buffer info area
* Intern types while serializing * Move DynCtxt to separate module * Show projected types instead of their paths * Clean up transmutes * Add comment on type projections * Add mini-buffer for full type information * Add mini-buffer pinning, clean up icons and projection replacement
- Loading branch information
1 parent
fbf02cf
commit 5e3742f
Showing
49 changed files
with
3,676 additions
and
3,617 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,68 @@ | ||
use rustc_infer::infer::InferCtxt; | ||
|
||
// These types are safe for dependents to use. | ||
use crate::interner::TyInterner; | ||
|
||
pub trait DynCtxt<'tcx> | ||
where | ||
Self: 'tcx, | ||
{ | ||
type Static: 'static; | ||
type Dynamic: 'tcx; | ||
|
||
fn tls() -> &'static fluid_let::DynamicVariable<&'static Self::Static>; | ||
|
||
fn invoke_in<'a, T>(v: &'a Self::Dynamic, f: impl FnOnce() -> T) -> T | ||
where | ||
'tcx: 'a, | ||
{ | ||
log::trace!( | ||
"Setting dynamic ctx {:?}", | ||
std::any::TypeId::of::<Self::Static>() | ||
); | ||
|
||
let cell = Self::tls(); | ||
let vstat: &'static Self::Static = unsafe { std::mem::transmute(v) }; | ||
|
||
cell.set(vstat, f) | ||
} | ||
|
||
fn access<T>(f: impl for<'a> FnOnce(&'a Self::Dynamic) -> T) -> T { | ||
log::trace!( | ||
"Accessing dynamic ctx {:?}", | ||
std::any::TypeId::of::<Self::Static>() | ||
); | ||
|
||
let cell = Self::tls(); | ||
cell.get(|v_opt| { | ||
let v: &'static Self::Static = v_opt.expect("no dynamic context set"); | ||
let vdyn: &Self::Dynamic = unsafe { std::mem::transmute(v) }; | ||
|
||
f(vdyn) | ||
}) | ||
} | ||
} | ||
|
||
// NOTE: setting the dynamic TCX should *only* happen | ||
// before calling the serialize function, it must guarantee | ||
// that the 'tcx lifetime is the same as that of the serialized item. | ||
fluid_let::fluid_let! {static INFCX: &'static InferCtxt<'static>} | ||
fluid_let::fluid_let! {static TY_BUF: &'static TyInterner<'static>} | ||
|
||
impl<'tcx> DynCtxt<'tcx> for InferCtxt<'tcx> { | ||
type Static = InferCtxt<'static>; | ||
type Dynamic = InferCtxt<'tcx>; | ||
|
||
fn tls() -> &'static fluid_let::DynamicVariable<&'static Self::Static> { | ||
&INFCX | ||
} | ||
} | ||
|
||
impl<'tcx> DynCtxt<'tcx> for TyInterner<'tcx> { | ||
type Static = TyInterner<'static>; | ||
type Dynamic = TyInterner<'tcx>; | ||
|
||
fn tls() -> &'static fluid_let::DynamicVariable<&'static Self::Static> { | ||
&TY_BUF | ||
} | ||
} |
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,64 @@ | ||
use std::collections::HashMap; // FIXME: change back to above | ||
use std::{ | ||
cell::RefCell, | ||
cmp::{Eq, PartialEq}, | ||
hash::Hash, | ||
}; | ||
|
||
use index_vec::{Idx, IndexVec}; | ||
// use rustc_data_structures::fx::FxHashMap as HashMap; | ||
use rustc_middle::ty; | ||
|
||
crate::define_idx! { | ||
usize, | ||
TyIdx | ||
} | ||
|
||
pub type TyInterner<'tcx> = | ||
RefCell<Interner<ty::Ty<'tcx>, TyIdx, serde_json::Value>>; | ||
|
||
pub struct Interner<K: PartialEq + Eq + Hash, I: Idx, D> { | ||
values: IndexVec<I, D>, | ||
keys: HashMap<K, I>, | ||
} | ||
|
||
impl<K, I, D> Default for Interner<K, I, D> | ||
where | ||
K: PartialEq + Eq + Hash, | ||
I: Idx, | ||
{ | ||
fn default() -> Self { | ||
Self { | ||
values: IndexVec::with_capacity(1_000_000), | ||
keys: HashMap::with_capacity(1_000_000), | ||
} | ||
} | ||
} | ||
|
||
impl<K, I, D> Interner<K, I, D> | ||
where | ||
K: PartialEq + Eq + Hash, | ||
I: Idx, | ||
{ | ||
pub fn get_idx(&self, key: &K) -> Option<I> { | ||
self.keys.get(key).copied() | ||
} | ||
|
||
pub fn get_data(&self, key: &I) -> Option<&D> { | ||
self.values.get(*key) | ||
} | ||
|
||
pub fn insert(&mut self, k: K, d: D) -> I { | ||
let idx = self.values.push(d); | ||
self.keys.insert(k, idx); | ||
idx | ||
} | ||
|
||
pub fn insert_no_key(&mut self, d: D) -> I { | ||
self.values.push(d) | ||
} | ||
|
||
pub fn consume(self) -> IndexVec<I, D> { | ||
self.values | ||
} | ||
} |
Oops, something went wrong.