Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement runtime with dynamic dispatch #1051

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
38 changes: 0 additions & 38 deletions programs/benches/dict_insert.c

This file was deleted.

38 changes: 0 additions & 38 deletions programs/benches/dict_snapshot.c

This file was deleted.

37 changes: 0 additions & 37 deletions programs/benches/factorial_2M.c

This file was deleted.

37 changes: 0 additions & 37 deletions programs/benches/fib_2M.c

This file was deleted.

37 changes: 0 additions & 37 deletions programs/benches/linear_search.c

This file was deleted.

37 changes: 0 additions & 37 deletions programs/benches/logistic_map.c

This file was deleted.

17 changes: 0 additions & 17 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ lazy_static! {
(DICT_SQUASH_UNIQUE_KEY_COST.cost() - DICT_SQUASH_REPEATED_ACCESS_COST.cost()) as u64;
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn cairo_native__get_version(target: *mut u8, length: usize) -> usize {
let version = env!("CARGO_PKG_VERSION");
Expand All @@ -59,7 +58,6 @@ pub unsafe extern "C" fn cairo_native__get_version(target: *mut u8, length: usiz
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__debug__print(
target_fd: i32,
data: *const [u8; 32],
Expand Down Expand Up @@ -99,7 +97,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__debug__print(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__pedersen(
dst: &mut [u8; 32],
lhs: &[u8; 32],
Expand Down Expand Up @@ -133,7 +130,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__pedersen(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__hades_permutation(
op0: &mut [u8; 32],
op1: &mut [u8; 32],
Expand Down Expand Up @@ -263,7 +259,6 @@ impl Drop for FeltDict {
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__dict_new(
size: u64,
align: u64,
Expand Down Expand Up @@ -292,7 +287,6 @@ pub unsafe extern "C" fn cairo_native__dict_new(
// Note: Using `Option<extern "C" fn(*mut c_void)>` is ffi-safe thanks to Option's null
// pointer optimization. Check out
// https://doc.rust-lang.org/nomicon/ffi.html#the-nullable-pointer-optimization for more info.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__dict_drop(ptr: *const FeltDict) {
drop(Rc::from_raw(ptr));
}
Expand All @@ -303,7 +297,6 @@ pub unsafe extern "C" fn cairo_native__dict_drop(ptr: *const FeltDict) {
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__dict_dup(dict_ptr: *const FeltDict) -> *const FeltDict {
let old_dict = Rc::from_raw(dict_ptr);
let new_dict = Rc::clone(&old_dict);
Expand All @@ -322,7 +315,6 @@ pub unsafe extern "C" fn cairo_native__dict_dup(dict_ptr: *const FeltDict) -> *c
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__dict_get(
dict: *const FeltDict,
key: &[u8; 32],
Expand Down Expand Up @@ -372,7 +364,6 @@ pub unsafe extern "C" fn cairo_native__dict_get(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__dict_gas_refund(ptr: *const FeltDict) -> u64 {
let dict = Rc::from_raw(ptr);
let amount =
Expand All @@ -392,7 +383,6 @@ pub unsafe extern "C" fn cairo_native__dict_gas_refund(ptr: *const FeltDict) ->
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_point_from_x_nz(
point_ptr: &mut [[u8; 32]; 2],
) -> bool {
Expand Down Expand Up @@ -430,7 +420,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_point_from_x_nz(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_point_try_new_nz(
point_ptr: &mut [[u8; 32]; 2],
) -> bool {
Expand All @@ -456,7 +445,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_point_try_new_nz(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_init(state_ptr: &mut [[u8; 32]; 4]) {
// https://github.com/starkware-libs/cairo/blob/aaad921bba52e729dc24ece07fab2edf09ccfa15/crates/cairo-lang-runner/src/casm_run/mod.rs#L1802
let mut rng = rand::thread_rng();
Expand Down Expand Up @@ -489,7 +477,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_init(state_ptr: &mu
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_add(
state_ptr: &mut [[u8; 32]; 4],
point_ptr: &[[u8; 32]; 2],
Expand Down Expand Up @@ -528,7 +515,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_add(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_add_mul(
state_ptr: &mut [[u8; 32]; 4],
scalar_ptr: &[u8; 32],
Expand Down Expand Up @@ -572,7 +558,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_add_mul(
///
/// This function is intended to be called from MLIR, deals with pointers, and is therefore
/// definitely unsafe to use manually.
#[no_mangle]
pub unsafe extern "C" fn cairo_native__libfunc__ec__ec_state_try_finalize_nz(
point_ptr: &mut [[u8; 32]; 2],
state_ptr: &[[u8; 32]; 4],
Expand Down Expand Up @@ -615,15 +600,13 @@ thread_local! {

/// Store the gas builtin in the internal thread local. Returns the old pointer, to restore it after execution.
/// Not a runtime metadata method, it should be called before the program is executed.
#[no_mangle]
pub extern "C" fn cairo_native__set_costs_builtin(ptr: *const u64) -> *const u64 {
let old = BUILTIN_COSTS.get();
BUILTIN_COSTS.set(ptr);
old
}

/// Get the gas builtin from the internal thread local.
#[no_mangle]
pub extern "C" fn cairo_native__get_costs_builtin() -> *const u64 {
if BUILTIN_COSTS.get().is_null() {
// We shouldn't panic here, but we can print a big message.
Expand Down
Loading
Loading