From 445d1b6118dc4cf39d797567d9e1fbdb97b60f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sm=C3=B3=C5=82ka?= Date: Thu, 21 Nov 2024 17:08:32 +0100 Subject: [PATCH] Introduced queries for crate plugins in `DefsGroup` and `SemanticGroup` commit-id:5dc187d6 --- crates/cairo-lang-compiler/src/db.rs | 6 +- crates/cairo-lang-defs/src/db.rs | 95 +++++++++++++++- crates/cairo-lang-defs/src/ids.rs | 102 ++++++++++++++++++ crates/cairo-lang-defs/src/test.rs | 3 +- crates/cairo-lang-doc/src/tests/test_utils.rs | 6 +- crates/cairo-lang-lowering/src/test_utils.rs | 7 +- crates/cairo-lang-plugins/src/test.rs | 3 +- crates/cairo-lang-semantic/src/db.rs | 47 +++++++- crates/cairo-lang-semantic/src/ids.rs | 49 +++++++++ crates/cairo-lang-semantic/src/lib.rs | 1 + crates/cairo-lang-semantic/src/test_utils.rs | 8 +- .../src/test_utils.rs | 7 +- 12 files changed, 318 insertions(+), 16 deletions(-) create mode 100644 crates/cairo-lang-semantic/src/ids.rs diff --git a/crates/cairo-lang-compiler/src/db.rs b/crates/cairo-lang-compiler/src/db.rs index b276125ae99..771505778b4 100644 --- a/crates/cairo-lang-compiler/src/db.rs +++ b/crates/cairo-lang-compiler/src/db.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use anyhow::{Result, anyhow, bail}; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use cairo_lang_defs::plugin::{InlineMacroExprPlugin, MacroPlugin}; use cairo_lang_filesystem::cfg::CfgSet; use cairo_lang_filesystem::db::{ @@ -14,7 +14,7 @@ use cairo_lang_filesystem::ids::{CrateId, FlagId, VirtualFile}; use cairo_lang_lowering::db::{LoweringDatabase, LoweringGroup, init_lowering_group}; use cairo_lang_parser::db::{ParserDatabase, ParserGroup}; use cairo_lang_project::ProjectConfig; -use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup}; +use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup, init_semantic_group}; use cairo_lang_semantic::inline_macros::get_default_plugin_suite; use cairo_lang_semantic::plugin::{AnalyzerPlugin, PluginSuite}; use cairo_lang_sierra_generator::db::SierraGenDatabase; @@ -58,6 +58,8 @@ impl RootDatabase { let mut res = Self { storage: Default::default() }; init_files_group(&mut res); init_lowering_group(&mut res, inlining_strategy); + init_defs_group(&mut res); + init_semantic_group(&mut res); res.set_macro_plugins(plugins); res.set_inline_macro_plugins(inline_macro_plugins.into()); res.set_analyzer_plugins(analyzer_plugins); diff --git a/crates/cairo-lang-defs/src/db.rs b/crates/cairo-lang-defs/src/db.rs index f95ff94fc40..9fa5fe2482f 100644 --- a/crates/cairo-lang-defs/src/db.rs +++ b/crates/cairo-lang-defs/src/db.rs @@ -96,10 +96,48 @@ pub trait DefsGroup: // Plugins. // ======== #[salsa::input] - fn macro_plugins(&self) -> Vec>; - #[salsa::input] + fn macro_plugins(&self) -> Vec>; // TODO: Delete in favour or [`default_macro_plugins`] + #[salsa::input] // TODO: Delete in favour or [`default_inline_macro_plugins`] fn inline_macro_plugins(&self) -> Arc>>; + #[salsa::input] + fn default_macro_plugins(&self) -> Arc<[MacroPluginId]>; + + #[salsa::input] + fn macro_plugin_overrides(&self) -> Arc>>; + + #[salsa::interned] + fn intern_macro_plugin(&self, plugin: MacroPluginLongId) -> MacroPluginId; + + /// Returns [`MacroPluginId`]s of the plugins set for the crate with [`CrateId`]. + /// Provides an override if it has been set with + /// [`DefsGroup::set_override_crate_macro_plugins`] or the default + /// ([`DefsGroup::default_macro_plugins`]) otherwise. + fn crate_macro_plugins(&self, crate_id: CrateId) -> Arc<[MacroPluginId]>; + + #[salsa::input] + fn default_inline_macro_plugins(&self) -> Arc>; + + #[salsa::input] + fn inline_macro_plugin_overrides( + &self, + ) -> Arc>>>; + + #[salsa::interned] + fn intern_inline_macro_plugin( + &self, + plugin: InlineMacroExprPluginLongId, + ) -> InlineMacroExprPluginId; + + /// Returns [`InlineMacroExprPluginId`]s of the plugins set for the crate with [`CrateId`]. + /// Provides an override if it has been set with + /// [`DefsGroup::set_override_crate_inline_macro_plugins`] or the default + /// ([`DefsGroup::default_inline_macro_plugins`]) otherwise. + fn crate_inline_macro_plugins( + &self, + crate_id: CrateId, + ) -> Arc>; + /// Returns the set of attributes allowed anywhere. /// An attribute on any item that is not in this set will be handled as an unknown attribute. fn allowed_attributes(&self) -> Arc>; @@ -261,6 +299,29 @@ pub trait DefsGroup: ) -> Maybe>; } +/// Initializes the [`DefsGroup`] database to a proper state. +pub fn init_defs_group(db: &mut dyn DefsGroup) { + db.set_macro_plugin_overrides(Arc::new(OrderedHashMap::default())); + db.set_inline_macro_plugin_overrides(Arc::new(OrderedHashMap::default())); +} + +fn crate_macro_plugins(db: &dyn DefsGroup, crate_id: CrateId) -> Arc<[MacroPluginId]> { + db.macro_plugin_overrides() + .get(&crate_id) + .cloned() + .unwrap_or_else(|| db.default_macro_plugins()) +} + +fn crate_inline_macro_plugins( + db: &dyn DefsGroup, + crate_id: CrateId, +) -> Arc> { + db.inline_macro_plugin_overrides() + .get(&crate_id) + .cloned() + .unwrap_or_else(|| db.default_inline_macro_plugins()) +} + fn allowed_attributes(db: &dyn DefsGroup) -> Arc> { let base_attrs = [ INLINE_ATTR, @@ -1145,3 +1206,33 @@ fn module_item_name_stable_ptr( } }) } + +pub trait DefsGroupEx: DefsGroup { + /// Overrides the default macro plugins available for [`CrateId`] with `plugins`. + /// + /// *Note*: Sets the following Salsa input: `DefsGroup::macro_plugin_overrides`. + fn set_override_crate_macro_plugins( + &mut self, + crate_id: CrateId, + plugins: Arc<[MacroPluginId]>, + ) { + let mut overrides = self.macro_plugin_overrides().as_ref().clone(); + overrides.insert(crate_id, plugins); + self.set_macro_plugin_overrides(Arc::new(overrides)); + } + + /// Overrides the default inline macro plugins available for [`CrateId`] with `plugins`. + /// + /// *Note*: Sets the following Salsa input: `DefsGroup::inline_macro_plugin_overrides`. + fn set_override_crate_inline_macro_plugins( + &mut self, + crate_id: CrateId, + plugins: Arc>, + ) { + let mut overrides = self.inline_macro_plugin_overrides().as_ref().clone(); + overrides.insert(crate_id, plugins); + self.set_inline_macro_plugin_overrides(Arc::new(overrides)); + } +} + +impl DefsGroupEx for T {} diff --git a/crates/cairo-lang-defs/src/ids.rs b/crates/cairo-lang-defs/src/ids.rs index b98af99c767..f5df4a2120a 100644 --- a/crates/cairo-lang-defs/src/ids.rs +++ b/crates/cairo-lang-defs/src/ids.rs @@ -21,6 +21,9 @@ // // Call sites, variable usages, assignments, etc. are NOT definitions. +use std::hash::{Hash, Hasher}; +use std::sync::Arc; + use cairo_lang_debug::debug::DebugWithDb; use cairo_lang_diagnostics::Maybe; pub use cairo_lang_filesystem::ids::UnstableSalsaId; @@ -37,6 +40,7 @@ use smol_str::SmolStr; use crate::db::DefsGroup; use crate::diagnostic_utils::StableLocation; +use crate::plugin::{InlineMacroExprPlugin, MacroPlugin}; // A trait for an id for a language element. pub trait LanguageElementId { @@ -321,6 +325,104 @@ define_short_id!( intern_plugin_generated_file ); +/// An ID allowing for interning the [`MacroPlugin`] into Salsa database. +#[derive(Clone, Debug)] +pub struct MacroPluginLongId(pub Arc); + +impl MacroPlugin for MacroPluginLongId { + fn generate_code( + &self, + db: &dyn SyntaxGroup, + item_ast: ast::ModuleItem, + metadata: &crate::plugin::MacroPluginMetadata<'_>, + ) -> crate::plugin::PluginResult { + self.0.generate_code(db, item_ast, metadata) + } + + fn declared_attributes(&self) -> Vec { + self.0.declared_attributes() + } + + fn declared_derives(&self) -> Vec { + self.0.declared_derives() + } + + fn executable_attributes(&self) -> Vec { + self.0.executable_attributes() + } + + fn phantom_type_attributes(&self) -> Vec { + self.0.phantom_type_attributes() + } +} + +// `PartialEq` and `Hash` cannot be derived on `Arc`, +// but pointer-based equality and hash semantics are enough in this case. +impl PartialEq for MacroPluginLongId { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.0, &other.0) + } +} + +impl Eq for MacroPluginLongId {} + +impl Hash for MacroPluginLongId { + fn hash(&self, state: &mut H) { + Arc::as_ptr(&self.0).hash(state) + } +} + +define_short_id!( + MacroPluginId, + MacroPluginLongId, + DefsGroup, + lookup_intern_macro_plugin, + intern_macro_plugin +); + +/// An ID allowing for interning the [`InlineMacroExprPlugin`] into Salsa database. +#[derive(Clone, Debug)] +pub struct InlineMacroExprPluginLongId(pub Arc); + +impl InlineMacroExprPlugin for InlineMacroExprPluginLongId { + fn generate_code( + &self, + db: &dyn SyntaxGroup, + item_ast: &ast::ExprInlineMacro, + metadata: &crate::plugin::MacroPluginMetadata<'_>, + ) -> crate::plugin::InlinePluginResult { + self.0.generate_code(db, item_ast, metadata) + } + + fn documentation(&self) -> Option { + self.0.documentation() + } +} + +// `PartialEq` and `Hash` cannot be derived on `Arc`, +// but pointer-based equality and hash semantics are enough in this case. +impl PartialEq for InlineMacroExprPluginLongId { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.0, &other.0) + } +} + +impl Eq for InlineMacroExprPluginLongId {} + +impl Hash for InlineMacroExprPluginLongId { + fn hash(&self, state: &mut H) { + Arc::as_ptr(&self.0).hash(state) + } +} + +define_short_id!( + InlineMacroExprPluginId, + InlineMacroExprPluginLongId, + DefsGroup, + lookup_intern_inline_macro_plugin, + intern_inline_macro_plugin +); + define_language_element_id_as_enum! { #[toplevel] /// Id for direct children of a module. diff --git a/crates/cairo-lang-defs/src/test.rs b/crates/cairo-lang-defs/src/test.rs index dd04906ee25..12efaaf699d 100644 --- a/crates/cairo-lang-defs/src/test.rs +++ b/crates/cairo-lang-defs/src/test.rs @@ -17,7 +17,7 @@ use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use cairo_lang_utils::{Intern, LookupIntern, Upcast, extract_matches, try_extract_matches}; use indoc::indoc; -use crate::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use crate::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use crate::ids::{ FileIndex, GenericParamLongId, ModuleFileId, ModuleId, ModuleItemId, NamedLanguageElementId, SubmoduleLongId, @@ -40,6 +40,7 @@ impl Default for DatabaseForTesting { fn default() -> Self { let mut res = Self { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); res.set_macro_plugins(vec![ Arc::new(FooToBarPlugin), Arc::new(RemoveOrigPlugin), diff --git a/crates/cairo-lang-doc/src/tests/test_utils.rs b/crates/cairo-lang-doc/src/tests/test_utils.rs index ba6353ecc04..0cdb1215b5f 100644 --- a/crates/cairo-lang-doc/src/tests/test_utils.rs +++ b/crates/cairo-lang-doc/src/tests/test_utils.rs @@ -1,5 +1,5 @@ use anyhow::{Result, anyhow}; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group}; use cairo_lang_defs::ids::ModuleId; use cairo_lang_filesystem::db::{ AsFilesGroupMut, CrateConfiguration, ExternalFiles, FilesDatabase, FilesGroup, FilesGroupEx, @@ -8,7 +8,7 @@ use cairo_lang_filesystem::db::{ use cairo_lang_filesystem::detect::detect_corelib; use cairo_lang_filesystem::ids::{CrateId, Directory, FileLongId}; use cairo_lang_parser::db::{ParserDatabase, ParserGroup}; -use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup}; +use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup, init_semantic_group}; use cairo_lang_syntax::node::db::{SyntaxDatabase, SyntaxGroup}; use cairo_lang_utils::{Intern, Upcast}; @@ -33,6 +33,8 @@ impl Default for TestDatabase { fn default() -> Self { let mut res = Self { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); + init_semantic_group(&mut res); res.set_macro_plugins(vec![]); res } diff --git a/crates/cairo-lang-lowering/src/test_utils.rs b/crates/cairo-lang-lowering/src/test_utils.rs index c039d6f4cba..a157cc2208a 100644 --- a/crates/cairo-lang-lowering/src/test_utils.rs +++ b/crates/cairo-lang-lowering/src/test_utils.rs @@ -1,13 +1,13 @@ use std::sync::{LazyLock, Mutex}; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use cairo_lang_filesystem::db::{ AsFilesGroupMut, ExternalFiles, FilesDatabase, FilesGroup, init_dev_corelib, init_files_group, }; use cairo_lang_filesystem::detect::detect_corelib; use cairo_lang_filesystem::ids::VirtualFile; use cairo_lang_parser::db::{ParserDatabase, ParserGroup}; -use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup}; +use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup, init_semantic_group}; use cairo_lang_semantic::inline_macros::get_default_plugin_suite; use cairo_lang_syntax::node::db::{SyntaxDatabase, SyntaxGroup}; use cairo_lang_utils::Upcast; @@ -41,11 +41,12 @@ impl LoweringDatabaseForTesting { pub fn new() -> Self { let mut res = LoweringDatabaseForTesting { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); + init_semantic_group(&mut res); let suite = get_default_plugin_suite(); res.set_macro_plugins(suite.plugins); res.set_inline_macro_plugins(suite.inline_macro_plugins.into()); res.set_analyzer_plugins(suite.analyzer_plugins); - let corelib_path = detect_corelib().expect("Corelib not found in default location."); init_dev_corelib(&mut res, corelib_path); init_lowering_group(&mut res, InliningStrategy::Default); diff --git a/crates/cairo-lang-plugins/src/test.rs b/crates/cairo-lang-plugins/src/test.rs index d860baf6e0d..051141a5a8a 100644 --- a/crates/cairo-lang-plugins/src/test.rs +++ b/crates/cairo-lang-plugins/src/test.rs @@ -1,7 +1,7 @@ use std::default::Default; use std::sync::Arc; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use cairo_lang_defs::ids::ModuleId; use cairo_lang_defs::plugin::{ MacroPlugin, MacroPluginMetadata, PluginDiagnostic, PluginGeneratedFile, PluginResult, @@ -64,6 +64,7 @@ impl Default for DatabaseForTesting { fn default() -> Self { let mut res = Self { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); res.set_macro_plugins(get_base_plugins()); res } diff --git a/crates/cairo-lang-semantic/src/db.rs b/crates/cairo-lang-semantic/src/db.rs index ba26a75dcfe..2d2fa35fd65 100644 --- a/crates/cairo-lang-semantic/src/db.rs +++ b/crates/cairo-lang-semantic/src/db.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use cairo_lang_defs::db::DefsGroup; +use cairo_lang_defs::db::{DefsGroup, DefsGroupEx}; use cairo_lang_defs::diagnostic_utils::StableLocation; use cairo_lang_defs::ids::{ ConstantId, EnumId, ExternFunctionId, ExternTypeId, FreeFunctionId, FunctionTitleId, @@ -23,6 +23,7 @@ use smol_str::SmolStr; use crate::diagnostic::SemanticDiagnosticKind; use crate::expr::inference::{self, ImplVar, ImplVarId}; +use crate::ids::{AnalyzerPluginId, AnalyzerPluginLongId}; use crate::items::constant::{ConstValueId, Constant, ImplConstantId}; use crate::items::function_with_body::FunctionBody; use crate::items::functions::{ImplicitPrecedence, InlineConfiguration}; @@ -1559,6 +1560,21 @@ pub trait SemanticGroup: #[salsa::input] fn analyzer_plugins(&self) -> Vec>; + #[salsa::input] + fn default_analyzer_plugins(&self) -> Arc<[AnalyzerPluginId]>; + + #[salsa::input] + fn analyzer_plugin_overrides(&self) -> Arc>>; + + #[salsa::interned] + fn intern_analyzer_plugin(&self, plugin: AnalyzerPluginLongId) -> AnalyzerPluginId; + + /// Returns [`AnalyzerPluginId`]s of the plugins set for the crate with [`CrateId`]. + /// Returns + /// [`SemanticGroup::override_crate_analyzer_plugins`] if it has been set, + /// or the ([`SemanticGroup::default_analyzer_plugins`]) otherwise. + fn crate_analyzer_plugins(&self, crate_id: CrateId) -> Arc<[AnalyzerPluginId]>; + /// Returns the set of `allow` that were declared as by a plugin. /// An allow that is not in this set will be handled as an unknown allow. fn declared_allows(&self) -> Arc>; @@ -1605,6 +1621,11 @@ pub trait SemanticGroup: ) -> Arc<[(TraitId, String)]>; } +/// Initializes the [`SemanticGroup`] database to a proper state. +pub fn init_semantic_group(db: &mut dyn SemanticGroup) { + db.set_analyzer_plugin_overrides(Arc::new(OrderedHashMap::default())); +} + impl> Elongate for T { fn elongate(&self) -> &(dyn SemanticGroup + 'static) { self.upcast() @@ -1708,6 +1729,13 @@ fn module_semantic_diagnostics( Ok(diagnostics.build()) } +fn crate_analyzer_plugins(db: &dyn SemanticGroup, crate_id: CrateId) -> Arc<[AnalyzerPluginId]> { + db.analyzer_plugin_overrides() + .get(&crate_id) + .cloned() + .unwrap_or_else(|| db.default_analyzer_plugins()) +} + fn declared_allows(db: &dyn SemanticGroup) -> Arc> { Arc::new(OrderedHashSet::from_iter( db.analyzer_plugins().into_iter().flat_map(|plugin| plugin.declared_allows()), @@ -1852,3 +1880,20 @@ pub fn get_resolver_data_options( .flatten() .collect() } + +pub trait SemanticGroupEx: SemanticGroup { + /// Overrides the default analyzer plugins available for [`CrateId`] with `plugins`. + /// + /// *Note*: Sets the following Salsa input: `SemanticGroup::analyzer_plugin_overrides`. + fn set_override_crate_analyzer_plugins( + &mut self, + crate_id: CrateId, + plugins: Arc<[AnalyzerPluginId]>, + ) { + let mut overrides = self.analyzer_plugin_overrides().as_ref().clone(); + overrides.insert(crate_id, plugins); + self.set_analyzer_plugin_overrides(Arc::new(overrides)); + } +} + +impl SemanticGroupEx for T {} diff --git a/crates/cairo-lang-semantic/src/ids.rs b/crates/cairo-lang-semantic/src/ids.rs new file mode 100644 index 00000000000..3940b8c4eb3 --- /dev/null +++ b/crates/cairo-lang-semantic/src/ids.rs @@ -0,0 +1,49 @@ +use std::hash::{Hash, Hasher}; +use std::sync::Arc; + +use cairo_lang_utils::define_short_id; + +use crate::db::SemanticGroup; +use crate::plugin::AnalyzerPlugin; + +/// An Id allowing interning [`AnalyzerPlugin`] into Salsa database. +#[derive(Clone, Debug)] +pub struct AnalyzerPluginLongId(pub Arc); + +impl AnalyzerPlugin for AnalyzerPluginLongId { + fn diagnostics( + &self, + db: &dyn crate::db::SemanticGroup, + module_id: cairo_lang_defs::ids::ModuleId, + ) -> Vec { + self.0.diagnostics(db, module_id) + } + + fn declared_allows(&self) -> Vec { + self.0.declared_allows() + } +} + +// `PartialEq` and `Hash` cannot be derived on `Arc`, +// but pointer-based equality and hash semantics are enough in this case. +impl PartialEq for AnalyzerPluginLongId { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.0, &other.0) + } +} + +impl Eq for AnalyzerPluginLongId {} + +impl Hash for AnalyzerPluginLongId { + fn hash(&self, state: &mut H) { + Arc::as_ptr(&self.0).hash(state) + } +} + +define_short_id!( + AnalyzerPluginId, + AnalyzerPluginLongId, + SemanticGroup, + lookup_intern_analyzer_plugin, + intern_analyzer_plugin +); diff --git a/crates/cairo-lang-semantic/src/lib.rs b/crates/cairo-lang-semantic/src/lib.rs index 55bf65d53b8..b03cb9561aa 100644 --- a/crates/cairo-lang-semantic/src/lib.rs +++ b/crates/cairo-lang-semantic/src/lib.rs @@ -6,6 +6,7 @@ pub mod corelib; pub mod db; pub mod diagnostic; pub mod expr; +pub mod ids; pub mod inline_macros; pub mod items; pub mod literals; diff --git a/crates/cairo-lang-semantic/src/test_utils.rs b/crates/cairo-lang-semantic/src/test_utils.rs index 69097e35dab..905b6217dac 100644 --- a/crates/cairo-lang-semantic/src/test_utils.rs +++ b/crates/cairo-lang-semantic/src/test_utils.rs @@ -1,6 +1,6 @@ use std::sync::{LazyLock, Mutex}; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use cairo_lang_defs::ids::{FunctionWithBodyId, ModuleId, SubmoduleId, SubmoduleLongId}; use cairo_lang_diagnostics::{Diagnostics, DiagnosticsBuilder}; use cairo_lang_filesystem::db::{ @@ -17,7 +17,7 @@ use cairo_lang_test_utils::verify_diagnostics_expectation; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use cairo_lang_utils::{Intern, LookupIntern, OptionFrom, Upcast, extract_matches}; -use crate::db::{SemanticDatabase, SemanticGroup}; +use crate::db::{SemanticDatabase, SemanticGroup, init_semantic_group}; use crate::inline_macros::get_default_plugin_suite; use crate::items::functions::GenericFunctionId; use crate::{ConcreteFunctionWithBodyId, SemanticDiagnostic, semantic}; @@ -41,10 +41,14 @@ impl SemanticDatabaseForTesting { pub fn new_empty() -> Self { let mut res = SemanticDatabaseForTesting { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); + init_semantic_group(&mut res); + let suite = get_default_plugin_suite(); res.set_macro_plugins(suite.plugins); res.set_inline_macro_plugins(suite.inline_macro_plugins.into()); res.set_analyzer_plugins(suite.analyzer_plugins); + let corelib_path = detect_corelib().expect("Corelib not found in default location."); init_dev_corelib(&mut res, corelib_path); res diff --git a/crates/cairo-lang-sierra-generator/src/test_utils.rs b/crates/cairo-lang-sierra-generator/src/test_utils.rs index b9b39be2181..987ca8128fb 100644 --- a/crates/cairo-lang-sierra-generator/src/test_utils.rs +++ b/crates/cairo-lang-sierra-generator/src/test_utils.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, LazyLock, Mutex}; -use cairo_lang_defs::db::{DefsDatabase, DefsGroup, try_ext_as_virtual_impl}; +use cairo_lang_defs::db::{DefsDatabase, DefsGroup, init_defs_group, try_ext_as_virtual_impl}; use cairo_lang_defs::ids::ModuleId; use cairo_lang_filesystem::db::{ AsFilesGroupMut, ExternalFiles, FilesDatabase, FilesGroup, FilesGroupEx, init_dev_corelib, @@ -11,7 +11,7 @@ use cairo_lang_filesystem::flag::Flag; use cairo_lang_filesystem::ids::{FlagId, 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::db::{SemanticDatabase, SemanticGroup, init_semantic_group}; use cairo_lang_semantic::test_utils::setup_test_crate; use cairo_lang_sierra::ids::{ConcreteLibfuncId, GenericLibfuncId}; use cairo_lang_sierra::program; @@ -65,6 +65,9 @@ impl SierraGenDatabaseForTesting { pub fn new_empty() -> Self { let mut res = SierraGenDatabaseForTesting { storage: Default::default() }; init_files_group(&mut res); + init_defs_group(&mut res); + init_semantic_group(&mut res); + let suite = get_default_plugin_suite(); res.set_macro_plugins(suite.plugins); res.set_inline_macro_plugins(suite.inline_macro_plugins.into());