Skip to content

AST: Remove legacy GSB-based GenericSignature query implementation #40812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ namespace swift {
class TypeVariableType;
class TupleType;
class FunctionType;
class GenericSignatureBuilder;
class ArchetypeType;
class Identifier;
class InheritedNameSet;
Expand Down Expand Up @@ -1225,26 +1224,13 @@ class ASTContext final {
/// Increments \c NumTypoCorrections then checks this against the limit in
/// the language options.
bool shouldPerformTypoCorrection();

private:
/// Register the given generic signature builder to be used as the canonical
/// generic signature builder for the given signature, if we don't already
/// have one.
void registerGenericSignatureBuilder(GenericSignature sig,
GenericSignatureBuilder &&builder);
friend class GenericSignatureBuilder;

private:
friend class IntrinsicInfo;
/// Retrieve an LLVMContext that is used for scratch space for intrinsic lookup.
llvm::LLVMContext &getIntrinsicScratchContext() const;

public:
/// Retrieve or create the stored generic signature builder for the given
/// canonical generic signature and module.
GenericSignatureBuilder *getOrCreateGenericSignatureBuilder(
CanGenericSignature sig);

rewriting::RewriteContext &getRewriteContext();

/// This is a hack to break cycles. Don't introduce new callers of this
Expand Down
9 changes: 0 additions & 9 deletions include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace swift {

class GenericSignatureBuilder;
class ProtocolConformanceRef;
class ProtocolType;
class SubstitutionMap;
Expand Down Expand Up @@ -84,7 +83,6 @@ class ConformanceAccessPath {
ConformanceAccessPath(ArrayRef<Entry> path) : path(path) {}

friend class GenericSignatureImpl;
friend class GenericSignatureBuilder;
friend class rewriting::RequirementMachine;

public:
Expand Down Expand Up @@ -338,9 +336,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final

ASTContext &getASTContext() const;

/// Retrieve the generic signature builder for the given generic signature.
GenericSignatureBuilder *getGenericSignatureBuilder() const;

/// Retrieve the requirement machine for the given generic signature.
rewriting::RequirementMachine *getRequirementMachine() const;

Expand Down Expand Up @@ -385,8 +380,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
///
/// The type parameters must be known to not be concrete within the context.
bool areSameTypeParameterInContext(Type type1, Type type2) const;
bool areSameTypeParameterInContext(Type type1, Type type2,
GenericSignatureBuilder &builder) const;

/// Determine if \c sig can prove \c requirement, meaning that it can deduce
/// T: Foo or T == U (etc.) with the information it knows. This includes
Expand All @@ -396,8 +389,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
Requirement requirement, bool allowMissing = false) const;

bool isCanonicalTypeInContext(Type type) const;
bool isCanonicalTypeInContext(Type type,
GenericSignatureBuilder &builder) const;

/// Retrieve the conformance access path used to extract the conformance of
/// interface \c type to the given \c protocol.
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,6 @@ namespace swift {
ASTVerifierOverrideKind ASTVerifierOverride =
ASTVerifierOverrideKind::NoOverride;

/// Whether the new experimental generics implementation is enabled.
RequirementMachineMode EnableRequirementMachine =
RequirementMachineMode::Enabled;

/// Enables merged associated type support, which might go away.
bool RequirementMachineMergedAssociatedTypes = true;

Expand Down
4 changes: 0 additions & 4 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,6 @@ def no_emit_module_separately:
Flags<[NoInteractiveOption, HelpHidden]>,
HelpText<"Force using merge-module as the incremental build mode (new Driver only)">;

def requirement_machine_EQ : Joined<["-"], "requirement-machine=">,
Flags<[FrontendOption, ModuleInterfaceOption]>,
HelpText<"Control usage of experimental generics implementation: 'on', 'off', or 'verify'">;

def requirement_machine_protocol_signatures_EQ : Joined<["-"], "requirement-machine-protocol-signatures=">,
Flags<[FrontendOption]>,
HelpText<"Control usage of experimental protocol requirement signature minimization: 'on', 'off', or 'verify'">;
Expand Down
118 changes: 0 additions & 118 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "swift/AST/ASTContext.h"
#include "ClangTypeConverter.h"
#include "ForeignRepresentationInfo.h"
#include "GenericSignatureBuilder.h"
#include "SubstitutionMapStorage.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/ConcreteDeclRef.h"
Expand Down Expand Up @@ -72,17 +71,9 @@
using namespace swift;

#define DEBUG_TYPE "ASTContext"
STATISTIC(NumRegisteredGenericSignatureBuilders,
"# of generic signature builders successfully registered");
STATISTIC(NumRegisteredGenericSignatureBuildersAlready,
"# of generic signature builders already registered");
STATISTIC(NumCollapsedSpecializedProtocolConformances,
"# of specialized protocol conformances collapsed");

/// Define this to 1 to enable expensive assertions of the
/// GenericSignatureBuilder.
#define SWIFT_GSB_EXPENSIVE_ASSERTIONS 0

void ModuleLoader::anchor() {}
void ClangModuleLoader::anchor() {}

Expand Down Expand Up @@ -480,10 +471,6 @@ struct ASTContext::Implementation {

llvm::FoldingSet<GenericSignatureImpl> GenericSignatures;

/// Stored generic signature builders for canonical generic signatures.
llvm::DenseMap<GenericSignature, std::unique_ptr<GenericSignatureBuilder>>
GenericSignatureBuilders;

/// A cache of information about whether particular nominal types
/// are representable in a foreign language.
llvm::DenseMap<NominalTypeDecl *, ForeignRepresentationInfo>
Expand Down Expand Up @@ -1938,111 +1925,6 @@ void ASTContext::addLoadedModule(ModuleDecl *M) {
getImpl().LoadedModules[M->getRealName()] = M;
}

void ASTContext::registerGenericSignatureBuilder(
GenericSignature sig,
GenericSignatureBuilder &&builder) {
if (LangOpts.EnableRequirementMachine == RequirementMachineMode::Enabled)
return;

auto canSig = sig.getCanonicalSignature();
auto &genericSignatureBuilders = getImpl().GenericSignatureBuilders;
auto known = genericSignatureBuilders.find(canSig);
if (known != genericSignatureBuilders.end()) {
++NumRegisteredGenericSignatureBuildersAlready;
return;
}

++NumRegisteredGenericSignatureBuilders;
genericSignatureBuilders[canSig] =
std::make_unique<GenericSignatureBuilder>(std::move(builder));
}

GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
CanGenericSignature sig) {
// We should only create GenericSignatureBuilders if the requirement machine
// mode is ::Disabled or ::Verify.
assert(LangOpts.EnableRequirementMachine != RequirementMachineMode::Enabled &&
"Shouldn't create GenericSignatureBuilder when RequirementMachine "
"is enabled");

// Check whether we already have a generic signature builder for this
// signature and module.
auto &genericSignatureBuilders = getImpl().GenericSignatureBuilders;
auto known = genericSignatureBuilders.find(sig);
if (known != genericSignatureBuilders.end())
return known->second.get();

// Create a new generic signature builder with the given signature.
auto builder = new GenericSignatureBuilder(*this);

// Store this generic signature builder (no generic environment yet).
genericSignatureBuilders[sig] =
std::unique_ptr<GenericSignatureBuilder>(builder);

builder->addGenericSignature(sig);

#if SWIFT_GSB_EXPENSIVE_ASSERTIONS
auto builderSig =
builder->computeGenericSignature(/*allowConcreteGenericParams=*/true);
if (builderSig.getCanonicalSignature() != sig) {
llvm::errs() << "ERROR: generic signature builder is not idempotent.\n";
llvm::errs() << "Original generic signature : ";
sig->print(llvm::errs());
llvm::errs() << "\nReprocessed generic signature: ";
auto reprocessedSig = builderSig.getCanonicalSignature();

reprocessedSig->print(llvm::errs());
llvm::errs() << "\n";

if (sig.getGenericParams().size() ==
reprocessedSig.getGenericParams().size() &&
sig.getRequirements().size() ==
reprocessedSig.getRequirements().size()) {
for (unsigned i : indices(sig.getRequirements())) {
auto sigReq = sig.getRequirements()[i];
auto reprocessedReq = reprocessedSig.getRequirements()[i];
if (sigReq.getKind() != reprocessedReq.getKind()) {
llvm::errs() << "Requirement mismatch:\n";
llvm::errs() << " Original: ";
sigReq.print(llvm::errs(), PrintOptions());
llvm::errs() << "\n Reprocessed: ";
reprocessedReq.print(llvm::errs(), PrintOptions());
llvm::errs() << "\n";
break;
}

if (!sigReq.getFirstType()->isEqual(reprocessedReq.getFirstType())) {
llvm::errs() << "First type mismatch, original is:\n";
sigReq.getFirstType().dump(llvm::errs());
llvm::errs() << "Reprocessed:\n";
reprocessedReq.getFirstType().dump(llvm::errs());
llvm::errs() << "\n";
break;
}

if (sigReq.getKind() == RequirementKind::SameType &&
!sigReq.getSecondType()->isEqual(reprocessedReq.getSecondType())) {
llvm::errs() << "Second type mismatch, original is:\n";
sigReq.getSecondType().dump(llvm::errs());
llvm::errs() << "Reprocessed:\n";
reprocessedReq.getSecondType().dump(llvm::errs());
llvm::errs() << "\n";
break;
}
}
}

llvm_unreachable("idempotency problem with a generic signature");
}
#else
// FIXME: This should be handled lazily in the future, and therefore not
// required.
builder->processDelayedRequirements();
#endif

return builder;
}

rewriting::RewriteContext &
ASTContext::getRewriteContext() {
auto &rewriteCtx = getImpl().TheRewriteContext;
Expand Down
Loading