Skip to content

Commit

Permalink
faster Expr constructor (large impact on sysimg build time)
Browse files Browse the repository at this point in the history
another Core.convert method to prevent types from old Base from leaking in
  • Loading branch information
JeffBezanson committed Oct 14, 2014
1 parent 0f67c69 commit bec065f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ TypeVar(n::Symbol, lb::ANY, ub::ANY, b::Bool) =

TypeConstructor(p::ANY, t::ANY) = ccall(:jl_new_type_constructor, Any, (Any, Any), p::Tuple, t::Type)

Expr(hd::Symbol, args::ANY...) = ccall(:jl_new_expr, Any, (Any, Any), hd, args)::Expr
Expr(args::ANY...) = _expr(args...)

LineNumberNode(n::Int) = ccall(:jl_new_struct, Any, (Any,Any...), LineNumberNode, n)::LineNumberNode
LabelNode(n::Int) = ccall(:jl_new_struct, Any, (Any,Any...), LabelNode, n)::LabelNode
Expand All @@ -273,4 +273,5 @@ Module() = Module(:anonymous)
Task(f::ANY) = ccall(:jl_new_task, Any, (Any, Int), f::Function, 0)::Task

# simple convert for use by constructors of types in Core
convert(::Type{Any}, x::ANY) = x
convert{T}(::Type{T}, x::T) = x
1 change: 1 addition & 0 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ t_func[Union] = (0, Inf,
else
Type
end))
t_func[_expr] = (1, Inf, (args...)->Expr)
t_func[method_exists] = (2, 2, cmp_tfunc)
t_func[applicable] = (1, Inf, (f, args...)->Bool)
t_func[tuplelen] = (1, 1, x->Int)
Expand Down
2 changes: 1 addition & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ eval(m,x) = Core.eval(m,x)

include = Core.include

using Core: Intrinsics, arraylen, arrayref, arrayset, arraysize,
using Core: Intrinsics, arraylen, arrayref, arrayset, arraysize, _expr,
tuplelen, tupleref, kwcall, _apply, typeassert, apply_type

include("exports.jl")
Expand Down
14 changes: 8 additions & 6 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int jl_field_index(jl_datatype_t *t, jl_sym_t *fld, int err)
jl_value_t *jl_get_nth_field(jl_value_t *v, size_t i)
{
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
assert(i < jl_tuple_len(st->names));
size_t offs = jl_field_offset(st,i) + sizeof(void*);
if (st->fields[i].isptr) {
return *(jl_value_t**)((char*)v + offs);
Expand Down Expand Up @@ -892,16 +893,17 @@ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
return ex;
}

DLLEXPORT jl_value_t *jl_new_expr(jl_sym_t *head, jl_tuple_t *args)
JL_CALLABLE(jl_f_new_expr)
{
size_t nargs = jl_tuple_len(args);
jl_array_t *ar = jl_alloc_cell_1d(nargs);
JL_NARGSV(Expr, 1);
JL_TYPECHK(Expr, symbol, args[0]);
jl_array_t *ar = jl_alloc_cell_1d(nargs-1);
JL_GC_PUSH1(&ar);
for(size_t i=0; i < nargs; i++)
jl_cellset(ar, i, jl_tupleref(args,i));
for(size_t i=0; i < nargs-1; i++)
jl_cellset(ar, i, args[i+1]);
jl_expr_t *ex = (jl_expr_t*)alloc_4w();
ex->type = (jl_value_t*)jl_expr_type;
ex->head = head;
ex->head = (jl_sym_t*)args[0];
ex->args = ar;
ex->etype = (jl_value_t*)jl_any_type;
JL_GC_POP();
Expand Down
2 changes: 2 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ JL_CALLABLE(jl_f_arraysize)

jl_value_t *jl_arrayref(jl_array_t *a, size_t i)
{
assert(i < jl_array_len(a));
jl_value_t *el_type = (jl_value_t*)jl_tparam0(jl_typeof(a));
jl_value_t *elt;
if (!a->ptrarray) {
Expand Down Expand Up @@ -490,6 +491,7 @@ int jl_array_isdefined(jl_value_t **args0, int nargs)

void jl_arrayset(jl_array_t *a, jl_value_t *rhs, size_t i)
{
assert(i < jl_array_len(a));
jl_value_t *el_type = jl_tparam0(jl_typeof(a));
if (el_type != (jl_value_t*)jl_any_type) {
if (!jl_subtype(rhs, el_type, 1))
Expand Down
1 change: 1 addition & 0 deletions src/builtin_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ JL_CALLABLE(jl_f_methodexists);
JL_CALLABLE(jl_f_applicable);
JL_CALLABLE(jl_f_invoke);
JL_CALLABLE(jl_f_yieldto);
JL_CALLABLE(jl_f_new_expr);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ void jl_init_primitives(void)
add_builtin_func("getfield", jl_f_get_field);
add_builtin_func("setfield!", jl_f_set_field);
add_builtin_func("fieldtype", jl_f_field_type);
add_builtin_func("_expr", jl_f_new_expr);

add_builtin_func("arraylen", jl_f_arraylen);
add_builtin_func("arrayref", jl_f_arrayref);
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ void jl_init_serializer(void)
jl_f_methodexists, jl_f_applicable,
jl_f_invoke, jl_apply_generic,
jl_unprotect_stack,
jl_f_yieldto, jl_f_sizeof,
jl_f_yieldto, jl_f_sizeof, jl_f_new_expr,
NULL };
i=2;
while (fptrs[i-2] != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ So far only the second case can actually occur.
((not (contains (lambda (e) (and (pair? e) (eq? (car e) '$))) e))
`(copyast (inert ,e)))
((not (any splice-expr? e))
`(call (top Expr) ,.(map expand-backquote e)))
`(call (top _expr) ,.(map expand-backquote e)))
(else
(let loop ((p (cdr e)) (q '()))
(if (null? p)
Expand Down
1 change: 1 addition & 0 deletions src/support/libsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include "dtypes.h"
#include "utils.h"
#include "utf8.h"
Expand Down

0 comments on commit bec065f

Please sign in to comment.