Skip to content

Commit

Permalink
Merge pull request #1419 from hzeller:fix-passes-dslx-inc
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 635622446
  • Loading branch information
copybara-github committed May 21, 2024
2 parents 9958114 + 6eeb75b commit 0da1b56
Show file tree
Hide file tree
Showing 82 changed files with 235 additions and 53 deletions.
14 changes: 14 additions & 0 deletions xls/dslx/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ cc_library(
"//xls/common:visitor",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"//xls/dslx/bytecode",
"//xls/dslx/bytecode:bytecode_emitter",
"//xls/dslx/bytecode:bytecode_interpreter",
"//xls/dslx/bytecode:bytecode_interpreter_options",
"//xls/dslx/frontend:ast",
"//xls/dslx/frontend:ast_utils",
"//xls/dslx/frontend:module",
"//xls/dslx/frontend:pos",
"//xls/dslx/type_system:deduce_utils",
"//xls/dslx/type_system:parametric_env",
Expand Down Expand Up @@ -238,8 +240,10 @@ cc_test(
srcs = ["interp_value_test.cc"],
deps = [
":interp_value",
":value_format_descriptor",
"//xls/common:xls_gunit_main",
"//xls/common/status:matchers",
"//xls/ir:format_preference",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
Expand All @@ -253,6 +257,7 @@ cc_library(
deps = [
":interp_value",
"//xls/dslx/frontend:ast",
"//xls/dslx/frontend:pos",
"//xls/dslx/type_system:type_info",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
Expand All @@ -261,6 +266,7 @@ cc_library(
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:variant",
],
)

Expand All @@ -269,6 +275,7 @@ cc_test(
srcs = ["interp_bindings_test.cc"],
deps = [
":interp_bindings",
":interp_value",
"//xls/common:xls_gunit_main",
"//xls/common/status:matchers",
"@com_google_absl//absl/status",
Expand Down Expand Up @@ -298,6 +305,7 @@ cc_library(
"//xls/common/status:status_macros",
"//xls/dslx/bytecode:bytecode_cache_interface",
"//xls/dslx/frontend:ast",
"//xls/dslx/frontend:ast_node",
"//xls/dslx/frontend:module",
"//xls/dslx/frontend:pos",
"//xls/dslx/type_system:type_info",
Expand Down Expand Up @@ -349,7 +357,9 @@ cc_library(
srcs = ["mangle.cc"],
hdrs = ["mangle.h"],
deps = [
":interp_value",
"//xls/dslx/type_system:parametric_env",
"//xls/ir:format_preference",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/log:check",
Expand All @@ -364,9 +374,11 @@ cc_test(
name = "mangle_test",
srcs = ["mangle_test.cc"],
deps = [
":interp_value",
":mangle",
"//xls/common:xls_gunit_main",
"//xls/common/status:matchers",
"//xls/dslx/type_system:parametric_env",
"@com_google_googletest//:gtest",
],
)
Expand Down Expand Up @@ -409,6 +421,7 @@ cc_library(
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down Expand Up @@ -702,6 +715,7 @@ cc_library(
srcs = ["extract_module_name.cc"],
hdrs = ["extract_module_name.h"],
deps = [
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:str_format",
],
Expand Down
3 changes: 3 additions & 0 deletions xls/dslx/bytecode/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ cc_library(
"//xls/common:visitor",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"//xls/dslx:dslx_builtins",
"//xls/dslx:import_data",
"//xls/dslx:interp_value",
"//xls/dslx:interp_value_utils",
"//xls/dslx:make_value_format_descriptor",
"//xls/dslx:value_format_descriptor",
"//xls/dslx/frontend:ast",
"//xls/dslx/frontend:ast_utils",
"//xls/dslx/frontend:module",
"//xls/dslx/type_system:deduce_utils",
"//xls/dslx/type_system:parametric_env",
"//xls/dslx/type_system:type",
Expand Down Expand Up @@ -297,6 +299,7 @@ cc_test(
"//xls/dslx/run_routines",
"//xls/dslx/type_system:parametric_env",
"//xls/dslx/type_system:type_info",
"//xls/ir:bits",
"//xls/ir:format_preference",
"//xls/ir:format_strings",
"@com_google_googletest//:gtest",
Expand Down
2 changes: 2 additions & 0 deletions xls/dslx/bytecode/bytecode_emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
#include "xls/common/symbolized_stacktrace.h"
#include "xls/common/visitor.h"
#include "xls/dslx/bytecode/bytecode.h"
#include "xls/dslx/dslx_builtins.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/frontend/ast_utils.h"
#include "xls/dslx/frontend/module.h"
#include "xls/dslx/import_data.h"
#include "xls/dslx/interp_value.h"
#include "xls/dslx/interp_value_utils.h"
Expand Down
25 changes: 13 additions & 12 deletions xls/dslx/bytecode/bytecode_interpreter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "xls/dslx/run_routines/run_routines.h"
#include "xls/dslx/type_system/parametric_env.h"
#include "xls/dslx/type_system/type_info.h"
#include "xls/ir/bits.h"
#include "xls/ir/format_preference.h"
#include "xls/ir/format_strings.h"

Expand Down Expand Up @@ -1680,7 +1681,7 @@ fn doomed() {

absl::StatusOr<InterpValue> value = Interpret(kProgram, "doomed");
EXPECT_THAT(value.status(), StatusIs(absl::StatusCode::kInternal,
HasSubstr(R"(lhs and rhs were not equal:
HasSubstr(R"(lhs and rhs were not equal:
MyStruct {
< a: u32:0
> a: u32:7
Expand Down Expand Up @@ -1740,9 +1741,9 @@ fn doomed() {

absl::StatusOr<InterpValue> value = Interpret(kProgram, "doomed");
EXPECT_THAT(value.status(), StatusIs(absl::StatusCode::kInternal,
AllOf(HasSubstr("were not equal"),
HasSubstr(
R"(lhs and rhs were not equal:
AllOf(HasSubstr("were not equal"),
HasSubstr(
R"(lhs and rhs were not equal:
S {
a: u32:42
b: u32:42
Expand Down Expand Up @@ -1802,10 +1803,10 @@ fn doomed() {
})";

absl::StatusOr<InterpValue> value = Interpret(kProgram, "doomed");
EXPECT_THAT(value.status(), StatusIs(absl::StatusCode::kInternal,
AllOf(
HasSubstr("were not equal"),
HasSubstr(R"(lhs and rhs were not equal:
EXPECT_THAT(value.status(),
StatusIs(absl::StatusCode::kInternal,
AllOf(HasSubstr("were not equal"),
HasSubstr(R"(lhs and rhs were not equal:
MyStruct {
c: InnerStruct[2]:[
InnerStruct {
Expand Down Expand Up @@ -1837,10 +1838,10 @@ fn doomed() {
assert_eq(a, b)
})";
absl::StatusOr<InterpValue> value = Interpret(kProgram, "doomed");
EXPECT_THAT(value.status(), StatusIs(absl::StatusCode::kInternal,
AllOf(
HasSubstr("Flowers::ROSES (u24:16711807"),
HasSubstr("Flowers::VIOLETS (u24:15631086"))));
EXPECT_THAT(value.status(),
StatusIs(absl::StatusCode::kInternal,
AllOf(HasSubstr("Flowers::ROSES (u24:16711807"),
HasSubstr("Flowers::VIOLETS (u24:15631086"))));
}

TEST(BytecodeInterpreterTest, TraceChannels) {
Expand Down
2 changes: 2 additions & 0 deletions xls/dslx/constexpr_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
#include "xls/common/status/ret_check.h"
#include "xls/common/status/status_macros.h"
#include "xls/common/visitor.h"
#include "xls/dslx/bytecode/bytecode.h"
#include "xls/dslx/bytecode/bytecode_emitter.h"
#include "xls/dslx/bytecode/bytecode_interpreter.h"
#include "xls/dslx/bytecode/bytecode_interpreter_options.h"
#include "xls/dslx/errors.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/frontend/ast_utils.h"
#include "xls/dslx/frontend/module.h"
#include "xls/dslx/frontend/pos.h"
#include "xls/dslx/import_data.h"
#include "xls/dslx/interp_value.h"
Expand Down
6 changes: 6 additions & 0 deletions xls/dslx/cpp_transpiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//xls/build_rules:xls_build_defs.bzl", "xls_dslx_library")
load(
"//xls/build_rules:xls_macros.bzl",
"xls_dslx_cpp_type_library",
Expand Down Expand Up @@ -153,3 +154,8 @@ cc_test(
"@com_google_googletest//:gtest",
],
)

xls_dslx_library(
name = "test_types",
srcs = ["test_types.x"],
)
2 changes: 2 additions & 0 deletions xls/dslx/dslx_builtins_signatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "xls/dslx/dslx_builtins_signatures.h"

#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
Expand All @@ -27,6 +28,7 @@
#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
Expand Down
17 changes: 8 additions & 9 deletions xls/dslx/error_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ absl::Status PrintPositionalError(
// file_limit as a whole is an exclusive limit (the first not-included
// character), but its file_limit.lineno() is inclusive (addresses the
// last line, not the one after).
const Pos file_limit(error_span.filename(),
lines.size() - 1, lines.back().size());
const Pos file_limit(error_span.filename(), lines.size() - 1,
lines.back().size());

// Caps the effective start and limit against the file start and limit,
// and caps the limit against the start.
const Pos start = std::max(file_start,
std::min(error_span.start(), file_limit));
const Pos start =
std::max(file_start, std::min(error_span.start(), file_limit));
const Pos limit = std::max(start, std::min(file_limit, error_span.limit()));

int64_t line_count_each_side = error_context_line_count / 2;
Expand Down Expand Up @@ -114,7 +114,7 @@ absl::Status PrintPositionalError(
// When emitting multiline errors, we put a leading bar at the start of the
// line to show which are in the error range. When we're not doing multiline
// errors, this is just empty.
const std::string bar_on = absl::StrCat(msg_color_leader, " |", color_reset);
const std::string bar_on = absl::StrCat(msg_color_leader, " |", color_reset);
const std::string bar_off = (is_multiline ? " " : "");
std::string_view bar = bar_off;

Expand All @@ -124,14 +124,13 @@ absl::Status PrintPositionalError(
error_span.limit().ToStringNoFile());

for (int64_t i = first_line_printed; i <= last_line_printed; ++i) {
os << absl::StreamFormat("%s%04d:%s%s %s\n",
pos_color_leader, i + 1, color_reset, bar, lines[i]);
os << absl::StreamFormat("%s%04d:%s%s %s\n", pos_color_leader, i + 1,
color_reset, bar, lines[i]);
if (i == start.lineno()) {
// Emit arrow pointing to all of, or the start of, the error.
if (is_multiline) {
std::string spaces(std::string_view("0000: |").size(), ' ');
std::string underscores(
std::max(int64_t{0}, start.colno()) + 1, '_');
std::string underscores(std::max(int64_t{0}, start.colno()) + 1, '_');
os << absl::StreamFormat("%s%s%s^%s\n", msg_color_leader, spaces,
underscores, color_reset);
// Each line will also draw a little bit of a vertical bar
Expand Down
1 change: 1 addition & 0 deletions xls/dslx/extract_module_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <filesystem> // NOLINT
#include <string>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"

Expand Down
4 changes: 4 additions & 0 deletions xls/dslx/frontend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cc_library(
":ast",
":ast_utils",
":module",
":pos",
":proc",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
Expand Down Expand Up @@ -119,6 +120,7 @@ cc_library(
"//xls/dslx:channel_direction",
"//xls/ir:code_template",
"//xls/ir:foreign_function",
"//xls/ir:foreign_function_data_cc_proto",
"//xls/ir:format_strings",
"//xls/ir:name_uniquer",
],
Expand Down Expand Up @@ -315,6 +317,7 @@ cc_test(
name = "bindings_test",
srcs = ["bindings_test.cc"],
deps = [
":ast",
":bindings",
":pos",
"@com_google_absl//absl/status",
Expand Down Expand Up @@ -405,6 +408,7 @@ cc_library(
"//xls/ir:bits",
"//xls/ir:bits_ops",
"//xls/ir:foreign_function_data_cc_proto",
"//xls/ir:format_preference",
"//xls/ir:format_strings",
"//xls/ir:number_parser",
],
Expand Down
13 changes: 8 additions & 5 deletions xls/dslx/frontend/ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <optional>
Expand Down Expand Up @@ -50,6 +51,7 @@
#include "xls/dslx/frontend/token_utils.h"
#include "xls/ir/bits.h"
#include "xls/ir/bits_ops.h"
#include "xls/ir/format_preference.h"
#include "xls/ir/format_strings.h"
#include "xls/ir/number_parser.h"

Expand Down Expand Up @@ -526,7 +528,7 @@ const absl::btree_set<BinopKind>& GetBinopShifts() {

std::string BinopKindFormat(BinopKind kind) {
switch (kind) {
// clang-format off
// clang-format off
// Shifts.
case BinopKind::kShl: return "<<";
case BinopKind::kShr: return ">>";
Expand Down Expand Up @@ -2162,11 +2164,12 @@ std::vector<AstNode*> Statement::GetChildren(bool want_types) const {
return {ToAstNode(wrapped_)};
}

Span ExprOrTypeSpan(const ExprOrType &expr_or_type) {
Span ExprOrTypeSpan(const ExprOrType& expr_or_type) {
return absl::visit(Visitor{
[](Expr* expr) { return expr->span(); },
[](TypeAnnotation* type) { return type->span(); },
}, expr_or_type);
[](Expr* expr) { return expr->span(); },
[](TypeAnnotation* type) { return type->span(); },
},
expr_or_type);
}

} // namespace xls::dslx
1 change: 1 addition & 0 deletions xls/dslx/frontend/ast_cloner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/frontend/ast_utils.h"
#include "xls/dslx/frontend/module.h"
#include "xls/dslx/frontend/pos.h"
#include "xls/dslx/frontend/proc.h"
#include "xls/ir/format_strings.h"

Expand Down
1 change: 1 addition & 0 deletions xls/dslx/frontend/bindings_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "absl/status/status.h"
#include "xls/common/status/matchers.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/frontend/pos.h"

namespace xls::dslx {
Expand Down
Loading

0 comments on commit 0da1b56

Please sign in to comment.