Skip to content

Runtime: Fix runtime type resolution when mangled names refer to protocol extensions with Self same type constraints. #74997

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

Conversation

jckarter
Copy link
Contributor

@jckarter jckarter commented Jul 5, 2024

…ocol extensions with Self same type constraints.

If a type or opaque type descriptor appears inside of a protocol extension of the form:

extension P where Self == Nominal { ... }

then the runtime representation of the extension context was interpreted by the runtime demangler as a nominal type extension, even though the parameterization is on the <Self> generic signature of the protocol extension and not the generic signature of the nominal type. This would cause spurious rejection of mangled names referencing the extension context because we mistakenly thought that the type arguments mismatched with the nominal type signature rather than matching them to the extension context.

Add some code to _findExtendedTypeContextDescriptor to detect when an extension is a protocol extension with a Self == SameType constraint, and pass the extension along rather than treating it as a nominal type extension. Fixes rdar://130168101.

@jckarter
Copy link
Contributor Author

jckarter commented Jul 5, 2024

@swift-ci Please test

@al45tair
Copy link
Contributor

al45tair commented Jul 8, 2024

macOS failure was about availability of some return types; either needs the minimum system version to be higher or some @available annotations.

…ocol extensions with Self same type constraints.

If a type or opaque type descriptor appears inside of a protocol extension of the form:

```
extension P where Self == Nominal { ... }
```

then the runtime representation of the extension context was interpreted by the runtime
demangler as a nominal type extension, even though the parameterization is on the
`<Self>` generic signature of the protocol extension and not the generic signature of
the nominal type. This would cause spurious rejection of mangled names referencing the
extension context because we mistakenly thought that the type arguments mismatched with
the nominal type signature rather than matching them to the extension context.

Add some code to `_findExtendedTypeContextDescriptor` to detect when an extension is
a protocol extension with a `Self == SameType` constraint, and pass the extension along
rather than treating it as a nominal type extension. Fixes rdar://130168101.
@jckarter jckarter force-pushed the protocol-extension-self-same-type-runtime-resolution branch from baddbb5 to e0df8ff Compare July 8, 2024 14:41
@jckarter
Copy link
Contributor Author

jckarter commented Jul 8, 2024

@swift-ci Please test

@@ -402,6 +402,38 @@ _findExtendedTypeContextDescriptor(const ContextDescriptor *maybeExtension,
Demangle::NodePointer &node = demangledNode ? *demangledNode : localNode;

auto mangledName = extension->getMangledExtendedContext();

// A extension of the form `extension Protocol where Self == ConcreteType`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// A extension of the form `extension Protocol where Self == ConcreteType`
// An extension of the form `extension Protocol where Self == ConcreteType`

Extreme nitpick.

@jckarter
Copy link
Contributor Author

jckarter commented Jul 8, 2024

@swift-ci Please test macOS

@jckarter jckarter merged commit dfc5321 into swiftlang:main Jul 9, 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.

3 participants