Skip to content

Commit

Permalink
feat: cairo-lang-utils supports no_std (starkware-libs#4759)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro authored Jan 9, 2024
1 parent 14edeca commit c609a8b
Show file tree
Hide file tree
Showing 71 changed files with 621 additions and 353 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:
types: [checks_requested]

jobs:
ensure-no_std:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-07-05
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- run: |
cd ensure-no_std && cargo build
parallel-tests:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -41,6 +53,7 @@ jobs:
- test -p cairo-lang-test-runner
- test -p cairo-lang-test-utils
- test -p cairo-lang-utils
- test -p cairo-lang-utils --no-default-features --features=serde
- test -p tests
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ node_modules
.DS_Store
perf.data*
flamegraph.svg

ensure-no_std/Cargo.lock
ensure-no_std/target/

13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = [
"crates/bin/starknet-sierra-upgrade-validate",
"tests",
]
exclude = ["ensure-no_std"]

[workspace.package]
version = "2.4.1"
Expand Down Expand Up @@ -77,21 +78,22 @@ diffy = "0.3.0"
env_logger = "0.10.0"
genco = "0.17.8"
good_lp = { version = "1.7.0", features = ["minilp"], default-features = false }
hashbrown = "0.14.3"
id-arena = "2.2.1"
ignore = "0.4.20"
indent = "0.1.1"
indexmap = { version = "2.1.0", features = ["serde"] }
indexmap = { version = "2.1.0", default-features = false }
indoc = "2.0.4"
itertools = "0.11.0"
itertools = { version = "0.11.0", default-features = false }
keccak = "0.1.4"
lalrpop-util = { version = "0.20.0", features = ["lexer"] }
log = "0.4"
lsp = { version = "0.94", package = "lsp-types" }
num-bigint = { version = "0.4", features = ["serde"] }
num-bigint = { version = "0.4", default-features = false }
num-integer = "0.1"
num-traits = "0.2"
num-traits = { version = "0.2", default-features = false }
once_cell = "1.18.0"
parity-scale-codec = "3.6.5"
parity-scale-codec = { version = "3.6.5", default-features = false }
parity-scale-codec-derive = "3.6.5"
path-clean = "1.0.1"
pretty_assertions = "1.4.0"
Expand All @@ -102,7 +104,7 @@ rstest = "0.18.2"
salsa = "0.16.1"
scarb-metadata = "1"
schemars = { version = "0.8.15", features = ["preserve_order"] }
serde = { version = "1.0.192", features = ["derive"] }
serde = { version = "1.0.192", default-features = false, features = ["derive"] }
serde_json = "1.0"
sha3 = "0.10.8"
smol_str = { version = "0.2.0", features = ["serde"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/bin/generate-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license-file.workspace = true
[dependencies]
log.workspace = true

cairo-lang-utils = { path = "../../cairo-lang-utils", features = [
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "2.4.1", features = [
"env_logger",
] }
cairo-lang-syntax-codegen = { path = "../../cairo-lang-syntax-codegen" }
cairo-lang-syntax-codegen = { path = "../../cairo-lang-syntax-codegen", version = "2.4.1" }
4 changes: 2 additions & 2 deletions crates/bin/starknet-sierra-compile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ description = "Compiler executable for the Sierra intemediate representation wit
[dependencies]
anyhow.workspace = true
clap.workspace = true
serde.workspace = true
serde = { workspace = true, default-features = true }
serde_json.workspace = true

cairo-lang-sierra = { path = "../../cairo-lang-sierra", version = "2.4.1" }
cairo-lang-starknet = { path = "../../cairo-lang-starknet", version = "2.4.1" }
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "2.4.1" }
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "2.4.1", features = ["serde"] }
4 changes: 2 additions & 2 deletions crates/bin/starknet-sierra-upgrade-validate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ description = "Compiler executable for validating a Sierra upgrade is valid"
[dependencies]
anyhow.workspace = true
clap.workspace = true
serde.workspace = true
serde = { workspace = true, default-features = true }
serde_json.workspace = true
rayon.workspace = true
indicatif = "0.17.7"

cairo-lang-starknet = { path = "../../cairo-lang-starknet", version = "2.4.1" }
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "2.4.1" }
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "2.4.1", features = ["serde"] }
10 changes: 5 additions & 5 deletions crates/cairo-lang-casm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ license-file.workspace = true
description = "Cairo assembly encoding."

