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

Cleanup Deprecated Metadata #2129

Merged

Conversation

InsertCreativityHere
Copy link
Member

This PR addresses part of #2085.

Now, when the Slice compiler generates a [[deprecated]], [Obsolete], etc. something to mark an item as deprecated,
it will only supply a message when the user did.

Whereas right now, if the user didn't supply a message, we auto-compute one.
#2085 points out that this auto-computed message is broken anyways.


While fixing this, I also did some cleanup. Mostly adding 2 functions to the Parser: isDeprecated and getDeprecateReason.
Instead of our previous approach of defining approximate copies of these functions in each slice2xxx separate folder...


After this PR I'll address the 2nd part of #2085, which is removing the 'deprecated' metadata from the dispatch side of things.

@InsertCreativityHere InsertCreativityHere changed the title Deprecated stuff Cleanup Deprecated Metadata May 7, 2024
bool
Slice::Contained::isDeprecated(bool checkParent) const
{
const string deprecate = "deprecate";
Copy link
Member

Choose a reason for hiding this comment

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

Even though your functions are named "isDeprecated", you didn't add "deprecated" as an alias for the "deprecate" metadata?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but only because isDeprecate isn't a sensible thing to say IMO. Nothing to do with our eventual renaming.
I plan to add the alias in my next PR, alongside removing the dispatch side.

cpp/src/Slice/Parser.h Show resolved Hide resolved
string deprecateMetadata, deprecateSymbol;
if (p1->findMetaData("deprecate", deprecateMetadata) ||
(p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata)))
string deprecateSymbol;
Copy link
Member

Choose a reason for hiding this comment

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

I'd use "deprecated" instead of "deprecate".

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. deprecateSymbol was just the old name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also fixed!

[["swift:class-resolver-prefix:IceDefaultValue",
"suppress-warning:deprecated"]] // For enumerator references
[["swift:class-resolver-prefix:IceDefaultValue"]]
[["suppress-warning:deprecated"]] // For enumerator references
Copy link
Member

Choose a reason for hiding this comment

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

For suppress warning, we already use deprecated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. Of course! See: #2093 (comment)
And maybe weigh in on the rest of that comment.

bool
Slice::Contained::isDeprecated(bool checkParent) const
{
const string deprecate = "deprecate";
Copy link
Member

Choose a reason for hiding this comment

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

I would be nice to update findMetaData to take a string_view and switch this const to a constexpr.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll do that in a follow-up PR though.
I want to avoid going too far down that rabbit hole though.
It'd probably take months to clean and modernize the compilers...

{
string msg = "is deprecated";
if (deprecateMetadata.find("deprecate:") == 0 && deprecateMetadata.size() > 10)
if (auto reason = p1->getDeprecationReason(false))
Copy link
Member

Choose a reason for hiding this comment

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

Should this be true as well? Since we're checking the parent above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right. Fixed.

{
_out << nl << " * @deprecated " << deprecateReason;
_out << nl << " * @deprecated";
if (auto reason = p->getDeprecationReason(false))
Copy link
Member

Choose a reason for hiding this comment

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

why not true?

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 guess is that if a parent is deprecated, we only want to generate a comment once (on that parent),
instead of generating it on everything inside of it?

This is just what we were already doing though. If you look at the code underneath this:
writeDocComment(p, getDeprecateReason(p, 0, "type"));
The 0 means: don't bother with the parent.
And we always pass 0 for javascript.

cpp/src/slice2matlab/Main.cpp Show resolved Hide resolved
@@ -83,28 +83,35 @@ namespace
return "???";
}

string getDeprecateReason(const ContainedPtr& p1, const ContainedPtr& p2, const string& type)
string getDeprecateReason(const ContainedPtr& p1, const string& type)
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we should generate a special doc-comment message for deprecated operation and the like.

But we should at least give this helper function a clearer/consistent name, like getDocCommentDeprecationReason.

@@ -1625,15 +1618,10 @@ Slice::JavaVisitor::writeDispatch(Output& out, const InterfaceDefPtr& p)

out << sp;
writeHiddenDocComment(out);
for (OperationList::iterator r = allOps.begin(); r != allOps.end(); ++r)
for (const OperationPtr& op : allOps)
Copy link
Member

Choose a reason for hiding this comment

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

I would add a TODO: temporary.

@InsertCreativityHere InsertCreativityHere merged commit c4a96d3 into zeroc-ice:main May 10, 2024
16 of 17 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.

3 participants