Skip to content

Minor 'ice2slice' Fixes #3827

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

Merged

Conversation

InsertCreativityHere
Copy link
Member

This PR:

  • fixes a bug in ice2slice where it wasn't registering generated files with the FileTracker.
  • removes an assert which caused ice2slice to crash when it saw an operation.

Comment on lines -12 to -17
const char*
Slice::FileException::ice_id() const noexcept
{
return "::Slice::FileException";
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This exception is only used internally by the Slice compilers.
We never check or care about it's id. So why bother defining it.

Copy link
Member

Choose a reason for hiding this comment

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

Whenever we define a LocalException, it needs to be a proper LocalException, with an ice_id(). We should never "half-define" a LocalException.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is now a runtime_error instead of a LocalException.

It really has no business being a LocalException since it doesn't interact at all with the Ice runtime.
And none of the functionality offered by LocalExecption was ever used by it.

// First check if any 'xxx:identifier' has been applied to this element.
// If so, we return that instead of the element's Slice identifier.
const string metadata = languageName + ":identifier";
const string metadata = unit()->languageName() + ":identifier";
if (auto customName = getMetadataArgs(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.

This assert was to prevent us from calling mappedName in ice2slice (ice2slice should always use the Slice name).
But, there are helper functions in libSlice which use this function; Indirectly causing ice2slice to crash.

So I removed the assert.
We can self-police ourselves to not use mappedName in ice2slice.

@@ -610,11 +611,11 @@ Gen::TypesVisitor::visitSequence(const SequencePtr& p)
}
out << "<"
// TODO the generic argument must be the IceRPC C# mapped type
<< typeToString(p->type(), p->scope(), false) << ">\")]";
<< typeToString(p->type(), scope, false) << ">\")]";
Copy link
Member Author

Choose a reason for hiding this comment

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

We already store p->scope() in a variable.
No need to keep calling it over and over.

@@ -704,6 +704,7 @@ Gen::TypesVisitor::getOutput(const ContainedPtr& contained)
{
string outputName = getOutputName(_fileBase, _modules.size() > 1 ? scope : "");
unique_ptr<Output> out = make_unique<Output>(outputName.c_str());
FileTracker::instance()->addFile(outputName);
Copy link
Member Author

Choose a reason for hiding this comment

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

Whenever a Slice compiler creates a file/directory, it should let FileTracker know.

For ice2slice specifically, it calls FileTracker::cleanup() if something goes wrong:

//
// If a file could not be created, then clean up any created files.
//
FileTracker::instance()->cleanup();
But this call is useless without telling FileTracker which files were generated.

// First check if any 'xxx:identifier' has been applied to this element.
// If so, we return that instead of the element's Slice identifier.
const string metadata = languageName + ":identifier";
const string metadata = unit()->languageName() + ":identifier";
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 add metadata validation to ice2slice, otherwise in theory you could us the :identifier metadata to get unexpected behavior here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's actually a very sneaky find. I didn't see it, but you're right, a user could use :identifier to have an effect here.

But yes, we need to add validation which would reject bogus metadata like this. See: #3257.

@InsertCreativityHere InsertCreativityHere merged commit 190ab11 into zeroc-ice:main Apr 7, 2025
23 checks passed
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