Skip to content

Commit

Permalink
Improve compile-time error messages in ascent_macro
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Nov 1, 2024
1 parent 2e4eb1d commit 81572ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ascent_macro/src/ascent_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl AscentConfig {
[Self::MEASURE_RULE_TIMES_ATTR, Self::GENERATE_RUN_TIMEOUT_ATTR, Self::INTER_RULE_PARALLELISM_ATTR, REL_DS_ATTR];
for attr in attrs.iter() {
if !recognized_attrs.iter().any(|recognized_attr| attr.meta.path().is_ident(recognized_attr)) {
let recognized_attrs: Vec<_> = recognized_attrs.iter().map(|attr| format!("`{attr}`")).collect();
return Err(Error::new_spanned(attr,
format!("unrecognized attribute. recognized attributes are: {}",
recognized_attrs.join(", "))));
Expand Down Expand Up @@ -299,7 +300,7 @@ fn compile_rule_to_ir_rule(rule: &RuleNode, prog: &AscentProgram) -> syn::Result
// TODO may someday this will work
let other_var = grounded_vars.iter().find(|&x| x == &v).unwrap();
let other_err = Error::new(other_var.span(), "variable being shadowed");
let mut err = Error::new(v.span(), format!("'{}' shadows another variable with the same name", v));
let mut err = Error::new(v.span(), format!("`{}` shadows another variable with the same name", v));
err.combine(other_err);
return Err(err);
}
Expand Down Expand Up @@ -413,7 +414,7 @@ fn compile_rule_to_ir_rule(rule: &RuleNode, prog: &AscentProgram) -> syn::Result
let rel = prog.relations.iter().find(|r| hcl_node.rel == r.name);
let rel = match rel {
Some(rel) => rel,
None => return Err(Error::new(hcl_node.rel.span(), format!("relation {} not defined", hcl_node.rel))),
None => return Err(Error::new(hcl_node.rel.span(), format!("relation `{}` is not defined", hcl_node.rel))),
};

let rel = RelationIdentity::from(rel);
Expand Down Expand Up @@ -479,11 +480,11 @@ pub(crate) fn prog_get_relation<'a>(prog: &'a AscentProgram, name: &Ident, arity
match relation {
Some(rel) => {
if rel.field_types.len() != arity {
Err(Error::new(name.span(), format!("Wrong arity for relation {}. Actual arity: {}", name, rel.field_types.len())))
Err(Error::new(name.span(), format!("wrong arity for relation `{name}` (expected {expected}, found {actual})", expected = arity, actual = rel.field_types.len())))
} else {
Ok(rel)
}
},
None => Err(Error::new(name.span(), format!("Relation {} not defined", name))),
None => Err(Error::new(name.span(), format!("relation `{}` not defined", name))),
}
}
2 changes: 1 addition & 1 deletion ascent_macro/src/ascent_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub(crate) fn compile_hir_to_mir(hir: &AscentIr) -> syn::Result<AscentMir>{
if let MirBodyItem::Agg(agg) = bi {
if dynamic_relations.contains_key(&agg.rel.relation) {
return Err(syn::Error::new(agg.span,
format!("use of aggregated relation {} cannot be stratified", &agg.rel.relation.name)));
format!("use of aggregated relation `{}` cannot be stratified", &agg.rel.relation.name)));
}
}
}
Expand Down

0 comments on commit 81572ff

Please sign in to comment.