mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 04:27:58 +00:00
solc-json-interface: do not unconditionally skip serialization of custom keys (#337)
The data structure can be used to build the JSON input for `resolc` too. In that case serializing of provided custom options should not be dismissed. Makes the memory settings struct more modular as a drive-by. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -16,6 +16,10 @@ Supported `polkadot-sdk` rev: `2503.0.1`
|
||||
|
||||
- Removed the license printer from the `resolc` binary.
|
||||
|
||||
### Fixed
|
||||
|
||||
- solc-json-interface: Serializing of any custom key in the JSON input is only skipped if not provided.
|
||||
|
||||
## v0.1.0
|
||||
|
||||
This is a development pre-release.
|
||||
|
||||
Generated
+1
-1
@@ -8705,7 +8705,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-solc-json-interface"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"rayon",
|
||||
|
||||
+14
-14
@@ -15,20 +15,20 @@ rust-version = "1.85.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
resolc = { path = "crates/resolc" }
|
||||
revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
|
||||
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
|
||||
revive-common = { version = "0.1.0", path = "crates/common" }
|
||||
revive-differential = { version = "0.1.0", path = "crates/differential" }
|
||||
revive-integration = { version = "0.1.0", path = "crates/integration" }
|
||||
revive-linker = { version = "0.1.0", path = "crates/linker" }
|
||||
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
|
||||
revive-llvm-context = { version = "0.1.0", path = "crates/llvm-context" }
|
||||
revive-runtime-api = { version = "0.1.0", path = "crates/runtime-api" }
|
||||
revive-runner = { version = "0.1.0", path = "crates/runner" }
|
||||
revive-solc-json-interface = { version = "0.1.0", path = "crates/solc-json-interface" }
|
||||
revive-stdlib = { version = "0.1.0", path = "crates/stdlib" }
|
||||
revive-build-utils = { version = "0.1.0", path = "crates/build-utils" }
|
||||
revive-yul = { version = "0.1.0", path = "crates/yul" }
|
||||
revive-benchmarks = { path = "crates/benchmarks" }
|
||||
revive-builtins = { path = "crates/builtins" }
|
||||
revive-common = { path = "crates/common" }
|
||||
revive-differential = { path = "crates/differential" }
|
||||
revive-integration = { path = "crates/integration" }
|
||||
revive-linker = { path = "crates/linker" }
|
||||
lld-sys = { path = "crates/lld-sys" }
|
||||
revive-llvm-context = { path = "crates/llvm-context" }
|
||||
revive-runtime-api = { path = "crates/runtime-api" }
|
||||
revive-runner = { path = "crates/runner" }
|
||||
revive-solc-json-interface = { path = "crates/solc-json-interface" }
|
||||
revive-stdlib = { path = "crates/stdlib" }
|
||||
revive-build-utils = { path = "crates/build-utils" }
|
||||
revive-yul = { path = "crates/yul" }
|
||||
|
||||
hex = "0.4.3"
|
||||
cc = "1.2"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The entry function.
|
||||
|
||||
use inkwell::types::BasicType;
|
||||
use revive_solc_json_interface::PolkaVMDefaultHeapMemorySize;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
@@ -38,9 +39,12 @@ impl Entry {
|
||||
context.xlen_type().const_zero(),
|
||||
);
|
||||
|
||||
let heap_memory_type = context
|
||||
.byte_type()
|
||||
.array_type(context.memory_config.heap_size);
|
||||
let heap_memory_type = context.byte_type().array_type(
|
||||
context
|
||||
.memory_config
|
||||
.heap_size
|
||||
.unwrap_or(PolkaVMDefaultHeapMemorySize),
|
||||
);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_HEAP_MEMORY,
|
||||
heap_memory_type,
|
||||
|
||||
@@ -25,6 +25,8 @@ use inkwell::debug_info::AsDIScope;
|
||||
use inkwell::debug_info::DIScope;
|
||||
use inkwell::types::BasicType;
|
||||
use inkwell::values::BasicValue;
|
||||
use revive_solc_json_interface::PolkaVMDefaultHeapMemorySize;
|
||||
use revive_solc_json_interface::PolkaVMDefaultStackMemorySize;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsPolkaVMMemory;
|
||||
|
||||
use crate::optimizer::settings::Settings as OptimizerSettings;
|
||||
@@ -233,7 +235,13 @@ where
|
||||
Self::set_data_layout(llvm, &module);
|
||||
Self::link_stdlib_module(llvm, &module);
|
||||
Self::link_polkavm_imports(llvm, &module);
|
||||
Self::set_polkavm_stack_size(llvm, &module, memory_config.stack_size);
|
||||
Self::set_polkavm_stack_size(
|
||||
llvm,
|
||||
&module,
|
||||
memory_config
|
||||
.stack_size
|
||||
.unwrap_or(PolkaVMDefaultStackMemorySize),
|
||||
);
|
||||
Self::set_module_flags(llvm, &module);
|
||||
|
||||
let intrinsics = Intrinsics::new(llvm, &module);
|
||||
@@ -1443,7 +1451,11 @@ where
|
||||
}
|
||||
|
||||
pub fn heap_size(&self) -> inkwell::values::IntValue<'ctx> {
|
||||
self.xlen_type()
|
||||
.const_int(self.memory_config.heap_size as u64, false)
|
||||
self.xlen_type().const_int(
|
||||
self.memory_config
|
||||
.heap_size
|
||||
.unwrap_or(PolkaVMDefaultHeapMemorySize) as u64,
|
||||
false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ pub fn standard_json<T: Compiler>(
|
||||
revive_llvm_context::OptimizerSettings::try_from(&solc_input.settings.optimizer)?;
|
||||
|
||||
let polkavm_settings = solc_input.settings.polkavm.unwrap_or_default();
|
||||
debug_config.emit_debug_info = polkavm_settings.debug_information;
|
||||
debug_config.emit_debug_info = polkavm_settings.debug_information.unwrap_or_default();
|
||||
|
||||
let include_metadata_hash = match solc_input.settings.metadata {
|
||||
Some(ref metadata) => metadata.bytecode_hash != Some(MetadataHash::None),
|
||||
@@ -265,7 +265,9 @@ pub fn standard_json<T: Compiler>(
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
polkavm_settings.memory_config,
|
||||
polkavm_settings
|
||||
.memory_config
|
||||
.unwrap_or_else(SolcStandardJsonInputSettingsPolkaVMMemory::default),
|
||||
)?;
|
||||
build.write_to_standard_json(&mut solc_output, &solc_version)?;
|
||||
}
|
||||
|
||||
@@ -142,14 +142,10 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
None => true,
|
||||
};
|
||||
|
||||
let mut memory_config =
|
||||
revive_solc_json_interface::SolcStandardJsonInputSettingsPolkaVMMemory::default();
|
||||
if let Some(heap_size) = arguments.heap_size {
|
||||
memory_config.heap_size = heap_size
|
||||
}
|
||||
if let Some(stack_size) = arguments.stack_size {
|
||||
memory_config.stack_size = stack_size
|
||||
}
|
||||
let memory_config = revive_solc_json_interface::SolcStandardJsonInputSettingsPolkaVMMemory::new(
|
||||
arguments.heap_size,
|
||||
arguments.stack_size,
|
||||
);
|
||||
|
||||
let build = if arguments.yul {
|
||||
resolc::yul(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revive-solc-json-interface"
|
||||
version.workspace = true
|
||||
version = "0.2.0"
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
@@ -20,4 +20,4 @@ anyhow = { workspace = true }
|
||||
rayon = { workspace = true, optional = true }
|
||||
semver = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -9,6 +9,8 @@ pub use self::standard_json::input::settings::metadata::Metadata as SolcStandard
|
||||
pub use self::standard_json::input::settings::metadata_hash::MetadataHash as SolcStandardJsonInputSettingsMetadataHash;
|
||||
pub use self::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
pub use self::standard_json::input::settings::polkavm::memory::MemoryConfig as SolcStandardJsonInputSettingsPolkaVMMemory;
|
||||
pub use self::standard_json::input::settings::polkavm::memory::DEFAULT_HEAP_SIZE as PolkaVMDefaultHeapMemorySize;
|
||||
pub use self::standard_json::input::settings::polkavm::memory::DEFAULT_STACK_SIZE as PolkaVMDefaultStackMemorySize;
|
||||
pub use self::standard_json::input::settings::polkavm::PolkaVM as SolcStandardJsonInputSettingsPolkaVM;
|
||||
pub use self::standard_json::input::settings::selection::file::flag::Flag as SolcStandardJsonInputSettingsSelectionFileFlag;
|
||||
pub use self::standard_json::input::settings::selection::file::File as SolcStandardJsonInputSettingsSelectionFile;
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct Settings {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<Metadata>,
|
||||
/// The resolc custom PolkaVM settings.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub polkavm: Option<PolkaVM>,
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ impl Settings {
|
||||
|
||||
/// Sets the necessary defaults.
|
||||
pub fn normalize(&mut self, version: &semver::Version) {
|
||||
self.polkavm = None;
|
||||
self.optimizer.normalize(version);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ pub struct Optimizer {
|
||||
/// Whether the optimizer is enabled.
|
||||
pub enabled: bool,
|
||||
/// The optimization mode string.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mode: Option<char>,
|
||||
/// The `solc` optimizer details.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub details: Option<Details>,
|
||||
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub fallback_to_optimizing_for_size: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ impl Optimizer {
|
||||
|
||||
/// Sets the necessary defaults.
|
||||
pub fn normalize(&mut self, version: &semver::Version) {
|
||||
self.mode = None;
|
||||
self.fallback_to_optimizing_for_size = None;
|
||||
self.details = if version >= &semver::Version::new(0, 5, 5) {
|
||||
Some(Details::disabled(version))
|
||||
} else {
|
||||
|
||||
@@ -2,20 +2,35 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_HEAP_SIZE: u32 = 64 * 1024;
|
||||
pub const DEFAULT_STACK_SIZE: u32 = 32 * 1024;
|
||||
|
||||
/// The PolkaVM memory configuration.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub struct MemoryConfig {
|
||||
/// The emulated EVM linear heap memory size in bytes.
|
||||
pub heap_size: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub heap_size: Option<u32>,
|
||||
/// The PVM stack size in bytes.
|
||||
pub stack_size: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stack_size: Option<u32>,
|
||||
}
|
||||
|
||||
impl MemoryConfig {
|
||||
/// A shorthand constructor.
|
||||
pub fn new(heap_size: Option<u32>, stack_size: Option<u32>) -> Self {
|
||||
Self {
|
||||
heap_size,
|
||||
stack_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MemoryConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
heap_size: 64 * 1024,
|
||||
stack_size: 32 * 1024,
|
||||
heap_size: Some(DEFAULT_HEAP_SIZE),
|
||||
stack_size: Some(DEFAULT_STACK_SIZE),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,18 @@ pub mod memory;
|
||||
#[derive(Clone, Copy, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct PolkaVM {
|
||||
/// The PolkaVM target machine memory configuration settings.
|
||||
pub memory_config: MemoryConfig,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub memory_config: Option<MemoryConfig>,
|
||||
/// Instruct LLVM to emit debug information.
|
||||
pub debug_information: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub debug_information: Option<bool>,
|
||||
}
|
||||
|
||||
impl PolkaVM {
|
||||
pub fn new(memory_config: Option<MemoryConfig>, debug_information: bool) -> Self {
|
||||
Self {
|
||||
memory_config: memory_config.unwrap_or_default(),
|
||||
debug_information,
|
||||
memory_config,
|
||||
debug_information: Some(debug_information),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user