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

Remove unstable features #310

Merged
merged 55 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
324b42f
start adding ec tests
edg-l Aug 8, 2023
85e4193
possible bug in ec
edg-l Aug 8, 2023
b6bd736
more tests, brainfuck example but gets stuck on infinite loop
edg-l Aug 8, 2023
10a6c4a
improv
edg-l Aug 8, 2023
166b39e
array proptest
edg-l Aug 8, 2023
eb71219
irrelevant
edg-l Aug 8, 2023
3f72fad
check
edg-l Aug 9, 2023
e972558
better test
edg-l Aug 9, 2023
898c528
bool tests
edg-l Aug 9, 2023
58636bd
remove
edg-l Aug 10, 2023
30f957b
add test cases from before refactor
edg-l Aug 10, 2023
351db2e
upd lockfile
edg-l Aug 10, 2023
aafedbb
fix a enum bug when comparing
edg-l Aug 11, 2023
962930b
better
edg-l Aug 11, 2023
27c5cf2
fix another bug
edg-l Aug 11, 2023
0f3f2ae
2 more tests enabled
edg-l Aug 11, 2023
9ed0011
fixes #291
edg-l Aug 11, 2023
ac10539
Merge branch 'main' into fix_array_slice
entropidelic Aug 23, 2023
10f59ca
Update corelib version and fix tests
entropidelic Aug 23, 2023
af49135
Fix tests after corelib changes
entropidelic Aug 24, 2023
7315201
Merge branch 'main' into fix_array_slice
entropidelic Aug 24, 2023
af582be
Test CI with older nightly version
entropidelic Aug 24, 2023
bb26fbc
Test CI with older nightly version
entropidelic Aug 24, 2023
8da034e
Rollback rust toolchain version in CI
entropidelic Aug 24, 2023
ed682e9
Test CI with older nightly version
entropidelic Aug 24, 2023
ab155b5
Test CI with older nightly version
entropidelic Aug 24, 2023
d7e94b6
Test CI with older nightly version
entropidelic Aug 24, 2023
0fc15f7
Rollback rust toolchain version in CI
entropidelic Aug 24, 2023
969eaf7
Remove some unstable features
entropidelic Aug 25, 2023
eb5a2d2
Merge remote-tracking branch 'origin/main' into remove-unstable-features
entropidelic Sep 5, 2023
630d5e2
Remove map_try_insert unstable feature
entropidelic Sep 5, 2023
2f59a14
Remove iterator_try_collect unstable feature
entropidelic Sep 5, 2023
9d38875
Remove box_into_inner unstable feature
entropidelic Sep 5, 2023
3b2e6bd
Remove hash_extract_if unstable feature
entropidelic Sep 5, 2023
0f245f3
Merge remote-tracking branch 'origin/main' into remove-unstable-features
entropidelic Sep 5, 2023
10ea76e
remove unused code
entropidelic Sep 5, 2023
3a221ae
Remove strict_provenance unstable feature
entropidelic Sep 6, 2023
e1530a6
Remove nonzero_ops unstable feature
entropidelic Sep 6, 2023
9be0f25
initial update to llvm 17
edg-l Sep 28, 2023
6618861
fix tests
edg-l Sep 28, 2023
ac9b098
update ci
edg-l Sep 28, 2023
24f012f
update ci
edg-l Sep 28, 2023
fcd45d5
fix bench
edg-l Sep 28, 2023
e380036
fix macos ci
edg-l Sep 29, 2023
50c7ba8
fixes
edg-l Sep 29, 2023
db49f28
Merge branch 'update_llvm17' into remove-unstable-features
edg-l Oct 2, 2023
af13a81
Merge remote-tracking branch 'origin/main' into remove-unstable-features
edg-l Oct 2, 2023
a5a1c1d
fix warns
edg-l Oct 2, 2023
9a9cab7
port to stable
edg-l Oct 2, 2023
51dd5fe
clippy
edg-l Oct 2, 2023
9ebbcb4
Merge branch 'main' into remove-unstable-features
edg-l Oct 2, 2023
d7914ca
change ci
edg-l Oct 3, 2023
9fce0a0
udeps needs nightly
edg-l Oct 3, 2023
27efdbb
upd udeps
edg-l Oct 3, 2023
e930dc9
improve comments
edg-l Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/easy_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![feature(iter_intersperse)]

use cairo_native::context::NativeContext;
use cairo_native::executor::NativeExecutor;
use itertools::Itertools;
use serde_json::json;
use std::{io::stdout, path::Path};

