Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove filename from line number nodes #15000

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
#end

#immutable LineNumberNode
# file::Symbol
# line::Int
#end

Expand Down Expand Up @@ -310,7 +309,7 @@ _new(:TopNode, :Symbol)
_new(:NewvarNode, :Symbol)
_new(:QuoteNode, :ANY)
_new(:GenSym, :Int)
eval(:((::Type{LineNumberNode})(f::Symbol, l::Int) = $(Expr(:new, :LineNumberNode, :f, :l))))
eval(:((::Type{LineNumberNode})(l::Int) = $(Expr(:new, :LineNumberNode, :l))))
eval(:((::Type{GlobalRef})(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))

Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Any, (Any, Bool), name, std_imports)::Module
Expand Down
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ end

emphasize(io, str::AbstractString) = have_color ? print_with_color(:red, io, str) : print(io, uppercase(str))

show_linenumber(io::IO, file, line) = print(io," # ", file,", line ",line,':')
show_linenumber(io::IO, line) = print(io," # line ",line,':')

# show a block, e g if/for/etc
function show_block(io::IO, head, args::Vector, body, indent::Int)
Expand Down Expand Up @@ -486,7 +486,7 @@ end
## AST printing ##

show_unquoted(io::IO, sym::Symbol, ::Int, ::Int) = print(io, sym)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.file, ex.line)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.line)
show_unquoted(io::IO, ex::LabelNode, ::Int, ::Int) = print(io, ex.label, ": ")
show_unquoted(io::IO, ex::GotoNode, ::Int, ::Int) = print(io, "goto ", ex.label)
show_unquoted(io::IO, ex::TopNode, ::Int, ::Int) = print(io,"top(",ex.name,')')
Expand Down
8 changes: 1 addition & 7 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,8 @@ jl_lambda_info_t *jl_new_lambda_info(jl_value_t *ast, jl_svec_t *tvars, jl_svec_
if (has_meta(body, pure_sym))
li->pure = 1;
jl_value_t *body1 = skip_meta(body);
if (jl_is_linenode(body1)) {
li->file = jl_linenode_file(body1);
if (jl_is_linenode(body1))
li->line = jl_linenode_line(body1);
}
else if (jl_is_expr(body1) && ((jl_expr_t*)body1)->head == line_sym) {
li->file = (jl_sym_t*)jl_exprarg(body1, 1);
li->line = jl_unbox_long(jl_exprarg(body1, 0));
}
jl_array_t *vis = jl_lam_vinfo((jl_expr_t*)li->ast);
jl_array_t *args = jl_lam_args((jl_expr_t*)li->ast);
size_t narg = jl_array_len(args);
Expand Down
27 changes: 7 additions & 20 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int eo)
e = cdr_(e);
}
nli = jl_new_lambda_info((jl_value_t*)ex, tvars, jl_emptysvec, jl_current_module);
nli->file = jl_symbol(jl_filename);
jl_preresolve_globals(nli->ast, nli);
JL_GC_POP();
return (jl_value_t*)nli;
Expand All @@ -494,16 +495,10 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int eo)
else
n++;
if (!eo) {
if (sym == line_sym && n==2) {
// NOTE: n==3 case exists: '(line, linenum, filename, funcname) passes
// the original name through to keyword-arg specializations.
// See 'line handling in julia-syntax.scm:keywords-method-def-expr
jl_value_t *filename = NULL, *linenum = NULL;
JL_GC_PUSH2(&filename, &linenum);
filename = scm_to_julia_(fl_ctx, car_(cdr_(e)), 0);
linenum = scm_to_julia_(fl_ctx, car_(e), 0);
jl_value_t *temp = jl_new_struct(jl_linenumbernode_type,
filename, linenum);
if (sym == line_sym && n==1) {
jl_value_t *linenum = scm_to_julia_(fl_ctx, car_(e), 0);
JL_GC_PUSH1(&linenum);
jl_value_t *temp = jl_new_struct(jl_linenumbernode_type, linenum);
JL_GC_POP();
return temp;
}
Expand Down Expand Up @@ -657,19 +652,11 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v)
fl_free_gc_handles(fl_ctx, 1);
return scmv;
}
if (jl_typeis(v, jl_linenumbernode_type)) {
// GC Note: jl_fieldref(v, 1) allocates but neither jl_fieldref(v, 0)
// or julia_to_list2 should allocate here
value_t args = julia_to_list2(fl_ctx, jl_fieldref(v,1), jl_fieldref(v,0));
fl_gc_handle(fl_ctx, &args);
value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)line_sym);
value_t scmv = fl_cons(fl_ctx, hd, args);
fl_free_gc_handles(fl_ctx, 1);
return scmv;
}
// GC Note: jl_fieldref(v, 0) allocate for LabelNode, GotoNode
// but we don't need a GC root here because julia_to_list2
// shouldn't allocate in this case.
if (jl_typeis(v, jl_linenumbernode_type))
return julia_to_list2(fl_ctx, (jl_value_t*)line_sym, jl_fieldref(v,0));
if (jl_typeis(v, jl_labelnode_type))
return julia_to_list2(fl_ctx, (jl_value_t*)label_sym, jl_fieldref(v,0));
if (jl_typeis(v, jl_gotonode_type))
Expand Down
3 changes: 1 addition & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,8 +1388,7 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v,
n += jl_printf(out, ")");
}
else if (vt == jl_linenumbernode_type) {
n += jl_printf(out, "# line %" PRIuPTR " %s",
jl_linenode_line(v), jl_symbol_name(jl_linenode_file(v)));
n += jl_printf(out, "# line %" PRIuPTR, jl_linenode_line(v));
}
else if (vt == jl_expr_type) {
jl_expr_t *e = (jl_expr_t*)v;
Expand Down
2 changes: 2 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ JL_DLLEXPORT Type *julia_type_to_llvm(jl_value_t *jt, bool *isboxed)
return PointerType::get(lt, 0);
}
if (jl_is_bitstype(jt)) {
if (jt == (jl_value_t*)jl_long_type)
return T_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could probably also just generally generically cache these in jst->struct_decl

int nb = jl_datatype_size(jt);
if (jl_is_floattype(jt)) {
#ifndef DISABLE_FLOAT16
Expand Down
13 changes: 2 additions & 11 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4421,13 +4421,13 @@ static void emit_function(jl_lambda_info_t *lam, jl_llvm_functions_t *declaratio
bool do_coverage = jl_options.code_coverage == JL_LOG_ALL || (jl_options.code_coverage == JL_LOG_USER && in_user_code);
bool do_malloc_log = jl_options.malloc_log == JL_LOG_ALL || (jl_options.malloc_log == JL_LOG_USER && in_user_code);
jl_value_t *stmt = skip_meta(stmts);
std::string filename = "no file";
jl_sym_t *file = lam->file;
std::string filename = jl_symbol_name(lam->file);
char *dbgFuncName = jl_symbol_name(lam->name);
int lno = -1;
// look for initial (line num filename [funcname]) node, [funcname] for kwarg methods.
if (jl_is_linenode(stmt)) {
lno = jl_linenode_line(stmt);
filename = jl_symbol_name(jl_linenode_file(stmt));
}
else if (jl_is_expr(stmt) && ((jl_expr_t*)stmt)->head == line_sym &&
jl_array_dim0(((jl_expr_t*)stmt)->args) > 0) {
Expand Down Expand Up @@ -4929,21 +4929,12 @@ static void emit_function(jl_lambda_info_t *lam, jl_llvm_functions_t *declaratio
if (jl_is_linenode(stmt) ||
(jl_is_expr(stmt) && ((jl_expr_t*)stmt)->head == line_sym)) {

jl_sym_t *file = NULL;
if (jl_is_linenode(stmt)) {
lno = jl_linenode_line(stmt);
file = jl_linenode_file(stmt);
}
else if (jl_is_expr(stmt)) {
lno = jl_unbox_long(jl_exprarg(stmt,0));
if (jl_array_dim0(((jl_expr_t*)stmt)->args) > 1) {
jl_value_t *a1 = jl_exprarg(stmt,1);
if (jl_is_symbol(a1)) {
file = (jl_sym_t*)a1;
}
}
}
assert(jl_symbol_name(file));

# ifdef LLVM37
DIFile *dfil = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ JL_DLLEXPORT jl_lambda_info_t *jl_instantiate_staged(jl_lambda_info_t *generator
jl_cellset(((jl_expr_t*)jl_exprarg(ex,1))->args, 0, body);

linenum = jl_box_long(generator->line);
jl_value_t *linenode = jl_new_struct(jl_linenumbernode_type, generator->file, linenum);
jl_value_t *linenode = jl_new_struct(jl_linenumbernode_type, linenum);
jl_cellset(body->args, 0, linenode);

// invoke code generator
Expand Down
4 changes: 2 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3437,8 +3437,8 @@ void jl_init_types(void)

jl_linenumbernode_type =
jl_new_datatype(jl_symbol("LineNumberNode"), jl_any_type, jl_emptysvec,
jl_svec(2, jl_symbol("file"), jl_symbol("line")),
jl_svec(2, jl_symbol_type, jl_long_type), 0, 0, 2);
jl_svec(1, jl_symbol("line")),
jl_svec(1, jl_long_type), 0, 0, 1);

jl_labelnode_type =
jl_new_datatype(jl_symbol("LabelNode"), jl_any_type, jl_emptysvec,
Expand Down
4 changes: 2 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,15 @@
(memv tok '(#\) #\] #\} else elseif catch finally =))))

(define (line-number-node s)
`(line ,(input-port-line (ts:port s)) ,current-filename))
`(line ,(input-port-line (ts:port s))))

;; insert line/file for short-form function defs, otherwise leave alone
(define (short-form-function-loc ex lno)
(if (and (pair? ex)
(eq? (car ex) '=)
(pair? (cadr ex))
(eq? (caadr ex) 'call))
`(= ,(cadr ex) (block (line ,lno ,current-filename) ,(caddr ex)))
`(= ,(cadr ex) (block (line ,lno) ,(caddr ex)))
ex))

;; parse a@b@c@... as (@ a b c ...) for some operator @
Expand Down
9 changes: 2 additions & 7 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@
,(method-def-expr-
name positional-sparams (append pargl vararg)
`(block
,(if (null? lno)
`(line 0 || ||)
(append (car lno) '(||)))
,@lno
,@(if (not ordered-defaults)
'()
(map make-assignment keynames vals))
Expand Down Expand Up @@ -445,9 +443,7 @@
(car pargl))
,@(cdr pargl) ,@vararg)
`(block
,@(if (null? lno) '()
;; TODO jb/functions get a better `name` for functions specified by type
(list (append (car lno) (list (undot-name name)))))
,@lno
,@stmts) isstaged)

;; call with unsorted keyword args. this sorts and re-dispatches.
Expand All @@ -459,7 +455,6 @@
positional-sparams)
`((|::| ,UNUSED (call (|.| Core 'kwftype) ,ftype)) (:: ,kw (top Array)) ,@pargl ,@vararg)
`(block
(line 0 || ||)
;; initialize keyword args to their defaults, or set a flag telling
;; whether this keyword needs to be set.
,@(map (lambda (name dflt flag)
Expand Down
3 changes: 1 addition & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,7 @@ STATIC_INLINE jl_value_t *jl_cellset(void *a, size_t i, void *x)
// Not using jl_fieldref to avoid allocations
#define jl_symbolnode_sym(s) (*(jl_sym_t**)s)
#define jl_symbolnode_type(s) (((jl_value_t**)s)[1])
#define jl_linenode_file(x) (*(jl_sym_t**)x)
#define jl_linenode_line(x) (((intptr_t*)x)[1])
#define jl_linenode_line(x) (((intptr_t*)x)[0])
#define jl_labelnode_label(x) (((intptr_t*)x)[0])
#define jl_gotonode_label(x) (((intptr_t*)x)[0])
#define jl_globalref_mod(s) (*(jl_module_t**)s)
Expand Down
10 changes: 5 additions & 5 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ end

# same-file inline
eval(Expr(:function, Expr(:call, :test_inline_1),
Expr(:block, LineNumberNode(symbol("backtrace.jl"), 42),
LineNumberNode(symbol("backtrace.jl"), 37),
Expr(:block, LineNumberNode(42),
LineNumberNode(37),
Expr(:call, :throw, "foo"))))

# different-file inline
const absfilepath = OS_NAME == :Windows ? "C:\\foo\\bar\\baz.jl" : "/foo/bar/baz.jl"
eval(Expr(:function, Expr(:call, :test_inline_2),
Expr(:block, LineNumberNode(symbol("backtrace.jl"), 99),
LineNumberNode(symbol("foobar.jl"), 666),
LineNumberNode(symbol(absfilepath), 111),
Expr(:block, LineNumberNode(99),
LineNumberNode(666),
LineNumberNode(111),
Expr(:call, :throw, "foo"))))

try
Expand Down