Skip to content

Commit

Permalink
fix #4505, scope of inner functions with static parameters
Browse files Browse the repository at this point in the history
also incidentally fixes #4677
  • Loading branch information
JeffBezanson committed Oct 30, 2013
1 parent 2cc702d commit ceeade0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
9 changes: 2 additions & 7 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ static void simple_escape_analysis(jl_value_t *expr, bool esc, jl_codectx_t *ctx
simple_escape_analysis(jl_exprarg(e,0), esc, ctx);
simple_escape_analysis(jl_exprarg(e,1), esc, ctx);
simple_escape_analysis(jl_exprarg(e,2), esc, ctx);
simple_escape_analysis(jl_exprarg(e,3), esc, ctx);
}
else {
size_t elen = jl_array_dim0(e->args);
Expand Down Expand Up @@ -2126,12 +2125,9 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed,
make_gcroot(a1, ctx);
Value *a2 = boxed(emit_expr(args[2], ctx));
make_gcroot(a2, ctx);
Value *a3 = boxed(emit_expr(args[3], ctx));
make_gcroot(a3, ctx);
Value *mdargs[6] = { name, bp, literal_pointer_val((void*)bnd),
a1, a2, a3 };
Value *mdargs[5] = { name, bp, literal_pointer_val((void*)bnd), a1, a2 };
ctx->argDepth = last_depth;
return builder.CreateCall(jlmethod_func, ArrayRef<Value*>(&mdargs[0], 6));
return builder.CreateCall(jlmethod_func, ArrayRef<Value*>(&mdargs[0], 5));
}
else if (head == const_sym) {
jl_sym_t *sym = (jl_sym_t*)args[0];
Expand Down Expand Up @@ -3331,7 +3327,6 @@ static void init_julia_llvm_env(Module *m)
mdargs.push_back(T_pint8);
mdargs.push_back(jl_pvalue_llvmt);
mdargs.push_back(jl_pvalue_llvmt);
mdargs.push_back(jl_pvalue_llvmt);
jlmethod_func =
Function::Create(FunctionType::get(jl_pvalue_llvmt, mdargs, false),
Function::ExternalLinkage,
Expand Down
8 changes: 3 additions & 5 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,11 @@ static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl)
bp = &b->value;
}
}
jl_value_t *atypes=NULL, *meth=NULL, *tvars=NULL;
JL_GC_PUSH3(&atypes, &meth, &tvars);
jl_value_t *atypes=NULL, *meth=NULL;
JL_GC_PUSH2(&atypes, &meth);
atypes = eval(args[1], locals, nl);
meth = eval(args[2], locals, nl);
tvars = eval(args[3], locals, nl);
jl_method_def(fname, bp, b, (jl_tuple_t*)atypes,
(jl_function_t*)meth, (jl_tuple_t*)tvars);
jl_method_def(fname, bp, b, (jl_tuple_t*)atypes, (jl_function_t*)meth);
JL_GC_POP();
return *bp;
}
Expand Down
16 changes: 8 additions & 8 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@
(let* ((types (llist-types argl))
(body (method-lambda-expr argl body)))
(if (null? sparams)
`(method ,name (tuple ,@types) ,body (tuple))
(let ((f (gensy)))
`(call (lambda (,@names ,f)
(method ,name (tuple ,@types) ,f (tuple ,@names)))
,@(symbols->typevars names bounds #t)
,body)))))))
`(method ,name (tuple (tuple ,@types) (tuple)) ,body)
`(method ,name
(call (lambda ,names
(tuple (tuple ,@types) (tuple ,@names)))
,@(symbols->typevars names bounds #t))
,body))))))

(define (vararg? x) (and (pair? x) (eq? (car x) '...)))
(define (trans? x) (and (pair? x) (eq? (car x) '|.'|)))
Expand Down Expand Up @@ -779,6 +779,7 @@
,mut)))
(scope-block
(block
(global ,name)
(global ,@params)
,@(if (and (null? defs)
;; don't generate an outer constructor if the type has
Expand Down Expand Up @@ -2740,8 +2741,7 @@ So far only the second case can actually occur.
(vinfo:set-iasg! vi #t)))))
`(method ,(cadr e)
,(analyze-vars (caddr e) env captvars)
,(analyze-vars (cadddr e) env captvars)
,(cadddr (cdr e))))
,(analyze-vars (cadddr e) env captvars)))
(else (cons (car e)
(map (lambda (x) (analyze-vars x env captvars))
(cdr e))))))
Expand Down
3 changes: 1 addition & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ void jl_initialize_generic_function(jl_function_t *f, jl_sym_t *name);
void jl_add_method(jl_function_t *gf, jl_tuple_t *types, jl_function_t *meth,
jl_tuple_t *tvars);
jl_value_t *jl_method_def(jl_sym_t *name, jl_value_t **bp, jl_binding_t *bnd,
jl_tuple_t *argtypes, jl_function_t *f,
jl_tuple_t *tvars);
jl_tuple_t *argtypes, jl_function_t *f);
jl_value_t *jl_box_bool(int8_t x);
jl_value_t *jl_box_int8(int32_t x);
jl_value_t *jl_box_uint8(uint32_t x);
Expand Down
5 changes: 4 additions & 1 deletion src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,11 @@ static int type_contains(jl_value_t *ty, jl_value_t *x)
void print_func_loc(JL_STREAM *s, jl_lambda_info_t *li);

jl_value_t *jl_method_def(jl_sym_t *name, jl_value_t **bp, jl_binding_t *bnd,
jl_tuple_t *argtypes, jl_function_t *f, jl_tuple_t *t)
jl_tuple_t *argtypes, jl_function_t *f)
{
// argtypes is a tuple ((types...), (typevars...))
jl_tuple_t *t = (jl_tuple_t*)jl_t1(argtypes);
argtypes = (jl_tuple_t*)jl_t0(argtypes);
jl_value_t *gf;
if (bnd) {
//jl_declare_constant(bnd);
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1077,3 +1077,10 @@ end
# issue #4645
i4645(x) = (println(zz); zz = x; zz)
@test_throws i4645(4)

# issue #4505
let
g4505{X}(::X) = 0
@test g4505(0) == 0
end
@test !isdefined(:g4505)

0 comments on commit ceeade0

Please sign in to comment.