From f2a9f47838dfb1ff4e03f4b051bc85cd43f9708a Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Thu, 5 Sep 2024 10:27:37 +0200 Subject: [PATCH 01/20] Handle error gracefully --- Cargo.lock | 1 + extensions/scarb-doc/Cargo.toml | 1 + .../scarb-doc/src/docs_generation/markdown.rs | 13 ++- extensions/scarb-doc/src/errors.rs | 110 ++++++++++++++++++ extensions/scarb-doc/src/lib.rs | 8 +- extensions/scarb-doc/src/main.rs | 9 +- .../scarb-doc/src/metadata/compilation.rs | 88 ++++++++------ .../scarb-doc/src/versioned_json_output.rs | 13 ++- 8 files changed, 190 insertions(+), 53 deletions(-) create mode 100644 extensions/scarb-doc/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index b9ee24099..fb767f396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4722,6 +4722,7 @@ dependencies = [ "serde", "serde_json", "smol_str", + "thiserror", "walkdir", ] diff --git a/extensions/scarb-doc/Cargo.toml b/extensions/scarb-doc/Cargo.toml index 3403d4058..f502d8176 100644 --- a/extensions/scarb-doc/Cargo.toml +++ b/extensions/scarb-doc/Cargo.toml @@ -30,6 +30,7 @@ serde.workspace = true serde_json.workspace = true salsa.workspace = true smol_str.workspace = true +thiserror.workspace = true [dev-dependencies] assert_fs.workspace = true diff --git a/extensions/scarb-doc/src/docs_generation/markdown.rs b/extensions/scarb-doc/src/docs_generation/markdown.rs index c5b2ede90..c5d64740a 100644 --- a/extensions/scarb-doc/src/docs_generation/markdown.rs +++ b/extensions/scarb-doc/src/docs_generation/markdown.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result}; +use anyhow::Result; use camino::Utf8Path; use itertools::{chain, Itertools}; use std::fs; @@ -9,6 +9,7 @@ use crate::docs_generation::markdown::traits::{ generate_markdown_list_for_top_level_subitems, TopLevelMarkdownDocItem, }; use crate::docs_generation::{collect_all_top_level_items, TopLevelItems}; +use crate::errors::{IODirectoryCreationError, IOWriteError}; use crate::types::{ Constant, Enum, ExternFunction, ExternType, FreeFunction, Impl, ImplAlias, Module, Struct, Trait, TypeAlias, @@ -126,17 +127,17 @@ impl MarkdownContent { pub fn save(self, output_dir: &Utf8Path) -> Result<()> { let source_directory_path = output_dir.join(SOURCE_DIRECTORY); fs::create_dir_all(&source_directory_path) - .context("failed to create directory for docs")?; + .map_err(|e| IODirectoryCreationError::new(e, "generated documentation"))?; fs::write(output_dir.join(BOOK_TOML_FILENAME), self.book_toml) - .context("failed to write book.toml content to a file")?; + .map_err(|e| IOWriteError::new(e, "book.toml"))?; fs::write(source_directory_path.join(SUMMARY_FILENAME), self.summary) - .context("failed to write summary content to a file")?; + .map_err(|e| IOWriteError::new(e, "summary"))?; for (filename, file_content) in self.doc_files { - fs::write(source_directory_path.join(filename), file_content) - .context("failed to write content to a doc file")?; + fs::write(source_directory_path.join(filename.clone()), file_content) + .map_err(|e| IOWriteError::new(e, filename.as_ref()))?; } Ok(()) diff --git a/extensions/scarb-doc/src/errors.rs b/extensions/scarb-doc/src/errors.rs new file mode 100644 index 000000000..a0ec8277d --- /dev/null +++ b/extensions/scarb-doc/src/errors.rs @@ -0,0 +1,110 @@ +use core::fmt; +use scarb_metadata::MetadataCommandError as ScarbMetadataCommandFail; +use serde_json::Error as SerdeError; +use std::error::Error as StdError; +use std::io::Error as IOError; +use thiserror::Error; + +#[derive(Debug, Error)] +#[error("failed to serialize information about crates")] +pub struct PackagesSerializationError(#[from] SerdeError); + +#[derive(Debug, Error)] +#[error("failed to find {0} package")] +pub struct MissingPackageError(pub String); + +#[derive(Debug, Error)] +#[error("Cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`.")] +pub struct CfgParseError(#[from] SerdeError); + +#[derive(Debug, Error)] +#[error("failed to find corelib")] +pub struct MissingCorelibError; + +#[derive(Debug, Error)] +#[error("failed to find compilation unit for package {0}")] +pub struct MissingCompilationUnitForPackage(pub String); + +#[derive(Debug, Error)] +#[error("metadata command failed")] +pub struct MetadataCommandError(#[from] ScarbMetadataCommandFail); + +pub struct IODirectoryCreationError { + inner_error: IOError, + directory_purpose: String, +} + +impl IODirectoryCreationError { + pub fn new(err: IOError, directory_purpose: &str) -> Self { + Self { + inner_error: err, + directory_purpose: String::from(directory_purpose), + } + } +} + +impl fmt::Debug for IODirectoryCreationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "failed to create directory for {} due to error: {}", + self.directory_purpose, self.inner_error + ) + } +} + +impl fmt::Display for IODirectoryCreationError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "failed to write content {} due to error: {}", + self.directory_purpose, self.inner_error + ) + } +} + +impl StdError for IODirectoryCreationError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + Some(&self.inner_error) + } +} + +pub struct IOWriteError { + inner_error: IOError, + content_name: String, +} + +impl IOWriteError { + pub fn new(err: IOError, content: &str) -> Self { + Self { + inner_error: err, + content_name: String::from(content), + } + } +} + +impl fmt::Debug for IOWriteError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "failed to write content {} to a file due to error: {}", + self.content_name, self.inner_error + ) + } +} + +impl fmt::Display for IOWriteError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "failed to write content {} to a file due to error: {}", + self.content_name, self.inner_error + ) + } +} + +impl StdError for IOWriteError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + Some(&self.inner_error) + } +} diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index fa14dc9ec..e5c0f2950 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use cairo_lang_compiler::project::ProjectConfig; use cairo_lang_filesystem::db::{Edition, FilesGroup}; use cairo_lang_filesystem::ids::CrateLongId; @@ -10,6 +11,7 @@ use types::Crate; pub mod db; pub mod docs_generation; +pub mod errors; pub mod metadata; pub mod types; pub mod versioned_json_output; @@ -30,7 +32,7 @@ pub fn generate_packages_information( metadata: &Metadata, metadata_for_packages: &[PackageMetadata], document_private_items: bool, -) -> Vec { +) -> Result> { let mut packages_information = vec![]; for package_metadata in metadata_for_packages { let authors = package_metadata.manifest_metadata.authors.clone(); @@ -46,7 +48,7 @@ pub fn generate_packages_information( let should_document_private_items = should_ignore_visibility || document_private_items; - let project_config = get_project_config(metadata, package_metadata); + let project_config = get_project_config(metadata, package_metadata)?; let crate_ = generate_language_elements_tree_for_package( package_metadata.name.clone(), @@ -62,7 +64,7 @@ pub fn generate_packages_information( }, }); } - packages_information + Ok(packages_information) } fn generate_language_elements_tree_for_package( diff --git a/extensions/scarb-doc/src/main.rs b/extensions/scarb-doc/src/main.rs index bbce2309e..7acabe4d6 100644 --- a/extensions/scarb-doc/src/main.rs +++ b/extensions/scarb-doc/src/main.rs @@ -1,6 +1,7 @@ use anyhow::{Context, Result}; use clap::Parser; use scarb_doc::docs_generation::markdown::MarkdownContent; +use scarb_doc::errors::MetadataCommandError; use scarb_doc::metadata::get_target_dir; use scarb_metadata::MetadataCommand; @@ -52,7 +53,7 @@ fn main_inner() -> Result<()> { .inherit_stderr() .envs(args.features.to_env_vars()) .exec() - .context("metadata command failed")?; + .map_err(|e| MetadataCommandError::from(e))?; let metadata_for_packages = args.packages_filter.match_many(&metadata)?; let output_dir = get_target_dir(&metadata).join(OUTPUT_DIR); @@ -60,13 +61,11 @@ fn main_inner() -> Result<()> { &metadata, &metadata_for_packages, args.document_private_items, - ); + )?; match args.output_format { OutputFormat::Json => { - VersionedJsonOutput::new(packages_information) - .save_to_file(&output_dir) - .context("failed to write output of scarb doc to a file")?; + VersionedJsonOutput::new(packages_information).save_to_file(&output_dir)? } OutputFormat::Markdown => { for pkg_information in packages_information { diff --git a/extensions/scarb-doc/src/metadata/compilation.rs b/extensions/scarb-doc/src/metadata/compilation.rs index 7223c6490..b32ae20c9 100644 --- a/extensions/scarb-doc/src/metadata/compilation.rs +++ b/extensions/scarb-doc/src/metadata/compilation.rs @@ -4,6 +4,7 @@ use scarb_metadata::{ use smol_str::{SmolStr, ToSmolStr}; use std::path::PathBuf; +use anyhow::{bail, Error, Result}; use cairo_lang_compiler::project::{AllCratesConfig, ProjectConfig, ProjectConfigContent}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{CrateSettings, Edition, ExperimentalFeaturesConfig}; @@ -11,6 +12,10 @@ use cairo_lang_filesystem::ids::Directory; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use itertools::Itertools; +use crate::errors::{ + CfgParseError, MissingCompilationUnitForPackage, MissingCorelibError, MissingPackageError, +}; + const LIB_TARGET_KIND: &str = "lib"; const STARKNET_TARGET_KIND: &str = "starknet-contract"; const CORELIB_CRATE_NAME: &str = "core"; @@ -18,25 +23,26 @@ const CORELIB_CRATE_NAME: &str = "core"; pub fn get_project_config( metadata: &Metadata, package_metadata: &PackageMetadata, -) -> ProjectConfig { - let compilation_unit_metadata = package_compilation_unit(metadata, package_metadata.id.clone()); - let corelib = get_corelib(compilation_unit_metadata); +) -> Result { + let compilation_unit_metadata = + package_compilation_unit(metadata, package_metadata.id.clone())?; + let corelib = get_corelib(compilation_unit_metadata)?; let dependencies = get_dependencies(compilation_unit_metadata); - let crates_config = get_crates_config(metadata, compilation_unit_metadata); - ProjectConfig { + let crates_config = get_crates_config(metadata, compilation_unit_metadata)?; + Ok(ProjectConfig { base_path: package_metadata.root.clone().into(), corelib: Some(Directory::Real(corelib.source_root().into())), content: ProjectConfigContent { crate_roots: dependencies, crates_config, }, - } + }) } fn package_compilation_unit( metadata: &Metadata, package_id: PackageId, -) -> &CompilationUnitMetadata { +) -> Result<&CompilationUnitMetadata, MissingCompilationUnitForPackage> { let relevant_cus = metadata .compilation_units .iter() @@ -51,17 +57,18 @@ fn package_compilation_unit( .iter() .find(|m| m.target.kind == STARKNET_TARGET_KIND) }) - .expect("failed to find compilation unit for package") + .ok_or(MissingCompilationUnitForPackage(package_id.to_string())) + .copied() } fn get_corelib( compilation_unit_metadata: &CompilationUnitMetadata, -) -> &CompilationUnitComponentMetadata { +) -> Result<&CompilationUnitComponentMetadata> { compilation_unit_metadata .components .iter() .find(|du| du.name == CORELIB_CRATE_NAME) - .expect("Corelib could not be found") + .ok_or(Error::new(MissingCorelibError)) } fn get_dependencies( @@ -83,30 +90,41 @@ fn get_dependencies( fn get_crates_config( metadata: &Metadata, compilation_unit_metadata: &CompilationUnitMetadata, -) -> AllCratesConfig { - let crates_config: OrderedHashMap = compilation_unit_metadata +) -> Result { + let crates_config: Result> = compilation_unit_metadata .components .iter() .map(|component| { - let pkg = metadata.get_package(&component.package).unwrap_or_else(|| { - panic!( - "failed to find = {} package", - &component.package.to_string() - ) - }); - ( - SmolStr::from(&component.name), - get_crate_settings_for_package( - pkg, - component.cfg.as_ref().map(|cfg_vec| build_cfg_set(cfg_vec)), - ), - ) + let pkg = metadata.get_package(&component.package); + let cfg_result = component + .cfg + .as_ref() + .map(|cfg_vec| build_cfg_set(cfg_vec)) + .transpose(); + + match (pkg, cfg_result) { + (Some(pkg), Ok(cfg_set)) => Ok(( + SmolStr::from(&component.name), + get_crate_settings_for_package(pkg, cfg_set), + )), + (None, _) => { + bail!(MissingPackageError(component.package.to_string())) + } + (_, Err(e)) => bail!(e), + } }) .collect(); - AllCratesConfig { - override_map: crates_config, - ..Default::default() + if let Err(error) = crates_config { + return Err(error); + } + + match crates_config { + Ok(crates_config) => Ok(AllCratesConfig { + override_map: crates_config, + ..Default::default() + }), + Err(error) => Err(error), } } @@ -139,10 +157,12 @@ fn get_crate_settings_for_package( } } -fn build_cfg_set(cfg: &[scarb_metadata::Cfg]) -> CfgSet { - CfgSet::from_iter(cfg.iter().map(|cfg| { - serde_json::to_value(cfg) - .and_then(serde_json::from_value::) - .expect("Cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`.") - })) +fn build_cfg_set(cfg: &[scarb_metadata::Cfg]) -> Result { + cfg.iter() + .map(|cfg| { + serde_json::to_value(cfg) + .and_then(serde_json::from_value::) + .map_err(|e| CfgParseError::from(e)) + }) + .collect::>() } diff --git a/extensions/scarb-doc/src/versioned_json_output.rs b/extensions/scarb-doc/src/versioned_json_output.rs index 61c56fa3d..f6569600c 100644 --- a/extensions/scarb-doc/src/versioned_json_output.rs +++ b/extensions/scarb-doc/src/versioned_json_output.rs @@ -1,5 +1,8 @@ -use crate::PackageInformation; -use anyhow::{Context, Result}; +use crate::{ + errors::{IODirectoryCreationError, IOWriteError, PackagesSerializationError}, + PackageInformation, +}; +use anyhow::Result; use camino::Utf8Path; use serde::Serialize; use std::fs; @@ -23,15 +26,15 @@ impl VersionedJsonOutput { pub fn save_to_file(&self, output_dir: &Utf8Path) -> Result<()> { fs::create_dir_all(output_dir) - .context("failed to create output directory for scarb doc")?; + .map_err(|e| IODirectoryCreationError::new(e, "generated documentation"))?; let output_path = output_dir.join(JSON_OUTPUT_FILENAME); let output = serde_json::to_string_pretty(&self) - .expect("failed to serialize information about crates") + .map_err(|e| PackagesSerializationError::from(e))? + "\n"; - fs::write(output_path, output)?; + fs::write(output_path, output).map_err(|e| IOWriteError::new(e, "json documentation"))?; Ok(()) } From a206c42ffdc549f2cc8561f6c78163ad4c57030c Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Tue, 10 Sep 2024 13:33:15 +0200 Subject: [PATCH 02/20] Complete removing unwrap from compilator queries --- Cargo.lock | 1 + extensions/scarb-doc/Cargo.toml | 1 + extensions/scarb-doc/src/db.rs | 194 ++++++++++---------- extensions/scarb-doc/src/errors.rs | 4 + extensions/scarb-doc/src/lib.rs | 54 +++++- extensions/scarb-doc/src/main.rs | 8 +- extensions/scarb-doc/src/types.rs | 279 ++++++++++++++++------------- 7 files changed, 316 insertions(+), 225 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb767f396..234b540e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4703,6 +4703,7 @@ dependencies = [ "assert_fs", "cairo-lang-compiler", "cairo-lang-defs", + "cairo-lang-diagnostics", "cairo-lang-doc", "cairo-lang-filesystem", "cairo-lang-parser", diff --git a/extensions/scarb-doc/Cargo.toml b/extensions/scarb-doc/Cargo.toml index f502d8176..bad2b7cd7 100644 --- a/extensions/scarb-doc/Cargo.toml +++ b/extensions/scarb-doc/Cargo.toml @@ -21,6 +21,7 @@ cairo-lang-semantic.workspace = true cairo-lang-starknet.workspace = true cairo-lang-syntax.workspace = true cairo-lang-utils.workspace = true +cairo-lang-diagnostics.workspace = true expect-test.workspace = true indoc.workspace = true itertools.workspace = true diff --git a/extensions/scarb-doc/src/db.rs b/extensions/scarb-doc/src/db.rs index 1a9dc8958..a6b89c529 100644 --- a/extensions/scarb-doc/src/db.rs +++ b/extensions/scarb-doc/src/db.rs @@ -1,7 +1,11 @@ +use anyhow::Result; +use cairo_lang_compiler::db::RootDatabase; +use cairo_lang_compiler::diagnostics::DiagnosticsReporter; use cairo_lang_compiler::project::{ update_crate_root, update_crate_roots_from_project_config, ProjectConfig, }; use cairo_lang_defs::db::{ext_as_virtual_impl, DefsDatabase, DefsGroup}; +use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Severity}; use cairo_lang_doc::db::{DocDatabase, DocGroup}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{ @@ -19,115 +23,125 @@ use cairo_lang_utils::Upcast; use salsa; /// The Cairo compiler Salsa database tailored for scarb-doc usage. -#[salsa::database( - FilesDatabase, - ParserDatabase, - SyntaxDatabase, - DefsDatabase, - SemanticDatabase, - DocDatabase -)] +// #[salsa::database( +// FilesDatabase, +// ParserDatabase, +// SyntaxDatabase, +// DefsDatabase, +// SemanticDatabase, +// DocDatabase +// )] pub struct ScarbDocDatabase { - storage: salsa::Storage, + // storage: salsa::Storage, + pub db: RootDatabase, } impl ScarbDocDatabase { - pub fn new(project_config: Option) -> Self { - let mut db = Self { - storage: Default::default(), - }; - - init_files_group(&mut db); + pub fn new(project_config: Option) -> Result { + let mut db_builder = RootDatabase::builder(); + if let Some(config) = project_config { + db_builder.with_project_config(config); + } + db_builder.with_cfg(Self::initial_cfg_set()); - db.set_cfg_set(Self::initial_cfg_set().into()); let plugin_suite = [get_default_plugin_suite(), starknet_plugin_suite()] .into_iter() .fold(PluginSuite::default(), |mut acc, suite| { acc.add(suite); acc }); + db_builder.with_plugin_suite(plugin_suite); + let db = db_builder.build()?; + // let mut db = Self { + // storage: Default::default(), + // }; - db.apply_plugin_suite(plugin_suite); - - if let Some(config) = project_config { - db.apply_project_config(config); - } - - db - } - - fn initial_cfg_set() -> CfgSet { - CfgSet::from_iter([Cfg::name("doc")]) - } - - fn apply_plugin_suite(&mut self, plugin_suite: PluginSuite) { - self.set_macro_plugins(plugin_suite.plugins); - self.set_inline_macro_plugins(plugin_suite.inline_macro_plugins.into()); - self.set_analyzer_plugins(plugin_suite.analyzer_plugins); - } - - fn apply_project_config(&mut self, config: ProjectConfig) { - update_crate_roots_from_project_config(self, &config); - if let Some(corelib) = &config.corelib { - update_crate_root(self, &config, CORELIB_CRATE_NAME.into(), corelib.clone()); - } - } -} - -impl salsa::Database for ScarbDocDatabase {} + // init_files_group(&mut db); + // let diag = ScarbDocDatabase::setup_diagnostics(); -impl ExternalFiles for ScarbDocDatabase { - fn ext_as_virtual(&self, external_id: salsa::InternId) -> VirtualFile { - ext_as_virtual_impl(self.upcast(), external_id) - } -} - -impl salsa::ParallelDatabase for ScarbDocDatabase { - fn snapshot(&self) -> salsa::Snapshot { - salsa::Snapshot::new(ScarbDocDatabase { - storage: self.storage.snapshot(), - }) - } -} + // db.set_cfg_set(Self::initial_cfg_set().into()); -impl AsFilesGroupMut for ScarbDocDatabase { - fn as_files_group_mut(&mut self) -> &mut (dyn FilesGroup + 'static) { - self - } -} + // db.apply_plugin_suite(plugin_suite); -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn FilesGroup + 'static) { - self - } -} + // if let Some(config) = project_config { + // db.apply_project_config(config); + // } -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn ParserGroup + 'static) { - self + Ok(Self { db }) } -} -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn SyntaxGroup + 'static) { - self + fn initial_cfg_set() -> CfgSet { + CfgSet::from_iter([Cfg::name("doc")]) } -} -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn DefsGroup + 'static) { - self - } + // fn apply_plugin_suite(&mut self, plugin_suite: PluginSuite) { + // self.set_macro_plugins(plugin_suite.plugins); + // self.set_inline_macro_plugins(plugin_suite.inline_macro_plugins.into()); + // self.set_analyzer_plugins(plugin_suite.analyzer_plugins); + // } + + // fn apply_project_config(&mut self, config: ProjectConfig) { + // update_crate_roots_from_project_config(self, &config); + // if let Some(corelib) = &config.corelib { + // update_crate_root(self, &config, CORELIB_CRATE_NAME.into(), corelib.clone()); + // } + // } } -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn SemanticGroup + 'static) { - self - } -} - -impl Upcast for ScarbDocDatabase { - fn upcast(&self) -> &(dyn DocGroup + 'static) { - self - } -} +// impl salsa::Database for ScarbDocDatabase {} + +// impl ExternalFiles for ScarbDocDatabase { +// fn ext_as_virtual(&self, external_id: salsa::InternId) -> VirtualFile { +// ext_as_virtual_impl(self.upcast(), external_id) +// } +// } + +// impl salsa::ParallelDatabase for ScarbDocDatabase { +// fn snapshot(&self) -> salsa::Snapshot { +// salsa::Snapshot::new(ScarbDocDatabase { +// storage: self.storage.snapshot(), +// }) +// } +// } + +// impl AsFilesGroupMut for ScarbDocDatabase { +// fn as_files_group_mut(&mut self) -> &mut (dyn FilesGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn FilesGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn ParserGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn SyntaxGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn DefsGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn SemanticGroup + 'static) { +// self +// } +// } + +// impl Upcast for ScarbDocDatabase { +// fn upcast(&self) -> &(dyn DocGroup + 'static) { +// self +// } +// } diff --git a/extensions/scarb-doc/src/errors.rs b/extensions/scarb-doc/src/errors.rs index a0ec8277d..465e77246 100644 --- a/extensions/scarb-doc/src/errors.rs +++ b/extensions/scarb-doc/src/errors.rs @@ -29,6 +29,10 @@ pub struct MissingCompilationUnitForPackage(pub String); #[error("metadata command failed")] pub struct MetadataCommandError(#[from] ScarbMetadataCommandFail); +#[derive(Debug, Error)] +#[error("could not compile {0} due to previous error")] +pub struct DiagnosticError(pub String); + pub struct IODirectoryCreationError { inner_error: IOError, directory_purpose: String, diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index e5c0f2950..3636ce2b8 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -1,7 +1,11 @@ use anyhow::Result; +use cairo_lang_compiler::diagnostics::DiagnosticsReporter; use cairo_lang_compiler::project::ProjectConfig; +use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Maybe, Severity}; use cairo_lang_filesystem::db::{Edition, FilesGroup}; use cairo_lang_filesystem::ids::CrateLongId; +use cairo_lang_utils::Upcast; +use errors::DiagnosticError; use scarb_metadata::{Metadata, PackageMetadata}; use serde::Serialize; @@ -16,13 +20,13 @@ pub mod metadata; pub mod types; pub mod versioned_json_output; -#[derive(Serialize)] +#[derive(Serialize, Clone)] pub struct PackageInformation { pub crate_: Crate, pub metadata: AdditionalMetadata, } -#[derive(Serialize)] +#[derive(Serialize, Clone)] pub struct AdditionalMetadata { pub name: String, pub authors: Option>, @@ -39,7 +43,8 @@ pub fn generate_packages_information( let edition = package_metadata .edition .as_ref() - .map(|edition| edition_from_string(edition).unwrap()); + .map(|edition| edition_from_string(edition)) + .transpose()?; let should_ignore_visibility = match edition { Some(edition) => edition.ignore_visibility(), @@ -54,7 +59,8 @@ pub fn generate_packages_information( package_metadata.name.clone(), project_config, should_document_private_items, - ); + ) + .map_err(|_| DiagnosticError(package_metadata.name.clone()))?; packages_information.push(PackageInformation { crate_, @@ -71,14 +77,48 @@ fn generate_language_elements_tree_for_package( package_name: String, project_config: ProjectConfig, document_private_items: bool, -) -> Crate { - let db = ScarbDocDatabase::new(Some(project_config)); +) -> Maybe { + let db = ScarbDocDatabase::new(Some(project_config))?; - let main_crate_id = db.intern_crate(CrateLongId::Real(package_name.into())); + let main_crate_id = db.db.intern_crate(CrateLongId::Real(package_name.into())); + + let mut diagnostics_reporter = setup_diagnostics_reporter(); + + diagnostics_reporter.ensure(&db.db); Crate::new(&db, main_crate_id, document_private_items) } +fn setup_diagnostics_reporter() -> DiagnosticsReporter { + DiagnosticsReporter::callback({ + |entry: FormattedDiagnosticEntry| { + let msg = entry + .message() + .strip_suffix('\n') + .unwrap_or(entry.message()); + match entry.severity() { + Severity::Error => { + if let Some(code) = entry.error_code() { + // config.ui().error_with_code(code.as_str(), msg) + eprintln!("{} {}", code.as_str(), msg); + } else { + eprintln!("{}", msg); + } + } + Severity::Warning => { + if let Some(code) = entry.error_code() { + // config.ui().warn_with_code(code.as_str(), msg) + eprintln!("{} {}", code.as_str(), msg); + } else { + // config.ui().warn(msg) + eprintln!("{}", msg); + } + } + }; + } + }); +} + pub fn edition_from_string(edition_str: &str) -> Result { // Format `edition` to be a valid JSON string. let edition = format!("\"{}\"", edition_str); diff --git a/extensions/scarb-doc/src/main.rs b/extensions/scarb-doc/src/main.rs index 7acabe4d6..4fe10438b 100644 --- a/extensions/scarb-doc/src/main.rs +++ b/extensions/scarb-doc/src/main.rs @@ -57,11 +57,15 @@ fn main_inner() -> Result<()> { let metadata_for_packages = args.packages_filter.match_many(&metadata)?; let output_dir = get_target_dir(&metadata).join(OUTPUT_DIR); - let packages_information = generate_packages_information( + let packages_information_result = generate_packages_information( &metadata, &metadata_for_packages, args.document_private_items, - )?; + ); + + println!("{:?}", &packages_information_result.is_err()); + + let packages_information = packages_information_result?; match args.output_format { OutputFormat::Json => { diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 71676d5f1..0c873a786 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -1,7 +1,12 @@ // TODO(drknzz): Remove when not needed. -#![allow(dead_code)] +// #![allow(dead_code)] -use cairo_lang_semantic::items::visibility; +use std::sync::Arc; + +use anyhow::{bail, Error, Result}; +use cairo_lang_diagnostics::{DiagnosticAdded, Maybe}; +use cairo_lang_semantic::items::{constant, impl_alias, visibility}; +use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use cairo_lang_utils::Upcast; use itertools::Itertools; use serde::Serialize; @@ -19,7 +24,7 @@ use cairo_lang_doc::db::DocGroup; use cairo_lang_doc::documentable_item::DocumentableItemId; use cairo_lang_filesystem::ids::CrateId; use cairo_lang_semantic::db::SemanticGroup; -use cairo_lang_syntax::node::ast; +use cairo_lang_syntax::node::ast::{self, ItemConstant}; use crate::db::ScarbDocDatabase; @@ -29,11 +34,15 @@ pub struct Crate { } impl Crate { - pub fn new(db: &ScarbDocDatabase, crate_id: CrateId, include_private_items: bool) -> Self { + pub fn new( + db: &ScarbDocDatabase, + crate_id: CrateId, + include_private_items: bool, + ) -> Maybe { let root_module_id = ModuleId::CrateRoot(crate_id); - Self { - root_module: Module::new(db, root_module_id, root_module_id, include_private_items), - } + Ok(Self { + root_module: Module::new(db, root_module_id, root_module_id, include_private_items)?, + }) } } @@ -41,19 +50,16 @@ fn is_visible_in_module( db: &ScarbDocDatabase, root_module_id: ModuleId, element_id: &dyn TopLevelLanguageElementId, -) -> bool { +) -> Maybe { let cotaining_module_id = element_id.parent_module(db); - match db - .module_item_info_by_name(cotaining_module_id, element_id.name(db.upcast())) - .unwrap() - { - Some(module_item_info) => visibility::peek_visible_in( + match db.module_item_info_by_name(cotaining_module_id, element_id.name(db.upcast()))? { + Some(module_item_info) => Ok(visibility::peek_visible_in( db, module_item_info.visibility, cotaining_module_id, root_module_id, - ), - None => false, + )), + None => Ok(false), } } @@ -79,10 +85,10 @@ pub struct Module { impl Module { pub fn new( db: &ScarbDocDatabase, - root_module_id: ModuleId, module_id: ModuleId, + root_module_id: ModuleId, include_private_items: bool, - ) -> Self { + ) -> Maybe { // FIXME(#1438): compiler doesn't support fetching root crate doc let item_data = match module_id { ModuleId::CrateRoot(crate_id) => ItemData { @@ -100,96 +106,76 @@ impl Module { let should_include_item = |id: &dyn TopLevelLanguageElementId| { if include_private_items { - return true; + return Ok(true); } is_visible_in_module(db, root_module_id, id) }; - let module_constants = db.module_constants(module_id).unwrap(); - let constants = module_constants - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| Constant::new(db, *id)) - .collect(); - - let module_free_functions = db.module_free_functions(module_id).unwrap(); - let free_functions = module_free_functions - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| FreeFunction::new(db, *id)) - .collect(); - - let module_structs = db.module_structs(module_id).unwrap(); - let structs = module_structs - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| Struct::new(db, *id, root_module_id, include_private_items)) - .collect(); - - let module_enums = db.module_enums(module_id).unwrap(); - let enums = module_enums - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| Enum::new(db, *id)) - .collect(); - - let module_type_aliases = db.module_type_aliases(module_id).unwrap(); - let type_aliases = module_type_aliases - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| TypeAlias::new(db, *id)) - .collect(); - - let module_impl_aliases = db.module_impl_aliases(module_id).unwrap(); - let impl_aliases = module_impl_aliases - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| ImplAlias::new(db, *id)) - .collect(); - - let module_traits = db.module_traits(module_id).unwrap(); - let traits = module_traits - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| Trait::new(db, *id)) - .collect(); - - let module_impls = db.module_impls(module_id).unwrap(); - let impls = module_impls - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| Impl::new(db, *id)) - .collect(); - - let module_extern_types = db.module_extern_types(module_id).unwrap(); - let extern_types = module_extern_types - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| ExternType::new(db, *id)) - .collect(); - - let module_extern_functions = db.module_extern_functions(module_id).unwrap(); - let extern_functions = module_extern_functions - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| ExternFunction::new(db, *id)) - .collect(); - - let module_submodules = db.module_submodules(module_id).unwrap(); - let submodules = module_submodules - .iter() - .filter(|(id, _)| should_include_item(*id)) - .map(|(id, _)| { - Self::new( + let module_constants = db.module_constants(module_id)?; + let constants = filter_map_item_id_to_item(module_constants, should_include_item, |id| { + Ok(Constant::new(db, id)) + })?; + + let module_free_functions = db.module_free_functions(module_id)?; + let free_functions = + filter_map_item_id_to_item(module_free_functions, should_include_item, |id| { + Ok(FreeFunction::new(db, id)) + })?; + + let module_structs = db.module_structs(module_id)?; + let structs = filter_map_item_id_to_item(module_structs, should_include_item, |id| { + Struct::new(db, id, root_module_id, include_private_items) + })?; + + let module_enums = db.module_enums(module_id)?; + let enums = + filter_map_item_id_to_item(module_enums, should_include_item, |id| Enum::new(db, id))?; + + let module_type_aliases = db.module_type_aliases(module_id)?; + let type_aliases = + filter_map_item_id_to_item(module_type_aliases, should_include_item, |id| { + Ok(TypeAlias::new(db, id)) + })?; + + let module_impl_aliases = db.module_impl_aliases(module_id)?; + let impl_aliases = + filter_map_item_id_to_item(module_impl_aliases, should_include_item, |id| { + Ok(ImplAlias::new(db, id)) + })?; + + let module_traits = db.module_traits(module_id)?; + let traits = filter_map_item_id_to_item(module_traits, should_include_item, |id| { + Trait::new(db, id) + })?; + + let module_impls = db.module_impls(module_id)?; + let impls = + filter_map_item_id_to_item(module_impls, should_include_item, |id| Impl::new(db, id))?; + + let module_extern_types = db.module_extern_types(module_id)?; + let extern_types = + filter_map_item_id_to_item(module_extern_types, should_include_item, |id| { + Ok(ExternType::new(db, id)) + })?; + + let module_extern_functions = db.module_extern_functions(module_id)?; + let extern_functions = + filter_map_item_id_to_item(module_extern_functions, should_include_item, |id| { + Ok(ExternFunction::new(db, id)) + })?; + + let module_submodules = db.module_submodules(module_id)?; + let submodules: Vec = + filter_map_item_id_to_item(module_submodules, should_include_item, |id| { + Module::new( db, + ModuleId::Submodule(id), root_module_id, - ModuleId::Submodule(*id), include_private_items, ) - }) - .collect(); + })?; - Self { + Ok(Self { module_id, item_data, submodules, @@ -203,10 +189,42 @@ impl Module { impls, extern_types, extern_functions, - } + }) } } +/// Takes the HashMap of items (returned from db query), filter them based on the `should_include_item_function` returned value, +/// and then generates an item based on its ID with function `generate_item_function`. +/// Generic types: +/// T - Type representing ID of an item. Accepts any kind of `TopLevelLanguageElementId`. +/// F - function that checks whether the id should be included in the result Vector. +/// G - A closure (as a function), which generates an item based on the item's ID. +/// J - Type representing an item ast type. +/// K - Type of generated item. +fn filter_map_item_id_to_item( + items: Arc>, + should_include_item_function: F, + generate_item_function: G, +) -> Result, DiagnosticAdded> +where + T: Copy + TopLevelLanguageElementId, + F: Fn(&dyn TopLevelLanguageElementId) -> Result, + G: Fn(T) -> Maybe, +{ + items + .iter() + .filter_map(|(id, _)| match should_include_item_function(id) { + Ok(result) => { + if !result { + return None; + } + Some(Ok(generate_item_function(*id))) + } + Err(a) => Some(Err(a)), + }) + .collect::>>>()? +} + #[derive(Serialize, Clone)] pub struct ItemData { pub name: String, @@ -311,8 +329,8 @@ impl Struct { id: StructId, root_module_id: ModuleId, include_private_items: bool, - ) -> Self { - let members = db.struct_members(id).unwrap(); + ) -> Maybe { + let members = db.struct_members(id)?; let item_data = ItemData::new_without_signature( db, @@ -322,22 +340,31 @@ impl Struct { let members = members .iter() - .filter(|(_, semantic_member)| { - include_private_items - || is_visible_in_module(db, root_module_id, &semantic_member.id) - }) - .map(|(_name, semantic_member)| { - Member::new(db, semantic_member.id, item_data.full_path.clone()) + .filter_map(|(_, semantic_member)| { + match is_visible_in_module(db, root_module_id, &semantic_member.id) { + Ok(visible) => { + if include_private_items || visible { + Some(Ok(Member::new( + db, + semantic_member.id, + item_data.full_path.clone(), + ))) + } else { + None + } + } + Err(e) => Some(Err(e)), + } }) - .collect::>(); + .collect::>>()?; let node = id.stable_ptr(db); - Self { + Ok(Self { id, node, members, item_data, - } + }) } } @@ -388,8 +415,8 @@ pub struct Enum { } impl Enum { - pub fn new(db: &ScarbDocDatabase, id: EnumId) -> Self { - let variants = db.enum_variants(id).unwrap(); + pub fn new(db: &ScarbDocDatabase, id: EnumId) -> Maybe { + let variants = db.enum_variants(id)?; let item_data = ItemData::new_without_signature( db, id, @@ -402,12 +429,12 @@ impl Enum { .collect::>(); let node = id.stable_ptr(db); - Self { + Ok(Self { id, node, variants, item_data, - } + }) } } @@ -510,7 +537,7 @@ pub struct Trait { } impl Trait { - pub fn new(db: &ScarbDocDatabase, id: TraitId) -> Self { + pub fn new(db: &ScarbDocDatabase, id: TraitId) -> Maybe { let item_data = ItemData::new( db, id, @@ -522,7 +549,7 @@ impl Trait { .unwrap() .to_string(); - let trait_constants = db.trait_constants(id).unwrap(); + let trait_constants = db.trait_constants(id)?; let trait_constants = trait_constants .iter() .map(|(_name, trait_constant_id)| { @@ -530,7 +557,7 @@ impl Trait { }) .collect::>(); - let trait_types = db.trait_types(id).unwrap(); + let trait_types = db.trait_types(id)?; let trait_types = trait_types .iter() .map(|(_name, trait_type_id)| { @@ -538,21 +565,21 @@ impl Trait { }) .collect::>(); - let trait_functions = db.trait_functions(id).unwrap(); + let trait_functions = db.trait_functions(id)?; let trait_functions = trait_functions .iter() .map(|(_name, trait_function_id)| TraitFunction::new(db, *trait_function_id)) .collect::>(); let node = id.stable_ptr(db); - Self { + Ok(Self { id, node, trait_constants, trait_types, trait_functions, item_data, - } + }) } } @@ -659,7 +686,7 @@ pub struct Impl { } impl Impl { - pub fn new(db: &ScarbDocDatabase, id: ImplDefId) -> Self { + pub fn new(db: &ScarbDocDatabase, id: ImplDefId) -> Maybe { let item_data = ItemData::new( db, id, @@ -671,33 +698,33 @@ impl Impl { .unwrap() .to_string(); - let impl_types = db.impl_types(id).unwrap(); + let impl_types = db.impl_types(id)?; let impl_types = impl_types .iter() .map(|(id, _)| ImplType::new(db, *id, full_path_to_impl.clone())) .collect::>(); - let impl_constants = db.impl_constants(id).unwrap(); + let impl_constants = db.impl_constants(id)?; let impl_constants = impl_constants .iter() .map(|(id, _)| ImplConstant::new(db, *id, full_path_to_impl.clone())) .collect::>(); - let impl_functions = db.impl_functions(id).unwrap(); + let impl_functions = db.impl_functions(id)?; let impl_functions = impl_functions .iter() .map(|(_name, id)| ImplFunction::new(db, *id)) .collect::>(); let node = id.stable_ptr(db); - Self { + Ok(Self { id, node, impl_types, impl_constants, impl_functions, item_data, - } + }) } } From 97e61a28eb26be2432916718f2142329a8346fac Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Wed, 11 Sep 2024 14:24:28 +0200 Subject: [PATCH 03/20] Support all compilation tests errors and handle them correcly / tests added --- Cargo.lock | 149 +++---------- Cargo.toml | 48 ++--- extensions/scarb-doc/Cargo.toml | 1 + extensions/scarb-doc/src/db.rs | 209 ++++++++++--------- extensions/scarb-doc/src/lib.rs | 88 +++++--- extensions/scarb-doc/src/main.rs | 2 - extensions/scarb-doc/src/types.rs | 6 +- extensions/scarb-doc/tests/code/code_1.cairo | 1 - extensions/scarb-doc/tests/code/code_4.cairo | 1 - extensions/scarb-doc/tests/diagnostics.rs | 95 +++++++++ scarb/src/compiler/compilers/test.rs | 12 +- 11 files changed, 328 insertions(+), 284 deletions(-) create mode 100644 extensions/scarb-doc/tests/diagnostics.rs diff --git a/Cargo.lock b/Cargo.lock index 234b540e2..861ba9b50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,8 +567,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-utils", "indoc", @@ -580,8 +579,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-defs", @@ -605,16 +603,14 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -629,8 +625,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -640,8 +635,7 @@ dependencies = [ [[package]] name = "cairo-lang-doc" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-defs", "cairo-lang-formatter", @@ -654,8 +648,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-utils", "good_lp", @@ -663,8 +656,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -677,8 +669,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -697,8 +688,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -733,8 +723,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -797,8 +786,7 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -816,8 +804,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -834,8 +821,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "quote", @@ -844,8 +830,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -857,8 +842,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "ark-ff", "ark-secp256k1", @@ -887,8 +871,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -912,8 +895,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-utils", @@ -938,8 +920,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -953,8 +934,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -968,8 +948,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -991,8 +970,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -1011,8 +989,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -1020,8 +997,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1049,8 +1025,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -1071,8 +1046,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1086,8 +1060,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "genco", "xshell", @@ -1095,8 +1068,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1121,8 +1093,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1143,8 +1114,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -1155,19 +1125,15 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.0" -source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" +version = "2.8.2" dependencies = [ - "env_logger", "hashbrown 0.14.5", "indexmap 2.2.6", "itertools 0.12.1", - "log", "num-bigint", "num-traits 0.2.19", "schemars", "serde", - "time", ] [[package]] @@ -1763,29 +1729,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -3041,12 +2984,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c3b1f728c459d27b12448862017b96ad4767b1ec2ec5e6434e99f1577f085b8" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.30" @@ -3790,15 +3727,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - [[package]] name = "number_prefix" version = "0.4.0" @@ -4706,6 +4634,7 @@ dependencies = [ "cairo-lang-diagnostics", "cairo-lang-doc", "cairo-lang-filesystem", + "cairo-lang-lowering", "cairo-lang-parser", "cairo-lang-semantic", "cairo-lang-starknet", @@ -5544,14 +5473,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", - "itoa", - "libc", "num-conv", - "num_threads", "powerfmt", "serde", "time-core", - "time-macros", ] [[package]] @@ -5560,16 +5485,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" -[[package]] -name = "time-macros" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" -dependencies = [ - "num-conv", - "time-core", -] - [[package]] name = "tiny-keccak" version = "2.0.2" diff --git a/Cargo.toml b/Cargo.toml index 4aee61a3c..a6fb541e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,30 +35,30 @@ anyhow = "1" assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } -cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d", features = ["env_logger"] } +cairo-lang-casm = { path = "../cairo/crates/cairo-lang-casm" } +cairo-lang-compiler = { path = "../cairo/crates/cairo-lang-compiler" } +cairo-lang-debug = { path = "../cairo/crates/cairo-lang-debug" } +cairo-lang-defs = { path = "../cairo/crates/cairo-lang-defs" } +cairo-lang-diagnostics = { path = "../cairo/crates/cairo-lang-diagnostics" } +cairo-lang-doc = { path = "../cairo/crates/cairo-lang-doc" } +cairo-lang-filesystem = { path = "../cairo/crates/cairo-lang-filesystem" } +cairo-lang-formatter = { path = "../cairo/crates/cairo-lang-formatter" } +cairo-lang-language-server = { path = "../cairo/crates/cairo-lang-language-server" } +cairo-lang-lowering = { path = "../cairo/crates/cairo-lang-lowering" } +cairo-lang-parser = { path = "../cairo/crates/cairo-lang-parser" } +cairo-lang-project = { path = "../cairo/crates/cairo-lang-project" } +cairo-lang-runner = { path = "../cairo/crates/cairo-lang-runner" } +cairo-lang-semantic = { path = "../cairo/crates/cairo-lang-semantic" } +cairo-lang-sierra = { path = "../cairo/crates/cairo-lang-sierra" } +cairo-lang-sierra-generator = { path = "../cairo/crates/cairo-lang-sierra-generator" } +cairo-lang-sierra-to-casm = { path = "../cairo/crates/cairo-lang-sierra-to-casm" } +cairo-lang-sierra-type-size = { path = "../cairo/crates/cairo-lang-sierra-type-size" } +cairo-lang-starknet = { path = "../cairo/crates/cairo-lang-starknet" } +cairo-lang-starknet-classes = { path = "../cairo/crates/cairo-lang-starknet-classes" } +cairo-lang-syntax = { path = "../cairo/crates/cairo-lang-syntax" } +cairo-lang-test-plugin = { path = "../cairo/crates/cairo-lang-test-plugin" } +cairo-lang-test-runner = { path = "../cairo/crates/cairo-lang-test-runner" } +cairo-lang-utils = { path = "../cairo/crates/cairo-lang-utils" } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/extensions/scarb-doc/Cargo.toml b/extensions/scarb-doc/Cargo.toml index bad2b7cd7..75117f8c0 100644 --- a/extensions/scarb-doc/Cargo.toml +++ b/extensions/scarb-doc/Cargo.toml @@ -21,6 +21,7 @@ cairo-lang-semantic.workspace = true cairo-lang-starknet.workspace = true cairo-lang-syntax.workspace = true cairo-lang-utils.workspace = true +cairo-lang-lowering.workspace = true cairo-lang-diagnostics.workspace = true expect-test.workspace = true indoc.workspace = true diff --git a/extensions/scarb-doc/src/db.rs b/extensions/scarb-doc/src/db.rs index a6b89c529..e7984fa40 100644 --- a/extensions/scarb-doc/src/db.rs +++ b/extensions/scarb-doc/src/db.rs @@ -1,17 +1,14 @@ -use anyhow::Result; -use cairo_lang_compiler::db::RootDatabase; -use cairo_lang_compiler::diagnostics::DiagnosticsReporter; use cairo_lang_compiler::project::{ update_crate_root, update_crate_roots_from_project_config, ProjectConfig, }; use cairo_lang_defs::db::{ext_as_virtual_impl, DefsDatabase, DefsGroup}; -use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Severity}; use cairo_lang_doc::db::{DocDatabase, DocGroup}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{ init_files_group, AsFilesGroupMut, ExternalFiles, FilesDatabase, FilesGroup, CORELIB_CRATE_NAME, }; -use cairo_lang_filesystem::ids::VirtualFile; +use cairo_lang_filesystem::ids::{CrateId, CrateLongId, VirtualFile}; +use cairo_lang_lowering::db::{LoweringDatabase, LoweringGroup}; use cairo_lang_parser::db::{ParserDatabase, ParserGroup}; use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup}; use cairo_lang_semantic::inline_macros::get_default_plugin_suite; @@ -23,125 +20,129 @@ use cairo_lang_utils::Upcast; use salsa; /// The Cairo compiler Salsa database tailored for scarb-doc usage. -// #[salsa::database( -// FilesDatabase, -// ParserDatabase, -// SyntaxDatabase, -// DefsDatabase, -// SemanticDatabase, -// DocDatabase -// )] +#[salsa::database( + FilesDatabase, + ParserDatabase, + SyntaxDatabase, + DefsDatabase, + SemanticDatabase, + DocDatabase, + LoweringDatabase +)] pub struct ScarbDocDatabase { - // storage: salsa::Storage, - pub db: RootDatabase, + storage: salsa::Storage, + main_package_name: String, } impl ScarbDocDatabase { - pub fn new(project_config: Option) -> Result { - let mut db_builder = RootDatabase::builder(); - if let Some(config) = project_config { - db_builder.with_project_config(config); - } - db_builder.with_cfg(Self::initial_cfg_set()); - + pub fn new(project_config: Option, main_package_name: String) -> Self { let plugin_suite = [get_default_plugin_suite(), starknet_plugin_suite()] .into_iter() .fold(PluginSuite::default(), |mut acc, suite| { acc.add(suite); acc }); - db_builder.with_plugin_suite(plugin_suite); - let db = db_builder.build()?; - // let mut db = Self { - // storage: Default::default(), - // }; + let mut db = Self { + storage: Default::default(), + main_package_name, + }; - // init_files_group(&mut db); - // let diag = ScarbDocDatabase::setup_diagnostics(); + init_files_group(&mut db); - // db.set_cfg_set(Self::initial_cfg_set().into()); + db.set_cfg_set(Self::initial_cfg_set().into()); - // db.apply_plugin_suite(plugin_suite); + db.apply_plugin_suite(plugin_suite); - // if let Some(config) = project_config { - // db.apply_project_config(config); - // } + if let Some(config) = project_config { + db.apply_project_config(config); + } - Ok(Self { db }) + db + } + + pub fn get_main_crate_id(&self) -> CrateId { + self.intern_crate(CrateLongId::Real(self.main_package_name.clone().into())) } fn initial_cfg_set() -> CfgSet { CfgSet::from_iter([Cfg::name("doc")]) } - // fn apply_plugin_suite(&mut self, plugin_suite: PluginSuite) { - // self.set_macro_plugins(plugin_suite.plugins); - // self.set_inline_macro_plugins(plugin_suite.inline_macro_plugins.into()); - // self.set_analyzer_plugins(plugin_suite.analyzer_plugins); - // } - - // fn apply_project_config(&mut self, config: ProjectConfig) { - // update_crate_roots_from_project_config(self, &config); - // if let Some(corelib) = &config.corelib { - // update_crate_root(self, &config, CORELIB_CRATE_NAME.into(), corelib.clone()); - // } - // } + fn apply_plugin_suite(&mut self, plugin_suite: PluginSuite) { + self.set_macro_plugins(plugin_suite.plugins); + self.set_inline_macro_plugins(plugin_suite.inline_macro_plugins.into()); + self.set_analyzer_plugins(plugin_suite.analyzer_plugins); + } + + fn apply_project_config(&mut self, config: ProjectConfig) { + update_crate_roots_from_project_config(self, &config); + if let Some(corelib) = &config.corelib { + update_crate_root(self, &config, CORELIB_CRATE_NAME.into(), corelib.clone()); + } + } +} + +impl salsa::Database for ScarbDocDatabase {} + +impl ExternalFiles for ScarbDocDatabase { + fn ext_as_virtual(&self, external_id: salsa::InternId) -> VirtualFile { + ext_as_virtual_impl(self.upcast(), external_id) + } +} + +impl salsa::ParallelDatabase for ScarbDocDatabase { + fn snapshot(&self) -> salsa::Snapshot { + salsa::Snapshot::new(ScarbDocDatabase { + storage: self.storage.snapshot(), + main_package_name: self.main_package_name.clone(), + }) + } +} + +impl AsFilesGroupMut for ScarbDocDatabase { + fn as_files_group_mut(&mut self) -> &mut (dyn FilesGroup + 'static) { + self + } } -// impl salsa::Database for ScarbDocDatabase {} - -// impl ExternalFiles for ScarbDocDatabase { -// fn ext_as_virtual(&self, external_id: salsa::InternId) -> VirtualFile { -// ext_as_virtual_impl(self.upcast(), external_id) -// } -// } - -// impl salsa::ParallelDatabase for ScarbDocDatabase { -// fn snapshot(&self) -> salsa::Snapshot { -// salsa::Snapshot::new(ScarbDocDatabase { -// storage: self.storage.snapshot(), -// }) -// } -// } - -// impl AsFilesGroupMut for ScarbDocDatabase { -// fn as_files_group_mut(&mut self) -> &mut (dyn FilesGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn FilesGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn ParserGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn SyntaxGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn DefsGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn SemanticGroup + 'static) { -// self -// } -// } - -// impl Upcast for ScarbDocDatabase { -// fn upcast(&self) -> &(dyn DocGroup + 'static) { -// self -// } -// } +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn FilesGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn ParserGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn SyntaxGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn DefsGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn SemanticGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn DocGroup + 'static) { + self + } +} + +impl Upcast for ScarbDocDatabase { + fn upcast(&self) -> &(dyn LoweringGroup + 'static) { + self + } +} diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index 3636ce2b8..c60e76b9f 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -1,12 +1,11 @@ use anyhow::Result; use cairo_lang_compiler::diagnostics::DiagnosticsReporter; -use cairo_lang_compiler::project::ProjectConfig; use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Maybe, Severity}; use cairo_lang_filesystem::db::{Edition, FilesGroup}; -use cairo_lang_filesystem::ids::CrateLongId; -use cairo_lang_utils::Upcast; use errors::DiagnosticError; -use scarb_metadata::{Metadata, PackageMetadata}; +use itertools::Itertools; +use scarb_metadata::{CompilationUnitMetadata, Metadata, PackageMetadata}; +use scarb_ui::{OutputFormat, Ui}; use serde::Serialize; use crate::db::ScarbDocDatabase; @@ -55,12 +54,19 @@ pub fn generate_packages_information( let project_config = get_project_config(metadata, package_metadata)?; - let crate_ = generate_language_elements_tree_for_package( - package_metadata.name.clone(), - project_config, - should_document_private_items, - ) - .map_err(|_| DiagnosticError(package_metadata.name.clone()))?; + let db = ScarbDocDatabase::new(Some(project_config), package_metadata.name.clone()); + + let package_compilation_unit = metadata + .compilation_units + .iter() + .find(|unit| unit.package == package_metadata.id); + + let mut diagnostics_reporter = setup_diagnostics_reporter(&db, package_compilation_unit); + diagnostics_reporter.ensure(&db)?; + + let crate_ = + generate_language_elements_tree_for_package(&db, should_document_private_items) + .map_err(|_| DiagnosticError(package_metadata.name.clone()))?; packages_information.push(PackageInformation { crate_, @@ -74,24 +80,28 @@ pub fn generate_packages_information( } fn generate_language_elements_tree_for_package( - package_name: String, - project_config: ProjectConfig, + db: &ScarbDocDatabase, document_private_items: bool, ) -> Maybe { - let db = ScarbDocDatabase::new(Some(project_config))?; - - let main_crate_id = db.db.intern_crate(CrateLongId::Real(package_name.into())); - - let mut diagnostics_reporter = setup_diagnostics_reporter(); - - diagnostics_reporter.ensure(&db.db); + let main_crate_id = db.get_main_crate_id(); Crate::new(&db, main_crate_id, document_private_items) } -fn setup_diagnostics_reporter() -> DiagnosticsReporter { - DiagnosticsReporter::callback({ - |entry: FormattedDiagnosticEntry| { +fn setup_diagnostics_reporter<'a>( + db: &ScarbDocDatabase, + package_compilation_unit: Option<&CompilationUnitMetadata>, +) -> DiagnosticsReporter<'a> { + let ui = Ui::new(scarb_ui::Verbosity::default(), OutputFormat::default()); + let main_crate_id = db.get_main_crate_id(); + let ignore_warnings_crates = db + .crates() + .into_iter() + .filter(|crate_id| crate_id != &main_crate_id) + .collect_vec(); + + let diagnostics_reporter = DiagnosticsReporter::callback({ + move |entry: FormattedDiagnosticEntry| { let msg = entry .message() .strip_suffix('\n') @@ -99,24 +109,42 @@ fn setup_diagnostics_reporter() -> DiagnosticsReporter { match entry.severity() { Severity::Error => { if let Some(code) = entry.error_code() { - // config.ui().error_with_code(code.as_str(), msg) - eprintln!("{} {}", code.as_str(), msg); + ui.error_with_code(code.as_str(), msg); } else { - eprintln!("{}", msg); + ui.error(msg) } } Severity::Warning => { if let Some(code) = entry.error_code() { - // config.ui().warn_with_code(code.as_str(), msg) - eprintln!("{} {}", code.as_str(), msg); + ui.warn_with_code(code.as_str(), msg) } else { - // config.ui().warn(msg) - eprintln!("{}", msg); + ui.warn(msg) } } }; } - }); + }) + .with_ignore_warnings_crates(&ignore_warnings_crates); + + // We check whether the warnings are allowed during compilation. + match package_compilation_unit { + Some(package_compilation_unit) => { + if allows_warnings(package_compilation_unit) { + return diagnostics_reporter.allow_warnings(); + } + diagnostics_reporter + } + None => diagnostics_reporter, + } +} + +fn allows_warnings(compulation_unit: &CompilationUnitMetadata) -> bool { + compulation_unit + .compiler_config + .as_object() + .and_then(|config| config.get("allow_warnings")) + .and_then(|value| value.as_bool()) + .unwrap_or(true) } pub fn edition_from_string(edition_str: &str) -> Result { diff --git a/extensions/scarb-doc/src/main.rs b/extensions/scarb-doc/src/main.rs index 4fe10438b..1dbc99803 100644 --- a/extensions/scarb-doc/src/main.rs +++ b/extensions/scarb-doc/src/main.rs @@ -63,8 +63,6 @@ fn main_inner() -> Result<()> { args.document_private_items, ); - println!("{:?}", &packages_information_result.is_err()); - let packages_information = packages_information_result?; match args.output_format { diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 0c873a786..7eab0fb1e 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -3,9 +3,9 @@ use std::sync::Arc; -use anyhow::{bail, Error, Result}; +use anyhow::Result; use cairo_lang_diagnostics::{DiagnosticAdded, Maybe}; -use cairo_lang_semantic::items::{constant, impl_alias, visibility}; +use cairo_lang_semantic::items::visibility; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use cairo_lang_utils::Upcast; use itertools::Itertools; @@ -24,7 +24,7 @@ use cairo_lang_doc::db::DocGroup; use cairo_lang_doc::documentable_item::DocumentableItemId; use cairo_lang_filesystem::ids::CrateId; use cairo_lang_semantic::db::SemanticGroup; -use cairo_lang_syntax::node::ast::{self, ItemConstant}; +use cairo_lang_syntax::node::ast::{self}; use crate::db::ScarbDocDatabase; diff --git a/extensions/scarb-doc/tests/code/code_1.cairo b/extensions/scarb-doc/tests/code/code_1.cairo index 4f5be0931..3bdb85533 100644 --- a/extensions/scarb-doc/tests/code/code_1.cairo +++ b/extensions/scarb-doc/tests/code/code_1.cairo @@ -81,7 +81,6 @@ mod tests { use super::fib as fib_function; /// Really - #[test] /// works. fn it_works() { assert(fib_function(16) == 987, 'it works!'); diff --git a/extensions/scarb-doc/tests/code/code_4.cairo b/extensions/scarb-doc/tests/code/code_4.cairo index cd9f09e73..b436b7651 100644 --- a/extensions/scarb-doc/tests/code/code_4.cairo +++ b/extensions/scarb-doc/tests/code/code_4.cairo @@ -92,7 +92,6 @@ mod tests { use super::fib as fib_function; /// Really - #[test] /// works. fn it_works() { assert(fib_function(16) == 987, 'it works!'); diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs new file mode 100644 index 000000000..b2ec47021 --- /dev/null +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -0,0 +1,95 @@ +use assert_fs::TempDir; +use indoc::indoc; +use scarb_test_support::{command::Scarb, project_builder::ProjectBuilder}; + +#[test] +fn test_diagnostics_success() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello_world") + .lib_cairo(indoc! {r#" + fn main() { + println!("Hello world!"); + } + "#}) + .build(&t); + + Scarb::quick_snapbox() + .arg("doc") + .current_dir(&t) + .assert() + .success(); +} + +#[test] +fn test_diagnostics_error() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello_world") + .lib_cairo(indoc! {r#" + fn main() { + println!("Hello world!"); + wrong code + } + "#}) + .build(&t); + + Scarb::quick_snapbox() + .arg("doc") + .current_dir(&t) + .assert() + .failure() + .stdout_matches(indoc! {r#" + error: Identifier not found. + [..] + wrong code + ^***^ + + error: Missing semicolon + [..] + wrong code + ^ + + error: Identifier not found. + [..] + wrong code + ^**^ + + error: Compilation failed. + "#}); +} + +#[test] +fn test_diagnostics_not_allowed_warnings() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello_world") + .lib_cairo(indoc! {r#" + fn main() { + println!("Hello world!"); + let a = 5; + } + "#}) + .manifest_extra(indoc! {r#" + [cairo] + allow-warnings = false + "#}) + .build(&t); + + Scarb::quick_snapbox() + .arg("doc") + .current_dir(&t) + .assert() + .failure() + .stdout_matches(indoc! {r#" + warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + [..] + let a = 5; + ^ + + error: Compilation failed. + "#}); +} diff --git a/scarb/src/compiler/compilers/test.rs b/scarb/src/compiler/compilers/test.rs index a517a6104..96bb145c9 100644 --- a/scarb/src/compiler/compilers/test.rs +++ b/scarb/src/compiler/compilers/test.rs @@ -39,6 +39,9 @@ impl Compiler for TestCompiler { .with_crates(&main_crate_ids) .ensure(db)?; + let diagnostics_reporter = + build_compiler_config(db, &unit, &main_crate_ids, ws).diagnostics_reporter; + let test_compilation = { let _ = trace_span!("compile_test").enter(); let config = TestsCompilationConfig { @@ -50,8 +53,13 @@ impl Compiler for TestCompiler { .compiler_config .unstable_add_statements_code_locations_debug_info, }; - let allow_warnings = unit.compiler_config.allow_warnings; - compile_test_prepared_db(db, config, main_crate_ids, test_crate_ids, allow_warnings)? + compile_test_prepared_db( + db, + config, + main_crate_ids, + test_crate_ids, + diagnostics_reporter, + )? }; { From ac3826f70a2d8518a64142a81ca7d4e916d1b47a Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Wed, 11 Sep 2024 16:27:57 +0200 Subject: [PATCH 04/20] Get rid of all unhandled errors --- .../scarb-doc/src/docs_generation/markdown.rs | 69 ++++++----- .../src/docs_generation/markdown/summary.rs | 38 +++--- .../src/docs_generation/markdown/traits.rs | 108 +++++++++--------- extensions/scarb-doc/src/lib.rs | 2 +- extensions/scarb-doc/src/main.rs | 4 +- .../scarb-doc/src/metadata/compilation.rs | 35 +++--- extensions/scarb-doc/src/types.rs | 22 ++-- .../scarb-doc/src/versioned_json_output.rs | 5 +- 8 files changed, 141 insertions(+), 142 deletions(-) diff --git a/extensions/scarb-doc/src/docs_generation/markdown.rs b/extensions/scarb-doc/src/docs_generation/markdown.rs index c5d64740a..cbc558833 100644 --- a/extensions/scarb-doc/src/docs_generation/markdown.rs +++ b/extensions/scarb-doc/src/docs_generation/markdown.rs @@ -1,6 +1,6 @@ use anyhow::Result; use camino::Utf8Path; -use itertools::{chain, Itertools}; +use itertools::chain; use std::fs; use crate::docs_generation::markdown::book_toml::generate_book_toml_content; @@ -34,10 +34,10 @@ pub struct MarkdownContent { } impl MarkdownContent { - pub fn from_crate(package_information: &PackageInformation) -> Self { + pub fn from_crate(package_information: &PackageInformation) -> Result { let top_level_items = collect_all_top_level_items(&package_information.crate_); - let summary_file_content = generate_summary_file_content(&top_level_items); + let summary_file_content = generate_summary_file_content(&top_level_items)?; let TopLevelItems { modules, constants, @@ -53,75 +53,78 @@ impl MarkdownContent { } = top_level_items; let docs_for_top_level_items = chain!( - generate_top_level_docs_contents(&modules), - generate_top_level_docs_contents(&constants), - generate_top_level_docs_contents(&free_functions), - generate_top_level_docs_contents(&structs), - generate_top_level_docs_contents(&enums), - generate_top_level_docs_contents(&type_aliases), - generate_top_level_docs_contents(&impl_aliases), - generate_top_level_docs_contents(&traits), - generate_top_level_docs_contents(&impls), - generate_top_level_docs_contents(&extern_types), - generate_top_level_docs_contents(&extern_functions), + generate_top_level_docs_contents(&modules)?, + generate_top_level_docs_contents(&constants)?, + generate_top_level_docs_contents(&free_functions)?, + generate_top_level_docs_contents(&structs)?, + generate_top_level_docs_contents(&enums)?, + generate_top_level_docs_contents(&type_aliases)?, + generate_top_level_docs_contents(&impl_aliases)?, + generate_top_level_docs_contents(&traits)?, + generate_top_level_docs_contents(&impls)?, + generate_top_level_docs_contents(&extern_types)?, + generate_top_level_docs_contents(&extern_functions)?, ) - .collect_vec(); + .collect::>(); let summaries_for_top_level_items = vec![ ( Module::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&modules, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&modules, BASE_HEADER_LEVEL)?, ), ( Constant::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&constants, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&constants, BASE_HEADER_LEVEL)?, ), ( FreeFunction::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&free_functions, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&free_functions, BASE_HEADER_LEVEL)?, ), ( Struct::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&structs, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&structs, BASE_HEADER_LEVEL)?, ), ( Enum::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&enums, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&enums, BASE_HEADER_LEVEL)?, ), ( TypeAlias::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&type_aliases, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&type_aliases, BASE_HEADER_LEVEL)?, ), ( ImplAlias::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&impl_aliases, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&impl_aliases, BASE_HEADER_LEVEL)?, ), ( Trait::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&traits, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&traits, BASE_HEADER_LEVEL)?, ), ( Impl::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&impls, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&impls, BASE_HEADER_LEVEL)?, ), ( ExternType::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&extern_types, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems(&extern_types, BASE_HEADER_LEVEL)?, ), ( ExternFunction::ITEMS_SUMMARY_FILENAME.to_string(), - generate_markdown_list_for_top_level_subitems(&extern_functions, BASE_HEADER_LEVEL), + generate_markdown_list_for_top_level_subitems( + &extern_functions, + BASE_HEADER_LEVEL, + )?, ), ] .into_iter() .filter(|(_filename, content)| !content.is_empty()) - .collect_vec(); + .collect::>(); - Self { + Ok(Self { book_toml: generate_book_toml_content(&package_information.metadata), summary: summary_file_content, doc_files: chain!(docs_for_top_level_items, summaries_for_top_level_items).collect(), - } + }) } pub fn save(self, output_dir: &Utf8Path) -> Result<()> { @@ -146,9 +149,13 @@ impl MarkdownContent { fn generate_top_level_docs_contents( items: &[&impl TopLevelMarkdownDocItem], -) -> Vec<(Filename, String)> { +) -> Result> { items .iter() - .map(|item| (item.filename(), item.generate_markdown(BASE_HEADER_LEVEL))) + .map(|item| { + let filename = item.filename(); + item.generate_markdown(BASE_HEADER_LEVEL) + .map(|markdown| (filename, markdown)) + }) .collect() } diff --git a/extensions/scarb-doc/src/docs_generation/markdown/summary.rs b/extensions/scarb-doc/src/docs_generation/markdown/summary.rs index b1fa35a87..d34cc08a2 100644 --- a/extensions/scarb-doc/src/docs_generation/markdown/summary.rs +++ b/extensions/scarb-doc/src/docs_generation/markdown/summary.rs @@ -1,10 +1,11 @@ +use anyhow::Result; use std::fmt::Write; use crate::docs_generation::markdown::traits::TopLevelMarkdownDocItem; use crate::docs_generation::markdown::BASE_HEADER_LEVEL; use crate::docs_generation::TopLevelItems; -pub fn generate_summary_file_content(top_level_items: &TopLevelItems) -> String { +pub fn generate_summary_file_content(top_level_items: &TopLevelItems) -> Result { let header = str::repeat("#", BASE_HEADER_LEVEL); let mut markdown = format!("{header} Summary\n\n"); @@ -23,24 +24,24 @@ pub fn generate_summary_file_content(top_level_items: &TopLevelItems) -> String extern_functions, } = top_level_items; - markdown += &generate_markdown_list_summary_for_top_level_subitems(modules); - markdown += &generate_markdown_list_summary_for_top_level_subitems(constants); - markdown += &generate_markdown_list_summary_for_top_level_subitems(free_functions); - markdown += &generate_markdown_list_summary_for_top_level_subitems(structs); - markdown += &generate_markdown_list_summary_for_top_level_subitems(enums); - markdown += &generate_markdown_list_summary_for_top_level_subitems(type_aliases); - markdown += &generate_markdown_list_summary_for_top_level_subitems(impl_aliases); - markdown += &generate_markdown_list_summary_for_top_level_subitems(traits); - markdown += &generate_markdown_list_summary_for_top_level_subitems(impls); - markdown += &generate_markdown_list_summary_for_top_level_subitems(extern_types); - markdown += &generate_markdown_list_summary_for_top_level_subitems(extern_functions); - - markdown + markdown += &generate_markdown_list_summary_for_top_level_subitems(modules)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(constants)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(free_functions)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(structs)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(enums)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(type_aliases)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(impl_aliases)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(traits)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(impls)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(extern_types)?; + markdown += &generate_markdown_list_summary_for_top_level_subitems(extern_functions)?; + + Ok(markdown) } fn generate_markdown_list_summary_for_top_level_subitems( subitems: &[&T], -) -> String { +) -> Result { let mut markdown = String::new(); if !subitems.is_empty() { @@ -49,12 +50,11 @@ fn generate_markdown_list_summary_for_top_level_subitems String; + fn generate_markdown(&self, header_level: usize) -> Result; } impl MarkdownDocItem for T where T: PrimitiveDocItem, { - fn generate_markdown(&self, header_level: usize) -> String { + fn generate_markdown(&self, header_level: usize) -> Result { generate_markdown_from_item_data(self, header_level) } } impl MarkdownDocItem for Enum { - fn generate_markdown(&self, header_level: usize) -> String { - let mut markdown = generate_markdown_from_item_data(self, header_level); + fn generate_markdown(&self, header_level: usize) -> Result { + let mut markdown = generate_markdown_from_item_data(self, header_level)?; - markdown += &generate_markdown_for_subitems(&self.variants, header_level); + markdown += &generate_markdown_for_subitems(&self.variants, header_level)?; - markdown + Ok(markdown) } } impl MarkdownDocItem for Impl { - fn generate_markdown(&self, header_level: usize) -> String { - let mut markdown = generate_markdown_from_item_data(self, header_level); + fn generate_markdown(&self, header_level: usize) -> Result { + let mut markdown = generate_markdown_from_item_data(self, header_level)?; - markdown += &generate_markdown_for_subitems(&self.impl_constants, header_level); - markdown += &generate_markdown_for_subitems(&self.impl_functions, header_level); - markdown += &generate_markdown_for_subitems(&self.impl_types, header_level); + markdown += &generate_markdown_for_subitems(&self.impl_constants, header_level)?; + markdown += &generate_markdown_for_subitems(&self.impl_functions, header_level)?; + markdown += &generate_markdown_for_subitems(&self.impl_types, header_level)?; - markdown + Ok(markdown) } } impl MarkdownDocItem for Module { - fn generate_markdown(&self, header_level: usize) -> String { - let mut markdown = generate_markdown_from_item_data(self, header_level); + fn generate_markdown(&self, header_level: usize) -> Result { + let mut markdown = generate_markdown_from_item_data(self, header_level)?; markdown += &generate_markdown_list_for_top_level_subitems( &self.submodules.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.constants.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.free_functions.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.structs.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.enums.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.type_aliases.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.impl_aliases.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.traits.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.impls.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.extern_types.iter().collect_vec(), header_level + 1, - ); + )?; markdown += &generate_markdown_list_for_top_level_subitems( &self.extern_functions.iter().collect_vec(), header_level + 1, - ); + )?; - markdown + Ok(markdown) } } impl MarkdownDocItem for Struct { - fn generate_markdown(&self, header_level: usize) -> String { - let mut markdown = generate_markdown_from_item_data(self, header_level); + fn generate_markdown(&self, header_level: usize) -> Result { + let mut markdown = generate_markdown_from_item_data(self, header_level)?; - markdown += &generate_markdown_for_subitems(&self.members, header_level); + markdown += &generate_markdown_for_subitems(&self.members, header_level)?; - markdown + Ok(markdown) } } impl MarkdownDocItem for Trait { - fn generate_markdown(&self, header_level: usize) -> String { - let mut markdown = generate_markdown_from_item_data(self, header_level); + fn generate_markdown(&self, header_level: usize) -> Result { + let mut markdown = generate_markdown_from_item_data(self, header_level)?; - markdown += &generate_markdown_for_subitems(&self.trait_constants, header_level); - markdown += &generate_markdown_for_subitems(&self.trait_functions, header_level); - markdown += &generate_markdown_for_subitems(&self.trait_types, header_level); + markdown += &generate_markdown_for_subitems(&self.trait_constants, header_level)?; + markdown += &generate_markdown_for_subitems(&self.trait_functions, header_level)?; + markdown += &generate_markdown_for_subitems(&self.trait_types, header_level)?; - markdown + Ok(markdown) } } pub fn generate_markdown_list_for_top_level_subitems( subitems: &[&T], header_level: usize, -) -> String { +) -> Result { let mut markdown = String::new(); if !subitems.is_empty() { let header = str::repeat("#", header_level); - writeln!(&mut markdown, "{header} {}\n", T::HEADER).unwrap(); + writeln!(&mut markdown, "{header} {}\n", T::HEADER)?; for item in subitems { - writeln!(&mut markdown, "{}", item.generate_markdown_list_item()).unwrap(); + writeln!(&mut markdown, "{}", item.generate_markdown_list_item())?; } } - markdown + Ok(markdown) } fn generate_markdown_for_subitems( subitems: &[T], header_level: usize, -) -> String { +) -> Result { let mut markdown = String::new(); if !subitems.is_empty() { let header = str::repeat("#", header_level + 1); - writeln!(&mut markdown, "{header} {}\n", T::HEADER).unwrap(); + writeln!(&mut markdown, "{header} {}\n", T::HEADER)?; for item in subitems { writeln!( &mut markdown, "{}", - item.generate_markdown(header_level + 2) - ) - .unwrap(); + item.generate_markdown(header_level + 2)? + )?; } } - markdown + Ok(markdown) } -fn generate_markdown_from_item_data(doc_item: &impl DocItem, header_level: usize) -> String { +fn generate_markdown_from_item_data( + doc_item: &impl DocItem, + header_level: usize, +) -> Result { let mut markdown = String::new(); let header = str::repeat("#", header_level); - writeln!(&mut markdown, "{header} {}\n", doc_item.name()).unwrap(); + writeln!(&mut markdown, "{header} {}\n", doc_item.name())?; if let Some(doc) = doc_item.doc() { - writeln!(&mut markdown, "{doc}\n").unwrap(); + writeln!(&mut markdown, "{doc}\n")?; } writeln!( &mut markdown, "Fully qualified path: `{}`\n", doc_item.full_path() - ) - .unwrap(); + )?; if let Some(sig) = &doc_item.signature() { if !sig.is_empty() { // TODO(#1457) add cairo support to mdbook - writeln!(&mut markdown, "```rust\n{sig}\n```\n").unwrap(); + writeln!(&mut markdown, "```rust\n{sig}\n```\n")?; } } - markdown + Ok(markdown) } diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index c60e76b9f..931c3b209 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -85,7 +85,7 @@ fn generate_language_elements_tree_for_package( ) -> Maybe { let main_crate_id = db.get_main_crate_id(); - Crate::new(&db, main_crate_id, document_private_items) + Crate::new(db, main_crate_id, document_private_items) } fn setup_diagnostics_reporter<'a>( diff --git a/extensions/scarb-doc/src/main.rs b/extensions/scarb-doc/src/main.rs index 1dbc99803..2efa32df9 100644 --- a/extensions/scarb-doc/src/main.rs +++ b/extensions/scarb-doc/src/main.rs @@ -53,7 +53,7 @@ fn main_inner() -> Result<()> { .inherit_stderr() .envs(args.features.to_env_vars()) .exec() - .map_err(|e| MetadataCommandError::from(e))?; + .map_err(MetadataCommandError::from)?; let metadata_for_packages = args.packages_filter.match_many(&metadata)?; let output_dir = get_target_dir(&metadata).join(OUTPUT_DIR); @@ -73,7 +73,7 @@ fn main_inner() -> Result<()> { for pkg_information in packages_information { let pkg_output_dir = output_dir.join(&pkg_information.metadata.name); - MarkdownContent::from_crate(&pkg_information) + MarkdownContent::from_crate(&pkg_information)? .save(&pkg_output_dir) .with_context(|| { format!( diff --git a/extensions/scarb-doc/src/metadata/compilation.rs b/extensions/scarb-doc/src/metadata/compilation.rs index b32ae20c9..cfc6c1777 100644 --- a/extensions/scarb-doc/src/metadata/compilation.rs +++ b/extensions/scarb-doc/src/metadata/compilation.rs @@ -91,7 +91,7 @@ fn get_crates_config( metadata: &Metadata, compilation_unit_metadata: &CompilationUnitMetadata, ) -> Result { - let crates_config: Result> = compilation_unit_metadata + let crates_config: OrderedHashMap = compilation_unit_metadata .components .iter() .map(|component| { @@ -105,7 +105,7 @@ fn get_crates_config( match (pkg, cfg_result) { (Some(pkg), Ok(cfg_set)) => Ok(( SmolStr::from(&component.name), - get_crate_settings_for_package(pkg, cfg_set), + get_crate_settings_for_package(pkg, cfg_set)?, )), (None, _) => { bail!(MissingPackageError(component.package.to_string())) @@ -113,32 +113,25 @@ fn get_crates_config( (_, Err(e)) => bail!(e), } }) - .collect(); + .collect::>>()?; - if let Err(error) = crates_config { - return Err(error); - } - - match crates_config { - Ok(crates_config) => Ok(AllCratesConfig { - override_map: crates_config, - ..Default::default() - }), - Err(error) => Err(error), - } + Ok(AllCratesConfig { + override_map: crates_config, + ..Default::default() + }) } fn get_crate_settings_for_package( package: &PackageMetadata, cfg_set: Option, -) -> CrateSettings { +) -> Result { let edition = package .edition .clone() - .map_or(Edition::default(), |edition| { + .map_or(Ok(Edition::default()), |edition| { let edition_value = serde_json::Value::String(edition); - serde_json::from_value(edition_value).unwrap() - }); + serde_json::from_value(edition_value) + })?; let experimental_features = ExperimentalFeaturesConfig { negative_impls: package @@ -149,12 +142,12 @@ fn get_crate_settings_for_package( .contains(&String::from("coupons")), }; - CrateSettings { + Ok(CrateSettings { edition, cfg_set, experimental_features, version: Some(package.version.clone()), - } + }) } fn build_cfg_set(cfg: &[scarb_metadata::Cfg]) -> Result { @@ -162,7 +155,7 @@ fn build_cfg_set(cfg: &[scarb_metadata::Cfg]) -> Result { .map(|cfg| { serde_json::to_value(cfg) .and_then(serde_json::from_value::) - .map_err(|e| CfgParseError::from(e)) + .map_err(CfgParseError::from) }) .collect::>() } diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 7eab0fb1e..de7094b58 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -201,13 +201,13 @@ impl Module { /// G - A closure (as a function), which generates an item based on the item's ID. /// J - Type representing an item ast type. /// K - Type of generated item. -fn filter_map_item_id_to_item( +fn filter_map_item_id_to_item( items: Arc>, should_include_item_function: F, generate_item_function: G, ) -> Result, DiagnosticAdded> where - T: Copy + TopLevelLanguageElementId, + T: Copy + TopLevelLanguageElementId + ?Sized, F: Fn(&dyn TopLevelLanguageElementId) -> Result, G: Fn(T) -> Maybe, { @@ -543,11 +543,10 @@ impl Trait { id, LookupItemId::ModuleItem(ModuleItemId::Trait(id)).into(), ); - let full_path_to_trait = item_data - .full_path - .strip_suffix(item_data.name.as_str()) - .unwrap() - .to_string(); + let full_path_to_trait = match item_data.full_path.strip_suffix(item_data.name.as_str()) { + Some(full_path) => full_path.to_string(), + None => return Err(DiagnosticAdded), + }; let trait_constants = db.trait_constants(id)?; let trait_constants = trait_constants @@ -692,11 +691,10 @@ impl Impl { id, LookupItemId::ModuleItem(ModuleItemId::Impl(id)).into(), ); - let full_path_to_impl = item_data - .full_path - .strip_suffix(item_data.name.as_str()) - .unwrap() - .to_string(); + let full_path_to_impl = match item_data.full_path.strip_suffix(item_data.name.as_str()) { + Some(full_path) => full_path.to_string(), + None => return Err(DiagnosticAdded), + }; let impl_types = db.impl_types(id)?; let impl_types = impl_types diff --git a/extensions/scarb-doc/src/versioned_json_output.rs b/extensions/scarb-doc/src/versioned_json_output.rs index f6569600c..55a1f63eb 100644 --- a/extensions/scarb-doc/src/versioned_json_output.rs +++ b/extensions/scarb-doc/src/versioned_json_output.rs @@ -30,9 +30,8 @@ impl VersionedJsonOutput { let output_path = output_dir.join(JSON_OUTPUT_FILENAME); - let output = serde_json::to_string_pretty(&self) - .map_err(|e| PackagesSerializationError::from(e))? - + "\n"; + let output = + serde_json::to_string_pretty(&self).map_err(PackagesSerializationError::from)? + "\n"; fs::write(output_path, output).map_err(|e| IOWriteError::new(e, "json documentation"))?; From b709a5e79c20a39b5ce7b34c72d023b29f49c95a Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Wed, 11 Sep 2024 16:29:47 +0200 Subject: [PATCH 05/20] Change dependencies to old ones --- Cargo.lock | 148 ++++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 48 ++++++++--------- 2 files changed, 141 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 861ba9b50..fd7b88df2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,7 +567,8 @@ dependencies = [ [[package]] name = "cairo-lang-casm" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-utils", "indoc", @@ -579,7 +580,8 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-defs", @@ -603,14 +605,16 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -625,7 +629,8 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -635,7 +640,8 @@ dependencies = [ [[package]] name = "cairo-lang-doc" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-defs", "cairo-lang-formatter", @@ -648,7 +654,8 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-utils", "good_lp", @@ -656,7 +663,8 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -669,7 +677,8 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -688,7 +697,8 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -723,7 +733,8 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -786,7 +797,8 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -804,7 +816,8 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -821,7 +834,8 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "quote", @@ -830,7 +844,8 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -842,7 +857,8 @@ dependencies = [ [[package]] name = "cairo-lang-runner" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "ark-ff", "ark-secp256k1", @@ -871,7 +887,8 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -895,7 +912,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-utils", @@ -920,7 +938,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -934,7 +953,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -948,7 +968,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -970,7 +991,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -989,7 +1011,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -997,7 +1020,8 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1025,7 +1049,8 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -1046,7 +1071,8 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1060,7 +1086,8 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "genco", "xshell", @@ -1068,7 +1095,8 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1093,7 +1121,8 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1114,7 +1143,8 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -1125,15 +1155,19 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.2" +version = "2.8.0" +source = "git+https://github.com/starkware-libs/cairo?rev=c8407b2b6aa5bf61a6788228127c7735e4af6a4d#c8407b2b6aa5bf61a6788228127c7735e4af6a4d" dependencies = [ + "env_logger", "hashbrown 0.14.5", "indexmap 2.2.6", "itertools 0.12.1", + "log", "num-bigint", "num-traits 0.2.19", "schemars", "serde", + "time", ] [[package]] @@ -1729,6 +1763,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -2984,6 +3041,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c3b1f728c459d27b12448862017b96ad4767b1ec2ec5e6434e99f1577f085b8" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.30" @@ -3727,6 +3790,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -5473,10 +5545,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", + "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", + "time-macros", ] [[package]] @@ -5485,6 +5561,16 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" diff --git a/Cargo.toml b/Cargo.toml index a6fb541e5..4aee61a3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,30 +35,30 @@ anyhow = "1" assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } -cairo-lang-casm = { path = "../cairo/crates/cairo-lang-casm" } -cairo-lang-compiler = { path = "../cairo/crates/cairo-lang-compiler" } -cairo-lang-debug = { path = "../cairo/crates/cairo-lang-debug" } -cairo-lang-defs = { path = "../cairo/crates/cairo-lang-defs" } -cairo-lang-diagnostics = { path = "../cairo/crates/cairo-lang-diagnostics" } -cairo-lang-doc = { path = "../cairo/crates/cairo-lang-doc" } -cairo-lang-filesystem = { path = "../cairo/crates/cairo-lang-filesystem" } -cairo-lang-formatter = { path = "../cairo/crates/cairo-lang-formatter" } -cairo-lang-language-server = { path = "../cairo/crates/cairo-lang-language-server" } -cairo-lang-lowering = { path = "../cairo/crates/cairo-lang-lowering" } -cairo-lang-parser = { path = "../cairo/crates/cairo-lang-parser" } -cairo-lang-project = { path = "../cairo/crates/cairo-lang-project" } -cairo-lang-runner = { path = "../cairo/crates/cairo-lang-runner" } -cairo-lang-semantic = { path = "../cairo/crates/cairo-lang-semantic" } -cairo-lang-sierra = { path = "../cairo/crates/cairo-lang-sierra" } -cairo-lang-sierra-generator = { path = "../cairo/crates/cairo-lang-sierra-generator" } -cairo-lang-sierra-to-casm = { path = "../cairo/crates/cairo-lang-sierra-to-casm" } -cairo-lang-sierra-type-size = { path = "../cairo/crates/cairo-lang-sierra-type-size" } -cairo-lang-starknet = { path = "../cairo/crates/cairo-lang-starknet" } -cairo-lang-starknet-classes = { path = "../cairo/crates/cairo-lang-starknet-classes" } -cairo-lang-syntax = { path = "../cairo/crates/cairo-lang-syntax" } -cairo-lang-test-plugin = { path = "../cairo/crates/cairo-lang-test-plugin" } -cairo-lang-test-runner = { path = "../cairo/crates/cairo-lang-test-runner" } -cairo-lang-utils = { path = "../cairo/crates/cairo-lang-utils" } +cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "c8407b2b6aa5bf61a6788228127c7735e4af6a4d", features = ["env_logger"] } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } From 8a55a052ea0308a8f2798f161dedde2555775083 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Thu, 12 Sep 2024 15:33:04 +0200 Subject: [PATCH 06/20] Upgrade Cairo / add test for allowed warnings --- Cargo.lock | 62 +++++++++---------- Cargo.toml | 48 +++++++------- extensions/scarb-doc/src/types.rs | 2 + .../src/hello_world-tests-it_works.md | 2 +- .../src/hello_world-tests-it_works.md | 2 +- .../tests/data/json_output_test_data.json | 2 +- extensions/scarb-doc/tests/diagnostics.rs | 32 ++++++++++ 7 files changed, 92 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef410dbb2..458f90910 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-utils", "indoc", @@ -581,7 +581,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-defs", @@ -606,7 +606,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-utils", ] @@ -614,7 +614,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -630,7 +630,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -641,7 +641,7 @@ dependencies = [ [[package]] name = "cairo-lang-doc" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-defs", "cairo-lang-filesystem", @@ -656,7 +656,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-utils", "good_lp", @@ -665,7 +665,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -679,7 +679,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -699,7 +699,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -735,7 +735,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -799,7 +799,7 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -818,7 +818,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -836,7 +836,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "quote", @@ -846,7 +846,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -859,7 +859,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "ark-ff", "ark-secp256k1", @@ -889,7 +889,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -914,7 +914,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-utils", @@ -940,7 +940,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -955,7 +955,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -970,7 +970,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -993,7 +993,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -1013,7 +1013,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -1022,7 +1022,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1051,7 +1051,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -1073,7 +1073,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1088,7 +1088,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "genco", "xshell", @@ -1097,7 +1097,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1123,7 +1123,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1145,7 +1145,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -1157,7 +1157,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=1eb938a901d448a44e868b9e930a828d16db9d97#1eb938a901d448a44e868b9e930a828d16db9d97" +source = "git+https://github.com/starkware-libs/cairo?rev=c52b49dead2dea12905541ae122baa120178c189#c52b49dead2dea12905541ae122baa120178c189" dependencies = [ "env_logger", "hashbrown 0.14.5", diff --git a/Cargo.toml b/Cargo.toml index 1555e1b16..0e3c4f958 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,30 +35,30 @@ anyhow = "1" assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } -cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "1eb938a901d448a44e868b9e930a828d16db9d97", features = ["env_logger"] } +cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "c52b49dead2dea12905541ae122baa120178c189", features = ["env_logger"] } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 73aa79891..754cb4788 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use anyhow::Result; use cairo_lang_diagnostics::{DiagnosticAdded, Maybe}; use cairo_lang_semantic::items::visibility; diff --git a/extensions/scarb-doc/tests/data/hello_world_no_features/src/hello_world-tests-it_works.md b/extensions/scarb-doc/tests/data/hello_world_no_features/src/hello_world-tests-it_works.md index 71afcebe5..875cbcb4e 100644 --- a/extensions/scarb-doc/tests/data/hello_world_no_features/src/hello_world-tests-it_works.md +++ b/extensions/scarb-doc/tests/data/hello_world_no_features/src/hello_world-tests-it_works.md @@ -1,6 +1,6 @@ # it_works -Really +Really works. Fully qualified path: `hello_world::tests::it_works` diff --git a/extensions/scarb-doc/tests/data/hello_world_with_features/src/hello_world-tests-it_works.md b/extensions/scarb-doc/tests/data/hello_world_with_features/src/hello_world-tests-it_works.md index 71afcebe5..875cbcb4e 100644 --- a/extensions/scarb-doc/tests/data/hello_world_with_features/src/hello_world-tests-it_works.md +++ b/extensions/scarb-doc/tests/data/hello_world_with_features/src/hello_world-tests-it_works.md @@ -1,6 +1,6 @@ # it_works -Really +Really works. Fully qualified path: `hello_world::tests::it_works` diff --git a/extensions/scarb-doc/tests/data/json_output_test_data.json b/extensions/scarb-doc/tests/data/json_output_test_data.json index 8a3237db1..2450236c7 100644 --- a/extensions/scarb-doc/tests/data/json_output_test_data.json +++ b/extensions/scarb-doc/tests/data/json_output_test_data.json @@ -24,7 +24,7 @@ { "item_data": { "name": "it_works", - "doc": "Really", + "doc": "Really works.", "signature": "fn it_works()", "full_path": "hello_world::tests::it_works" } diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index b2ec47021..369b46ab9 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -61,6 +61,38 @@ fn test_diagnostics_error() { "#}); } +#[test] +fn test_diagnostics_allowed_warnings() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello_world") + .lib_cairo(indoc! {r#" + fn main() { + println!("Hello world!"); + let a = 5; + } + "#}) + .manifest_extra(indoc! {r#" + [cairo] + allow-warnings = true + "#}) + .build(&t); + + Scarb::quick_snapbox() + .arg("doc") + .current_dir(&t) + .assert() + .success() + .stdout_matches(indoc! {r#" + warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + [..] + let a = 5; + ^ + + "#}); +} + #[test] fn test_diagnostics_not_allowed_warnings() { let t = TempDir::new().unwrap(); From f614f0166120494fe4fc93fb34c4d624bd702a59 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Thu, 12 Sep 2024 15:35:05 +0200 Subject: [PATCH 07/20] cleanup --- extensions/scarb-doc/src/types.rs | 2 +- scarb/src/compiler/compilers/test.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/extensions/scarb-doc/src/types.rs b/extensions/scarb-doc/src/types.rs index 754cb4788..08254ac01 100644 --- a/extensions/scarb-doc/src/types.rs +++ b/extensions/scarb-doc/src/types.rs @@ -204,7 +204,7 @@ fn filter_map_item_id_to_item( generate_item_function: G, ) -> Result, DiagnosticAdded> where - T: Copy + TopLevelLanguageElementId + ?Sized, + T: Copy + TopLevelLanguageElementId, F: Fn(&dyn TopLevelLanguageElementId) -> Result, G: Fn(T) -> Maybe, { diff --git a/scarb/src/compiler/compilers/test.rs b/scarb/src/compiler/compilers/test.rs index e69a8e7ee..5a930c441 100644 --- a/scarb/src/compiler/compilers/test.rs +++ b/scarb/src/compiler/compilers/test.rs @@ -37,11 +37,6 @@ impl Compiler for TestCompiler { diagnostics_reporter.ensure(db)?; - let mut diagnostics_reporter = - build_compiler_config(db, &unit, &test_crate_ids, ws).diagnostics_reporter; - - diagnostics_reporter.ensure(db)?; - let test_compilation = { let _ = trace_span!("compile_test").enter(); let config = TestsCompilationConfig { From a2c009677f38ce318e29430f0dae5662248c3f98 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Fri, 13 Sep 2024 12:14:16 +0200 Subject: [PATCH 08/20] Fix tests windows --- extensions/scarb-doc/tests/diagnostics.rs | 48 ++++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 369b46ab9..0cc1b38ba 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -36,12 +36,35 @@ fn test_diagnostics_error() { "#}) .build(&t); - Scarb::quick_snapbox() + let snapbox = Scarb::quick_snapbox() .arg("doc") .current_dir(&t) .assert() - .failure() - .stdout_matches(indoc! {r#" + .failure(); + + #[cfg(windows)] + snapbox.stdout_matches(indoc! {r#" + error: Identifier not found. + [..] + wrong code + ^***^ + + error: Missing semicolon + [..] + wrong code + ^ + + error: Identifier not found. + [..] + wrong code + ^**^ + + error: Compilation failed. + error: process did not exit successfully: exit code: 1 + "#}); + + #[cfg(not(windows))] + snapbox.stdout_matches(indoc! {r#" error: Identifier not found. [..] wrong code @@ -111,12 +134,25 @@ fn test_diagnostics_not_allowed_warnings() { "#}) .build(&t); - Scarb::quick_snapbox() + let snapbox = Scarb::quick_snapbox() .arg("doc") .current_dir(&t) .assert() - .failure() - .stdout_matches(indoc! {r#" + .failure(); + + #[cfg(windows)] + snapbox.stdout_matches(indoc! {r#" + warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + [..] + let a = 5; + ^ + + error: Compilation failed. + error: process did not exit successfully: exit code: 1 + "#}); + + #[cfg(not(windows))] + snapbox.stdout_matches(indoc! {r#" warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. [..] let a = 5; From ea00bc2daccc2c1b48e89fc2859c085a42b1e253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Tr=C4=85tnowiecki?= Date: Tue, 1 Oct 2024 23:58:50 +0200 Subject: [PATCH 09/20] Update Cairo --- Cargo.lock | 63 ++++++++++--------- Cargo.toml | 48 +++++++------- extensions/scarb-doc/src/lib.rs | 9 ++- .../scarb-snforge-test-collector/Cargo.toml | 1 + .../src/compilation.rs | 1 + .../src/compilation/test_collector.rs | 9 ++- .../src/crate_collection.rs | 5 ++ .../scarb-snforge-test-collector/src/main.rs | 1 + .../compilers/starknet_contract/compiler.rs | 13 +++- scarb/src/compiler/compilers/test.rs | 14 ++++- scarb/src/compiler/db.rs | 8 ++- scarb/src/compiler/helpers.rs | 9 ++- scarb/src/ops/expand.rs | 9 ++- 13 files changed, 119 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 235f9782d..b588c575c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-utils", "indoc", @@ -581,7 +581,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-defs", @@ -606,7 +606,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-utils", ] @@ -614,7 +614,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -630,7 +630,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -641,7 +641,7 @@ dependencies = [ [[package]] name = "cairo-lang-doc" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-defs", "cairo-lang-filesystem", @@ -656,7 +656,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-utils", "good_lp", @@ -665,7 +665,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -680,7 +680,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -700,7 +700,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -736,7 +736,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -800,7 +800,7 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -819,7 +819,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -837,7 +837,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "quote", @@ -847,7 +847,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -860,7 +860,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "ark-ff", "ark-secp256k1", @@ -890,7 +890,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -915,7 +915,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-utils", @@ -941,7 +941,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -956,7 +956,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -971,7 +971,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -994,7 +994,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -1023,7 +1023,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1052,7 +1052,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -1074,7 +1074,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1089,7 +1089,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "genco", "xshell", @@ -1098,7 +1098,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1124,7 +1124,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1146,7 +1146,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -1158,7 +1158,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=e4136a412b03aff3ba1dec3eb8d8d22356cd67ae#e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" +source = "git+https://github.com/starkware-libs/cairo?rev=227cea949132c062088d067b9f6b7ea4be9e4d16#227cea949132c062088d067b9f6b7ea4be9e4d16" dependencies = [ "env_logger", "hashbrown 0.14.5", @@ -4789,6 +4789,7 @@ dependencies = [ "scarb-metadata 1.12.0", "scarb-test-support", "scarb-ui", + "semver", "serde", "serde_json", "smol_str", diff --git a/Cargo.toml b/Cargo.toml index 630de62ef..9c37623d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,30 +35,30 @@ anyhow = "1" assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } -cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "e4136a412b03aff3ba1dec3eb8d8d22356cd67ae", features = ["env_logger"] } +cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "227cea949132c062088d067b9f6b7ea4be9e4d16", features = ["env_logger"] } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index fa14dc9ec..8340d30be 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -49,7 +49,7 @@ pub fn generate_packages_information( let project_config = get_project_config(metadata, package_metadata); let crate_ = generate_language_elements_tree_for_package( - package_metadata.name.clone(), + package_metadata, project_config, should_document_private_items, ); @@ -66,13 +66,16 @@ pub fn generate_packages_information( } fn generate_language_elements_tree_for_package( - package_name: String, + package: &PackageMetadata, project_config: ProjectConfig, document_private_items: bool, ) -> Crate { let db = ScarbDocDatabase::new(Some(project_config)); - let main_crate_id = db.intern_crate(CrateLongId::Real(package_name.into())); + let main_crate_id = db.intern_crate(CrateLongId::Real { + name: package.name.clone().into(), + version: Some(package.version.clone()), + }); Crate::new(&db, main_crate_id, document_private_items) } diff --git a/extensions/scarb-snforge-test-collector/Cargo.toml b/extensions/scarb-snforge-test-collector/Cargo.toml index e67101277..a2b160a79 100644 --- a/extensions/scarb-snforge-test-collector/Cargo.toml +++ b/extensions/scarb-snforge-test-collector/Cargo.toml @@ -33,6 +33,7 @@ num-traits.workspace = true rayon.workspace = true scarb-metadata = { path = "../../scarb-metadata" } scarb-ui = { path = "../../utils/scarb-ui" } +semver.workspace = true serde.workspace = true serde_json.workspace = true smol_str.workspace = true diff --git a/extensions/scarb-snforge-test-collector/src/compilation.rs b/extensions/scarb-snforge-test-collector/src/compilation.rs index 92b0e7bf8..636ae09ad 100644 --- a/extensions/scarb-snforge-test-collector/src/compilation.rs +++ b/extensions/scarb-snforge-test-collector/src/compilation.rs @@ -30,6 +30,7 @@ impl TestCompilationTarget { fn compile_tests(&self, compilation_unit: &CompilationUnit) -> Result { let (program_artifact, test_cases) = collect_tests( &self.crate_name, + self.crate_version.clone(), self.crate_root.as_std_path(), &self.lib_content, compilation_unit, diff --git a/extensions/scarb-snforge-test-collector/src/compilation/test_collector.rs b/extensions/scarb-snforge-test-collector/src/compilation/test_collector.rs index 0863c1465..e80634345 100644 --- a/extensions/scarb-snforge-test-collector/src/compilation/test_collector.rs +++ b/extensions/scarb-snforge-test-collector/src/compilation/test_collector.rs @@ -26,6 +26,7 @@ use cairo_lang_sierra_generator::replace_ids::replace_sierra_ids_in_program; use cairo_lang_starknet::starknet_plugin_suite; use cairo_lang_test_plugin::test_plugin_suite; use itertools::Itertools; +use semver::Version; use serde::Serialize; use smol_str::SmolStr; use std::path::Path; @@ -88,6 +89,7 @@ pub struct TestDetails { pub fn collect_tests( crate_name: &str, + crate_version: Version, crate_root: &Path, lib_content: &str, compilation_unit: &CompilationUnit, @@ -119,6 +121,7 @@ pub fn collect_tests( let main_crate_id = insert_lib_entrypoint_content_into_db( db, crate_name, + crate_version, crate_root, lib_content, main_package_crate_settings, @@ -258,11 +261,15 @@ fn build_diagnostics_reporter(compilation_unit: &CompilationUnit) -> Diagnostics fn insert_lib_entrypoint_content_into_db( db: &mut RootDatabase, crate_name: &str, + crate_version: Version, crate_root: &Path, lib_content: &str, main_package_crate_settings: CrateSettings, ) -> CrateId { - let main_crate_id = db.intern_crate(CrateLongId::Real(SmolStr::from(crate_name))); + let main_crate_id = db.intern_crate(CrateLongId::Real { + name: SmolStr::from(crate_name), + version: Some(crate_version), + }); db.set_crate_config( main_crate_id, Some(CrateConfiguration { diff --git a/extensions/scarb-snforge-test-collector/src/crate_collection.rs b/extensions/scarb-snforge-test-collector/src/crate_collection.rs index 998da8985..0cf4db7a6 100644 --- a/extensions/scarb-snforge-test-collector/src/crate_collection.rs +++ b/extensions/scarb-snforge-test-collector/src/crate_collection.rs @@ -1,6 +1,7 @@ use crate::metadata::CompilationUnit; use anyhow::{anyhow, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; +use semver::Version; use serde::Serialize; use walkdir::WalkDir; @@ -16,12 +17,14 @@ pub enum CrateLocation { pub struct TestCompilationTarget { pub crate_root: Utf8PathBuf, pub crate_name: String, + pub crate_version: Version, pub crate_location: CrateLocation, pub lib_content: String, } pub fn collect_test_compilation_targets( package_name: &str, + package_version: Version, package_path: &Utf8Path, compilation_unit: &CompilationUnit, ) -> Result> { @@ -29,6 +32,7 @@ pub fn collect_test_compilation_targets( let mut compilation_targets = vec![TestCompilationTarget { crate_root: compilation_unit.main_package_source_root(), crate_name: package_name.to_string(), + crate_version: package_version.clone(), crate_location: CrateLocation::Lib, lib_content: std::fs::read_to_string(package_source_file_path) .with_context(|| format!("failed to read = {package_source_file_path}"))?, @@ -38,6 +42,7 @@ pub fn collect_test_compilation_targets( if tests_dir_path.exists() { compilation_targets.push(TestCompilationTarget { crate_name: "tests".to_string(), + crate_version: package_version, crate_location: CrateLocation::Tests, lib_content: get_or_create_test_lib_content(tests_dir_path.as_path())?, crate_root: tests_dir_path, diff --git a/extensions/scarb-snforge-test-collector/src/main.rs b/extensions/scarb-snforge-test-collector/src/main.rs index 3e9f04e30..c9e19f346 100644 --- a/extensions/scarb-snforge-test-collector/src/main.rs +++ b/extensions/scarb-snforge-test-collector/src/main.rs @@ -44,6 +44,7 @@ fn main() -> Result<()> { let compilation_targets = collect_test_compilation_targets( &package_metadata.name, + package_metadata.version.clone(), &package_metadata.root, &compilation_unit, )?; diff --git a/scarb/src/compiler/compilers/starknet_contract/compiler.rs b/scarb/src/compiler/compilers/starknet_contract/compiler.rs index 915085beb..de75ab178 100644 --- a/scarb/src/compiler/compilers/starknet_contract/compiler.rs +++ b/scarb/src/compiler/compilers/starknet_contract/compiler.rs @@ -105,6 +105,7 @@ impl Compiler for StarknetContractCompiler { main_crate_ids, props.build_external_contracts.clone(), compiler_config, + &unit, db, ws, )?; @@ -150,12 +151,14 @@ pub fn get_compiled_contracts( main_crate_ids: Vec, build_external_contracts: Option>, compiler_config: CompilerConfig<'_>, + unit: &CairoCompilationUnit, db: &mut RootDatabase, ws: &Workspace<'_>, ) -> Result { let contracts = find_project_contracts( db.upcast_mut(), ws.config().ui(), + unit, main_crate_ids, build_external_contracts, )?; @@ -180,6 +183,7 @@ pub fn get_compiled_contracts( fn find_project_contracts( mut db: &dyn SemanticGroup, ui: Ui, + unit: &CairoCompilationUnit, main_crate_ids: Vec, external_contracts: Option>, ) -> Result> { @@ -197,9 +201,14 @@ fn find_project_contracts( .iter() .map(|selector| selector.package().into()) .unique() - .map(|package_name: SmolStr| { + .map(|name: SmolStr| { + let version = unit + .components() + .iter() + .find(|component| component.package.id.name.to_smol_str() == name) + .map(|component| component.package.id.version.clone()); db.upcast_mut() - .intern_crate(CrateLongId::Real(package_name)) + .intern_crate(CrateLongId::Real { name, version }) }) .collect::>(); let contracts = find_contracts(db, crate_ids.as_ref()); diff --git a/scarb/src/compiler/compilers/test.rs b/scarb/src/compiler/compilers/test.rs index 6772f8a83..30c5a5e98 100644 --- a/scarb/src/compiler/compilers/test.rs +++ b/scarb/src/compiler/compilers/test.rs @@ -38,7 +38,7 @@ impl Compiler for TestCompiler { let test_crate_ids = collect_main_crate_ids(&unit, db); // Search for all contracts in deps specified with `build-external-contracts`. let all_crate_ids = - get_contract_crate_ids(&build_external_contracts, test_crate_ids.clone(), db); + get_contract_crate_ids(&build_external_contracts, test_crate_ids.clone(), &unit, db); let starknet = unit.cairo_plugins.iter().any(|plugin| { plugin.package.id.name == PackageName::STARKNET @@ -125,6 +125,7 @@ fn compile_contracts( main_crate_ids, props.build_external_contracts.clone(), compiler_config, + &unit, db, ws, )?; @@ -147,6 +148,7 @@ fn external_contracts_selectors( fn get_contract_crate_ids( build_external_contracts: &Option>, test_crate_ids: Vec, + unit: &CairoCompilationUnit, db: &mut RootDatabase, ) -> Vec { let mut all_crate_ids = build_external_contracts @@ -157,7 +159,15 @@ fn get_contract_crate_ids( .map(|selector| selector.package()) .sorted() .unique() - .map(|package_name| db.intern_crate(CrateLongId::Real(package_name.to_smolstr()))) + .map(|package_name| { + let version = unit + .components() + .iter() + .find(|component| component.package.id.name == package_name) + .map(|component| component.package.id.version.clone()); + let name = package_name.to_smolstr(); + db.intern_crate(CrateLongId::Real { name, version }) + }) .collect_vec() }) .unwrap_or_default(); diff --git a/scarb/src/compiler/db.rs b/scarb/src/compiler/db.rs index 2adbabfc6..196ee109a 100644 --- a/scarb/src/compiler/db.rs +++ b/scarb/src/compiler/db.rs @@ -89,8 +89,12 @@ fn inject_virtual_wrapper_lib(db: &mut RootDatabase, unit: &CairoCompilationUnit .collect(); for component in components { - let crate_name = component.cairo_package_name(); - let crate_id = db.intern_crate(CrateLongId::Real(crate_name)); + let name = component.cairo_package_name(); + let version = component.package.id.version.clone(); + let crate_id = db.intern_crate(CrateLongId::Real { + name, + version: Some(version), + }); let file_stems = component .targets .iter() diff --git a/scarb/src/compiler/helpers.rs b/scarb/src/compiler/helpers.rs index c4b072596..e6b1ea82e 100644 --- a/scarb/src/compiler/helpers.rs +++ b/scarb/src/compiler/helpers.rs @@ -90,9 +90,12 @@ impl From for InliningStrategy { } pub fn collect_main_crate_ids(unit: &CairoCompilationUnit, db: &RootDatabase) -> Vec { - vec![db.intern_crate(CrateLongId::Real( - unit.main_component().cairo_package_name(), - ))] + let name = unit.main_component().cairo_package_name(); + let version = unit.main_component().package.id.version.clone(); + vec![db.intern_crate(CrateLongId::Real { + name, + version: Some(version), + })] } pub fn write_json( diff --git a/scarb/src/ops/expand.rs b/scarb/src/ops/expand.rs index 76861250a..e8d2c287f 100644 --- a/scarb/src/ops/expand.rs +++ b/scarb/src/ops/expand.rs @@ -160,9 +160,12 @@ fn do_expand( ws: &Workspace<'_>, ) -> Result<()> { let ScarbDatabase { db, .. } = build_scarb_root_database(compilation_unit, ws)?; - let main_crate_id = db.intern_crate(CrateLongId::Real( - compilation_unit.main_component().cairo_package_name(), - )); + let name = compilation_unit.main_component().cairo_package_name(); + let version = compilation_unit.main_component().package.id.version.clone(); + let main_crate_id = db.intern_crate(CrateLongId::Real { + name, + version: Some(version), + }); let mut compiler_config = build_compiler_config(&db, compilation_unit, &[main_crate_id], ws); // Report diagnostics, but do not fail. let _ = compiler_config.diagnostics_reporter.check(&db); From da36090a05574dce8b6e0cdfe2d4075b50d10d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Tr=C4=85tnowiecki?= Date: Wed, 2 Oct 2024 01:21:01 +0200 Subject: [PATCH 10/20] Fix dep version for corelib --- extensions/scarb-doc/src/metadata/compilation.rs | 6 ++++-- extensions/scarb-snforge-test-collector/src/metadata.rs | 8 +++++--- scarb/src/compiler/db.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/extensions/scarb-doc/src/metadata/compilation.rs b/extensions/scarb-doc/src/metadata/compilation.rs index 74570dc45..fbcbf5b71 100644 --- a/extensions/scarb-doc/src/metadata/compilation.rs +++ b/extensions/scarb-doc/src/metadata/compilation.rs @@ -152,7 +152,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name == *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -162,7 +164,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/extensions/scarb-snforge-test-collector/src/metadata.rs b/extensions/scarb-snforge-test-collector/src/metadata.rs index 292274e5b..9d0131b89 100644 --- a/extensions/scarb-snforge-test-collector/src/metadata.rs +++ b/extensions/scarb-snforge-test-collector/src/metadata.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, ensure, Context, Result}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{ - CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, + CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, CORELIB_CRATE_NAME, }; use cairo_lang_project::AllCratesConfig; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -249,7 +249,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name == *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -259,7 +261,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/scarb/src/compiler/db.rs b/scarb/src/compiler/db.rs index 196ee109a..cf9384529 100644 --- a/scarb/src/compiler/db.rs +++ b/scarb/src/compiler/db.rs @@ -6,6 +6,7 @@ use cairo_lang_defs::ids::ModuleId; use cairo_lang_defs::plugin::MacroPlugin; use cairo_lang_filesystem::db::{ AsFilesGroupMut, CrateSettings, DependencySettings, FilesGroup, FilesGroupEx, + CORELIB_CRATE_NAME, }; use cairo_lang_filesystem::ids::{CrateLongId, Directory}; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -174,7 +175,9 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { ( compilation_unit_component.package.id.name.to_string(), DependencySettings { - version: Some(compilation_unit_component.package.id.version.clone()), + version: (compilation_unit_component.package.id.name.to_string() + != *CORELIB_CRATE_NAME) + .then_some(compilation_unit_component.package.id.version.clone()), }, ) }) @@ -184,7 +187,8 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { dependencies.insert( component.package.id.name.to_string(), DependencySettings { - version: Some(component.package.id.version.clone()), + version: (component.package.id.name.to_string() != *CORELIB_CRATE_NAME) + .then_some(component.package.id.version.clone()), }, ); From 30f4bbd2b30b0fc79af1b99af90a7f508cc2bb9c Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Wed, 2 Oct 2024 13:30:38 +0200 Subject: [PATCH 11/20] Change diagnostics tests as they should not run if the queries run without error --- extensions/scarb-doc/src/lib.rs | 9 ++- extensions/scarb-doc/tests/diagnostics.rs | 81 ++--------------------- 2 files changed, 12 insertions(+), 78 deletions(-) diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index 26391786f..e358f85e7 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -62,14 +62,17 @@ pub fn generate_packages_information( .find(|unit| unit.package == package_metadata.id); let mut diagnostics_reporter = setup_diagnostics_reporter(&db, package_compilation_unit); - diagnostics_reporter.ensure(&db)?; let crate_ = generate_language_elements_tree_for_package(&db, should_document_private_items) - .map_err(|_| DiagnosticError(package_metadata.name.clone()))?; + .map_err(|_| DiagnosticError(package_metadata.name.clone())); + + if crate_.is_err() { + diagnostics_reporter.ensure(&db)?; + } packages_information.push(PackageInformation { - crate_, + crate_: crate_?, metadata: AdditionalMetadata { name: package_metadata.name.clone(), authors, diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 0cc1b38ba..de0fdebe9 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -23,7 +23,7 @@ fn test_diagnostics_success() { } #[test] -fn test_diagnostics_error() { +fn test_diagnostics_with_error_code() { let t = TempDir::new().unwrap(); ProjectBuilder::start() @@ -36,52 +36,11 @@ fn test_diagnostics_error() { "#}) .build(&t); - let snapbox = Scarb::quick_snapbox() + Scarb::quick_snapbox() .arg("doc") .current_dir(&t) .assert() - .failure(); - - #[cfg(windows)] - snapbox.stdout_matches(indoc! {r#" - error: Identifier not found. - [..] - wrong code - ^***^ - - error: Missing semicolon - [..] - wrong code - ^ - - error: Identifier not found. - [..] - wrong code - ^**^ - - error: Compilation failed. - error: process did not exit successfully: exit code: 1 - "#}); - - #[cfg(not(windows))] - snapbox.stdout_matches(indoc! {r#" - error: Identifier not found. - [..] - wrong code - ^***^ - - error: Missing semicolon - [..] - wrong code - ^ - - error: Identifier not found. - [..] - wrong code - ^**^ - - error: Compilation failed. - "#}); + .success(); } #[test] @@ -106,14 +65,7 @@ fn test_diagnostics_allowed_warnings() { .arg("doc") .current_dir(&t) .assert() - .success() - .stdout_matches(indoc! {r#" - warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. - [..] - let a = 5; - ^ - - "#}); + .success(); } #[test] @@ -134,30 +86,9 @@ fn test_diagnostics_not_allowed_warnings() { "#}) .build(&t); - let snapbox = Scarb::quick_snapbox() + Scarb::quick_snapbox() .arg("doc") .current_dir(&t) .assert() - .failure(); - - #[cfg(windows)] - snapbox.stdout_matches(indoc! {r#" - warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. - [..] - let a = 5; - ^ - - error: Compilation failed. - error: process did not exit successfully: exit code: 1 - "#}); - - #[cfg(not(windows))] - snapbox.stdout_matches(indoc! {r#" - warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. - [..] - let a = 5; - ^ - - error: Compilation failed. - "#}); + .success(); } From 0dbfad5b8b4d0e8bd5527df2c5b39dc0d7f1cf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Tr=C4=85tnowiecki?= Date: Wed, 2 Oct 2024 01:21:01 +0200 Subject: [PATCH 12/20] Fix dep version for corelib --- extensions/scarb-doc/src/metadata/compilation.rs | 6 ++++-- extensions/scarb-snforge-test-collector/src/metadata.rs | 8 +++++--- scarb/src/compiler/db.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/extensions/scarb-doc/src/metadata/compilation.rs b/extensions/scarb-doc/src/metadata/compilation.rs index 74570dc45..f8f70c7b7 100644 --- a/extensions/scarb-doc/src/metadata/compilation.rs +++ b/extensions/scarb-doc/src/metadata/compilation.rs @@ -152,7 +152,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name != *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -162,7 +164,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/extensions/scarb-snforge-test-collector/src/metadata.rs b/extensions/scarb-snforge-test-collector/src/metadata.rs index 292274e5b..a574fd3fc 100644 --- a/extensions/scarb-snforge-test-collector/src/metadata.rs +++ b/extensions/scarb-snforge-test-collector/src/metadata.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, ensure, Context, Result}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{ - CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, + CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, CORELIB_CRATE_NAME, }; use cairo_lang_project::AllCratesConfig; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -249,7 +249,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name != *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -259,7 +261,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/scarb/src/compiler/db.rs b/scarb/src/compiler/db.rs index 196ee109a..cf9384529 100644 --- a/scarb/src/compiler/db.rs +++ b/scarb/src/compiler/db.rs @@ -6,6 +6,7 @@ use cairo_lang_defs::ids::ModuleId; use cairo_lang_defs::plugin::MacroPlugin; use cairo_lang_filesystem::db::{ AsFilesGroupMut, CrateSettings, DependencySettings, FilesGroup, FilesGroupEx, + CORELIB_CRATE_NAME, }; use cairo_lang_filesystem::ids::{CrateLongId, Directory}; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -174,7 +175,9 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { ( compilation_unit_component.package.id.name.to_string(), DependencySettings { - version: Some(compilation_unit_component.package.id.version.clone()), + version: (compilation_unit_component.package.id.name.to_string() + != *CORELIB_CRATE_NAME) + .then_some(compilation_unit_component.package.id.version.clone()), }, ) }) @@ -184,7 +187,8 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { dependencies.insert( component.package.id.name.to_string(), DependencySettings { - version: Some(component.package.id.version.clone()), + version: (component.package.id.name.to_string() != *CORELIB_CRATE_NAME) + .then_some(component.package.id.version.clone()), }, ); From b4a5d630f97c9911a8c21dece720353999db2b66 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Fri, 4 Oct 2024 16:00:49 +0200 Subject: [PATCH 13/20] Skip lowering diagnostics / update cairo --- Cargo.lock | 62 ++++++++++++++++----------------- Cargo.toml | 48 ++++++++++++------------- extensions/scarb-doc/src/lib.rs | 3 +- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0958ddb2..5f727c91d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-utils", "indoc", @@ -581,7 +581,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-defs", @@ -606,7 +606,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-utils", ] @@ -614,7 +614,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -630,7 +630,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -641,7 +641,7 @@ dependencies = [ [[package]] name = "cairo-lang-doc" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-defs", "cairo-lang-filesystem", @@ -656,7 +656,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-utils", "good_lp", @@ -665,7 +665,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -680,7 +680,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -700,7 +700,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -736,7 +736,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -800,7 +800,7 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -819,7 +819,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -837,7 +837,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "quote", @@ -847,7 +847,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -860,7 +860,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "ark-ff", "ark-secp256k1", @@ -890,7 +890,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -915,7 +915,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-utils", @@ -941,7 +941,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -956,7 +956,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -971,7 +971,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -994,7 +994,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -1023,7 +1023,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1052,7 +1052,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -1074,7 +1074,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1089,7 +1089,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "genco", "xshell", @@ -1098,7 +1098,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1124,7 +1124,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -1146,7 +1146,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -1158,7 +1158,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.8.2" -source = "git+https://github.com/starkware-libs/cairo?rev=323ea7e281f8bda571e678a0aaa928247b6e618d#323ea7e281f8bda571e678a0aaa928247b6e618d" +source = "git+https://github.com/starkware-libs/cairo?rev=d7813fb076008a9124c78a0c7cb60bae9e17d767#d7813fb076008a9124c78a0c7cb60bae9e17d767" dependencies = [ "env_logger", "hashbrown 0.14.5", diff --git a/Cargo.toml b/Cargo.toml index c86cc47f1..c3987f343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,30 +35,30 @@ anyhow = "1" assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } -cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "323ea7e281f8bda571e678a0aaa928247b6e618d", features = ["env_logger"] } +cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-doc = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "d7813fb076008a9124c78a0c7cb60bae9e17d767", features = ["env_logger"] } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index e358f85e7..0534a4819 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -61,7 +61,8 @@ pub fn generate_packages_information( .iter() .find(|unit| unit.package == package_metadata.id); - let mut diagnostics_reporter = setup_diagnostics_reporter(&db, package_compilation_unit); + let mut diagnostics_reporter = + setup_diagnostics_reporter(&db, package_compilation_unit).skip_lowering_diagnostics(); let crate_ = generate_language_elements_tree_for_package(&db, should_document_private_items) From 02e96d6ab77c8b95676e14c901eb019b74a0b233 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Mon, 14 Oct 2024 11:44:36 +0200 Subject: [PATCH 14/20] Add error test for doc diagnostics --- extensions/scarb-doc/tests/diagnostics.rs | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index de0fdebe9..04d040100 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -92,3 +92,140 @@ fn test_diagnostics_not_allowed_warnings() { .assert() .success(); } + +#[test] +fn test_diagnostics_error() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello_world") + .lib_cairo(indoc! {r#" + #[starknet::contract] + pub(crate) mod DualCaseERC20Mock { + use starknet::ContractAddress; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + + #[storage] + pub struct Storage { + #[substorage(v0)] + pub erc20: ERC20Component::Storage + } + + #[event] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event + } + } + } + "#}) + .build(&t); + + let snapbox = Scarb::quick_snapbox() + .arg("doc") + .current_dir(&t) + .assert() + .failure(); + + #[cfg(windows)] + snapbox.stdout_matches(indoc! {r#" + error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute. + --> [..] + } + ^ + + error: Identifier not found. + --> [..] + ERC20Event: ERC20Component::Event + ^************^ + + error: Identifier not found. + --> [..] + pub erc20: ERC20Component::Storage + ^************^ + + error: Type annotations needed. Failed to infer ?0. + --> [..] + #[storage] + ^********^ + + error: Invalid drop trait implementation, Trait `core::traits::Drop::<>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop` + --> [..] + #[storage] + ^********^ + + error: Trait has no implementation in context: core::starknet::event::Event::. + --> [..] + #[starknet::contract] + ^*******************^ + + error: Identifier not found. + --> [..] + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + ^************^ + + error: Invalid drop trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageDrop:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Compilation failed. + error: process did not exit successfully: exit code: 1 + "#}); + + #[cfg(not(windows))] + snapbox.stdout_matches(indoc! {r#" + error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute. + --> [..] + } + ^ + + error: Identifier not found. + --> [..] + ERC20Event: ERC20Component::Event + ^************^ + + error: Identifier not found. + --> [..] + pub erc20: ERC20Component::Storage + ^************^ + + error: Type annotations needed. Failed to infer ?0. + --> [..] + #[storage] + ^********^ + + error: Invalid drop trait implementation, Trait `core::traits::Drop::<>` has multiple implementations, in: `hello_world::DualCaseERC20Mock::ContractStateDrop`, `hello_world::DualCaseERC20Mock::StorageStorageBaseDrop` + --> [..] + #[storage] + ^********^ + + error: Trait has no implementation in context: core::starknet::event::Event::. + --> [..] + #[starknet::contract] + ^*******************^ + + error: Identifier not found. + --> [..] + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + ^************^ + + error: Invalid drop trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageDrop:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Invalid copy trait implementation, Candidate impl core::starknet::storage::storage_base::FlattenedStorageCopy:: has an unused generic parameter. + --> [..] + #[storage] + ^********^ + + error: Compilation failed. + "#}); +} From 6610a9441a49efdef02a07e9b57bf1f222616e2e Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Mon, 14 Oct 2024 13:46:46 +0200 Subject: [PATCH 15/20] Fix windows tests --- extensions/scarb-doc/tests/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 04d040100..768c1ec20 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -130,7 +130,7 @@ fn test_diagnostics_error() { #[cfg(windows)] snapbox.stdout_matches(indoc! {r#" - error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute. + error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute. --> [..] } ^ From 35c6deea648a42733b882023fd46ed782b58ff66 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalski Date: Mon, 14 Oct 2024 17:04:14 +0200 Subject: [PATCH 16/20] Review related changes --- Cargo.lock | 9 ++++----- extensions/scarb-doc/Cargo.toml | 1 - extensions/scarb-doc/src/db.rs | 10 +--------- extensions/scarb-doc/src/errors.rs | 2 +- extensions/scarb-doc/src/lib.rs | 22 ++++------------------ 5 files changed, 10 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93341bb15..3da2e8ac2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1573,9 +1573,9 @@ checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "deno_task_shell" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1b0c646a53492068b6675af74cecbef486e670be2c0cdd06e7e636d167e50f" +checksum = "4f444918f7102c1a5a143e9d57809e499fb4d365070519bf2e8bdb16d586af2a" dependencies = [ "anyhow", "futures", @@ -3851,9 +3851,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -4757,7 +4757,6 @@ dependencies = [ "scarb-metadata 1.12.0", "scarb-test-support", "scarb-ui", - "semver", "serde", "serde_json", "smol_str", diff --git a/extensions/scarb-doc/Cargo.toml b/extensions/scarb-doc/Cargo.toml index b1f5247ad..75117f8c0 100644 --- a/extensions/scarb-doc/Cargo.toml +++ b/extensions/scarb-doc/Cargo.toml @@ -33,7 +33,6 @@ serde_json.workspace = true salsa.workspace = true smol_str.workspace = true thiserror.workspace = true -semver.workspace = true [dev-dependencies] assert_fs.workspace = true diff --git a/extensions/scarb-doc/src/db.rs b/extensions/scarb-doc/src/db.rs index 4fabf8c90..3adf7143f 100644 --- a/extensions/scarb-doc/src/db.rs +++ b/extensions/scarb-doc/src/db.rs @@ -18,8 +18,6 @@ use cairo_lang_syntax::node::db::{SyntaxDatabase, SyntaxGroup}; use cairo_lang_utils::Upcast; use salsa; -use scarb_metadata::PackageMetadata; -use semver::Version; /// The Cairo compiler Salsa database tailored for scarb-doc usage. #[salsa::database( @@ -33,12 +31,10 @@ use semver::Version; )] pub struct ScarbDocDatabase { storage: salsa::Storage, - main_package_name: String, - main_package_version: Version, } impl ScarbDocDatabase { - pub fn new(project_config: Option, main_package: &PackageMetadata) -> Self { + pub fn new(project_config: Option) -> Self { let plugin_suite = [get_default_plugin_suite(), starknet_plugin_suite()] .into_iter() .fold(PluginSuite::default(), |mut acc, suite| { @@ -47,8 +43,6 @@ impl ScarbDocDatabase { }); let mut db = Self { storage: Default::default(), - main_package_name: main_package.name.clone(), - main_package_version: main_package.version.clone(), }; init_files_group(&mut db); @@ -94,8 +88,6 @@ impl salsa::ParallelDatabase for ScarbDocDatabase { fn snapshot(&self) -> salsa::Snapshot { salsa::Snapshot::new(ScarbDocDatabase { storage: self.storage.snapshot(), - main_package_name: self.main_package_name.clone(), - main_package_version: self.main_package_version.clone(), }) } } diff --git a/extensions/scarb-doc/src/errors.rs b/extensions/scarb-doc/src/errors.rs index 465e77246..a1f9a4933 100644 --- a/extensions/scarb-doc/src/errors.rs +++ b/extensions/scarb-doc/src/errors.rs @@ -14,7 +14,7 @@ pub struct PackagesSerializationError(#[from] SerdeError); pub struct MissingPackageError(pub String); #[derive(Debug, Error)] -#[error("Cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`.")] +#[error("cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`")] pub struct CfgParseError(#[from] SerdeError); #[derive(Debug, Error)] diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index 294a66e91..0c999aa86 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -2,7 +2,7 @@ use crate::db::ScarbDocDatabase; use crate::metadata::compilation::get_project_config; use anyhow::Result; use cairo_lang_compiler::diagnostics::DiagnosticsReporter; -use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Maybe, Severity}; +use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Severity}; use cairo_lang_filesystem::{ db::{Edition, FilesGroup}, ids::{CrateId, CrateLongId}, @@ -57,7 +57,7 @@ pub fn generate_packages_information( let project_config = get_project_config(metadata, package_metadata)?; - let db = ScarbDocDatabase::new(Some(project_config), package_metadata); + let db = ScarbDocDatabase::new(Some(project_config)); let main_crate_id = db.intern_crate(CrateLongId::Real { name: package_metadata.name.clone().into(), @@ -73,12 +73,8 @@ pub fn generate_packages_information( setup_diagnostics_reporter(&db, main_crate_id, package_compilation_unit) .skip_lowering_diagnostics(); - let crate_ = generate_language_elements_tree_for_package( - &db, - main_crate_id, - should_document_private_items, - ) - .map_err(|_| DiagnosticError(package_metadata.name.clone())); + let crate_ = Crate::new(&db, main_crate_id, should_document_private_items) + .map_err(|_| DiagnosticError(package_metadata.name.clone())); if crate_.is_err() { diagnostics_reporter.ensure(&db)?; @@ -95,16 +91,6 @@ pub fn generate_packages_information( Ok(packages_information) } -fn generate_language_elements_tree_for_package( - db: &ScarbDocDatabase, - main_crate_id: CrateId, - document_private_items: bool, -) -> Maybe { - // let main_crate_id = db.get_main_crate_id(); - - Crate::new(db, main_crate_id, document_private_items) -} - fn setup_diagnostics_reporter<'a>( db: &ScarbDocDatabase, main_crate_id: CrateId, From d7462e8bbc526bf02668beb49cc38e8fc549591b Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 14 Oct 2024 18:50:33 +0200 Subject: [PATCH 17/20] Update extensions/scarb-doc/tests/diagnostics.rs Signed-off-by: maciektr --- extensions/scarb-doc/tests/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 768c1ec20..d746faf8c 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -176,7 +176,7 @@ fn test_diagnostics_error() { ^********^ error: Compilation failed. - error: process did not exit successfully: exit code: 1 + error: process did not exit successfully: exit code: 1 "#}); #[cfg(not(windows))] From 5a2ac73a8f9e45bcfc90debc17b66278e15871fe Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 14 Oct 2024 19:58:56 +0200 Subject: [PATCH 18/20] Update extensions/scarb-doc/tests/diagnostics.rs Signed-off-by: maciektr --- extensions/scarb-doc/tests/diagnostics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index d746faf8c..4e9b47499 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -177,6 +177,7 @@ fn test_diagnostics_error() { error: Compilation failed. error: process did not exit successfully: exit code: 1 + "#}); #[cfg(not(windows))] From 3c0b8d7abd42ada7c817a426f7d44c92842745ba Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 14 Oct 2024 21:23:46 +0200 Subject: [PATCH 19/20] Update extensions/scarb-doc/tests/diagnostics.rs Signed-off-by: maciektr --- extensions/scarb-doc/tests/diagnostics.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 4e9b47499..332cc78f3 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -176,9 +176,7 @@ fn test_diagnostics_error() { ^********^ error: Compilation failed. - error: process did not exit successfully: exit code: 1 - - "#}); + error: process did not exit successfully: exit code: 1"#}); #[cfg(not(windows))] snapbox.stdout_matches(indoc! {r#" From 982488b2ab65a418fbcf3f1cf31f8e4b44540723 Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 14 Oct 2024 22:17:52 +0200 Subject: [PATCH 20/20] Apply suggestions from code review Signed-off-by: maciektr --- extensions/scarb-doc/tests/diagnostics.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/scarb-doc/tests/diagnostics.rs b/extensions/scarb-doc/tests/diagnostics.rs index 332cc78f3..01a367c1d 100644 --- a/extensions/scarb-doc/tests/diagnostics.rs +++ b/extensions/scarb-doc/tests/diagnostics.rs @@ -176,7 +176,8 @@ fn test_diagnostics_error() { ^********^ error: Compilation failed. - error: process did not exit successfully: exit code: 1"#}); + error: process did not exit successfully: exit code: 1 + "#}); #[cfg(not(windows))] snapbox.stdout_matches(indoc! {r#"