diff --git a/xls/dslx/ir_convert/ir_converter_test.cc b/xls/dslx/ir_convert/ir_converter_test.cc index 6e4d167389..2ce91dc9ab 100644 --- a/xls/dslx/ir_convert/ir_converter_test.cc +++ b/xls/dslx/ir_convert/ir_converter_test.cc @@ -885,52 +885,6 @@ fn f(outer_thing_1: u32, outer_thing_2: u32) -> u32 { ExpectIr(converted, TestName()); } -TEST(IrConverterTest, ParametricDefaultInStruct) { - const char* kProgram = R"( -struct Foo { - a: uN[X], - b: uN[Y], -} - -fn make_zero_foo() -> Foo { - zero!>() -} - -fn test() -> Foo { - make_zero_foo() -} -)"; - - XLS_ASSERT_OK_AND_ASSIGN( - std::string converted, - ConvertModuleForTest(kProgram, ConvertOptions{.emit_positions = false})); - ExpectIr(converted, TestName()); -} - -TEST(IrConverterTest, ParametricDefaultClog2InStruct) { - const char* kProgram = R"( -import std; - -struct Foo { - a: uN[X], - b: uN[Y], -} - -fn make_zero_foo() -> Foo { - zero!>() -} - -fn test() -> Foo { - make_zero_foo() -} -)"; - - XLS_ASSERT_OK_AND_ASSIGN( - std::string converted, - ConvertModuleForTest(kProgram, ConvertOptions{.emit_positions = false})); - ExpectIr(converted, TestName()); -} - TEST(IrConverterTest, UnrollForSimple) { const char* kProgram = R"( fn test() -> u32 { diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_ParametricDefaultInStruct.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_ParametricDefaultInStruct.ir deleted file mode 100644 index c7d2181508..0000000000 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_ParametricDefaultInStruct.ir +++ /dev/null @@ -1,12 +0,0 @@ -package test_module - -file_number 0 "test_module.x" - -fn __test_module__make_zero_foo__5() -> (bits[5], bits[6]) { - X: bits[32] = literal(value=5, id=1) - ret literal.2: (bits[5], bits[6]) = literal(value=(0, 0), id=2) -} - -fn __test_module__test() -> (bits[5], bits[6]) { - ret invoke.3: (bits[5], bits[6]) = invoke(to_apply=__test_module__make_zero_foo__5, id=3) -} diff --git a/xls/dslx/type_system/deduce.cc b/xls/dslx/type_system/deduce.cc index 509489a94c..5be5e74b3b 100644 --- a/xls/dslx/type_system/deduce.cc +++ b/xls/dslx/type_system/deduce.cc @@ -88,29 +88,6 @@ absl::StatusOr EvaluateConstexprValue(DeduceCtx* ctx, ctx->GetCurrentParametricEnv(), node, type); } -// Evaluates the given `dim` to the extent possible with the given `env`. -// Examples: -// - If `dim` is already a constant, the result is `dim`. -// - If `dim` is `X + 1`, and `env` says `X` == `5`, then the result is `6`. -// - If `dim` is `X + 1`, and `env` says `X` == `Y` and does not have `Y`, -// then the result is `Y + 1`. -// - If `dim` is `X + 1`, and `env` says `X` == `Y` and `Y` == `5`, then the -// result is `6`. -TypeDim EvaluateTypeDim(TypeDim dim, const ParametricExpression::Env& env) { - absl::flat_hash_set prev_free_variables; - while (std::holds_alternative(dim.value())) { - auto& parametric = std::get(dim.value()); - absl::flat_hash_set next_free_variables = - parametric->GetFreeVariables(); - if (prev_free_variables == next_free_variables) { - break; - } - prev_free_variables = std::move(next_free_variables); - dim = TypeDim(parametric->Evaluate(env)); - } - return dim; -} - // Attempts to convert an expression from the full DSL AST into the // ParametricExpression sub-AST (a limited form that we can embed into a // TypeDim for later instantiation). @@ -1843,10 +1820,6 @@ static absl::StatusOr> ConcretizeStructAnnotation( struct_def->identifier()), ctx->file_table()); } - XLS_ASSIGN_OR_RETURN(std::unique_ptr parametric_expr, - ExprToParametric(defined_parametric->expr(), ctx)); - parametric_env.emplace(defined_parametric->identifier(), - TypeDim(std::move(parametric_expr))); } ParametricExpression::Env env; @@ -1862,7 +1835,11 @@ static absl::StatusOr> ConcretizeStructAnnotation( XLS_ASSIGN_OR_RETURN( std::unique_ptr mapped_type, base_type.MapSize([&](const TypeDim& dim) -> absl::StatusOr { - return EvaluateTypeDim(dim, env); + if (std::holds_alternative(dim.value())) { + auto& parametric = std::get(dim.value()); + return TypeDim(parametric->Evaluate(env)); + } + return dim; })); VLOG(5) << "ConcreteStructAnnotation mapped type: " @@ -1870,7 +1847,7 @@ static absl::StatusOr> ConcretizeStructAnnotation( // Attach the nominal parametrics to the type, so that we will remember the // fact that we have instantiated e.g. Foo as Foo<5, 6>. - return mapped_type->AddNominalTypeDims(parametric_env); + return mapped_type->AddNominalTypeDims(std::move(parametric_env)); } absl::StatusOr> DeduceTypeRefTypeAnnotation(