Skip to content
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

RFC: Refactor the package to make it self-generated and more #210

Closed
wants to merge 47 commits into from
Closed

RFC: Refactor the package to make it self-generated and more #210

wants to merge 47 commits into from

Conversation

Gnimuc
Copy link
Member

@Gnimuc Gnimuc commented Oct 11, 2018

I'm investigating how to rebuild the package directly on the auto-generated libclang bindings. Almost done. Please give it a review at your convenience ;)

Change Summary

  • rebuild Clang.jl directly on top of the auto-generated libclang C bindings
    • the new submodule LibClang is one-to-one mapped to the libclang C APIs. it depends on two new files: CEnum.jl and ctypes.jl. CEnum.jl is for better C-compatible enum handling. ctypes.jl contains those C stdlib types that are missing corresponding Julia aliases. when generating wrappers, we should also ship these two files to users.
    • module cindex's base functions are now rebuild on top of LibClang. almost all of the old APIs are renamed, please take a look at index.jl, trans_unit.jl, cursor.jl, type.jl, token.jl and show.jl for details.
    • module cindex's CL-prefixed types are removed, since methods are now directly dynamic-dispatched on Val{CEnum} value types(not sure whether this is a good idea or not).
    • unwind wrap_c.jl and add an AbstractContext type for extensibility
      • this is easier for users who would like to write their own wrap! for certain cursor decls
        and dispatched on their own context.
      • for compatibility's sake, init+run are rebuild on top of DefaultContext. also, old cindex and wrap_c modules can be loaded with Clang.Deprecated.cindex; using Clang.Deprecated.wrap_c;
  • provide an out-of-box installation experience with BB2 on Linux, masOS and Windows, this may attract more users to use this package.
    • the newly released binaries of LLVMBuilder are still not compatible with Julia-1.0, so I built a compatible version with an older version of BinaryBuilder locally and uploaded on the Github releases of this repo.
  • bugfixes and TODO list:

Gnimuc and others added 9 commits September 30, 2018 16:26
Co-Authored-By: Martijn Visser <[email protected]>
let's make Clang.jl self-generated.
1. remove old cindex wrappers
2. add a new low-level module LibClang that is one-to-one mapped to libclang APIs and exports everything
@ihnorton
Copy link
Collaborator

I'll try to give this a read-through this weekend, very cool!

@codecov-io
Copy link

codecov-io commented Oct 21, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@1c5f425). Click here to learn what that means.
The diff coverage is 33.99%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #210   +/-   ##
=========================================
  Coverage          ?   24.11%           
=========================================
  Files             ?       23           
  Lines             ?     1518           
  Branches          ?        0           
=========================================
  Hits              ?      366           
  Misses            ?     1152           
  Partials          ?        0
Impacted Files Coverage Δ
src/deprecated/util.jl 0% <ø> (ø)
src/deprecated/cindex/types.jl 0% <ø> (ø)
src/deprecated/cindex/base.jl 0% <ø> (ø)
src/deprecated/wrap_cpp.jl 0% <ø> (ø)
src/deprecated/cindex.jl 1.41% <ø> (ø)
src/show.jl 0% <0%> (ø)
src/compat.jl 0% <0%> (ø)
src/deprecated/wrap_c.jl 0% <0%> (ø)
src/cltypes.jl 100% <100%> (ø)
src/LibClang.jl 100% <100%> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c5f425...75628a5. Read the comment docs.

@Gnimuc
Copy link
Member Author

Gnimuc commented Oct 21, 2018

the CI failure on Linux might due to the compatibility of the LLVM binaries. I've released two windows binaries and it works well on my VM.

@musm
Copy link

musm commented Nov 12, 2018

This is great, thanks for the hard work.

@Gnimuc Gnimuc changed the title WIP: Refactor the package to make it self-generated RFC: Refactor the package to make it self-generated and more Nov 13, 2018
@samuelpowell
Copy link
Contributor

Cross-referencing a brief thread on discourse regarding #213 - this branch has fixed this issue and seems to work very well. (Running on Ubuntu 18.04 with Julia 1.0.2 generic binaries).

error("llvm-config returned non-existent libdir path: '$(llvm_libdir)")
end
# Download binaries from hosted location
bin_prefix = "https://github.com/ihnorton/Clang.jl/releases/download/Julia1.0-compatible"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool! This looks like we actually want to have a "LLVMBuilder.jl" that has a hard-bound on the Julia version that you can depend on through the package-system, so that each version of Julia get's the right version of LLVMBuilder (and of course we should provide compatible releases (my apologies)). Also it means we should become a bit more conservative in what LLVMBuilder provides and maybe have a second mode for the more experimental features.

cc @staticfloat

Choose a reason for hiding this comment

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

It saddens me that LLVM is so incompatible.

Let's create a JuliaCompatibleLLVM in Yggdrasil, register JuliaCompatibleLLVM.jl, hook up the appropriate BinaryProvider junk, and keep JuliaCompatibleLLVM as close to base Julia's LLVM as possible. We can keep LLVMBuilder with all the bells and whistles that others may want.

@ihnorton
Copy link
Collaborator

@Gnimuc I started taking a look through this. Wow! It is a lot of work and some really nice changes. Thank you!

@ihnorton
Copy link
Collaborator

To start off at a high level, this change immediately stood out out:

module cindex's CL-prefixed types are removed, since methods are now directly dynamic-dispatched on Val{CEnum} value types(not sure whether this is a good idea or not).

Not sure either -- did you have considerations for performance that led in this direction? At first glance, it feels a little bit unwieldy for a high-level API (IIUC, have to pull out the enum, wrap in a Val etc. to pass a cursor to functions).

@Gnimuc
Copy link
Member Author

Gnimuc commented Nov 29, 2018

It looks like this PR downgraded the package too much. 😅 For backward compatibility, it's also not a good idea to remove CL-prefixed types. But it seems very easy to get them back -- regenerate those types from the CX enums and define some conversion methods. I'll give it a test at this weekend.

@Gnimuc
Copy link
Member Author

Gnimuc commented Dec 11, 2018

@ihnorton I've brought those CL-types back and it's indeed much faster than dispatching on Val.

@Gnimuc
Copy link
Member Author

Gnimuc commented Dec 13, 2018

gently bump. hi @ihnorton, is there any chance to get this PR merged before Julia-1.1 release?

Since the LLVM & Clang used in Julia-1.1 may not be compatible with those in used Julia-1.0, we need to cap this package to Julia-1.0 firstly, tag a v0.8 release and then provide Julia-1.1 support and tag a v0.9 release. Or should we just jump over Julia-1.0 and directly target Julia-1.1?

rschwarz added a commit to scipopt/SCIP.jl that referenced this pull request Dec 15, 2018
@ihnorton
Copy link
Collaborator

cap this package to Julia-1.0 firstly, tag a v0.8 release and then provide Julia-1.1 support and tag a v0.9 release. Or should we just jump over Julia-1.0 and directly target Julia-1.1?

This sounds good! The compatibility of generated bindings is more important than what version Clang.jl will run on, so I think it is fine to target Julia 1.1.

@ihnorton
Copy link
Collaborator

@Gnimuc this looks great. I looked through the generated files in scipopt/SCIP.jl#76 as the large test, and the output is very nice.

I'm not sure what is up with the rebase conflict, but please go ahead and tag then merge when you are ready 👍

@Gnimuc
Copy link
Member Author

Gnimuc commented Dec 23, 2018

I also get rebase conflicts, so close this and submit a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment