Skip to content

Commit c0f7c2d

Browse files
committed
gccrs: Add implicit infer support for unify on const types
gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::commit): commit hook update (UnifyRules::go): insert implicit infer const types Signed-off-by: Philip Herron <[email protected]>
1 parent 8334e09 commit c0f7c2d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

gcc/rust/typecheck/rust-unify.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other,
137137
// if any of the types are inference variables lets fix them
138138
if (ref_tyty->is<TyTy::InferType> ())
139139
context.insert_implicit_type (ref, resolved);
140+
else if (resolved->is<TyTy::ConstType> ()
141+
&& ref_tyty->is<TyTy::ConstType> ())
142+
{
143+
auto &const_expr = *static_cast<TyTy::ConstType *> (resolved);
144+
if (const_expr.get_const_kind ()
145+
== TyTy::ConstType::ConstKind::Value)
146+
{
147+
context.insert_implicit_type (ref, resolved);
148+
}
149+
}
140150
}
141151
}
142152
}
@@ -264,6 +274,35 @@ UnifyRules::go ()
264274
// set the rtype now to the new inference var
265275
ltype = i;
266276
}
277+
else if (ltype->is<TyTy::ConstType> () && rtype->is<TyTy::ConstType> ())
278+
{
279+
const auto &lhs = *static_cast<TyTy::ConstType *> (ltype);
280+
const auto &rhs = *static_cast<TyTy::ConstType *> (rtype);
281+
282+
bool both_are_decls
283+
= lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl
284+
&& rhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl;
285+
bool have_decls
286+
= lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl
287+
|| rhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl;
288+
289+
if (have_decls && !both_are_decls)
290+
{
291+
if (lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl)
292+
{
293+
TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var (
294+
lhs, lhs.get_locus ());
295+
ltype = iv.get_tyty ();
296+
}
297+
else if (rhs.get_const_kind ()
298+
== TyTy::ConstType::ConstKind::Decl)
299+
{
300+
TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var (
301+
rhs, rhs.get_locus ());
302+
rtype = iv.get_tyty ();
303+
}
304+
}
305+
}
267306
}
268307

269308
if ((ltype->is<TyTy::ConstType> () || rtype->is<TyTy::ConstType> ())

0 commit comments

Comments
 (0)