Skip to content

Fix bad method resolution and add move_val_init #1999

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

Merged
merged 3 commits into from
Mar 18, 2023
Merged

Conversation

philberty
Copy link
Member

@philberty philberty commented Mar 16, 2023

Fixes #1981 #1902

@philberty philberty force-pushed the phil/move_val_init branch 3 times, most recently from 31f4fbb to 549ba42 Compare March 17, 2023 18:17
@philberty philberty mentioned this pull request Mar 17, 2023
41 tasks
In the senario where you infer types via unify_site_and but choose to not
commit the result you can end up with coercion to infer the result later on
which does not get fully replaced resulting in a stray inference variable
that can be left alone as a general inference variable leading to missing
type context info. This patch gives support to add type hints to inference
variables so they can be defaulted correctly in more complex cases. The
old system relied on the unification result commiting and overriding the
inference variables so they dissapear out of the current typeing context.

This was needed to fix #1981 where it is valid to inject inference
variables here. This lead to a regression in a few of the complex generic
trait test cases such as execute/torture/traits9.rs which had the wrong
argument type and defaulted wrongly to i32 instead of isize.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): fix ctor
	* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): likewise
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::push_new_loop_context): likewise
	* typecheck/rust-tyty-util.cc (TyVar::get_implicit_infer_var): likewise
	* typecheck/rust-tyty.cc (InferType::InferType): new ctor with type hint
	(InferType::clone): fix ctor
	(InferType::apply_primitive_type_hint): new function to apply possible hint
	* typecheck/rust-tyty.h: update prototypes
	* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): apply type hints
	(UnifyRules::expect_bool): likewise
	(UnifyRules::expect_char): likewise
	(UnifyRules::expect_int): likewise
	(UnifyRules::expect_uint): likewise
	(UnifyRules::expect_float): likewise
	(UnifyRules::expect_isize): likewise
	(UnifyRules::expect_usize): likewise

Signed-off-by: Philip Herron <[email protected]>
We should use the result of our attempted unify inference as this will
allow the direct unification of generic pointer types to concrete ones.

Fixes #1981

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::select): use the result

Signed-off-by: Philip Herron <[email protected]>
This implements it as a builtin memcpy using the generic param T for the
size hint.

Fixes #1902

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (move_val_init_handler): new intrinsice
	(uninit_handler): use a builtin memcpy

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1981.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
@philberty philberty force-pushed the phil/move_val_init branch from 549ba42 to 95b3f53 Compare March 17, 2023 22:51
@philberty philberty added this to the Final upstream patches milestone Mar 17, 2023
@philberty philberty linked an issue Mar 17, 2023 that may be closed by this pull request
2 tasks
@philberty philberty added this pull request to the merge queue Mar 18, 2023
@philberty philberty merged commit 6b77eb3 into master Mar 18, 2023
@philberty philberty deleted the phil/move_val_init branch March 20, 2023 21:21
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.

Bad method resolution Support move-val-init intrinsic
1 participant