Skip to content

Conversation

@philberty
Copy link
Member

This patch refactors the const generic type system to follow the same pattern as regular type parameters. The monolithic ConstType is split into four distinct types:

ConstParamType (generic parameter placeholder)
ConstValueType (resolved constant value)
ConstInferType (inference variable)
ConstErrorType (error sentinel)

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): refactor to new classes
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise
(CompilePatternBindings::visit): likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): likewise
* backend/rust-compile-type.h: likewise
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
* typecheck/rust-substitution-mapper.h: likewise
* typecheck/rust-tyty-call.h: likewise
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::clone): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): likewise
* typecheck/rust-tyty-util.h: likewise
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty-visitor.h: likewise
* typecheck/rust-tyty.cc (BaseType::destructure): likewise
(BaseType::monomorphized_clone): likewise
(BaseType::is_concrete): likewise
(VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
(ArrayType::as_string): likewise
(ArrayType::get_capacity): likewise
(ArrayType::handle_substitions): likewise
(generate_tree_str): likewise
(ConstType::ConstType): likewise
(ConstParamType::ConstParamType): likewise
(ConstType::accept_vis): likewise
(ConstParamType::const_kind): likewise
(ConstParamType::get_symbol): likewise
(ConstParamType::can_resolve): likewise
(ConstParamType::resolve): likewise
(ConstParamType::accept_vis): likewise
(ConstType::set_value): likewise
(ConstType::as_string): likewise
(ConstParamType::as_string): likewise
(ConstType::clone): likewise
(ConstParamType::clone): likewise
(ConstType::get_symbol): likewise
(ConstParamType::get_name): likewise
(ConstType::can_resolve): likewise
(ConstParamType::is_equal): likewise
(ConstType::resolve): likewise
(ConstValueType::ConstValueType): likewise
(ConstValueType::const_kind): likewise
(ConstValueType::accept_vis): likewise
(ConstValueType::as_string): likewise
(ConstValueType::clone): likewise
(ConstValueType::get_name): likewise
(ConstValueType::is_equal): likewise
(ConstValueType::get_value): likewise
(ConstInferType::ConstInferType): likewise
(ConstInferType::const_kind): likewise
(ConstInferType::accept_vis): likewise
(ConstType::get_name): likewise
(ConstInferType::as_string): likewise
(ConstInferType::clone): likewise
(ConstInferType::get_name): likewise
(ConstType::is_equal): likewise
(ConstInferType::is_equal): likewise
(ConstErrorType::ConstErrorType): likewise
(ConstErrorType::const_kind): likewise
(ConstType::handle_substitions): likewise
(ConstErrorType::accept_vis): likewise
(ConstErrorType::as_string): likewise
(ConstErrorType::clone): likewise
(ConstErrorType::get_name): likewise
(ConstErrorType::is_equal): likewise
* typecheck/rust-tyty.h (class BaseConstType): likewise
(class ConstType): likewise
(class ConstParamType): likewise
(class ConstValueType): likewise
(class ConstInferType): likewise
(class ConstErrorType): likewise
* typecheck/rust-unify.cc (UnifyRules::commit): likewise
(UnifyRules::go): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_const): likewise
* typecheck/rust-unify.h: likewise

@philberty philberty force-pushed the phil/const-generics-dev branch 2 times, most recently from 4780f2f to a82fc0e Compare October 6, 2025 13:04
This patch refactors the const generic type system to follow the same pattern
as regular type parameters. The monolithic ConstType is split into four
distinct types:

  ConstParamType (generic parameter placeholder)
  ConstValueType (resolved constant value)
  ConstInferType (inference variable)
  ConstErrorType (error sentinel)

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): refactor to new classes
	* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise
	(CompilePatternBindings::visit): likewise
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): likewise
	* backend/rust-compile-type.h: likewise
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): likewise
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
	* typecheck/rust-substitution-mapper.h: likewise
	* typecheck/rust-type-util.cc (unify_site_and): remove bad delete (alpine32)
	* typecheck/rust-tyty-call.h: refactor to new classes
	* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::clone): likewise
	(SubstitutionRef::infer_substitions): likewise
	* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): likewise
	* typecheck/rust-tyty-util.h: likewise
	* typecheck/rust-tyty-variance-analysis-private.h: likewise
	* typecheck/rust-tyty-visitor.h: likewise
	* typecheck/rust-tyty.cc (BaseType::destructure): likewise
	(BaseType::monomorphized_clone): likewise
	(BaseType::is_concrete): likewise
	(VariantDef::clone): likewise
	(VariantDef::monomorphized_clone): likewise
	(ArrayType::as_string): likewise
	(ArrayType::get_capacity): likewise
	(ArrayType::handle_substitions): likewise
	(generate_tree_str): likewise
	(ConstType::ConstType): likewise
	(ConstParamType::ConstParamType): likewise
	(ConstType::accept_vis): likewise
	(ConstParamType::const_kind): likewise
	(ConstParamType::get_symbol): likewise
	(ConstParamType::can_resolve): likewise
	(ConstParamType::resolve): likewise
	(ConstParamType::accept_vis): likewise
	(ConstType::set_value): likewise
	(ConstType::as_string): likewise
	(ConstParamType::as_string): likewise
	(ConstType::clone): likewise
	(ConstParamType::clone): likewise
	(ConstType::get_symbol): likewise
	(ConstParamType::get_name): likewise
	(ConstType::can_resolve): likewise
	(ConstParamType::is_equal): likewise
	(ConstType::resolve): likewise
	(ConstValueType::ConstValueType): likewise
	(ConstValueType::const_kind): likewise
	(ConstValueType::accept_vis): likewise
	(ConstValueType::as_string): likewise
	(ConstValueType::clone): likewise
	(ConstValueType::get_name): likewise
	(ConstValueType::is_equal): likewise
	(ConstValueType::get_value): likewise
	(ConstInferType::ConstInferType): likewise
	(ConstInferType::const_kind): likewise
	(ConstInferType::accept_vis): likewise
	(ConstType::get_name): likewise
	(ConstInferType::as_string): likewise
	(ConstInferType::clone): likewise
	(ConstInferType::get_name): likewise
	(ConstType::is_equal): likewise
	(ConstInferType::is_equal): likewise
	(ConstErrorType::ConstErrorType): likewise
	(ConstErrorType::const_kind): likewise
	(ConstType::handle_substitions): likewise
	(ConstErrorType::accept_vis): likewise
	(ConstErrorType::as_string): likewise
	(ConstErrorType::clone): likewise
	(ConstErrorType::get_name): likewise
	(ConstErrorType::is_equal): likewise
	* typecheck/rust-tyty.h (class BaseConstType): likewise
	(class ConstType): likewise
	(class ConstParamType): likewise
	(class ConstValueType): likewise
	(class ConstInferType): likewise
	(class ConstErrorType): likewise
	* typecheck/rust-unify.cc (UnifyRules::commit): likewise
	(UnifyRules::go): likewise
	(UnifyRules::expect_array): likewise
	(UnifyRules::expect_const): likewise
	* typecheck/rust-unify.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty force-pushed the phil/const-generics-dev branch from a82fc0e to 5509599 Compare October 6, 2025 13:25
@philberty philberty added this pull request to the merge queue Oct 6, 2025
@philberty philberty added this to the RfL const generics milestone Oct 6, 2025
Merged via the queue into master with commit ff47336 Oct 6, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Const Generics 2 Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants