Skip to content

Commit c2b487d

Browse files
authored
fix lineinfo depth missed update (#36782)
The codepaths disagreed about whether to update the inlining depth, triggering the assertion for this (and leading to bad printing). Merge the code paths so that doesn't happen anymore Fixes #35919
1 parent ede53f6 commit c2b487d

File tree

2 files changed

+36
-74
lines changed

2 files changed

+36
-74
lines changed

base/compiler/ssair/show.jl

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ function compute_ir_line_annotations(code::IRCode)
316316
push!(loc_methods, loc_method)
317317
last_line = line
318318
(lineno != 0) && (last_lineno = lineno)
319+
nothing
319320
end
320321
return (loc_annotations, loc_methods, loc_lineno)
321322
end
@@ -396,14 +397,14 @@ function DILineInfoPrinter(linetable::Vector, showtypes::Bool=false)
396397
end
397398
else
398399
npops = length(context) - nctx
399-
end
400-
# look at the first non-matching element to see if we are only changing the line number
401-
if !update_line_only && nctx < nframes
402-
let CtxLine = context[nctx + 1],
403-
FrameLine = DI[nframes - nctx]
404-
if CtxLine.file === FrameLine.file &&
405-
method_name(CtxLine) === method_name(FrameLine)
406-
update_line_only = true
400+
# look at the first non-matching element to see if we are only changing the line number
401+
if !update_line_only && nctx < nframes
402+
let CtxLine = context[nctx + 1],
403+
FrameLine = DI[nframes - nctx]
404+
if CtxLine.file === FrameLine.file &&
405+
method_name(CtxLine) === method_name(FrameLine)
406+
update_line_only = true
407+
end
407408
end
408409
end
409410
end
@@ -416,35 +417,12 @@ function DILineInfoPrinter(linetable::Vector, showtypes::Bool=false)
416417
println(io)
417418
end
418419
end
419-
# see what change we made to the outermost line number
420-
if update_line_only
421-
frame = DI[nframes - nctx]
422-
nctx += 1
423-
push!(context, frame)
424-
if frame.line != typemax(frame.line) && frame.line != 0
425-
print(io, linestart)
426-
Base.with_output_color(linecolor, io) do io
427-
print(io, indent(""), " @ ", frame.file, ":", frame.line, " within `", method_name(frame), "'")
428-
if collapse
429-
method = method_name(frame)
430-
while nctx < nframes
431-
frame = DI[nframes - nctx]
432-
method_name(frame) === method || break
433-
nctx += 1
434-
push!(context, frame)
435-
print(io, " @ ", frame.file, ":", frame.line)
436-
end
437-
end
438-
end
439-
println(io)
440-
end
441-
end
442-
# now print the rest of the new frames
420+
# now print the new frames
443421
while nctx < nframes
444422
frame = DI[nframes - nctx]
445423
nctx += 1
446424
started = false
447-
if showtypes && !isa(frame.method, Symbol) && nctx != 1
425+
if !update_line_only && showtypes && !isa(frame.method, Symbol) && nctx != 1
448426
print(io, linestart)
449427
Base.with_output_color(linecolor, io) do io
450428
print(io, indent(""))
@@ -457,8 +435,12 @@ function DILineInfoPrinter(linetable::Vector, showtypes::Bool=false)
457435
Base.with_output_color(linecolor, io) do io
458436
print(io, indent(""))
459437
push!(context, frame)
460-
context_depth[] += 1
461-
nctx != 1 && print(io, started ? "" : "")
438+
if update_line_only
439+
update_line_only = false
440+
else
441+
context_depth[] += 1
442+
nctx != 1 && print(io, started ? "" : "")
443+
end
462444
print(io, " @ ", frame.file)
463445
if frame.line != typemax(frame.line) && frame.line != 0
464446
print(io, ":", frame.line)

src/disasm.cpp

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ void DILineInfoPrinter::emit_lineinfo(raw_ostream &Out, std::vector<DILineInfo>
208208
}
209209
else {
210210
npops = context.size() - nctx;
211-
}
212-
// look at the first non-matching element to see if we are only changing the line number
213-
if (!update_line_only && nctx < nframes) {
214-
const DILineInfo &CtxLine = context.at(nctx);
215-
const DILineInfo &FrameLine = DI.at(nframes - 1 - nctx);
216-
if (CtxLine.FileName == FrameLine.FileName &&
217-
StringRef(CtxLine.FunctionName).rtrim(';') == StringRef(FrameLine.FunctionName).rtrim(';')) {
218-
update_line_only = true;
211+
// look at the first non-matching element to see if we are only changing the line number
212+
if (!update_line_only && nctx < nframes) {
213+
const DILineInfo &CtxLine = context.at(nctx);
214+
const DILineInfo &FrameLine = DI.at(nframes - 1 - nctx);
215+
if (CtxLine.FileName == FrameLine.FileName &&
216+
StringRef(CtxLine.FunctionName).rtrim(';') == StringRef(FrameLine.FunctionName).rtrim(';')) {
217+
update_line_only = true;
218+
}
219219
}
220220
}
221221
context.resize(nctx);
@@ -225,46 +225,26 @@ void DILineInfoPrinter::emit_lineinfo(raw_ostream &Out, std::vector<DILineInfo>
225225
Out << LineStart << inlining_indent("") << repeat{npops, ""} << '\n';
226226
}
227227
}
228-
// see what change we made to the outermost line number
229-
if (update_line_only) {
230-
const DILineInfo &frame = DI.at(nframes - 1 - nctx);
231-
nctx += 1;
232-
context.push_back(frame);
233-
if (frame.Line != UINT_MAX && frame.Line != 0) {
234-
StringRef method = StringRef(frame.FunctionName).rtrim(';');
235-
Out << LineStart << inlining_indent("")
236-
<< " @ " << frame.FileName
237-
<< ":" << frame.Line
238-
<< " within `" << method << "'";
239-
if (collapse_recursive) {
240-
while (nctx < nframes) {
241-
const DILineInfo &frame = DI.at(nframes - 1 - nctx);
242-
if (StringRef(frame.FunctionName).rtrim(';') != method)
243-
break;
244-
nctx += 1;
245-
context.push_back(frame);
246-
Out << " @ " << frame.FileName
247-
<< ":" << frame.Line;
248-
}
249-
}
250-
Out << "\n";
251-
}
252-
}
253-
// now print the rest of the new frames
228+
// print the new frames
254229
while (nctx < nframes) {
255230
const DILineInfo &frame = DI.at(nframes - 1 - nctx);
256231
Out << LineStart << inlining_indent("");
257232
nctx += 1;
258233
context.push_back(frame);
259-
this->inline_depth += 1;
260-
if (bracket_outer || nctx != 1)
261-
Out << "";
234+
if (update_line_only) {
235+
update_line_only = false;
236+
}
237+
else {
238+
this->inline_depth += 1;
239+
if (bracket_outer || nctx != 1)
240+
Out << "";
241+
}
262242
Out << " @ " << frame.FileName;
263243
if (frame.Line != UINT_MAX && frame.Line != 0)
264244
Out << ":" << frame.Line;
265-
Out << " within `" << StringRef(frame.FunctionName).rtrim(';') << "'";
245+
StringRef method = StringRef(frame.FunctionName).rtrim(';');
246+
Out << " within `" << method << "'";
266247
if (collapse_recursive) {
267-
StringRef method = StringRef(frame.FunctionName).rtrim(';');
268248
while (nctx < nframes) {
269249
const DILineInfo &frame = DI.at(nframes - 1 - nctx);
270250
if (StringRef(frame.FunctionName).rtrim(';') != method)

0 commit comments

Comments
 (0)