Skip to content

Commit

Permalink
Experiment with accessor API
Browse files Browse the repository at this point in the history
  • Loading branch information
AZWN committed Nov 27, 2023
1 parent 1e3d77a commit 42a3f51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 194 deletions.
1 change: 1 addition & 0 deletions scopegraphs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bumpalo = "3.14.0"
prust-lib = {git="https://github.com/jdonszelmann/prust", branch = "main"}
scopegraphs-regular-expressions = {path = "../scopegraphs-regular-expressions"}

Expand Down
58 changes: 30 additions & 28 deletions scopegraphs-lib/src/resolve/topdown.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::hash::Hash;
use std::iter;

use crate::label::Label;
use crate::{
label::Label,
scopegraph::{Scope, ScopeRef},

Check failure on line 6 in scopegraphs-lib/src/resolve/topdown.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved imports `crate::scopegraph::Scope`, `crate::scopegraph::ScopeRef`

error[E0432]: unresolved imports `crate::scopegraph::Scope`, `crate::scopegraph::ScopeRef` --> scopegraphs-lib/src/resolve/topdown.rs:6:18 | 6 | scopegraph::{Scope, ScopeRef}, | ^^^^^ ^^^^^^^^ no `ScopeRef` in `scopegraph` | | | no `Scope` in `scopegraph` | = help: consider importing this struct instead: std::thread::Scope
};
use scopegraphs_regular_expressions::RegexMatcher;

use super::{Env, Path, ResolvedPath};
Expand All @@ -16,6 +19,7 @@ impl<LABEL, T> LabelOrder<LABEL> for T where T: Fn(&EdgeOrData<LABEL>, &EdgeOrDa
pub trait DataOrder<DATA>: for<'sg> Fn(&'sg DATA, &'sg DATA) -> bool {}
impl<DATA, T> DataOrder<DATA> for T where for<'sg> T: Fn(&'sg DATA, &'sg DATA) -> bool {}

#[derive(Debug, Hash, PartialEq, Eq)]
pub enum EdgeOrData<'lbl, LABEL> {
Data,
Edge(&'lbl LABEL),
Expand All @@ -29,19 +33,18 @@ impl<LABEL> Clone for EdgeOrData<'_, LABEL> {
}
impl<LABEL> Copy for EdgeOrData<'_, LABEL> {}

pub fn resolve<'sg, 'lbl, SCOPE, LABEL: 'lbl, DATA>(
sg: &'sg ScopeGraph<SCOPE, LABEL, DATA>,
pub fn resolve<'sg, 'lbl, LABEL: 'lbl, DATA>(
sg: &'sg ScopeGraph<LABEL, DATA>,
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
data_wellformedness: &impl DataWellformedness<DATA>,
label_order: &impl LabelOrder<LABEL>,
data_order: &impl DataOrder<DATA>,
source: &'sg SCOPE,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA>
source: ScopeRef<'sg, 'lbl, LABEL, DATA>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA>
where
LABEL: Label<'lbl>,
SCOPE: Hash + Eq,
ResolvedPath<'sg, 'lbl, SCOPE, LABEL, DATA>: Hash + Eq,
Path<'sg, 'lbl, SCOPE, LABEL>: Clone,
ResolvedPath<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA>: Hash + Eq,
Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>: Clone,
{
let all_edges: Vec<EdgeOrData<LABEL>> = LABEL::iter_ref()
.map(EdgeOrData::Edge)
Expand All @@ -59,29 +62,28 @@ where
context.resolve_all(path_wellformedness, &Path::new(source))
}

struct ResolutionContext<'sg, 'lbl, 'query, SCOPE, LABEL, DATA, DWF, LO, DO> {
struct ResolutionContext<'sg, 'lbl, 'query, LABEL, DATA, DWF, LO, DO> {
all_edges: Vec<EdgeOrData<'lbl, LABEL>>,
sg: &'sg ScopeGraph<SCOPE, LABEL, DATA>,
sg: &'sg ScopeGraph<LABEL, DATA>,
data_wellformedness: &'query DWF,
label_order: &'query LO,
data_order: &'query DO,
}

impl<'sg, 'lbl, 'query, SCOPE, LABEL: 'lbl, DATA, DWF, LO, DO>
ResolutionContext<'sg, 'lbl, 'query, SCOPE, LABEL, DATA, DWF, LO, DO>
impl<'sg, 'lbl: 'sg, 'query, LABEL: 'lbl, DATA, DWF, LO, DO>
ResolutionContext<'sg, 'lbl, 'query, LABEL, DATA, DWF, LO, DO>
where
SCOPE: Eq + Hash,
ResolvedPath<'sg, 'lbl, SCOPE, LABEL, DATA>: Hash + Eq,
ResolvedPath<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA>: Hash + Eq,
DO: DataOrder<DATA>,
DWF: DataWellformedness<DATA>,
LO: LabelOrder<LABEL>,
Path<'sg, 'lbl, SCOPE, LABEL>: Clone,
Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>: Clone,
{
fn resolve_all(
&self,
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
let edges: Vec<_> = self
.all_edges
.iter()
Expand All @@ -99,10 +101,10 @@ where
&self,
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
edges: &[EdgeOrData<'lbl, LABEL>],
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
let max = self.max(edges);
let mut env: Env<SCOPE, LABEL, DATA> = Env::new();
let mut env: Env<Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> = Env::new();

for edge in max {
let smaller = self.smaller(edge, edges);
Expand All @@ -117,8 +119,8 @@ where
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
edge: EdgeOrData<'lbl, LABEL>,
edges: &[EdgeOrData<'lbl, LABEL>],
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
let mut env = Env::new();
env.merge(self.resolve_edges(path_wellformedness, edges, path));
let new = self
Expand All @@ -137,8 +139,8 @@ where
&self,
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
edge: EdgeOrData<'lbl, LABEL>,
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
match edge {
EdgeOrData::Edge(label) => self.resolve_label(path_wellformedness, label, path),
EdgeOrData::Data => self.resolve_data(path),
Expand All @@ -149,8 +151,8 @@ where
&self,
path_wellformedness: &mut impl RegexMatcher<&'lbl LABEL>,
label: &'lbl LABEL,
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
path_wellformedness.step(label);
let mut env = Env::new();
for tgt in self.sg.get_edges(path.target(), label) {
Expand All @@ -164,8 +166,8 @@ where

fn resolve_data(
&self,
path: &Path<'sg, 'lbl, SCOPE, LABEL>,
) -> Env<'sg, 'lbl, SCOPE, LABEL, DATA> {
path: &Path<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL>,
) -> Env<'sg, 'lbl, Scope<'sg, 'lbl, LABEL, DATA>, LABEL, DATA> {
if let Some(data) = self.sg.get_data(path.target()) {
if (self.data_wellformedness)(data) {
return Env::single(path.clone().resolve(data));
Expand Down
166 changes: 0 additions & 166 deletions scopegraphs-lib/src/scopegraph.rs

This file was deleted.

0 comments on commit 42a3f51

Please sign in to comment.