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

Better support CoreFoundation types in RemoteMirror #76586

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Sep 19, 2024

This plugs a hole where we failed to recognize a CF type when it appeared as the payload of an enum stored as a property. Curiously, RemoteMirror is able to reflect this when the enum appears by itself, just not when it's stored as a property.

The simplest fix is to hook into the calculation which computes a TypeInfo (basically, the tree of fields) from a TypeRef (basically, the name of the type, including generic context). Specifically, we sometimes end up here with a "type alias" that none of the lookup support seems to be able to handle. Fortunately, these aliases demangle into a pretty predictable shape, so this just pattern-matches the specific demangle tree shape to recognize these as "type aliases in the __C module whose name starts with CF and ends with Ref".

Resolves rdar://82465109

This plugs a hole where we failed to recognize a CF type when it
appeared as the payload of an enum stored as a property.  Curiously,
RemoteMirror is able to reflect this when the enum appears by itself,
just not when it's stored as a property.

The simplest fix is to hook into the TypeInfo calculation which
computes a TypeInfo (basically, the tree of fields) from a TypeRef
(basically, the name of the type, including generic context).
Specifically, we sometimes end up here with a "type alias" that
none of the lookup support seems to be able to handle.  Fortunately,
these aliases demangle into a pretty predictable shape, so this
just pattern-matches the specific demangle tree shape to recognize
these as "type aliases in the `__C` module whose name starts with `CF`
and ends with `Ref`".

Resolves rdar://82465109
@tbkka tbkka requested review from slavapestov and a team as code owners September 19, 2024 21:01
@tbkka
Copy link
Contributor Author

tbkka commented Sep 19, 2024

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented Sep 19, 2024

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented Sep 19, 2024

@swift-ci Please test

&& Name->getKind() == Node::Kind::Identifier
&& Name->hasText()) {
auto CName = Name->getText();
// Heuristic: Hopefully good enough.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could go out and find a matching foreign type descriptor to get a definitive answer about what the type is. But that would be a lot more difficult, and this heuristic should definitely be good enough. We can keep that in our pocket in case this doesn't work right somewhere.

@tbkka
Copy link
Contributor Author

tbkka commented Sep 20, 2024

Looks like an unrelated failure in a SIL test.

@tbkka
Copy link
Contributor Author

tbkka commented Sep 20, 2024

@swift-ci Please test Linux platform

@tbkka tbkka merged commit 5d5627a into swiftlang:main Sep 20, 2024
5 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.

2 participants