tshort / StaticCompiler.jl

Compiles Julia code to a standalone library (experimental)
Other
489 stars 31 forks source link

Multiple function shared lib #79

Closed gbaraldi closed 2 years ago

gbaraldi commented 2 years ago

Option to compile a shared lib with multiple functions. The API receives a vector of tuples that look like Tuple{func,Tuple{args}. Ideally this would receive a module and compile the methods defined in the module, but I still have to figure out how to do that.

brenhinkeller commented 2 years ago

This looks awesome!

chriselrod commented 2 years ago

Ideally this would receive a module and compile the methods defined in the module, but I still have to figure out how to do that.

All methods in a module? How would you determine function-argument pairs, and name mangling if there are multiple arguments for the same function?

gbaraldi commented 2 years ago

@chriselrod The perfect API in my mind would be something like

module SquareLib

@noinline square(n::Float64) = n*n

function squaresquare(n::Float64)
    square(square(n))
end

function squaresquaresquare(n::Float64)
    square(squaresquare(n))
end

end

compile_shlib(SquareLib)

So all methods have to have concrete types as arguments, have different names etc. The issue is I don't know how I would do that. Maybe instead of a module I would use a macro and a scope or something. I am taking suggestions ;)

chriselrod commented 2 years ago

C++ has extern "C" { } for this.

What about just looking for all Base.@ccallable functions?

brenhinkeller commented 2 years ago

Hmm, looks like there's maybe an issue with the name (de?)mangling in the test? You can ignore "integration nightly" though

gbaraldi commented 2 years ago

Looking for the ccallable functions is an option, I'm not sure how I would do that since I think it only changes a bit in the MethodInstance but I only need the MethodInstance anyway

brenhinkeller commented 2 years ago

Tests look good now! LGTM but I'll defer to Mason

MasonProtter commented 2 years ago

Yeah, this looks good @gbaraldi. Do you have any interest in trying to make the compile interface also work with this? No problem if not

gbaraldi commented 2 years ago

@MasonProtter I will take a look tomorrow, since you call into generate_obj it's just a question of adding a function and some way to serialize multiple compiled functions.

brenhinkeller commented 2 years ago

Still thinking about the compile interface, or want to merge this without and think about that later?

brenhinkeller commented 2 years ago

I'm about to disappear for fieldwork, so no rush on my end but I probably won't be able to be very responsive for a bit after tomorrow

MasonProtter commented 2 years ago

Okay, let’s just merge this and deal with compile in a later PR