Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created February 28, 2018 22:57
Show Gist options
  • Save nikomatsakis/f2103b4c3f4299a77e8eb472b236d985 to your computer and use it in GitHub Desktop.
Save nikomatsakis/f2103b4c3f4299a77e8eb472b236d985 to your computer and use it in GitHub Desktop.
#![feature(universal_impl_trait)]
#![feature(nll)]
#[derive(Copy, Clone)]
struct TyCtxt<'b, 'gcx: 'tcx, 'tcx: 'b> {
data: &'b *mut (&'gcx (), &'tcx ())
}
pub struct IsolatedEncoder<'a, 'b: 'a, 'tcx: 'b> {
pub tcx: TyCtxt<'b, 'tcx, 'tcx>,
ecx: &'a mut EncodeContext<'b, 'tcx>,
}
pub struct EncodeContext<'a, 'tcx: 'a> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
#[derive(Copy, Clone)]
struct DefId { data: u32 }
pub struct IndexBuilder<'a, 'b: 'a, 'tcx: 'b> {
items: Index,
pub ecx: &'a mut EncodeContext<'b, 'tcx>,
}
struct Index { }
impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
pub fn record<'x, DATA>(
&'x mut self,
id: DefId,
op: fn(&mut IsolatedEncoder<'x, 'b, 'tcx>, DATA) -> Entry<'tcx>,
data: DATA,
) {
assert!(id.is_local());
// We don't track this since we are explicitly computing the incr. comp.
// hashes anyway. In theory we could do some tracking here and use it to
// avoid rehashing things (and instead cache the hashes) but it's
// unclear whether that would be a win since hashing is cheap enough.
self.ecx.tcx.dep_graph_with_ignore(move || {
let mut entry_builder = IsolatedEncoder::new(self.ecx);
let entry = op(&mut entry_builder, data);
let entry = entry_builder.lazy(&entry);
self.items.record(id, entry);
})
}
}
impl<'a,'gcx,'tcx> TyCtxt<'a,'gcx,'tcx> {
fn dep_graph_with_ignore(self, _: impl FnOnce()) { }
}
impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
pub fn new(ecx: &'a mut EncodeContext) {
IsolatedEncoder {
tcx: ecx.tcx,
ecx
}
}
}
impl Index {
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'tcx>>) {
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment