Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Jan 2, 2025
1 parent c6a0984 commit 7a22871
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum BindingGraphInitializationError {
pub fn create_with_resolver(
version: Version,
resolver: Rc<dyn PathResolver<KindTypes>>,
) -> Result<BindingGraphBuilder, ParserInitializationError> {
) -> Result<BindingGraphBuilder, BindingGraphInitializationError> {
let mut binding_graph = BindingGraphBuilder::create(
version.clone(),
binding_rules::BINDING_RULES_SOURCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ impl CompilationUnit {
files: self.files.clone(),
};

let mut binding_graph =
let mut builder =
create_with_resolver(self.language_version.clone(), Rc::new(resolver))?;

for (id, file) in &self.files {
binding_graph.add_user_file(id, file.create_tree_cursor());
builder.add_user_file(id, file.create_tree_cursor());
}

Ok(binding_graph.resolve())
Ok(builder.build())
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/runtime/cargo/crate/src/runtime/cst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod terminal_kind;
pub use edge_label::EdgeLabel;
pub(crate) use lexical_context::{IsLexicalContext, LexicalContext, LexicalContextType};
pub use metaslang_cst::kinds::{
EdgeLabelExtensions, NonterminalKindExtensions, TerminalKindExtensions,
EdgeLabelExtensions, NodeKind, NonterminalKindExtensions, TerminalKindExtensions,
};
pub use nonterminal_kind::NonterminalKind;
pub use terminal_kind::TerminalKind;
Expand Down
2 changes: 1 addition & 1 deletion crates/metaslang/bindings/generated/public_api.txt

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

2 changes: 1 addition & 1 deletion crates/metaslang/bindings/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<KT: KindTypes + 'static> BindingGraphBuilder<KT> {
result
}

pub fn resolve(self) -> Rc<BindingGraph<KT>> {
pub fn build(self) -> Rc<BindingGraph<KT>> {
let resolver = Resolver::new(&self);
let resolved_references = resolver.resolve();
BindingGraph::build(self, resolved_references)
Expand Down
20 changes: 10 additions & 10 deletions crates/metaslang/bindings/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ pub struct BindingGraph<KT: KindTypes + 'static> {

impl<KT: KindTypes + 'static> BindingGraph<KT> {
pub(crate) fn build(
binding_graph: BindingGraphBuilder<KT>,
builder: BindingGraphBuilder<KT>,
resolved_references: HashMap<GraphHandle, Vec<GraphHandle>>,
) -> Rc<Self> {
let mut files = HashMap::new();
for handle in binding_graph.stack_graph.iter_files() {
for handle in builder.stack_graph.iter_files() {
files.insert(
handle,
FileDescriptor::from(binding_graph.stack_graph[handle].name()),
FileDescriptor::from(builder.stack_graph[handle].name()),
);
}
let mut definitions = BTreeMap::new();
let mut references = BTreeMap::new();
for handle in binding_graph.stack_graph.iter_nodes() {
let graph_node = &binding_graph.stack_graph[handle];
for handle in builder.stack_graph.iter_nodes() {
let graph_node = &builder.stack_graph[handle];
let Some(file) = graph_node.file() else {
continue;
};
if graph_node.is_definition() {
let cursor = binding_graph
let cursor = builder
.cursors
.get(&handle)
.expect("Definition to have a valid cursor")
.clone();
let definiens = binding_graph.definitions_info[&handle].definiens.clone();
let definiens = builder.definitions_info[&handle].definiens.clone();
definitions.insert(
handle,
DefinitionInfo {
Expand All @@ -70,7 +70,7 @@ impl<KT: KindTypes + 'static> BindingGraph<KT> {
},
);
} else if graph_node.is_reference() {
let cursor = binding_graph
let cursor = builder
.cursors
.get(&handle)
.expect("Reference to have a valid cursor")
Expand All @@ -83,8 +83,8 @@ impl<KT: KindTypes + 'static> BindingGraph<KT> {
files,
definitions,
references,
cursor_to_definitions: binding_graph.cursor_to_definitions,
cursor_to_references: binding_graph.cursor_to_references,
cursor_to_definitions: builder.cursor_to_definitions,
cursor_to_references: builder.cursor_to_references,
resolved_references,
})
}
Expand Down
28 changes: 28 additions & 0 deletions crates/metaslang/cst/src/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,31 @@ pub trait KindTypes: std::fmt::Debug + Clone + PartialEq {
type TerminalKind: TerminalKindExtensions;
type EdgeLabel: EdgeLabelExtensions;
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NodeKind<T: KindTypes> {
Nonterminal(T::NonterminalKind),
Terminal(T::TerminalKind),
}

impl<T: KindTypes> From<NodeKind<T>> for &'static str {
fn from(val: NodeKind<T>) -> Self {
match val {
NodeKind::Nonterminal(t) => t.as_static_str(),
NodeKind::Terminal(t) => t.as_static_str(),
}
}
}

impl<T: KindTypes> std::fmt::Display for NodeKind<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NodeKind::Nonterminal(t) => {
write!(f, "{}", t.as_static_str())
}
NodeKind::Terminal(t) => {
write!(f, "{}", t.as_static_str())
}
}
}
}
30 changes: 1 addition & 29 deletions crates/metaslang/cst/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,9 @@ use std::rc::Rc;
use serde::Serialize;

use crate::cursor::{Cursor, CursorIterator};
use crate::kinds::{BaseKind, KindTypes, TerminalKindExtensions};
use crate::kinds::{KindTypes, NodeKind, TerminalKindExtensions};
use crate::text_index::TextIndex;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NodeKind<T: KindTypes> {
Nonterminal(T::NonterminalKind),
Terminal(T::TerminalKind),
}

impl<T: KindTypes> From<NodeKind<T>> for &'static str {
fn from(val: NodeKind<T>) -> Self {
match val {
NodeKind::Nonterminal(t) => t.as_static_str(),
NodeKind::Terminal(t) => t.as_static_str(),
}
}
}

impl<T: KindTypes> std::fmt::Display for NodeKind<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NodeKind::Nonterminal(t) => {
write!(f, "{}", t.as_static_str())
}
NodeKind::Terminal(t) => {
write!(f, "{}", t.as_static_str())
}
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct TerminalNode<T: KindTypes> {
pub kind: T::TerminalKind,
Expand Down

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 @@ -9,7 +9,7 @@ use crate::cst::{Edge, Node, NonterminalNode, TerminalKind, TerminalNode};
use crate::parser::{Parser, ParserInitializationError};

pub fn add_built_ins(
binding_graph_builder: &mut BindingGraphBuilder,
builder: &mut BindingGraphBuilder,
version: Version,
) -> Result<(), ParserInitializationError> {
let source = get_built_ins_contents(&version);
Expand All @@ -18,7 +18,7 @@ pub fn add_built_ins(

let built_ins_cursor = transform(parse_output.tree()).cursor_with_offset(TextIndex::ZERO);

binding_graph_builder.add_system_file("built_ins.sol", built_ins_cursor);
builder.add_system_file("built_ins.sol", built_ins_cursor);
Ok(())
}

Expand Down

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

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

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 @@ -94,7 +94,7 @@ impl ParsedPart<'_> {

fn check_bindings_coverage<'a>(
part: &'a ParsedPart<'a>,
binding_graph: &'a BindingGraph,
binding_graph: &Rc<BindingGraph>,
) -> (Report<'a, ReportSpan<'a>>, bool) {
let mut all_identifiers_bound = true;
let mut builder: ReportBuilder<'_, ReportSpan<'_>> = Report::build(
Expand Down Expand Up @@ -219,7 +219,7 @@ fn build_report_for_part<'a>(

fn build_definiens_report<'a>(
part: &'a ParsedPart<'a>,
all_definitions: &'a [Definition<'a>],
all_definitions: &'a [Definition],
) -> Report<'a, ReportSpan<'a>> {
let mut builder: ReportBuilder<'_, ReportSpan<'_>> =
Report::build(ReportKind::Custom("Definiens", Color::Unset), part.path, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn run(group_name: &str, test_name: &str) -> Result<()> {

for version in &VERSION_BREAKS {
let parser = Parser::create(version.clone())?;
let mut binding_graph =
let mut builder =
bindings::create_with_resolver(version.clone(), Rc::new(TestsPathResolver {}))?;

let mut parsed_parts: Vec<ParsedPart<'_>> = Vec::new();
Expand All @@ -55,8 +55,8 @@ pub fn run(group_name: &str, test_name: &str) -> Result<()> {
} in &multi_part.parts
{
let parse_output = parser.parse(Parser::ROOT_KIND, contents);
let graph = binding_graph
.add_user_file_returning_graph(path, parse_output.create_tree_cursor());
let graph =
builder.add_user_file_returning_graph(path, parse_output.create_tree_cursor());
parsed_parts.push(ParsedPart {
path,
contents,
Expand All @@ -65,7 +65,7 @@ pub fn run(group_name: &str, test_name: &str) -> Result<()> {
});
}

let binding_graph = binding_graph.resolve();
let binding_graph = builder.build();
let (bindings_output, all_resolved) = render_bindings(&binding_graph, &parsed_parts)?;

let parse_success = parsed_parts.iter().all(|part| part.parse_output.is_valid());
Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/testing/perf/src/tests/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn setup() -> BindingGraphBuilder {
}

pub fn run(binding_graph_builder: BindingGraphBuilder) {
let binding_graph = binding_graph_builder.resolve();
let binding_graph = binding_graph_builder.build();

let definition_count = binding_graph
.all_definitions()
Expand Down
39 changes: 20 additions & 19 deletions crates/solidity/testing/sanctuary/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use infra_utils::paths::PathExtensions;
use itertools::Itertools;
use metaslang_bindings::PathResolver;
use semver::Version;
use slang_solidity::bindings::{self, BindingGraphBuilder};
use slang_solidity::bindings::{self, BindingGraph};
use slang_solidity::cst::{Cursor, KindTypes, NonterminalKind, Query, TextRange};
use slang_solidity::diagnostic::{Diagnostic, Severity};
use slang_solidity::parser::{ParseOutput, Parser};
Expand Down Expand Up @@ -186,7 +186,7 @@ fn run_bindings_check(
output: &ParseOutput,
) -> Result<Vec<BindingError>> {
let mut errors = Vec::new();
let binding_graph = create_bindings(version, source_id, output)?.resolve();
let binding_graph = create_bindings(version, source_id, output)?;

for reference in binding_graph.all_references() {
if reference.get_file().is_system() {
Expand All @@ -201,45 +201,46 @@ fn run_bindings_check(
}
}

// Check that all `Identifier` and `YulIdentifier` nodes are bound to either
// a definition or a reference
let query = Query::parse("@identifier ([Identifier] | [YulIdentifier])").unwrap();
let tree_cursor = output.create_tree_cursor();
for result in tree_cursor.query(vec![query]) {
let identifier_cursor = result.captures.get("identifier").unwrap().first().unwrap();
let parent = {
let mut parent_cursor = identifier_cursor.spawn();
parent_cursor.go_to_parent();
parent_cursor.node()
};
if parent.is_nonterminal_with_kind(NonterminalKind::ExperimentalFeature) {
// ignore identifiers in `pragma experimental` directives
// Check that all `Identifier` and `YulIdentifier` nodes are bound to either a definition or a reference:

let cursor = output.create_tree_cursor();

while cursor
.go_to_next_terminal_with_kinds(&[TerminalKind::Identifier, TerminalKind::YulIdentifier])
{
if matches!(
cursor.ancestors().next(),
Some(ancestor) if ancestor.kind == NonterminalKind::ExperimentalFeature
) {
// ignore identifiers in `pragma experimental` directives, as they are unbound feature names:
continue;
}

if binding_graph.definition_at(identifier_cursor).is_none()
&& binding_graph.reference_at(identifier_cursor).is_none()
{
errors.push(BindingError::UnboundIdentifier(identifier_cursor.clone()));
}
}

Ok(errors)
}

fn create_bindings(
version: &Version,
source_id: &str,
output: &ParseOutput,
) -> Result<BindingGraphBuilder> {
let mut binding_graph_builder = bindings::create_with_resolver(
) -> Result<Rc<BindingGraph>> {
let mut builder = bindings::create_with_resolver(
version.clone(),
Rc::new(SingleFileResolver {
source_id: source_id.into(),
}),
)?;

binding_graph_builder.add_user_file(source_id, output.create_tree_cursor());
builder.add_user_file(source_id, output.create_tree_cursor());

Ok(binding_graph_builder)
Ok(builder.build())
}

/// The `PathResolver` that always resolves to the given `source_id`.
Expand Down

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

Loading

0 comments on commit 7a22871

Please sign in to comment.