Skip to content

Commit d63f37a

Browse files
committed
Add --inline={yes|no} startup option
Turning off inlining improves the quality of backtraces for debugging
1 parent cf8e27d commit d63f37a

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

base/c.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,23 @@ macro ccallable(def)
140140
end
141141
error("expected method definition in @ccallable")
142142
end
143+
144+
# Julia compiler options struct (see jl_compileropts_t in src/julia.h)
145+
immutable JLCompilerOpts
146+
julia_home::Ptr{Cchar}
147+
julia_bin::Ptr{Cchar}
148+
build_path::Ptr{Cchar}
149+
image_file::Ptr{Cchar}
150+
cpu_target::Ptr{Cchar}
151+
code_coverage::Int8
152+
malloc_log::Int8
153+
check_bounds::Int8
154+
dumpbitcode::Int8
155+
int_literals::Cint
156+
compile_enabled::Int8
157+
opt_level::Int8
158+
depwarn::Int8
159+
can_inline::Int8
160+
end
161+
162+
compileropts() = unsafe_load(cglobal(:jl_compileropts, JLCompilerOpts))

base/inference.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,11 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
15541554

15551555
if !rec
15561556
@assert fulltree.args[3].head === :body
1557-
fulltree.args[3] = inlining_pass(fulltree.args[3], sv, fulltree)[1]
1558-
# inlining can add variables
1559-
sv.vars = append_any(f_argnames(fulltree), fulltree.args[2][1])
1557+
if compileropts().can_inline == 1
1558+
fulltree.args[3] = inlining_pass(fulltree.args[3], sv, fulltree)[1]
1559+
# inlining can add variables
1560+
sv.vars = append_any(f_argnames(fulltree), fulltree.args[2][1])
1561+
end
15601562
tuple_elim_pass(fulltree)
15611563
tupleref_elim_pass(fulltree.args[3], sv)
15621564
linfo.inferred = true

base/util.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,3 @@ end
241241

242242
warn(err::Exception; prefix="ERROR: ", kw...) =
243243
warn(sprint(io->showerror(io,err)), prefix=prefix; kw...)
244-
245-
# Julia compiler options struct (see jl_compileropts_t in src/julia.h)
246-
immutable JLCompilerOpts
247-
julia_home::Ptr{Cchar}
248-
julia_bin::Ptr{Cchar}
249-
build_path::Ptr{Cchar}
250-
image_file::Ptr{Cchar}
251-
cpu_target::Ptr{Cchar}
252-
code_coverage::Int8
253-
malloc_log::Int8
254-
check_bounds::Int8
255-
dumpbitcode::Int8
256-
int_literals::Cint
257-
compile_enabled::Int8
258-
opt_level::Int8
259-
depwarn::Int8
260-
end
261-
262-
compileropts() = unsafe_load(cglobal(:jl_compileropts, JLCompilerOpts))

src/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jl_compileropts_t jl_compileropts = { NULL, // julia_home
101101
JL_COMPILEROPT_COMPILE_DEFAULT,
102102
0, // opt_level
103103
1, // depwarn
104+
1 // can_inline
104105
};
105106

106107
int jl_boot_file_loaded = 0;

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ typedef struct {
13311331
int8_t compile_enabled;
13321332
int8_t opt_level;
13331333
int8_t depwarn;
1334+
int8_t can_inline;
13341335
} jl_compileropts_t;
13351336

13361337
extern DLLEXPORT jl_compileropts_t jl_compileropts;

ui/repl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static const char *opts =
7272
" --track-allocation={none|user|all}\n"
7373
" Count bytes allocated by each source line\n"
7474
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n"
75+
" --inline={yes|no} Control whether inlining is permitted (even for functions declared as @inline)\n"
7576
" -O, --optimize Run time-intensive code optimizations\n"
7677
" --int-literals={32|64} Select integer literal size independent of platform\n"
7778
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n"
@@ -95,6 +96,7 @@ void parse_opts(int *argcp, char ***argvp)
9596
{ "dump-bitcode", required_argument, 0, 302 },
9697
{ "compile", required_argument, 0, 303 },
9798
{ "depwarn", required_argument, 0, 304 },
99+
{ "inline", required_argument, 0, 305 },
98100
{ 0, 0, 0, 0 }
99101
};
100102
int c;
@@ -198,6 +200,16 @@ void parse_opts(int *argcp, char ***argvp)
198200
exit(1);
199201
}
200202
break;
203+
case 305: /* inline */
204+
if (!strcmp(optarg,"yes"))
205+
jl_compileropts.can_inline = 1;
206+
else if (!strcmp(optarg,"no"))
207+
jl_compileropts.can_inline = 0;
208+
else {
209+
ios_printf(ios_stderr, "julia: invalid argument to --inline (%s)\n", optarg);
210+
exit(1);
211+
}
212+
break;
201213
default:
202214
ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c);
203215
ios_printf(ios_stderr, "This is a bug, please report it.\n");

0 commit comments

Comments
 (0)