Skip to content

Commit c068761

Browse files
NL02copybara-github
authored andcommitted
Append base channel scope names with a leading underscore to avoid using reserved keywords saved for codegen
PiperOrigin-RevId: 844945649
1 parent 2ac90c9 commit c068761

File tree

92 files changed

+1299
-1297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1299
-1297
lines changed

xls/dslx/ir_convert/channel_scope.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ absl::StatusOr<ChannelOrArray> ChannelScope::DefineChannelOrArrayInternal(
125125
std::string base_channel_name;
126126
if (convert_options_.lower_to_proc_scoped_channels) {
127127
// When using proc scoped channels the channel names do not have to be
128-
// mangled with the full call stack and module, just uniquified.
128+
// mangled with the full call stack and module, just uniquified with a
129+
// leading underscore.
129130
base_channel_name =
130-
channel_name_uniquer_.GetSanitizedUniqueName(short_name);
131+
"_" + channel_name_uniquer_.GetSanitizedUniqueName(short_name);
131132
} else {
132133
XLS_ASSIGN_OR_RETURN(base_channel_name, CreateBaseChannelName(short_name));
133134
}

xls/dslx/ir_convert/channel_scope_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ TEST_P(ChannelScopeTest, DefineChannel) {
145145
EXPECT_TRUE(std::holds_alternative<Channel*>(result));
146146
Channel* channel = std::get<Channel*>(result);
147147
if (GetParam()) {
148-
EXPECT_EQ(channel->name(), "the_channel");
148+
EXPECT_EQ(channel->name(), "_the_channel");
149149
} else {
150150
EXPECT_EQ(channel->name(), "the_package__the_channel");
151151
}
@@ -169,7 +169,7 @@ TEST_P(ChannelScopeTest, DefineChannelWithDefaultFifoConfig) {
169169
EXPECT_TRUE(std::holds_alternative<Channel*>(result));
170170
Channel* channel = std::get<Channel*>(result);
171171
if (GetParam()) {
172-
EXPECT_EQ(channel->name(), "the_channel");
172+
EXPECT_EQ(channel->name(), "_the_channel");
173173
} else {
174174
EXPECT_EQ(channel->name(), "the_package__the_channel");
175175
}
@@ -199,7 +199,7 @@ TEST_P(ChannelScopeTest, DefineBoundaryChannel) {
199199
EXPECT_TRUE(std::holds_alternative<Channel*>(result));
200200
if (GetParam()) {
201201
EXPECT_THAT(conv_.interface.channels(), ElementsAre(EqualsProto(R"pb(
202-
name: "the_channel"
202+
name: "_the_channel"
203203
type { type_enum: BITS bit_count: 32 }
204204
direction: IN
205205
)pb")));
@@ -222,12 +222,12 @@ TEST_P(ChannelScopeTest, DefineBoundaryInputChannelArray) {
222222
if (GetParam()) {
223223
EXPECT_THAT(conv_.interface.channels(),
224224
ElementsAre(EqualsProto(R"pb(
225-
name: "the_channel__0"
225+
name: "_the_channel__0"
226226
type { type_enum: BITS bit_count: 32 }
227227
direction: IN
228228
)pb"),
229229
EqualsProto(R"pb(
230-
name: "the_channel__1"
230+
name: "_the_channel__1"
231231
type { type_enum: BITS bit_count: 32 }
232232
direction: IN
233233
)pb")));
@@ -256,12 +256,12 @@ TEST_P(ChannelScopeTest, DefineBoundaryOutputChannelArray) {
256256
if (GetParam()) {
257257
EXPECT_THAT(conv_.interface.channels(),
258258
ElementsAre(EqualsProto(R"pb(
259-
name: "the_channel__0"
259+
name: "_the_channel__0"
260260
type { type_enum: BITS bit_count: 32 }
261261
direction: OUT
262262
)pb"),
263263
EqualsProto(R"pb(
264-
name: "the_channel__1"
264+
name: "_the_channel__1"
265265
type { type_enum: BITS bit_count: 32 }
266266
direction: OUT
267267
)pb")));
@@ -363,11 +363,11 @@ TEST_P(ChannelScopeTest, AssociateWithExistingChannelArrayDifferentProcIds) {
363363
XLS_ASSERT_OK_AND_ASSIGN(ChannelRef test_channel1_ref,
364364
scope_->GetChannelForArrayIndex(
365365
proc_id1, CreateIndexOp(ch_ref, {"2"})));
366-
EXPECT_EQ(std::get<Channel*>(test_channel1_ref)->name(), "arr1__2");
366+
EXPECT_EQ(std::get<Channel*>(test_channel1_ref)->name(), "_arr1__2");
367367
XLS_ASSERT_OK_AND_ASSIGN(ChannelRef test_channel2_ref,
368368
scope_->GetChannelForArrayIndex(
369369
proc_id2, CreateIndexOp(ch_ref, {"2"})));
370-
EXPECT_EQ(std::get<Channel*>(test_channel2_ref)->name(), "arr2__2");
370+
EXPECT_EQ(std::get<Channel*>(test_channel2_ref)->name(), "_arr2__2");
371371
} else {
372372
XLS_ASSERT_OK_AND_ASSIGN(ChannelRef test_channel1_ref,
373373
scope_->GetChannelForArrayIndex(
@@ -392,7 +392,7 @@ TEST_P(ChannelScopeTest, HandleChannelIndex1DValid) {
392392
ChannelRef channel_ref,
393393
scope_->GetChannelForArrayIndex(ProcId{}, CreateIndexOp(decl, {"2"})));
394394
if (GetParam()) {
395-
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "the_channel__2");
395+
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "_the_channel__2");
396396
} else {
397397
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(),
398398
"the_package__the_channel__2");
@@ -409,7 +409,7 @@ TEST_P(ChannelScopeTest, HandleChannelIndex2DValid) {
409409
scope_->GetChannelForArrayIndex(
410410
ProcId{}, CreateIndexOp(decl, {"4", "1"})));
411411
if (GetParam()) {
412-
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "the_channel__4_1");
412+
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "_the_channel__4_1");
413413
} else {
414414
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(),
415415
"the_package__the_channel__4_1");
@@ -471,7 +471,7 @@ TEST_P(ChannelScopeTest, HandleSubarrayIndex) {
471471
scope_->GetChannelForArrayIndex(
472472
ProcId{}, CreateIndexOp(subarray_ref, {"1"})));
473473
if (GetParam()) {
474-
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "the_channel__4_1");
474+
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(), "_the_channel__4_1");
475475
} else {
476476
EXPECT_EQ(std::get<Channel*>(channel_ref)->name(),
477477
"the_package__the_channel__4_1");

xls/dslx/ir_convert/ir_converter_test.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7127,7 +7127,8 @@ proc main {
71277127
XLS_ASSERT_OK_AND_ASSIGN(
71287128
xls::Proc * test_proc,
71297129
conv.package->GetProc("__test_module__test_proc_0__3_4_next"));
7130-
XLS_ASSERT_OK_AND_ASSIGN(Channel * my_chan, test_proc->GetChannel("my_chan"));
7130+
XLS_ASSERT_OK_AND_ASSIGN(Channel * my_chan,
7131+
test_proc->GetChannel("_my_chan"));
71317132
ASSERT_EQ(my_chan->kind(), ChannelKind::kStreaming);
71327133
EXPECT_EQ(down_cast<StreamingChannel*>(my_chan)->GetFifoDepth(), 7);
71337134
}
@@ -7176,8 +7177,8 @@ proc main {
71767177
conv.package->GetProc("__test_module__main_0_next"));
71777178
std::vector<Channel*> channels = {proc->channels().begin(),
71787179
proc->channels().end()};
7179-
EXPECT_THAT(channels, AllOf(Contains(m::Channel("my_chan")),
7180-
Contains(m::Channel("my_chan__1"))));
7180+
EXPECT_THAT(channels, AllOf(Contains(m::Channel("_my_chan")),
7181+
Contains(m::Channel("_my_chan__1"))));
71817182
}
71827183

71837184
TEST_F(IrConverterTest, ChannelArrayDestructureWithWildcard) {
@@ -7211,10 +7212,10 @@ TEST_F(IrConverterTest, ChannelArrayDestructureWithWildcard) {
72117212
conv.package->GetProc("__test_module__SomeProc_0_next"));
72127213
std::vector<Channel*> channels = {proc->channels().begin(),
72137214
proc->channels().end()};
7214-
EXPECT_THAT(channels, UnorderedElementsAre(m::Channel("the_chan_array__0"),
7215-
m::Channel("the_chan_array__1"),
7216-
m::Channel("the_chan_array__2"),
7217-
m::Channel("the_chan_array__3")));
7215+
EXPECT_THAT(channels, UnorderedElementsAre(m::Channel("_the_chan_array__0"),
7216+
m::Channel("_the_chan_array__1"),
7217+
m::Channel("_the_chan_array__2"),
7218+
m::Channel("_the_chan_array__3")));
72187219
}
72197220

72207221
TEST_F(IrConverterTest, ChannelArrayDestructureWithRestOfTuple) {
@@ -7248,10 +7249,10 @@ TEST_F(IrConverterTest, ChannelArrayDestructureWithRestOfTuple) {
72487249
conv.package->GetProc("__test_module__SomeProc_0_next"));
72497250
std::vector<Channel*> channels = {proc->channels().begin(),
72507251
proc->channels().end()};
7251-
EXPECT_THAT(channels, UnorderedElementsAre(m::Channel("the_chan_array__0"),
7252-
m::Channel("the_chan_array__1"),
7253-
m::Channel("the_chan_array__2"),
7254-
m::Channel("the_chan_array__3")));
7252+
EXPECT_THAT(channels, UnorderedElementsAre(m::Channel("_the_chan_array__0"),
7253+
m::Channel("_the_chan_array__1"),
7254+
m::Channel("_the_chan_array__2"),
7255+
m::Channel("_the_chan_array__3")));
72557256
}
72567257

72577258
TEST_F(IrConverterTest, DealOutChannelArrayElementsToSpawnee) {
@@ -7315,10 +7316,10 @@ TEST_F(IrConverterTest, DealOutChannelArrayElementsToSpawnee) {
73157316
procA->channels().end()};
73167317
EXPECT_THAT(channels,
73177318
UnorderedElementsAre(
7318-
m::Channel("toward_a__0_0"), m::Channel("toward_a__0_1"),
7319-
m::Channel("toward_a__1_0"), m::Channel("toward_a__1_1"),
7320-
m::Channel("toward_b__0_0"), m::Channel("toward_b__0_1"),
7321-
m::Channel("toward_b__1_0"), m::Channel("toward_b__1_1")));
7319+
m::Channel("_toward_a__0_0"), m::Channel("_toward_a__0_1"),
7320+
m::Channel("_toward_a__1_0"), m::Channel("_toward_a__1_1"),
7321+
m::Channel("_toward_b__0_0"), m::Channel("_toward_b__0_1"),
7322+
m::Channel("_toward_b__1_0"), m::Channel("_toward_b__1_1")));
73227323
}
73237324

73247325
TEST_F(IrConverterTest, MultipleNonLeafSpawnsOfSameProc) {

xls/dslx/ir_convert/testdata/ir_converter_test_BoundaryChannels.ir

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package test_module
22

33
file_number 0 "test_module.x"
44

5-
top proc __test_module__foo_0_next<in_0: bits[32] in, in_1: bits[32] in, output: bits[32] out>(__state: (), init={()}) {
6-
chan_interface in_0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
7-
chan_interface in_1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
8-
chan_interface output(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
5+
top proc __test_module__foo_0_next<_in_0: bits[32] in, _in_1: bits[32] in, _output: bits[32] out>(__state: (), init={()}) {
6+
chan_interface _in_0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
7+
chan_interface _in_1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
8+
chan_interface _output(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
99
after_all.5: token = after_all(id=5)
1010
literal.3: bits[1] = literal(value=1, id=3)
11-
receive.6: (token, bits[32]) = receive(after_all.5, predicate=literal.3, channel=in_0, id=6)
11+
receive.6: (token, bits[32]) = receive(after_all.5, predicate=literal.3, channel=_in_0, id=6)
1212
tok: token = tuple_index(receive.6, index=0, id=8)
13-
receive.10: (token, bits[32]) = receive(tok, predicate=literal.3, channel=in_1, id=10)
13+
receive.10: (token, bits[32]) = receive(tok, predicate=literal.3, channel=_in_1, id=10)
1414
a: bits[32] = tuple_index(receive.6, index=1, id=9)
1515
b: bits[32] = tuple_index(receive.10, index=1, id=13)
1616
tok__1: token = tuple_index(receive.10, index=0, id=12)
@@ -21,6 +21,6 @@ top proc __test_module__foo_0_next<in_0: bits[32] in, in_1: bits[32] in, output:
2121
tuple.4: () = tuple(id=4)
2222
tuple_index.7: token = tuple_index(receive.6, index=0, id=7)
2323
tuple_index.11: token = tuple_index(receive.10, index=0, id=11)
24-
tok__2: token = send(tok__1, add.14, predicate=literal.3, channel=output, id=15)
24+
tok__2: token = send(tok__1, add.14, predicate=literal.3, channel=_output, id=15)
2525
next_value.17: () = next_value(param=__state, value=tuple.16, id=17)
2626
}

xls/dslx/ir_convert/testdata/ir_converter_test_ChannelArrayAndChannelMembers.ir

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ package test_module
22

33
file_number 0 "test_module.x"
44

5-
top proc __test_module__main_0_next<in_chans__0: bits[32] in, in_chans__1: bits[32] in, in_chans__2: bits[32] in, out_chan: bits[16] out>(__state: (), init={()}) {
6-
chan_interface in_chans__0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
7-
chan_interface in_chans__1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
8-
chan_interface in_chans__2(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
9-
chan_interface out_chan(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
5+
top proc __test_module__main_0_next<_in_chans__0: bits[32] in, _in_chans__1: bits[32] in, _in_chans__2: bits[32] in, _out_chan: bits[16] out>(__state: (), init={()}) {
6+
chan_interface _in_chans__0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
7+
chan_interface _in_chans__1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
8+
chan_interface _in_chans__2(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
9+
chan_interface _out_chan(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
1010
literal.8: token = literal(value=token, id=8)
1111
literal.3: bits[1] = literal(value=1, id=3)
1212
literal.5: token = literal(value=token, id=5)
1313
literal.6: bits[16] = literal(value=42, id=6)
14-
receive.9: (token, bits[32]) = receive(literal.8, predicate=literal.3, channel=in_chans__1, id=9)
14+
receive.9: (token, bits[32]) = receive(literal.8, predicate=literal.3, channel=_in_chans__1, id=9)
1515
__state: () = state_read(state_element=__state, id=2)
1616
tuple.11: () = tuple(id=11)
1717
__token: token = literal(value=token, id=1)
1818
tuple.4: () = tuple(id=4)
19-
send.7: token = send(literal.5, literal.6, predicate=literal.3, channel=out_chan, id=7)
19+
send.7: token = send(literal.5, literal.6, predicate=literal.3, channel=_out_chan, id=7)
2020
tuple_index.10: token = tuple_index(receive.9, index=0, id=10)
2121
next_value.12: () = next_value(param=__state, value=tuple.11, id=12)
2222
}

xls/dslx/ir_convert/testdata/ir_converter_test_ChannelArrayDecl.ir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package test_module
33
file_number 0 "test_module.x"
44

55
top proc __test_module__main_0_next<>(__state: (), init={()}) {
6-
chan data_0__0(bits[32], id=0, kind=streaming, ops=send_receive, flow_control=ready_valid, strictness=proven_mutually_exclusive)
7-
chan_interface data_0__0(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
8-
chan_interface data_0__0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
9-
chan data_0__1(bits[32], id=1, kind=streaming, ops=send_receive, flow_control=ready_valid, strictness=proven_mutually_exclusive)
10-
chan_interface data_0__1(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
11-
chan_interface data_0__1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
6+
chan _data_0__0(bits[32], id=0, kind=streaming, ops=send_receive, flow_control=ready_valid, strictness=proven_mutually_exclusive)
7+
chan_interface _data_0__0(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
8+
chan_interface _data_0__0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
9+
chan _data_0__1(bits[32], id=1, kind=streaming, ops=send_receive, flow_control=ready_valid, strictness=proven_mutually_exclusive)
10+
chan_interface _data_0__1(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
11+
chan_interface _data_0__1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
1212
__state: () = state_read(state_element=__state, id=2)
1313
__token: token = literal(value=token, id=1)
1414
literal.3: bits[1] = literal(value=1, id=3)

0 commit comments

Comments
 (0)