Skip to content

Commit

Permalink
Fix spelling issues. (#339)
Browse files Browse the repository at this point in the history
* Fix spelling issues.

* Update `Nullable` type docs.

* Update docs I forgot to update in a previous PR.

---------

Co-authored-by: Esteve Soler Arderiu <[email protected]>
  • Loading branch information
azteca1998 and azteca1998 authored Nov 2, 2023
1 parent 4012a10 commit 9c796f4
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 49 deletions.
4 changes: 2 additions & 2 deletions DEVELOPER-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ You can find this functionality under `src/values.rs` and `src/values/{typename}

Serialization is done using `Serde`, and each type provides a `deserialize` and `serialize` function. The inner workings of such functions can be a bit complex due to how the JIT runner works. You need to work with pointers and unsafe rust.

In `values.rs` we should also declare whether the type is complex under `is_complex` in the `ValueBuilder` trait implmentation.
In `values.rs` we should also declare whether the type is complex under `is_complex` in the `ValueBuilder` trait implementation.

> Complex types are always passed by pointer (both as params and return values) and require a stack allocation. Examples of complex values include structs and enums, but not felts since LLVM considers them integers.
Expand Down Expand Up @@ -215,7 +215,7 @@ Some commonly used dialects in this project:

#### The arith dialect

It contains arithmetic operations, such as `addi`, `subi` for addition and substraction.
It contains arithmetic operations, such as `addi`, `subi` for addition and subtraction.

#### The cf dialect

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld;polly" \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_TARGETS_TO_BUILD="Native;NVPTX" \
-DLLVM_TARGETS_TO_BUILD="Native" \
-DCMAKE_INSTALL_PREFIX=/opt/llvm-17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLLVM_PARALLEL_LINK_JOBS=4 \
Expand Down Expand Up @@ -342,7 +342,7 @@ make deps
make build
```

Or with your native CPU Architecture for even more perfomance (usually):
Or with your native CPU Architecture for even more performance (usually):
```bash
make build-native
```
Expand Down Expand Up @@ -462,7 +462,7 @@ fn main() {
// Compile the cairo program to sierra.
let sierra_program = cairo_native::utils::cairo_to_sierra(program_path);

// Instantiate a Cairo Native MLIR contex. This data structure is responsible for the
// Instantiate a Cairo Native MLIR context. This data structure is responsible for the
// MLIR initialization and compilation of sierra programs into a MLIR module.
let native_context = NativeContext::new();

Expand All @@ -486,7 +486,7 @@ fn main() {
native_executor
.execute(&fn_id, params, returns, required_init_gas).unwrap();

println!("Cairo program was compiled and executed succesfully.");
println!("Cairo program was compiled and executed successfully.");
}
```

Expand All @@ -510,8 +510,8 @@ make bench
```

The `bench` target will run the `./scripts/bench-hyperfine.sh` script.
This script runs hyperfine comands to compare the execution time of programs in the `./programs/benches/` folder.
Each program is compiled and executed via the execution engine with the `sierrajit` command and via the cairo-vm with the `cairo-run` command provided by the `cairo` codebase.
This script runs hyperfine commands to compare the execution time of programs in the `./programs/benches/` folder.
Each program is compiled and executed via the execution engine with the `cairo-native-run` command and via the cairo-vm with the `cairo-run` command provided by the `cairo` codebase.
The `cairo-run` command should be available in the `$PATH` and ideally compiled with `cargo build --release`.
If you want the benchmarks to run using a specific build, or the `cairo-run` commands conflicts with something (e.g. the cairo-svg package binaries in macos) then the command to run `cairo-run` with a full path can be specified with the `$CAIRO_RUN` environment variable.

Expand All @@ -520,7 +520,7 @@ If you want the benchmarks to run using a specific build, or the `cairo-run` com
# to mlir with llvm dialect
sierra2mlir program.sierra -o program.mlir

# trranslate all dialects to the llvm dialect
# translate all dialects to the llvm dialect
"$MLIR_SYS_170_PREFIX/bin/mlir-opt" \
--canonicalize \
--convert-scf-to-cf \
Expand Down
12 changes: 6 additions & 6 deletions examples/easy_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ fn main() {
// Compile the cairo program to sierra.
let sierra_program = cairo_native::utils::cairo_to_sierra(program_path);

// Instantiate a Cairo Native MLIR contex. This data structure is responsible for the
// MLIR initialization and compilation of sierra programs into a MLIR module.
// Instantiate a Cairo Native MLIR context. This data structure is responsible for the MLIR
// initialization and compilation of sierra programs into a MLIR module.
let native_context = NativeContext::new();

// Compile the sierra program into a MLIR module.
let native_program = native_context.compile(&sierra_program).unwrap();

// Get necessary information for the execution of the program from a given entrypoint:
// * entrypoint function id
// * required initial gas
// - Entrypoint function id
// - Required initial gas
let name = cairo_native::utils::felt252_short_str("user");
let entry_point = "hello::hello::greet";
let params = json!([name]);
Expand All @@ -38,7 +38,7 @@ fn main() {
// Instantiate MLIR executor.
let native_executor = NativeExecutor::new(native_program);

// Execute the program
// Execute the program.
native_executor
.execute(fn_id, params, returns, required_init_gas)
.unwrap_or_else(|e| match &e.source {
Expand All @@ -59,5 +59,5 @@ fn main() {
e => panic!("{:?}", e),
});

println!("Cairo program was compiled and executed succesfully.");
println!("Cairo program was compiled and executed successfully.");
}
2 changes: 1 addition & 1 deletion examples/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,6 @@ fn main() {
}
*/

println!("Cairo program was compiled and executed succesfully.");
println!("Cairo program was compiled and executed successfully.");
println!("{result:#?}");
}
2 changes: 1 addition & 1 deletion examples/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,6 @@ fn main() {
.expect("failed to serialize starknet execution result");

println!();
println!("Cairo program was compiled and executed succesfully.");
println!("Cairo program was compiled and executed successfully.");
println!("{result:#?}");
}
17 changes: 7 additions & 10 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};

use cairo_lang_sierra::program::Program;

use crate::{context::NativeContext, executor::NativeExecutor};
use cairo_lang_sierra::program::Program;
use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};

/// A Cache for programs with the same context.
pub struct ProgramCache<'a, K: PartialEq + Eq + Hash> {
context: &'a NativeContext,
// Since we already hold a reference to the Context, it doesn't make sense to use thread-safe refcounting.
// Using a Arc<RwLock<T>> here is useless because NativeExecutor is not Send and Sync.
// Since we already hold a reference to the Context, it doesn't make sense to use thread-safe
// reference counting. Using a Arc<RwLock<T>> here is useless because NativeExecutor is neither
// Send nor Sync.
cache: HashMap<K, Rc<RefCell<NativeExecutor<'a>>>>,
}

