Skip to content

RemoteMirror generic multi-payload-enum fixes #41903

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

Merged
merged 4 commits into from
Mar 28, 2022

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Mar 18, 2022

Apparently, RemoteMirror chokes on certain MPEs with generic payload types.
It does not recognize the generic payload type so ends up defaulting to a
zero size. This causes the overall enum size to be miscalculated unless there
is another non-generic payload that's at least as large.

Resolves rdar://90490128

Apparently, RemoteMirror chokes on certain MPEs with generic payload types.
It does not recognize the generic payload type so ends up defaulting to a
zero size.  This causes the overall enum size to be miscalculated unless there
is another non-generic payload that's at least as large.

Step 1: Test case
@tbkka
Copy link
Contributor Author

tbkka commented Mar 18, 2022

First step: Test case.

@tbkka
Copy link
Contributor Author

tbkka commented Mar 18, 2022

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented Mar 21, 2022

✅Test fails.

@tbkka
Copy link
Contributor Author

tbkka commented Mar 22, 2022

The underlying issue seems to be that when you have a generic multi-payload enum inside a generic class, we need to resolve a generic type parameter with depth "1". That in turn requires that the layout computations for the enum be able to follow the parent link to the class type. For some reason, that parent link is not being uniformly populated: running in the debugger, I can see places where the type has a parent link and other places where it doesn't. (This could be related to the fact that I'm seeing multiple independent typerefs for the same type.)

tbkka added 2 commits March 25, 2022 14:16
This particular case requires us to reprocess the metatype to "thicken" it.
That process inadvertently lost information about the depth of generic
nesting, which caused the RemoteMirror to be unable to resolve the type of
`C.E.t` at runtime.
```
  class C<T> {
    enum E<T> {
    case t(T)
    case u(Int)
    }
    var e: E<T>?
  }
```

This adds code to the thickening logic to preserve parent-type
information, which allows us to properly handle nested generic
types of this sort.

Resolves rdar://90490128
@tbkka
Copy link
Contributor Author

tbkka commented Mar 25, 2022

Thanks to @slavapestov for pointing me to the right fix for this. The "metatype thickening" logic was inadvertently dropping information about the surrounding generic type when you had nested generics. The solution was to recursively thicken the parent in this case.

@tbkka
Copy link
Contributor Author

tbkka commented Mar 25, 2022

@swift-ci Please test

@tbkka
Copy link
Contributor Author

tbkka commented Mar 26, 2022

Most recent tests passed everywhere except on 32-bit (expected because the sizes are different there). I fixed up the test accordingly and it should pass now.

@tbkka
Copy link
Contributor Author

tbkka commented Mar 28, 2022

@swift-ci Please test

@tbkka tbkka requested a review from slavapestov March 28, 2022 20:55
@tbkka tbkka merged commit 1232424 into swiftlang:main Mar 28, 2022
@tbkka tbkka deleted the tbkka-remoteMirror-genericMPE branch August 1, 2024 16:37
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.

1 participant