diff --git a/Compiler/src/typeinfer.jl b/Compiler/src/typeinfer.jl index 9a3b312346225..66d046b00820f 100644 --- a/Compiler/src/typeinfer.jl +++ b/Compiler/src/typeinfer.jl @@ -1448,6 +1448,11 @@ function collectinvokes!(workqueue::CompilationQueue, ci::CodeInfo, sptypes::Vec finalizer = argextype(stmt.args[2], ci, sptypes) obj = argextype(stmt.args[3], ci, sptypes) atype = argtypes_to_type(Any[finalizer, obj]) + elseif ftyp === typeof(Core._predeclare_call) && length(stmt.args) > 1 + atype = argtypes_to_type(Any[ + argextype(stmt.args[i], ci, sptypes) + for i in 2:length(stmt.args) + ]) else # No dynamic dispatch to resolve / enqueue continue diff --git a/Compiler/src/verifytrim.jl b/Compiler/src/verifytrim.jl index 19d8bcd623275..845eded18d88d 100644 --- a/Compiler/src/verifytrim.jl +++ b/Compiler/src/verifytrim.jl @@ -154,6 +154,7 @@ function may_dispatch(@nospecialize ftyp) return Core._apply isa ftyp || Core._apply_iterate isa ftyp || Core._call_in_world_total isa ftyp || + Core._predeclare_call isa ftyp || Core.invoke isa ftyp || Core.invoke_in_world isa ftyp || Core.invokelatest isa ftyp || @@ -233,6 +234,21 @@ function verify_codeinstance!(codeinst::CodeInstance, codeinfo::CodeInfo, inspec error = "unresolved finalizer registered" end + elseif Core._predeclare_call isa ftyp + if length(stmt.args) > 1 + atype = argtypes_to_type(Any[ + argextype(stmt.args[i], codeinfo, sptypes) + for i in 2:length(stmt.args) + ]) + + mi = compileable_specialization_for_call(interp, atype) + if mi !== nothing + ci = get(caches, mi, nothing) + ci isa CodeInstance && continue + end + + error = "unresolved pre-declared call" + end else error = "unresolved call to builtin" end diff --git a/src/builtin_proto.h b/src/builtin_proto.h index 607106f35bac0..8d7b85e43a43a 100644 --- a/src/builtin_proto.h +++ b/src/builtin_proto.h @@ -17,6 +17,7 @@ extern "C" { XX(_equiv_typedef,"_equiv_typedef") \ XX(_expr,"_expr") \ XX(_import, "_import") \ + XX(_predeclare_call,"_predeclare_call") \ XX(_primitivetype,"_primitivetype") \ XX(_setsuper,"_setsuper!") \ XX(_structtype,"_structtype") \ diff --git a/src/builtins.c b/src/builtins.c index 36b5d79ec0851..2349a6635012d 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1685,6 +1685,17 @@ JL_CALLABLE(jl_f_invoke) return jl_gf_invoke(argtypes, args[0], &args[2], nargs - 1); } +JL_CALLABLE(jl_f__predeclare_call) +{ + JL_NARGSV(_predeclare_call, 1); + + // jl_datatype_t *tt = jl_inst_arg_tuple_type(args[0], &args[1], nargs, 1); + // JL_GC_PROMISE_ROOTED(tt); // it is a concrete type + // jl_compile_hint(tt) + + return jl_nothing; +} + // Expr constructor for internal use ------------------------------------------ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)