[dependencies]
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1", features = ["serde", "schemars"] }
indoc.workspace = true
num-bigint.workspace = true
num-traits.workspace = true
num-bigint = { workspace = true, default-features = true }
num-traits = { workspace = true, default-features = true }
parity-scale-codec.workspace = true
parity-scale-codec-derive.workspace = true
schemars = { workspace = true, features = ["preserve_order"] }
serde.workspace = true
serde = { workspace = true, default-features = true }
thiserror.workspace = true

[dev-dependencies]
env_logger.workspace = true
itertools.workspace = true
itertools = { workspace = true, default-features = true }
pretty_assertions.workspace = true
test-case.workspace = true
test-log.workspace = true
2 changes: 1 addition & 1 deletion crates/cairo-lang-defs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "2.4.1" }
cairo-lang-parser = { path = "../cairo-lang-parser", version = "2.4.1" }
cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
itertools.workspace = true
itertools = { workspace = true, default-features = true }
salsa.workspace = true
smol_str.workspace = true

Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-defs/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn module_main_file(db: &dyn DefsGroup, module_id: ModuleId) -> Maybe<FileId> {
}
ModuleId::Submodule(submodule_id) => {
let parent = submodule_id.parent_module(db);
let item_module_ast = &db.priv_module_data(parent)?.submodules[submodule_id];
let item_module_ast = &db.priv_module_data(parent)?.submodules[&submodule_id];
match item_module_ast.body(db.upcast()) {
MaybeModuleBody::Some(_) => {
// This is an inline module, we return the file where the inline module was
Expand Down Expand Up @@ -361,7 +361,7 @@ fn priv_module_data(db: &dyn DefsGroup, module_id: ModuleId) -> Maybe<ModuleData
ModuleId::CrateRoot(_) => file_syntax.items(syntax_db),
ModuleId::Submodule(submodule_id) => {
let parent_module_data = db.priv_module_data(submodule_id.parent_module(db))?;
let item_module_ast = &parent_module_data.submodules[submodule_id];
let item_module_ast = &parent_module_data.submodules[&submodule_id];

match item_module_ast.body(syntax_db) {
MaybeModuleBody::Some(body) => {
Expand Down Expand Up @@ -956,7 +956,7 @@ fn module_item_name_stable_ptr(
) -> Maybe<SyntaxStablePtrId> {
let data = db.priv_module_data(module_id)?;
let db = db.upcast();
Ok(match item_id {
Ok(match &item_id {
ModuleItemId::Constant(id) => data.constants[id].name(db).stable_ptr().untyped(),
ModuleItemId::Submodule(id) => data.submodules[id].name(db).stable_ptr().untyped(),
ModuleItemId::Use(id) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Diagnostic utilities."
cairo-lang-debug = { path = "../cairo-lang-debug", version = "2.4.1" }
cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
itertools.workspace = true
itertools = { workspace = true, default-features = true }

[dev-dependencies]
env_logger.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-eq-solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn try_solve_equations_iteration<Var: Clone + Debug + PartialEq + Eq + Hash>(
target_vars: &[Var],
) -> Option<OrderedHashMap<Var, i64>> {
let mut vars = variables!();
let mut orig_to_solver_var = OrderedHashMap::default();
let mut orig_to_solver_var = OrderedHashMap::new();
// Add all variables to structure and map.
for eq in equations {
for var in eq.var_to_coef.keys() {
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-filesystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ description = "Virtual filesystem for the compiler."

[dependencies]
cairo-lang-debug = { path = "../cairo-lang-debug", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1", features = ["serde"] }
path-clean.workspace = true
salsa.workspace = true
serde.workspace = true
serde = { workspace = true, default-features = true }
smol_str.workspace = true

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
diffy.workspace = true
ignore.workspace = true
itertools.workspace = true
itertools = { workspace = true, default-features = true }
salsa.workspace = true
serde.workspace = true
serde = { workspace = true, default-features = true }
smol_str.workspace = true
thiserror.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-language-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ log.workspace = true
lsp.workspace = true
salsa.workspace = true
scarb-metadata.workspace = true
serde.workspace = true
serde = { workspace = true, default-features = true }
serde_json.workspace = true
tokio.workspace = true
tower-lsp.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-lowering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ cairo-lang-semantic = { path = "../cairo-lang-semantic", version = "2.4.1" }
cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
id-arena.workspace = true
itertools.workspace = true
itertools = { workspace = true, default-features = true }
log.workspace = true
num-bigint.workspace = true
num-traits.workspace = true
num-bigint = { workspace = true, default-features = true }
num-traits = { workspace = true, default-features = true }
once_cell.workspace = true
salsa.workspace = true
smol_str.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-lowering/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fn priv_function_with_body_lowering(
) -> Maybe<Arc<FlatLowered>> {
let semantic_function_id = function_id.base_semantic_function(db);
let multi_lowering = db.priv_function_with_body_multi_lowering(semantic_function_id)?;
let lowered = match db.lookup_intern_lowering_function_with_body(function_id) {
let lowered = match &db.lookup_intern_lowering_function_with_body(function_id) {
ids::FunctionWithBodyLongId::Semantic(_) => multi_lowering.main_lowering.clone(),
ids::FunctionWithBodyLongId::Generated { element, .. } => {
multi_lowering.generated_lowerings[element].clone()
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-lowering/src/lower/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl BlockBuilder {
MemberPath::Var(var) => ctx.semantic_defs[var].ty(),
MemberPath::Member { member_id, concrete_struct_id, .. } => {
ctx.db.concrete_struct_members(*concrete_struct_id).unwrap()
[member_id.name(ctx.db.upcast())]
.ty
[&member_id.name(ctx.db.upcast())]
.ty
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-lowering/src/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ fn lower_single_pattern(
.db
.concrete_struct_members(structure.concrete_struct_id)
.map_err(LoweringFlowError::Failed)?;
let mut required_members = UnorderedHashMap::from_iter(
let mut required_members = UnorderedHashMap::<_, _>::from_iter(
structure.field_patterns.iter().map(|(member, pattern)| (member.id, pattern)),
);
let generator = generators::StructDestructure {
Expand Down Expand Up @@ -1016,7 +1016,7 @@ fn lower_expr_loop(
_ => unreachable!("Loop expression must be either loop or while."),
};

let usage = &ctx.block_usages.block_usages[loop_expr_id];
let usage = &ctx.block_usages.block_usages[&loop_expr_id];

// Determine signature.
let params = usage.usage.iter().map(|(_, expr)| expr.clone()).collect_vec();
Expand Down Expand Up @@ -1740,7 +1740,7 @@ fn lower_expr_struct_ctor(
.db
.concrete_struct_members(expr.concrete_struct_id)
.map_err(LoweringFlowError::Failed)?;
let member_expr = UnorderedHashMap::from_iter(expr.members.iter().cloned());
let member_expr = UnorderedHashMap::<_, _>::from_iter(expr.members.iter().cloned());
Ok(LoweredExpr::AtVariable(
generators::StructConstruct {
inputs: members
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-lowering/src/lower/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl BlockUsages {
Expr::Loop(expr) => {
self.handle_expr(function_body, expr.body, current);
// Copy body usage to loop usage.
self.block_usages.insert(expr_id, self.block_usages[expr.body].clone());
self.block_usages.insert(expr_id, self.block_usages[&expr.body].clone());
}
Expr::While(expr) => {
let mut usage = Default::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn optimize_matches(lowered: &mut FlatLowered) {
analysis.get_root_info();
let ctx = analysis.analyzer;

let mut target_blocks = UnorderedHashSet::default();
let mut target_blocks = UnorderedHashSet::new();
for FixInfo { statement_location, target_block, remapping } in ctx.fixes.into_iter() {
let block = &mut lowered.blocks[statement_location.0];

Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "2.4.1" }
cairo-lang-syntax-codegen = { path = "../cairo-lang-syntax-codegen", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
colored.workspace = true
itertools.workspace = true
num-bigint.workspace = true
num-traits.workspace = true
itertools = { workspace = true, default-features = true }
num-bigint = { workspace = true, default-features = true }
num-traits = { workspace = true, default-features = true }
salsa.workspace = true
smol_str.workspace = true
unescaper.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "2.4.1" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "2.4.1" }
indent.workspace = true
indoc.workspace = true
itertools.workspace = true
itertools = { workspace = true, default-features = true }
salsa.workspace = true
smol_str.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-plugins/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn expand_module_text(
) -> String {
let mut output = String::new();
// A collection of all the use statements in the module.
let mut uses_list = UnorderedHashSet::default();
let mut uses_list = UnorderedHashSet::new();
let syntax_db = db.upcast();
// Collect the module diagnostics.
for (file_id, diag) in db.module_plugin_diagnostics(module_id).unwrap().iter() {
Expand Down
Loading

0 comments on commit c609a8b

Please sign in to comment.