Skip to content

[Runtime] Fix private generic type witness demangling failure #25611

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 1 commit into from
Jun 20, 2019

Conversation

beccadax
Copy link
Contributor

This one’s screwily specific—if you have:

  • a private generic type,
  • with a nested generic type in it,
  • and the nested type conforms to a protocol with an associated type,
  • and that associated type’s witness is a generic type,
  • and some of the witness type’s generic parameters are generic parameters of the nested type,

demangling would fail. The problem is that the substitution machinery in the runtime would consider there to be three, not two, generic context depths involved. Depth 1, which should correspond to the nested type, would instead have no generic parameters. The fix is to skip over depths with zero generic parameters.

Fixes rdar://problem/47773183.

This one’s screwily specific—if you have:

* a private generic type,
* with a nested generic type in it,
* and the nested type conforms to a protocol with an associated type,
* and that associated type’s witness is a generic type,
* and some of the witness type’s generic parameters are generic parameters of the nested type,

demangling would fail. The problem is that the substitution machinery in the runtime would consider there to be three, not two, generic context depths involved. Depth 1, which should correspond to the nested type, would instead have no generic parameters. The fix is to skip over depths with zero generic parameters.

Fixes <rdar://problem/47773183>.
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Jun 19, 2019

Note: This fix works, but I feel like the compiler might actually be generating incorrect metadata too. In the test case, the generic context descriptor appears to include these depths:

0: Anonymous context for private types
1: Parent<ParentType>
2: Nested<First, Second>

But before this bug fix, it was attributing the generic parameters to these depths:

0: ParentType
1: (none)
2: First, Second

It seems to me like the anonymous context probably shouldn't be counted as a depth (its isGeneric flag is set; maybe it shouldn't be?), but my understanding might be flawed.

@beccadax beccadax requested review from DougGregor and jckarter June 19, 2019 18:54
@jckarter
Copy link
Contributor

Yeah, it should be correct to skip over anonymous contexts, since those are only runtime representation and don't have any correspondence to the depths used by mangled references.

@beccadax beccadax merged commit 4149c8f into swiftlang:master Jun 20, 2019
beccadax added a commit to beccadax/swift that referenced this pull request Jun 20, 2019
…ang#25611)

This one’s screwily specific--if you have:

* a private generic type,
* with a nested generic type in it,
* and the nested type conforms to a protocol with an associated type,
* and that associated type’s witness is a generic type,
* and some of the witness type’s generic parameters are generic parameters of the nested type,

demangling would fail. The problem is that the substitution machinery in the runtime would consider there to be three, not two, generic context depths involved. Depth 1, which should correspond to the nested type, would instead have no generic parameters. The fix is to skip over depths with zero generic parameters.

Fixes <rdar://problem/47773183>.
@beccadax beccadax deleted the nested-private-witness-crasher branch June 20, 2019 19:07
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