Skip to content

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

Merged
philberty merged 1 commit into
masterfrom
phil/dev-array-capacity
Jul 10, 2025
Merged

gccrs: Do proper const folding during typechecking for array capacities#3889
philberty merged 1 commit into
masterfrom
phil/dev-array-capacity

Conversation

@philberty

@philberty philberty commented Jul 8, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

@Polygonalr this should help you

@philberty

Copy link
Copy Markdown
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 <herron.philip@googlemail.com>
@philberty philberty force-pushed the phil/dev-array-capacity branch from 8422d94 to e526dea Compare July 8, 2025 21:23

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! great job :D

@philberty philberty added this pull request to the merge queue Jul 10, 2025
Merged via the queue into master with commit 8722b01 Jul 10, 2025
13 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in libcore 1.49 Jul 10, 2025
@philberty philberty deleted the phil/dev-array-capacity branch July 10, 2025 10:50
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.

ArrayType does not have a const capacity

2 participants