Skip to content

Fix Windows when C compiler is ignorant of system module #3151

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

stevapple
Copy link
Contributor

@stevapple stevapple commented Mar 13, 2022

Both of the issues are raised because symbols CoreFoundation conflicts with the interface of WinSDK. Since these libraries are implementation only, they shouldn't become the interface of Foundation, so we should resolve the overload by manually pick up from WinSDK.

These problem blocks Foundation from compiling when C compiler has no knowledge of system module maps, which is the case for other platforms.

  • Fix usability of symbols imported from WinSDK
  • Fix ambiguous use of overloaded symbols

@stevapple stevapple changed the title Fix Windows Fix Windows when C compiler is ignorant of system module Mar 13, 2022
@stevapple
Copy link
Contributor Author

As long as this doesn't break current builds, I believe it's a worthy add-on -- can anyone trigger a Windows toolchain build?

@millenomi
Copy link
Contributor

I'm confused by this one; CF shouldn't be visible on Windows at all. @compnerd?

@compnerd
Copy link
Member

Yeah, CoreFoundation isn't visible on Windows, I don't think that this is about clients. This feels like it is papering over some other issue.

@stevapple
Copy link
Contributor Author

stevapple commented Mar 31, 2022

CF is visible to Foundation implementation itself — That’s why I met these problems here.

So far these problems are met:

  • Some symbols cannot be used from inline because CoreFoundation is implementation-only, so we need to declare them explicitly;
  • Type of some DWORD constants are mismatched: it should be UInt32, but CF regards it as Int32.

I think the first one is reasonable: we’re also meeting this on other platforms.

The second problem is because the constants defined in WinBase.h are literals without explicit type, so Swift regards it as signed by default. I wonder if there’s any more elegant solution here.

@millenomi
Copy link
Contributor

millenomi commented Mar 31, 2022

I think @compnerd fixed at least the latter on main with explicit typing. Can you recheck?

In general, Foundation reexports some amount of the C stdlib when imported — but on Windows that's CRT, not WinSDK. Why are we exporting HANDLE?

@stevapple
Copy link
Contributor Author

stevapple commented Apr 3, 2022

List of fixed issues

HANDLE visibility

Error:

S:\swift-corelibs-foundation\Sources\Foundation\FileHandle.swift:52:38: error: cannot use type alias 'HANDLE' here; 'CoreFoundation' has been imported as implementation-only
    public private(set) var _handle: HANDLE
                                     ^
CoreFoundation.HANDLE:1:18: note: type declared here
public typealias HANDLE = UnsafeMutableRawPointer

Fix (FileHandle.swift, Process.swift):

#if canImport(WinSDK)
// We used to get the alias that was re-exported by CoreFoundation
// but we want to explicitly depend on its types in this file,
// so we need to make sure Swift doesn't think it's @_implementationOnly.
import struct WinSDK.HANDLE
#endif

A bunch of undefined symbols