Expand Down Expand Up @@ -54,8 +53,7 @@ fn main() {
.param_types
.iter()
.map(ToString::to_string)
.intersperse_with(|| ", ".to_string())
.collect::<String>()
.join(", ")
)
}
e => panic!("{:?}", e),
Expand Down
4 changes: 1 addition & 3 deletions examples/erc20.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(strict_provenance)]

use cairo_felt::Felt252;
use cairo_native::context::NativeContext;
use cairo_native::executor::NativeExecutor;
Expand Down Expand Up @@ -294,7 +292,7 @@ fn main() {
.get_metadata::<SyscallHandlerMeta>()
.unwrap()
.as_ptr()
.addr();
.as_ptr() as *const () as usize;

edg-l marked this conversation as resolved.
Show resolved Hide resolved
let fn_id = find_function_id(
&sierra_program,
Expand Down
4 changes: 1 addition & 3 deletions examples/starknet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(strict_provenance)]

use cairo_felt::Felt252;
use cairo_lang_compiler::CompilerConfig;
use cairo_native::context::NativeContext;
Expand Down Expand Up @@ -296,7 +294,7 @@ fn main() {
.get_metadata::<SyscallHandlerMeta>()
.unwrap()
.as_ptr()
.addr();
.as_ptr() as *const () as usize;

edg-l marked this conversation as resolved.
Show resolved Hide resolved
let fn_id = find_function_id(&sierra_program, "hello_starknet::hello_starknet::main");
let required_init_gas = native_program.get_required_init_gas(fn_id);
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly"
channel = "stable"
components = ["rustfmt", "clippy"]
profile = "minimal"
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
edition = "2021"
group_imports = "One"
# nightly: group_imports = "One"
newline_style = "Unix"
use_field_init_shorthand = true
8 changes: 3 additions & 5 deletions src/bin/cairo-native-dump.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(arc_unwrap_or_clone)]

use cairo_lang_compiler::{
compile_prepared_db, db::RootDatabase, diagnostics::DiagnosticsReporter,
project::setup_project, CompilerConfig,
Expand All @@ -25,7 +23,6 @@ use std::{
ffi::OsStr,
fs,
path::{Path, PathBuf},
sync::Arc,
};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

Expand Down Expand Up @@ -89,14 +86,15 @@ fn load_program<'c>(
Some("cairo") => {
let mut db = RootDatabase::builder().detect_corelib().build()?;
let main_crate_ids = setup_project(&mut db, path)?;
let program = Arc::unwrap_or_clone(compile_prepared_db(
let program = (*compile_prepared_db(
&mut db,
main_crate_ids,
CompilerConfig {
replace_ids: true,
..Default::default()
},
)?);
)?)
.clone();

let debug_locations = if let Some(context) = context {
let debug_info = DebugInfo::extract(&db, &program).map_err(|_| {
Expand Down
13 changes: 4 additions & 9 deletions src/bin/cairo-native-run.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![feature(arc_unwrap_or_clone)]
#![feature(iter_intersperse)]
#![feature(nonzero_ops)]
#![feature(strict_provenance)]

use cairo_lang_compiler::{
compile_prepared_db, db::RootDatabase, project::setup_project, CompilerConfig,
};
Expand All @@ -19,6 +14,7 @@ use cairo_native::{
utils::register_runtime_symbols,
};
use clap::Parser;
use itertools::Itertools;
use melior::{
dialect::DialectRegistry,
ir::{Location, Module},
Expand All @@ -34,7 +30,6 @@ use std::{
fs::{self, File},
io::{self, Write},
path::{Path, PathBuf},
sync::Arc,
};
use tracing::info;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
Expand Down Expand Up @@ -163,8 +158,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.param_types
.iter()
.map(ToString::to_string)
.intersperse_with(|| ", ".to_string())
.collect::<String>()
.join(", ")
)
}
e => panic!("{:?}", e),
Expand Down Expand Up @@ -199,14 +193,15 @@ fn load_program(path: &Path) -> Result<Program, Box<dyn std::error::Error>> {
Some("cairo") => {
let mut db = RootDatabase::builder().detect_corelib().build()?;
let main_crate_ids = setup_project(&mut db, path)?;
Arc::unwrap_or_clone(compile_prepared_db(
(*compile_prepared_db(
&mut db,
main_crate_ids,
CompilerConfig {
replace_ids: true,
..Default::default()
},
)?)
.clone()
}
Some("sierra") => {
let program_src = fs::read_to_string(path)?;
Expand Down
10 changes: 9 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,15 @@ where
function.entry_point,
initial_state,
|statement_idx, state| {
let block = blocks.try_insert(statement_idx.0, Block::new(&[])).unwrap();
let block = {
if let std::collections::btree_map::Entry::Vacant(e) = blocks.entry(statement_idx.0)
{
e.insert(Block::new(&[]));
blocks.get_mut(&statement_idx.0).unwrap()
} else {
panic!("statement index already present in block");
}
};

Ok(match &statements[statement_idx.0] {
Statement::Invocation(invocation) => {
Expand Down
6 changes: 3 additions & 3 deletions src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl DebugInfo {
.map(|x| x.map(|location| (type_declaration.id.clone(), location)))
.transpose()
})
.try_collect()?;
.collect::<Result<HashMap<_, _>, DiagnosticAdded>>()?;

let libfunc_declarations = program
.libfunc_declarations
Expand All @@ -49,7 +49,7 @@ impl DebugInfo {
.map(|x| x.map(|location| (libfunc_declaration.id.clone(), location)))
.transpose()
})
.try_collect::<HashMap<_, _>>()?;
.collect::<Result<HashMap<_, _>, DiagnosticAdded>>()?;

let statements =
find_all_statements(db, |id| libfunc_declarations.contains_key(id), program)?;
Expand All @@ -58,7 +58,7 @@ impl DebugInfo {
.funcs
.iter()
.map(|function| Ok((function.id.clone(), find_func(db, function)?)))
.try_collect()?;
.collect::<Result<HashMap<_, _>, DiagnosticAdded>>()?;

Ok(Self {
type_declarations,
Expand Down
16 changes: 10 additions & 6 deletions src/debug_info/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ fn find_statement_locations(
db.concrete_function_with_body_postpanic_lowered(function_long_id.body(db)?.unwrap())?;

// Map Sierra to pre-Sierra statements.
let mut sierra_to_pre_sierra_mappings =
let sierra_to_pre_sierra_mappings =
map_sierra_to_pre_sierra_statements(function.entry_point, statements, &function_impl.body);

// Remove Sierra-specific invocations (they have no location since they are compiler-generated).
sierra_to_pre_sierra_mappings
.extract_if(|_, statement| match statement {
GenStatement::Invocation(invocation) => contains_libfunc(&invocation.libfunc_id),
GenStatement::Return(_) => false,
let sierra_to_pre_sierra_mappings: HashMap<_, _> = sierra_to_pre_sierra_mappings
.into_iter()
.filter(|(_, statement)| {
if let GenStatement::Invocation(invocation) = statement {
!contains_libfunc(&invocation.libfunc_id)
} else {
false
}
})
.for_each(|_| {});
.collect();

// Map Sierra to lowering statements by using the pre-Sierra mappings.
Ok(remap_sierra_statements_to_locations(
Expand Down
9 changes: 5 additions & 4 deletions src/error/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cairo_lang_sierra::{
ids::{ConcreteLibfuncId, ConcreteTypeId},
program_registry::ProgramRegistryError,
};
use std::{backtrace::Backtrace, fmt, ops::Deref};
use std::{fmt, ops::Deref};
use thiserror::Error;

pub type CompileError = Box<Error<CoreType, CoreLibfunc>>;
Expand All @@ -21,7 +21,8 @@ where
<TType as GenericType>::Concrete: TypeBuilder<TType, TLibfunc>,
<TLibfunc as GenericLibfunc>::Concrete: LibfuncBuilder<TType, TLibfunc>,
{
pub backtrace: Backtrace,
// TODO: enable once its stable in rust
// pub backtrace: Backtrace,
pub source: ErrorImpl<TType, TLibfunc>,
}

Expand Down Expand Up @@ -61,7 +62,7 @@ where
{
fn from(error: E) -> Self {
Self {
backtrace: Backtrace::capture(),
// backtrace: Backtrace::capture(),
source: error.into(),
}
}
Expand Down Expand Up @@ -91,7 +92,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Error")
.field("backtrace", &self.backtrace)
// .field("backtrace", &self.backtrace)
.field("source", &self.source)
.finish()
}
Expand Down
9 changes: 5 additions & 4 deletions src/error/jit_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cairo_lang_sierra::{
program_registry::ProgramRegistryError,
};
use serde::{Deserializer, Serializer};
use std::{alloc::LayoutError, backtrace::Backtrace, fmt, ops::Deref};
use std::{alloc::LayoutError, fmt, ops::Deref};
use thiserror::Error;

pub type RunnerError<'de, D, S> = Box<Error<'de, CoreType, CoreLibfunc, D, S>>;
Expand All @@ -23,7 +23,8 @@ where
D: Deserializer<'de>,
S: Serializer,
{
pub backtrace: Backtrace,
// TODO: enable once its stable in rust
// pub backtrace: Backtrace,
pub source: ErrorImpl<'de, TType, TLibfunc, D, S>,
}

Expand Down Expand Up @@ -69,7 +70,7 @@ where
{
fn from(error: E) -> Self {
Self {
backtrace: Backtrace::capture(),
// backtrace: Backtrace::capture(),
source: error.into(),
}
}
Expand Down Expand Up @@ -103,7 +104,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Error")
.field("backtrace", &self.backtrace)
// .field("backtrace", &self.backtrace)
.field("source", &self.source)
.finish()
}
Expand Down
10 changes: 7 additions & 3 deletions src/error/libfuncs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use cairo_lang_sierra::program_registry::ProgramRegistryError;
use std::{alloc::LayoutError, backtrace::Backtrace, fmt, num::TryFromIntError, ops::Deref};
use std::{alloc::LayoutError, fmt, num::TryFromIntError, ops::Deref};
use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
pub struct Error {
pub backtrace: Backtrace,
// TODO: enable once its stable in rust
// pub backtrace: Backtrace,
pub source: ErrorImpl,
}

Expand All @@ -30,7 +31,7 @@ where
{
fn from(error: E) -> Self {
Self {
backtrace: Backtrace::capture(),
// backtrace: Backtrace::capture(),
source: error.into(),
}
}
Expand All @@ -41,6 +42,8 @@ pub enum ErrorImpl {
#[error(transparent)]
LayoutError(#[from] LayoutError),
#[error(transparent)]
LayoutErrorPolyfill(#[from] crate::utils::LayoutError),
#[error(transparent)]
MlirError(#[from] melior::Error),
#[error(transparent)]
ProgramRegistryError(#[from] Box<ProgramRegistryError>),
Expand All @@ -54,6 +57,7 @@ impl From<super::CoreTypeBuilderError> for ErrorImpl {
super::types::ErrorImpl::LayoutError(e) => Self::LayoutError(e),
super::types::ErrorImpl::ProgramRegistryError(e) => Self::ProgramRegistryError(e),
super::types::ErrorImpl::TryFromIntError(e) => Self::TryFromIntError(e),
super::types::ErrorImpl::LayoutErrorPolyfill(e) => Self::LayoutErrorPolyfill(e),
}
}
}
9 changes: 6 additions & 3 deletions src/error/types.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use cairo_lang_sierra::program_registry::ProgramRegistryError;
use std::{alloc::LayoutError, backtrace::Backtrace, fmt, num::TryFromIntError, ops::Deref};
use std::{alloc::LayoutError, fmt, num::TryFromIntError, ops::Deref};
use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
pub struct Error {
pub backtrace: Backtrace,
// TODO: enable once its stable in rust
// pub backtrace: Backtrace,
pub source: ErrorImpl,
}

Expand All @@ -30,7 +31,7 @@ where
{
fn from(error: E) -> Self {
Self {
backtrace: Backtrace::capture(),
// backtrace: Backtrace::capture(),
source: error.into(),
}
}
Expand All @@ -41,6 +42,8 @@ pub enum ErrorImpl {
#[error(transparent)]
LayoutError(#[from] LayoutError),
#[error(transparent)]
LayoutErrorPolyfill(#[from] crate::utils::LayoutError),
#[error(transparent)]
ProgramRegistryError(#[from] Box<ProgramRegistryError>),
#[error(transparent)]
TryFromIntError(#[from] TryFromIntError),
Expand Down
3 changes: 2 additions & 1 deletion src/jit_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ where
TType,
TLibfunc,
>>::new(
ret_ptr.map_addr(|addr| unsafe { addr.unchecked_add(offset) }),
// ret_ptr.map_addr(|addr| unsafe { addr.unchecked_add(offset) }),
NonNull::new(((ret_ptr.as_ptr() as usize) + offset) as *mut _).unwrap(),
registry,
ty,
))
Expand Down
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@
//! - `registry: &ProgramRegistry<TType, TLibfunc>`: The registry extracted from the program.
//! - `metadata: &mut MetadataStorage`: Current compiler metadata.

#![feature(alloc_layout_extra)]
#![feature(arc_unwrap_or_clone)]
#![feature(box_into_inner)]
#![feature(error_generic_member_access)]
#![feature(hash_extract_if)]
#![feature(int_roundings)]
#![feature(iter_intersperse)]
#![feature(iterator_try_collect)]
#![feature(map_try_insert)]
#![feature(nonzero_ops)]
#![feature(strict_provenance)]
// #![warn(missing_docs)]
#![allow(clippy::missing_safety_doc)]

Expand Down
Loading
Loading