Skip to content

[SR-1613][SourceKit] Require blocks runtime #2703

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

Conversation

modocache
Copy link
Contributor

@modocache modocache commented May 25, 2016

What's in this pull request?

SourceKit makes heavy use of blocks. In order to port SourceKit to Linux, we either need to rewrite much of it to use function pointers, or we must require a blocks runtime. This commit requires a blocks runtime, but only when SourceKit is being built. Currently, SourceKit is not built on Linux, so this should not affect anyone.

You may attempt to build SourceKit on Linux by applying this patch.

Resolved bug number: (SR-1613)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@@ -235,7 +238,7 @@ function(_add_variant_link_flags)
RESULT_VAR_NAME result)

if("${LFLAGS_SDK}" STREQUAL "LINUX")
list(APPEND result "-lpthread" "-ldl")
list(APPEND result "-lpthread" "-ldl" "-lBlocksRuntime")
Copy link
Contributor

Choose a reason for hiding this comment

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

This creates a new dependency for new ports that don't need SourceKit to start bootstrapping; this will also link it into the standard library, which does not need it. Could we limit this to only SourceKit binaries and libraries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was wondering about this as well. Can do! I'll add these flags to add_sourcekit_library() instead of here.

SourceKit makes heavy use of blocks. In order to port SourceKit to Linux,
we either need to rewrite much of it to use function pointers, or we must
require a blocks runtime. This commit requires a blocks runtime, but only
when SourceKit is being built. Currently, SourceKit is not built on Linux,
so this should not affect anyone.
@modocache modocache force-pushed the sr-1613-sourcekit-linux-blocks branch from f68ccb8 to d7e2e1f Compare May 25, 2016 21:18
@modocache
Copy link
Contributor Author

@gribozavr Thanks for the tips! I updated the patch to only link a blocks runtime on Linux.

@swift-ci please test

@lattner
Copy link
Contributor

lattner commented May 26, 2016

I'm not opposed to this patch, but a nicer solution is to use C++ lambdas. C function pointers are falling off the cliff too far.

@rintaro
Copy link
Member

rintaro commented May 26, 2016

Hopefully, in the future, we could build blocks runtime and distribute it with swiftRuntime?
I want ClangImporter to enable -fblocks in Linux as well.

@akyrtzi
Copy link
Contributor

akyrtzi commented May 26, 2016

a nicer solution is to use C++ lambdas

To clarify, blocks are primarily used for the C API and code around it (tools using the C API, implementation of the C API, etc.), otherwise C++ lambdas are used liberally.

@modocache
Copy link
Contributor Author

@akyrtzi Would you be alright with me merging this change? I think it's in agreement with your comments on SR-1613:

you should make it optional and only linking it for SourceKit (meaning if someone only wants to build the compiler they should not need the block runtime).

It also gets us a lot closer to SourceKit on Linux, which we need in order to generate lists of XCTest test methods.

@akyrtzi
Copy link
Contributor

akyrtzi commented May 26, 2016

Change LGTM, thanks for working on this!

@modocache modocache merged commit 6c4acf2 into swiftlang:master May 26, 2016
@modocache
Copy link
Contributor Author

Excellent, thanks @akyrtzi! I'll cc you on future pull requests as well. :)

@modocache modocache deleted the sr-1613-sourcekit-linux-blocks branch May 26, 2016 21:27
@briancroom
Copy link
Contributor

It's worth pointing out here that there are already two Blocks runtimes in the public repos under the Apple GitHub org. There's the original one in compiler-rt which isn't hooked into the build system at all AFAICT, and there's the one in Foundation which ends up linked into libFoundation.so.

To @rintaro's point, it would be great to eventually remove this dependency on an external Blocks runtime package and instead provide one as a part of the Swift build.

@@ -84,6 +84,11 @@ function(add_sourcekit_default_compiler_flags target)
ANALYZE_CODE_COVERAGE "${analyze_code_coverage}"
RESULT_VAR_NAME link_flags)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this has been merged already, but should we be considering other non-Darwin platforms here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. I'm worried about SR-710 getting done in time for Swift 3.0, so I'm reducing scope a bit here. Ideally, I'd like SourceKit to run everywhere. Were it able to do so, we'd probably want to change this to handle more than just Linux.

@RLovelett
Copy link
Contributor

With #3835 (e.g., ClangImporter: enable -fblocks on non-Darwin platforms) appearing as a PR (yet to land) and swift-corelibs-libdispatch #139: SR-2309: embed BlocksRuntime in libdispatch to eliminate external dep… (already landed) would now be a good time to revisit @rintaro and @briancroom's suggestion?

Namely to stop depending on an external BlocksRuntime? I point this out because a pre-packed BlocksRuntime does not exist on all distros, as it does on Ubuntu.

Also, it would seem that with or without SourceKit in mind this is going to become on issue on a number of distros due to #4203 progressing.

Also just to be clear I'm not asking anyone to solve this per-se. I'm trying to get a feel for what the likely hood of such a PR getting reviewed/accepted should I attempt to make one.

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.

7 participants