File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 2222#include " swift/ClangImporter/ClangImporter.h"
2323#include " swift/Serialization/SerializedModuleLoader.h"
2424#include " swift/Subsystems.h"
25+ #include " llvm/ADT/DenseMap.h"
2526
2627using namespace swift ;
2728using namespace swift ::unittest;
@@ -74,3 +75,27 @@ Type SemaTest::getStdlibType(StringRef name) const {
7475
7576 return Type ();
7677}
78+
79+ ConstraintSystem::PotentialBindings
80+ SemaTest::inferBindings (ConstraintSystem &cs, TypeVariableType *typeVar) {
81+ llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
82+ cache;
83+
84+ for (auto *typeVar : cs.getTypeVariables ()) {
85+ if (!typeVar->getImpl ().hasRepresentativeOrFixed ())
86+ cache.insert ({typeVar, cs.inferBindingsFor (typeVar, /* finalize=*/ false )});
87+ }
88+
89+ for (auto *typeVar : cs.getTypeVariables ()) {
90+ auto cachedBindings = cache.find (typeVar);
91+ if (cachedBindings == cache.end ())
92+ continue ;
93+
94+ auto &bindings = cachedBindings->getSecond ();
95+ bindings.finalize (cs, cache);
96+ }
97+
98+ auto result = cache.find (typeVar);
99+ assert (result != cache.end ());
100+ return result->second ;
101+ }
Original file line number Diff line number Diff line change 1818#include " swift/Basic/LangOptions.h"
1919#include " swift/Basic/Platform.h"
2020#include " swift/Basic/SourceManager.h"
21- #include " llvm/ADT/StringRef .h"
21+ #include " swift/Sema/ConstraintSystem .h"
2222#include " llvm/ADT/SmallString.h"
23+ #include " llvm/ADT/StringRef.h"
2324#include " llvm/Support/Host.h"
2425#include " llvm/Support/Path.h"
2526#include " gtest/gtest.h"
2627#include < string>
2728
29+ using namespace swift ::constraints;
30+
2831namespace swift {
2932namespace unittest {
3033
@@ -62,6 +65,9 @@ class SemaTest : public SemaTestBase {
6265
6366protected:
6467 Type getStdlibType (StringRef name) const ;
68+
69+ static ConstraintSystem::PotentialBindings
70+ inferBindings (ConstraintSystem &cs, TypeVariableType *typeVar);
6571};
6672
6773} // end namespace unittest
You can’t perform that action at this time.
0 commit comments