S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:124:51: error: cannot find 'NI_MAXHOST' in scope
            Array<WCHAR>(repeating: 0, count: Int(NI_MAXHOST))
                                                  ^~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:128:13: error: cannot find 'GetAdaptersAddresses' in scope
            GetAdaptersAddresses(ULONG(AF_UNSPEC), 0, nil, nil, &ulSize)
            ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:128:40: error: cannot find 'AF_UNSPEC' in scope
            GetAdaptersAddresses(ULONG(AF_UNSPEC), 0, nil, nil, &ulSize)
                                       ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:135:20: error: cannot find 'GetAdaptersAddresses' in scope
        ulResult = GetAdaptersAddresses(ULONG(AF_UNSPEC), 0, nil,
                   ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:135:47: error: cannot find 'AF_UNSPEC' in scope
        ulResult = GetAdaptersAddresses(ULONG(AF_UNSPEC), 0, nil,
                                              ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:136:76: error: cannot find 'IP_ADAPTER_ADDRESSES' in scope
                                        arAdapters.assumingMemoryBound(to: IP_ADAPTER_ADDRESSES.self),
                                                                           ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:140:44: error: cannot find type 'IP_ADAPTER_ADDRESSES' in scope
        var pAdapter: UnsafeMutablePointer<IP_ADAPTER_ADDRESSES>? =
                                           ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:145:49: error: cannot find type 'IP_ADAPTER_UNICAST_ADDRESS' in scope
          var arAddresses: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS> =
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:148:46: error: cannot find type 'IP_ADAPTER_UNICAST_ADDRESS' in scope
          var pAddress: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS>? =
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:153:18: error: cannot find 'GetNameInfoW' in scope
              if GetNameInfoW(pAddress!.pointee.Address.lpSockaddr,
                 ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:156:31: error: cannot find 'NI_NUMERICHOST' in scope
                              NI_NUMERICHOST) == 0 {
                              ^~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:209:22: error: cannot find type 'ADDRINFOW' in scope
          var hints: ADDRINFOW = ADDRINFOW()
                     ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:210:42: error: cannot find type 'ADDRINFOW' in scope
          memset(&hints, 0, MemoryLayout<ADDRINFOW>.size)
                                         ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:214:30: error: cannot find 'AI_PASSIVE' in scope
            hints.ai_flags = AI_PASSIVE | AI_CANONNAME
                             ^~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:214:43: error: cannot find 'AI_CANONNAME' in scope
            hints.ai_flags = AI_PASSIVE | AI_CANONNAME
                                          ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:216:30: error: cannot find 'AI_PASSIVE' in scope
            hints.ai_flags = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST
                             ^~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:216:43: error: cannot find 'AI_CANONNAME' in scope
            hints.ai_flags = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST
                                          ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:216:58: error: cannot find 'AI_NUMERICHOST' in scope
            hints.ai_flags = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST
                                                         ^~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:220:29: error: cannot find 'AF_UNSPEC' in scope
          hints.ai_family = AF_UNSPEC
                            ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:221:31: error: cannot find 'SOCK_STREAM' in scope
          hints.ai_socktype = SOCK_STREAM
                              ^~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:222:31: error: cannot find 'IPPROTO_TCP' in scope
          hints.ai_protocol = IPPROTO_TCP.rawValue
                              ^~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:224:46: error: cannot find type 'ADDRINFOW' in scope
          var aiResult: UnsafeMutablePointer<ADDRINFOW>?
                                             ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:227:16: error: cannot find 'GetAddrInfoW' in scope
            if GetAddrInfoW($0, nil, &hints, &aiResult) == 0 {
               ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:232:19: error: cannot find 'FreeAddrInfoW' in scope
          defer { FreeAddrInfoW(aiResult) }
                  ^~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:234:76: error: cannot find 'NI_MAXHOST' in scope
          var wszHostName: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(NI_MAXHOST))
                                                                           ^~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:237:25: error: cannot find type 'ADDRINFOW' in scope
            let aiInfo: ADDRINFOW = aiResult!.pointee
                        ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:238:25: error: cannot find type 'socklen_t' in scope
            var sa_len: socklen_t = 0
                        ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:241:18: error: cannot find 'AF_INET' in scope
            case AF_INET:
                 ^~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:243:18: error: cannot find 'AF_INET6' in scope
            case AF_INET6:
                 ^~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:242:24: error: cannot find 'socklen_t' in scope
              sa_len = socklen_t(MemoryLayout<sockaddr_in>.size)
                       ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:242:47: error: cannot find type 'sockaddr_in' in scope
              sa_len = socklen_t(MemoryLayout<sockaddr_in>.size)
                                              ^~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:244:24: error: cannot find 'socklen_t' in scope
              sa_len = socklen_t(MemoryLayout<sockaddr_in6>.size)
                       ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:244:47: error: cannot find type 'sockaddr_in6' in scope
              sa_len = socklen_t(MemoryLayout<sockaddr_in6>.size)
                                              ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:251:18: error: cannot find 'GetNameInfoW' in scope
              if GetNameInfoW(aiInfo.ai_addr, sa_len, &wszHostName,
                 ^~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:252:37: error: cannot find 'NI_MAXHOST' in scope
                              DWORD(NI_MAXHOST), nil, 0, flags) == 0 {
                                    ^~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:258:33: error: cannot find 'NI_NUMERICHOST' in scope
            lookup(&_addresses, NI_NUMERICHOST)
                                ^~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:259:29: error: cannot find 'NI_NAMEREQD' in scope
            lookup(&_names, NI_NAMEREQD)
                            ^~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:260:29: error: cannot find 'NI_NOFQDN' in scope
            lookup(&_names, NI_NOFQDN | NI_NAMEREQD)
                            ^~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\Host.swift:260:41: error: cannot find 'NI_NAMEREQD' in scope
            lookup(&_names, NI_NOFQDN | NI_NAMEREQD)
                                        ^~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:81:36: error: cannot find type 'KNOWNFOLDERID' in scope
    private class func url(for id: KNOWNFOLDERID) -> URL {
                                   ^~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:22:7: error: cannot find 'PathAllocCombine' in scope
      PathAllocCombine($0, $1, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &pszPath)
      ^~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:22:38: error: cannot find 'PATHCCH_ALLOW_LONG_PATHS' in scope
      PathAllocCombine($0, $1, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &pszPath)
                                     ^~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:37:27: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        guard hVolumes != INVALID_HANDLE_VALUE else { return nil }
                          ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:84:13: error: cannot find 'SHGetKnownFolderPath' in scope
            SHGetKnownFolderPath(id, DWORD(KF_FLAG_DEFAULT.rawValue), nil, &pszPath)
            ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:84:44: error: cannot find 'KF_FLAG_DEFAULT' in scope
            SHGetKnownFolderPath(id, DWORD(KF_FLAG_DEFAULT.rawValue), nil, &pszPath)
                                           ^~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:88:9: error: cannot find 'CoTaskMemFree' in scope
        CoTaskMemFree(pszPath)
        ^~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:100:42: error: cannot find 'FOLDERID_Desktop' in scope
            return [FileManager.url(for: FOLDERID_Desktop)]
                                         ^~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:104:42: error: cannot find 'FOLDERID_Documents' in scope
            return [FileManager.url(for: FOLDERID_Documents)]
                                         ^~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:113:46: error: cannot find 'FOLDERID_ProgramData' in scope
                return [FileManager.url(for: FOLDERID_ProgramData)]
                                             ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:115:46: error: cannot find 'FOLDERID_LocalAppData' in scope
                return [FileManager.url(for: FOLDERID_LocalAppData)]
                                             ^~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:122:42: error: cannot find 'FOLDERID_Downloads' in scope
            return [FileManager.url(for: FOLDERID_Downloads)]
                                         ^~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:126:42: error: cannot find 'FOLDERID_UserProfiles' in scope
            return [FileManager.url(for: FOLDERID_UserProfiles)]
                                         ^~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:130:42: error: cannot find 'FOLDERID_Videos' in scope
            return [FileManager.url(for: FOLDERID_Videos)]
                                         ^~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:134:42: error: cannot find 'FOLDERID_Music' in scope
            return [FileManager.url(for: FOLDERID_Music)]
                                         ^~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:138:42: error: cannot find 'FOLDERID_PicturesLibrary' in scope
            return [FileManager.url(for: FOLDERID_PicturesLibrary)]
                                         ^~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:142:42: error: cannot find 'FOLDERID_Public' in scope
            return [FileManager.url(for: FOLDERID_Public)]
                                         ^~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:146:42: error: cannot find 'FOLDERID_RecycleBinFolder' in scope
            return [FileManager.url(for: FOLDERID_RecycleBinFolder)]
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:207:30: error: cannot find 'INVALID_HANDLE_VALUE' in scope
            if hDirectory == INVALID_HANDLE_VALUE {
                             ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:274:31: error: cannot find 'PathCchStripToRoot' in scope
            let hr: HRESULT = PathCchStripToRoot(&szVolumePath, szVolumePath.count)
                              ^~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:340:22: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        if handle == INVALID_HANDLE_VALUE {
                     ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:368:39: error: cannot find 'FSCTL_GET_REPARSE_POINT' in scope
        guard DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, nil, 0,
                                      ^~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:454:21: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        if hFile == INVALID_HANDLE_VALUE {
                    ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:624:30: error: cannot find 'INVALID_HANDLE_VALUE' in scope
                if handle == INVALID_HANDLE_VALUE {
                             ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:690:17: error: cannot find 'INVALID_HANDLE_VALUE' in scope
          }) ?? INVALID_HANDLE_VALUE
                ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:691:24: error: cannot find 'INVALID_HANDLE_VALUE' in scope
          if handle == INVALID_HANDLE_VALUE { return false }
                       ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:769:22: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        if handle == INVALID_HANDLE_VALUE {
                     ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:818:15: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        }) ?? INVALID_HANDLE_VALUE
              ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:819:27: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        if path1Handle == INVALID_HANDLE_VALUE { return false }
                          ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:828:15: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        }) ?? INVALID_HANDLE_VALUE
              ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:829:27: error: cannot find 'INVALID_HANDLE_VALUE' in scope
        if path2Handle == INVALID_HANDLE_VALUE { return false }
                          ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:916:19: error: cannot find 'INVALID_HANDLE_VALUE' in scope
      if hFile == INVALID_HANDLE_VALUE {
                  ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:976:23: error: cannot find 'INVALID_HANDLE_VALUE' in scope
                }) ?? INVALID_HANDLE_VALUE
                      ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:977:30: error: cannot find 'INVALID_HANDLE_VALUE' in scope
                if handle == INVALID_HANDLE_VALUE { return firstValidItem() }
                             ^~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:1028:24: error: cannot find 'PathRelativePathToW' in scope
                return PathRelativePathToW(&relativePath, baseUrlFsr, fromAttrs, urlFsr, toAttrs)
                       ^~~~~~~~~~~~~~~~~~~

Fix (NSSwiftRuntime.swift):

@_exported import WinSDK.core

FILETIME overlay issue

Error:

S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:780:51: error: value of type 'FILETIME' (aka '_FILETIME') has no member 'time_t'
        statInfo.st_atime = info.ftLastAccessTime.time_t
                            ~~~~~~~~~~~~~~~~~~~~~ ^~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:781:49: error: value of type 'FILETIME' (aka '_FILETIME') has no member 'time_t'
        statInfo.st_ctime = info.ftCreationTime.time_t
                            ~~~~~~~~~~~~~~~~~~~ ^~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:800:50: error: value of type 'FILETIME' (aka '_FILETIME') has no member 'time_t'
        statInfo.st_mtime = info.ftLastWriteTime.time_t
                            ~~~~~~~~~~~~~~~~~~~~ ^~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:910:26: error: argument passed to call that takes no arguments
          FILETIME(from: time_t((accessTime ?? stat.lastAccessDate).timeIntervalSince1970))
                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:912:26: error: argument passed to call that takes no arguments
          FILETIME(from: time_t((modificationTime ?? stat.lastModificationDate).timeIntervalSince1970))
                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:1026:33: error: ambiguous use of operator '!='
                guard fromAttrs != INVALID_FILE_ATTRIBUTES, toAttrs != INVALID_FILE_ATTRIBUTES else {
                                ^
Swift.Equatable:2:24: note: found this candidate
    public static func != (lhs: Self, rhs: Self) -> Bool
                       ^
Swift.BinaryInteger:2:24: note: found this candidate
    public static func != (lhs: Self, rhs: Self) -> Bool
                       ^
Swift.BinaryInteger:3:24: note: found this candidate
    public static func != <Other>(lhs: Self, rhs: Other) -> Bool where Other : BinaryInteger
                       ^

Fix (FileManager+Win32.swift):

import struct WinSDK.FILETIME

Ambiguity of INVALID_FILE_ATTRIBUTES comparing

Error:

S:\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:1026:33: error: ambiguous use of operator '!='
                guard fromAttrs != INVALID_FILE_ATTRIBUTES, toAttrs != INVALID_FILE_ATTRIBUTES else {
                                ^
Swift.Equatable:2:24: note: found this candidate
    public static func != (lhs: Self, rhs: Self) -> Bool
                       ^
Swift.BinaryInteger:2:24: note: found this candidate
    public static func != (lhs: Self, rhs: Self) -> Bool
                       ^
Swift.BinaryInteger:3:24: note: found this candidate
    public static func != <Other>(lhs: Self, rhs: Other) -> Bool where Other : BinaryInteger
                       ^

Fix (FileManager+Win32.swift):

// FIXME: This is a workaround for CoreFoundation/WinSDK overload
// of the same constants with different types.  We should prevent
// CoreFoundation from re-exporting them.
fileprivate let INVALID_FILE_ATTRIBUTES = DWORD(bitPattern: -1)

Overloads of HANDLE_FLAG_INHERIT and STARTF_USESTDHANDLES

Error:

S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:502:39: error: ambiguous use of 'STARTF_USESTDHANDLES'
        siStartupInfo.dwFlags = DWORD(STARTF_USESTDHANDLES)
                                      ^
CoreFoundation.STARTF_USESTDHANDLES:1:12: note: found this candidate
public var STARTF_USESTDHANDLES: Int32 { get }
           ^
WinSDK.STARTF_USESTDHANDLES:1:12: note: found this candidate
public var STARTF_USESTDHANDLES: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:511:79: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
        defer { modifiedPipes.forEach { SetHandleInformation($0.handle, DWORD(HANDLE_FLAG_INHERIT), $0.prevValue) } }
                                                                              ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:518:81: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            modifiedPipes.append((handle: handle, prevValue: handleInfo & DWORD(HANDLE_FLAG_INHERIT)))
                                                                                ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:525:75: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(pipe.fileHandleForWriting._handle, DWORD(HANDLE_FLAG_INHERIT), 0)
                                                                          ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:535:56: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(handle._handle, DWORD(HANDLE_FLAG_INHERIT), 1)
                                                       ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:543:75: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(pipe.fileHandleForReading._handle, DWORD(HANDLE_FLAG_INHERIT), 0)
                                                                          ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:553:56: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(handle._handle, DWORD(HANDLE_FLAG_INHERIT), 1)
                                                       ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:561:75: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(pipe.fileHandleForReading._handle, DWORD(HANDLE_FLAG_INHERIT), 0)
                                                                          ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^
S:\swift-corelibs-foundation\Sources\Foundation\Process.swift:571:56: error: ambiguous use of 'HANDLE_FLAG_INHERIT'
            SetHandleInformation(handle._handle, DWORD(HANDLE_FLAG_INHERIT), 1)
                                                       ^
CoreFoundation.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: Int32 { get }
           ^
WinSDK.HANDLE_FLAG_INHERIT:1:12: note: found this candidate
public var HANDLE_FLAG_INHERIT: DWORD { get }
           ^

Fix (Process.swift):

// FIXME: This is a workaround for CoreFoundation/WinSDK overload
// of the same constants with different types.  We should prevent
// CoreFoundation from re-exporting them.
fileprivate let HANDLE_FLAG_INHERIT = DWORD(0x00000001)
fileprivate let STARTF_USESTDHANDLES = DWORD(0x00000100)

@stevapple stevapple force-pushed the fix-windows branch 3 times, most recently from 3ee4ed0 to f87197d Compare April 3, 2022 14:15
Symbols that are re-exported from @implementationOnly modules harms usability, so we explicitly import them from WinSDK.
Some constants are exported by CoreFoundation, but they has mismatched
type with WinSDK overlay.  Set them explicitly.
@stevapple
Copy link
Contributor Author

Any other questions on this pitch? @millenomi

@stevapple
Copy link
Contributor Author

Can you trigger a Windows build to see if anything breaks? @millenomi

@stevapple
Copy link
Contributor Author

Ping

@parkera
Copy link
Contributor

parkera commented Aug 9, 2022

Thanks @stevapple. One more question -- do we need to mark the import WinSDK as @_implementationOnly as well?

@stevapple
Copy link
Contributor Author

I'm afraid that's not possible👀 A small part of core WinSDK types have already been leaked into Foundation's interface.

@stevapple
Copy link
Contributor Author

Before merging this, could you please trigger a Windows toolchain build to verify that it doesn't break?

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.

4 participants