Skip to content

Commit 59b150f

Browse files
cdlearycopybara-github
authored andcommitted
[DSLX:ir_convert] Rename error from ConversionError to "IrConversionError".
This should be a more helpful indicator of where things are going wrong, vs not indicating what kind of conversion. Software does lots of conversions in lots of places. :-) This one is about DSLX to XLS IR. Note that generally users should never see these except as a form of internal or unimplemented error, they are only in the exceptional cases where e.g. the frontend can express something we can't yet convert to IR. PiperOrigin-RevId: 612913122
1 parent d42f55c commit 59b150f

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

xls/dslx/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ cc_library(
119119
hdrs = ["errors.h"],
120120
deps = [
121121
":import_record",
122+
":interp_value",
122123
"//xls/dslx/frontend:ast_node",
123124
"//xls/dslx/frontend:pos",
124125
"//xls/dslx/type_system:concrete_type",

xls/dslx/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include <string_view>
1818

1919
#include "absl/status/status.h"
20+
#include "absl/types/span.h"
2021
#include "xls/dslx/frontend/ast_node.h"
2122
#include "xls/dslx/frontend/pos.h"
2223
#include "xls/dslx/import_record.h"
24+
#include "xls/dslx/interp_value.h"
2325
#include "xls/dslx/type_system/concrete_type.h"
2426

2527
// Specialized error types that can be encountered during DSLX evaluation.

xls/dslx/ir_convert/function_converter.cc

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ namespace {
7979
constexpr WarningCollector* kNoWarningCollector = nullptr;
8080

8181
// Returns a status that indicates an error in the IR conversion process.
82-
absl::Status ConversionErrorStatus(const std::optional<Span>& span,
83-
std::string_view message) {
82+
absl::Status IrConversionErrorStatus(const std::optional<Span>& span,
83+
std::string_view message) {
8484
return absl::InternalError(
85-
absl::StrFormat("ConversionError: %s %s",
85+
absl::StrFormat("IrConversionError: %s %s",
8686
span ? span->ToString() : "<no span>", message));
8787
}
8888

@@ -805,10 +805,12 @@ absl::Status FunctionConverter::HandleBuiltinCheckedCast(
805805

806806
if (dynamic_cast<ArrayType*>(output_type.get()) != nullptr ||
807807
dynamic_cast<ArrayType*>(input_type.get()) != nullptr) {
808-
return absl::UnimplementedError(
809-
absl::StrFormat("ConversionError: CheckedCast to and from arrays (%s) "
810-
"is not currently supported for IR conversion.",
811-
node->span().ToString()));
808+
return IrConversionErrorStatus(
809+
node->span(),
810+
absl::StrFormat("CheckedCast to and from array "
811+
"is not currently supported for IR conversion; "
812+
"attempted checked cast from: %s to: %s",
813+
input_type->ToString(), output_type->ToString()));
812814
}
813815

814816
// TODO(tedhong): 2023-05-22 Add verilog assertion that cast has not
@@ -864,7 +866,7 @@ absl::Status FunctionConverter::HandleBuiltinWideningCast(
864866
absl::Status FunctionConverter::HandleMatch(const Match* node) {
865867
if (node->arms().empty() ||
866868
!node->arms().back()->patterns()[0]->IsIrrefutable()) {
867-
return ConversionErrorStatus(
869+
return IrConversionErrorStatus(
868870
node->span(),
869871
"Only matches with trailing irrefutable patterns (i.e. `_ => ...`) "
870872
"are currently supported for IR conversion.");
@@ -945,10 +947,10 @@ absl::Status FunctionConverter::HandleMatch(const Match* node) {
945947
});
946948
MatchArm* default_arm = node->arms().back();
947949
if (default_arm->patterns().size() != 1) {
948-
return absl::UnimplementedError(
949-
absl::StrFormat("ConversionError: %s Multiple patterns in default arm "
950-
"is not currently supported for IR conversion.",
951-
node->span().ToString()));
950+
return IrConversionErrorStatus(
951+
node->span(),
952+
"Multiple patterns in default arm "
953+
"is not currently supported for IR conversion.");
952954
}
953955
XLS_RETURN_IF_ERROR(
954956
HandleMatcher(default_arm->patterns()[0],
@@ -986,11 +988,12 @@ absl::Status FunctionConverter::HandleMatch(const Match* node) {
986988
absl::StatusOr<FunctionConverter::RangeData> FunctionConverter::GetRangeData(
987989
const Expr* iterable) {
988990
auto error = [&] {
989-
return absl::InvalidArgumentError(
990-
absl::StrFormat("ConversionError: %s iterable (%s) "
991+
return IrConversionErrorStatus(
992+
iterable->span(),
993+
absl::StrFormat("iterable `%s` "
991994
"must be bits-typed, constexpr, and its start must be "
992995
"less than or equal to its limit.",
993-
iterable->span().ToString(), iterable->ToString()));
996+
iterable->ToString()));
994997
};
995998

996999
// Easy case first: using the `..` range operator.
@@ -1825,10 +1828,11 @@ absl::Status FunctionConverter::HandleInvocation(const Invocation* node) {
18251828
};
18261829
auto it = map.find(called_name);
18271830
if (it == map.end()) {
1828-
return absl::InvalidArgumentError(
1829-
absl::StrFormat("ConversionError: %s Could not find name for "
1830-
"invocation: %s; available: [%s]",
1831-
node->span().ToString(), called_name,
1831+
return IrConversionErrorStatus(
1832+
node->span(),
1833+
absl::StrFormat("Could not find name for "
1834+
"invocation: `%s`; available: [%s]",
1835+
called_name,
18321836
absl::StrJoin(module_->GetFunctionNames(), ", ")));
18331837
}
18341838
XLS_RETURN_IF_ERROR(accept_args().status());
@@ -3174,7 +3178,7 @@ absl::StatusOr<std::unique_ptr<ConcreteType>> FunctionConverter::ResolveType(
31743178
XLS_RET_CHECK(current_type_info_ != nullptr);
31753179
std::optional<const ConcreteType*> t = current_type_info_->GetItem(node);
31763180
if (!t.has_value()) {
3177-
return ConversionErrorStatus(
3181+
return IrConversionErrorStatus(
31783182
node->GetSpan(),
31793183
absl::StrFormat("Failed to convert IR because type was missing for AST "
31803184
"node: %s (kind: %s)",

0 commit comments

Comments
 (0)