Skip to content

Initial Swift3 wrapping overlay for libdispatch #94

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
Jul 1, 2016

Conversation

dgrove-oss
Copy link
Contributor

@dgrove-oss dgrove-oss commented Jun 28, 2016

A useful checkpoint along the way to a complete implementation of
the Swift3 overlay for libdispatch on non-Objective C platforms.
The overlay code builds successfully and simple example programs
using queues and timers work as expected.

The basic approach is to wrap the C libdispatch objects in Swift
objects and make the C dispatch APIs available internally via the
CDispatch module.

A few pieces (marked with FIXME) are ifdefed out to avoid compilation
problems (will get back to them in later commits) or still need to
be implemented (release on deinit).

Although the installed libdispatch can be used in Swift programs via
'import Dispatch', the swiftc command for the client program currently
needs to pass additional command line flags (to be fixed later). For example:
swiftc -Xcc -fblocks -Xcc -D__DISPATCH_BUILDING_SWIFT_MODULE__=1 Forever.swift

@dgrove-oss dgrove-oss force-pushed the swift3-overlay-pr1 branch from d2152e1 to 759e8f8 Compare June 29, 2016 14:57
public enum Deallocator {
/// Use `free`
case free

#if HAVE_MACH

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a mach specific thing from my understanding for dispatch: it probably could be just like the backing for Data;
https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift#L19

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right. I was mentally mapping this deallocator to DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE which is guarded by HAVE_MACH in data.c. It probably makes sense to implement similar functionality via munmap on Linux.

@mwwa
Copy link
Contributor

mwwa commented Jun 29, 2016

Things look pretty good here, the _swift_dispatch_source_type_signal bug is really the only thing that should block the review itself (and that pre-existing bug is my fault, not yours).

@dgrove-oss dgrove-oss force-pushed the swift3-overlay-pr1 branch from 65bf634 to c1afdcb Compare June 29, 2016 20:44
@dgrove-oss
Copy link
Contributor Author

Squashed & forced pushed to consolidate back to a single commit. Thanks for the feedback!

@phausler
Copy link

In an attempt to see if this can resolve some of the other issues I was having I ran a build of this and it is failing from:

/usr/bin/ld: /home/phausler/Documents/Public/build/Ninja-RelWithDebInfoAssert/libdispatch-linux-x86_64/src/swift/Block.o: relocation R_X86_64_PC32 against protected symbol `_TMaV8Dispatch21DispatchWorkItemFlags' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value


public protocol DispatchSourceType {
#if false // crashes the swift compiler
typealias DispatchSourceHandler = @convention(block) () -> Void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an associatedtype no?

@dgrove-oss
Copy link
Contributor Author

Re the linker error, the workaround is to use the gold linker. As a hack, I just changed the /usr/bin/ld symlink on my system to point to /usr/bin/ld.gold. From the various email discussions about linking I'd expect a more principled fix for all of Swift to use the gold linker should be coming soon

@seabaylea
Copy link
Contributor

Adding -fuse-ld=gold as a linker flag should work. I added that to experimental/foundation to get past the same issue. That's the approach used by the other core libraries.

@dgrove-oss
Copy link
Contributor Author

Thanks for the pointer to the ld.gold change Chris; I picked it up for this changeset and confirm it works (undid the hack on my system of linking /usr/bin/ld to ld.gold).

SOURCE(MACH_SEND)
SOURCE(MACH_RECV)
SOURCE(MEMORYPRESSURE)
#endif
SOURCE(PROC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc should be ignored too

@dgrove-oss
Copy link
Contributor Author

I've updated taking into account @MadCoder's comments on usage of HAVE_MACH and the vnode source.

It wasn't clear to me if you had converged on the API for DataOr/DataAdd, so I didn't do anything there yet.

@dgrove-oss dgrove-oss force-pushed the swift3-overlay-pr1 branch from a8bd36d to f81a0bd Compare June 30, 2016 21:41
A useful checkpoint along the way to a complete implementation of
the Swift3 overlay for libdispatch on non-Objective C platforms.
The overlay code builds successfully and simple example programs
using queues and timers work as expected.

The basic approach is to wrap the C libdispatch objects in Swift
objects and make the C dispatch APIs available internally via the
CDispatch module.

A few pieces (marked with FIXME) are ifdefed out to avoid compilation
problems (will get back to them in later commits) or still need to
be implemented (release on deinit).

Although the installed libdispatch can be used in Swift programs via
'import Dispatch', the swiftc command for the client program currently
needs to pass additional command line flags (to be fixed later). For example:
  swiftc -Xcc -fblocks -Xcc -D__DISPATCH_BUILDING_SWIFT_MODULE__=1 Forever.swift
@dgrove-oss dgrove-oss force-pushed the swift3-overlay-pr1 branch from f81a0bd to a38736c Compare June 30, 2016 21:52
func setRegistrationHandler(qos: DispatchQoS, flags: DispatchWorkItemFlags, handler: DispatchSourceHandler?)

func setRegistrationHandler(handler: DispatchWorkItem)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the eventHandler functions of the DispatchSourceType protocol to match the functions defined in the extension in Source.swift. This enables the code to compile successfully (ie without triggering an assertion failure in swiftc). Is this the right change from an API perspective?

@dgrove-oss
Copy link
Contributor Author

rebased on top of #96 and squashed down to a single commit again.

@dgrove-oss
Copy link
Contributor Author

Additional changes needed, or is this ready to merge and I'll deal with the handful of FIXME's in a separate PR next week?

@mwwa mwwa merged commit 5b893c8 into swiftlang:master Jul 1, 2016
@mwwa
Copy link
Contributor

mwwa commented Jul 1, 2016

Done! Thanks.

@dgrove-oss dgrove-oss deleted the swift3-overlay-pr1 branch July 1, 2016 19:56
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Jul 21, 2016
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Jul 26, 2016
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Jul 29, 2016
norio-nomura added a commit to norio-nomura/swift-dev that referenced this pull request Jul 29, 2016
Using my forked repositories:
- swift-corelibs-libdispatch
  - Disable failing tests
- swiftpm
  - Add workaround for swiftlang/swift-corelibs-libdispatch#94
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Jul 30, 2016
norio-nomura added a commit to norio-nomura/swift-dev that referenced this pull request Jul 30, 2016
Using my forked repositories:
- swift-corelibs-libdispatch
  - Revert SE-0111
  - Disable failing tests
- swiftpm
  - Add workaround for swiftlang/swift-corelibs-libdispatch#94
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Aug 5, 2016
norio-nomura added a commit to norio-nomura/swift-dev that referenced this pull request Aug 5, 2016
Using my forked repositories:
- swift
  - Run tests of SourceKit and disable failing tests
- swift-corelibs-libdispatch
  - Disable failing tests
- swiftpm
  - Add workaround for swiftlang/swift-corelibs-libdispatch#94
norio-nomura added a commit to norio-nomura/swift-package-manager that referenced this pull request Aug 6, 2016
norio-nomura added a commit to norio-nomura/swift-dev that referenced this pull request Aug 6, 2016
Using my forked repositories:
- swift
  - Cherry picked some commits for building SourceKitInProc on Linux
  - Workarounds for link errors
- swift-corelibs-libdispatch
  - Based on 3ce8734
  - Disable failing tests
- swiftpm
  - Add workaround for swiftlang/swift-corelibs-libdispatch#94
das pushed a commit that referenced this pull request Aug 11, 2016
Initial Swift3 wrapping overlay for libdispatch

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
das added a commit that referenced this pull request Aug 11, 2016
The Linux and Darwin module maps need to be kept separate as they have
different linkage requirements.

<rdar://problem/27366695>

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
norio-nomura added a commit to norio-nomura/swift-dev that referenced this pull request Aug 13, 2016
Using my forked repositories:
- swift
  - Cherry picked some commits for building SourceKitInProc on Linux
  - Workarounds for link errors
- swift-corelibs-libdispatch
  - Based on 3ce8734
  - Disable failing tests
- swiftpm
  - Add workaround for swiftlang/swift-corelibs-libdispatch#94
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.

6 participants