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

Fixed POSIXError.Code for Linux #2113

Merged
merged 1 commit into from Apr 17, 2019
Merged

Conversation

colemancda
Copy link
Contributor

@colemancda colemancda commented Apr 14, 2019

Right now POSIXError is broken on Linux, with Foundation defining POSIXError.Code that is valid for Darwin, not Linux.

@CodaFi
Copy link
Member

CodaFi commented Apr 14, 2019

What's the policy on API breakage in Corelibs at this point @parkera @millenomi? I mean, I doubt there's very much code that is e.g. switching over every single error code.

@CodaFi
Copy link
Member

CodaFi commented Apr 14, 2019

@swift-ci please test

@colemancda
Copy link
Contributor Author

What's the policy on API breakage in Corelibs at this point @parkera @millenomi? I mean, I doubt there's very much code that is e.g. switching over every single error code.

All that code should still work, the new struct type is functionally the same as the enum only that init(rawValue: Int) is no longer synthesized by the compiler. So any existing switch statements or code that uses this type would continue to work the same was when it was an enum, the only exception would be when using Swift Reflection capabilities the type will be an struct and not enum anymore.

@CodaFi
Copy link
Member

CodaFi commented Apr 14, 2019

This will break:

func f(_ x : POSIXError.Code) {
  switch x {
  case .EPERM: //
  /*
  And so on
  */ 
  case .EQFULL: //
  }
}

We will now detect this as a non-exhaustive switch (all the enum patterns are now expression patterns).

@colemancda
Copy link
Contributor Author

colemancda commented Apr 14, 2019

This will break:

func f(_ x : POSIXError.Code) {
  switch x {
  case .EPERM: //
  /*
  And so on
  */ 
  case .EQFULL: //
  }
}

We will now detect this as a non-exhaustive switch (all the enum patterns are now expression patterns).

That is correct, but that code was invalid in the first place. This project is only used on non-Darwin platforms, and to my knowledge a non-exhaustive switch statement would be invalid anyway because this has been broken in Linux since 2016, not to mention different Linux kernel versions and other OS like BSD and Android would have different error codes entirely.

@CodaFi
Copy link
Member

CodaFi commented Apr 14, 2019

Hm, looks like this patch isn't quite rebased enough to build yet.

@colemancda
Copy link
Contributor Author

colemancda commented Apr 14, 2019

The error is that POSIXErrorCode is undefined on Linux, despite Glibc being imported.

/home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux@2/swift-corelibs-foundation/Foundation/NSError.swift:910:33: error: use of undeclared type 'POSIXErrorCode'
15:20:51         internal let errorCode: POSIXErrorCode
15:20:51                                 ^~~~~~~~~~~~~~

I don't see how that's possible since it is defined as part of the Glibc module apple/swift@8157194#diff-c86969eead9d9f63ad0faa3e75802e66R268.

As far as I can tell, POSIXErrorCode is still present https://github.com/apple/swift/blob/master/stdlib/public/Platform/POSIXError.swift#L271

colemancda added a commit to PureSwift/Bluetooth that referenced this pull request Apr 14, 2019
Should not use `POSIXError.Code` on Linux since it is currently broken.

apple/swift-corelibs-foundation#2113
colemancda added a commit to PureSwift/Bluetooth that referenced this pull request Apr 14, 2019
Use `POSIXErrorCode` to validate `errno` value.

apple/swift-corelibs-foundation#2113
@colemancda
Copy link
Contributor Author

POSIXError.Code is just a typealias on Darwin, so I changed the implementation to reflect that.

https://github.com/apple/swift/blob/577e04d35be3dba4954bd99eac5ef2af264c60b3/stdlib/public/Darwin/Foundation/NSError.swift#L2450

@colemancda
Copy link
Contributor Author

Depends on apple/swift#24028 for Glibc.POSIXErrorCode to be a valid identifier

