Skip to content

Commit 9b1e379

Browse files
authored
Merge branch 'master' into prevent_stack_overflow_in_type_promotion
2 parents 14327df + ab49eb1 commit 9b1e379

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

src/jitlayers.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,46 @@ static void finish_params(Module *M, jl_codegen_params_t &params, SmallVector<or
255255
}
256256
}
257257

258+
// Return a specptr that is ABI-compatible with `from_abi` which invokes `codeinst`.
259+
//
260+
// If `codeinst` is NULL, the returned specptr instead performs a standard `apply_generic`
261+
// call via a dynamic dispatch.
258262
extern "C" JL_DLLEXPORT_CODEGEN
259-
void *jl_jit_abi_converter_impl(jl_task_t *ct, void *unspecialized, jl_abi_t from_abi,
260-
jl_code_instance_t *codeinst, jl_callptr_t invoke, void *target, int target_specsig)
263+
void *jl_jit_abi_converter_impl(jl_task_t *ct, jl_abi_t from_abi,
264+
jl_code_instance_t *codeinst)
261265
{
262-
if (codeinst == nullptr && unspecialized != nullptr)
263-
return unspecialized;
266+
void *target = nullptr;
267+
bool target_specsig = false;
268+
jl_callptr_t invoke = nullptr;
269+
if (codeinst != nullptr) {
270+
uint8_t specsigflags;
271+
jl_method_instance_t *mi = jl_get_ci_mi(codeinst);
272+
void *specptr = nullptr;
273+
jl_read_codeinst_invoke(codeinst, &specsigflags, &invoke, &specptr, /* waitcompile */ 1);
274+
if (invoke != nullptr) {
275+
if (invoke == jl_fptr_const_return_addr) {
276+
target = nullptr;
277+
target_specsig = false;
278+
}
279+
else if (invoke == jl_fptr_args_addr) {
280+
assert(specptr != nullptr);
281+
if (!from_abi.specsig && jl_subtype(codeinst->rettype, from_abi.rt))
282+
return specptr; // no adapter required
283+
284+
target = specptr;
285+
target_specsig = false;
286+
}
287+
else if (specsigflags & 0b1) {
288+
assert(specptr != nullptr);
289+
if (from_abi.specsig && jl_egal(mi->specTypes, from_abi.sigt) && jl_egal(codeinst->rettype, from_abi.rt))
290+
return specptr; // no adapter required
291+
292+
target = specptr;
293+
target_specsig = true;
294+
}
295+
}
296+
}
297+
264298
orc::ThreadSafeModule result_m;
265299
std::string gf_thunk_name;
266300
{

src/julia_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,7 @@ JL_DLLEXPORT jl_value_t *jl_get_cfunction_trampoline(
16391639
void *(*init_trampoline)(void *tramp, void **nval),
16401640
jl_unionall_t *env, jl_value_t **vals);
16411641
JL_DLLEXPORT void *jl_get_abi_converter(jl_task_t *ct, void *data);
1642-
JL_DLLIMPORT void *jl_jit_abi_converter(jl_task_t *ct, void *unspecialized, jl_abi_t from_abi,
1643-
jl_code_instance_t *codeinst, jl_callptr_t invoke, void *target, int target_specsig);
1642+
JL_DLLIMPORT void *jl_jit_abi_converter(jl_task_t *ct, jl_abi_t from_abi, jl_code_instance_t *codeinst);
16441643

16451644

16461645
// Special filenames used to refer to internal julia libraries

src/runtime_ccall.cpp

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -422,42 +422,25 @@ void *jl_get_abi_converter(jl_task_t *ct, void *data)
422422
JL_UNLOCK(&cfun_lock);
423423
return f;
424424
};
425-
jl_callptr_t invoke = nullptr;
426425
bool is_opaque_closure = false;
427426
jl_abi_t from_abi = { sigt, declrt, nargs, specsig, is_opaque_closure };
428-
if (codeinst != NULL) {
429-
jl_value_t *astrt = codeinst->rettype;
430-
if (astrt != (jl_value_t*)jl_bottom_type &&
431-
jl_type_intersection(astrt, declrt) == jl_bottom_type) {
432-
// Do not warn if the function never returns since it is
433-
// occasionally required by the C API (typically error callbacks)
434-
// even though we're likely to encounter memory errors in that case
435-
jl_printf(JL_STDERR, "WARNING: cfunction: return type of %s does not match\n", name_from_method_instance(mi));
436-
}
437-
uint8_t specsigflags;
438-
jl_read_codeinst_invoke(codeinst, &specsigflags, &invoke, &f, 1);
439-
if (invoke != nullptr) {
440-
if (invoke == jl_fptr_const_return_addr) {
441-
return assign_fptr(jl_jit_abi_converter(ct, cfuncdata->unspecialized, from_abi, codeinst, invoke, nullptr, false));
442-
}
443-
else if (invoke == jl_fptr_args_addr) {
444-
assert(f);
445-
if (!specsig && jl_subtype(astrt, declrt))
446-
return assign_fptr(f);
447-
return assign_fptr(jl_jit_abi_converter(ct, cfuncdata->unspecialized, from_abi, codeinst, invoke, f, false));
448-
}
449-
else if (specsigflags & 0b1) {
450-
assert(f);
451-
if (specsig && jl_egal(mi->specTypes, sigt) && jl_egal(declrt, astrt))
452-
return assign_fptr(f);
453-
return assign_fptr(jl_jit_abi_converter(ct, cfuncdata->unspecialized, from_abi, codeinst, invoke, f, true));
454-
}
455-
}
427+
if (codeinst == nullptr) {
428+
// Generate an adapter to a dynamic dispatch
429+
if (cfuncdata->unspecialized == nullptr)
430+
cfuncdata->unspecialized = jl_jit_abi_converter(ct, from_abi, nullptr);
431+
432+
return assign_fptr(cfuncdata->unspecialized);
433+
}
434+
435+
jl_value_t *astrt = codeinst->rettype;
436+
if (astrt != (jl_value_t*)jl_bottom_type &&
437+
jl_type_intersection(astrt, declrt) == jl_bottom_type) {
438+
// Do not warn if the function never returns since it is
439+
// occasionally required by the C API (typically error callbacks)
440+
// even though we're likely to encounter memory errors in that case
441+
jl_printf(JL_STDERR, "WARNING: cfunction: return type of %s does not match\n", name_from_method_instance(mi));
456442
}
457-
f = jl_jit_abi_converter(ct, cfuncdata->unspecialized, from_abi, codeinst, invoke, nullptr, false);
458-
if (codeinst == nullptr)
459-
cfuncdata->unspecialized = f;
460-
return assign_fptr(f);
443+
return assign_fptr(jl_jit_abi_converter(ct, from_abi, codeinst));
461444
}
462445

463446
void jl_init_runtime_ccall(void)

test/spawn.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ busybox_hash_correct(file) = bytes2hex(open(SHA.sha256, file)) == "ed2f95da95552
2525

2626
function _tryonce_download_from_cache(desired_url::AbstractString)
2727
cache_url = "https://cache.julialang.org/$(desired_url)"
28-
cache_output_filename = joinpath(mktempdir(), "busybox")
28+
cache_output_filename = joinpath(mktempdir(), "busybox" * (Sys.iswindows() ? ".exe" : ""))
2929
cache_response = Downloads.request(
3030
cache_url;
3131
output = cache_output_filename,

0 commit comments

Comments
 (0)