Skip to content

Conversation

philberty
Copy link
Member

This is a patch set to rid of this old interface. Its been a mess hiding issues in our
unify code and type system in general.

This interface is not respecting the coercion api commit is always false,
we need to ensure this is respected via the try flag like the rest of the
coercion logic.

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::select): respect try flag

Signed-off-by: Philip Herron <[email protected]>
I needed to remove som usage of const so we can get rid of can_eq in
type bounds probe. This means we can use the types_compatable interface
instead. Which is much better.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.h: remove const
	* backend/rust-compile-expr.cc: likewise
	* backend/rust-compile.cc (HIRCompileBase::coerce_to_dyn_object): likewise
	* typecheck/rust-hir-type-bounds.h: likewise
	* typecheck/rust-type-util.cc (lookup_associated_impl_block): likewise
	* typecheck/rust-type-util.h (lookup_associated_impl_block): likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): likewise
	(TypeBoundsProbe::Probe): likewise
	* typecheck/rust-tyty-cmp.h: likewise
	* typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): likewise
	* typecheck/rust-tyty.cc (BaseType::satisfies_bound): likewise
	(BaseType::bounds_compatible): likewise
	(VariantDef::clone): likewise
	(VariantDef::monomorphized_clone): likewise
	(OpaqueType::is_equal): likewise
	(DynamicObjectType::is_equal): likewise
	* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <[email protected]>
We use the types compatable interface for unify here and so if
we dont respect the commit flag the interface can have unintended
side effects with infer type hints throwing things off down the line.

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): dont commit
	(UnifyRules::expect_adt): likewise
	(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]>
Getting close to getting rid of can_eq and tyty-cmp soon.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate):
	refactor to types_compatable

Signed-off-by: Philip Herron <[email protected]>
We need to make the type bounds check a flag because it can turn into a
recursive type bounds check. This allows us to remove another can_eq usage

gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (types_compatable):  add check bounds flag
	(unify_site_and): likewise
	* typecheck/rust-type-util.h (types_compatable): likewise
	(unify_site_and): likewise
	* typecheck/rust-tyty-bounds.cc: likewise
	* typecheck/rust-unify.cc (UnifyRules::UnifyRules): likewise
	(UnifyRules::Resolve): likewise
	(UnifyRules::resolve_subtype): likewise
	(UnifyRules::go): likewise
	* typecheck/rust-unify.h: likewise

Signed-off-by: Philip Herron <[email protected]>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (BaseType::satisfies_bound): use types_compatable instead

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1725-2.rs: remove bad error message

Signed-off-by: Philip Herron <[email protected]>
We should only clone when we commit and it was successful. With no
cloning there is a regression in min specialization 2. Probably because
it needs to know the unify site hirid and ensure we have it set there.

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::Resolve): check for success
	(UnifyRules::expect_inference_variable): dont clone
	(UnifyRules::expect_adt): likewise
	(UnifyRules::expect_str): likewise
	(UnifyRules::expect_reference): likewise
	(UnifyRules::expect_pointer): likewise
	(UnifyRules::expect_param): likewise
	(UnifyRules::expect_array): likewise
	(UnifyRules::expect_slice): likewise
	(UnifyRules::expect_fndef): likewise
	(UnifyRules::expect_fnptr): likewise
	(UnifyRules::expect_tuple): likewise
	(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
	(UnifyRules::expect_never): likewise
	(UnifyRules::expect_placeholder): likewise
	(UnifyRules::expect_projection): likewise
	(UnifyRules::expect_dyn): likewise
	(UnifyRules::expect_closure): likewise

Signed-off-by: Philip Herron <[email protected]>
During unification we denote failures using a new error mark node. This
keeps a static one and reuses it instead.

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (unify_error_type_node): new static node
	(UnifyRules::go): likewise
	(UnifyRules::expect_inference_variable): likewise
	(UnifyRules::expect_adt): likewise
	(UnifyRules::expect_str): likewise
	(UnifyRules::expect_reference): likewise
	(UnifyRules::expect_pointer): likewise
	(UnifyRules::expect_param): likewise
	(UnifyRules::expect_array): likewise
	(UnifyRules::expect_slice): likewise
	(UnifyRules::expect_fndef): likewise
	(UnifyRules::expect_fnptr): likewise
	(UnifyRules::expect_tuple): likewise
	(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
	(UnifyRules::expect_never): likewise
	(UnifyRules::expect_placeholder): likewise
	(UnifyRules::expect_projection): likewise
	(UnifyRules::expect_dyn): likewise
	(UnifyRules::expect_closure): likewise
	(UnifyRules::expect_opaque): likewise
	(UnifyRules::expect_const): likewise

Signed-off-by: Philip Herron <[email protected]>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (ParamType::is_equal): uses types_compatable

Signed-off-by: Philip Herron <[email protected]>
This was an initial helper from back in the day which was not maintained
but was a nice const simple way to check if types are compatable. But
reusing our unify code is much much more acurate and single source of
truth on the type system.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (InferType::can_eq): remove
	(ErrorType::can_eq): likewise
	(ADTType::can_eq): likewise
	(TupleType::can_eq): likewise
	(FnType::can_eq): likewise
	(FnPtr::can_eq): likewise
	(ClosureType::can_eq): likewise
	(ArrayType::can_eq): likewise
	(SliceType::can_eq): likewise
	(BoolType::can_eq): likewise
	(IntType::can_eq): likewise
	(UintType::can_eq): likewise
	(FloatType::can_eq): likewise
	(USizeType::can_eq): likewise
	(ISizeType::can_eq): likewise
	(CharType::can_eq): likewise
	(ReferenceType::can_eq): likewise
	(PointerType::can_eq): likewise
	(ParamType::can_eq): likewise
	(ConstType::can_eq): likewise
	(OpaqueType::can_eq): likewise
	(StrType::can_eq): likewise
	(NeverType::can_eq): likewise
	(PlaceholderType::can_eq): likewise
	(ProjectionType::can_eq): likewise
	(DynamicObjectType::can_eq): likewise
	* typecheck/rust-tyty.h: remove can_eq
	* typecheck/rust-tyty-cmp.h: Removed.

Signed-off-by: Philip Herron <[email protected]>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (VariantDef::clone): fix formatting
	(VariantDef::monomorphized_clone): likewise
	* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <[email protected]>
@philberty philberty enabled auto-merge August 29, 2025 18:38
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.

1 participant