colemancda added a commit to PureSwift/Bluetooth that referenced this pull request Apr 14, 2019
@colemancda
Copy link
Contributor Author

@CodaFi Please test again. Fixed any usage of POSIXError.Code with switch statements.

@spevans
Copy link
Collaborator

spevans commented Apr 14, 2019

@swift-ci test

@colemancda
Copy link
Contributor Author

@spevans For some reason seems the CI was never triggered.

colemancda added a commit to PureSwift/BluetoothLinux that referenced this pull request Apr 15, 2019
@spevans
Copy link
Collaborator

spevans commented Apr 15, 2019

@swift-ci test

@colemancda
Copy link
Contributor Author

@spevans Fixed invalid error code for Linux in 7998141
Please test again

@spevans
Copy link
Collaborator

spevans commented Apr 15, 2019

@swift-ci test

@colemancda
Copy link
Contributor Author

@spevans For some reason seems the CI was never triggered, again.

@spevans
Copy link
Collaborator

spevans commented Apr 15, 2019

@swift-ci test

@colemancda
Copy link
Contributor Author

@spevans The CI seems to be broken or just not responding.
@compnerd @drodriguez Any ideas on these CI issues?

@colemancda
Copy link
Contributor Author

Stuck at

Screen Shot 2019-04-15 at 10 58 46 AM

@drodriguez
Copy link
Collaborator

We don’t have more visibility than you to the CI machines (except the Android/Windows ones). You can look in https://ci.swift.org/job/swift-corelibs-foundation-PR-Linux/ to see if 2113 is in the left list. The last one I see is https://ci.swift.org/job/swift-corelibs-foundation-PR-Linux/2503/. Since apple/swift#24028 haven’t been merge, I think the “please test” invocations have to say so, so the CI is started with the right set of PRs.

@compnerd
Copy link
Collaborator

@swift-ci please test

Foundation/NSError.swift Outdated Show resolved Hide resolved
@colemancda
Copy link
Contributor Author

colemancda commented Apr 16, 2019

@compnerd To provide proper Windows support, we would need POSIXErrorCode defined in ucrt , similar to how Darwin and Glibc define POSIXErrorCode. Unfortunately that needs to be done in the compiler project, not here. Any thoughts?

@colemancda
Copy link
Contributor Author

@compnerd Added POSIXErrorCode for Windows to support Foundation on Windows.

apple/swift#24056

@pushkarnk
Copy link
Collaborator

@swift-ci test

@colemancda
Copy link
Contributor Author

I didn't break this

04:03:10 <unknown>:0: warning: missing submodule 'CoreFoundation'
04:03:10 
/home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux/swift-corelibs-xctest/Sources/XCTest/Public/XCTestMain.swift:20:23: error: missing required module 'CoreFoundation'
04:03:10     @_exported import Foundation
04:03:10

@compnerd
Copy link
Collaborator

@swift-ci please test Linux platform

@colemancda
Copy link
Contributor Author

@compnerd CI passed, ready to merge.

@CodaFi
Copy link
Member

CodaFi commented Apr 16, 2019

I still want confirmation from somebody at Apple that this is ready to go.

Ping @parkera @millenomi

@compnerd
Copy link
Collaborator

This seems reasonable to me, but @millenomi may have opinions on this.

@colemancda
Copy link
Contributor Author

colemancda commented Apr 17, 2019

For reference, POSIXError.Code was implemented as a duplicate enum previously, this PR removed that to match how the Foundation Swift overlay for Darwin is implemented, which just defines Foundation.POSIXError.Code as a typealias for Darwin.POSIXErrorCode.

https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/NSError.swift#L2450

@colemancda
Copy link
Contributor Author

@millenomi @parkera ?

@millenomi
Copy link
Contributor

Thank you for the ping — lots of traffic have pushed this a lot lower than I hoped.

@millenomi
Copy link
Contributor

It's good.

