Skip to content

gccrs: add discriminant value intrinsic#3425

Merged
philberty merged 1 commit into
masterfrom
phil/enum-intrinsics
Feb 11, 2025
Merged

gccrs: add discriminant value intrinsic#3425
philberty merged 1 commit into
masterfrom
phil/enum-intrinsics

Conversation

@philberty

@philberty philberty commented Feb 10, 2025

Copy link
Copy Markdown
Member

This is pretty nasty piece of rust in my opinion the return type of this intrinsic results into a lang item associated type:

<T as DiscriminantKind>::Discriminant

This is a special case which needs to support mapping onto the repr type of the associated ADT that is passed in, but defaults to isize otherwise.

This patch assumes we only come accross this case in a HIR::CALL_EXPR, so and makes assumutions that its always of this function signiture. I will do some checking in libcore to verify that assumption. More work is needed to parse the repr type on enums but the code is there to support this when its in to change the types etc.

Addresses #3348

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (discriminant_value_handler): new handler
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): track the defid
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): default isize
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): special case CallExpr
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): parse repr options enum
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove bad diagnostic
* typecheck/rust-tyty.cc (PlaceholderType::PlaceholderType): track defid
(PlaceholderType::clone): likewise
(PlaceholderType::get_def_id): likeiwse
* typecheck/rust-tyty.h: placeholder track defid
* util/rust-lang-item.cc: add new lang items
* util/rust-lang-item.h: likewise

gcc/testsuite/ChangeLog:

* rust/execute/torture/enum_intrinsics1.rs: New test.

This is pretty nasty piece of rust in my opinion the return type of this
intrinsic results into a lang item associated type:

  <T as DiscriminantKind>::Discriminant

This is a special case which needs to support mapping onto the repr type
of the associated ADT that is passed in, but defaults to iszie otherwise.

This patch assumes we only come accross this case in a HIR::CALL_EXPR, so
and makes assumutions that its always of this function signiture. I will
do some checking in libcore to verify that assumption. More work is needed
to parse the repr type on enums but the code is there to support this when
its in to change the types etc.

Addresses #3348

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (discriminant_value_handler): new handler
	* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): track the defid
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): default isize
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): special case CallExpr
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): parse repr options enum
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove bad diagnostic
	* typecheck/rust-tyty.cc (PlaceholderType::PlaceholderType): track defid
	(PlaceholderType::clone): likewise
	(PlaceholderType::get_def_id): likeiwse
	* typecheck/rust-tyty.h: placeholder track defid
	* util/rust-lang-item.cc: add new lang items
	* util/rust-lang-item.h: likewise

gcc/testsuite/ChangeLog:

	* rust/execute/torture/enum_intrinsics1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty added this to the Remaining typecheck issues milestone Feb 10, 2025
@philberty philberty added this pull request to the merge queue Feb 11, 2025
Merged via the queue into master with commit 3fd738c Feb 11, 2025
@philberty philberty mentioned this pull request Feb 11, 2025
@philberty philberty linked an issue Feb 11, 2025 that may be closed by this pull request
@philberty philberty deleted the phil/enum-intrinsics branch February 13, 2025 13:08
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.

enum instrinsics

1 participant