Skip to content

Commit e5f5c6d

Browse files
committed
feat: handle runtime code size errors separately
1 parent b85bd03 commit e5f5c6d

12 files changed

Lines changed: 93 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solx-solc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ rayon = "=1.10.0"
1616
serde = { version = "=1.0.210", "features" = [ "derive" ] }
1717
serde_json = { version = "=1.0.128", features = [ "arbitrary_precision" ] }
1818
semver = { version = "=1.0.23", features = [ "serde" ] }
19-
libc = "0.2"
19+
libc = "=0.2.171"
2020
hex = "=0.4.3"
2121
num = "=0.4.3"
2222

23+
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "az-error-code-runtime-code-size" }
2324
era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }

solx-solc/src/solc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,14 @@ impl Compiler {
133133
anyhow::bail!("solc standard JSON output parsing: {error:?}");
134134
}
135135
};
136-
eprintln!("{}", serde_json::to_string_pretty(&solc_output).unwrap());
137136

138137
input_json.resolve_sources();
138+
solc_output
139+
.errors
140+
.retain(|error| match error.error_code.as_deref() {
141+
Some(code) => !StandardJsonOutputError::IGNORED_WARNING_CODES.contains(&code),
142+
None => true,
143+
});
139144
solc_output.errors.append(messages);
140145
solc_output.preprocess_ast(&input_json.sources, &self.version)?;
141146
solc_output.remove_evm_artifacts();

