Skip to content

Commit b45feba

Browse files
committed
Remove SemanticBuilder and address PR comments
1 parent e4499cb commit b45feba

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

crates/solidity/outputs/cargo/crate/src/backend/passes/p1_flatten_contracts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use crate::backend::ir::ir2_flat_contracts::{self as output, input};
77
use crate::cst::TerminalNode;
88
use crate::utils::versions::VERSION_0_5_0;
99

10+
/// This pass makes ergonomic changes to the AST in order to make it easier to
11+
/// use. It includes changes such as removing redundant intermediate nodes,
12+
/// unifying similar node types and computing visibility/mutability from
13+
/// collections of attributes.
1014
pub fn run_file(language_version: &Version, source_unit: &input::SourceUnit) -> output::SourceUnit {
1115
let mut pass = Pass {
1216
language_version: language_version.clone(),

crates/solidity/outputs/cargo/crate/src/backend/semantic/mod.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@ use crate::compilation::File;
1111
use crate::cst::{Cursor, NonterminalNode};
1212
use crate::parser::ParseError;
1313

14-
pub struct SemanticBuilder {
15-
language_version: Version,
16-
files: Vec<Rc<File>>,
17-
}
18-
19-
impl SemanticBuilder {
20-
pub fn create(language_version: Version) -> Self {
21-
Self {
22-
language_version,
23-
files: Vec::new(),
24-
}
25-
}
26-
27-
pub fn add_file(&mut self, file: Rc<File>) {
28-
self.files.push(file);
29-
}
30-
31-
pub fn build(self) -> SemanticAnalysis {
32-
SemanticAnalysis::create(self.language_version, self.files)
33-
}
34-
}
35-
3614
#[derive(Clone)]
3715
pub struct SemanticFile {
3816
file: Rc<File>,
@@ -76,12 +54,15 @@ pub struct SemanticAnalysis {
7654
}
7755

7856
impl SemanticAnalysis {
79-
fn create(language_version: Version, files: Vec<Rc<File>>) -> Self {
57+
pub(crate) fn create<'a>(
58+
language_version: Version,
59+
files: impl Iterator<Item = &'a Rc<File>>,
60+
) -> Self {
8061
let mut semantic_analysis = Self::new(language_version);
8162

8263
for file in files {
8364
let file_id = file.id().to_string();
84-
let Some(structured_ast) = passes::p0_build_ast::run_file(&file) else {
65+
let Some(structured_ast) = passes::p0_build_ast::run_file(file) else {
8566
// TODO(validation): the file is not valid and cannot be turned
8667
// into a typed IR tree
8768
continue;
@@ -90,7 +71,10 @@ impl SemanticAnalysis {
9071
semantic_analysis.language_version(),
9172
&structured_ast,
9273
);
93-
let semantic_file = SemanticFile { file, ir_root };
74+
let semantic_file = SemanticFile {
75+
file: Rc::clone(file),
76+
ir_root,
77+
};
9478
semantic_analysis.files.insert(file_id, semantic_file);
9579
}
9680

crates/solidity/outputs/cargo/crate/src/compilation/unit.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ impl CompilationUnit {
7878
#[cfg(feature = "__private_backend_api")]
7979
#[doc(hidden)]
8080
pub fn semantic_analysis(&self) -> &Rc<SemanticAnalysis> {
81-
use crate::backend::semantic::SemanticBuilder;
82-
8381
self.semantic_analysis.get_or_init(|| {
84-
let mut builder = SemanticBuilder::create(self.language_version.clone());
85-
for file in self.files.values() {
86-
builder.add_file(Rc::clone(file));
87-
}
88-
Rc::new(builder.build())
82+
Rc::new(SemanticAnalysis::create(
83+
self.language_version.clone(),
84+
self.files.values(),
85+
))
8986
})
9087
}
9188
}

0 commit comments

Comments
 (0)