mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-18 00:01:04 +00:00
remove system mode and request memoization
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -21,8 +21,6 @@ pub struct Settings {
|
|||||||
|
|
||||||
/// Fallback to optimizing for size if the bytecode is too large.
|
/// Fallback to optimizing for size if the bytecode is too large.
|
||||||
pub is_fallback_to_size_enabled: bool,
|
pub is_fallback_to_size_enabled: bool,
|
||||||
/// Whether the system request memoization is disabled.
|
|
||||||
pub is_system_request_memoization_disabled: bool,
|
|
||||||
|
|
||||||
/// Whether the LLVM `verify each` option is enabled.
|
/// Whether the LLVM `verify each` option is enabled.
|
||||||
pub is_verify_each_enabled: bool,
|
pub is_verify_each_enabled: bool,
|
||||||
@@ -43,7 +41,6 @@ impl Settings {
|
|||||||
level_back_end,
|
level_back_end,
|
||||||
|
|
||||||
is_fallback_to_size_enabled: false,
|
is_fallback_to_size_enabled: false,
|
||||||
is_system_request_memoization_disabled: false,
|
|
||||||
|
|
||||||
is_verify_each_enabled: false,
|
is_verify_each_enabled: false,
|
||||||
is_debug_logging_enabled: false,
|
is_debug_logging_enabled: false,
|
||||||
@@ -65,7 +62,6 @@ impl Settings {
|
|||||||
level_back_end,
|
level_back_end,
|
||||||
|
|
||||||
is_fallback_to_size_enabled: false,
|
is_fallback_to_size_enabled: false,
|
||||||
is_system_request_memoization_disabled: false,
|
|
||||||
|
|
||||||
is_verify_each_enabled,
|
is_verify_each_enabled,
|
||||||
is_debug_logging_enabled,
|
is_debug_logging_enabled,
|
||||||
@@ -206,20 +202,10 @@ impl Settings {
|
|||||||
self.is_fallback_to_size_enabled = true;
|
self.is_fallback_to_size_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disables the system request memoization.
|
|
||||||
pub fn disable_system_request_memoization(&mut self) {
|
|
||||||
self.is_system_request_memoization_disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the fallback to optimizing for size is enabled.
|
/// Whether the fallback to optimizing for size is enabled.
|
||||||
pub fn is_fallback_to_size_enabled(&self) -> bool {
|
pub fn is_fallback_to_size_enabled(&self) -> bool {
|
||||||
self.is_fallback_to_size_enabled
|
self.is_fallback_to_size_enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the system request memoization is disabled.
|
|
||||||
pub fn is_system_request_memoization_disabled(&self) -> bool {
|
|
||||||
self.is_system_request_memoization_disabled
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Settings {
|
impl PartialEq for Settings {
|
||||||
|
|||||||
@@ -95,12 +95,6 @@ impl<'ctx> Function<'ctx> {
|
|||||||
&& name != self::runtime::FUNCTION_LOAD_IMMUTABLE_DATA)
|
&& name != self::runtime::FUNCTION_LOAD_IMMUTABLE_DATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether the function is related to the near call ABI.
|
|
||||||
pub fn is_near_call_abi(name: &str) -> bool {
|
|
||||||
name.starts_with(Self::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
|| name == Self::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the LLVM function declaration.
|
/// Returns the LLVM function declaration.
|
||||||
pub fn declaration(&self) -> Declaration<'ctx> {
|
pub fn declaration(&self) -> Declaration<'ctx> {
|
||||||
self.declaration
|
self.declaration
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ where
|
|||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type =
|
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_DEPLOY_CODE,
|
runtime::FUNCTION_DEPLOY_CODE,
|
||||||
function_type,
|
function_type,
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ where
|
|||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let entry_arguments = vec![context.bool_type().as_basic_type_enum()];
|
let entry_arguments = vec![context.bool_type().as_basic_type_enum()];
|
||||||
let entry_function_type = context.function_type(entry_arguments, 0, false);
|
let entry_function_type = context.function_type(entry_arguments, 0);
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_ENTRY,
|
runtime::FUNCTION_ENTRY,
|
||||||
entry_function_type,
|
entry_function_type,
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ where
|
|||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type =
|
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_RUNTIME_CODE,
|
runtime::FUNCTION_RUNTIME_CODE,
|
||||||
function_type,
|
function_type,
|
||||||
|
|||||||
@@ -413,47 +413,14 @@ where
|
|||||||
&self.llvm_runtime
|
&self.llvm_runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Declare a function already existing in the module.
|
|
||||||
pub fn declare_extern_function(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
|
||||||
let function = self.module().get_function(name).ok_or_else(|| {
|
|
||||||
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let basic_block = self.llvm.append_basic_block(function, name);
|
|
||||||
let declaration = FunctionDeclaration::new(
|
|
||||||
self.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false),
|
|
||||||
function,
|
|
||||||
);
|
|
||||||
let function = Function::new(
|
|
||||||
name.to_owned(),
|
|
||||||
declaration,
|
|
||||||
FunctionReturn::None,
|
|
||||||
basic_block,
|
|
||||||
basic_block,
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
|
||||||
|
|
||||||
let function = Rc::new(RefCell::new(function));
|
|
||||||
self.functions.insert(name.to_string(), function.clone());
|
|
||||||
|
|
||||||
Ok(function)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Appends a function to the current module.
|
/// Appends a function to the current module.
|
||||||
pub fn add_function(
|
pub fn add_function(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &str,
|
name: &str,
|
||||||
r#type: inkwell::types::FunctionType<'ctx>,
|
r#type: inkwell::types::FunctionType<'ctx>,
|
||||||
return_values_length: usize,
|
return_values_length: usize,
|
||||||
mut linkage: Option<inkwell::module::Linkage>,
|
linkage: Option<inkwell::module::Linkage>,
|
||||||
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
||||||
if Function::is_near_call_abi(name) && self.is_system_mode() {
|
|
||||||
linkage = Some(inkwell::module::Linkage::External);
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = self.module().add_function(name, r#type, linkage);
|
let value = self.module().add_function(name, r#type, linkage);
|
||||||
|
|
||||||
let entry_block = self.llvm.append_basic_block(value, "entry");
|
let entry_block = self.llvm.append_basic_block(value, "entry");
|
||||||
@@ -492,10 +459,6 @@ where
|
|||||||
return_block,
|
return_block,
|
||||||
);
|
);
|
||||||
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
||||||
if Function::is_near_call_abi(function.name()) && self.is_system_mode() {
|
|
||||||
Function::set_exception_handler_attributes(self.llvm, function.declaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
let function = Rc::new(RefCell::new(function));
|
let function = Rc::new(RefCell::new(function));
|
||||||
self.functions.insert(name.to_string(), function.clone());
|
self.functions.insert(name.to_string(), function.clone());
|
||||||
|
|
||||||
@@ -556,10 +519,6 @@ where
|
|||||||
manager,
|
manager,
|
||||||
name,
|
name,
|
||||||
self.optimizer.settings().to_owned(),
|
self.optimizer.settings().to_owned(),
|
||||||
self.yul_data
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| data.is_system_mode())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
self.include_metadata_hash,
|
self.include_metadata_hash,
|
||||||
self.debug_config.clone(),
|
self.debug_config.clone(),
|
||||||
)
|
)
|
||||||
@@ -1330,12 +1289,11 @@ where
|
|||||||
&self,
|
&self,
|
||||||
argument_types: Vec<T>,
|
argument_types: Vec<T>,
|
||||||
return_values_size: usize,
|
return_values_size: usize,
|
||||||
is_near_call_abi: bool,
|
|
||||||
) -> inkwell::types::FunctionType<'ctx>
|
) -> inkwell::types::FunctionType<'ctx>
|
||||||
where
|
where
|
||||||
T: BasicType<'ctx>,
|
T: BasicType<'ctx>,
|
||||||
{
|
{
|
||||||
let mut argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
let argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
||||||
.as_slice()
|
.as_slice()
|
||||||
.iter()
|
.iter()
|
||||||
.map(T::as_basic_type_enum)
|
.map(T::as_basic_type_enum)
|
||||||
@@ -1347,11 +1305,6 @@ where
|
|||||||
.void_type()
|
.void_type()
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
||||||
_size if is_near_call_abi && self.is_system_mode() => {
|
|
||||||
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
|
||||||
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
|
||||||
return_type.fn_type(argument_types.as_slice(), false)
|
|
||||||
}
|
|
||||||
size => self
|
size => self
|
||||||
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
@@ -1544,12 +1497,4 @@ where
|
|||||||
anyhow::bail!("The immutable size data is not available");
|
anyhow::bail!("The immutable size data is not available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the system mode is enabled.
|
|
||||||
pub fn is_system_mode(&self) -> bool {
|
|
||||||
self.yul_data
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| data.is_system_mode())
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,28 +8,12 @@ use num::Zero;
|
|||||||
/// Describes some data that is only relevant to Yul.
|
/// Describes some data that is only relevant to Yul.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct YulData {
|
pub struct YulData {
|
||||||
/// The system mode flag.
|
|
||||||
/// The call simulations only work if this mode is enabled.
|
|
||||||
is_system_mode: bool,
|
|
||||||
/// The list of constant arrays in the code section.
|
/// The list of constant arrays in the code section.
|
||||||
/// It is a temporary storage used until the finalization method is called.
|
/// It is a temporary storage used until the finalization method is called.
|
||||||
const_arrays: BTreeMap<u8, Vec<num::BigUint>>,
|
const_arrays: BTreeMap<u8, Vec<num::BigUint>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl YulData {
|
impl YulData {
|
||||||
/// A shortcut constructor.
|
|
||||||
pub fn new(is_system_mode: bool) -> Self {
|
|
||||||
Self {
|
|
||||||
is_system_mode,
|
|
||||||
const_arrays: BTreeMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the system mode is enabled.
|
|
||||||
pub fn is_system_mode(&self) -> bool {
|
|
||||||
self.is_system_mode
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Declares a temporary constant array representation.
|
/// Declares a temporary constant array representation.
|
||||||
pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> {
|
pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> {
|
||||||
if self.const_arrays.contains_key(&index) {
|
if self.const_arrays.contains_key(&index) {
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ pub trait Dependency {
|
|||||||
dependency: Self,
|
dependency: Self,
|
||||||
path: &str,
|
path: &str,
|
||||||
optimizer_settings: OptimizerSettings,
|
optimizer_settings: OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<DebugConfig>,
|
debug_config: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String>;
|
) -> anyhow::Result<String>;
|
||||||
@@ -118,7 +117,6 @@ impl Dependency for DummyDependency {
|
|||||||
_dependency: Self,
|
_dependency: Self,
|
||||||
_path: &str,
|
_path: &str,
|
||||||
_optimizer_settings: OptimizerSettings,
|
_optimizer_settings: OptimizerSettings,
|
||||||
_is_system_mode: bool,
|
|
||||||
_include_metadata_hash: bool,
|
_include_metadata_hash: bool,
|
||||||
_debug_config: Option<DebugConfig>,
|
_debug_config: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
|
|||||||
@@ -1139,7 +1139,6 @@ where
|
|||||||
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
|
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
|
||||||
.as_basic_type_enum()],
|
.as_basic_type_enum()],
|
||||||
output_size,
|
output_size,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
(r#type, output_size)
|
(r#type, output_size)
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1155,6 @@ where
|
|||||||
input_size
|
input_size
|
||||||
],
|
],
|
||||||
output_size,
|
output_size,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
(r#type, output_size)
|
(r#type, output_size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ pub fn yul(
|
|||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
solc: &mut SolcCompiler,
|
solc: &mut SolcCompiler,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
@@ -64,27 +63,17 @@ pub fn yul(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let solc_validator = if is_system_mode {
|
if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION {
|
||||||
None
|
anyhow::bail!(
|
||||||
} else {
|
|
||||||
if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
||||||
SolcCompiler::LAST_SUPPORTED_VERSION,
|
SolcCompiler::LAST_SUPPORTED_VERSION,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(&*solc)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
let solc_validator = Some(&*solc);
|
||||||
let project = Project::try_from_yul_path(path, solc_validator)?;
|
let project = Project::try_from_yul_path(path, solc_validator)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -93,7 +82,6 @@ pub fn yul(
|
|||||||
pub fn llvm_ir(
|
pub fn llvm_ir(
|
||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
@@ -108,12 +96,7 @@ pub fn llvm_ir(
|
|||||||
|
|
||||||
let project = Project::try_from_llvm_ir_path(path)?;
|
let project = Project::try_from_llvm_ir_path(path)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -128,7 +111,6 @@ pub fn standard_output(
|
|||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
@@ -152,7 +134,6 @@ pub fn standard_output(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
optimizer_settings.is_fallback_to_size_enabled(),
|
optimizer_settings.is_fallback_to_size_enabled(),
|
||||||
optimizer_settings.is_system_request_memoization_disabled(),
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
solc_pipeline == SolcPipeline::Yul,
|
solc_pipeline == SolcPipeline::Yul,
|
||||||
@@ -198,12 +179,7 @@ pub fn standard_output(
|
|||||||
debug_config.as_ref(),
|
debug_config.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -214,7 +190,6 @@ pub fn standard_json(
|
|||||||
solc: &mut SolcCompiler,
|
solc: &mut SolcCompiler,
|
||||||
detect_missing_libraries: bool,
|
detect_missing_libraries: bool,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
@@ -275,12 +250,7 @@ pub fn standard_json(
|
|||||||
&resolc_version,
|
&resolc_version,
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?;
|
build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?;
|
||||||
}
|
}
|
||||||
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
||||||
@@ -298,7 +268,6 @@ pub fn combined_json(
|
|||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
@@ -319,7 +288,6 @@ pub fn combined_json(
|
|||||||
solc_optimizer_enabled,
|
solc_optimizer_enabled,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
force_evmla,
|
force_evmla,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
base_path,
|
base_path,
|
||||||
include_paths,
|
include_paths,
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ pub struct Input {
|
|||||||
pub contract: Contract,
|
pub contract: Contract,
|
||||||
/// The project representation.
|
/// The project representation.
|
||||||
pub project: Project,
|
pub project: Project,
|
||||||
/// The system mode flag.
|
|
||||||
pub is_system_mode: bool,
|
|
||||||
/// Whether to append the metadata hash.
|
/// Whether to append the metadata hash.
|
||||||
pub include_metadata_hash: bool,
|
pub include_metadata_hash: bool,
|
||||||
/// The optimizer settings.
|
/// The optimizer settings.
|
||||||
@@ -29,7 +27,6 @@ impl Input {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
project: Project,
|
project: Project,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
@@ -37,7 +34,6 @@ impl Input {
|
|||||||
Self {
|
Self {
|
||||||
contract,
|
contract,
|
||||||
project,
|
project,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
debug_config,
|
debug_config,
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ pub fn run(input_file: Option<&mut std::fs::File>) -> anyhow::Result<()> {
|
|||||||
let result = input.contract.compile(
|
let result = input.contract.compile(
|
||||||
input.project,
|
input.project,
|
||||||
input.optimizer_settings,
|
input.optimizer_settings,
|
||||||
input.is_system_mode,
|
|
||||||
input.include_metadata_hash,
|
input.include_metadata_hash,
|
||||||
input.debug_config,
|
input.debug_config,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ impl Contract {
|
|||||||
mut self,
|
mut self,
|
||||||
project: Project,
|
project: Project,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<ContractBuild> {
|
) -> anyhow::Result<ContractBuild> {
|
||||||
@@ -127,8 +126,7 @@ impl Contract {
|
|||||||
context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default());
|
context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default());
|
||||||
match self.ir {
|
match self.ir {
|
||||||
IR::Yul(_) => {
|
IR::Yul(_) => {
|
||||||
let yul_data = revive_llvm_context::PolkaVMContextYulData::new(is_system_mode);
|
context.set_yul_data(Default::default());
|
||||||
context.set_yul_data(yul_data);
|
|
||||||
}
|
}
|
||||||
IR::EVMLA(_) => {
|
IR::EVMLA(_) => {
|
||||||
let evmla_data = revive_llvm_context::PolkaVMContextEVMLAData::new(version.default);
|
let evmla_data = revive_llvm_context::PolkaVMContextEVMLAData::new(version.default);
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ impl Project {
|
|||||||
pub fn compile(
|
pub fn compile(
|
||||||
self,
|
self,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
@@ -74,7 +73,6 @@ impl Project {
|
|||||||
let process_output = crate::process::call(ProcessInput::new(
|
let process_output = crate::process::call(ProcessInput::new(
|
||||||
contract,
|
contract,
|
||||||
project.clone(),
|
project.clone(),
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
optimizer_settings.clone(),
|
optimizer_settings.clone(),
|
||||||
debug_config.clone(),
|
debug_config.clone(),
|
||||||
@@ -239,7 +237,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
|||||||
project: Self,
|
project: Self,
|
||||||
identifier: &str,
|
identifier: &str,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
@@ -259,7 +256,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
|||||||
.compile(
|
.compile(
|
||||||
project,
|
project,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ pub struct Arguments {
|
|||||||
#[structopt(long = "fallback-Oz")]
|
#[structopt(long = "fallback-Oz")]
|
||||||
pub fallback_to_optimizing_for_size: bool,
|
pub fallback_to_optimizing_for_size: bool,
|
||||||
|
|
||||||
/// Disable the system request memoization.
|
|
||||||
#[structopt(long = "disable-system-request-memoization")]
|
|
||||||
pub disable_system_request_memoization: bool,
|
|
||||||
|
|
||||||
/// Disable the `solc` optimizer.
|
/// Disable the `solc` optimizer.
|
||||||
/// Use it if your project uses the `MSIZE` instruction, or in other cases.
|
/// Use it if your project uses the `MSIZE` instruction, or in other cases.
|
||||||
/// Beware that it will prevent libraries from being inlined.
|
/// Beware that it will prevent libraries from being inlined.
|
||||||
@@ -123,13 +119,6 @@ pub struct Arguments {
|
|||||||
#[structopt(long = "force-evmla")]
|
#[structopt(long = "force-evmla")]
|
||||||
pub force_evmla: bool,
|
pub force_evmla: bool,
|
||||||
|
|
||||||
/// Enable system contract compilation mode.
|
|
||||||
/// In this mode PolkaVM extensions are enabled. For example, calls to addresses `0xFFFF` and below
|
|
||||||
/// are substituted by special PolkaVM instructions.
|
|
||||||
/// In the Yul mode, the `verbatim_*` instruction family is available.
|
|
||||||
#[structopt(long = "system-mode")]
|
|
||||||
pub is_system_mode: bool,
|
|
||||||
|
|
||||||
/// Set metadata hash mode.
|
/// Set metadata hash mode.
|
||||||
/// The only supported value is `none` that disables appending the metadata hash.
|
/// The only supported value is `none` that disables appending the metadata hash.
|
||||||
/// Is enabled by default.
|
/// Is enabled by default.
|
||||||
@@ -267,12 +256,6 @@ impl Arguments {
|
|||||||
if self.solc.is_some() {
|
if self.solc.is_some() {
|
||||||
anyhow::bail!("`solc` is not used in LLVM IR and PolkaVM assembly modes.");
|
anyhow::bail!("`solc` is not used in LLVM IR and PolkaVM assembly modes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_system_mode {
|
|
||||||
anyhow::bail!(
|
|
||||||
"System contract mode is not supported in LLVM IR and PolkaVM assembly modes."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.combined_json.is_some() {
|
if self.combined_json.is_some() {
|
||||||
@@ -319,11 +302,6 @@ impl Arguments {
|
|||||||
"Falling back to -Oz must specified in standard JSON input settings."
|
"Falling back to -Oz must specified in standard JSON input settings."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.disable_system_request_memoization {
|
|
||||||
anyhow::bail!(
|
|
||||||
"Disabling the system request memoization must specified in standard JSON input settings."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if self.metadata_hash.is_some() {
|
if self.metadata_hash.is_some() {
|
||||||
anyhow::bail!("Metadata hash mode must specified in standard JSON input settings.");
|
anyhow::bail!("Metadata hash mode must specified in standard JSON input settings.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,9 +101,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
if arguments.fallback_to_optimizing_for_size {
|
if arguments.fallback_to_optimizing_for_size {
|
||||||
optimizer_settings.enable_fallback_to_size();
|
optimizer_settings.enable_fallback_to_size();
|
||||||
}
|
}
|
||||||
if arguments.disable_system_request_memoization {
|
|
||||||
optimizer_settings.disable_system_request_memoization();
|
|
||||||
}
|
|
||||||
optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each;
|
optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each;
|
||||||
optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging;
|
optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging;
|
||||||
|
|
||||||
@@ -121,7 +118,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
input_files.as_slice(),
|
input_files.as_slice(),
|
||||||
&mut solc,
|
&mut solc,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
@@ -129,7 +125,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
revive_solidity::llvm_ir(
|
revive_solidity::llvm_ir(
|
||||||
input_files.as_slice(),
|
input_files.as_slice(),
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
@@ -138,7 +133,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
&mut solc,
|
&mut solc,
|
||||||
arguments.detect_missing_libraries,
|
arguments.detect_missing_libraries,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
arguments.allow_paths,
|
arguments.allow_paths,
|
||||||
@@ -155,7 +149,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
!arguments.disable_solc_optimizer,
|
!arguments.disable_solc_optimizer,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
@@ -176,7 +169,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
!arguments.disable_solc_optimizer,
|
!arguments.disable_solc_optimizer,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ pub struct Optimizer {
|
|||||||
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
pub fallback_to_optimizing_for_size: Option<bool>,
|
pub fallback_to_optimizing_for_size: Option<bool>,
|
||||||
/// Whether to disable the system request memoization.
|
|
||||||
#[serde(skip_serializing)]
|
|
||||||
pub disable_system_request_memoization: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Optimizer {
|
impl Optimizer {
|
||||||
@@ -34,14 +31,12 @@ impl Optimizer {
|
|||||||
mode: Option<char>,
|
mode: Option<char>,
|
||||||
version: &semver::Version,
|
version: &semver::Version,
|
||||||
fallback_to_optimizing_for_size: bool,
|
fallback_to_optimizing_for_size: bool,
|
||||||
disable_system_request_memoization: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled,
|
enabled,
|
||||||
mode,
|
mode,
|
||||||
details: Some(Details::disabled(version)),
|
details: Some(Details::disabled(version)),
|
||||||
fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size),
|
fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size),
|
||||||
disable_system_request_memoization: Some(disable_system_request_memoization),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +61,6 @@ impl TryFrom<&Optimizer> for revive_llvm_context::OptimizerSettings {
|
|||||||
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
||||||
result.enable_fallback_to_size();
|
result.enable_fallback_to_size();
|
||||||
}
|
}
|
||||||
if value.disable_system_request_memoization.unwrap_or_default() {
|
|
||||||
result.disable_system_request_memoization();
|
|
||||||
}
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ pub fn build_solidity_with_options(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
@@ -106,7 +105,7 @@ pub fn build_solidity_with_options(
|
|||||||
|
|
||||||
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
||||||
|
|
||||||
let build: crate::Build = project.compile(optimizer_settings, false, false, None)?;
|
let build: crate::Build = project.compile(optimizer_settings, false, None)?;
|
||||||
build.write_to_standard_json(
|
build.write_to_standard_json(
|
||||||
&mut output,
|
&mut output,
|
||||||
&solc_version,
|
&solc_version,
|
||||||
@@ -144,7 +143,6 @@ pub fn build_solidity_with_options_evm(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
@@ -193,13 +191,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
|||||||
libraries.clone(),
|
libraries.clone(),
|
||||||
None,
|
None,
|
||||||
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
||||||
SolcStandardJsonInputSettingsOptimizer::new(
|
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||||
true,
|
|
||||||
None,
|
|
||||||
&solc_version.default,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
None,
|
None,
|
||||||
@@ -229,7 +221,7 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let project =
|
let project =
|
||||||
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
||||||
let _build = project.compile(optimizer_settings, false, false, None)?;
|
let _build = project.compile(optimizer_settings, false, None)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -259,13 +251,7 @@ pub fn check_solidity_warning(
|
|||||||
libraries,
|
libraries,
|
||||||
None,
|
None,
|
||||||
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
||||||
SolcStandardJsonInputSettingsOptimizer::new(
|
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||||
true,
|
|
||||||
None,
|
|
||||||
&solc_version.default,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
suppressed_warnings,
|
suppressed_warnings,
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ impl FunctionCall {
|
|||||||
Name::UserDefined(name)
|
Name::UserDefined(name)
|
||||||
if name.starts_with(
|
if name.starts_with(
|
||||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
||||||
) && context.is_system_mode() =>
|
) =>
|
||||||
{
|
{
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,12 +234,7 @@ where
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let function_type = context.function_type(
|
let function_type = context.function_type(argument_types, self.result.len());
|
||||||
argument_types,
|
|
||||||
self.result.len(),
|
|
||||||
self.identifier
|
|
||||||
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX),
|
|
||||||
);
|
|
||||||
|
|
||||||
let function = context.add_function(
|
let function = context.add_function(
|
||||||
self.identifier.as_str(),
|
self.identifier.as_str(),
|
||||||
@@ -323,7 +318,6 @@ where
|
|||||||
context.current_function().borrow().r#return(),
|
context.current_function().borrow().r#return(),
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { .. }
|
revive_llvm_context::PolkaVMFunctionReturn::Compound { .. }
|
||||||
)
|
)
|
||||||
&& context.is_system_mode()
|
|
||||||
{
|
{
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user