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!

Copy link
Member

Choose a reason for hiding this comment

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

You don't need to update the Changelog file manually - it gets updated automatically by a script every day in the upstream GCC repo :) please restore the file here or it may cause issues

@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 6 times, most recently from ba38fc7 to 8a9448e Compare January 8, 2026 15:44
Generic const expressions such as { N + 1 } are symbolic and cannot be
evaluated immediately during type checking path resolution. Previously,
these expressions were allowed to propagate, leading to assertion failures
and internal compiler errors (ICE) in the backend when it attempted to
resolve them as concrete values.

This patch adds validation in the typechecker to detect non-literal
const generic arguments during path resolution. It rejects symbolic
expressions gracefully by emitting a diagnostic, preventing the compiler
from crashing.

Fixes Rust-GCC#4302

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
	Reject non-literal generic const arguments to prevent ICE.
	(TypeCheckExpr::resolve_segments): Likewise.

gcc/testsuite/ChangeLog:

	* 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 8a9448e to a403b82 Compare January 8, 2026 15:46
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