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

Check usage for verbose formatting of instructions in crashes #4145

Open
jonmeow opened this issue Jul 17, 2024 · 3 comments
Open

Check usage for verbose formatting of instructions in crashes #4145

jonmeow opened this issue Jul 17, 2024 · 3 comments
Assignees

Comments

@jonmeow
Copy link
Contributor

jonmeow commented Jul 17, 2024

#4125 added verbose formatting of instructions in crashes. If it's not used, or it gets in the way (a crash during a pretty printing) we might want to roll it back. This issue is to help track whether it's in use.

For example, this is the %<unexpected> formatted SemIR in the example crash output:

2.	Check::Context
          NodeStack:
(elided)
            2. IntLiteral:
              %<unexpected>.inst+26.loc12_10: i32 = int_literal 0 [template = constants.%.2]

Please comment here if you either:

  1. Have a toolchain crash where you find the instruction formatting useful (it'd particularly help to explain why formatted was helpful)
    • Also if you have a crash where you expected it to be helpful, but it wasn't.
  2. Have a toolchain crash which doesn't produce a stack trace, instead doing something like a SIGSEGV after argument printing and before Check::Context printing (which is symptomatic of a crash during the formatting, and could be worked around by just commenting it out temporarily).
@jonmeow
Copy link
Contributor Author

jonmeow commented Aug 7, 2024

In #4198, I got a stack trace from Formatter while trying to debug an interface crash. I'm trying to make the formatter more robust as a consequence. Note what I saw was actually a little quirky, with both stack traces and both CHECK messages, I think because of how CHECK works. But then I was trying to figure out what exactly was going on, it's pretty misleading to have the crash in formatter.

╚╡bazel run //toolchain -- compile --phase=check test.carbon
INFO: Invocation ID: 5ea2342f-85c0-4e36-898a-d37cba1c5e35
INFO: Analyzed target //toolchain:toolchain (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //toolchain/install:prefix_root/bin/carbon up-to-date:
  bazel-bin/toolchain/install/prefix_root/bin/carbon
INFO: Elapsed time: 0.320s, Critical Path: 0.07s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/toolchain/install/prefix_root/bin/carbon compile '--phase=check' test.carbon
Please report issues to https://github.com/carbon-language/carbon-lang/issues and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon compile --phase=check test.carbon
1.	Check::Context
          NodeStack:
            0. InterfaceDefinitionStart: interface0
          inst_block_stack_:
            0. block<invalid> {
                package: <namespace> = namespace [template] {
                  .Core = <unexpected>.inst+2
                  .A = <unexpected>.inst+3.loc1_13
                }
                <unexpected>.inst+1 = import Core
                <unexpected>.inst+3.loc1_13: type = interface_decl @A [template = constants.%.1] {}
                <unexpected>.inst+7.loc2_13: type = interface_decl @A [template = constants.%.1] {}
              }
            1. block5 {
                <unexpected>.inst+13.loc3_17: invalid = fn_decl #0 0x000055e881da841d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x710b41d)
 #1 0x000055e881da895b PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #2 0x000055e881da6006 llvm::sys::RunSignalHandlers() (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x7109006)
 #3 0x000055e881da93c5 SignalHandler(int) Signals.cpp:0:0
 #4 0x00007fd1d1e4c1a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0)
 #5 0x00007fd1d1e9a0ec __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fd1d1e4c102 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007fd1d1e354f2 abort ./stdlib/abort.c:81:7
 #8 0x000055e881cd3b75 (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x7036b75)
 #9 0x000055e87db8dd95 (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2ef0d95)
#10 0x000055e87dbb62a2 Carbon::SemIR::ConstantId::is_template() const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2f192a2)
#11 0x000055e87e322260 Carbon::SemIR::ConstantValueStore::GetInstId(Carbon::SemIR::ConstantId) const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x3685260)
#12 0x000055e87e4d1ba6 void Carbon::SemIR::FormatterImpl::FormatInst<Carbon::SemIR::FunctionDecl>(Carbon::SemIR::InstId, Carbon::SemIR::FunctionDecl) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x3834ba6)
#13 0x000055e87e4cc8bf Carbon::SemIR::FormatterImpl::FormatInst(Carbon::SemIR::InstId, Carbon::SemIR::Inst) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x382f8bf)
#14 0x000055e87e4c749b Carbon::SemIR::FormatterImpl::FormatInst(Carbon::SemIR::InstId) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x382a49b)
#15 0x000055e87e4c88b7 Carbon::SemIR::FormatterImpl::FormatCodeBlock(llvm::ArrayRef<Carbon::SemIR::InstId>) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x382b8b7)
#16 0x000055e87e4c73af Carbon::SemIR::FormatterImpl::FormatPartialTrailingCodeBlock(llvm::ArrayRef<Carbon::SemIR::InstId>) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x382a3af)
#17 0x000055e87e4c72c8 Carbon::SemIR::Formatter::PrintPartialTrailingCodeBlock(llvm::ArrayRef<Carbon::SemIR::InstId>, int, llvm::raw_ostream&) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x382a2c8)
#18 0x000055e87e436cd8 Carbon::Check::InstBlockStack::PrintForStackDump(Carbon::SemIR::Formatter&, int, llvm::raw_ostream&) const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x3799cd8)
#19 0x000055e87e39cbb2 Carbon::Check::Context::PrintForStackDump(llvm::raw_ostream&) const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x36ffbb2)
#20 0x000055e87e2e4cc0 Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0::operator()(llvm::raw_ostream&) const check.cpp:0:0
#21 0x000055e87e2e4c8d decltype(std::declval<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0&>()(std::declval<llvm::raw_ostream&>())) std::__1::__invoke[abi:v160006]<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0&, llvm::raw_ostream&>(Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0&, llvm::raw_ostream&) check.cpp:0:0
#22 0x000055e87e2e4c3d void std::__1::__invoke_void_return_wrapper<void, true>::__call<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0&, llvm::raw_ostream&>(Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0&, llvm::raw_ostream&) check.cpp:0:0
#23 0x000055e87e2e4c15 std::__1::__function::__alloc_func<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0, std::__1::allocator<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0>, void (llvm::raw_ostream&)>::operator()[abi:v160006](llvm::raw_ostream&) check.cpp:0:0
#24 0x000055e87e2e4031 std::__1::__function::__func<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0, std::__1::allocator<Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*)::$_0>, void (llvm::raw_ostream&)>::operator()(llvm::raw_ostream&) check.cpp:0:0
#25 0x000055e87dbad6ca std::__1::__function::__value_func<void (llvm::raw_ostream&)>::operator()[abi:v160006](llvm::raw_ostream&) const driver.cpp:0:0
#26 0x000055e87dbad67d std::__1::function<void (llvm::raw_ostream&)>::operator()(llvm::raw_ostream&) const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2f1067d)
#27 0x000055e87e2e4d61 Carbon::PrettyStackTraceFunction::print(llvm::raw_ostream&) const (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x3647d61)
#28 0x000055e881d93cb9 PrintStack(llvm::raw_ostream&) PrettyStackTrace.cpp:0:0
#29 0x000055e881d93bc7 PrintCurStackTrace(llvm::raw_ostream&) PrettyStackTrace.cpp:0:0
#30 0x000055e881d93e1d CrashHandler(void*) PrettyStackTrace.cpp:0:0
#31 0x000055e881da6006 llvm::sys::RunSignalHandlers() (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x7109006)
#32 0x000055e881da93c5 SignalHandler(int) Signals.cpp:0:0
#33 0x00007fd1d1e4c1a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0)
#34 0x00007fd1d1e9a0ec __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#35 0x00007fd1d1e4c102 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#36 0x00007fd1d1e354f2 abort ./stdlib/abort.c:81:7
#37 0x000055e881cd3b75 (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x7036b75)
#38 0x000055e87db8dd95 (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2ef0d95)
#39 0x000055e87e40f1c6 Carbon::Check::FinishGenericDecl(Carbon::Check::Context&, Carbon::SemIR::InstId) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x37721c6)
#40 0x000055e87e32fecb Carbon::Check::BuildFunctionDecl(Carbon::Check::Context&, Carbon::Parse::NodeIdOneOf<Carbon::Parse::NodeIdForKind<Carbon::Parse::NodeKind::FunctionDecl>, Carbon::Parse::NodeIdForKind<Carbon::Parse::NodeKind::FunctionDefinitionStart>, Carbon::Parse::NodeIdForKind<Carbon::Parse::NodeKind::BuiltinFunctionDefinitionStart>>, bool) handle_function.cpp:0:0
#41 0x000055e87e32f847 Carbon::Check::HandleParseNode(Carbon::Check::Context&, Carbon::Parse::NodeIdForKind<Carbon::Parse::NodeKind::FunctionDecl>) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x3692847)
#42 0x000055e87e2cd465 Carbon::Check::ProcessNodeIds(Carbon::Check::Context&, llvm::raw_ostream*, Carbon::ErrorTrackingDiagnosticConsumer&, Carbon::Parse::NodeLocConverter*) check.cpp:0:0
#43 0x000055e87e2b11dc Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*) check.cpp:0:0
#44 0x000055e87e2ae1ab Carbon::Check::CheckParseTrees(llvm::MutableArrayRef<Carbon::Check::Unit>, bool, llvm::raw_ostream*) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x36111ab)
#45 0x000055e87db8b5e4 Carbon::Driver::Compile(Carbon::Driver::CompileOptions const&, Carbon::Driver::CodegenOptions const&) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2eee5e4)
#46 0x000055e87db8ab66 Carbon::Driver::RunCommand(llvm::ArrayRef<llvm::StringRef>) (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2eedb66)
#47 0x000055e87db6ebca main (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2ed1bca)
#48 0x00007fd1d1e36b8a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#49 0x00007fd1d1e36c45 call_init ./csu/../csu/libc-start.c:128:20
#50 0x00007fd1d1e36c45 __libc_start_main ./csu/../csu/libc-start.c:347:5
#51 0x000055e87db6e961 _start (/usr/local/google/home/jperkins/.cache/bazel/_bazel_jperkins/85deb7d9d96f7e0e80b42618a55969d7/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/install/prefix_root/bin/carbon+0x2ed1961)
CHECK failure at toolchain/check/generic.cpp:302: context.generic_region_stack().PeekDependentInsts().empty(): Have dependent instructions but no compile time bindings are in scope.
CHECK failure at ./toolchain/sem_ir/ids.h:140: is_valid()
zsh: IOT instruction  bazel run //toolchain -- compile --phase=check test.carbon

github-merge-queue bot pushed a commit that referenced this issue Aug 7, 2024
The prior code crashed when trying to find the function's `Self`
parameter, I believe. `fail_redefine_with_dependents.carbon` handles
this case. It wasn't caught by the prior case because the `F` didn't
have any dependent parameters.

Note this also ran into a formatter crash, with invalid constants. I'm
fixing that here, but will also note it on #4145 (the crash in
FinishGenericDecl was muddled by a crash in Formatter code).
@geoffromer
Copy link
Contributor

I just ran into a similar issue, where the stack trace pretty-printer crashed in the formatter, giving me both stack traces and both CHECK failures, and it derailed my debugging for a little while.

For what it's worth, I've frequently found it to be helpful when the stack trace shows the Carbon code that was being processed at the time of the crash, but I'm not sure if that's in scope for this issue.

@jonmeow
Copy link
Contributor Author

jonmeow commented Sep 24, 2024

For what it's worth, I've frequently found it to be helpful when the stack trace shows the Carbon code that was being processed at the time of the crash, but I'm not sure if that's in scope for this issue.

Correct. This is really about printing of textual IR for inst IDs; I think what you're describing is the printing of lines of code for node IDs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants