google / google/xls

[DSLX] IR conversion fails to resolve function invocations inside new-style proc next() method

Open
#4,925 0 comments 0 reactions 1 assignee Claimed by @richmckeever View on GitHub
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

**Describe the bug**

Consider the following code that calls some `std::-`function in next() in new-style proc

```Rust
import std;
#[test]
proc MinimalProcTest {
done: chan out,
}
impl MinimalProcTest {
fn new(done: chan out) -> Self {
MinimalProcTest { done }
}
fn next(self) {
let x = std::abs(s32:-42);
send(join(), self.done, x == s32:42);
}
}
```

```
$ bazel-bin/xls/dslx/interpreter_main fun_in_next.x --evaluator=ir-interpreter
Error: INTERNAL: IrConversionError: fun_in_next.x:11:25-11:34 Could not find name for invocation: `__std__abs__32`; available: []
=== Source Location Trace: ===
xls/dslx/ir_convert/function_converter.cc:113
xls/dslx/ir_convert/function_converter.cc:999
xls/dslx/ir_convert/function_converter.cc:678
xls/dslx/ir_convert/function_converter.cc:5053
xls/dslx/ir_convert/function_converter.cc:5013
xls/dslx/ir_convert/function_converter.cc:4326
xls/dslx/ir_convert/ir_converter.cc:365
xls/dslx/ir_convert/ir_converter.cc:486
xls/dslx/run_routines/ir_test_runner.cc:237
xls/dslx/run_routines/run_routines.cc:1031
xls/dslx/interpreter_main.cc:280
```

**Expected behavior**
No crash :)

**Environment (this can be helpful for troubleshooting):**
built xls from head (also with some local patches applied #4909 and #4292

**Additional context**

NB: AI suggested patch

```patch
--- a/xls/dslx/get_conversion_records.cc
+++ b/xls/dslx/get_conversion_records.cc
@@ -420,6 +420,12 @@ class ConversionRecordVisitor : public AstNodeRecursiveVisitor {
<< canonical_initializer.constructor_type_info->name()
<< " and next() TI " << canonical_initializer.next_type_info->name();

+ ConversionRecordVisitor next_fn_visitor(
+ (*next_fn)->owner(), canonical_initializer.next_type_info,
+ include_tests_, proc_id_factory_, top_, resolved_proc_alias_,
+ records_, processed_invocations_);
+ XLS_RETURN_IF_ERROR((*next_fn)->Accept(&next_fn_visitor));
+
XLS_ASSIGN_OR_RETURN(
ConversionRecord cr,
MakeConversionRecord(p, proc_id_factory_->CreateProcId(p),
```

(we then run into the next unimplemented issue, but at least we can keep going one more)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.