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 Swift Metadata #3533

Merged

Conversation

InsertCreativityHere
Copy link
Member

@InsertCreativityHere InsertCreativityHere commented Feb 11, 2025

This PR removes the swift:inherits metadata, and implements #3529 (we no longer require re-openings of the same module with swift:module metadatas to have the same 'prefix' argument)

EDIT: It also now changes all the identifiers in the scope tests.

@InsertCreativityHere InsertCreativityHere requested review from bernardnormier and externl and removed request for bernardnormier February 11, 2025 19:45
@InsertCreativityHere InsertCreativityHere marked this pull request as ready for review February 11, 2025 20:58
@@ -683,36 +670,6 @@ SwiftGenerator::validateSwiftModuleMappings(const UnitPtr& unit)
<< current->second << "'" << endl;
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 keep the message on a single line, no \n.

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 didn't even notice this was split up. Fixed.

ModuleMap mappedModules;
// With a given Swift module a Slice module has to map to a single prefix
std::map<std::string, ModuleMap> mappedModulePrefixes;
// Each Slice unit has to map all top-level modules to a single Swift module.
Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful to describe what this map is. It seems to be a map filename -> swift module 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.

The map was deleted.
The previous check was being applied to all files, even included ones.
This seemed over-zealous to me. Now we only check the single file that is being compiler.

And since we're only checking one file, we don't need a file-name map anymore.

// With a given Swift module a Slice module has to map to a single prefix
std::map<std::string, ModuleMap> mappedModulePrefixes;
// Each Slice unit has to map all top-level modules to a single Swift module.
map<string, string> mappedModules;

// Any modules that are directly contained on the unit are (by definition) top-level modules.
// And since there is only one unit per compilation, this must be all the top-level modules.
for (const auto& module : unit->modules())
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 not use module as a variable name. It's an identifier with special meaning in C++20: https://en.cppreference.com/w/cpp/keyword

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.
I renamed it to mod.

@@ -201,6 +201,36 @@ func allTests(helper: TestHelper) async throws {
try test(cmap3["a"]!!.s == s1)
}

do {
let obj = try communicator.stringToProxy("dpi:\(helper.getTestEndpoint())")!
Copy link
Member

Choose a reason for hiding this comment

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

No stringToProxy followed by checkedCast in new code, please!

If you want to test ice_isA, call ice_isA.

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 was just copy-pasting from the lines above.
I removed all the checkedCast calls from this test; all of them were superfluous.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't remember the preferred syntax, check the top-level CHANGELOG-3.8.md or the greeter demo:

// Swift
let greeter = try makeProxy(
  communicator: communicator,
  proxyString: "greeter:tcp -h localhost -p 4061",
  type: GreeterPrx.self)

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 wasn't familiar enough with Swift to remember that we supported this there.
I updated scope in Swift to use makeProxy. The other languages were all already correct.


module Inner2
// Check that it's okay for 'swift:module' to have different 'prefix' arguments.
Copy link
Member

Choose a reason for hiding this comment

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

I am sure we can test this "feature" with a simpler test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I also want to make sure that it gets mapped to the correct place as well.
Not just that "the compiler doesn't issue an error anymore".

Because we don't have a test for the swift:module anywhere, and scope felt like an adequate place to put it.
Since the point of the metadata is changing the mapped scopes.


void shutdown();
interface I
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 definitely never name an interface 'I'.

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 was just being consistent with the rest of this test.
I updated the scope tests to use better names.

Test::C opC(Test::C c1, out Test::C c2);
Test::CSeq opCSeq(Test::CSeq c1, out Test::CSeq c2);
Test::CMap opCMap(Test::CMap c1, out Test::CMap c2);
long l;
Copy link
Member

Choose a reason for hiding this comment

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

Trying hard to find the worse names?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, just following our old 'conventions'!
I updated almost all of the names in this test to be less horrible.

@@ -201,6 +201,36 @@ func allTests(helper: TestHelper) async throws {
try test(cmap3["a"]!!.s == s1)
}

do {
let obj = try communicator.stringToProxy("dpi:\(helper.getTestEndpoint())")!
Copy link
Member

Choose a reason for hiding this comment

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

If you don't remember the preferred syntax, check the top-level CHANGELOG-3.8.md or the greeter demo:

// Swift
let greeter = try makeProxy(
  communicator: communicator,
  proxyString: "greeter:tcp -h localhost -p 4061",
  type: GreeterPrx.self)

@InsertCreativityHere InsertCreativityHere merged commit 6dbee6f into zeroc-ice:main Feb 18, 2025
22 of 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.

3 participants