Skip to content

gccrs: Do proper const folding during typechecking for array capacities #3889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

philberty
Copy link
Member

@philberty philberty commented Jul 8, 2025

This patch adds proper folding to the const expression for array capacity we already have the const folding mechanics and the query system needed to handle cases where the capacity is a function call in a const context. This leverages and pulls the gcc tree capacity into the TyTy::ArrayType so it can be used for more typechecking and eventually doing more const generics work.

Addresses #3885
Fixes #3882

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::query_compile_const_expr): new wrapper
* backend/rust-compile-base.h: add prototype
* backend/rust-compile-context.cc (Context::get): singleton helper
* backend/rust-compile-context.h: likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): handle infer's that can default
* rust-session-manager.cc (Session::compile_crate): create the gcc context earlier for tychk
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): const fold it
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): fix constructor call
(ArrayType::as_string): print capacity
(ArrayType::clone): fix constructor call
* typecheck/rust-tyty.h: track capacity
* typecheck/rust-unify.cc (UnifyRules::expect_array): check the capacities

gcc/testsuite/ChangeLog:

* rust/compile/all-cast.rs: shows array capacity now
* rust/compile/arrays2.rs: likewise
* rust/compile/const3.rs: fix error message
* rust/compile/const_generics_3.rs: disable until typecheck we get proper errors now!
* rust/compile/usize1.rs: proper capacity error message

@philberty
Copy link
Member Author

@Polygonalr this should help you

@philberty
Copy link
Member Author

@CohenArthur we get proper error checking now on gcc/testsuite/rust/compile/const_generics_3.rs .

In theory const generics isn't that far away now

This patch adds proper folding to the const expression for array capacity we
already have the const folding mechanics and the query system needed to handle cases
where the capacity is a function call in a const context. This leverages and pulls the
gcc tree capacity into the TyTy::ArrayType so it can be used for more typechecking and
eventually doing more const generics work.

Addresses #3885
Fixes #3882

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::query_compile_const_expr): new wrapper
	* backend/rust-compile-base.h: add prototype
	* backend/rust-compile-context.cc (Context::get): singleton helper
	* backend/rust-compile-context.h: likewise
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): handle infer's that can default
	* rust-session-manager.cc (Session::compile_crate): create the gcc context earlier for tychk
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): const fold it
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): fix constructor call
	(ArrayType::as_string): print capacity
	(ArrayType::clone): fix constructor call
	* typecheck/rust-tyty.h: track capacity
	* typecheck/rust-unify.cc (UnifyRules::expect_array): check the capacities

gcc/testsuite/ChangeLog:

	* rust/compile/all-cast.rs: shows array capacity now
	* rust/compile/arrays2.rs: likewise
	* rust/compile/const3.rs: fix error message
	* rust/compile/const_generics_3.rs: disable until typecheck we get proper errors now!
	* rust/compile/usize1.rs: proper capacity error message

Signed-off-by: Philip Herron <[email protected]>
@philberty philberty force-pushed the phil/dev-array-capacity branch from 8422d94 to e526dea Compare July 8, 2025 21:23
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.

LGTM! great job :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

ArrayType does not have a const capacity
2 participants