Expand Down Expand Up @@ -45,11 +44,9 @@ impl<'a, K: Clone + PartialEq + Eq + Hash> ProgramCache<'a, K> {

#[cfg(test)]
mod test {
use std::time::Instant;

use crate::utils::test::load_cairo;

use super::*;
use crate::utils::test::load_cairo;
use std::time::Instant;

#[test]
fn test_cache() {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
/// The function accepts a `Function` argument, which provides the function's entry point, signature
/// and name. Check out [compile](self::compile) for a description of the other arguments.
///
/// The [module docs](self) contain more information about the compiliation process.
/// The [module docs](self) contain more information about the compilation process.
fn compile_func<TType, TLibfunc>(
context: &Context,
module: &Module,
Expand Down
2 changes: 1 addition & 1 deletion src/error/jit_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
}
}

pub fn make_insuficient_gas_error<'de, TType, TLibfunc, D, S>(
pub fn make_insufficient_gas_error<'de, TType, TLibfunc, D, S>(
needed: u128,
have: u128,
) -> Error<'de, TType, TLibfunc, D, S>
Expand Down
12 changes: 6 additions & 6 deletions src/jit_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
error::{
jit_engine::{
make_deserializer_error, make_insuficient_gas_error, make_serializer_error,
make_deserializer_error, make_insufficient_gas_error, make_serializer_error,
make_type_builder_error,
},
JitRunnerError,
Expand All @@ -27,8 +27,8 @@ use tracing::debug;
/// Execute a function on an engine loaded with a Sierra program.
///
/// The JIT execution of a Sierra program requires an [`ExecutionEngine`] already configured with
/// the compiled module. This has been designed this way because it allows engine reusal, as opposed
/// to building a different engine every time a function is called and therefore losing all
/// the compiled module. This has been designed this way because it allows reusing the engine, as
/// opposed to building a different engine every time a function is called and therefore losing all
/// potential optimizations that are already present.
///
/// The registry is needed to convert the params and return values into and from the JIT ABI. Check
Expand Down Expand Up @@ -69,15 +69,15 @@ where
})
.map_err(make_deserializer_error)?;

