Skip to content

Commit

Permalink
Documented diagnostics cycle breaking. (starkware-libs#5051)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvalsw authored Feb 12, 2024
1 parent c0eecd2 commit 6e0c62b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion crates/cairo-lang-semantic/src/items/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ pub fn priv_impl_declaration_data_inner(
#[derive(Clone, Debug, PartialEq, Eq, DebugWithDb)]
#[debug_db(dyn SemanticGroup + 'static)]
pub struct ImplDefinitionData {
/// The diagnostics here are "flat" - that is, only the diagnostics found on the impl level
/// itself, and don't include the diagnostics of its items. The reason it's this way is that
/// computing the items' diagnostics require a query about their impl, forming a cycle of
/// queries. Adding the items' diagnostics only after the whole computation breaks this cycle.
diagnostics: Diagnostics<SemanticDiagnostic>,
function_asts: OrderedHashMap<ImplFunctionId, ast::FunctionWithBody>,
item_type_asts: Arc<OrderedHashMap<ImplTypeId, ast::ItemTypeAlias>>,
Expand All @@ -446,7 +450,8 @@ pub fn impl_semantic_definition_diagnostics(
return Diagnostics::default();
};

// TODO(yuval): move these into priv_impl_definition_data.
// The diagnostics from `priv_impl_definition_data` are only the diagnostics from the impl
// level. They should be enriched with the items' diagnostics.
diagnostics.extend(data.diagnostics);
for impl_function_id in data.function_asts.keys() {
diagnostics.extend(db.impl_function_declaration_diagnostics(*impl_function_id));
Expand Down
7 changes: 6 additions & 1 deletion crates/cairo-lang-semantic/src/items/trt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ pub fn priv_trait_declaration_data(
#[derive(Clone, Debug, PartialEq, Eq, DebugWithDb)]
#[debug_db(dyn SemanticGroup + 'static)]
pub struct TraitDefinitionData {
/// The diagnostics here are "flat" - that is, only the diagnostics found on the trait level
/// itself, and don't include the diagnostics of its items. The reason it's this way is that
/// computing the items' diagnostics require a query about their trait, forming a cycle of
/// queries. Adding the items' diagnostics only after the whole computation breaks this cycle.
diagnostics: Diagnostics<SemanticDiagnostic>,
function_asts: OrderedHashMap<TraitFunctionId, ast::TraitItemFunction>,
item_type_asts: OrderedHashMap<TraitTypeId, ast::TraitItemType>,
Expand All @@ -286,7 +290,8 @@ pub fn trait_semantic_definition_diagnostics(
return Diagnostics::default();
};

// TODO(yuval): move these into priv_trait_definition_data.
// The diagnostics from `priv_trait_definition_data` are only the diagnostics from the trait
// level. They should be enriched with the items' diagnostics.
diagnostics.extend(data.diagnostics);
for trait_function_id in data.function_asts.keys() {
diagnostics.extend(db.trait_function_declaration_diagnostics(*trait_function_id));
Expand Down

0 comments on commit 6e0c62b

Please sign in to comment.