aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-02-26 18:30:49 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:18:59 +0100
commit00b8eff7bda39ebd7ca9e278c33736f7f9e09994 (patch)
tree81e505834960be7ba0a142cc98de5153519ffa27
parent4306bf12227d62ebcb8b2d9c3d570be8e4b767ff (diff)
downloadgcc-00b8eff7bda39ebd7ca9e278c33736f7f9e09994.zip
gcc-00b8eff7bda39ebd7ca9e278c33736f7f9e09994.tar.gz
gcc-00b8eff7bda39ebd7ca9e278c33736f7f9e09994.tar.bz2
gccrs: refactor unify commit as a static function from unify code
Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::Resolve): refactor (UnifyRules::commit): refactor * typecheck/rust-unify.h: likewise
-rw-r--r--gcc/rust/typecheck/rust-unify.cc27
-rw-r--r--gcc/rust/typecheck/rust-unify.h5
2 files changed, 21 insertions, 11 deletions
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 69ab2a9..d2d8ef5 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -36,7 +36,7 @@ UnifyRules::Resolve (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
TyTy::BaseType *result = r.go ();
if (r.commit_flag)
- r.commit (result);
+ UnifyRules::commit (lhs.get_ty (), rhs.get_ty (), result);
bool failed = result->get_kind () == TyTy::TypeKind::ERROR;
if (failed && r.emit_error)
@@ -58,19 +58,26 @@ UnifyRules::get_other ()
}
void
-UnifyRules::commit (TyTy::BaseType *resolved)
+UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other,
+ TyTy::BaseType *resolved)
{
- resolved->append_reference (get_base ()->get_ref ());
- resolved->append_reference (get_other ()->get_ref ());
- for (auto ref : get_base ()->get_combined_refs ())
+ TypeCheckContext &context = *TypeCheckContext::get ();
+ Analysis::Mappings &mappings = *Analysis::Mappings::get ();
+
+ TyTy::BaseType *b = base->destructure ();
+ TyTy::BaseType *o = other->destructure ();
+
+ resolved->append_reference (b->get_ref ());
+ resolved->append_reference (o->get_ref ());
+ for (auto ref : b->get_combined_refs ())
resolved->append_reference (ref);
- for (auto ref : get_other ()->get_combined_refs ())
+ for (auto ref : o->get_combined_refs ())
resolved->append_reference (ref);
- get_other ()->append_reference (resolved->get_ref ());
- get_other ()->append_reference (get_base ()->get_ref ());
- get_base ()->append_reference (resolved->get_ref ());
- get_base ()->append_reference (get_other ()->get_ref ());
+ o->append_reference (resolved->get_ref ());
+ o->append_reference (b->get_ref ());
+ b->append_reference (resolved->get_ref ());
+ b->append_reference (o->get_ref ());
bool result_resolved = resolved->get_kind () != TyTy::TypeKind::INFER;
bool result_is_infer_var = resolved->get_kind () == TyTy::TypeKind::INFER;
diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h
index 65f1ffe..dcd1583 100644
--- a/gcc/rust/typecheck/rust-unify.h
+++ b/gcc/rust/typecheck/rust-unify.h
@@ -32,6 +32,9 @@ public:
TyTy::TyWithLocation rhs, Location locus,
bool commit_flag, bool emit_error);
+ static void commit (TyTy::BaseType *base, TyTy::BaseType *other,
+ TyTy::BaseType *resolved);
+
protected:
TyTy::BaseType *expect_inference_variable (TyTy::InferType *ltype,
TyTy::BaseType *rtype);
@@ -69,7 +72,7 @@ private:
Location locus, bool commit_flag, bool emit_error);
void emit_type_mismatch () const;
- void commit (TyTy::BaseType *resolved);
+
TyTy::BaseType *go ();
TyTy::BaseType *get_base ();