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 format strings to assert and assume #3802

Merged
merged 4 commits into from Feb 22, 2024

Conversation

uenoku
Copy link
Contributor

@uenoku uenoku commented Jan 31, 2024

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

  • Backend code generation

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference).

Release Notes

This supports format strings for assert and assume statements as proposed in chipsalliance/firrtl-spec#166. This change might break existing code if message contains %.

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.

Copy link

linux-foundation-easycla bot commented Jan 31, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

This supports format strings for assert and assume statements.
Internal representaion of `Verification` object is modified in a similar way to
`Print`. Cover cannot be used with a format string so conversion raires an exception
when we try constructing a cover statement with a format string.
@seldridge seldridge added the Backend Code Generation Affects backend code generation, will be included in release notes label Jan 31, 2024
@sequencer
Copy link
Member

The Panama part lgtm. Although we don’t have enough test for now.

Copy link
Member

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

LGTM, but may be good to get another approval 👍 .

Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

This looks good. I'm requesting @jackkoenig to take a look for some of the data class pieces.

Comment on lines 224 to 226
if (op == Formal.Cover && args.nonEmpty) {
throwException("cover message cannot be used as a format string")
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be done as a require inside the constructor of the Verification op. (Arguably that motivates splitting this into separate IR structures for assert, assume, and cover, but that's not necessary.)

@@ -436,6 +436,7 @@ object Formal extends Enumeration {
pred: Expression,
en: Expression,
msg: StringLit,
args: Seq[Expression],
Copy link
Member

Choose a reason for hiding this comment

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

If we're doing this the data class way, then this needs an @since(...). @jackkoenig: how do you want to handle this?

Copy link
Contributor

Choose a reason for hiding this comment

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

We've deprecated everything in package firrtl._ and we should probably make it all private as part of Chisel 7 so I'm fine with just making the breaking change. WIth that, I'm fine with this as is, or we can change it back to a case class which would let us delete the unapply (and companion object) rather than updating it.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I greatly prefer making all this private!

Comment on lines 459 to 462
def unapply(
s: Verification
): Some[(Formal.Value, Info, Expression, Expression, Expression, StringLit, Seq[Expression])] = {
Some((s.op, s.info, s.clk, s.pred, s.en, s.msg, s.args))
Copy link
Member

Choose a reason for hiding this comment

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

@jackkoenig: is this necessary to update for data class?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we keep the data class (implying we're trying to maintain source and binary compatibility), we should not update this (but should instead deprecate it). As is, this is making a breaking change, but I support just breaking it, see my other comment.

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

I approve but please just change @data class Verification to a case class. To do this, replace @data with case, delete @since, delete copy, and delete the companion object and unapply method.

Comment on lines 459 to 462
def unapply(
s: Verification
): Some[(Formal.Value, Info, Expression, Expression, Expression, StringLit, Seq[Expression])] = {
Some((s.op, s.info, s.clk, s.pred, s.en, s.msg, s.args))
Copy link
Contributor

Choose a reason for hiding this comment

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

If we keep the data class (implying we're trying to maintain source and binary compatibility), we should not update this (but should instead deprecate it). As is, this is making a breaking change, but I support just breaking it, see my other comment.

@@ -436,6 +436,7 @@ object Formal extends Enumeration {
pred: Expression,
en: Expression,
msg: StringLit,
args: Seq[Expression],
Copy link
Contributor

Choose a reason for hiding this comment

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

We've deprecated everything in package firrtl._ and we should probably make it all private as part of Chisel 7 so I'm fine with just making the breaking change. WIth that, I'm fine with this as is, or we can change it back to a case class which would let us delete the unapply (and companion object) rather than updating it.

WDYT?

@uenoku
Copy link
Contributor Author

uenoku commented Feb 22, 2024

@jackkoenig @seldridge Could you merge this? Thanks!

@jackkoenig jackkoenig merged commit d565ceb into chipsalliance:main Feb 22, 2024
14 checks passed
sequencer pushed a commit that referenced this pull request Feb 28, 2024
This supports format strings for assert and assume statements.
Internal representaion of `Verification` object is modified in a similar way to
`Print`. Cover cannot be used with a format string so conversion raires an exception
when we try constructing a cover statement with a format string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Code Generation Affects backend code generation, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants