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

Runtime: Don't append local discriminators to locally defined type names. #14332

Closed
wants to merge 1 commit into from

Conversation

5at5ish
Copy link
Contributor

@5at5ish 5at5ish commented Feb 1, 2018

If a type was defined locally, a printed representation of an instance of that
type would contain a local discriminator. Introducing an additional demangling
option allows to opt out of this behaviour.

Resolves SR-6787.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up, Timur!

@@ -67,6 +68,7 @@ struct DemangleOptions {
Opt.ShortenThunk = true;
Opt.ShortenValueWitness = true;
Opt.ShortenArchetype = true;
Opt.ShowLocalDiscriminators = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this one be false, since ShowPrivateDiscriminators and DisplayModuleNames are also false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check fails if it's false. We could customize options here, to address that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would just pass -Xllvm -sil-full-demangle for that one test.

@@ -100,6 +100,7 @@ static void _buildNameForMetadata(const Metadata *type,

Demangle::DemangleOptions options;
options.QualifyEntities = qualified;
options.ShowLocalDiscriminators = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one probably goes with qualified, like ShowPrivateDiscriminators. Because…

expectEqual(String(describing: type(of: t)), "LocalType")
}

StringDescribingTestSuite.test("String(reflecting:) shouldn't include local discriminator") {
Copy link
Contributor

Choose a reason for hiding this comment

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

String(reflecting:) should give a unique answer for every unique type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should assertion message be reworded?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, like the one for private discriminators.

…mes.

If a type was defined locally, a printed representation of an instance of that
type would contain a local discriminator. Introducing an additional demangling
option allows to opt out of this behaviour.

Resolves: SR-6787.
@5at5ish
Copy link
Contributor Author

5at5ish commented Feb 2, 2018

@jrose-apple Addressed your comments.

let representation = String(reflecting: type(of: t))

expectEqual(representation.prefix(6), "main.(")
expectEqual(representation.suffix(11), ").LocalType")
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, now we should be checking that the "#1" is there. Doesn't this fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't fail. Isn't it expected behaviour for locally defined types?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, no. If String(reflecting:) uniquely identifies a type, that means it has to include the "#1". Maybe look for where else ShowPrivateDiscriminators is set to true? Or just combine the two settings, since I can't think why we'd ever want them to be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like after merging this change, the logic should be reconsidered.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that affects this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment to the ticket.

@CodaFi
Copy link
Member

CodaFi commented Nov 14, 2019

There's been a change in the descriptor format and part of this was addressed by #12298. I'm going to close this out. Thank you for taking a look at this issue!

@CodaFi CodaFi closed this Nov 14, 2019
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.

None yet

3 participants