solx-solc/src/standard_json/output/error/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Error {
4646
///
4747
pub fn new<S>(
4848
r#type: &str,
49+
error_code: Option<isize>,
4950
message: S,
5051
source_location: Option<SourceLocation>,
5152
sources: Option<&BTreeMap<String, StandardJsonInputSource>>,
@@ -59,7 +60,7 @@ impl Error {
5960
let mut formatted_message = if message_trimmed.starts_with(r#type) {
6061
message_trimmed.to_owned()
6162
} else {
62-
format!("{}: {}", r#type, message_trimmed)
63+
format!("{type}: {message_trimmed}")
6364
};
6465
formatted_message.push('\n');
6566
if let Some(ref source_location) = source_location {
@@ -76,7 +77,7 @@ impl Error {
7677

7778
Self {
7879
component: "general".to_owned(),
79-
error_code: None,
80+
error_code: error_code.map(|code| code.to_string()),
8081
formatted_message,
8182
message,
8283
severity: r#type.to_lowercase(),
@@ -89,28 +90,37 @@ impl Error {
8990
/// A shortcut constructor.
9091
///
9192
pub fn new_error<S>(
93+
error_code: Option<isize>,
9294
message: S,
9395
source_location: Option<SourceLocation>,
9496
sources: Option<&BTreeMap<String, StandardJsonInputSource>>,
9597
) -> Self
9698
where
9799
S: std::fmt::Display,
98100
{
99-
Self::new("Error", message, source_location, sources)
101+
Self::new("Error", error_code, message, source_location, sources)
100102
}
101103

102104
///
103105
/// A shortcut constructor.
104106
///
105107
pub fn new_warning<S>(
108+
error_code: Option<isize>,
106109
message: S,
107110
source_location: Option<SourceLocation>,
108111
sources: Option<&BTreeMap<String, StandardJsonInputSource>>,
109112
) -> Self
110113
where
111114
S: std::fmt::Display,
112115
{
113-
Self::new("Warning", message, source_location, sources)
116+
Self::new("Warning", error_code, message, source_location, sources)
117+
}
118+
}
119+
120+
impl From<(&str, &era_compiler_llvm_context::EVMWarning)> for Error {
121+
fn from((path, warning): (&str, &era_compiler_llvm_context::EVMWarning)) -> Self {
122+
let location = SourceLocation::new(path.to_owned());
123+
Self::new_warning(warning.code(), warning.to_string(), Some(location), None)
114124
}
115125
}
116126

solx-solc/src/standard_json/output/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl Output {
135135
///
136136
pub fn push_error(&mut self, path: Option<String>, error: anyhow::Error) {
137137
self.errors.push(JsonOutputError::new_error(
138+
None,
138139
error,
139140
path.map(JsonOutputErrorSourceLocation::new),
140141
None,

solx/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ num = "=0.4.3"
2929

3030
zkevm_opcode_defs = "=0.150.6"
3131

32+
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "az-error-code-runtime-code-size" }
3233
era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
33-
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "main" }
3434
solx-solc = { path = "../solx-solc" }
3535
solx-yul = { path = "../solx-yul" }
3636

solx/src/build_evm/contract/object.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub struct Object {
2929
pub is_assembled: bool,
3030
/// Binary object format.
3131
pub format: era_compiler_common::ObjectFormat,
32+
/// Compilation errors.
33+
pub errors: Vec<era_compiler_llvm_context::EVMWarning>,
3234
}
3335

3436
impl Object {
@@ -43,6 +45,7 @@ impl Object {
4345
code_segment: era_compiler_common::CodeSegment,
4446
dependencies: solx_yul::Dependencies,
4547
unlinked_libraries: BTreeSet<String>,
48+
errors: Vec<era_compiler_llvm_context::EVMWarning>,
4649
) -> Self {
4750
Self {
4851
identifier,
@@ -54,6 +57,7 @@ impl Object {
5457
unlinked_libraries,
5558
is_assembled: false,
5659
format: era_compiler_common::ObjectFormat::ELF,
60+
errors,
5761
}
5862
}
5963

solx/src/build_evm/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Build {
121121
Err(error) => {
122122
self.messages
123123
.push(solx_solc::StandardJsonOutputError::new_error(
124-
error, None, None,
124+
None, error, None, None,
125125
));
126126
continue;
127127
}
@@ -161,7 +161,7 @@ impl Build {
161161
Err(error) => {
162162
self.messages
163163
.push(solx_solc::StandardJsonOutputError::new_error(
164-
error, None, None,
164+
None, error, None, None,
165165
));
166166
continue;
167167
}
@@ -249,7 +249,23 @@ impl Build {
249249
let mut errors = Vec::with_capacity(self.results.len());
250250
for result in self.results.into_values() {
251251
let build = match result {
252-
Ok(build) => build,
252+
Ok(build) => {
253+
errors.extend(
254+
build
255+
.deploy_object
256+
.errors
257+
.iter()
258+
.map(|error| (build.name.full_path.as_str(), error).into()),
259+
);
260+
errors.extend(
261+
build
262+
.runtime_object
263+
.errors
264+
.iter()
265+
.map(|error| (build.name.full_path.as_str(), error).into()),
266+
);
267+
build
268+
}
253269
Err(error) => {
254270
errors.push(error);
255271
continue;

solx/src/process/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn run() -> anyhow::Result<()> {
3939
)
4040
.map(EVMOutput::new)
4141
.map_err(|error| {
42-
solx_solc::StandardJsonOutputError::new_error(error, Some(source_location), None)
42+
solx_solc::StandardJsonOutputError::new_error(None, error, Some(source_location), None)
4343
});
4444
serde_json::to_writer(std::io::stdout(), &result)
4545
.map_err(|error| anyhow::anyhow!("Stdout writing error: {error}"))?;
@@ -91,6 +91,7 @@ where
9191
String::from_utf8_lossy(result.stderr.as_slice()),
9292
);
9393
return Err(solx_solc::StandardJsonOutputError::new_error(
94+
None,
9495
message,
9596
Some(solx_solc::StandardJsonOutputErrorSourceLocation::new(
9697
path.to_owned(),

solx/src/project/contract/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ impl Contract {
132132
.map_err(|error| {
133133
anyhow::anyhow!("{runtime_code_segment} code LLVM IR generator: {error}")
134134
})?;
135-
let runtime_buffer = runtime_context.build()?;
136-
let runtime_build = EVMContractObject::new(
135+
let (runtime_buffer, runtime_code_errors) = runtime_context.build()?;
136+
let runtime_object = EVMContractObject::new(
137137
runtime_code_identifier,
138138
self.name.clone(),
139139
runtime_buffer.as_slice().to_owned(),
140140
true,
141141
runtime_code_segment,
142142
runtime_code_dependecies,
143143
runtime_code_libraries,
144+
runtime_code_errors,
144145
);
145146

146147
let immutables_map = runtime_buffer.get_immutables_evm();
@@ -170,21 +171,22 @@ impl Contract {
170171
.map_err(|error| {
171172
anyhow::anyhow!("{deploy_code_segment} code LLVM IR generator: {error}")
172173
})?;
173-
let deploy_buffer = deploy_context.build()?;
174-
let deploy_build = EVMContractObject::new(
174+
let (deploy_buffer, deploy_code_errors) = deploy_context.build()?;
175+
let deploy_object = EVMContractObject::new(
175176
deploy_code_identifier,
176177
self.name.clone(),
177178
deploy_buffer.as_slice().to_owned(),
178179
true,
179180
deploy_code_segment,
180181
deploy_code_dependecies,
181182
deploy_code_libraries,
183+
deploy_code_errors,
182184
);
183185

184186
Ok(EVMContractBuild::new(
185187
self.name,
186-
deploy_build,
187-
runtime_build,
188+
deploy_object,
189+
runtime_object,
188190
metadata_hash,
189191
metadata_string,
190192
))
@@ -232,15 +234,16 @@ impl Contract {
232234
.map_err(|error| {
233235
anyhow::anyhow!("{runtime_code_segment} code LLVM IR generator: {error}")
234236
})?;
235-
let runtime_buffer = runtime_context.build()?;
236-
let runtime_build = EVMContractObject::new(
237+
let (runtime_buffer, runtime_code_errors) = runtime_context.build()?;
238+
let runtime_object = EVMContractObject::new(
237239
runtime_code_identifier,
238240
self.name.clone(),
239241
runtime_buffer.as_slice().to_owned(),
240242
false,
241243
runtime_code_segment,
242244
runtime_code_dependecies,
243245
runtime_code_libraries,
246+
runtime_code_errors,
244247
);
245248

246249
let immutables_map = runtime_buffer.get_immutables_evm();
@@ -265,21 +268,22 @@ impl Contract {
265268
.map_err(|error| {
266269
anyhow::anyhow!("{deploy_code_segment} code LLVM IR generator: {error}")
267270
})?;
268-
let deploy_buffer = deploy_context.build()?;
269-
let deploy_build = EVMContractObject::new(
271+
let (deploy_buffer, deploy_code_errors) = deploy_context.build()?;
272+
let deploy_object = EVMContractObject::new(
270273
deploy_code_identifier,
271274
self.name.clone(),
272275
deploy_buffer.as_slice().to_owned(),
273276
false,
274277
deploy_code_segment,
275278
deploy_code_dependecies,
276279
deploy_code_libraries,
280+
deploy_code_errors,
277281
);
278282

279283
Ok(EVMContractBuild::new(
280284
self.name,
281-
deploy_build,
282-
runtime_build,
285+
deploy_object,
286+
runtime_object,
283287
metadata_hash,
284288
metadata_string,
285289
))

0 commit comments

Comments
 (0)