@millenomi millenomi merged commit d840648 into apple:master Apr 17, 2019
@colemancda colemancda deleted the posixErrorFix branch April 17, 2019 18:06
@compnerd
Copy link
Collaborator

This broke the windows build!

@colemancda
Copy link
Contributor Author

colemancda commented Apr 17, 2019

I would be happy to assist you in fixing it, but it shouldn't break, please take a look at apple/swift#24056 as long as that is compiling correctly, POSIXErrorCode should be defined for Darwin, Linux and Windows.

Are you compiling the compiler again before Foundation, or in separate steps? This will only work for a compiler built after apple/swift#24056

@compnerd
Copy link
Collaborator

@colemancda - that change is merged and is available, but, Im still seeing a ton of undefined values (e.g. ETOOMANYREFS)

@compnerd
Copy link
Collaborator

In fact, it has hit the CI too: https://dev.azure.com/compnerd/windows-swift/_build/results?buildId=1431

@colemancda
Copy link
Contributor Author

Ok, I am going to introduce a patch to fix that, I know where the issue is.

@colemancda
Copy link
Contributor Author

Windows build fixed in #2130

@shahmishal
Copy link
Member

We are seeing a failure on swift-5.1-branch due to this change:

https://ci.swift.org/view/swift-5.1-branch/job/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/475/

/home/buildnode/jenkins/workspace/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/swift-corelibs-foundation/Foundation/NSError.swift:919:29: error: use of undeclared type 'POSIXErrorCode'
01:25:06.442     public typealias Code = POSIXErrorCode
01:25:06.442                             ^~~~~~~~~~~~~~
01:25:06.442 /home/buildnode/jenkins/workspace/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/swift-corelibs-foundation/Foundation/NSError.swift:922:11: error: use of undeclared type 'POSIXErrorCode'
01:25:06.442 extension POSIXErrorCode: _ErrorCodeProtocol {
01:25:06.442           ^~~~~~~~~~~~~~
01:25:06.442 /home/buildnode/jenkins/workspace/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/swift-corelibs-foundation/Foundation/NSError.swift:908:15: error: type 'POSIXError' does not conform to protocol '_BridgedStoredNSError'
01:25:06.442 public struct POSIXError : _BridgedStoredNSError {
01:25:06.442               ^
01:25:06.442 /home/buildnode/jenkins/workspace/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/swift-corelibs-foundation/Foundation/NSError.swift:486:20: note: protocol requires nested type 'Code'; do you want to add it?
01:25:06.442     associatedtype Code: _ErrorCodeProtocol
01:25:06.442                    ^
01:25:06.442 /home/buildnode/jenkins/workspace/oss-swift-5.1-incremental-RA-linux-ubuntu-18_04/swift-corelibs-foundation/Foundation/NSError.swift:352:31: warning: conditional cast from 'Self' to 'NSError' always succeeds
01:25:06.442         if let nsError = self as? NSError {
01:25:06.442                               ^
01:25:06.442 ninja: build stopped: subcommand failed.

cc/ @colemancda @millenomi @compnerd

@shahmishal
Copy link
Member

This is blocking PR testing on swift-5.1-branch of apple/swift

@colemancda
Copy link
Contributor Author

colemancda commented Apr 17, 2019

Incremental builds are not going to work, this PR requires the Swift compiler to be built with apple/swift#24028 included. It seems the failure is due to building with a version of Swift that does not include that fix.

@colemancda
Copy link
Contributor Author

@shahmishal Please see apple/swift#24028

@shahmishal
Copy link
Member

@colemancda has apple/swift#24028 already been cherry-picked into swift-5.1-branch?

@colemancda
Copy link
Contributor Author

@shahmishal So either the compiler's swift-5.1-branch need to be updated with latest master commits, or just that single commit is needs to be merged apple/swift@787bc36

@shahmishal
Copy link
Member

if not, please create a PR for swift-5.1-branch.

@colemancda
Copy link
Contributor Author

Ok

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.

None yet

9 participants