Skip to content

gccrs: improve handling of defered operator overload handling - #4850

Merged
philberty merged 1 commit into
masterfrom
phil/dev-defer
Sep 6, 2026
Merged

gccrs: improve handling of defered operator overload handling#4850
philberty merged 1 commit into
masterfrom
phil/dev-defer

Conversation

@philberty

Copy link
Copy Markdown
Member

When we are compiling libcore each operation +-/* etc all resolve to libcore implementations of these that define the semantics but what can happen is because of infer vars its ambigious what implementation this should specialize to untill more type hints are applied so we return an infer variable result so type checking can continue and we try to resolve at the end.

gcc/rust/ChangeLog:

* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): optional result type
* typecheck/rust-hir-dot-operator.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): defer flag (TypeCheckExpr::visit): pass throw the borrow
* typecheck/rust-hir-type-check-expr.h: likewise
* typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new
* typecheck/rust-type-util.cc (unify_site): like parameter ordering (unify_site_and): likewise
* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_ambigious_op_overload): new (TypeCheckContext::compute_inference_variables): likewise (TypeCheckContext::compute_infer_var): likewise
* typecheck/rust-unify.cc (UnifyRules::Resolve): fix arguments (UnifyRules::resolve_subtype):likewise
* typecheck/rust-unify.h: likewise

gcc/testsuite/ChangeLog:

* rust/execute/torture/deferred-add-partial-ord.rs: New test.

@philberty philberty added the core Issue related to the compilation of the `core` crate label Sep 6, 2026
When we are compiling libcore each operation +-/* etc all resolve to libcore
implementations of these that define the semantics but what can happen is
because of infer vars its ambigious what implementation this should
specialize to untill more type hints are applied so we return an infer
variable result so type checking can continue and we try to resolve at
the end.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): optional result type
	* typecheck/rust-hir-dot-operator.h: likewise
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): defer flag
	(TypeCheckExpr::visit): pass throw the borrow
	* typecheck/rust-hir-type-check-expr.h: likewise
	* typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new
	* typecheck/rust-type-util.cc (unify_site): like parameter ordering
	(unify_site_and): likewise
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_ambigious_op_overload): new
	(TypeCheckContext::compute_inference_variables): likewise
	(TypeCheckContext::compute_infer_var): likewise
	* typecheck/rust-unify.cc (UnifyRules::Resolve): fix arguments
	(UnifyRules::resolve_subtype):likewise
	* typecheck/rust-unify.h: likewise

gcc/testsuite/ChangeLog:

	* rust/execute/torture/deferred-add-partial-ord.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty
philberty added this pull request to the merge queue Sep 6, 2026
Merged via the queue into master with commit 0e58f6b Sep 6, 2026
13 checks passed
@philberty
philberty deleted the phil/dev-defer branch September 7, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issue related to the compilation of the `core` crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant