Skip to content

Conversation

SpriteOvO
Copy link
Member

@SpriteOvO SpriteOvO commented Feb 21, 2024

Added a new function firrtlImportAnnotationsJSONRaw, which accepts a JSON serialized annotations string from external programs and outputs a parsed ArrayAttr.

Marked as draft because it's still in test. Done.

@SpriteOvO SpriteOvO marked this pull request as ready for review February 21, 2024 18:00
Copy link
Contributor

@sequencer sequencer left a comment

Choose a reason for hiding this comment

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

LGTM, I tested this PR w/ chipsalliance/chisel#3842 under chipsalliance/t1#425

MLIRBC elaborated successfully.

Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

I have one question, but the main implementation looks good to me. Please add a small CAPI unit test with some small example JSON string.

@@ -7,17 +7,21 @@
//===----------------------------------------------------------------------===//

#include "circt-c/Dialect/FIRRTL.h"
#include "../../Dialect/FIRRTL/Import/FIRAnnotations.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little unusual to depend on a header in the lib directory. I'm not sure if it's worth refactoring this, or if it's fine to depend on the implementation in lib/Dialect/FIRRTL/Import from the CAPI.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not fine, and headers in lib are there because they're not part of the library's interface.

Please move the declaration to an appropriate header location.

(although one might reasonably wonder if perhaps there's a reason this wasn't already there....)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a simple test for the new function and moved FIRAnnotations.h file from lib/Dialect/FIRRTL/Import/ to include/circt/Dialect/FIRRTL/Import/.

Thanks for the advice @dtzSiFive and the review from @mikeurbach 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I don't think simply moving the header into the include directory is what @dtzSiFive meant. The original problem was you were depending on one C++ API that was an implementation detail. But to address that, you have made the entire set of C++ implementation details public APIs. Please don't do that either.

I think what you could do is revert the last commit, and think about in which header the declaration of fromJSONRaw should live, and in which library the definition should live. For example, one idea is to create a new include/circt/Dialect/FIRRTL/Import/FIRAnnotations.h, only define fromJSONRaw, and keep the definition in the CIRCTImportFIRFile library.

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad, I misunderstood the comment. In the latest commit, I only moved the function fromJSONRaw to the new header include/circt/Dialect/FIRRTL/Import/FIRAnnotations.h, and I renamed it to importAnnotationsFromJSONRaw in order to make it cleaner in the public namespace.

Hopefully I'm on the right path this time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, yes, I think that is more in line with what I was thinking. @dtzSiFive does it make sense to you now to expose this one function from the existing library?

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're exposing this functionality, this seems the way to do it. Thanks! 👍

Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

Please don't wholesale move the FIRAnnotation.h header from private to public.

@SpriteOvO SpriteOvO force-pushed the firrtl-anno-capi branch 2 times, most recently from c38158d to 12daadd Compare February 22, 2024 22:16
@SpriteOvO
Copy link
Member Author

Final tiny change: Renamed the added CAPI firrtlImportAnnotationsJSONRaw to firrtlImportAnnotationsFromJSONRaw to align with the C++ function name.

Thanks to @mikeurbach @dtzSiFive for reviewing :) I'm gonna merge it when the CI passes.

@SpriteOvO SpriteOvO merged commit d010dd4 into llvm:main Feb 23, 2024
@SpriteOvO SpriteOvO deleted the firrtl-anno-capi branch February 23, 2024 18:32
\"target\":\"~AnnoTest|AnnoTest>in\"\
}]";
MlirAttribute rawAnnotationsAttr;
assert(firrtlImportAnnotationsFromJSONRaw(
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI @SpriteOvO , some builds may disable asserts, and we do test with asserts disabled in nightly CI. I missed this in review: this call shouldn't be wrapped in assert since it does meaningful work needed for the test to function. I changed it here: ed19a32

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! Once again, I forgot about this. 🤦 Thanks for your fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem, I will try to keep a better look out for it in review as well.

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.

4 participants