checkpoint: weird rustc bug permitting extra members

This commit is contained in:
Niko Matsakis 2018-09-29 06:41:00 -04:00
parent d7b1d194de
commit 36e2b9cdcc
5 changed files with 18 additions and 9 deletions

View file

@ -4,7 +4,6 @@ use std::cell::Cell;
#[derive(Default)]
pub struct QueryContextImpl {
runtime: salsa::runtime::Runtime<QueryContextImpl>,
storage: QueryContextImplStorage,
counter: Cell<usize>,
}
@ -26,8 +25,8 @@ impl queries::CounterContext for QueryContextImpl {
}
impl salsa::QueryContext for QueryContextImpl {
fn salsa_storage(&self) -> &QueryContextImplStorage {
&self.storage
fn extra(&self) -> u32 {
0
}
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {

View file

@ -3,3 +3,5 @@
mod implementation;
mod queries;
mod tests;
fn main() {}

View file

@ -1,3 +1,5 @@
#![cfg(test)]
use crate::implementation::QueryContextImpl;
use crate::queries::QueryContext;

View file

@ -29,9 +29,6 @@ pub mod transparent;
pub trait QueryContext: QueryContextStorageTypes {
/// Gives access to the underlying salsa runtime.
fn salsa_runtime(&self) -> &runtime::Runtime<Self>;
/// Gives access to the underlying query storage.
fn salsa_storage(&self) -> &Self::QueryStorage;
}
/// Defines the `QueryDescriptor` associated type. An impl of this
@ -49,7 +46,7 @@ pub trait QueryContextStorageTypes: Sized {
/// Defines the "storage type", where all the query data is kept.
/// This type is defined by the `query_context_storage` macro.
type QueryStorage;
type QueryContextStorage: Default;
}
pub trait QueryDescriptor<QC>: Debug + Eq + Hash {}
@ -362,7 +359,7 @@ macro_rules! query_context_storage {
impl $crate::QueryContextStorageTypes for $QueryContext {
type QueryDescriptor = __SalsaQueryDescriptor;
type QueryStorage = $Storage;
type QueryContextStorage = $Storage;
}
impl $crate::QueryDescriptor<$QueryContext> for __SalsaQueryDescriptor {
@ -376,7 +373,9 @@ macro_rules! query_context_storage {
) -> $crate::QueryTable<'_, Self, $QueryType> {
$crate::QueryTable::new(
self,
&$crate::QueryContext::salsa_storage(self).$query_method,
&$crate::QueryContext::salsa_runtime(self)
.storage()
.$query_method,
|_, key| {
let key = std::clone::Clone::clone(key);
__SalsaQueryDescriptor {

View file

@ -2,11 +2,13 @@ use crate::Query;
use crate::QueryContext;
use std::cell::RefCell;
use std::fmt::Write;
use std::sync::Arc;
pub struct Runtime<QC>
where
QC: QueryContext,
{
storage: Arc<QC::QueryContextStorage>,
execution_stack: RefCell<Vec<QC::QueryDescriptor>>,
}
@ -16,6 +18,7 @@ where
{
fn default() -> Self {
Runtime {
storage: Arc::default(),
execution_stack: RefCell::default(),
}
}
@ -25,6 +28,10 @@ impl<QC> Runtime<QC>
where
QC: QueryContext,
{
pub fn storage(&self) -> &QC::QueryContextStorage {
&self.storage
}
crate fn execute_query_implementation<Q>(
&self,
query: &QC,