Skip to content

Commit

Permalink
[DSLX:TS] Rename InstantiateParametricArgs to AppendArgsForInstantiat…
Browse files Browse the repository at this point in the history
…ion.

It wasn't doing anything with parametrics, was just inferring the types of
expressions in a way that was typically used /as preparation/ for parametric
instantiation. Between the name and the comment being more appropriate I think
it's less confusing now.

PiperOrigin-RevId: 621326853
  • Loading branch information
cdleary authored and copybara-github committed Apr 2, 2024
1 parent 1a064e8 commit 1f32f19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions xls/dslx/type_system/deduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2202,13 +2202,13 @@ absl::StatusOr<std::unique_ptr<Type>> DeduceSpawn(const Spawn* node,

// Gather up the type of all the (actual) arguments.
std::vector<InstantiateArg> config_args;
XLS_RETURN_IF_ERROR(InstantiateParametricArgs(
XLS_RETURN_IF_ERROR(AppendArgsForInstantiation(
node, node->callee(), node->config()->args(), ctx, &config_args));

std::vector<InstantiateArg> next_args;
next_args.push_back(
InstantiateArg{std::make_unique<TokenType>(), node->span()});
XLS_RETURN_IF_ERROR(InstantiateParametricArgs(
XLS_RETURN_IF_ERROR(AppendArgsForInstantiation(
node, node->callee(), node->next()->args(), ctx, &next_args));

// For each [constexpr] arg, mark the associated Param as constexpr.
Expand Down
8 changes: 4 additions & 4 deletions xls/dslx/type_system/deduce_invocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ absl::StatusOr<TypeAndParametricEnv> DeduceInstantiation(
{}};
}

absl::Status InstantiateParametricArgs(
absl::Status AppendArgsForInstantiation(
const Instantiation* inst, const Expr* callee, absl::Span<Expr* const> args,
DeduceCtx* ctx, std::vector<InstantiateArg>* instantiate_args) {
for (Expr* arg : args) {
XLS_ASSIGN_OR_RETURN(std::unique_ptr<Type> type,
DeduceAndResolve(arg, ctx));
VLOG(5) << absl::StreamFormat(
"InstantiateParametricArgs; arg: `%s` deduced: `%s` @ %s",
"AppendArgsForInstantiation; arg: `%s` deduced: `%s` @ %s",
arg->ToString(), type->ToString(), arg->span().ToString());
XLS_RET_CHECK(!type->IsMeta()) << "parametric arg: " << arg->ToString()
<< " type: " << type->ToString();
Expand Down Expand Up @@ -240,8 +240,8 @@ absl::StatusOr<std::unique_ptr<Type>> DeduceInvocation(const Invocation* node,

// Gather up the type of all the (actual) arguments.
std::vector<InstantiateArg> args;
XLS_RETURN_IF_ERROR(InstantiateParametricArgs(node, node->callee(),
node->args(), ctx, &args));
XLS_RETURN_IF_ERROR(AppendArgsForInstantiation(node, node->callee(),
node->args(), ctx, &args));

// Find the callee as a DSLX Function from the expression.
auto resolve_fn = [](const Instantiation* node,
Expand Down
10 changes: 4 additions & 6 deletions xls/dslx/type_system/deduce_invocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@

#include <functional>
#include <memory>
#include <variant>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"
#include "xls/dslx/frontend/ast.h"
#include "xls/dslx/interp_value.h"
#include "xls/dslx/type_system/ast_env.h"
#include "xls/dslx/type_system/deduce_ctx.h"
#include "xls/dslx/type_system/parametric_constraint.h"
Expand All @@ -37,9 +34,10 @@ namespace xls::dslx {
absl::StatusOr<std::unique_ptr<Type>> DeduceInvocation(const Invocation* node,
DeduceCtx* ctx);

// Helper that deduces the concrete types of the arguments to a parametric
// function or proc and returns them to the caller.
absl::Status InstantiateParametricArgs(
// Helper that deduces the concrete types of the arguments and appends them to
// "instantiate_args" -- getting them in this form is often a pre-step in
// instantiating a parametric function or proc.
absl::Status AppendArgsForInstantiation(
const Instantiation* inst, const Expr* callee, absl::Span<Expr* const> args,
DeduceCtx* ctx, std::vector<InstantiateArg>* instantiate_args);

Expand Down

0 comments on commit 1f32f19

Please sign in to comment.