mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-24 22:03:34 +00:00
Switch crate to pub(crate)
This commit is contained in:
parent
3b5f16cbcb
commit
1c349d4229
12 changed files with 25 additions and 30 deletions
|
@ -1,6 +1,5 @@
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![feature(in_band_lifetimes)]
|
#![feature(in_band_lifetimes)]
|
||||||
#![feature(crate_visibility_modifier)]
|
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![feature(integer_atomics)]
|
#![feature(integer_atomics)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
|
@ -67,14 +67,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read current value of the revision counter.
|
/// Read current value of the revision counter.
|
||||||
crate fn current_revision(&self) -> Revision {
|
pub(crate) fn current_revision(&self) -> Revision {
|
||||||
Revision {
|
Revision {
|
||||||
generation: self.shared_state.revision.load(Ordering::SeqCst),
|
generation: self.shared_state.revision.load(Ordering::SeqCst),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Increments the current revision counter and returns the new value.
|
/// Increments the current revision counter and returns the new value.
|
||||||
crate fn increment_revision(&self) -> Revision {
|
pub(crate) fn increment_revision(&self) -> Revision {
|
||||||
if !self.local_state.borrow().query_stack.is_empty() {
|
if !self.local_state.borrow().query_stack.is_empty() {
|
||||||
panic!("increment_revision invoked during a query computation");
|
panic!("increment_revision invoked during a query computation");
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ where
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn execute_query_implementation<V>(
|
pub(crate) fn execute_query_implementation<V>(
|
||||||
&self,
|
&self,
|
||||||
descriptor: &DB::QueryDescriptor,
|
descriptor: &DB::QueryDescriptor,
|
||||||
execute: impl FnOnce() -> V,
|
execute: impl FnOnce() -> V,
|
||||||
|
@ -132,13 +132,13 @@ where
|
||||||
/// - `descriptor`: the query whose result was read
|
/// - `descriptor`: the query whose result was read
|
||||||
/// - `changed_revision`: the last revision in which the result of that
|
/// - `changed_revision`: the last revision in which the result of that
|
||||||
/// query had changed
|
/// query had changed
|
||||||
crate fn report_query_read(&self, descriptor: &DB::QueryDescriptor, changed_at: ChangedAt) {
|
pub(crate) fn report_query_read(&self, descriptor: &DB::QueryDescriptor, changed_at: ChangedAt) {
|
||||||
if let Some(top_query) = self.local_state.borrow_mut().query_stack.last_mut() {
|
if let Some(top_query) = self.local_state.borrow_mut().query_stack.last_mut() {
|
||||||
top_query.add_read(descriptor, changed_at);
|
top_query.add_read(descriptor, changed_at);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn report_untracked_read(&self) {
|
pub(crate) fn report_untracked_read(&self) {
|
||||||
if let Some(top_query) = self.local_state.borrow_mut().query_stack.last_mut() {
|
if let Some(top_query) = self.local_state.borrow_mut().query_stack.last_mut() {
|
||||||
let changed_at = ChangedAt::Revision(self.current_revision());
|
let changed_at = ChangedAt::Revision(self.current_revision());
|
||||||
top_query.add_untracked_read(changed_at);
|
top_query.add_untracked_read(changed_at);
|
||||||
|
@ -146,7 +146,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obviously, this should be user configurable at some point.
|
/// Obviously, this should be user configurable at some point.
|
||||||
crate fn report_unexpected_cycle(&self, descriptor: DB::QueryDescriptor) -> ! {
|
pub(crate) fn report_unexpected_cycle(&self, descriptor: DB::QueryDescriptor) -> ! {
|
||||||
let local_state = self.local_state.borrow();
|
let local_state = self.local_state.borrow();
|
||||||
let LocalState { query_stack, .. } = &*local_state;
|
let LocalState { query_stack, .. } = &*local_state;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ pub struct Revision {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Revision {
|
impl Revision {
|
||||||
crate const ZERO: Self = Revision { generation: 0 };
|
pub(crate) const ZERO: Self = Revision { generation: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Revision {
|
impl std::fmt::Debug for Revision {
|
||||||
|
@ -243,7 +243,7 @@ impl ChangedAt {
|
||||||
|
|
||||||
/// An insertion-order-preserving set of queries. Used to track the
|
/// An insertion-order-preserving set of queries. Used to track the
|
||||||
/// inputs accessed during query execution.
|
/// inputs accessed during query execution.
|
||||||
crate enum QueryDescriptorSet<DB: Database> {
|
pub(crate) enum QueryDescriptorSet<DB: Database> {
|
||||||
/// All reads were to tracked things:
|
/// All reads were to tracked things:
|
||||||
Tracked(FxIndexSet<DB::QueryDescriptor>),
|
Tracked(FxIndexSet<DB::QueryDescriptor>),
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ impl<DB: Database> QueryDescriptorSet<DB> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct StampedValue<V> {
|
pub(crate) struct StampedValue<V> {
|
||||||
crate value: V,
|
pub(crate) value: V,
|
||||||
crate changed_at: ChangedAt,
|
pub(crate) changed_at: ChangedAt,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DatabaseImpl {
|
pub struct DatabaseImpl {
|
||||||
runtime: salsa::Runtime<DatabaseImpl>,
|
runtime: salsa::Runtime<DatabaseImpl>,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
crate struct Counter {
|
pub(crate) struct Counter {
|
||||||
value: Cell<usize>,
|
value: Cell<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Counter {
|
impl Counter {
|
||||||
crate fn increment(&self) -> usize {
|
pub(crate) fn increment(&self) -> usize {
|
||||||
let v = self.value.get();
|
let v = self.value.get();
|
||||||
self.value.set(v + 1);
|
self.value.set(v + 1);
|
||||||
v
|
v
|
||||||
|
|
|
@ -4,20 +4,20 @@ use crate::memoized_dep_inputs;
|
||||||
use crate::memoized_inputs;
|
use crate::memoized_inputs;
|
||||||
use crate::memoized_volatile;
|
use crate::memoized_volatile;
|
||||||
|
|
||||||
crate trait TestContext: salsa::Database {
|
pub(crate) trait TestContext: salsa::Database {
|
||||||
fn clock(&self) -> &Counter;
|
fn clock(&self) -> &Counter;
|
||||||
fn log(&self) -> &Log;
|
fn log(&self) -> &Log;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
crate struct TestContextImpl {
|
pub(crate) struct TestContextImpl {
|
||||||
runtime: salsa::Runtime<TestContextImpl>,
|
runtime: salsa::Runtime<TestContextImpl>,
|
||||||
clock: Counter,
|
clock: Counter,
|
||||||
log: Log,
|
log: Log,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestContextImpl {
|
impl TestContextImpl {
|
||||||
crate fn assert_log(&self, expected_log: &[&str]) {
|
pub(crate) fn assert_log(&self, expected_log: &[&str]) {
|
||||||
use difference::{Changeset, Difference};
|
use difference::{Changeset, Difference};
|
||||||
|
|
||||||
let expected_text = &format!("{:#?}", expected_log);
|
let expected_text = &format!("{:#?}", expected_log);
|
||||||
|
@ -42,7 +42,7 @@ impl TestContextImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
salsa::database_storage! {
|
salsa::database_storage! {
|
||||||
crate struct TestContextImplStorage for TestContextImpl {
|
pub(crate) struct TestContextImplStorage for TestContextImpl {
|
||||||
impl memoized_dep_inputs::MemoizedDepInputsContext {
|
impl memoized_dep_inputs::MemoizedDepInputsContext {
|
||||||
fn dep_memoized2() for memoized_dep_inputs::Memoized2;
|
fn dep_memoized2() for memoized_dep_inputs::Memoized2;
|
||||||
fn dep_memoized1() for memoized_dep_inputs::Memoized1;
|
fn dep_memoized1() for memoized_dep_inputs::Memoized1;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
crate struct Log {
|
pub(crate) struct Log {
|
||||||
data: RefCell<Vec<String>>,
|
data: RefCell<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Log {
|
impl Log {
|
||||||
crate fn add(&self, text: impl Into<String>) {
|
pub(crate) fn add(&self, text: impl Into<String>) {
|
||||||
self.data.borrow_mut().push(text.into());
|
self.data.borrow_mut().push(text.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn take(&self) -> Vec<String> {
|
pub(crate) fn take(&self) -> Vec<String> {
|
||||||
std::mem::replace(&mut *self.data.borrow_mut(), vec![])
|
std::mem::replace(&mut *self.data.borrow_mut(), vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
|
||||||
#![feature(underscore_imports)]
|
#![feature(underscore_imports)]
|
||||||
|
|
||||||
mod counter;
|
mod counter;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::implementation::{TestContext, TestContextImpl};
|
||||||
use salsa::Database;
|
use salsa::Database;
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
crate trait MemoizedDepInputsContext: TestContext {
|
pub(crate) trait MemoizedDepInputsContext: TestContext {
|
||||||
fn dep_memoized2(key: ()) -> usize {
|
fn dep_memoized2(key: ()) -> usize {
|
||||||
type Memoized2;
|
type Memoized2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::implementation::{TestContext, TestContextImpl};
|
||||||
use salsa::Database;
|
use salsa::Database;
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
crate trait MemoizedInputsContext: TestContext {
|
pub(crate) trait MemoizedInputsContext: TestContext {
|
||||||
fn max(key: ()) -> usize {
|
fn max(key: ()) -> usize {
|
||||||
type Max;
|
type Max;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::implementation::{TestContext, TestContextImpl};
|
||||||
use salsa::Database;
|
use salsa::Database;
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
crate trait MemoizedVolatileContext: TestContext {
|
pub(crate) trait MemoizedVolatileContext: TestContext {
|
||||||
// Queries for testing a "volatile" value wrapped by
|
// Queries for testing a "volatile" value wrapped by
|
||||||
// memoization.
|
// memoization.
|
||||||
fn memoized2(key: ()) -> usize {
|
fn memoized2(key: ()) -> usize {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
|
||||||
#![feature(underscore_imports)]
|
#![feature(underscore_imports)]
|
||||||
|
|
||||||
mod implementation;
|
mod implementation;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
crate trait Counter: salsa::Database {
|
pub(crate) trait Counter: salsa::Database {
|
||||||
fn increment(&self) -> usize;
|
fn increment(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
crate trait Database: Counter {
|
pub(crate) trait Database: Counter {
|
||||||
fn memoized(key: ()) -> usize {
|
fn memoized(key: ()) -> usize {
|
||||||
type Memoized;
|
type Memoized;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue