google / google/xls

FFI: If local dslx implementation of a FFI function contains assert, optimizer complains as tokens are not passed

Open
#1,189 0 comments 0 reactions 0 assignees View on GitHub
bug ffi
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

To test, let's modify the ffi example by adding an assert (`fail!()`):

```diff
--- a/xls/examples/ffi.x
+++ b/xls/examples/ffi.x
@@ -39,7 +39,7 @@
fn divmod(a:bits[A_WIDTH], b:bits[B_WIDTH])
-> (bits[A_WIDTH], bits[B_WIDTH], bool) {
if (b == u32:0) {
- (a, b, true)
+ fail!("division_by_zero", (a, b, true))
} else {
(a / b, a % b, false)
}
```

Then if we trigger an ir conversion and ir optimization:
```
bazel build xls/examples:ffi_codegen
```

... the `opt_main` will fail with
```
Error: INTERNAL: Node type contains token type even though it shouldn't: invoke.56: (token, (bits[32], bits[32], bits[1])) = invoke(after_all.34, literal.35, dividend, divisor, to_apply=__itok__ffi__divmod__32_32, id=56, pos=[(0,49,8)])
```

This is probably because the FFI function is not inlined and this creates some missed assumptions later on.

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.