Skip to content
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

Misc API changes #37

Merged
merged 9 commits into from
Oct 15, 2021
Merged
Changes from 1 commit
Commits
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
make Database::segments not an option
digama0 committed Oct 14, 2021
commit 2ddd2221dee556a237928a083e91131cc40bce42
16 changes: 8 additions & 8 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -373,7 +373,7 @@ impl<T> Promise<T> {
#[derive(Debug)]
pub struct Database {
options: Arc<DbOptions>,
segments: Option<Arc<SegmentSet>>,
segments: Arc<SegmentSet>,
/// We track the "current" and "previous" for all known passes, so that each
/// pass can use its most recent results for optimized incremental
/// processing. Any change to the segment vector zeroizes the current
@@ -414,7 +414,7 @@ impl Drop for Database {
self.scopes = None;
self.prev_nameset = None;
self.nameset = None;
self.segments = None;
Arc::make_mut(&mut self.segments).clear();
self.outline = None;
});
}
@@ -430,7 +430,7 @@ impl Database {
let options = Arc::new(options);
let exec = Executor::new(options.jobs);
Database {
segments: Some(Arc::new(SegmentSet::new(options.clone(), &exec))),
segments: Arc::new(SegmentSet::new(options.clone(), &exec)),
options,
nameset: None,
scopes: None,
@@ -475,7 +475,7 @@ impl Database {
/// appropriate.
pub fn parse(&mut self, start: String, text: Vec<(String, Vec<u8>)>) {
time(&self.options.clone(), "parse", || {
Arc::make_mut(self.segments.as_mut().unwrap()).read(start, text);
Arc::make_mut(&mut self.segments).read(start, text);
self.nameset = None;
self.scopes = None;
self.verify = None;
@@ -488,8 +488,8 @@ impl Database {
///
/// Unlike the other accessors, this is not lazy (subject to change when the
/// modification API goes in.)
pub(crate) fn parse_result(&self) -> &Arc<SegmentSet> {
self.segments.as_ref().unwrap()
pub(crate) const fn parse_result(&self) -> &Arc<SegmentSet> {
&self.segments
}

/// Calculates and returns the name to definition lookup table.
@@ -644,8 +644,8 @@ impl Database {

/// A getter method which does not build the outline
#[must_use]
pub const fn get_outline(&self) -> &Option<Arc<OutlineNode>> {
&self.outline
pub const fn get_outline(&self) -> Option<&Arc<OutlineNode>> {
self.outline.as_ref()
}

/// Get a statement by label.
8 changes: 8 additions & 0 deletions src/segment_set.rs
Original file line number Diff line number Diff line change
@@ -176,6 +176,14 @@ impl SegmentSet {
}
}

/// Reset the segment set to the empty state.
pub(crate) fn clear(&mut self) {
*Arc::make_mut(&mut self.order) = SegmentOrder::new();
self.segments = new_map();
self.parse_cache = new_map();
self.file_cache = new_map();
}

/// Iterates over all loaded segments in logical order.
pub(crate) fn segments(&self) -> Vec<SegmentRef<'_>> {
// this might be an actual iterator in the future if needs be