Skip to content

Commit e22ee48

Browse files
maleadtsimeonschaub
authored andcommitted
Simplify static_eval, remove allocation restriction (JuliaLang#37209)
* Simplify static_eval. Remove the sparam and allow_alloc parameters, which are enabled in all uses of static_eval (which there are way fewer than there used to be). * Remove static_alloc codegen param.
1 parent 3530720 commit e22ee48

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

base/reflection.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ default_debug_info_kind() = unsafe_load(cglobal(:jl_default_debug_info_kind, Cin
958958
struct CodegenParams
959959
track_allocations::Cint
960960
code_coverage::Cint
961-
static_alloc::Cint
962961
prefer_specsig::Cint
963962
gnu_pubnames::Cint
964963
debug_info_kind::Cint
@@ -974,15 +973,15 @@ struct CodegenParams
974973
generic_context::Any
975974

976975
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
977-
static_alloc::Bool=true, prefer_specsig::Bool=false,
976+
prefer_specsig::Bool=false,
978977
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
979978
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
980979
emit_function=nothing, emitted_function=nothing,
981980
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
982981
generic_context = nothing)
983982
return new(
984983
Cint(track_allocations), Cint(code_coverage),
985-
Cint(static_alloc), Cint(prefer_specsig),
984+
Cint(prefer_specsig),
986985
Cint(gnu_pubnames), debug_info_kind,
987986
module_setup, module_activation, raise_exception,
988987
emit_function, emitted_function, lookup,

src/ccall.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static void interpret_symbol_arg(jl_codectx_t &ctx, native_sym_arg_t &out, jl_va
486486
const char *&f_name = out.f_name;
487487
const char *&f_lib = out.f_lib;
488488

489-
jl_value_t *ptr = static_eval(ctx, arg, true);
489+
jl_value_t *ptr = static_eval(ctx, arg);
490490
if (ptr == NULL) {
491491
jl_cgval_t arg1 = emit_expr(ctx, arg);
492492
jl_value_t *ptr_ty = arg1.typ;
@@ -557,7 +557,7 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
557557
JL_GC_PUSH2(&rt, &sym.gcroot);
558558

559559
if (nargs == 2) {
560-
rt = static_eval(ctx, args[2], true, true);
560+
rt = static_eval(ctx, args[2]);
561561
if (rt == NULL) {
562562
JL_GC_POP();
563563
jl_cgval_t argv[2];
@@ -629,7 +629,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
629629
JL_GC_PUSH4(&ir, &rt, &at, &entry);
630630
if (jl_is_ssavalue(ir_arg))
631631
ir_arg = jl_arrayref((jl_array_t*)ctx.source->code, ((jl_ssavalue_t*)ir_arg)->id - 1);
632-
ir = static_eval(ctx, ir_arg, true, true);
632+
ir = static_eval(ctx, ir_arg);
633633
if (!ir) {
634634
emit_error(ctx, "error statically evaluating llvm IR argument");
635635
return jl_cgval_t();
@@ -640,7 +640,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
640640
rt = jl_tparam0(rtt);
641641
}
642642
if (!rt) {
643-
rt = static_eval(ctx, args[2], true, true);
643+
rt = static_eval(ctx, args[2]);
644644
if (!rt) {
645645
emit_error(ctx, "error statically evaluating llvmcall return type");
646646
return jl_cgval_t();
@@ -652,7 +652,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
652652
at = jl_tparam0(att);
653653
}
654654
if (!at) {
655-
at = static_eval(ctx, args[3], true, true);
655+
at = static_eval(ctx, args[3]);
656656
if (!at) {
657657
emit_error(ctx, "error statically evaluating llvmcall argument tuple");
658658
return jl_cgval_t();

src/cgutils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2965,7 +2965,6 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
29652965
// language features
29662966
(a->track_allocations == b->track_allocations) &&
29672967
(a->code_coverage == b->code_coverage) &&
2968-
(a->static_alloc == b->static_alloc) &&
29692968
(a->prefer_specsig == b->prefer_specsig) &&
29702969
// hooks
29712970
(a->module_setup == b->module_setup) &&

src/codegen.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static int globalUnique = 0;
849849
// --- code generation ---
850850
extern "C" {
851851
int jl_default_debug_info_kind = (int) DICompileUnit::DebugEmissionKind::FullDebug;
852-
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 0,
852+
jl_cgparams_t jl_default_cgparams = {1, 1, 0,
853853
#ifdef _OS_WINDOWS_
854854
0,
855855
#else
@@ -1993,10 +1993,10 @@ static jl_value_t *static_apply_type(jl_codectx_t &ctx, const jl_cgval_t *args,
19931993
return result;
19941994
}
19951995

1996-
// try to statically evaluate, NULL if not possible
1997-
static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex, int sparams=true, int allow_alloc=true)
1996+
// try to statically evaluate, NULL if not possible. note that this may allocate, and as
1997+
// such the resulting value should not be embedded directly in the generated code.
1998+
static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex)
19981999
{
1999-
if (!JL_FEAT_TEST(ctx, static_alloc)) allow_alloc = 0;
20002000
if (jl_is_symbol(ex)) {
20012001
jl_sym_t *sym = (jl_sym_t*)ex;
20022002
if (jl_is_const(ctx.module, sym))
@@ -2032,16 +2032,16 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex, int sparams=tr
20322032
if (jl_is_expr(ex)) {
20332033
jl_expr_t *e = (jl_expr_t*)ex;
20342034
if (e->head == call_sym) {
2035-
jl_value_t *f = static_eval(ctx, jl_exprarg(e, 0), sparams, allow_alloc);
2035+
jl_value_t *f = static_eval(ctx, jl_exprarg(e, 0));
20362036
if (f) {
20372037
if (jl_array_dim0(e->args) == 3 && f == jl_builtin_getfield) {
2038-
m = (jl_module_t*)static_eval(ctx, jl_exprarg(e, 1), sparams, allow_alloc);
2038+
m = (jl_module_t*)static_eval(ctx, jl_exprarg(e, 1));
20392039
// Check the tag before evaluating `s` so that a value of random
20402040
// type won't be corrupted.
20412041
if (!m || !jl_is_module(m))
20422042
return NULL;
20432043
// Assumes that the module is rooted somewhere.
2044-
s = (jl_sym_t*)static_eval(ctx, jl_exprarg(e, 2), sparams, allow_alloc);
2044+
s = (jl_sym_t*)static_eval(ctx, jl_exprarg(e, 2));
20452045
if (s && jl_is_symbol(s)) {
20462046
jl_binding_t *b = jl_get_binding(m, s);
20472047
if (b && b->constp) {
@@ -2055,13 +2055,11 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex, int sparams=tr
20552055
size_t i;
20562056
size_t n = jl_array_dim0(e->args)-1;
20572057
if (n==0 && f==jl_builtin_tuple) return (jl_value_t*)jl_emptytuple;
2058-
if (!allow_alloc)
2059-
return NULL;
20602058
jl_value_t **v;
20612059
JL_GC_PUSHARGS(v, n+1);
20622060
v[0] = f;
20632061
for (i = 0; i < n; i++) {
2064-
v[i+1] = static_eval(ctx, jl_exprarg(e, i+1), sparams, allow_alloc);
2062+
v[i+1] = static_eval(ctx, jl_exprarg(e, i+1));
20652063
if (v[i+1] == NULL) {
20662064
JL_GC_POP();
20672065
return NULL;

src/julia.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,6 @@ typedef jl_value_t *(*jl_codeinstance_lookup_t)(jl_method_instance_t *mi JL_PROP
21132113
typedef struct {
21142114
int track_allocations; // can we track allocations?
21152115
int code_coverage; // can we measure coverage?
2116-
int static_alloc; // is the compiler allowed to allocate statically?
21172116
int prefer_specsig; // are specialized function signatures preferred?
21182117

21192118
// controls the emission of debug-info. mirrors the clang options

0 commit comments

Comments
 (0)