Skip to content

Extract RefCount implementation from header to cpp file #6827

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

Closed
wants to merge 1 commit into from
Closed

Extract RefCount implementation from header to cpp file #6827

wants to merge 1 commit into from

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Jan 15, 2017

RefCount.h is part of the runtime. The runtime must be built with Clang. RefCount.h uses clang/gcc specific atomic builtins.

However, RefCount.h is included by HeapObject.h, which is included from Metadata.h, which is included from IRGen.

IRGen can be built with MSVC, so therefore RefCount must also be able to be built with MSVC.

MSVC doesn't have these builtins, so we need to extract the compiler-specific implementation to the runtime, so we expose a compiler-independent interface to the compiler-independent swiftc compiler

@hughbe
Copy link
Contributor Author

hughbe commented Jan 15, 2017

I'd like to explore using <atomic> C++ 11 functions but there's a slight problem. C++ 11 exposes atomic_fetch_add, but doesn't have an equivalent for atomic_add_fetch so there's not a 1-1 conversion between GCC/Clang intrinsics and <atomic> functions. If anyone has any ideas as to how to do this, please let me know.

@gottesmm FYI

@gottesmm
Copy link
Contributor

@gparker42

@gottesmm
Copy link
Contributor

I will leave a real review to @gparker42, but is there any reason to merge it into the *.cpp file. Why not just keep it as a local header.

@hughbe
Copy link
Contributor Author

hughbe commented Jan 16, 2017

I've outlined my reasoning in the Pr description: basically we want to expose a compiler independent interface to the swift.exe source which can be built with MSVC, whilst allowing the use of GCC/Clang built ins in the runtime, which must be built with Clang.
RefCount.h is an external dependency of IRGen so must able to be compiled with Msvc for the rest of the swift compiler to be built with msvc

@hughbe
Copy link
Contributor Author

hughbe commented Jan 16, 2017

@swift-ci please test

@gottesmm
Copy link
Contributor

I misunderstood what you were doing. I thought you were moving everything from the .h into the .cpp file.

For future reference, the word you are looking for is "out of line", i.e. move definition of ref count implementation out of line into *.cpp file. The phrase is a much clearer signal that you are leaving the declaration in the header.

This looks fine to me, but I defer to @gparker42. This is his area.

@hughbe
Copy link
Contributor Author

hughbe commented Jan 16, 2017

Sorry, my bad - just learning all the C++ stuff

@gparker42
Copy link
Contributor

I have rewritten all of this code in #5282 which is expected to land soon.

Did you measure the performance and look at the generated code of the .cpp implementation? Inlining optimization is important for the refcount implementation, and moving the code to a .cpp file will prevent inlining in the absence of tricks like link-time optimization.

@gparker42
Copy link
Contributor

I think #5282's implementation is <atomic> everywhere in RefCount.h. Is that sufficient to solve the MSVC issues?

@hughbe
Copy link
Contributor Author

hughbe commented Jan 17, 2017

I had no idea about Perf. Can try checking though, but its likely we can close this PR now that there's some conversion to Atomic

As per your pull request - thats awesome! As long as it doesn't use compiler insitrinsics I'm happy. Atomic is fully supported with MsvC

@gparker42
Copy link
Contributor

Sounds good. Let us know how #5282 fares with MSVC (before or after it gets merged).

@gparker42 gparker42 closed this Jan 18, 2017
@hughbe hughbe deleted the refcount-impl branch January 18, 2017 12:14
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.

3 participants