// If program has a required initial gas, check if a gas builting exists
// and check if the passed gas was enough, if so, deduct the required gas before execution.
// If program has a required initial gas, check if a gas builtin exists and check if the passed
// gas was enough, if so, deduct the required gas before execution.
if let Some(required_initial_gas) = required_initial_gas {
for (id, param) in entry_point.signature.param_types.iter().zip(params.iter()) {
if id.debug_name.as_deref() == Some("GasBuiltin") {
let gas_builtin = unsafe { *param.cast::<u128>().as_ptr() };

if gas_builtin < required_initial_gas {
return Err(make_insuficient_gas_error(
return Err(make_insufficient_gas_error(
required_initial_gas,
gas_builtin,
));
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//!
//! ## Usage
//!
//! The API containts two structs, `NativeContext` and `NativeExecutor`.
//! The API contains two structs, `NativeContext` and `NativeExecutor`.
//! The main purpose of `NativeContext` is MLIR initialization, compilation and lowering to LLVM.
//! `NativeExecutor` in the other hand is responsible of executing MLIR compiled sierra programs
//! from an entrypoint.
Expand Down Expand Up @@ -37,7 +37,7 @@
//! // Compile the cairo program to sierra.
//! let sierra_program = cairo_native::utils::cairo_to_sierra(program_path);
//!
//! // Instantiate a Cairo Native MLIR contex. This data structure is responsible for the
//! // Instantiate a Cairo Native MLIR context. This data structure is responsible for the
//! // MLIR initialization and compilation of sierra programs into a MLIR module.
//! let native_context = NativeContext::new();
//!
Expand Down
3 changes: 2 additions & 1 deletion src/libfuncs/array.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! # Array libfuncs
// TODO: A future possible improvement would be to put the array behind a double pointer and a reference counter, to avoid unnecesary clones.
// TODO: A future possible improvement would be to put the array behind a double pointer and a
// reference counter, to avoid unnecessary clones.

use super::{LibfuncBuilder, LibfuncHelper};
use crate::{
Expand Down
4 changes: 2 additions & 2 deletions src/libfuncs/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn build_bool_binary<'ctx, 'this, TType, TLibfunc>(
helper: &LibfuncHelper<'ctx, 'this>,
_metadata: &mut MetadataStorage,
info: &SignatureOnlyConcreteLibfunc,
binop: BoolOp,
bin_op: BoolOp,
) -> Result<()>
where
TType: GenericType,
Expand Down Expand Up @@ -133,7 +133,7 @@ where
));
let rhs_tag = op.result(0)?.into();

let op = match binop {
let op = match bin_op {
BoolOp::And => entry.append_operation(arith::andi(lhs_tag, rhs_tag, location)),
BoolOp::Xor => entry.append_operation(arith::xori(lhs_tag, rhs_tag, location)),
BoolOp::Or => entry.append_operation(arith::ori(lhs_tag, rhs_tag, location)),
Expand Down
5 changes: 2 additions & 3 deletions src/libfuncs/snapshot_take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ where
<TType as GenericType>::Concrete: TypeBuilder<TType, TLibfunc, Error = CoreTypeBuilderError>,
<TLibfunc as GenericLibfunc>::Concrete: LibfuncBuilder<TType, TLibfunc, Error = Error>,
{
// TODO: Should this act like dup like it does now? or are there special requirements. So far it seems to work.
// TODO: Handle non-trivially-copyable types (ex. arrays) and maybe update docs.

// Handle non-trivially-copyable types (ex. arrays) by invoking their override or just copy the
// original value otherwise.
let original_value = entry.argument(0)?.into();
let cloned_value = match metadata
.get_mut::<SnapshotClonesMeta<TType, TLibfunc>>()
Expand Down
2 changes: 1 addition & 1 deletion src/types/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ where
))
}

/// Extract layout for the default enum representation, itsdiscriminant and all its payloads.
/// Extract layout for the default enum representation, its discriminant and all its payloads.
pub fn get_layout_for_variants<TType, TLibfunc>(
registry: &ProgramRegistry<TType, TLibfunc>,
variants: &[ConcreteTypeId],
Expand Down
4 changes: 2 additions & 2 deletions src/types/nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! Nullable is represented as a pointer, usually the null value will point to a alloca in the stack.
//!
//! This is so we only check if the ptr is nullptr for nulability, instead of using a enum in this case.
//! TODO
//! A nullable is functionally equivalent to Rust's `Option<Box<T>>`. Since it's always paired with
//! `Box<T>` we can reuse its pointer, just leaving it null when there's no value.
use super::{TypeBuilder, WithSelf};
use crate::{
Expand Down
5 changes: 2 additions & 3 deletions tests/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ lazy_static! {
};
}

// because comparing a felt to 1 to create boolean, which uses felt252_is_zero and felt sub,add, has a bug we use u8 on other tests
// until this is fixed.
// the bug may be in felt substraction
// Since comparing a felt to 1 to create boolean (uses felt252_is_zero and felt sub,add) has a bug,
// we'll be using use u8 on other tests until this is fixed. The bug may be in felt subtraction.
#[ignore = "TODO: comparing a felt252 == 1 will lead to wrong results"]
#[test]
fn felt252_to_bool_bug() {
Expand Down

0 comments on commit 9c796f4

Please sign in to comment.