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
Jit bind #2726
Jit bind #2726
Conversation
Ready, I think. |
Great that you submitted some parts as separate PRs. |
@@ -83,10 +83,306 @@ void compileDynamicCode(in CompilerSettings settings = CompilerSettings.init) | |||
rtCompileProcessImpl(context, context.sizeof); | |||
} | |||
|
|||
auto bind(F, Args...)(F func, Args args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
auto bind(F, Args...)(F func, Args args) | ||
{ | ||
import std.format; | ||
static assert(isFunctionPointer!F); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice to add a message to the user when this fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
alias FuncParams = Parameters!(F); | ||
alias Ret = ReturnType!F; | ||
F func = null; | ||
static assert(func.offsetof == 0, "func must be fist"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in error msg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
just rebase (and something bad happened with commit dates so github display nonsense like |
rebased, added docs |
return BindPtrType.make!Index(func, mapBindParams!(F, 0)(args).expand); | ||
} | ||
|
||
immutable placeholder = _placeholder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This member should also be documented briefly. Probably just a reference to bind
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Updated: delegate as first parameter, |
Rebased. TODO: probably need to write some design overview |
b29b3df
to
1bb464f
Compare
ready |
@@ -0,0 +1,27 @@ | |||
#ifndef BIND_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
runtime/jit-rt/cpp-so/param_slice.h
Outdated
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// ParamSlice declaration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;-) nitpick: this comment is useless, I can read the same a few lines down in C++. What would help is to explain what ParamSlice is used for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@@ -0,0 +1,25 @@ | |||
# Dynamic compile bind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you added some design documentation
@@ -405,7 +405,7 @@ if(LDC_DYNAMIC_COMPILE STREQUAL "AUTO") | |||
if (NOT (LDC_LLVM_VER LESS 500)) | |||
set(LDC_DYNAMIC_COMPILE True) | |||
add_definitions(-DLDC_DYNAMIC_COMPILE) | |||
add_definitions(-DLDC_DYNAMIC_COMPILE_API_VERSION=1) | |||
add_definitions(-DLDC_DYNAMIC_COMPILE_API_VERSION=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to add an item about this to the release notes.
I've made some grammar fixes to the documentation. |
See some inline comments. |
42f6b52
to
70f5dbb
Compare
70f5dbb
to
42f34c8
Compare
… later (needed for bind)
42f34c8
to
08695cd
Compare
bind-like functionality which allow to generate efficient specialized versions of functions (much like easy::jit).
Add
ldc.dynamic_compile.bind
function with interface similar to C++std::bind
. Function returnsBindPtr
object (which is reference counted internally) withopCall
method.Actual body is generated during
compileDynamicCode
and after thatBindPtr
can be called.Function passed to
bind
must be marked@dynamicCompile
, otherwiseBindPtr.isCallable()
will returnfalse
and 'opCall' asserts.If function bind as parameter marked as
@dynamicCompile
it will be efficiently optimized (seedynamiccompile/bind_func_opt.d
test).Also bind functions can be chained together (see
dynamiccompile/bind_nested_opt.d
test).