Skip to content

[NFC] A trio of patches to improve incremental build times and compiler abstraction #34172

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 3 commits into from
Oct 3, 2020

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Oct 3, 2020

Incremental improvements to the runtime — at least the ones I make :) — often add new things to Runtime/Config.h and ABI/MetadataValues.h. Currently, MetadataValues.h is included by TypeLowering.h, which is ubiquitously included by SILGen and everything afterward, so editing it requires rebuilding all that.

  1. Split the one pertinent declaration out into its own file and make TypeLowering just include that.
  2. That file includes a helper function that uses swift_runtime_unreachable, which is a layering violation. Fix it by moving Unreachable.h into Basic, renaming the function to swift_unreachable, and making it forward to llvm_unreachable (which is generally superior) whenever we're building with LLVM support, which we indicate with a new -D flag within the appropriate lib/ directories.
  3. Move some of the attribute macros from Runtime/Config.h to Basic/Compiler.h so that we don't have to include Config.h just to get compiler abstraction.

@rjmccall rjmccall force-pushed the compiler-abstraction branch from 3befc16 to 0fb4079 Compare October 3, 2020 06:55
@rjmccall
Copy link
Contributor Author

rjmccall commented Oct 3, 2020

@swift-ci Please smoke test.

# Declare that files in this library are built with LLVM's support
# libraries available.
macro(set_swift_llvm_is_available)
add_compile_options(-DSWIFT_LLVM_SUPPORT_IS_AVAILABLE)
Copy link
Member

Choose a reason for hiding this comment

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

Why not instead of this just forward to __swift::__runtime::llvm_unreachable instead of llvm_unreachable? We should have that in the LLVMSupport in the runtime as well (or can be trivially restored).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a lot of code in headers, some of which can be usefully included in multiple environments: the compiler (which links LLVM support), the runtime (which can have a limited support library), and various other tools (which we generally shouldn't add linker assumptions to). This define tells those headers which environment we're in so that they can use the best implementation mechanism for that environment. This means that in code we can provide a single interface that works anywhere instead of expecting clients to carefully pick which interface they use; for example, it's now always fine to just use swift_unreachable.

I think what you're suggesting doesn't address that problem at all, because we'd be assuming the existence of a swift::runtime::unreachable. Without some level of configuration awareness, that actually makes the problem worse, because we'd have to actually put that function somewhere that gets linked into everything. Whereas if we want the runtime to have a better unreachable implementation than the current non-LLVM one, we could certainly just extend my approach to pass -DSWIFT_RUNTIME_SUPPORT_IS_AVAILABLE and make Unreachable.h take advantage of that.

Copy link
Member

Choose a reason for hiding this comment

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

I was suggesting that for anything in stdlib, swift_unreachable just maps to __swift::__runtime::llvm_unavailable which is part of stdlib/LLVMSupport and for the compiler we just use llvm_unreachable from LLVMSupport which is linked against anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Not everything in stdlib/ is linked into the runtime. It might be linked with the runtime, but we don't want to export symbols like this from the runtime.
  2. I'm pretty sure that not everything in lib/ is linked with LLVMSupport.
  3. The whole point of the cmake stuff here is telling the compiler what kind of thing we're building as part of, because that's not currently passed down in any other way that I can see.

@rjmccall rjmccall merged commit d1070da into swiftlang:main Oct 3, 2020
@rjmccall rjmccall deleted the compiler-abstraction branch October 3, 2020 18:59
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.

2 participants