Skip to content

Commit dbffe11

Browse files
richmckeevercopybara-github
authored andcommitted
Enable references to global constants in parametric defaults.
This basically requires more careful control of the order of conversion from InferenceTable to TypeInfo, because ConstexprEvaluator presumes all prerequisites are proactively loaded. This also changes inference_table_test to be more of a pure unit test for the table functions, because we are now at the point where equivalent end-to-end testing is being done with less hackery in typecheck_module_v2_test. The hackery previously in inference_table_test relied on the table being the source of node order. PiperOrigin-RevId: 709194186
1 parent b959a4e commit dbffe11

File tree

6 files changed

+420
-338
lines changed

6 files changed

+420
-338
lines changed

xls/dslx/type_system_v2/BUILD

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cc_library(
2828
"//xls/dslx/frontend:ast",
2929
"//xls/dslx/frontend:ast_node",
3030
"//xls/dslx/frontend:ast_node_visitor_with_default",
31-
"//xls/dslx/frontend:ast_utils",
3231
"//xls/dslx/frontend:module",
3332
"//xls/dslx/frontend:pos",
3433
"@com_google_absl//absl/algorithm:container",
@@ -50,6 +49,7 @@ cc_library(
5049
deps = [
5150
":inference_table",
5251
":type_annotation_utils",
52+
"//xls/common:visitor",
5353
"//xls/common/status:status_macros",
5454
"//xls/dslx:constexpr_evaluator",
5555
"//xls/dslx:errors",
@@ -58,7 +58,7 @@ cc_library(
5858
"//xls/dslx:warning_collector",
5959
"//xls/dslx/frontend:ast",
6060
"//xls/dslx/frontend:ast_cloner",
61-
"//xls/dslx/frontend:ast_utils",
61+
"//xls/dslx/frontend:ast_node_visitor_with_default",
6262
"//xls/dslx/frontend:module",
6363
"//xls/dslx/frontend:pos",
6464
"//xls/dslx/type_system:deduce_utils",
@@ -74,6 +74,7 @@ cc_library(
7474
"@com_google_absl//absl/status",
7575
"@com_google_absl//absl/status:statusor",
7676
"@com_google_absl//absl/strings",
77+
"@com_google_absl//absl/types:variant",
7778
],
7879
)
7980

@@ -90,15 +91,13 @@ cc_test(
9091
"//xls/common/status:status_macros",
9192
"//xls/dslx:create_import_data",
9293
"//xls/dslx:import_data",
93-
"//xls/dslx:interp_value",
9494
"//xls/dslx:warning_collector",
9595
"//xls/dslx:warning_kind",
9696
"//xls/dslx/frontend:ast",
9797
"//xls/dslx/frontend:module",
9898
"//xls/dslx/frontend:parser",
9999
"//xls/dslx/frontend:pos",
100100
"//xls/dslx/frontend:scanner",
101-
"//xls/dslx/type_system:parametric_env",
102101
"//xls/dslx/type_system:type_info",
103102
"@com_google_absl//absl/container:flat_hash_map",
104103
"@com_google_absl//absl/log:check",

xls/dslx/type_system_v2/inference_table.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "xls/dslx/errors.h"
4040
#include "xls/dslx/frontend/ast.h"
4141
#include "xls/dslx/frontend/ast_node_visitor_with_default.h"
42-
#include "xls/dslx/frontend/ast_utils.h"
4342
#include "xls/dslx/frontend/module.h"
4443
#include "xls/dslx/frontend/pos.h"
4544

@@ -275,29 +274,6 @@ class InferenceTableImpl : public InferenceTable {
275274
node, [=](NodeData& data) { data.type_variable = variable; });
276275
}
277276

278-
NodesByParametricInvocation GetNodesByParametricInvocation() const override {
279-
NodesByParametricInvocation result;
280-
absl::flat_hash_set<const AstNode*> static_nodes;
281-
for (const auto& [node, node_data] : node_data_) {
282-
static_nodes.insert(node);
283-
}
284-
for (const std::unique_ptr<ParametricInvocation>& invocation :
285-
parametric_invocations_) {
286-
absl::flat_hash_set<const AstNode*> nodes =
287-
FlattenToSet(&invocation->callee());
288-
nodes.erase(&invocation->callee());
289-
static_nodes.erase(&invocation->callee());
290-
for (const AstNode* node : nodes) {
291-
static_nodes.erase(node);
292-
}
293-
result.emplace_back(invocation.get(),
294-
FilterAndConvertNodeSetToOrderedVector(nodes));
295-
}
296-
result.emplace_back(std::nullopt,
297-
FilterAndConvertNodeSetToOrderedVector(static_nodes));
298-
return result;
299-
}
300-
301277
std::optional<const TypeAnnotation*> GetTypeAnnotation(
302278
const AstNode* node) const override {
303279
const auto it = node_data_.find(node);

xls/dslx/type_system_v2/inference_table.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <utility>
2424
#include <vector>
2525

26-
#include "absl/container/flat_hash_map.h"
2726
#include "absl/status/status.h"
2827
#include "absl/status/statusor.h"
2928
#include "absl/strings/substitute.h"
@@ -183,8 +182,7 @@ class InferenceTable {
183182
std::optional<const Function*> caller,
184183
std::optional<const ParametricInvocation*> caller_invocation) = 0;
185184

186-
// Retrieves all the parametric invocations that have been defined for all
187-
// parametric functions.
185+
// Retrieves all the parametric invocations that have been defined.
188186
virtual std::vector<const ParametricInvocation*> GetParametricInvocations()
189187
const = 0;
190188

@@ -208,16 +206,6 @@ class InferenceTable {
208206
virtual absl::Status SetTypeAnnotation(const AstNode* node,
209207
const TypeAnnotation* type) = 0;
210208

211-
using NodesByParametricInvocation =
212-
std::vector<std::pair<std::optional<const ParametricInvocation*>,
213-
std::vector<const AstNode*>>>;
214-
215-
// Returns a table of parametric invocation to the nodes in the callee
216-
// function, plus an element at the end for all nodes not in a parametric
217-
// context.
218-
virtual NodesByParametricInvocation GetNodesByParametricInvocation()
219-
const = 0;
220-
221209
// Returns the type annotation for `node` in the table, if any.
222210
virtual std::optional<const TypeAnnotation*> GetTypeAnnotation(
223211
const AstNode* node) const = 0;

0 commit comments

Comments
 (0)