mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-05-01 06:27:55 +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.
|
||||
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.
|
||||
pub is_verify_each_enabled: bool,
|
||||
@@ -43,7 +41,6 @@ impl Settings {
|
||||
level_back_end,
|
||||
|
||||
is_fallback_to_size_enabled: false,
|
||||
is_system_request_memoization_disabled: false,
|
||||
|
||||
is_verify_each_enabled: false,
|
||||
is_debug_logging_enabled: false,
|
||||
@@ -65,7 +62,6 @@ impl Settings {
|
||||
level_back_end,
|
||||
|
||||
is_fallback_to_size_enabled: false,
|
||||
is_system_request_memoization_disabled: false,
|
||||
|
||||
is_verify_each_enabled,
|
||||
is_debug_logging_enabled,
|
||||
@@ -206,20 +202,10 @@ impl Settings {
|
||||
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.
|
||||
pub fn is_fallback_to_size_enabled(&self) -> bool {
|
||||
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 {
|
||||
|
||||
@@ -95,12 +95,6 @@ impl<'ctx> Function<'ctx> {
|
||||
&& 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.
|
||||
pub fn declaration(&self) -> Declaration<'ctx> {
|
||||
self.declaration
|
||||
|
||||
@@ -42,8 +42,7 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type =
|
||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
||||
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||
context.add_function(
|
||||
runtime::FUNCTION_DEPLOY_CODE,
|
||||
function_type,
|
||||
|
||||
@@ -188,7 +188,7 @@ where
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
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(
|
||||
runtime::FUNCTION_ENTRY,
|
||||
entry_function_type,
|
||||
|
||||
@@ -42,8 +42,7 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type =
|
||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
||||
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||
context.add_function(
|
||||
runtime::FUNCTION_RUNTIME_CODE,
|
||||
function_type,
|
||||
|
||||
@@ -413,47 +413,14 @@ where
|
||||
&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.
|
||||
pub fn add_function(
|
||||
&mut self,
|
||||
name: &str,
|
||||
r#type: inkwell::types::FunctionType<'ctx>,
|
||||
return_values_length: usize,
|
||||
mut linkage: Option<inkwell::module::Linkage>,
|
||||
linkage: Option<inkwell::module::Linkage>,
|
||||
) -> 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 entry_block = self.llvm.append_basic_block(value, "entry");
|
||||
@@ -492,10 +459,6 @@ where
|
||||
return_block,
|
||||
);
|
||||
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));
|
||||
self.functions.insert(name.to_string(), function.clone());
|
||||
|
||||
@@ -556,10 +519,6 @@ where
|
||||
manager,
|
||||
name,
|
||||
self.optimizer.settings().to_owned(),
|
||||
self.yul_data
|
||||
.as_ref()
|
||||
.map(|data| data.is_system_mode())
|
||||
.unwrap_or_default(),
|
||||
self.include_metadata_hash,
|
||||
self.debug_config.clone(),
|
||||
)
|
||||
@@ -1330,12 +1289,11 @@ where
|
||||
&self,
|
||||
argument_types: Vec<T>,
|
||||
return_values_size: usize,
|
||||
is_near_call_abi: bool,
|
||||
) -> inkwell::types::FunctionType<'ctx>
|
||||
where
|
||||
T: BasicType<'ctx>,
|
||||
{
|
||||
let mut argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
||||
let argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
||||
.as_slice()
|
||||
.iter()
|
||||
.map(T::as_basic_type_enum)
|
||||
@@ -1347,11 +1305,6 @@ where
|
||||
.void_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
|
||||
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
||||
.fn_type(argument_types.as_slice(), false),
|
||||
@@ -1544,12 +1497,4 @@ where
|
||||
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.
|
||||
#[derive(Debug, Default)]
|
||||
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.
|
||||
/// It is a temporary storage used until the finalization method is called.
|
||||
const_arrays: BTreeMap<u8, Vec<num::BigUint>>,
|
||||
}
|
||||
|
||||
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.
|
||||
pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> {
|
||||
if self.const_arrays.contains_key(&index) {
|
||||
|
||||
@@ -97,7 +97,6 @@ pub trait Dependency {
|
||||
dependency: Self,
|
||||
path: &str,
|
||||
optimizer_settings: OptimizerSettings,
|
||||
is_system_mode: bool,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: Option<DebugConfig>,
|
||||
) -> anyhow::Result<String>;
|
||||
@@ -118,7 +117,6 @@ impl Dependency for DummyDependency {
|
||||
_dependency: Self,
|
||||
_path: &str,
|
||||
_optimizer_settings: OptimizerSettings,
|
||||
_is_system_mode: bool,
|
||||
_include_metadata_hash: bool,
|
||||
_debug_config: Option<DebugConfig>,
|
||||
) -> anyhow::Result<String> {
|
||||
|
||||
Reference in New Issue
Block a user