Only allow channel operation for tokens in DSLX
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
Only allow channel operation for tokens in DSLX, do not allow other operations on token (e.g. binops, etc...). Ideally, produce an error message during IR conversion when unsupported operations on tokens are performed. Example follows.
The following DSLX code
```
const DEFAULT_INIT_STATE = [[(u48:140737488355327, u24:65536, u23:4194303), (u48:188252559977002, u24:11184810, u23:4816403), (u48:0, u24:11261202, u23:5026188), (u48:239479300900322, u24:8388607, u23:4194303), (u48:9160167381346, u24:2048, u23:4194303), (u48:99390719332924, u24:5592405, u23:2795463), (u48:281474976710655, u24:11184810, u23:4413856), (u48:16384, u24:5592405, u23:2796202), (u48:281474976710655, u24:8388607, u23:5592405), (u48:140737488355327, u24:8, u23:8077795)]];
const W32_V1 = u32:1;
type x2 = (u48, u24, u23);
type x3 = x2[10];
proc main {
x19: chan in;
config(x19: chan in) {
(x19,)
}
next(x0: token, x1: x3[W32_V1]) {
let x4: token = for (i, x) in u4:0..u4:8 {
x
}(x0);
let x5: (x3[W32_V1], token, token) = (x1, x0, x4);
let x6: token = join(x4, x4);
let x7: u50 = u50:0x2_67ae_3107_61cc;
let x8: u50 = !(x7);
let x9: u50 = (x8) << (if (x7) >= (u50:0) { u50:0 } else { x7 });
let x10: u50 = (x7) ^ (x8);
let x11: x3[1] = slice(x1, x7, x3[1]:[(x1)[u32:0], ...]);
let x12: u50 = (x9) + (x9);
let x13: token = join(x0, x0);
let x14: u50 = rev(x12);
let x15: u50 = (x7) * (x12);
let x16: u50 = !(x7);
let x17: u50 = (x16) << (if (x15) >= (u50:30) { u50:30 } else { x15 });
let x18: bool = (x5) == (x5);
let x20: (token, u45) = recv(x13, x19);
let x21: token = x20.0;
let x22: u45 = x20.1;
let x23: u50 = !(x9);
let x24: u50 = (x9) >> (if (x15) >= (u50:11) { u50:11 } else { x15 });
let x25: x3 = (x1)[if (x24) >= (u50:0) { u50:0 } else { x24 }];
x1
}
}
```
translates to:
```
package sample
file_number 0 "fake_file.x"
chan sample__x19(bits[45], id=0, kind=streaming, ops=receive_only, flow_control=ready_valid, metadata="""""")
fn ____sample__main_0_next_counted_for_0_body(i: bits[4], __token_wrapped: (token, bits[1], token)) -> (token, bits[1], token) {
literal.5: bits[4] = literal(value=0, id=5)
tuple_index.8: token = tuple_index(__token_wrapped, index=0, id=8)
tuple_index.9: bits[1] = tuple_index(__token_wrapped, index=1, id=9)
tuple_index.10: token = tuple_index(__token_wrapped, index=2, id=10)
add.6: bits[4] = add(i, literal.5, id=6)
ret tuple.11: (token, bits[1], token) = tuple(tuple_index.8, tuple_index.9, tuple_index.10, id=11)
}
top proc __sample__main_0_next(__token: token, __state: (bits[48], bits[24], bits[23])[10][1], init={[[(140737488355327, 65536, 4194303), (188252559977002, 11184810, 4816403), (0, 11261202, 5026188), (239479300900322, 8388607, 4194303), (9160167381346, 2048, 4194303), (99390719332924, 5592405, 2795463), (281474976710655, 11184810, 4413856), (16384, 5592405, 2796202), (281474976710655, 8388607, 5592405), (140737488355327, 8, 8077795)]]}) {
x7: bits[50] = literal(value=676947797959116, id=18, pos=[(0,15,22)])
literal.20: bits[50] = literal(value=0, id=20, pos=[(0,17,43)])
uge.21: bits[1] = uge(x7, literal.20, id=21, pos=[(0,17,35)])
literal.22: bits[50] = literal(value=0, id=22, pos=[(0,17,52)])
x8: bits[50] = not(x7, id=19, pos=[(0,16,18)])
sel.23: bits[50] = sel(uge.21, cases=[x7, literal.22], id=23, pos=[(0,17,27)])
x9: bits[50] = shll(x8, sel.23, id=24, pos=[(0,17,23)])
x12: bits[50] = add(x9, x9, id=30, pos=[(0,20,24)])
x15: bits[50] = umul(x7, x12, id=33, pos=[(0,23,24)])
literal.48: bits[50] = literal(value=11, id=48, pos=[(0,31,45)])
literal.3: bits[1] = literal(value=1, id=3)
uge.49: bits[1] = uge(x15, literal.48, id=49, pos=[(0,31,37)])
literal.50: bits[50] = literal(value=11, id=50, pos=[(0,31,55)])
tuple.12: (token, bits[1], token) = tuple(__token, literal.3, __token, id=12)
sel.51: bits[50] = sel(uge.49, cases=[x15, literal.50], id=51, pos=[(0,31,28)])
literal.35: bits[50] = literal(value=30, id=35, pos=[(0,25,46)])
counted_for.13: (token, bits[1], token) = counted_for(tuple.12, trip_count=8, stride=1, body=____sample__main_0_next_counted_for_0_body, id=13)
x24: bits[50] = shrl(x9, sel.51, id=52, pos=[(0,31,24)])
literal.53: bits[50] = literal(value=0, id=53, pos=[(0,32,40)])
x13: token = after_all(__token, __token, id=31)
literal.26: bits[32] = literal(value=0, id=26, pos=[(0,19,51)])
uge.36: bits[1] = uge(x15, literal.35, id=36, pos=[(0,25,38)])
literal.37: bits[50] = literal(value=30, id=37, pos=[(0,25,56)])
x4: token = tuple_index(counted_for.13, index=2, id=15)
uge.54: bits[1] = uge(x24, literal.53, id=54, pos=[(0,32,32)])
literal.55: bits[50] = literal(value=0, id=55, pos=[(0,32,49)])
x20: (token, bits[45]) = receive(x13, channel_id=0, id=41)
array_index.27: (bits[48], bits[24], bits[23])[10] = array_index(__state, indices=[literal.26], id=27, pos=[(0,19,46)])
x16: bits[50] = not(x7, id=34, pos=[(0,24,19)])
sel.38: bits[50] = sel(uge.36, cases=[x15, literal.37], id=38, pos=[(0,25,29)])
x5: ((bits[48], bits[24], bits[23])[10][1], token, token) = tuple(__state, __token, x4, id=16, pos=[(0,13,41)])
sel.56: bits[50] = sel(uge.54, cases=[x24, literal.55], id=56, pos=[(0,32,23)])
x6: token = after_all(x4, x4, id=17)
tuple_index.42: token = tuple_index(x20, index=0, id=42)
tuple_index.14: token = tuple_index(counted_for.13, index=0, id=14)
x10: bits[50] = xor(x7, x8, id=25, pos=[(0,18,24)])
array.28: (bits[48], bits[24], bits[23])[10][1] = array(array_index.27, id=28, pos=[(0,19,41)])
x11: (bits[48], bits[24], bits[23])[10][1] = array_slice(__state, x7, width=1, id=29, pos=[(0,19,26)])
x14: bits[50] = reverse(x12, id=32, pos=[(0,22,22)])
x17: bits[50] = shll(x16, sel.38, id=39, pos=[(0,25,25)])
x18: bits[1] = eq(x5, x5, id=40, pos=[(0,26,25)])
literal.43: bits[32] = literal(value=0, id=43, pos=[(0,28,25)])
x21: token = tuple_index(x20, index=0, id=44, pos=[(0,28,24)])
literal.45: bits[32] = literal(value=1, id=45, pos=[(0,29,23)])
x22: bits[45] = tuple_index(x20, index=1, id=46, pos=[(0,29,22)])
x23: bits[50] = not(x9, id=47, pos=[(0,30,19)])
x25: (bits[48], bits[24], bits[23])[10] = array_index(__state, indices=[sel.56], id=57, pos=[(0,32,22)])
after_all.58: token = after_all(__token, x6, x13, tuple_index.42, id=58)
next (after_all.58, __state)
}
```
However, in the ir interpreter produces the following error:
```
INVALID_ARGUMENT: Tokens are incomparable so this expression is illegal: x18: bits[1] = eq(x5, x5, id=40, pos=[(0,26,25)])
=== Source Location Trace: ===
third_party/xls/jit/ir_builder_visitor.cc:351
)
```
Contributor guide
Assessment
This issue has not been assessed yet.