Open
Description
Previous ID | SR-15757 |
Radar | None |
Original Reporter | @lxbndr |
Type | Bug |
Attachment: Download
Environment
Windows 10
compnerd.org Swift version 5.5.2-dev (LLVM d461fd52e58eca6, Swift e6979d24987b522)
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler, Foundation |
Labels | Bug |
Assignee | @compnerd |
Priority | Medium |
md5: 349f7f16ee058b9b9b9d1effa84062f2
Issue Description:
It is impossible to subclass Foundation.InputStream
on the 5.5 release branch (as well as on the main
branch). The issue is reproducible with a few lines of code:
import Foundation
public class CustomStream: InputStream {}
Running compiler directly:
swiftc -parse-as-library -emit-library -sdk %SDKROOT% x06.swift -o x06.dll
Produces the following error:
x06.swift:3:14: error: cannot inherit from class 'InputStream' because it has overridable members that could not be loaded
public class CustomStream: InputStream {}
^
Additional observations
-
Rebuilding Foundation with
-enable-library-evolution
makes it possible to compile the sample code -
Rebuilding Foundation with enabled testability also helps
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
compnerd commentedon Jan 20, 2022
+@millenomi
compnerd commentedon Jan 20, 2022
My suspicion is that we are seeing some behavioural differences due to the
@_implementationOnly
import ofCoreFoundation
which was something that we did as CoreFoundation should not be exposed. However, in the process some internals may have accidentally been removed from serialization into the interface and the vtable entry therefore devirtualized, resulting in the failure to subclassInputStream
.millenomi commentedon Jan 20, 2022
What's happening here is that Windows is the first platform where CoreFoundation is not exposed, and thus entirely `_implementationOnly`. There is a fileprivate constructor in InputStream that takes a CF type, which apparently ends up in the vtable 🙁
The solution here is to turn any constructor of the form:
into:
millenomi commentedon Jan 20, 2022
This occurs outside of Windows, it's just masked by source compatibility requiring us to expose the CoreFoundation module publicly.
compnerd commentedon Jan 21, 2022
Exploring this a bit further: I think that there is a set of cases that are impacted here. Rather than trying to think through this, I decided for an empirical approach. I believe that the following should identify the full set of issues.
This identified the following cases where problems occur:
compnerd commentedon Jan 21, 2022
Added a test case that should reproduce the behaviour on any platform. The root of the issue is that we do need the values to be potentially in the vtable (if they are overridden locally). The values therefore are serialised out to the swiftmodule. However, on deserialisation, we need to treat the holes specially as they cannot be overridden.
compnerd commentedon Jan 22, 2022
swiftlang/swift#40972 helps to a certain extent, there is one last case which isn't solved involving
enum
storage.