8000 [DSLX] Fix imported types whose dimensions index an array constant. by copybara-service[bot] · Pull Request #5546 · google/xls · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions xls/dslx/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,16 @@ dslx_lang_test(
dslx_deps = [":mod_imported_const_struct_dslx"],
)

xls_dslx_library(
name = "mod_imported_array_const_dims_dslx",
srcs = ["mod_imported_array_const_dims.x"],
)

dslx_lang_test(
name = "mod_importer_array_const_dims",
dslx_deps = [":mod_imported_array_const_dims_dslx"],
)

xls_dslx_library(
name = "mod_imported_access_const_struct_dslx",
srcs = ["mod_imported_access_const_struct.x"],
Expand Down
22 changes: 22 additions & 0 deletions xls/dslx/tests/mod_imported_array_const_dims.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2026 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Structs whose member widths index into an array constant, for use from
// another module.

pub const WIDTHS = u32[3]:[40, 24, 10];

pub struct Histories { long: uN[WIDTHS[0]], short: uN[WIDTHS[2]] }

pub struct Tables<N: u32> { entries: uN[WIDTHS[1]][N] }
30 changes: 30 additions & 0 deletions xls/dslx/tests/mod_importer_array_const_dims.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2026 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Uses imported structs whose member widths are elements of an imported array
// constant (e.g. `uN[WIDTHS[0]]`).

import xls.dslx.tests.mod_imported_array_const_dims as dims;

fn main(h: dims::Histories, t: dims::Tables<u32:2>) -> (u40, u10, u24) {
(h.long + u40:1, h.short, t.entries[1])
}

#[test]
fn test_main() {
let h = dims::Histories { long: u40:41, short: u10:7 };
let t = dims::Tables { entries: u24[2]:[1, 2] };
assert_eq(main(h, t), (u40:42, u10:7, u24:2));
assert_eq(zero!<dims::Histories>().long, u40:0);
}
5 changes: 4 additions & 1 deletion xls/dslx/type_system_v2/type_annotation_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,10 @@ class StatefulResolver : public TypeAnnotationResolver {
XLS_ASSIGN_OR_RETURN(TypeInfo * ti,
import_data_.GetRootTypeInfoForNode(def));
XLS_ASSIGN_OR_RETURN(InterpValue value, ti->Get 5FDC ConstExpr(def));
if (value.IsTuple()) {
// Only scalar values can be expressed as a `Number`; aggregate
// constants (e.g. an array indexed in a dimension like
// `uN[SIZES[0]]`) are left as references.
if (value.IsTuple() || value.IsArray()) {
return std::nullopt;
}

Expand Down
Loading
0