Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

@Pasta-coder Pasta-coder commented Dec 27, 2025

Fixes #4302

ResolvePathRef::resolve_with_node_id assumed CONST types were always concrete values and asserted otherwise. Generic const expressions such as { N + 1 } are symbolic and cannot be evaluated prior to monomorphization, leading to an internal compiler error.

Reject non-value const kinds gracefully and emit a diagnostic instead of aborting.

gcc/testsuite:
* rust/compile/const-generic-ice-4302.rs: New test.

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 896d6ad to 1b1c341 Compare December 27, 2025 16:54
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great, only a few issues but nothing bad. Once this is fixed I'm happy to merge your PR. Thanks for your contribution!

@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch 5 times, most recently from e9afc67 to 3d52076 Compare January 3, 2026 23:44
@Pasta-coder
Copy link
Contributor Author

All checks are now passing and the PR is ready for merge.

@CohenArthur Thanks a lot for the review and helpful feedback — it clarified the expected coding style and workflow. I’ll keep future PRs focused with a clean commit history.

Please let me know if there’s anything else I should adjust.

@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 546caf5 to 56a7611 Compare January 6, 2026 07:28
@Pasta-coder
Copy link
Contributor Author

@P-E-P please review .

thankyou

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... i am not 100% sure this is the correct place to handle this because at this case is where it should be lazy evaluated and monomophized so i think this will cause false positives for other cases.

This should be handled in the typecheck pass when we resolve generic arguments instead where case cannot do N + 1 because N is not defined at this case.

@Pasta-coder
Copy link
Contributor Author

okay , i will look into that .

thanks for pointing this out .

@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch 16 times, most recently from c363e86 to ce25686 Compare January 10, 2026 01:56
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 17, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 95b67f1 to 5535d11 Compare January 17, 2026 19:32
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 17, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 5535d11 to dda5f8d Compare January 17, 2026 20:11
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 17, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from dda5f8d to 37fcefc Compare January 17, 2026 21:15
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 17, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 37fcefc to e7deae3 Compare January 17, 2026 21:28
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 18, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from e7deae3 to d9c6908 Compare January 18, 2026 06:06
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 18, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from d9c6908 to a34162f Compare January 18, 2026 06:10
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 18, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from a34162f to 8ea1187 Compare January 18, 2026 08:34
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 18, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 8ea1187 to 58e3abf Compare January 18, 2026 09:24
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 18, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 58e3abf to e848f80 Compare January 18, 2026 14:35
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 20, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	*rust/comppile/const_generics_12.rs: Update expected error messages to
        match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from e848f80 to f38160a Compare January 20, 2026 07:21
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 20, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	*rust/comppile/const_generics_12.rs: Update expected error messages to
	match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from f38160a to f641e6a Compare January 20, 2026 07:29
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 20, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	* rust/comppile/const_generics_12.rs: Update expected error messages to
	match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from f641e6a to 59f9c96 Compare January 20, 2026 08:13
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 20, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	* rust/comppile/const_generics_12.rs: Update expected error messages to
	match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 59f9c96 to ed3d5db Compare January 20, 2026 11:54
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 20, 2026
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	* rust/compile/const_generics_12.rs: Update expected error messages to
	match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from ed3d5db to 1b8bbbb Compare January 20, 2026 12:05
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.

This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.

Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
   using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
   underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
   diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.

Fixes Rust-GCC#4341

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
	Emit diagnostic and return error_mark_node for non-value constants.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
	underlying expression for ConstExprType.
	* backend/rust-compile-type.h: Declare visit method.
	* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
	(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
	dependent const arguments.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Handle ConstKind::Expr in switch to prevent fallthrough.
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
	Implement cloning for ConstExprType.
	* typecheck/rust-substitution-mapper.h: Add visit declarations.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
	for ConstExprType.
	* typecheck/rust-tyty-call.h: Declare visit method.
	* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
	Add stub implementation.
	* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
	* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
	(ConstExprType::accept_vis): Implement.
	(ConstExprType::as_string): Implement.
	(ConstExprType::clone): Implement.
	(ConstExprType::is_equal): Implement.
	(ConstExprType::get_expr): Implement.
	* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
	(class ConstExprType): New class definition.
	* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
	logic for ConstExprType.

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_10.rs: Update expected error messages to
	match <const_expr> representation.
	* rust/compile/issue-4302.rs: New test.
	* rust/compile/const_generics_12.rs: Update expected error messages to
	match <const_expr> representation.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix-const-generic-ice-4302-v2 branch from 1b8bbbb to 91c9be0 Compare January 20, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE in resolve_with_node_id, at rust/backend/rust-compile-resolve-path.cc GCEs

3 participants