|
17 | 17 | #include "swift/AST/ASTContext.h" |
18 | 18 | #include "ClangTypeConverter.h" |
19 | 19 | #include "ForeignRepresentationInfo.h" |
20 | | -#include "GenericSignatureBuilder.h" |
21 | 20 | #include "SubstitutionMapStorage.h" |
22 | 21 | #include "swift/AST/ClangModuleLoader.h" |
23 | 22 | #include "swift/AST/ConcreteDeclRef.h" |
|
72 | 71 | using namespace swift; |
73 | 72 |
|
74 | 73 | #define DEBUG_TYPE "ASTContext" |
75 | | -STATISTIC(NumRegisteredGenericSignatureBuilders, |
76 | | - "# of generic signature builders successfully registered"); |
77 | | -STATISTIC(NumRegisteredGenericSignatureBuildersAlready, |
78 | | - "# of generic signature builders already registered"); |
79 | 74 | STATISTIC(NumCollapsedSpecializedProtocolConformances, |
80 | 75 | "# of specialized protocol conformances collapsed"); |
81 | 76 |
|
82 | | -/// Define this to 1 to enable expensive assertions of the |
83 | | -/// GenericSignatureBuilder. |
84 | | -#define SWIFT_GSB_EXPENSIVE_ASSERTIONS 0 |
85 | | - |
86 | 77 | void ModuleLoader::anchor() {} |
87 | 78 | void ClangModuleLoader::anchor() {} |
88 | 79 |
|
@@ -480,10 +471,6 @@ struct ASTContext::Implementation { |
480 | 471 |
|
481 | 472 | llvm::FoldingSet<GenericSignatureImpl> GenericSignatures; |
482 | 473 |
|
483 | | - /// Stored generic signature builders for canonical generic signatures. |
484 | | - llvm::DenseMap<GenericSignature, std::unique_ptr<GenericSignatureBuilder>> |
485 | | - GenericSignatureBuilders; |
486 | | - |
487 | 474 | /// A cache of information about whether particular nominal types |
488 | 475 | /// are representable in a foreign language. |
489 | 476 | llvm::DenseMap<NominalTypeDecl *, ForeignRepresentationInfo> |
@@ -1938,111 +1925,6 @@ void ASTContext::addLoadedModule(ModuleDecl *M) { |
1938 | 1925 | getImpl().LoadedModules[M->getRealName()] = M; |
1939 | 1926 | } |
1940 | 1927 |
|
1941 | | -void ASTContext::registerGenericSignatureBuilder( |
1942 | | - GenericSignature sig, |
1943 | | - GenericSignatureBuilder &&builder) { |
1944 | | - if (LangOpts.EnableRequirementMachine == RequirementMachineMode::Enabled) |
1945 | | - return; |
1946 | | - |
1947 | | - auto canSig = sig.getCanonicalSignature(); |
1948 | | - auto &genericSignatureBuilders = getImpl().GenericSignatureBuilders; |
1949 | | - auto known = genericSignatureBuilders.find(canSig); |
1950 | | - if (known != genericSignatureBuilders.end()) { |
1951 | | - ++NumRegisteredGenericSignatureBuildersAlready; |
1952 | | - return; |
1953 | | - } |
1954 | | - |
1955 | | - ++NumRegisteredGenericSignatureBuilders; |
1956 | | - genericSignatureBuilders[canSig] = |
1957 | | - std::make_unique<GenericSignatureBuilder>(std::move(builder)); |
1958 | | -} |
1959 | | - |
1960 | | -GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder( |
1961 | | - CanGenericSignature sig) { |
1962 | | - // We should only create GenericSignatureBuilders if the requirement machine |
1963 | | - // mode is ::Disabled or ::Verify. |
1964 | | - assert(LangOpts.EnableRequirementMachine != RequirementMachineMode::Enabled && |
1965 | | - "Shouldn't create GenericSignatureBuilder when RequirementMachine " |
1966 | | - "is enabled"); |
1967 | | - |
1968 | | - // Check whether we already have a generic signature builder for this |
1969 | | - // signature and module. |
1970 | | - auto &genericSignatureBuilders = getImpl().GenericSignatureBuilders; |
1971 | | - auto known = genericSignatureBuilders.find(sig); |
1972 | | - if (known != genericSignatureBuilders.end()) |
1973 | | - return known->second.get(); |
1974 | | - |
1975 | | - // Create a new generic signature builder with the given signature. |
1976 | | - auto builder = new GenericSignatureBuilder(*this); |
1977 | | - |
1978 | | - // Store this generic signature builder (no generic environment yet). |
1979 | | - genericSignatureBuilders[sig] = |
1980 | | - std::unique_ptr<GenericSignatureBuilder>(builder); |
1981 | | - |
1982 | | - builder->addGenericSignature(sig); |
1983 | | - |
1984 | | -#if SWIFT_GSB_EXPENSIVE_ASSERTIONS |
1985 | | - auto builderSig = |
1986 | | - builder->computeGenericSignature(/*allowConcreteGenericParams=*/true); |
1987 | | - if (builderSig.getCanonicalSignature() != sig) { |
1988 | | - llvm::errs() << "ERROR: generic signature builder is not idempotent.\n"; |
1989 | | - llvm::errs() << "Original generic signature : "; |
1990 | | - sig->print(llvm::errs()); |
1991 | | - llvm::errs() << "\nReprocessed generic signature: "; |
1992 | | - auto reprocessedSig = builderSig.getCanonicalSignature(); |
1993 | | - |
1994 | | - reprocessedSig->print(llvm::errs()); |
1995 | | - llvm::errs() << "\n"; |
1996 | | - |
1997 | | - if (sig.getGenericParams().size() == |
1998 | | - reprocessedSig.getGenericParams().size() && |
1999 | | - sig.getRequirements().size() == |
2000 | | - reprocessedSig.getRequirements().size()) { |
2001 | | - for (unsigned i : indices(sig.getRequirements())) { |
2002 | | - auto sigReq = sig.getRequirements()[i]; |
2003 | | - auto reprocessedReq = reprocessedSig.getRequirements()[i]; |
2004 | | - if (sigReq.getKind() != reprocessedReq.getKind()) { |
2005 | | - llvm::errs() << "Requirement mismatch:\n"; |
2006 | | - llvm::errs() << " Original: "; |
2007 | | - sigReq.print(llvm::errs(), PrintOptions()); |
2008 | | - llvm::errs() << "\n Reprocessed: "; |
2009 | | - reprocessedReq.print(llvm::errs(), PrintOptions()); |
2010 | | - llvm::errs() << "\n"; |
2011 | | - break; |
2012 | | - } |
2013 | | - |
2014 | | - if (!sigReq.getFirstType()->isEqual(reprocessedReq.getFirstType())) { |
2015 | | - llvm::errs() << "First type mismatch, original is:\n"; |
2016 | | - sigReq.getFirstType().dump(llvm::errs()); |
2017 | | - llvm::errs() << "Reprocessed:\n"; |
2018 | | - reprocessedReq.getFirstType().dump(llvm::errs()); |
2019 | | - llvm::errs() << "\n"; |
2020 | | - break; |
2021 | | - } |
2022 | | - |
2023 | | - if (sigReq.getKind() == RequirementKind::SameType && |
2024 | | - !sigReq.getSecondType()->isEqual(reprocessedReq.getSecondType())) { |
2025 | | - llvm::errs() << "Second type mismatch, original is:\n"; |
2026 | | - sigReq.getSecondType().dump(llvm::errs()); |
2027 | | - llvm::errs() << "Reprocessed:\n"; |
2028 | | - reprocessedReq.getSecondType().dump(llvm::errs()); |
2029 | | - llvm::errs() << "\n"; |
2030 | | - break; |
2031 | | - } |
2032 | | - } |
2033 | | - } |
2034 | | - |
2035 | | - llvm_unreachable("idempotency problem with a generic signature"); |
2036 | | - } |
2037 | | -#else |
2038 | | - // FIXME: This should be handled lazily in the future, and therefore not |
2039 | | - // required. |
2040 | | - builder->processDelayedRequirements(); |
2041 | | -#endif |
2042 | | - |
2043 | | - return builder; |
2044 | | -} |
2045 | | - |
2046 | 1928 | rewriting::RewriteContext & |
2047 | 1929 | ASTContext::getRewriteContext() { |
2048 | 1930 | auto &rewriteCtx = getImpl().TheRewriteContext; |
|
0 commit comments