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

More Optional Class Cleanup #2262

Conversation

InsertCreativityHere
Copy link
Member

@InsertCreativityHere InsertCreativityHere commented Jun 3, 2024

This PR removes the public API for encoding/decoding classes from all the languages that still have it.
And changes our logic to throw an exception if we try to skip an optional class.
Note that it is still possible for users to send/receive optional classes if they use the lower-level stream API's, but we can only do so much here. A sufficiently motivated user will always find a way to send these.

It also brings all the tests back into alignment with one another, and removes the last place where we were manually sending/checking for optional classes using the stream APIs.


The error messages that were added to C++ and C# were different, so I standardized on cannot skip optional class.
This seemed the most consistent with our other error messages in the marshaling/unmarshaling logic:
cannot deserialize object, cannot unmarshal a proxy without a communicator, invalid Object slice, empty indirection table, etc. Feel free to comment alternatives.

@InsertCreativityHere InsertCreativityHere changed the title Final optional cleanup More Optional Class Cleanup Jun 3, 2024
@InsertCreativityHere InsertCreativityHere marked this pull request as ready for review June 4, 2024 13:57
@@ -29,7 +29,7 @@ function readPendingValues(obj)
end

function readValue(obj, cb)
%assert(~isempty(cb));
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why we have this commented out check... but it's safe to uncomment it now.
Empty patch functions should only be supplied when skipping an optional class.
This is now no longer possible.

Copy link
Member

Choose a reason for hiding this comment

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

See other comments.

Comment on lines -24 to -27
function r = readOptional(~, ~, ~)
r = false;
end

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 code was dead, so I removed it.

But, there's something fishy here.
In every other language, EncapsDecoder10 inherits this function as-is (since no 1.0 optional support) and EncapsDecoder11 overrides this function with a real implementation... Except in MATLAB, where we use a totally different code-path to reach the optional decoding implementation. I'm not sure why.

matlab/lib/+Ice/InputStream.m Outdated Show resolved Hide resolved
@@ -1622,43 +1622,6 @@ public void readValue(java.util.function.Consumer<Value> cb) {
readValue(cb, Value.class);
}
Copy link
Member

Choose a reason for hiding this comment

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

Please simplify the readValue above now that (presumably) the callback is never null.

@@ -2595,7 +2595,7 @@ private void skipOptional(OptionalFormat format)
}
case OptionalFormat.Class:
{
throw new MarshalException("cannot unmarshal or skip an \"optional class\" parameter or field");
throw new MarshalException("cannot skip an optional class");
Copy link
Member

Choose a reason for hiding this comment

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

Please simplify readValue above. The callback is non-nullable now.

@@ -1830,18 +1830,6 @@ class InputStream
});
}

readOptionalValue(tag, cb, T)
Copy link
Member

Choose a reason for hiding this comment

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

It's likely the cb in the readValue above can no longer be null.

@@ -239,7 +239,7 @@ public class InputStream {
case .FSize:
try skip(read())
case .Class:
try read(UnknownSlicedValue.self, cb: nil)
throw MarshalException(reason: "cannot skip an optional class")
Copy link
Member

Choose a reason for hiding this comment

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

Ditto - no more nil cb.

@@ -29,7 +29,7 @@ function readPendingValues(obj)
end

function readValue(obj, cb)
%assert(~isempty(cb));
Copy link
Member

Choose a reason for hiding this comment

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

See other comments.

@bernardnormier bernardnormier self-requested a review June 4, 2024 23:09
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.

Looks good.

I believe you forgot to update the InputStream C# code to remove nullable.

@InsertCreativityHere
Copy link
Member Author

I believe you forgot to update the InputStream C# code to remove nullable.

Which function are you talking about specifically?

For the main function that I touched: internal override void readValue(System.Action<Value?> cb)
I believe this is correct. The callback itself isn't nullable, but the value it receives is nullable because the decoding may of failed.

@bernardnormier
Copy link
Member

For the main function that I touched: internal override void readValue(System.Action<Value?> cb) I believe this is correct. The callback itself isn't nullable, but the value it receives is nullable because the decoding may of failed.

My mistake, the code is correct.

@InsertCreativityHere InsertCreativityHere merged commit 6f87143 into zeroc-ice:main Jun 5, 2024
17 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