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

Use database of partial paths to speed up bindings resolution #1198

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2117d83
Remove bindings target context `{set,get}_context` methods
ggiraldez Dec 16, 2024
76501df
Use `Reference::definitions()` instead of `resolve_definition()`
ggiraldez Dec 16, 2024
9ed010d
Migrate some binding assertions tests to snapshots
ggiraldez Dec 16, 2024
cd7eb08
Migrate binding assertions for constants, control and arrays to snaps…
ggiraldez Dec 17, 2024
ffc1c19
Migrate events and errors binding assertions tests to snapshots
ggiraldez Dec 17, 2024
c7113d7
Migrate functions/function types/scoping/imports bindings tests from …
ggiraldez Dec 17, 2024
6cc223c
Finish migration of bindings assertions to snapshots
ggiraldez Dec 17, 2024
5f5575b
Remove bindings assertions completely
ggiraldez Dec 17, 2024
e695f07
Remove parsing of context in bindings test files
ggiraldez Dec 17, 2024
0fbd092
Update public_api.txt
ggiraldez Dec 17, 2024
862f382
Remove `resolve_definition()` in favor of `definitions()`
ggiraldez Dec 17, 2024
a33b0e7
Remove C3 linearization algorithm implementation
ggiraldez Dec 17, 2024
009e9f3
Remove `tag` graph attribute
ggiraldez Dec 17, 2024
02905e4
Update perf tests resolved reference count
ggiraldez Dec 17, 2024
cb802ad
Formatting fixes
ggiraldez Dec 17, 2024
842ba72
Mark extension hooks and scopes with `is_exported` and `is_endpoint` …
ggiraldez Dec 4, 2024
d403c52
Basic resolver using a database of minimal partial paths
ggiraldez Dec 5, 2024
b66e21e
Disable graph debugging info (improving processing times)
ggiraldez Dec 5, 2024
c59033b
Add method to resolve all at once and save results
ggiraldez Dec 6, 2024
44ee978
Perform scope extension with a database of partial paths
ggiraldez Dec 6, 2024
78ad197
Fix linter warnings
ggiraldez Dec 10, 2024
f99d54c
Reclaim `PartialPaths` allocated memory after each reference resolved
ggiraldez Dec 10, 2024
ad0ec96
Encapsulate building the database when constructing the `DatabaseReso…
ggiraldez Dec 11, 2024
73c870e
Refactor: move most reference/definition getters to the `Bindings` owner
ggiraldez Dec 12, 2024
3acf4ce
Expose `DatabaseResolver` type as public
ggiraldez Dec 12, 2024
db02560
Update public_api.txt
ggiraldez Dec 17, 2024
25239f1
Replace old resolver with database resolver
ggiraldez Dec 19, 2024
e90a6e5
Remove obsolete `ResolutionError`
ggiraldez Dec 19, 2024
9b1cc3f
`Definition` and `Reference` take an `Rc<>` instead of a reference to…
ggiraldez Dec 19, 2024
203eda7
Add a bit of documentation
ggiraldez Dec 19, 2024
8c55602
Split builder part of `BindingGraph` to use before calling `resolve()`
ggiraldez Dec 19, 2024
70e9607
Rename bindings `Builder` to `Loader`
ggiraldez Dec 23, 2024
edf12f2
Refactor: move bindings builder into its own module along with resolv…
ggiraldez Dec 23, 2024
7cc333c
Remove wrappers for Definition/Reference used in WASM
ggiraldez Dec 23, 2024
bff3daa
Update stack-graphs dependency to the `nomic` branch of our fork
ggiraldez Dec 24, 2024
4b18696
Refactor performance to try to keep consistent with previous bencher …
ggiraldez Dec 24, 2024
1b36243
Update public_api.txt
ggiraldez Dec 24, 2024
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
11 changes: 4 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ serde = { version = "1.0.216", features = ["derive", "rc"] }
serde_json = { version = "1.0.133", features = ["preserve_order"] }
similar-asserts = { version = "1.6.0" }
smallvec = { version = "1.7.0", features = ["union"] }
stack-graphs = { version = "0.13.0" }
stack-graphs = { git = "https://github.com/NomicFoundation/stack-graphs", branch = "nomic" }
string-interner = { version = "0.17.0", features = [
OmarTawfik marked this conversation as resolved.
Show resolved Hide resolved
"std",
OmarTawfik marked this conversation as resolved.
Show resolved Hide resolved
"inline-more",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use semver::Version;
OmarTawfik marked this conversation as resolved.
Show resolved Hide resolved

use crate::bindings::BindingGraph;
use crate::bindings::BindingGraphBuilder;
use crate::parser::ParserInitializationError;

#[allow(clippy::needless_pass_by_value)]
pub fn add_built_ins(
_binding_graph: &mut BindingGraph,
_binding_graph_builder: &mut BindingGraphBuilder,
_version: Version,
) -> Result<(), ParserInitializationError> {
unreachable!("Built-ins are Solidity-specific")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use semver::Version;

use crate::cst::KindTypes;

pub type BindingGraphBuilder = metaslang_bindings::BindingGraphBuilder<KindTypes>;
pub type BindingGraph = metaslang_bindings::BindingGraph<KindTypes>;
pub type Definition<'a> = metaslang_bindings::Definition<'a, KindTypes>;
pub type Reference<'a> = metaslang_bindings::Reference<'a, KindTypes>;
pub type Definition = metaslang_bindings::Definition<KindTypes>;
pub type Reference = metaslang_bindings::Reference<KindTypes>;
pub type BindingLocation = metaslang_bindings::BindingLocation<KindTypes>;
pub type UserFileLocation = metaslang_bindings::UserFileLocation<KindTypes>;

Expand All @@ -29,8 +30,8 @@ pub enum BindingGraphInitializationError {
pub fn create_with_resolver(
version: Version,
resolver: Rc<dyn PathResolver<KindTypes>>,
) -> Result<BindingGraph, ParserInitializationError> {
let mut binding_graph = BindingGraph::create(
) -> Result<BindingGraphBuilder, ParserInitializationError> {
let mut binding_graph = BindingGraphBuilder::create(
version.clone(),
binding_rules::BINDING_RULES_SOURCE,
resolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl CompilationUnit {
binding_graph.add_user_file(id, file.create_tree_cursor());
}

Ok(Rc::new(binding_graph))
Ok(binding_graph.resolve())
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,8 @@ mod ffi {

mod rust {
pub use crate::rust_crate::bindings::{
BindingGraph, BindingLocation, BuiltInLocation, UserFileLocation,
BindingGraph, BindingLocation, BuiltInLocation, Definition, Reference, UserFileLocation,
};

/// TODO: This is a work-around for the fact that `metaslang_bindings` internals (handles, locators, etc...) are exposed.
/// We should clean this when we finally publish `__experimental_bindings_api`.
/// That means removing the types below, and using the original types instead.
#[derive(Debug, Clone)]
pub struct Definition {
pub id: usize,
pub name_location: BindingLocation,
pub definiens_location: BindingLocation,
}

impl From<crate::rust_crate::bindings::Definition<'_>> for Definition {
fn from(definition: crate::rust_crate::bindings::Definition<'_>) -> Self {
Self {
id: definition.id(),
name_location: definition.name_location(),
definiens_location: definition.definiens_location(),
}
}
}

/// TODO: This is a work-around for the fact that `metaslang_bindings` internals (handles, locators, etc...) are exposed.
/// We should clean this when we finally publish `__experimental_bindings_api`.
/// That means removing the types below, and using the original types instead.
#[derive(Debug, Clone)]
pub struct Reference {
pub id: usize,
pub location: BindingLocation,
pub definitions: Vec<Definition>,
}

impl From<crate::rust_crate::bindings::Reference<'_>> for Reference {
fn from(reference: crate::rust_crate::bindings::Reference<'_>) -> Self {
Self {
id: reference.id(),
location: reference.location(),
definitions: reference
.definitions()
.into_iter()
.map(Into::into)
.collect(),
}
}
}
}

impl ffi::Guest for crate::wasm_crate::World {
Expand Down Expand Up @@ -100,15 +56,15 @@ define_rc_wrapper! { BindingGraph {

define_wrapper! { Definition {
fn id(&self) -> u32 {
self._borrow_ffi().id.try_into().unwrap()
self._borrow_ffi().id().try_into().unwrap()
}

fn name_location(&self) -> ffi::BindingLocation {
self._borrow_ffi().name_location.clone()._into_ffi()
self._borrow_ffi().name_location()._into_ffi()
}

fn definiens_location(&self) -> ffi::BindingLocation {
self._borrow_ffi().definiens_location.clone()._into_ffi()
self._borrow_ffi().definiens_location()._into_ffi()
}
} }

Expand All @@ -120,15 +76,15 @@ define_wrapper! { Definition {

define_wrapper! { Reference {
fn id(&self) -> u32 {
self._borrow_ffi().id.try_into().unwrap()
self._borrow_ffi().id().try_into().unwrap()
}

fn location(&self) -> ffi::BindingLocation {
self._borrow_ffi().location.clone()._into_ffi()
self._borrow_ffi().location().clone()._into_ffi()
}

fn definitions(&self) -> Vec<ffi::Definition> {
self._borrow_ffi().definitions.iter().cloned().map(IntoFFI::_into_ffi).collect()
self._borrow_ffi().definitions().iter().cloned().map(IntoFFI::_into_ffi).collect()
}
} }

Expand Down
97 changes: 41 additions & 56 deletions crates/metaslang/bindings/generated/public_api.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ mod resolver {
use metaslang_graph_builder::graph::{Graph, Value};
use metaslang_graph_builder::ExecutionError;

use crate::{FileDescriptor, PathResolver};
use crate::builder::FileDescriptor;
use crate::PathResolver;

pub fn add_functions<KT: KindTypes + 'static>(
functions: &mut Functions<KT>,
Expand Down
Loading