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

Add safer Chisel annotation API, deprecate old ones #4643

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jackkoenig
Copy link
Contributor

Note that I tested that the deprecated versions of annotate work by updating them first, making sure all tests pass, then removing all uses of ChiselAnnotation and ChiselMultiAnnotation except in ChiselEnum. The ones in ChiselEnum have duplication checking that I could replicate with the annotations, but is annoying. I figure we'd rather just remove those (and roll out firrtl enums? 🙏) so I just left them. They also do help test the deprecated APIs.

This PR has two purposes:

  1. Make it possible to check that any data being annotated are annotatable. You can see we've done that for some annotations but not all--this new API enforces it for all annotations (or at least encourages enforcement).
  2. By [softly] requiring the user to record what Data are being annotated up front, we can improve the view renaming logic. Rather than having to conservatively rename tons and tons of views, we only do so for those that are actually annotated. This should be a huge performance improvement for designs that use lots of views.

(2) will be in a follow on PR.

One weirdness in the PR that I would appreciate review of is that the new API asks the caller to "report" all InstanceIds that will be annotated. We really only currently care about Data but I figure in the future we may want checks for other things. The awkwardness though, is that InstanceId includes Data, BaseModule, and MemBase, but not Hierarchy nor the new SRAM targets. So if we wanted more checks, we might need to change the API anyway in the future since users can't currently report Hierarchy or SRAM targets being annotated. I could take a step back and try to find a way to unify all of these, or just leave it, or switch the API to Data to make it more clear that that is all we're checking. WDYT?

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • API deprecation

Desired Merge Strategy

  • Squash

Release Notes

Creating annotations in Chisel now requires reporting what InstanceIds are going to be annotated so that Chisel can do some safety checks.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash), clean up the commit message, and label with Please Merge.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@jackkoenig jackkoenig added the Deprecation Deprecates an API, will be included in release notes label Jan 24, 2025
@jackkoenig jackkoenig added this to the 7.0 milestone Jan 24, 2025
@jackkoenig jackkoenig requested a review from seldridge January 24, 2025 23:13
@jackkoenig jackkoenig mentioned this pull request Jan 24, 2025
14 tasks
Comment on lines -598 to -609
object Circuit
extends scala.runtime.AbstractFunction7[String, Seq[Component], Seq[ChiselAnnotation], RenameMap, Seq[
DefTypeAlias
], Seq[Layer], Seq[DefOption], Circuit] {
def unapply(c: Circuit): Option[(String, Seq[Component], Seq[ChiselAnnotation], RenameMap, Seq[DefTypeAlias])] = {
Some((c.name, c.components, c.annotations, c.renames, c.typeAliases))
}

def apply(
name: String,
components: Seq[Component],
annotations: Seq[ChiselAnnotation],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of this was left over from previous needs to maintain binary compatibility. These APIs are all package private now so we can just delete them.

The new one enables safety checks and smarter logic for views.
@jackkoenig
Copy link
Contributor Author

I'm thinking maybe backport this deprecation to 6.x, then I can follow up with the API removal on main and then we can merge #4644 to get the performance improvement.

@jackkoenig jackkoenig modified the milestones: 7.0, 6.x Jan 27, 2025
Comment on lines +53 to 67
/** Create annotations.
*
* Avoid this API if possible.
*
* Anything being annotated must be passed as arguments so that Chisel can do safety checks.
* The caller is still responsible for calling .toTarget on those arguments in mkAnnos.
*/
def apply(targets: InstanceId*)(mkAnnos: => Seq[Annotation]): Unit = {
targets.foreach {
case d: Data => requireIsAnnotatable(d, "Data marked with annotation")
case _ => ()
}
// TODO record views that need to be renamed
Builder.annotations += (() => mkAnnos)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to do this which directly passes the targets to the annotation construction function directly?

For this to work, an Annotation (or a subclass of) would need to have a constructor that can build it from an InstanceId (or a Data).

I'm primarily worried about there being no check of the connection between the targets and the mkAnnos function as a user could put in incorrect targets or ignore them entirely to get the old, legacy behavior.

Can you think of a way to untangle this?

Comment on lines +23 to +24
"Avoid custom annotations. If you must use annotations, new annotate.apply method that takes Data",
"Chisel 7.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrong deprecation message, just deprecate the annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Deprecates an API, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants