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

Report Unknown Doc-Comment Tags in Slice #3127

Conversation

InsertCreativityHere
Copy link
Member

@InsertCreativityHere InsertCreativityHere commented Nov 11, 2024

This PR fixes #2088.
Now, the Slice parser rejects unknown doc-comment tags (including @remarks), making it's situation impossible to hit.

It also adds a check which rejects multi-line @see tags, since these are disallowed and @see should always be of the form: @see IDENTIFIER and nothing else.

When the parser encounters either of these cases, we discard (ignore) the offending line, and issue a warning for it.
I think that the predominant philosophy in compilers is that: "a badly formatted comment should never break your build".
Since, on a logical level, compilers should be ignoring all comments in your source file.

Since we currently have no validation of comments, I also added a new "InvalidComment" diagnostic category, which this PR uses.

for (; i != lines.end(); ++i)
{
const string l = IceInternal::trim(*i);
string line;
if (parseCommentLine(l, paramTag, true, name, line))
string lineText;
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to avoid shadowing the line method which is defined on this class.

Copy link
Member

@bernardnormier bernardnormier left a comment

Choose a reason for hiding this comment

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

I think that the predominant philosophy in compilers is that: "a badly formatted comment should never break your build".

That's not correct. Regular comments are ignored and as a result can't be malformed.
On the other hand, we should treat malformed doc-comments (bad syntax, unknown tags, misapplied tag, etc.) as errors, not warning. There is no sensible reason to tolerate them.

@InsertCreativityHere
Copy link
Member Author

After thinking about it more. I think even a warning is too harsh.
We shouldn't issue any diagnostics at all for unknown tags.
Just silently ignore them, and move on.

There is no sensible reason to tolerate them.

It's important to remember that there's two purposes to doc-comments.
One is that we use them to generate doc-comments in the mapped languages, yes.
But another, equally important one, is to document the Slice definitions themselves.
And Slice doc-comments support the full breadth of doxygen.

It just so happens that the Slice parser is only aware of a very limited subset of these.
Because supporting and mapping tags takes time and there's just better things to spend that time on.

But we do not want to restrict users to only using the very small subset of Doxygen tags that we map in the generated code.
This would rob them of the extensive functionality doxygen provides. And if there's any users out there who use this functionality (which we document as providing), the suggested change would completely break their builds.

TL;DR

Just because we the parser doesn't generate code for a doc-comment tag, does not make that tag invalid.
There is no such thing as "Slice comment tags" there are only "Doxygen comment tags",
and we should make no attempt to convert 'slice2xxx' into a Doxygen tag validator.

@InsertCreativityHere
Copy link
Member Author

Just to be clear, I still that this approach where collect all the unknown tags and just slap them at the end of doc comments isn't correct. If the Slice parser isn't aware of a tag, it should just ignore it and move on.

Obviously, the tags that the parser is aware of, we should validate.
But if a user wants to ensure that their doc comment is correct, slice2cpp isn't the correct tool for that. doxygen is.

@InsertCreativityHere
Copy link
Member Author

After discussion, we've come to the following middle ground:

  1. We agree that we shouldn't just slap the unknown tags into the code, we have to ignore and discard it.
  2. We should issue warnings for unknown tags; silently ignoring them would be too surprising.
  3. In the future, we should add parser support for other common Doxygen tags, to reduce the number of warnings users who are familiar with Doxygen will encounter.

@@ -0,0 +1,3 @@
WarningInvalidComment.ice:10: warning: ignoring unknown doc tag '@remarks' in comment
Copy link
Member

Choose a reason for hiding this comment

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

Should we refer to these comments as "doc comment[s]"?

I find the diagnostic "ignored xxx in comment" odd as everything in plain comment should be ignored.
If I write:

// @foo in a plain comment

I don't anticipate any diagnostic.

@@ -38,7 +38,8 @@ namespace Slice
{
All,
Deprecated,
InvalidMetadata
InvalidMetadata,
InvalidComment
Copy link
Member

Choose a reason for hiding this comment

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

Should be InvalidDocComment. A plain comment is always valid and ignored.

/// Contains unrecognized tags.
StringList misc() const;
/// Targets of @see tags.
/// Targets of '@see' tags.
Copy link
Member

Choose a reason for hiding this comment

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

We should rename this class DocComment.

@InsertCreativityHere
Copy link
Member Author

I agree with renaming Comment to doc comment, and have opened an issue to do it: #3141.
I'd rather delay all the renaming of comment -> doc comment until that PR, so it's all done together.

@InsertCreativityHere InsertCreativityHere merged commit 6e7c14b into zeroc-ice:main Nov 13, 2024
19 checks passed
InsertCreativityHere added a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

@remarks results in bad generated Swift code
3 participants