Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/front/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! in this place. Resolution is therefore concerned with creating and resolving
//! variable scopes.

use std::rc::Rc;

use ariadne::ReportKind;

use crate::{
Expand Down Expand Up @@ -215,15 +217,21 @@ impl<'tcx> VisitorMut for Resolve<'tcx> {
self.with_subscope(|this| this.visit_block(block))
}
StmtKind::Annotation(_, ref mut ident, ref mut args, ref mut inner_stmt) => {
self.visit_ident(ident)?;

match self.tcx.get(*ident).as_deref() {
None => {} // Declaration not found
// Resolve the annotation ident to the declaration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment formatting and dots at end of sentences

// Here we only look through annotation declarations therefore other declarations do not shadow annotations
match self
.tcx
.get_statement_annotations()
.get(&ident.name)
.map(Rc::as_ref)
{
Some(DeclKind::AnnotationDecl(intrin)) => {
*ident = intrin.name(); // Resolve to the declaration ident
let intrin = intrin.clone(); // clone so we can mutably borrow self
intrin.resolve(self, s.span, args)?;
}
_ => {} // Not an annotation declaration
_ => return Err(ResolveError::NotFound(*ident)), // Either not declared or not declared as an annotation,
// This case is same as None since we only look through annotations
}

self.with_subscope(|this| this.visit_stmt(inner_stmt))
Expand Down
15 changes: 14 additions & 1 deletion src/tyctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
rc::Rc,
};

use crate::ast::FuncDecl;
use crate::{ast::FuncDecl, intrinsic::annotations::AnnotationKind};
use crate::{
ast::{DeclKind, DeclRef, DomainDecl, Ident, LitKind, Span, Symbol, TyKind, VarKind},
intrinsic::distributions::DistributionProc,
Expand Down Expand Up @@ -157,6 +157,19 @@ impl TyCtx {
}
}

/// Get all annotation declarations that can be used on top of statements. These are slicing and encoding annotations.
pub fn get_statement_annotations(&self) -> IndexMap<Symbol, Rc<DeclKind>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you want to create this new IndexMap instead of just creating a version of get for annotations specifically? Seems wasteful.

IndexMap::from_iter(self.declarations.borrow().iter().flat_map(|(ident, decl)| {
if let DeclKind::AnnotationDecl(
AnnotationKind::Slicing(_) | AnnotationKind::Encoding(_),
) = decl.deref()
{
return Some((ident.name, decl.clone()));
}
None
}))
}

pub fn get_distributions(&self) -> IndexMap<Ident, Rc<DistributionProc>> {
IndexMap::from_iter(self.declarations.borrow().iter().flat_map(|(ident, decl)| {
if let DeclKind::ProcIntrin(intrin) = decl.deref() {
Expand Down
Loading