diff --git a/src/Checker.cc b/src/Checker.cc index 034f6ca22..91018248b 100644 --- a/src/Checker.cc +++ b/src/Checker.cc @@ -1347,9 +1347,9 @@ namespace bolt { return Constraint->Source; } - bool unify(Type* A, Type* B, bool DidSwap); + bool unifyField(Type* A, Type* B, bool DidSwap); - bool unifyField(Type* A, Type* B); + bool unify(Type* A, Type* B, bool DidSwap); bool unify() { return unify(Constraint->Left, Constraint->Right, false); @@ -1468,6 +1468,24 @@ namespace bolt { }; + bool Unifier::unifyField(Type* A, Type* B, bool DidSwap) { + if (llvm::isa(A) && llvm::isa(B)) { + return true; + } + if (llvm::isa(B)) { + std::swap(A, B); + DidSwap = !DidSwap; + } + if (llvm::isa(A)) { + auto Present = static_cast(B); + C.DE.add(CurrentFieldName, C.simplifyType(getLeft()), LeftPath, getSource()); + return false; + } + auto Present1 = static_cast(A); + auto Present2 = static_cast(B); + return unify(Present1->Ty, Present2->Ty, DidSwap); + }; + bool Unifier::unify(Type* A, Type* B, bool DidSwap) { A = C.simplifyType(A); @@ -1520,23 +1538,6 @@ namespace bolt { DidSwap = !DidSwap; }; - auto unifyField = [&](Type* A, Type* B) { - if (llvm::isa(A) && llvm::isa(B)) { - return true; - } - if (llvm::isa(B)) { - swap(); - } - if (llvm::isa(A)) { - auto Present = static_cast(B); - C.DE.add(CurrentFieldName, C.simplifyType(getLeft()), LeftPath, getSource()); - return false; - } - auto Present1 = static_cast(A); - auto Present2 = static_cast(B); - return unify(Present1->Ty, Present2->Ty, DidSwap); - }; - if (llvm::isa(A) && llvm::isa(B)) { auto Var1 = static_cast(A); auto Var2 = static_cast(B); @@ -1706,7 +1707,7 @@ namespace bolt { LeftPath.push_back(TypeIndex::forFieldType()); RightPath.push_back(TypeIndex::forFieldType()); CurrentFieldName = Field1->Name; - if (!unifyField(Field1->Ty, Field2->Ty)) { + if (!unifyField(Field1->Ty, Field2->Ty, DidSwap)) { Success = false; } LeftPath.pop_back(); @@ -1743,7 +1744,7 @@ namespace bolt { bool Success = true; pushLeft(TypeIndex::forFieldType()); CurrentFieldName = Field->Name; - if (!unifyField(Field->Ty, new TAbsent)) { + if (!unifyField(Field->Ty, new TAbsent, DidSwap)) { Success = false; } popLeft();