diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 8e5bf7e71f8c0..f57f390143a12 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -95,7 +95,6 @@ namespace swift { class TypeVariableType; class TupleType; class FunctionType; - class GenericSignatureBuilder; class ArchetypeType; class Identifier; class InheritedNameSet; @@ -1225,14 +1224,6 @@ 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; @@ -1240,11 +1231,6 @@ class ASTContext final { 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 diff --git a/include/swift/AST/GenericSignature.h b/include/swift/AST/GenericSignature.h index a11d5cc66700d..a750c247a7200 100644 --- a/include/swift/AST/GenericSignature.h +++ b/include/swift/AST/GenericSignature.h @@ -30,7 +30,6 @@ namespace swift { -class GenericSignatureBuilder; class ProtocolConformanceRef; class ProtocolType; class SubstitutionMap; @@ -84,7 +83,6 @@ class ConformanceAccessPath { ConformanceAccessPath(ArrayRef path) : path(path) {} friend class GenericSignatureImpl; - friend class GenericSignatureBuilder; friend class rewriting::RequirementMachine; public: @@ -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; @@ -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 @@ -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. diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 1b15badd14650..1bfed64e7d81e 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -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; diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index a4a80428ac67b..480dcb1fb2369 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -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'">; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 84982ee54c39a..21bfef2986770 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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" @@ -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() {} @@ -480,10 +471,6 @@ struct ASTContext::Implementation { llvm::FoldingSet GenericSignatures; - /// Stored generic signature builders for canonical generic signatures. - llvm::DenseMap> - GenericSignatureBuilders; - /// A cache of information about whether particular nominal types /// are representable in a foreign language. llvm::DenseMap @@ -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(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(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; diff --git a/lib/AST/GenericSignature.cpp b/lib/AST/GenericSignature.cpp index c16e66c068c6f..0ef013c6ef333 100644 --- a/lib/AST/GenericSignature.cpp +++ b/lib/AST/GenericSignature.cpp @@ -24,8 +24,6 @@ #include "swift/AST/Types.h" #include "swift/Basic/SourceManager.h" #include "swift/Basic/STLExtras.h" -#include "GenericSignatureBuilder.h" -#include "GenericSignatureBuilderImpl.h" #include "RequirementMachine/RequirementMachine.h" #include @@ -182,17 +180,6 @@ ArrayRef GenericSignature::getRequirements() const { : getPointer()->getRequirements(); } -GenericSignatureBuilder * -GenericSignatureImpl::getGenericSignatureBuilder() const { - // The generic signature builder is associated with the canonical signature. - if (!isCanonical()) - return getCanonicalSignature()->getGenericSignatureBuilder(); - - // generic signature builders are stored on the ASTContext. - return getASTContext().getOrCreateGenericSignatureBuilder( - CanGenericSignature(this)); -} - rewriting::RequirementMachine * GenericSignatureImpl::getRequirementMachine() const { if (Machine) @@ -290,156 +277,8 @@ GenericSignature::LocalRequirements GenericSignatureImpl::getLocalRequirements(Type depType) const { assert(depType->isTypeParameter() && "Expected a type parameter here"); - auto computeViaGSB = [&]() { - GenericSignature::LocalRequirements result; - - auto &builder = *getGenericSignatureBuilder(); - - auto resolved = - builder.maybeResolveEquivalenceClass( - depType, - ArchetypeResolutionKind::CompleteWellFormed, - /*wantExactPotentialArchetype=*/false); - if (!resolved) { - result.concreteType = ErrorType::get(depType); - return result; - } - - if (auto concreteType = resolved.getAsConcreteType()) { - result.concreteType = concreteType; - return result; - } - - auto *equivClass = resolved.getEquivalenceClass(builder); - - auto genericParams = getGenericParams(); - result.anchor = equivClass->getAnchor(builder, genericParams); - - if (equivClass->concreteType) { - result.concreteType = equivClass->concreteType; - return result; - } - - result.superclass = equivClass->superclass; - - for (const auto &conforms : equivClass->conformsTo) { - auto proto = conforms.first; - - if (!equivClass->isConformanceSatisfiedBySuperclass(proto)) - result.protos.push_back(proto); - } - - result.layout = equivClass->layout; - - return result; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getLocalRequirements(depType, getGenericParams()); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - auto typesEqual = [&](Type lhs, Type rhs, bool canonical) { - if (!lhs || !rhs) - return !lhs == !rhs; - if (lhs->isEqual(rhs)) - return true; - - if (canonical) - return false; - - if (getCanonicalTypeInContext(lhs) == - getCanonicalTypeInContext(rhs)) - return true; - - return false; - }; - - auto compare = [&]() { - // If the types are concrete, we don't care about the rest. - if (gsbResult.concreteType || rqmResult.concreteType) { - if (!typesEqual(gsbResult.concreteType, - rqmResult.concreteType, - false)) - return false; - - return true; - } - - if (!typesEqual(gsbResult.anchor, - rqmResult.anchor, - true)) - return false; - - if (gsbResult.layout != rqmResult.layout) - return false; - - auto lhsProtos = gsbResult.protos; - ProtocolType::canonicalizeProtocols(lhsProtos); - auto rhsProtos = rqmResult.protos; - ProtocolType::canonicalizeProtocols(rhsProtos); - - if (lhsProtos != rhsProtos) - return false; - - if (!typesEqual(gsbResult.superclass, - rqmResult.superclass, - false)) - return false; - - return true; - }; - - auto dumpReqs = [&](const GenericSignature::LocalRequirements &reqs) { - if (reqs.anchor) { - llvm::errs() << "- Anchor: " << reqs.anchor << "\n"; - reqs.anchor.dump(llvm::errs()); - } - if (reqs.concreteType) { - llvm::errs() << "- Concrete type: " << reqs.concreteType << "\n"; - reqs.concreteType.dump(llvm::errs()); - } - if (reqs.superclass) { - llvm::errs() << "- Superclass: " << reqs.superclass << "\n"; - reqs.superclass.dump(llvm::errs()); - } - if (reqs.layout) { - llvm::errs() << "- Layout: " << reqs.layout << "\n"; - } - for (const auto *proto : reqs.protos) { - llvm::errs() << "- Conforms to: " << proto->getName() << "\n"; - } - }; - - if (!compare()) { - llvm::errs() << "RequirementMachine::getLocalRequirements() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; depType.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says:\n"; - dumpReqs(gsbResult); - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says:\n"; - dumpReqs(rqmResult); - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getLocalRequirements( + depType, getGenericParams()); } ASTContext &GenericSignatureImpl::getASTContext() const { @@ -467,54 +306,7 @@ bool GenericSignatureImpl::requiresClass(Type type) const { assert(type->isTypeParameter() && "Only type parameters can have superclass requirements"); - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return false; - - // If this type was mapped to a concrete type, then there is no - // requirement. - if (equivClass->concreteType) return false; - - // If there is a layout constraint, it might be a class. - if (equivClass->layout && equivClass->layout->isClass()) return true; - - return false; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->requiresClass(type); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::requiresClass() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->requiresClass(type); } /// Determine the superclass bound on the given dependent type. @@ -522,64 +314,8 @@ Type GenericSignatureImpl::getSuperclassBound(Type type) const { assert(type->isTypeParameter() && "Only type parameters can have superclass requirements"); - auto computeViaGSB = [&]() -> Type { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return nullptr; - - // If this type was mapped to a concrete type, then there is no - // requirement. - if (equivClass->concreteType) return nullptr; - - // Retrieve the superclass bound. - return equivClass->superclass; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getSuperclassBound(type, getGenericParams()); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - auto check = [&]() { - if (!gsbResult || !rqmResult) - return !gsbResult == !rqmResult; - return gsbResult->isEqual(rqmResult); - }; - - if (!check()) { - llvm::errs() << "RequirementMachine::getSuperclassBound() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - if (gsbResult) - gsbResult.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - if (rqmResult) - rqmResult.dump(llvm::errs()); - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getSuperclassBound( + type, getGenericParams()); } /// Determine the set of protocols to which the given type parameter is @@ -588,170 +324,21 @@ GenericSignature::RequiredProtocols GenericSignatureImpl::getRequiredProtocols(Type type) const { assert(type->isTypeParameter() && "Expected a type parameter"); - auto computeViaGSB = [&]() -> GenericSignature::RequiredProtocols { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return { }; - - // If this type parameter was mapped to a concrete type, then there - // are no requirements. - if (equivClass->concreteType) return { }; - - // Retrieve the protocols to which this type conforms. - GenericSignature::RequiredProtocols result; - for (const auto &conforms : equivClass->conformsTo) - result.push_back(conforms.first); - - // Canonicalize the resulting set of protocols. - ProtocolType::canonicalizeProtocols(result); - - return result; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getRequiredProtocols(type); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::getRequiredProtocols() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: "; - for (auto *otherProto : gsbResult) - llvm::errs() << " " << otherProto->getName(); - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says: "; - for (auto *otherProto : rqmResult) - llvm::errs() << " " << otherProto->getName(); - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getRequiredProtocols(type); } bool GenericSignatureImpl::requiresProtocol(Type type, ProtocolDecl *proto) const { assert(type->isTypeParameter() && "Expected a type parameter"); - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return false; - - // FIXME: Optionally deal with concrete conformances here - // or have a separate method do that additionally? - // - // If this type parameter was mapped to a concrete type, then there - // are no requirements. - if (equivClass->concreteType) return false; - - // Check whether the representative conforms to this protocol. - return equivClass->conformsTo.count(proto) > 0; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->requiresProtocol(type, proto); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::requiresProtocol() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "Protocol: "; proto->dumpRef(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->requiresProtocol(type, proto); } /// Determine whether the given dependent type is equal to a concrete type. bool GenericSignatureImpl::isConcreteType(Type type) const { assert(type->isTypeParameter() && "Expected a type parameter"); - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return false; - - return bool(equivClass->concreteType); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->isConcreteType(type); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::isConcreteType() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->isConcreteType(type); } /// Return the concrete type that the given type parameter is constrained to, @@ -760,111 +347,14 @@ bool GenericSignatureImpl::isConcreteType(Type type) const { Type GenericSignatureImpl::getConcreteType(Type type) const { assert(type->isTypeParameter() && "Expected a type parameter"); - auto computeViaGSB = [&]() -> Type { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return nullptr; - - return equivClass->concreteType; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getConcreteType(type, getGenericParams()); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - auto check = [&]() { - if (!gsbResult || !rqmResult) - return !gsbResult == !rqmResult; - if (gsbResult->isEqual(rqmResult)) - return true; - - return (getCanonicalTypeInContext(gsbResult) - == getCanonicalTypeInContext(rqmResult)); - }; - - if (!check()) { - llvm::errs() << "RequirementMachine::getConcreteType() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - if (gsbResult) - gsbResult.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - if (rqmResult) - rqmResult.dump(llvm::errs()); - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getConcreteType(type, getGenericParams()); } LayoutConstraint GenericSignatureImpl::getLayoutConstraint(Type type) const { assert(type->isTypeParameter() && "Only type parameters can have layout constraints"); - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - auto equivClass = - builder.resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return LayoutConstraint(); - - return equivClass->layout; - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getLayoutConstraint(type); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::getLayoutConstraint() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getLayoutConstraint(type); } bool GenericSignatureImpl::areSameTypeParameterInContext(Type type1, @@ -875,71 +365,7 @@ bool GenericSignatureImpl::areSameTypeParameterInContext(Type type1, if (type1.getPointer() == type2.getPointer()) return true; - auto computeViaGSB = [&]() { - return areSameTypeParameterInContext(type1, type2, - *getGenericSignatureBuilder()); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->areSameTypeParameterInContext(type1, type2); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - auto firstConcreteType = getConcreteType(type1); - auto secondConcreteType = getConcreteType(type2); - if (!firstConcreteType->isEqual(secondConcreteType)) { - llvm::errs() << "RequirementMachine::areSameTypeParameterInContext() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "First dependent type: "; type1.dump(llvm::errs()); - llvm::errs() << "Second dependent type: "; type2.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - } - - return rqmResult; - } - } -} - -bool GenericSignatureImpl::areSameTypeParameterInContext(Type type1, - Type type2, - GenericSignatureBuilder &builder) const { - assert(type1->isTypeParameter()); - assert(type2->isTypeParameter()); - - if (type1.getPointer() == type2.getPointer()) - return true; - - auto equivClass1 = - builder.resolveEquivalenceClass( - type1, - ArchetypeResolutionKind::CompleteWellFormed); - assert(equivClass1 && "not a valid dependent type of this signature?"); - - auto equivClass2 = - builder.resolveEquivalenceClass( - type2, - ArchetypeResolutionKind::CompleteWellFormed); - assert(equivClass2 && "not a valid dependent type of this signature?"); - - return equivClass1 == equivClass2; + return getRequirementMachine()->areSameTypeParameterInContext(type1, type2); } bool GenericSignatureImpl::isRequirementSatisfied( @@ -1016,70 +442,7 @@ bool GenericSignatureImpl::isCanonicalTypeInContext(Type type) const { if (!type->hasTypeParameter()) return true; - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - return isCanonicalTypeInContext(type, builder); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->isCanonicalTypeInContext(type); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::isCanonicalTypeInContext() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } -} - -bool GenericSignatureImpl::isCanonicalTypeInContext( - Type type, GenericSignatureBuilder &builder) const { - // If the type isn't independently canonical, it's certainly not canonical - // in this context. - if (!type->isCanonical()) - return false; - - // All the contextual canonicality rules apply to type parameters, so if the - // type doesn't involve any type parameters, it's already canonical. - if (!type->hasTypeParameter()) - return true; - - // Look for non-canonical type parameters. - return !type.findIf([&](Type component) -> bool { - if (!component->isTypeParameter()) return false; - - auto equivClass = - builder.resolveEquivalenceClass( - Type(component), - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) return false; - - return (equivClass->concreteType || - !component->isEqual(equivClass->getAnchor(builder, - getGenericParams()))); - }); + return getRequirementMachine()->isCanonicalTypeInContext(type); } CanType GenericSignature::getCanonicalTypeInContext(Type type) const { @@ -1099,44 +462,8 @@ CanType GenericSignatureImpl::getCanonicalTypeInContext(Type type) const { if (!type->hasTypeParameter()) return CanType(type); - auto computeViaGSB = [&]() { - auto &builder = *getGenericSignatureBuilder(); - return builder.getCanonicalTypeInContext(type, { })->getCanonicalType(); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getCanonicalTypeInContext(type, { })->getCanonicalType(); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::getCanonicalTypeInContext() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n"; - gsbResult.dump(llvm::errs()); - llvm::errs() << "RequirementMachine says: " << rqmResult << "\n"; - rqmResult.dump(llvm::errs()); - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getCanonicalTypeInContext( + type, { })->getCanonicalType(); } ArrayRef> @@ -1150,129 +477,14 @@ CanGenericSignature::getGenericParams() const { ConformanceAccessPath GenericSignatureImpl::getConformanceAccessPath(Type type, ProtocolDecl *protocol) const { - auto computeViaGSB = [&]() { - return getGenericSignatureBuilder()->getConformanceAccessPath( - type, protocol, this); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->getConformanceAccessPath(type, protocol); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - auto compare = [&]() { - if (gsbResult.size() != rqmResult.size()) - return false; - - auto *begin1 = gsbResult.begin(); - auto *end1 = gsbResult.end(); - auto *begin2 = rqmResult.begin(); - auto *end2 = rqmResult.end(); - - while (begin1 < end1) { - assert(begin2 < end2); - - if (!begin1->first->isEqual(begin2->first)) - return false; - if (begin1->second != begin2->second) - return false; - - ++begin1; - ++begin2; - } - - return true; - }; - - if (!compare()) { - llvm::errs() << "RequirementMachine::getConformanceAccessPath() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "Protocol: "; protocol->dumpRef(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "GenericSignatureBuilder says: "; - gsbResult.print(llvm::errs()); - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says: "; - rqmResult.print(llvm::errs()); - llvm::errs() << "\n\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->getConformanceAccessPath(type, protocol); } TypeDecl * GenericSignatureImpl::lookupNestedType(Type type, Identifier name) const { assert(type->isTypeParameter()); - auto computeViaGSB = [&]() -> TypeDecl * { - auto *builder = getGenericSignatureBuilder(); - auto equivClass = - builder->resolveEquivalenceClass( - type, - ArchetypeResolutionKind::CompleteWellFormed); - if (!equivClass) - return nullptr; - - return equivClass->lookupNestedType(*builder, name); - }; - - auto computeViaRQM = [&]() { - auto *machine = getRequirementMachine(); - return machine->lookupNestedType(type, name); - }; - - auto &ctx = getASTContext(); - switch (ctx.LangOpts.EnableRequirementMachine) { - case RequirementMachineMode::Disabled: - return computeViaGSB(); - - case RequirementMachineMode::Enabled: - return computeViaRQM(); - - case RequirementMachineMode::Verify: { - auto rqmResult = computeViaRQM(); - auto gsbResult = computeViaGSB(); - - if (gsbResult != rqmResult) { - llvm::errs() << "RequirementMachine::lookupNestedType() is broken\n"; - llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n"; - llvm::errs() << "Dependent type: "; type.dump(llvm::errs()); - llvm::errs() << "GenericSignatureBuilder says: "; - if (gsbResult) - gsbResult->dumpRef(llvm::errs()); - else - llvm::errs() << ""; - llvm::errs() << "\n"; - llvm::errs() << "RequirementMachine says: "; - if (rqmResult) - rqmResult->dumpRef(llvm::errs()); - else - llvm::errs() << ""; - llvm::errs() << "\n"; - getRequirementMachine()->dump(llvm::errs()); - abort(); - } - - return rqmResult; - } - } + return getRequirementMachine()->lookupNestedType(type, name); } unsigned GenericParamKey::findIndexIn( diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index 113f0eb15cab7..f223f310a0e61 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -703,12 +703,6 @@ struct GenericSignatureBuilder::Implementation { llvm::DenseSet ExplicitConformancesImpliedByConcrete; - llvm::DenseMap, - ConformanceAccessPath> ConformanceAccessPaths; - - std::vector> - CurrentConformanceAccessPaths; - #ifndef NDEBUG /// Whether we've already computed redundant requiremnts. bool computedRedundantRequirements = false; @@ -3776,127 +3770,6 @@ Type GenericSignatureBuilder::getCanonicalTypeInContext(Type type, }); } -ConformanceAccessPath -GenericSignatureBuilder::getConformanceAccessPath(Type type, - ProtocolDecl *protocol, - GenericSignature sig) { - auto canType = getCanonicalTypeInContext(type, { })->getCanonicalType(); - assert(canType->isTypeParameter()); - - // Check if we've already cached the result before doing anything else. - auto found = Impl->ConformanceAccessPaths.find( - std::make_pair(canType, protocol)); - if (found != Impl->ConformanceAccessPaths.end()) { - return found->second; - } - - auto *Stats = Context.Stats; - - FrontendStatsTracer tracer(Stats, "get-conformance-access-path"); - - auto recordPath = [&](CanType type, ProtocolDecl *proto, - ConformanceAccessPath path) { - // Add the path to the buffer. - Impl->CurrentConformanceAccessPaths.emplace_back(type, path); - - // Add the path to the map. - auto key = std::make_pair(type, proto); - auto inserted = Impl->ConformanceAccessPaths.insert( - std::make_pair(key, path)); - assert(inserted.second); - (void) inserted; - - if (Stats) - ++Stats->getFrontendCounters().NumConformanceAccessPathsRecorded; - }; - - // If this is the first time we're asked to look up a conformance access path, - // visit all of the root conformance requirements in our generic signature and - // add them to the buffer. - if (Impl->ConformanceAccessPaths.empty()) { - for (const auto &req : sig.getRequirements()) { - // We only care about conformance requirements. - if (req.getKind() != RequirementKind::Conformance) - continue; - - auto rootType = req.getFirstType()->getCanonicalType(); - auto *rootProto = req.getProtocolDecl(); - - ConformanceAccessPath::Entry root(rootType, rootProto); - ArrayRef path(root); - ConformanceAccessPath result(Context.AllocateCopy(path)); - - recordPath(rootType, rootProto, result); - } - } - - // We enumerate conformance access paths in lexshort order until we find the - // path whose corresponding type canonicalizes to the one we are looking for. - while (true) { - auto found = Impl->ConformanceAccessPaths.find( - std::make_pair(canType, protocol)); - if (found != Impl->ConformanceAccessPaths.end()) { - return found->second; - } - - assert(Impl->CurrentConformanceAccessPaths.size() > 0); - - // The buffer consists of all conformance access paths of length N. - // Swap it out with an empty buffer, and fill it with all paths of - // length N+1. - std::vector> oldPaths; - std::swap(Impl->CurrentConformanceAccessPaths, oldPaths); - - for (const auto &pair : oldPaths) { - const auto &lastElt = pair.second.back(); - auto *lastProto = lastElt.second; - - // A copy of the current path, populated as needed. - SmallVector entries; - - for (const auto &req : lastProto->getRequirementSignature()) { - // We only care about conformance requirements. - if (req.getKind() != RequirementKind::Conformance) - continue; - - auto nextSubjectType = req.getFirstType()->getCanonicalType(); - auto *nextProto = req.getProtocolDecl(); - - // Compute the canonical anchor for this conformance requirement. - auto nextType = replaceSelfWithType(pair.first, nextSubjectType); - auto nextCanType = getCanonicalTypeInContext(nextType, { }) - ->getCanonicalType(); - - // Skip "derived via concrete" sources. - if (!nextCanType->isTypeParameter()) - continue; - - // If we've already seen a path for this conformance, skip it and - // don't add it to the buffer. Note that because we iterate over - // conformance access paths in lexshort order, the existing - // conformance access path is shorter than the one we found just now. - if (Impl->ConformanceAccessPaths.count( - std::make_pair(nextCanType, nextProto))) - continue; - - if (entries.empty()) { - // Fill our temporary vector. - entries.insert(entries.begin(), - pair.second.begin(), - pair.second.end()); - } - - // Add the next entry. - entries.emplace_back(nextSubjectType, nextProto); - ConformanceAccessPath result = Context.AllocateCopy(entries); - entries.pop_back(); - - recordPath(nextCanType, nextProto, result); - } - } - } -} - TypeArrayView GenericSignatureBuilder::getGenericParams() const { return TypeArrayView(Impl->GenericParams); @@ -8322,20 +8195,6 @@ GenericSignature GenericSignatureBuilder::computeGenericSignature( bool hadAnyError = Impl->HadAnyError; - // When we can, move this generic signature builder to make it the canonical - // builder, rather than constructing a new generic signature builder that - // will produce the same thing. - // - // We cannot do this when there were errors. - // - // Also, we cannot do this when building a requirement signature. - if (requirementSignatureSelfProto == nullptr && - !hadAnyError) { - // Register this generic signature builder as the canonical builder for the - // given signature. - Context.registerGenericSignatureBuilder(sig, std::move(*this)); - } - // Wipe out the internal state, ensuring that nobody uses this builder for // anything more. Impl.reset(); diff --git a/lib/AST/GenericSignatureBuilder.h b/lib/AST/GenericSignatureBuilder.h index ed62e018daff2..42637986165e8 100644 --- a/lib/AST/GenericSignatureBuilder.h +++ b/lib/AST/GenericSignatureBuilder.h @@ -788,22 +788,6 @@ class GenericSignatureBuilder { Type getCanonicalTypeInContext(Type type, TypeArrayView genericParams); - /// Retrieve the conformance access path used to extract the conformance of - /// interface \c type to the given \c protocol. - /// - /// \param type The interface type whose conformance access path is to be - /// queried. - /// \param protocol A protocol to which \c type conforms. - /// - /// \returns the conformance access path that starts at a requirement of - /// this generic signature and ends at the conformance that makes \c type - /// conform to \c protocol. - /// - /// \seealso ConformanceAccessPath - ConformanceAccessPath getConformanceAccessPath(Type type, - ProtocolDecl *protocol, - GenericSignature sig); - /// Dump all of the requirements, both specified and inferred. It cannot be /// statically proven that this doesn't modify the GSB. SWIFT_DEBUG_HELPER(void dump()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 86843f4ec20ff..7b27efdac2d79 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -854,20 +854,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.DisableSubstSILFunctionTypes = Args.hasArg(OPT_disable_subst_sil_function_types); - if (auto A = Args.getLastArg(OPT_requirement_machine_EQ)) { - auto value = llvm::StringSwitch>(A->getValue()) - .Case("off", RequirementMachineMode::Disabled) - .Case("on", RequirementMachineMode::Enabled) - .Case("verify", RequirementMachineMode::Verify) - .Default(None); - - if (value) - Opts.EnableRequirementMachine = *value; - else - Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, - A->getAsString(Args), A->getValue()); - } - if (auto A = Args.getLastArg(OPT_requirement_machine_protocol_signatures_EQ)) { auto value = llvm::StringSwitch>(A->getValue()) .Case("off", RequirementMachineMode::Disabled) diff --git a/test/Generics/ambiguous_protocol_inheritance.swift b/test/Generics/ambiguous_protocol_inheritance.swift index 47aff4d32d264..91ecc5062be7e 100644 --- a/test/Generics/ambiguous_protocol_inheritance.swift +++ b/test/Generics/ambiguous_protocol_inheritance.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify +// RUN: %target-typecheck-verify-swift protocol Base { // expected-note {{'Base' previously declared here}} // expected-note@-1 {{found this candidate}} diff --git a/test/Generics/associated_type_order.swift b/test/Generics/associated_type_order.swift index 50eebf6d21d85..da0a61474ac03 100644 --- a/test/Generics/associated_type_order.swift +++ b/test/Generics/associated_type_order.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s +// RUN: %target-swift-emit-silgen %s | %FileCheck %s protocol P1 { associatedtype B diff --git a/test/Generics/concrete_type_property_of_suffix.swift b/test/Generics/concrete_type_property_of_suffix.swift index c080298060b79..a66efbf257792 100644 --- a/test/Generics/concrete_type_property_of_suffix.swift +++ b/test/Generics/concrete_type_property_of_suffix.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify +// RUN: %target-typecheck-verify-swift protocol P { associatedtype T where T == U? diff --git a/test/Generics/conditional_requirement_inference.swift b/test/Generics/conditional_requirement_inference.swift index 9dc517e386e1f..8de9c97bfadca 100644 --- a/test/Generics/conditional_requirement_inference.swift +++ b/test/Generics/conditional_requirement_inference.swift @@ -1,5 +1,5 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=on -// RUN: not %target-swift-frontend -typecheck -debug-generic-signatures -requirement-machine=on %s 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift +// RUN: not %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s // Valid example @@ -55,4 +55,4 @@ func mergeP1AndP2(_: T) { takesP(T.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.T' conform to 'P'}} takesP(T.R.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.R.T' conform to 'P'}} takesP(T.R.R.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.R.R.T' conform to 'P'}} -} \ No newline at end of file +} diff --git a/test/Generics/generic_objc_superclass.swift b/test/Generics/generic_objc_superclass.swift index 98e658b52a87c..802d2c1ae7baf 100644 --- a/test/Generics/generic_objc_superclass.swift +++ b/test/Generics/generic_objc_superclass.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift %clang-importer-sdk -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift %clang-importer-sdk -dump-requirement-machine 2>&1 | %FileCheck %s // REQUIRES: objc_interop diff --git a/test/Generics/gsb_canonical_type_bug_1.swift b/test/Generics/gsb_canonical_type_bug_1.swift index 792f582db4fdc..58b03e6c35526 100644 --- a/test/Generics/gsb_canonical_type_bug_1.swift +++ b/test/Generics/gsb_canonical_type_bug_1.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s +// RUN: %target-swift-emit-silgen %s | %FileCheck %s // The GSB computes an incorrect canonical type here, which caused a SILGen assert. diff --git a/test/Generics/gsb_canonical_type_bug_2.swift b/test/Generics/gsb_canonical_type_bug_2.swift index 810743c1022f4..37a4a7ec4b71b 100644 --- a/test/Generics/gsb_canonical_type_bug_2.swift +++ b/test/Generics/gsb_canonical_type_bug_2.swift @@ -1,6 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s -// RUN: %target-swift-emit-silgen %s -requirement-machine=off | %FileCheck %s --check-prefix=CHECK-GSB -// RUN: not --crash %target-swift-emit-silgen %s -requirement-machine=verify +// RUN: %target-swift-emit-silgen %s | %FileCheck %s protocol P1 { associatedtype A @@ -23,4 +21,3 @@ extension P2 { } // CHECK-LABEL: sil hidden [ossa] @$s24gsb_canonical_type_bug_22P2PAAE3fooyyqd___1AQztAA2P1Rd__AA2P3Rd__1BAaHPQyd__Rsd__AeaGPQyd__AFRSlF : $@convention(method) (@in_guaranteed T, @in_guaranteed Self.A, @in_guaranteed Self) -> () -// CHECK-GSB-LABEL: sil hidden [ossa] @$s24gsb_canonical_type_bug_22P2PAAE3fooyyqd___1AAA2P1PQyd__tAaFRd__AA2P3Rd__1BAaIPQyd__Rsd__AhERtzlF : $@convention(method) (@in_guaranteed T, @in_guaranteed T.A, @in_guaranteed Self) -> () diff --git a/test/Generics/gsb_canonical_type_bug_3.swift b/test/Generics/gsb_canonical_type_bug_3.swift index 200f428f20d3a..b4e3220f442ae 100644 --- a/test/Generics/gsb_canonical_type_bug_3.swift +++ b/test/Generics/gsb_canonical_type_bug_3.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=on | %FileCheck %s +// RUN: %target-swift-emit-silgen %s | %FileCheck %s // The GSB computes an incorrect canonical type for bar() which causes // SILGen to assert. diff --git a/test/Generics/member_type_of_superclass_bound.swift b/test/Generics/member_type_of_superclass_bound.swift index 881faf2ab9bf4..3d482dd5a8d4d 100644 --- a/test/Generics/member_type_of_superclass_bound.swift +++ b/test/Generics/member_type_of_superclass_bound.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=verify +// RUN: %target-swift-emit-silgen %s // The substituted type of SS.x.x is computed by taking the type of S.x, // which is T.T in the generic signature , and then diff --git a/test/Generics/rdar79564324.swift b/test/Generics/rdar79564324.swift index c865bc2f5387d..7d7869a10b312 100644 --- a/test/Generics/rdar79564324.swift +++ b/test/Generics/rdar79564324.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend -emit-module %S/Inputs/rdar79564324_other.swift -emit-module-path %t/rdar79564324_other.swiftmodule -requirement-machine=on -dump-requirement-machine 2>&1 | %FileCheck %s -// RUN: %target-swift-frontend -emit-silgen %s -I %t -requirement-machine=on +// RUN: %target-swift-frontend -emit-module %S/Inputs/rdar79564324_other.swift -emit-module-path %t/rdar79564324_other.swiftmodule -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-swift-frontend -emit-silgen %s -I %t import rdar79564324_other diff --git a/test/Generics/recursive_conformances.swift b/test/Generics/recursive_conformances.swift index 391343baa48c4..9f527d53aed1c 100644 --- a/test/Generics/recursive_conformances.swift +++ b/test/Generics/recursive_conformances.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify +// RUN: %target-typecheck-verify-swift // Make sure the requirement machine can compute a confluent // completion in examples where we merge two associated types diff --git a/test/Generics/unify_associated_types.swift b/test/Generics/unify_associated_types.swift index 029ae439d7aaa..b3f37ac4eb179 100644 --- a/test/Generics/unify_associated_types.swift +++ b/test/Generics/unify_associated_types.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s struct Foo {} diff --git a/test/Generics/unify_concrete_types_1.swift b/test/Generics/unify_concrete_types_1.swift index 031c76fa33de7..a0c7335516bbe 100644 --- a/test/Generics/unify_concrete_types_1.swift +++ b/test/Generics/unify_concrete_types_1.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s struct Foo {} diff --git a/test/Generics/unify_concrete_types_2.swift b/test/Generics/unify_concrete_types_2.swift index ce406e844ff71..05c30771ff361 100644 --- a/test/Generics/unify_concrete_types_2.swift +++ b/test/Generics/unify_concrete_types_2.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s struct Foo {} diff --git a/test/Generics/unify_nested_types_1.swift b/test/Generics/unify_nested_types_1.swift index cd0ed49e5c7b4..b0fdcf861182d 100644 --- a/test/Generics/unify_nested_types_1.swift +++ b/test/Generics/unify_nested_types_1.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s protocol P1 { associatedtype T : P1 diff --git a/test/Generics/unify_nested_types_2.swift b/test/Generics/unify_nested_types_2.swift index 82704e88f0509..bac29a539b3fb 100644 --- a/test/Generics/unify_nested_types_2.swift +++ b/test/Generics/unify_nested_types_2.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s protocol P1 { associatedtype T : P1 diff --git a/test/Generics/unify_nested_types_3.swift b/test/Generics/unify_nested_types_3.swift index 0d6227327aea8..437c491a64028 100644 --- a/test/Generics/unify_nested_types_3.swift +++ b/test/Generics/unify_nested_types_3.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s protocol P1 { associatedtype T : P1 diff --git a/test/Generics/unify_nested_types_4.swift b/test/Generics/unify_nested_types_4.swift index 4e9be83392996..e04241a2faced 100644 --- a/test/Generics/unify_nested_types_4.swift +++ b/test/Generics/unify_nested_types_4.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s protocol P1 { associatedtype A : P1 diff --git a/test/Generics/unify_nested_types_5.swift b/test/Generics/unify_nested_types_5.swift index 1325e3e3bc642..d192849609382 100644 --- a/test/Generics/unify_nested_types_5.swift +++ b/test/Generics/unify_nested_types_5.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify +// RUN: %target-typecheck-verify-swift protocol P { associatedtype A : P diff --git a/test/Generics/unify_superclass_types_1.swift b/test/Generics/unify_superclass_types_1.swift index b54730731e3c3..fa454984dd8e5 100644 --- a/test/Generics/unify_superclass_types_1.swift +++ b/test/Generics/unify_superclass_types_1.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=verify -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s class Base {} class Derived : Base { diff --git a/test/Generics/unify_superclass_types_2.swift b/test/Generics/unify_superclass_types_2.swift index 0f04ee922f748..7f872d1c0f41d 100644 --- a/test/Generics/unify_superclass_types_2.swift +++ b/test/Generics/unify_superclass_types_2.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=on -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s // Note: The GSB fails this test, because it doesn't implement unification of // superclass type constructor arguments. diff --git a/test/Generics/unify_superclass_types_3.swift b/test/Generics/unify_superclass_types_3.swift index 4b5fa3e05930c..d3bcadcbd1c82 100644 --- a/test/Generics/unify_superclass_types_3.swift +++ b/test/Generics/unify_superclass_types_3.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=on -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s // Note: The GSB fails this test, because it doesn't implement unification of // superclass type constructor arguments. diff --git a/test/Generics/unify_superclass_types_4.swift b/test/Generics/unify_superclass_types_4.swift index 7494a807e777b..75f257ff08c5c 100644 --- a/test/Generics/unify_superclass_types_4.swift +++ b/test/Generics/unify_superclass_types_4.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -requirement-machine=on -dump-requirement-machine 2>&1 | %FileCheck %s +// RUN: %target-typecheck-verify-swift -dump-requirement-machine 2>&1 | %FileCheck %s // Note: The GSB fails this test, because it doesn't implement unification of // superclass type constructor arguments. diff --git a/test/IRGen/retroactive_conformance_path.swift b/test/IRGen/retroactive_conformance_path.swift index 1fc7f0bd223b2..3c596cc1f08a5 100644 --- a/test/IRGen/retroactive_conformance_path.swift +++ b/test/IRGen/retroactive_conformance_path.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-build-swift -module-name=test %s -o %t/a.out -requirement-machine=verify +// RUN: %target-build-swift -module-name=test %s -o %t/a.out // RUN: %target-run %t/a.out | %FileCheck %s // REQUIRES: executable_test // REQUIRES: CPU=arm64 || CPU=x86_64 diff --git a/test/IRGen/retroactive_conformance_path_2.swift b/test/IRGen/retroactive_conformance_path_2.swift index 44ef7f846278f..9fb81bf680345 100644 --- a/test/IRGen/retroactive_conformance_path_2.swift +++ b/test/IRGen/retroactive_conformance_path_2.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir -g -primary-file %s -requirement-machine=verify +// RUN: %target-swift-frontend -emit-ir -g -primary-file %s public struct TestType { } diff --git a/test/SILGen/mangle_conformance_access_path.swift b/test/SILGen/mangle_conformance_access_path.swift index d8168f9c641a5..2945ed8f55f38 100644 --- a/test/SILGen/mangle_conformance_access_path.swift +++ b/test/SILGen/mangle_conformance_access_path.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) // RUN: %target-swift-frontend -emit-module %S/Inputs/mangle_conformance_access_path_helper.swift -emit-module-path %t/mangle_conformance_access_path_helper.swiftmodule -// RUN: %target-swift-frontend -emit-silgen %s -I %t -requirement-machine=verify | %FileCheck %s +// RUN: %target-swift-frontend -emit-silgen %s -I %t | %FileCheck %s import mangle_conformance_access_path_helper diff --git a/test/SILGen/sil_verifier_method_self_type.swift b/test/SILGen/sil_verifier_method_self_type.swift index 173302307edb0..526c37fbcfbc1 100644 --- a/test/SILGen/sil_verifier_method_self_type.swift +++ b/test/SILGen/sil_verifier_method_self_type.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=verify +// RUN: %target-swift-emit-silgen %s public class C { public func method() -> Value { fatalError() } diff --git a/test/SILGen/type_lowering_subst_function_type_conditional_conformance.swift b/test/SILGen/type_lowering_subst_function_type_conditional_conformance.swift index 9f96871a95689..89ca825b02fbb 100644 --- a/test/SILGen/type_lowering_subst_function_type_conditional_conformance.swift +++ b/test/SILGen/type_lowering_subst_function_type_conditional_conformance.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -requirement-machine=verify | %FileCheck %s +// RUN: %target-swift-emit-silgen %s | %FileCheck %s enum E { case a(T.X) diff --git a/test/attr/attr_override.swift b/test/attr/attr_override.swift index cec2a90967ee9..d57e0538b8046 100644 --- a/test/attr/attr_override.swift +++ b/test/attr/attr_override.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -swift-version 5 -requirement-machine=verify +// RUN: %target-typecheck-verify-swift -swift-version 5 @override // expected-error {{'override' can only be specified on class members}} {{1-11=}} expected-error {{'override' is a declaration modifier, not an attribute}} {{1-2=}} func virtualAttributeCanNotBeUsedInSource() {} diff --git a/tools/sil-opt/SILOpt.cpp b/tools/sil-opt/SILOpt.cpp index 40754d11b4c15..302024875c1c5 100644 --- a/tools/sil-opt/SILOpt.cpp +++ b/tools/sil-opt/SILOpt.cpp @@ -458,11 +458,6 @@ static llvm::cl::opt llvm::cl::desc("Ignore [always_inline] attribute."), llvm::cl::init(false)); -static llvm::cl::opt EnableRequirementMachine( - "requirement-machine", - llvm::cl::desc("Control usage of experimental generics implementation: " - "'on', 'off', or 'verify'.")); - static void runCommandLineSelectedPasses(SILModule *Module, irgen::IRGenModule *IRGenMod) { const SILOptions &opts = Module->getOptions(); @@ -582,23 +577,6 @@ int main(int argc, char **argv) { Invocation.getDiagnosticOptions().VerifyMode = VerifyMode ? DiagnosticOptions::Verify : DiagnosticOptions::NoVerify; - if (EnableRequirementMachine.size()) { - auto value = llvm::StringSwitch>( - EnableRequirementMachine) - .Case("off", RequirementMachineMode::Disabled) - .Case("on", RequirementMachineMode::Enabled) - .Case("verify", RequirementMachineMode::Verify) - .Default(None); - - if (value) - Invocation.getLangOptions().EnableRequirementMachine = *value; - else { - fprintf(stderr, "Invalid value for -requirement-machine flag: %s\n", - EnableRequirementMachine.c_str()); - exit(-1); - } - } - // Setup the SIL Options. SILOptions &SILOpts = Invocation.getSILOptions(); SILOpts.InlineThreshold = SILInlineThreshold; diff --git a/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift b/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift index be4fda9ff0e61..ac1e3b214aeb9 100644 --- a/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift +++ b/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift @@ -1,6 +1,7 @@ -// RUN: %target-swift-frontend %s -emit-silgen -requirement-machine=off +// RUN: %target-swift-frontend %s -emit-silgen // rdar://80395274 tracks getting this to pass with the requirement machine. +// XFAIL: * import StdlibUnittest