Skip to content

Commit 567b404

Browse files
committed
gccrs: respect the unify rules commit flag
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]>
1 parent 9bd2443 commit 567b404

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

gcc/rust/typecheck/rust-unify.cc

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype,
385385
== TyTy::InferType::InferTypeKind::INTEGRAL);
386386
if (is_valid)
387387
{
388-
ltype->apply_primitive_type_hint (*rtype);
388+
if (commit_flag)
389+
ltype->apply_primitive_type_hint (*rtype);
389390
return rtype;
390391
}
391392
}
@@ -399,7 +400,8 @@ UnifyRules::expect_inference_variable (TyTy::InferType *ltype,
399400
== TyTy::InferType::InferTypeKind::FLOAT);
400401
if (is_valid)
401402
{
402-
ltype->apply_primitive_type_hint (*rtype);
403+
if (commit_flag)
404+
ltype->apply_primitive_type_hint (*rtype);
403405
return rtype;
404406
}
405407
}
@@ -523,7 +525,7 @@ UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype)
523525
}
524526
}
525527

526-
return type.clone ();
528+
return ltype;
527529
}
528530
break;
529531

@@ -1269,7 +1271,8 @@ UnifyRules::expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype)
12691271
= r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL;
12701272
if (is_valid)
12711273
{
1272-
r->apply_primitive_type_hint (*ltype);
1274+
if (commit_flag)
1275+
r->apply_primitive_type_hint (*ltype);
12731276
return ltype->clone ();
12741277
}
12751278
}
@@ -1319,7 +1322,8 @@ UnifyRules::expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype)
13191322
= r->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL;
13201323
if (is_valid)
13211324
{
1322-
r->apply_primitive_type_hint (*ltype);
1325+
if (commit_flag)
1326+
r->apply_primitive_type_hint (*ltype);
13231327
return ltype->clone ();
13241328
}
13251329
}
@@ -1370,7 +1374,8 @@ UnifyRules::expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype)
13701374
|| r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL;
13711375
if (is_valid)
13721376
{
1373-
r->apply_primitive_type_hint (*ltype);
1377+
if (commit_flag)
1378+
r->apply_primitive_type_hint (*ltype);
13741379
return ltype->clone ();
13751380
}
13761381
}
@@ -1428,7 +1433,8 @@ UnifyRules::expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype)
14281433
|| r->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL;
14291434
if (is_valid)
14301435
{
1431-
r->apply_primitive_type_hint (*ltype);
1436+
if (commit_flag)
1437+
r->apply_primitive_type_hint (*ltype);
14321438
return ltype->clone ();
14331439
}
14341440
}
@@ -1486,7 +1492,8 @@ UnifyRules::expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype)
14861492
|| r->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT;
14871493
if (is_valid)
14881494
{
1489-
r->apply_primitive_type_hint (*ltype);
1495+
if (commit_flag)
1496+
r->apply_primitive_type_hint (*ltype);
14901497
return ltype->clone ();
14911498
}
14921499
}
@@ -1543,7 +1550,8 @@ UnifyRules::expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype)
15431550
= r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT;
15441551
if (is_valid)
15451552
{
1546-
r->apply_primitive_type_hint (*ltype);
1553+
if (commit_flag)
1554+
r->apply_primitive_type_hint (*ltype);
15471555
return ltype->clone ();
15481556
}
15491557
}
@@ -1593,7 +1601,8 @@ UnifyRules::expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype)
15931601
= r->get_infer_kind () != TyTy::InferType::InferTypeKind::FLOAT;
15941602
if (is_valid)
15951603
{
1596-
r->apply_primitive_type_hint (*ltype);
1604+
if (commit_flag)
1605+
r->apply_primitive_type_hint (*ltype);
15971606
return ltype->clone ();
15981607
}
15991608
}

0 commit comments

Comments
 (0)