Skip to content

runtime: explicitly namespace ArrayRef in shared headers #31746

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
May 13, 2020

Conversation

compnerd
Copy link
Member

There are a set of headers shared between the Swift compiler and the
runtime. Ensure that we explicitly use llvm::ArrayRef rather than
ArrayRef which is aliased to ::llvm::ArrayRef. Doing so enables us
to replace the ArrayRef with an inline namespaced version fixing ODR
violations when the swift runtime is loaded into an address space with
LLVM.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4482b4ebe97508947286c6424d1c1df2e9566437

@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4482b4ebe97508947286c6424d1c1df2e9566437

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4482b4ebe97508947286c6424d1c1df2e9566437

@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4482b4ebe97508947286c6424d1c1df2e9566437

@shahmishal
Copy link
Member

@swift-ci please test windows

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Looks like you have whitespace problems everywhere you've spelled out llvm::ArrrayRef.

I don't know how spelling out llvm::ArrayRef in a bunch of places is easier to make use an inline namespace than a using declaration in a common location. I also don't know what ODR problems you could possibly be having with ArrayRef.

@compnerd
Copy link
Member Author

I can re-clang-format the changed areas. The explicit spelling helps by allowing the swift runtime to have a completely isolated __swift::__runtime::llvm::ArrayRef while allowing the compiler to use llvm::ArrayRef. The forward declaration causes the conflict and the inline namespace is ignored. I've simply removed the forward declaration in the runtime path, and adjusted the invocations accordingly.

The ODR violations that I am referring to occur when LLVM libraries are used in the same address space as the Swift runtime and are at different versions. There are collisions which occur due to the runtime's use of the llvm::. By isolating the LLVMSupport usage into an inline namespace, we can avoid the collision.

There are a set of headers shared between the Swift compiler and the
runtime.  Ensure that we explicitly use `llvm::ArrayRef` rather than
`ArrayRef` which is aliased to `::llvm::ArrayRef`.  Doing so enables us
to replace the `ArrayRef` with an inline namespaced version fixing ODR
violations when the swift runtime is loaded into an address space with
LLVM.
@compnerd
Copy link
Member Author

@rjmccall thanks for pointing out the whitespace issue, I really missed that. Ran clang-format over the patch again, definitely something went wrong originally.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@compnerd compnerd merged commit 9a141a8 into swiftlang:master May 13, 2020
@compnerd compnerd deleted the ArrayRef branch May 13, 2020 18:09
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.

4 participants