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

[SR-617] Self not always resolved dynamically with Generics #43234

Closed
AliSoftware opened this issue Jan 25, 2016 · 6 comments
Closed

[SR-617] Self not always resolved dynamically with Generics #43234

AliSoftware opened this issue Jan 25, 2016 · 6 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@AliSoftware
Copy link
Contributor

Previous ID SR-617
Radar rdar://problem/33690383
Original Reporter @AliSoftware
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, TypeChecker
Assignee @slavapestov
Priority Medium

md5: a5f1b5e1cecbc488866a6715ac310ea5

is duplicated by:

  • SR-1786 Wrong behaviour of protocol extension static methods
  • SR-5347 Adding a protocol requirement with a default is source-breaking

Issue Description:

Summary

In a function using Generics, the generic type will sometimes resolve Self statically instead of dynamically:

@belkadan
Copy link
Contributor

cc @DougGregor

@DougGregor
Copy link
Member

@rjmccall

The protocol-extension implementation of the typeDescription getter has this:

define hidden { i8*, i64, i64 } @_TZFeRq_1t15TypeDescribable_S_S0_g15typeDescriptionSS(%swift.type*, %swift.type* %Self, i8** %Self.TypeDescribable) #0 {
entry:
%Self1 = alloca %swift.type*, align 8
%1 = alloca %swift.type*, align 8
store %swift.type* %Self, %swift.type** %Self1, align 8
store %swift.type* %Self, %swift.type** %1, align 8
%2 = bitcast %swift.type** %1 to %swift.opaque*
%3 = call %swift.type* @swift_getMetatypeMetadata(%swift.type* %Self) #4

which looks like it's passing the 'Self' type of the witness table rather than the 'Self' type passed into this static member.

@rjmccall
Copy link
Member

The problem is that the Self archetype is not being bound to the dynamic type of the class, and the fix is that protocol witness thunks of protocol extension methods for conformances by non-final classes need to open the dynamic type and use that in the substitution they use when invoking the extension method.

That's going to require some non-trivial implementation work, though.

@swift-ci
Copy link
Collaborator

Comment by Marcus Smith (JIRA)

I'm running into this exact same problem as well, has there been any progress on this?

I'm happy to help in any way I can, but my code looks almost identical to what's already in the gist in the description.

@slavapestov
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

#12174

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

6 participants