xls icon indicating copy to clipboard operation
xls copied to clipboard

trace_fmt causes an internal XLS_RET_CHECK when building a xls_dslx_opt_ir rule

Open sandwichmaker opened this issue 2 years ago • 1 comments

Here is a minimal repro. Lets called it trace_fmt_repro.x.

pub const TWENTYFIVE = u8:25;
pub fn foo() -> u8 {
  let _ = trace_fmt!("{}", TWENTYFIVE);
  u8:1
}

#![test]
fn foo_test() {
  assert_eq(u8:1, foo())
}

With a BUILD file that looks like

xls_dslx_library(
    name = "trace_fmt_repro_dslx",
    srcs = ["trace_fmt_repro.x"],
)

xls_dslx_opt_ir(
    name = "trace_fmt_repro",
    dslx_top = "foo",
    # Don't emit asserts until they are emitted in a format which is expected by
    # the project consuming the Verilog.
    ir_conv_args = {
        "emit_fail_as_assert": "false",
    },
    library = ":trace_fmt_repro_dslx",
)

xls_dslx_test(
    name = "trace_fmt_repro_dslx_test",
    library = ":trace_fmt_repro_dslx",
)

Now blaze test trace_fmt_repro_dslx_test passes with an output that looks like

I0708 16:11:35.060264 2362626 init_google.cc:843] argv[4]: '-logtostderr'
I0708 16:11:35.060706 2362626 prodhostname_userspace_monitor_impl.cc:191] Not running under a Borglet, disabling ProdHostname userspace monitoring.
I0708 16:11:35.061032 2362626 logger.cc:296] Enabling threaded logging for severity WARNING
I0708 16:11:35.064730 2362626 mlock.cc:216] mlock()-ed 0 bytes for BuildID, using 0 syscalls.
[ RUN UNITTEST  ] foo_test
I0708 16:11:35.257525 2362626 bytecode_interpreter.cc:987] 25
[            OK ]
[===============] 1 test(s) ran; 0 failed; 0 skipped.

Notice that 25 is printed as expected. However if I now try to build trace_fmt_repro, I get the following trace

Converting DSLX file: <snip>trace_fmt_repro.x failed: (Exit 1) bash failed: error executing command (from target //<snip>:trace_fmt_repro) /usr/buildtools/buildhelpers/v4/bin/bash -c ... (remaining 1 argument skipped).  [forge_remote_host=ixkj11]
E0708 16:06:52.259056    8943 ir_converter.cc:1942] INTERNAL: XLS_RET_CHECK failure (third_party/xls/dslx/ir_converter.cc:1942) implicit_token_data_.has_value() Invoking trace_fmt!(), but no implicit token is present for caller @ <snip>/trace_fmt_repro.x:3:21-3:39
=== Source Location Trace: ===
third_party/xls/common/status/status_builder.cc:160

0x55feecba5b65: xabsl::StatusBuilder::CreateStatusAndConditionallyLog()
0x55feec661077: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::HandleFormatMacro()
0x55feec81f33b: xls::dslx::FormatMacro::Accept()
0x55feec65d83d: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::Visit()
0x55feec6623de: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::HandleLet()
0x55feec820e1b: xls::dslx::Let::Accept()
0x55feec65d83d: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::Visit()
0x55feec65f1f7: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::HandleBlock()
0x55feec81b57b: xls::dslx::Block::Accept()
0x55feec65d83d: xls::dslx::(anonymous namespace)::FunctionConverterVisitor::Visit()
0x55feec654522: xls::dslx::(anonymous namespace)::ConvertOneFunctionInternal()
0x55feec64f1e4: xls::dslx::ConvertCallGraph()
0x55feec65042d: xls::dslx::ConvertOneFunctionIntoPackageInternal<>()
0x55feec65021f: xls::dslx::ConvertOneFunctionIntoPackage()
0x55feec64739a: main
0x7f9a199f28d3: __libc_start_main
0x55feec64602a: _start

F0708 16:06:52.259115    8943 ir_converter_main.cc:206] Check failed: ::absl::OkStatus() == (status) (OK vs. INTERNAL: XLS_RET_CHECK failure (third_party/xls/dslx/ir_converter.cc:1942) implicit_token_data_.has_value() Invoking trace_fmt!(), but no implicit token is present for caller @<snip>/trace_fmt_repro.x:3:21-3:39
=== Source Location Trace: ===
third_party/xls/common/status/status_builder.cc:160
) 

We can narrow this down a bit further. Turns out the ir_conv_args is at fault here. If I use the following build rule

xls_dslx_opt_ir(
    name = "trace_fmt_repro",
    dslx_top = "foo",
    library = ":trace_fmt_repro_dslx",
)

then the problem goes away.

sandwichmaker avatar Jul 08 '22 23:07 sandwichmaker

Patch pending internal review. Sorry about the bug!

RobSpringer avatar Jul 25 '22 21:07 RobSpringer