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

Release/2.4 9 #1062

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
216 changes: 135 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
"resolver" = "2"

[workspace.package]
version = "2.4.3"
version = "2.4.4"
edition = "2021"

authors = ["Software Mansion <[email protected]>"]
Expand All @@ -30,27 +30,27 @@ anyhow = "1"
assert_fs = "1"
async-trait = "0.1"
axum = { version = "0.6", features = ["http2"] }
cairo-felt = "0.9.1"
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo.git", rev = "674984e3841566caba7f8089491c06a9a83c4599", features = ["env_logger"] }
cairo-felt = "0.8.2"
cairo-lang-casm = "2.4.4"
cairo-lang-compiler = "2.4.4"
cairo-lang-diagnostics = "2.4.4"
cairo-lang-debug = "2.4.4"
cairo-lang-defs = "2.4.4"
cairo-lang-filesystem = "2.4.4"
cairo-lang-formatter = "2.4.4"
cairo-lang-language-server = "2.4.4"
cairo-lang-lowering = "2.4.4"
cairo-lang-project = "2.4.4"
cairo-lang-runner = "2.4.4"
cairo-lang-semantic = "2.4.4"
cairo-lang-sierra = "2.4.4"
cairo-lang-sierra-generator = "2.4.4"
cairo-lang-sierra-to-casm = "2.4.4"
cairo-lang-starknet = "2.4.4"
cairo-lang-syntax = "2.4.4"
cairo-lang-test-plugin = "2.4.4"
cairo-lang-test-runner = "2.4.4"
cairo-lang-utils = { version = "2.4.4", features = ["env_logger"] }
camino = { version = "1", features = ["serde1"] }
cargo_metadata = ">=0.18"
clap = { version = "4", features = ["derive", "env", "string"] }
Expand Down Expand Up @@ -85,8 +85,8 @@ petgraph = "0.6"
predicates = "3"
proc-macro2 = "1"
quote = "1"
rayon = "1.8"
redb = "1.4"
rayon = "1.8"
reqwest = { version = "0.11", features = ["gzip", "brotli", "deflate", "json", "stream"], default-features = false }
semver = { version = "1", features = ["serde"] }
serde = { version = "1", features = ["serde_derive"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/starknet_hello_world/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod Balance {
self.value.write(value_);
}

#[abi(embed_v0)]
#[external(v0)]
impl Balance of super::IBalance<ContractState> {
fn get(self: @ContractState) -> u128 {
self.value.read()
Expand Down
2 changes: 1 addition & 1 deletion examples/starknet_multiple_contracts/src/balance.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod Balance {
self.value.write(value_);
}

#[abi(embed_v0)]
#[external(v0)]
impl Balance of super::IBalance<ContractState> {
fn get(self: @ContractState) -> u128 {
self.value.read()
Expand Down
2 changes: 1 addition & 1 deletion examples/starknet_multiple_contracts/src/forty_two.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod FortyTwo {
#[storage]
struct Storage {}

#[abi(embed_v0)]
#[external(v0)]
fn answer(ref self: ContractState) -> felt252 {
42
}
Expand Down
2 changes: 1 addition & 1 deletion examples/workspaces/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod FibContract {
#[storage]
struct Storage {}

#[abi(embed_v0)]
#[external(v0)]
fn answer(ref self: ContractState) -> felt252 {
add(fib(0, 1, 16), fib(0, 1, 8))
}
Expand Down
1 change: 0 additions & 1 deletion extensions/scarb-cairo-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ fn main() -> Result<()> {
Some(Default::default())
},
Default::default(),
false,
)?;

let result = runner
Expand Down
2 changes: 1 addition & 1 deletion extensions/scarb-cairo-run/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn can_limit_gas() {
Finished release target(s) in [..]
Running hello_world
Run completed successfully, returning [987]
Remaining gas: 67840
Remaining gas: 53640
"#});
}

Expand Down
1 change: 0 additions & 1 deletion extensions/scarb-cairo-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fn main() -> Result<()> {
filter: args.filter.clone(),
include_ignored: args.include_ignored,
ignored: args.ignored,
run_profiler: false,
};
let runner = CompiledTestRunner::new(test_compilation, config);
runner.run()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn collect_tests(
let main_crate_id =
insert_lib_entrypoint_content_into_db(db, crate_name, crate_root, lib_content);

if build_diagnostics_reporter(compilation_unit).check(db) {
if DiagnosticsReporter::stderr().check(db) {
return Err(anyhow!(
"Failed to compile test artifact, for detailed information go through the logs above"
));
Expand Down Expand Up @@ -166,14 +166,6 @@ pub fn collect_tests(
Ok((sierra_program, collected_tests))
}

fn build_diagnostics_reporter(compilation_unit: &CompilationUnit) -> DiagnosticsReporter<'static> {
if compilation_unit.allow_warnings() {
DiagnosticsReporter::stderr().allow_warnings()
} else {
DiagnosticsReporter::stderr()
}
}

// inspired with cairo-lang-compiler/src/project.rs:49 (part of setup_single_project_file)
fn insert_lib_entrypoint_content_into_db(
db: &mut RootDatabase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use cairo_felt::Felt252;
use cairo_lang_defs::plugin::PluginDiagnostic;
use cairo_lang_diagnostics::Severity;
use cairo_lang_syntax::attribute::structured::{Attribute, AttributeArg, AttributeArgVariant};
use cairo_lang_syntax::node::ast::{ArgClause, Expr, PathSegment};
use cairo_lang_syntax::node::db::SyntaxGroup;
Expand Down Expand Up @@ -103,7 +102,6 @@ pub fn forge_try_extract_test_config(
if maybe_test_config.is_none() {
for attr in [fork_attr, fuzzer_attr].into_iter().flatten() {
diagnostics.push(PluginDiagnostic {
severity: Severity::Error,
stable_ptr: attr.id_stable_ptr.untyped(),
message: "Attribute should only appear on tests.".into(),
});
Expand All @@ -116,7 +114,6 @@ pub fn forge_try_extract_test_config(
} else {
extract_fork_config(db, attr).on_none(|| {
diagnostics.push(PluginDiagnostic {
severity: Severity::Error,
stable_ptr: attr.args_stable_ptr.untyped(),
message: "Expected fork config must be of the form `url: <double quote \
string>, block_id: <snforge_std::BlockId>`."
Expand All @@ -131,7 +128,6 @@ pub fn forge_try_extract_test_config(
let fuzzer_config = if let Some(attr) = fuzzer_attr {
extract_fuzzer_config(db, attr).on_none(|| {
diagnostics.push(PluginDiagnostic {
severity: Severity::Error,
stable_ptr: attr.args_stable_ptr.untyped(),
message: "Expected fuzzer config must be of the form `runs: <u32>, seed: <u64>`"
.into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cairo_lang_defs::plugin::{MacroPlugin, PluginResult};
use cairo_lang_semantic::plugin::PluginSuite;
use cairo_lang_defs::plugin::{MacroPlugin, PluginResult, PluginSuite};
use cairo_lang_syntax::attribute::structured::AttributeListStructurize;
use cairo_lang_syntax::node::ast;
use cairo_lang_syntax::node::db::SyntaxGroup;
Expand All @@ -13,10 +12,10 @@ use super::forge_try_extract_test_config;
struct TestPlugin;

impl MacroPlugin for TestPlugin {
fn generate_code(&self, db: &dyn SyntaxGroup, item_ast: ast::ModuleItem) -> PluginResult {
fn generate_code(&self, db: &dyn SyntaxGroup, item_ast: ast::Item) -> PluginResult {
PluginResult {
code: None,
diagnostics: if let ast::ModuleItem::FreeFunction(free_func_ast) = item_ast {
diagnostics: if let ast::Item::FreeFunction(free_func_ast) = item_ast {
forge_try_extract_test_config(db, &free_func_ast.attributes(db).structurize(db))
.err()
} else {
Expand Down
38 changes: 13 additions & 25 deletions extensions/scarb-snforge-test-collector/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, ensure, Context, Result};
use cairo_lang_filesystem::db::{CrateSettings, Edition, ExperimentalFeaturesConfig};
use cairo_lang_project::AllCratesConfig;
use cairo_lang_filesystem::db::Edition;
use cairo_lang_project::{AllCratesConfig, SingleCrateConfig};
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use camino::{Utf8Path, Utf8PathBuf};
use itertools::Itertools;
Expand Down Expand Up @@ -104,30 +104,28 @@ impl CompilationUnit<'_> {
}

pub fn crates_config_for_compilation_unit(&self) -> AllCratesConfig {
let crates_config: OrderedHashMap<SmolStr, CrateSettings> = self
let crates_config: OrderedHashMap<SmolStr, SingleCrateConfig> = self
.unit_metadata
.components
.iter()
.map(|component| {
let pkg = self
.metadata
.get_package(&component.package)
.unwrap_or_else(|| panic!("Failed to find = {} package", &component.package));
(
SmolStr::from(&component.name),
CrateSettings {
edition: if let Some(edition) = pkg.edition.clone() {
SingleCrateConfig {
edition: if let Some(edition) = self
.metadata
.get_package(&component.package)
.unwrap_or_else(|| {
panic!("Failed to find = {} package", component.package)
})
.edition
.clone()
{
let edition_value = serde_json::Value::String(edition);
serde_json::from_value(edition_value).unwrap()
} else {
Edition::default()
},
// TODO (#1040): replace this with a macro
experimental_features: ExperimentalFeaturesConfig {
negative_impls: pkg
.experimental_features
.contains(&String::from("negative_impls")),
},
},
)
})
Expand All @@ -139,16 +137,6 @@ impl CompilationUnit<'_> {
}
}

/// Retrieve `allow-warnings` flag from the compiler config.
pub fn allow_warnings(&self) -> bool {
self.unit_metadata
.compiler_config
.as_object()
.and_then(|config| config.get("allow_warnings"))
.and_then(|value| value.as_bool())
.unwrap_or(true)
}

pub fn source_root(&self) -> Utf8PathBuf {
self.unit_metadata.target.source_root().to_path_buf()
}
Expand Down
44 changes: 0 additions & 44 deletions extensions/scarb-snforge-test-collector/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,50 +285,6 @@ fn forge_test_with_should_panic_message_attribute() {
assert_eq!(&json[0]["test_cases"][0]["name"], "forge_test::tests::test");
}

#[test]
fn allows_warnings_by_default() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.lib_cairo(indoc! {r#"
fn hello() -> felt252 {
let a = 41;
let b = 42;
b
}
"#})
.build(&t);

Scarb::quick_snapbox()
.arg("snforge-test-collector")
.current_dir(&t)
.assert()
.success();
}

#[test]
fn can_disallow_warnings() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.lib_cairo(indoc! {r#"
fn hello() -> felt252 {
let a = 41;
let b = 42;
b
}
"#})
.manifest_extra(indoc! {r#"
[cairo]
allow-warnings = false
"#})
.build(&t);

Scarb::quick_snapbox()
.arg("snforge-test-collector")
.current_dir(&t)
.assert()
.failure();
}

#[test]
fn uses_dev_dependencies() {
let t = TempDir::new().unwrap();
Expand Down
3 changes: 0 additions & 3 deletions scarb-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ pub struct PackageMetadata {
#[serde(flatten)]
pub manifest_metadata: ManifestMetadata,

/// Compiler experimental features allowed for this package.
pub experimental_features: Vec<String>,

/// Additional data not captured by deserializer.
#[cfg_attr(feature = "builder", builder(default))]
#[serde(flatten)]
Expand Down
1 change: 0 additions & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ anyhow.workspace = true
async-trait.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-defs.workspace = true
cairo-lang-diagnostics.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-formatter.workspace = true
cairo-lang-semantic.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/compiler/compilers/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Compiler for TestCompiler {
let diagnostics_reporter = build_compiler_config(&unit, ws).diagnostics_reporter;

diagnostics_reporter
.with_crates(&main_crate_ids)
.with_extra_crates(&main_crate_ids)
.ensure(db)?;

let test_compilation = {
Expand Down
18 changes: 7 additions & 11 deletions scarb/src/compiler/db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use anyhow::{anyhow, Result};
use cairo_lang_compiler::db::RootDatabase;
use cairo_lang_compiler::project::{AllCratesConfig, ProjectConfig, ProjectConfigContent};
use cairo_lang_compiler::project::{
AllCratesConfig, ProjectConfig, ProjectConfigContent, SingleCrateConfig,
};
use cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::ModuleId;
use cairo_lang_defs::plugin::MacroPlugin;
use cairo_lang_filesystem::db::{AsFilesGroupMut, CrateSettings, FilesGroup, FilesGroupEx};
use cairo_lang_filesystem::db::{AsFilesGroupMut, FilesGroup, FilesGroupEx};
use cairo_lang_filesystem::ids::{CrateLongId, Directory};
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use smol_str::SmolStr;
Expand Down Expand Up @@ -89,25 +91,19 @@ fn build_project_config(unit: &CompilationUnit) -> Result<ProjectConfig> {
})
.collect();

let crates_config: OrderedHashMap<SmolStr, CrateSettings> = unit
let crates_config: OrderedHashMap<SmolStr, SingleCrateConfig> = unit
.components
.iter()
.map(|component| {
let experimental_features = component.package.manifest.experimental_features.clone();
(
component.cairo_package_name(),
CrateSettings {
SingleCrateConfig {
edition: component.package.manifest.edition,
// TODO (#1040): replace this with a macro
experimental_features: cairo_lang_filesystem::db::ExperimentalFeaturesConfig {
negative_impls: experimental_features
.unwrap_or_default()
.contains(&SmolStr::new_inline("negative_impls")),
},
},
)
})
.collect();

let crates_config = AllCratesConfig {
override_map: crates_config,
..Default::default()
Expand Down
Loading