Skip to content

Commit

Permalink
fix #10695, Defining a function named "parse" fails in peculiar circu…
Browse files Browse the repository at this point in the history
…mstances

jl_has_intrinsics was using current_module, but is sometimes used to
examine the body of a function from elsewhere before compilation.
  • Loading branch information
JeffBezanson committed Mar 31, 2015
1 parent c5b803a commit 3d37c86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ void jl_show(jl_value_t *stream, jl_value_t *v)

extern int jl_in_inference;
extern int jl_boot_file_loaded;
int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops);
int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops, jl_module_t *m);

void jl_trampoline_compile_function(jl_function_t *f, int always_infer, jl_tuple_t *sig)
{
Expand All @@ -986,7 +986,7 @@ void jl_trampoline_compile_function(jl_function_t *f, int always_infer, jl_tuple
f->linfo->ast = jl_uncompress_ast(f->linfo, f->linfo->ast);
gc_wb(f->linfo, f->linfo->ast);
}
if (always_infer || jl_eval_with_compiler_p(jl_lam_body((jl_expr_t*)f->linfo->ast),1)) {
if (always_infer || jl_eval_with_compiler_p(jl_lam_body((jl_expr_t*)f->linfo->ast),1,f->linfo->module)) {
jl_type_infer(f->linfo, sig, f->linfo);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jl_value_t *jl_eval_global_var(jl_module_t *m, jl_sym_t *e)

void jl_check_static_parameter_conflicts(jl_lambda_info_t *li, jl_tuple_t *t, jl_sym_t *fname);

int jl_has_intrinsics(jl_expr_t *e);
int jl_has_intrinsics(jl_expr_t *e, jl_module_t *m);

extern int jl_boot_file_loaded;
extern int inside_typedef;
Expand Down Expand Up @@ -180,7 +180,7 @@ static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl, size_t ng
// directly calling an inner function ("let")
jl_lambda_info_t *li = (jl_lambda_info_t*)args[0];
if (jl_is_expr(li->ast) && !jl_lam_vars_captured((jl_expr_t*)li->ast) &&
!jl_has_intrinsics((jl_expr_t*)li->ast)) {
!jl_has_intrinsics((jl_expr_t*)li->ast, jl_current_module)) {
size_t na = nargs-1;
if (na == 0)
return jl_interpret_toplevel_thunk(li);
Expand Down
16 changes: 8 additions & 8 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,28 @@ jl_module_t *jl_base_relative_to(jl_module_t *m)
return (m==jl_core_module||m==jl_old_base_module||jl_base_module==NULL) ? m : jl_base_module;
}

int jl_has_intrinsics(jl_expr_t *e)
int jl_has_intrinsics(jl_expr_t *e, jl_module_t *m)
{
if (jl_array_len(e->args) == 0)
return 0;
if (e->head == static_typeof_sym) return 1;
jl_value_t *e0 = jl_exprarg(e,0);
if (e->head == call_sym &&
((jl_is_symbol(e0) && is_intrinsic(jl_current_module,(jl_sym_t*)e0)) ||
(jl_is_topnode(e0) && is_intrinsic(jl_base_relative_to(jl_current_module),(jl_sym_t*)jl_fieldref(e0,0)))))
((jl_is_symbol(e0) && is_intrinsic(m,(jl_sym_t*)e0)) ||
(jl_is_topnode(e0) && is_intrinsic(jl_base_relative_to(m),(jl_sym_t*)jl_fieldref(e0,0)))))
return 1;
int i;
for(i=0; i < jl_array_len(e->args); i++) {
jl_value_t *a = jl_exprarg(e,i);
if (jl_is_expr(a) && jl_has_intrinsics((jl_expr_t*)a))
if (jl_is_expr(a) && jl_has_intrinsics((jl_expr_t*)a, m))
return 1;
}
return 0;
}

// heuristic for whether a top-level input should be evaluated with
// the compiler or the interpreter.
int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops)
int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops, jl_module_t *m)
{
assert(jl_is_expr(expr));
if (expr->head==body_sym && compileloops) {
Expand Down Expand Up @@ -271,7 +271,7 @@ int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops)
}
}
}
if (jl_has_intrinsics(expr)) return 1;
if (jl_has_intrinsics(expr, m)) return 1;
return 0;
}

Expand Down Expand Up @@ -478,7 +478,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast)
thk = (jl_lambda_info_t*)jl_exprarg(ex,0);
assert(jl_is_lambda_info(thk));
assert(jl_is_expr(thk->ast));
ewc = jl_eval_with_compiler_p(jl_lam_body((jl_expr_t*)thk->ast), fast);
ewc = jl_eval_with_compiler_p(jl_lam_body((jl_expr_t*)thk->ast), fast, jl_current_module);
if (!ewc) {
if (jl_lam_vars_captured((jl_expr_t*)thk->ast)) {
// interpreter doesn't handle closure environment
Expand All @@ -487,7 +487,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast)
}
}
else {
if (head && jl_eval_with_compiler_p((jl_expr_t*)ex, fast)) {
if (head && jl_eval_with_compiler_p((jl_expr_t*)ex, fast, jl_current_module)) {
thk = jl_wrap_expr((jl_value_t*)ex);
ewc = 1;
}
Expand Down

0 comments on commit 3d37c86

Please sign in to comment.