mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 06:51:07 +00:00
std json: do not request EVM bytecode (#410)
These compiler outputs are irrelevant for the `resolc` compilation pipeline. It can also break the compilation pipeline. For example, solc may reject the code without via-ir or fail during the EVM codegen phase with stack too deep errors - which is not relevant to us. --------- Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -8,6 +8,7 @@ Supported `polkadot-sdk` rev: `2509.0.0`
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size).
|
- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size).
|
||||||
|
- Standard JSON mode: Don't forward EVM bytecode related output selections to solc.
|
||||||
|
|
||||||
## v0.5.0
|
## v0.5.0
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ pub fn standard_json<T: Compiler>(
|
|||||||
.debug_information
|
.debug_information
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
solc_input.extend_selection(SolcStandardJsonInputSettingsSelection::new_required());
|
solc_input.extend_selection(SolcStandardJsonInputSettingsSelection::new_required());
|
||||||
|
solc_input.retain_output_selection();
|
||||||
let mut solc_output = solc.standard_json(
|
let mut solc_output = solc.standard_json(
|
||||||
&mut solc_input,
|
&mut solc_input,
|
||||||
messages,
|
messages,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
//! The tests for running resolc with standard JSON option.
|
//! The tests for running resolc with standard JSON option.
|
||||||
|
|
||||||
|
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||||
|
|
||||||
use crate::tests::cli::utils::{
|
use crate::tests::cli::utils::{
|
||||||
assert_command_success, assert_equal_exit_codes, execute_resolc_with_stdin_input,
|
assert_command_success, assert_equal_exit_codes, execute_resolc_with_stdin_input,
|
||||||
execute_solc_with_stdin_input, STANDARD_JSON_CONTRACTS_PATH,
|
execute_solc_with_stdin_input, STANDARD_JSON_CONTRACTS_PATH, STANDARD_JSON_NO_EVM_CODEGEN_PATH,
|
||||||
};
|
};
|
||||||
|
|
||||||
const JSON_OPTION: &str = "--standard-json";
|
const JSON_OPTION: &str = "--standard-json";
|
||||||
@@ -21,3 +23,12 @@ fn runs_with_valid_input_file() {
|
|||||||
let solc_result = execute_solc_with_stdin_input(arguments, STANDARD_JSON_CONTRACTS_PATH);
|
let solc_result = execute_solc_with_stdin_input(arguments, STANDARD_JSON_CONTRACTS_PATH);
|
||||||
assert_equal_exit_codes(&solc_result, &resolc_result);
|
assert_equal_exit_codes(&solc_result, &resolc_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_evm_codegen_requested() {
|
||||||
|
let result = execute_resolc_with_stdin_input(&[JSON_OPTION], STANDARD_JSON_NO_EVM_CODEGEN_PATH);
|
||||||
|
assert_command_success(&result, "EVM codegen std json input fixture should build");
|
||||||
|
|
||||||
|
let output: SolcStandardJsonOutput = serde_json::from_str(&result.stdout).unwrap();
|
||||||
|
assert!(!output.errors.iter().any(|msg| msg.severity == "error"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,9 +18,15 @@ pub const YUL_CONTRACT_PATH: &str = "src/tests/data/yul/contract.yul";
|
|||||||
/// The memeset YUL contract test fixture path.
|
/// The memeset YUL contract test fixture path.
|
||||||
pub const YUL_MEMSET_CONTRACT_PATH: &str = "src/tests/data/yul/memset.yul";
|
pub const YUL_MEMSET_CONTRACT_PATH: &str = "src/tests/data/yul/memset.yul";
|
||||||
/// The standard JSON contracts test fixture path.
|
/// The standard JSON contracts test fixture path.
|
||||||
///
|
|
||||||
pub const STANDARD_JSON_CONTRACTS_PATH: &str =
|
pub const STANDARD_JSON_CONTRACTS_PATH: &str =
|
||||||
"src/tests/data/standard_json/solidity_contracts.json";
|
"src/tests/data/standard_json/solidity_contracts.json";
|
||||||
|
/// The standard JSON no EVM codegen test fixture path.
|
||||||
|
///
|
||||||
|
/// This contains EVM bytecode selection flags with provided code
|
||||||
|
/// that doesn't compile without `viaIr`. Because we remove those
|
||||||
|
/// selection flags, it should compile fine regardless.
|
||||||
|
pub const STANDARD_JSON_NO_EVM_CODEGEN_PATH: &str =
|
||||||
|
"src/tests/data/standard_json/no_evm_codegen.json";
|
||||||
|
|
||||||
/// The simple Solidity contract containing i256 divisions and remains that should be compiled
|
/// The simple Solidity contract containing i256 divisions and remains that should be compiled
|
||||||
/// correctly
|
/// correctly
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"language": "Solidity",
|
||||||
|
"sources": {
|
||||||
|
"/Users/omarabdulla/parity/revive-dt/resolc-compiler-tests/fixtures/solidity/translated_semantic_tests/array/copying/array_of_struct_memory_to_storage/array_of_struct_memory_to_storage.sol": {
|
||||||
|
"content": "contract C {\n struct S {\n uint128 a;\n uint64 b;\n uint128 c;\n }\n uint128[137] unused;\n S[] s;\n function f() public returns (uint128, uint64, uint128) {\n S[] memory m = new S[](3);\n m[2].a = 10;\n m[1].b = 11;\n m[0].c = 12;\n s = m;\n return (s[2].a, s[1].b, s[0].c);\n }\n}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"libraries": {},
|
||||||
|
"outputSelection": {
|
||||||
|
"*": {
|
||||||
|
"": [
|
||||||
|
"ast"
|
||||||
|
],
|
||||||
|
"*": [
|
||||||
|
"metadata",
|
||||||
|
"evm.methodIdentifiers",
|
||||||
|
"irOptimized",
|
||||||
|
"evm.bytecode",
|
||||||
|
"evm.deployedBytecode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"viaIR": true,
|
||||||
|
"optimizer": {
|
||||||
|
"enabled": false,
|
||||||
|
"details": {
|
||||||
|
"peephole": false,
|
||||||
|
"jumpdestRemover": false,
|
||||||
|
"orderLiterals": false,
|
||||||
|
"deduplicate": false,
|
||||||
|
"cse": false,
|
||||||
|
"constantOptimizer": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -210,4 +210,9 @@ impl Input {
|
|||||||
let _ = source.try_resolve();
|
let _ = source.try_resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes unneded output selections.
|
||||||
|
pub fn retain_output_selection(&mut self) {
|
||||||
|
self.settings.retain_output_selection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,4 +112,9 @@ impl Settings {
|
|||||||
pub fn selection_to_prune(&self) -> Selection {
|
pub fn selection_to_prune(&self) -> Selection {
|
||||||
self.output_selection.selection_to_prune()
|
self.output_selection.selection_to_prune()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes unneeded selections.
|
||||||
|
pub fn retain_output_selection(&mut self) {
|
||||||
|
self.output_selection.retain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,3 +47,16 @@ pub enum Flag {
|
|||||||
#[serde(rename = "ir")]
|
#[serde(rename = "ir")]
|
||||||
Ir,
|
Ir,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Flag {
|
||||||
|
/// Whether this selection flag is required for the revive codegen.
|
||||||
|
///
|
||||||
|
/// Specifically, EVM bytecode and related flags should never be requested.
|
||||||
|
/// It will be replaced by PVM code anyways.
|
||||||
|
pub fn is_required_for_codegen(&self) -> bool {
|
||||||
|
!matches!(
|
||||||
|
self,
|
||||||
|
Flag::EVMBC | Flag::EVMDBC | Flag::EVMLA | Flag::EVM | Flag::Assembly
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ impl PerFileSelection {
|
|||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.files.is_empty()
|
self.files.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes unneeded selections.
|
||||||
|
pub fn retain(&mut self) {
|
||||||
|
for file in self.files.values_mut() {
|
||||||
|
file.per_contract.retain(Flag::is_required_for_codegen);
|
||||||
|
file.per_file.retain(Flag::is_required_for_codegen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `solc --standard-json` output selection.
|
/// The `solc --standard-json` output selection.
|
||||||
@@ -125,4 +133,11 @@ impl Selection {
|
|||||||
.contains(path, flag)
|
.contains(path, flag)
|
||||||
.unwrap_or(self.all.contains(flag))
|
.unwrap_or(self.all.contains(flag))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes unneeded selections.
|
||||||
|
pub fn retain(&mut self) {
|
||||||
|
self.all.per_file.retain(Flag::is_required_for_codegen);
|
||||||
|
self.all.per_contract.retain(Flag::is_required_for_codegen);
|
||||||
|
self.files.retain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user