diff --git a/xls/dslx/type_system/BUILD b/xls/dslx/type_system/BUILD index d7c91d39f1..e1b742d314 100644 --- a/xls/dslx/type_system/BUILD +++ b/xls/dslx/type_system/BUILD @@ -93,6 +93,7 @@ cc_library( ":parametric_env", ":parametric_instantiator", ":type_and_parametric_env", + ":type_info", ":unwrap_meta_type", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/cleanup", diff --git a/xls/dslx/type_system/deduce.cc b/xls/dslx/type_system/deduce.cc index 5fe2ae91f5..86783d3061 100644 --- a/xls/dslx/type_system/deduce.cc +++ b/xls/dslx/type_system/deduce.cc @@ -60,6 +60,7 @@ #include "xls/dslx/type_system/parametric_env.h" #include "xls/dslx/type_system/parametric_instantiator.h" #include "xls/dslx/type_system/type_and_parametric_env.h" +#include "xls/dslx/type_system/type_info.h" #include "xls/dslx/type_system/unwrap_meta_type.h" #include "xls/dslx/warning_kind.h" #include "xls/ir/bits.h" diff --git a/xls/dslx/type_system/deduce.h b/xls/dslx/type_system/deduce.h index 6cd6b3ac88..b0199bbe31 100644 --- a/xls/dslx/type_system/deduce.h +++ b/xls/dslx/type_system/deduce.h @@ -20,6 +20,7 @@ #include "absl/status/statusor.h" #include "absl/types/span.h" +#include "xls/dslx/frontend/ast.h" #include "xls/dslx/frontend/ast_node.h" #include "xls/dslx/type_system/concrete_type.h" #include "xls/dslx/type_system/deduce_ctx.h" diff --git a/xls/dslx/type_system/typecheck_test.cc b/xls/dslx/type_system/typecheck_test.cc index f3f4eac552..27b28293d6 100644 --- a/xls/dslx/type_system/typecheck_test.cc +++ b/xls/dslx/type_system/typecheck_test.cc @@ -405,6 +405,16 @@ fn main(p: u32) -> () { HasSubstr("const_assert! expression is not constexpr"))); } +TEST(TypecheckErrorTest, FitsInTypeSN0) { + EXPECT_THAT(Typecheck(R"( +fn main() -> sN[0] { + sN[0]:0xffff_ffff_ffff_ffff_ffff +})"), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("Value '0xffff_ffff_ffff_ffff_ffff' does not " + "fit in the bitwidth of a sN[0]"))); +} + TEST(TypecheckTest, ForBuiltinInBody) { XLS_EXPECT_OK(Typecheck(R"( fn f() -> u32 { diff --git a/xls/ir/bits.cc b/xls/ir/bits.cc index 775a459581..a4e65aedfd 100644 --- a/xls/ir/bits.cc +++ b/xls/ir/bits.cc @@ -75,11 +75,17 @@ Bits Bits::AllOnes(int64_t bit_count) { /* static */ Bits Bits::MaxSigned(int64_t bit_count) { + if (bit_count == 0) { + return SBits(0, 0); + } return Bits::AllOnes(bit_count).UpdateWithSet(bit_count - 1, false); } /* static */ Bits Bits::MinSigned(int64_t bit_count) { + if (bit_count == 0) { + return SBits(0, 0); + } return Bits::PowerOfTwo(bit_count - 1, bit_count); } diff --git a/xls/ir/bits.h b/xls/ir/bits.h index 443e9629e7..a7fc4f9737 100644 --- a/xls/ir/bits.h +++ b/xls/ir/bits.h @@ -21,6 +21,7 @@ #include #include "absl/status/statusor.h" +#include "absl/types/span.h" #include "xls/common/logging/logging.h" #include "xls/common/math_util.h" #include "xls/data_structures/inline_bitmap.h"