Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for annotations #247

Merged
merged 18 commits into from
Jan 9, 2025
Merged

Conversation

chengluyu
Copy link
Member

I'm trying to support annotations. As we discussed, recursive pattern normalization/compilation should be an opt-in feature and can be enabled by an annotation. For example,

fun foo(xs) = if xs is
  @compile EmailList(values) then ...
  ...

I have only completed parsing as the first step. I am still not sure how it should be handled in the Elaborator, so I put this PR in draft status.

@LPTK
Copy link
Contributor

LPTK commented Dec 4, 2024

For reference, the PR where this was implemented in the previous version of the compiler by @CAG2Mark: #210

# Conflicts:
#	hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala
#	hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala
#	hkmc2/shared/src/main/scala/hkmc2/semantics/Term.scala
@chengluyu
Copy link
Member Author

Summary

  • Add case Annotated(qualifier, target) to both Tree and Terms.
  • Only annotations for declarations are stored in a new field annotations added to LetDecl, TermDefinition, and TypeLikeDef.
  • Annotating expressions and missing annotation targets will raise a warning. In such cases, annotation qualifiers will be discarded and not elaborated.
  • Annotation qualifiers must be a simple expression of selections or identifiers (or applications to them).

@chengluyu chengluyu marked this pull request as ready for review January 8, 2025 09:20
@chengluyu
Copy link
Member Author

Please squash and merge after review. Thanks.

Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

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

Thanks, it looks mostly good, but:

  • You should probably warn about useless annotations in Lowering rather than Elaborator – indeed, the lowering will later make use of some annotations, like @tailrec.
  • Similarly, in Lowering, you should warn against useless annotations even on definitions (like class and value definitions).

@chengluyu
Copy link
Member Author

It seems that there are still some warnings about unused annotations that need to be addressed in the elaborator, because by the time they reach the lowering phase, these trees are no longer present, such as open. Therefore, I kept the warnings in the elaborator when processing blocks.

Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

I'll merge after you the last conversation is resolved.

@LPTK LPTK merged commit 1b5d920 into hkust-taco:hkmc2 Jan 9, 2025
1 check passed
@LPTK LPTK deleted the hkmc2-ucs/annotations branch January 9, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants