diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index bc1a5592498bc..dc50d0178416d 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -918,6 +918,10 @@ class ASTContext final { /// needed to place array buffers into constant data sections. AvailabilityContext getImmortalRefCountSymbolsAvailability(); + /// Get the runtime availability of runtime functions for + /// variadic generic types. + AvailabilityContext getVariadicGenericTypeAvailability(); + /// Get the runtime availability of features introduced in the Swift 5.2 /// compiler for the target platform. AvailabilityContext getSwift52Availability(); diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 690f126a28e18..4ec0e2540a0ec 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -2160,10 +2160,10 @@ NOTE(decl_import_via_here,none, // Opaque return types ERROR(opaque_type_invalid_constraint,none, - "an 'opaque' type must specify only 'Any', 'AnyObject', protocols, " + "a 'some' type must specify only 'Any', 'AnyObject', protocols, " "and/or a base class", ()) NOTE(opaque_of_optional_rewrite,none, - "did you mean to write an optional of an 'opaque' type?", ()) + "did you mean to write an optional of an 'some' type?", ()) ERROR(inferred_opaque_type,none, "property definition has inferred type %0, involving the 'some' " "return type of another declaration", (Type)) @@ -6143,6 +6143,10 @@ ERROR(availability_parameterized_protocol_only_version_newer, none, "%0 %1 or newer", (StringRef, llvm::VersionTuple)) +ERROR(availability_variadic_type_only_version_newer, none, + "parameter packs in generic types are only available in %0 %1 or newer", + (StringRef, llvm::VersionTuple)) + NOTE(availability_guard_with_version_check, none, "add 'if #available' version check", ()) diff --git a/include/swift/Frontend/BackDeploymentLibs.def b/include/swift/Frontend/BackDeploymentLibs.def index 9f12ae773e7dc..9f3063d1c36c5 100644 --- a/include/swift/Frontend/BackDeploymentLibs.def +++ b/include/swift/Frontend/BackDeploymentLibs.def @@ -21,13 +21,14 @@ //===----------------------------------------------------------------------===// #ifndef BACK_DEPLOYMENT_LIB -# error "Must define BACK_DEPLOYMENT_LIB(Version, Filter, Library)" +# error "Must define BACK_DEPLOYMENT_LIB(Version, Filter, Library, ForceLoad)" #endif -BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50") -BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51") -BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements") -BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency") -BACK_DEPLOYMENT_LIB((5, 6), all, "swiftCompatibility56") +BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50", true) +BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51", true) +BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements", true) +BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency", true) +BACK_DEPLOYMENT_LIB((5, 6), all, "swiftCompatibility56", true) +BACK_DEPLOYMENT_LIB((5, 8), all, "swiftCompatibilityPacks", false) #undef BACK_DEPLOYMENT_LIB diff --git a/lib/AST/Availability.cpp b/lib/AST/Availability.cpp index 9225a67059deb..8a58c87f4ee26 100644 --- a/lib/AST/Availability.cpp +++ b/lib/AST/Availability.cpp @@ -517,6 +517,11 @@ ASTContext::getImmortalRefCountSymbolsAvailability() { return getSwiftFutureAvailability(); } +AvailabilityContext +ASTContext::getVariadicGenericTypeAvailability() { + return getSwift59Availability(); +} + AvailabilityContext ASTContext::getSwift52Availability() { auto target = LangOpts.Target; diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 1503fe0246cee..5e744db3a85e3 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -23,8 +23,8 @@ using namespace swift; /// Print information about a static void printCompatibilityLibrary( llvm::VersionTuple runtimeVersion, llvm::VersionTuple maxVersion, - StringRef filter, StringRef libraryName, bool &printedAny, - llvm::raw_ostream &out) { + StringRef filter, StringRef libraryName, bool forceLoad, + bool &printedAny, llvm::raw_ostream &out) { if (runtimeVersion > maxVersion) return; @@ -33,16 +33,21 @@ static void printCompatibilityLibrary( } out << "\n"; - out << " {\n"; + out << " {"; - out << " \"libraryName\": \""; + out << "\n \"libraryName\": \""; swift::writeEscaped(libraryName, out); - out << "\",\n"; + out << "\","; - out << " \"filter\": \""; + out << "\n \"filter\": \""; swift::writeEscaped(filter, out); - out << "\"\n"; - out << " }"; + out << "\""; + + if (!forceLoad) { + out << ",\n \"forceLoad\": false"; + } + + out << "\n }"; printedAny = true; } @@ -132,10 +137,10 @@ void targetinfo::printTripleInfo(const llvm::Triple &triple, // Compatibility libraries that need to be linked. out << " \"compatibilityLibraries\": ["; bool printedAnyCompatibilityLibrary = false; - #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName) \ - printCompatibilityLibrary( \ + #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \ + printCompatibilityLibrary( \ *runtimeVersion, llvm::VersionTuple Version, #Filter, LibraryName, \ - printedAnyCompatibilityLibrary, out); + ForceLoad, printedAnyCompatibilityLibrary, out); #include "swift/Frontend/BackDeploymentLibs.def" if (printedAnyCompatibilityLibrary) { diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index f3969819de929..f796fdaf42b60 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -406,6 +406,8 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, runtimeCompatibilityVersion = llvm::VersionTuple(5, 5); } else if (value.equals("5.6")) { runtimeCompatibilityVersion = llvm::VersionTuple(5, 6); + } else if (value.equals("5.8")) { + runtimeCompatibilityVersion = llvm::VersionTuple(5, 8); } else if (value.equals("none")) { runtimeCompatibilityVersion = None; } else { @@ -419,7 +421,8 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, if (runtimeCompatibilityVersion) { auto addBackDeployLib = [&](llvm::VersionTuple version, BackDeployLibFilter filter, - StringRef libraryName) { + StringRef libraryName, + bool forceLoad) { if (*runtimeCompatibilityVersion > version) return; @@ -431,14 +434,16 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, llvm::sys::path::append(BackDeployLib, "lib" + libraryName + ".a"); if (llvm::sys::fs::exists(BackDeployLib)) { - Arguments.push_back("-force_load"); + if (forceLoad) + Arguments.push_back("-force_load"); Arguments.push_back(context.Args.MakeArgString(BackDeployLib)); } }; - #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName) \ - addBackDeployLib( \ - llvm::VersionTuple Version, BackDeployLibFilter::Filter, LibraryName); + #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \ + addBackDeployLib( \ + llvm::VersionTuple Version, BackDeployLibFilter::Filter, \ + LibraryName, ForceLoad); #include "swift/Frontend/BackDeploymentLibs.def" } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index efb36aa088bef..d132e8d258872 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2563,6 +2563,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, runtimeCompatibilityVersion = llvm::VersionTuple(5, 5); } else if (version.equals("5.6")) { runtimeCompatibilityVersion = llvm::VersionTuple(5, 6); + } else if (version.equals("5.8")) { + runtimeCompatibilityVersion = llvm::VersionTuple(5, 8); } else { Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, versionArg->getAsString(Args), version); diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index bb0ba4ca92a40..2417e72ebb413 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -511,7 +511,8 @@ void IRGenModule::emitSourceFile(SourceFile &SF) { // harmless aside from code size. if (!IRGen.Opts.UseJIT) { auto addBackDeployLib = [&](llvm::VersionTuple version, - StringRef libraryName) { + StringRef libraryName, + bool forceLoad) { Optional compatibilityVersion; if (libraryName == "swiftCompatibilityDynamicReplacements") { compatibilityVersion = IRGen.Opts. @@ -532,11 +533,11 @@ void IRGenModule::emitSourceFile(SourceFile &SF) { this->addLinkLibrary(LinkLibrary(libraryName, LibraryKind::Library, - /*forceLoad*/ true)); + forceLoad)); }; - #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName) \ - addBackDeployLib(llvm::VersionTuple Version, LibraryName); + #define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \ + addBackDeployLib(llvm::VersionTuple Version, LibraryName, ForceLoad); #include "swift/Frontend/BackDeploymentLibs.def" } } diff --git a/lib/Sema/TypeCheckAvailability.cpp b/lib/Sema/TypeCheckAvailability.cpp index 83cea139c6305..a0283ee2ddc24 100644 --- a/lib/Sema/TypeCheckAvailability.cpp +++ b/lib/Sema/TypeCheckAvailability.cpp @@ -2008,8 +2008,9 @@ static void fixAvailability(SourceRange ReferenceRange, } } -void TypeChecker::diagnosePotentialOpaqueTypeUnavailability( - SourceRange ReferenceRange, const DeclContext *ReferenceDC, +void TypeChecker::diagnosePotentialUnavailability( + SourceRange ReferenceRange, Diag Diag, + const DeclContext *ReferenceDC, const UnavailabilityReason &Reason) { ASTContext &Context = ReferenceDC->getASTContext(); @@ -2017,61 +2018,49 @@ void TypeChecker::diagnosePotentialOpaqueTypeUnavailability( { auto Err = Context.Diags.diagnose( - ReferenceRange.Start, diag::availability_opaque_types_only_version_newer, + ReferenceRange.Start, Diag, prettyPlatformString(targetPlatform(Context.LangOpts)), Reason.getRequiredOSVersionRange().getLowerEndpoint()); // Direct a fixit to the error if an existing guard is nearly-correct - if (fixAvailabilityByNarrowingNearbyVersionCheck(ReferenceRange, - ReferenceDC, - RequiredRange, Context, Err)) - return; - } - fixAvailability(ReferenceRange, ReferenceDC, RequiredRange, Context); -} - -static void diagnosePotentialConcurrencyUnavailability( - SourceRange ReferenceRange, const DeclContext *ReferenceDC, - const UnavailabilityReason &Reason) { - ASTContext &Context = ReferenceDC->getASTContext(); - - auto RequiredRange = Reason.getRequiredOSVersionRange(); - { - auto Err = - Context.Diags.diagnose( - ReferenceRange.Start, - diag::availability_concurrency_only_version_newer, - prettyPlatformString(targetPlatform(Context.LangOpts)), - Reason.getRequiredOSVersionRange().getLowerEndpoint()); - - // Direct a fixit to the error if an existing guard is nearly-correct - if (fixAvailabilityByNarrowingNearbyVersionCheck(ReferenceRange, - ReferenceDC, - RequiredRange, Context, Err)) + if (fixAvailabilityByNarrowingNearbyVersionCheck( + ReferenceRange, ReferenceDC, RequiredRange, Context, Err)) return; } fixAvailability(ReferenceRange, ReferenceDC, RequiredRange, Context); } -void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange, - const DeclContext *ReferenceDC) { - // Check the availability of concurrency runtime support. +bool TypeChecker::checkAvailability(SourceRange ReferenceRange, + AvailabilityContext Availability, + Diag Diag, + const DeclContext *ReferenceDC) { ASTContext &ctx = ReferenceDC->getASTContext(); if (ctx.LangOpts.DisableAvailabilityChecking) - return; + return false; if (!shouldCheckAvailability(ReferenceDC->getAsDecl())) - return; + return false; auto runningOS = TypeChecker::overApproximateAvailabilityAtLocation( ReferenceRange.Start, ReferenceDC); - auto availability = ctx.getBackDeployedConcurrencyAvailability(); - if (!runningOS.isContainedIn(availability)) { - diagnosePotentialConcurrencyUnavailability( - ReferenceRange, ReferenceDC, - UnavailabilityReason::requiresVersionRange(availability.getOSVersion())); + if (!runningOS.isContainedIn(Availability)) { + diagnosePotentialUnavailability( + ReferenceRange, Diag, ReferenceDC, + UnavailabilityReason::requiresVersionRange(Availability.getOSVersion())); + return true; } + + return false; +} + +void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange, + const DeclContext *ReferenceDC) { + checkAvailability( + ReferenceRange, + ReferenceDC->getASTContext().getBackDeployedConcurrencyAvailability(), + diag::availability_concurrency_only_version_newer, + ReferenceDC); } /// Returns the diagnostic to emit for the potentially unavailable decl and sets @@ -3002,48 +2991,13 @@ bool isSubscriptReturningString(const ValueDecl *D, ASTContext &Context) { return resultTy->isString(); } -static bool diagnosePotentialParameterizedProtocolUnavailability( - SourceRange ReferenceRange, const DeclContext *ReferenceDC, - const UnavailabilityReason &Reason) { - ASTContext &Context = ReferenceDC->getASTContext(); - - auto RequiredRange = Reason.getRequiredOSVersionRange(); - { - auto Err = Context.Diags.diagnose( - ReferenceRange.Start, - diag::availability_parameterized_protocol_only_version_newer, - prettyPlatformString(targetPlatform(Context.LangOpts)), - Reason.getRequiredOSVersionRange().getLowerEndpoint()); - - // Direct a fixit to the error if an existing guard is nearly-correct - if (fixAvailabilityByNarrowingNearbyVersionCheck( - ReferenceRange, ReferenceDC, RequiredRange, Context, Err)) - return true; - } - fixAvailability(ReferenceRange, ReferenceDC, RequiredRange, Context); - return true; -} - bool swift::diagnoseParameterizedProtocolAvailability( SourceRange ReferenceRange, const DeclContext *ReferenceDC) { - // Check the availability of parameterized existential runtime support. - ASTContext &ctx = ReferenceDC->getASTContext(); - if (ctx.LangOpts.DisableAvailabilityChecking) - return false; - - if (!shouldCheckAvailability(ReferenceDC->getAsDecl())) - return false; - - auto runningOS = TypeChecker::overApproximateAvailabilityAtLocation( - ReferenceRange.Start, ReferenceDC); - auto availability = ctx.getParameterizedExistentialRuntimeAvailability(); - if (!runningOS.isContainedIn(availability)) { - return diagnosePotentialParameterizedProtocolUnavailability( - ReferenceRange, ReferenceDC, - UnavailabilityReason::requiresVersionRange( - availability.getOSVersion())); - } - return false; + return TypeChecker::checkAvailability( + ReferenceRange, + ReferenceDC->getASTContext().getParameterizedExistentialRuntimeAvailability(), + diag::availability_parameterized_protocol_only_version_newer, + ReferenceDC); } static void diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index 5fe1591e1bc4f..389809f35b93e 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -484,6 +484,12 @@ static void checkGenericParams(GenericContext *ownerCtx) { decl->diagnose(diag::experimental_type_with_parameter_pack); } + TypeChecker::checkAvailability( + gp->getSourceRange(), + ownerCtx->getASTContext().getVariadicGenericTypeAvailability(), + diag::availability_variadic_type_only_version_newer, + ownerCtx); + if (hasPack) { gp->diagnose(diag::more_than_one_pack_in_type); } diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp index 4f4ac2d6cdb93..9caecddf93e28 100644 --- a/lib/Sema/TypeCheckGeneric.cpp +++ b/lib/Sema/TypeCheckGeneric.cpp @@ -85,19 +85,11 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator, } // Check the availability of the opaque type runtime support. - if (!ctx.LangOpts.DisableAvailabilityChecking) { - auto runningOS = - TypeChecker::overApproximateAvailabilityAtLocation( - repr->getLoc(), - originatingDecl->getInnermostDeclContext()); - auto availability = ctx.getOpaqueTypeAvailability(); - if (!runningOS.isContainedIn(availability)) { - TypeChecker::diagnosePotentialOpaqueTypeUnavailability( - repr->getSourceRange(), - originatingDecl->getInnermostDeclContext(), - UnavailabilityReason::requiresVersionRange(availability.getOSVersion())); - } - } + TypeChecker::checkAvailability( + repr->getSourceRange(), + ctx.getOpaqueTypeAvailability(), + diag::availability_opaque_types_only_version_newer, + originatingDecl->getInnermostDeclContext()); // Create a generic signature for the opaque environment. This is the outer // generic signature with an added generic parameters representing the opaque diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h index 6ebf9de5df85e..d0d8bdbf76a9c 100644 --- a/lib/Sema/TypeChecker.h +++ b/lib/Sema/TypeChecker.h @@ -1117,9 +1117,10 @@ void diagnosePotentialUnavailability(const RootProtocolConformance *rootConf, const UnavailabilityReason &reason); void -diagnosePotentialOpaqueTypeUnavailability(SourceRange ReferenceRange, - const DeclContext *ReferenceDC, - const UnavailabilityReason &Reason); +diagnosePotentialUnavailability(SourceRange ReferenceRange, + Diag Diag, + const DeclContext *ReferenceDC, + const UnavailabilityReason &Reason); /// Type check a 'distributed actor' declaration. void checkDistributedActor(SourceFile *SF, NominalTypeDecl *decl); @@ -1127,6 +1128,11 @@ void checkDistributedActor(SourceFile *SF, NominalTypeDecl *decl); /// Type check a single 'distributed func' declaration. void checkDistributedFunc(FuncDecl *func); +bool checkAvailability(SourceRange ReferenceRange, + AvailabilityContext Availability, + Diag Diag, + const DeclContext *ReferenceDC); + void checkConcurrencyAvailability(SourceRange ReferenceRange, const DeclContext *ReferenceDC); diff --git a/stdlib/toolchain/CMakeLists.txt b/stdlib/toolchain/CMakeLists.txt index c32c7f3ffb51f..de2b0eaa73346 100644 --- a/stdlib/toolchain/CMakeLists.txt +++ b/stdlib/toolchain/CMakeLists.txt @@ -54,6 +54,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT) add_subdirectory(CompatibilityDynamicReplacements) add_subdirectory(CompatibilityConcurrency) add_subdirectory(CompatibilityThreading) + add_subdirectory(CompatibilityPacks) # This is a convenience target to have the list # of all the compatibility libraries needed to build @@ -63,6 +64,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT) target_link_libraries(HostCompatibilityLibs INTERFACE swiftCompatibilityConcurrency${vsuffix} swiftCompatibilityDynamicReplacements${vsuffix} + swiftCompatibilityPacks${vsuffix} swiftCompatibility50${vsuffix} swiftCompatibility51${vsuffix} swiftCompatibility56${vsuffix}) diff --git a/stdlib/toolchain/CompatibilityPacks/CMakeLists.txt b/stdlib/toolchain/CompatibilityPacks/CMakeLists.txt new file mode 100644 index 0000000000000..d918614430faa --- /dev/null +++ b/stdlib/toolchain/CompatibilityPacks/CMakeLists.txt @@ -0,0 +1,44 @@ +set(library_name "swiftCompatibilityPacks") + +include_directories("include/" "${SWIFT_STDLIB_SOURCE_DIR}") + +set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + +add_compile_definitions(SWIFT_COMPATIBILITY_PACKS) +add_swift_target_library("${library_name}" STATIC + Metadata.cpp + + TARGET_SDKS ${SWIFT_DARWIN_PLATFORMS} + + C_COMPILE_FLAGS + ${CXX_COMPILE_FLAGS} + "-D__STDC_WANT_LIB_EXT1__=1" + LINK_FLAGS ${CXX_LINK_FLAGS} + INCORPORATE_OBJECT_LIBRARIES swiftCompatibilityThreading + SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX} + DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS} + DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS} + DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS} + + MACCATALYST_BUILD_FLAVOR "zippered" + + INSTALL_IN_COMPONENT compiler + INSTALL_WITH_SHARED) + + +# FIXME: We need a more flexible mechanism to add lipo targets generated by +# add_swift_target_library to the ALL target. Until then this hack is necessary +# to ensure these libraries build. +foreach(sdk ${SWIFT_SDKS}) + set(target_name "${library_name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}") + if(NOT TARGET "${target_name}") + continue() + endif() + + set_target_properties("${target_name}" + PROPERTIES + EXCLUDE_FROM_ALL FALSE) +endforeach() diff --git a/stdlib/toolchain/CompatibilityPacks/Metadata.cpp b/stdlib/toolchain/CompatibilityPacks/Metadata.cpp new file mode 100644 index 0000000000000..b1608a3b125b8 --- /dev/null +++ b/stdlib/toolchain/CompatibilityPacks/Metadata.cpp @@ -0,0 +1,162 @@ +//===--- Metadata.cpp -----------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// Backward deployment of swift_allocateMetadataPack() and +// swift_allocateWitnessTablePack() runtime entry points. +// +//===----------------------------------------------------------------------===// + +#include "../../public/runtime/MetadataCache.h" + +using namespace swift; + +/// Copy and paste a symbol that needs to exist. +void *MetadataAllocator::Allocate(size_t size, size_t alignment) { + return malloc(size); +} + +/// Avoid depending on non-inline parts of llvm::hashing. +inline llvm::hash_code our_hash_integer_value(uint64_t value) { + const char *s = reinterpret_cast(&value); + const uint64_t a = llvm::hashing::detail::fetch32(s); + return llvm::hashing::detail::hash_16_bytes( + (a << 3), llvm::hashing::detail::fetch32(s + 4)); +} + +static inline llvm::hash_code our_hash_combine(llvm::hash_code seed, llvm::hash_code v) { + return seed ^ (v + 0x9e3779b9 + (seed<<6) + (seed>>2)); +} + +/// Copy and paste from Metadata.cpp. + +namespace { + +template +class PackCacheEntry { +public: + size_t Count; + + const PackType * const * getElements() const { + return reinterpret_cast(this + 1); + } + + const PackType ** getElements() { + return reinterpret_cast(this + 1); + } + + struct Key { + const PackType *const *Data; + const size_t Count; + + size_t getCount() const { + return Count; + } + + const PackType *getElement(size_t index) const { + assert(index < Count); + return Data[index]; + } + + friend llvm::hash_code hash_value(const Key &key) { + llvm::hash_code hash = 0; + for (size_t i = 0; i != key.getCount(); ++i) { + hash = our_hash_combine(hash, our_hash_integer_value( + reinterpret_cast(key.getElement(i)))); + } + return hash; + } + }; + + PackCacheEntry(const Key &key); + + intptr_t getKeyIntValueForDump() { + return 0; // No single meaningful value here. + } + + bool matchesKey(const Key &key) const { + if (key.getCount() != Count) + return false; + for (unsigned i = 0; i != Count; ++i) { + if (key.getElement(i) != getElements()[i]) + return false; + } + return true; + } + + friend llvm::hash_code hash_value(const PackCacheEntry &value) { + llvm::hash_code hash = 0; + for (size_t i = 0; i != value.Count; ++i) { + hash = our_hash_combine(hash, our_hash_integer_value( + reinterpret_cast(value.getElements()[i]))); + } + return hash; + } + + static size_t getExtraAllocationSize(const Key &key) { + return getExtraAllocationSize(key.Count); + } + + size_t getExtraAllocationSize() const { + return getExtraAllocationSize(Count); + } + + static size_t getExtraAllocationSize(unsigned count) { + return count * sizeof(const Metadata * const *); + } +}; + +template +PackCacheEntry::PackCacheEntry( + const typename PackCacheEntry::Key &key) { + Count = key.getCount(); + + for (unsigned i = 0; i < Count; ++i) + getElements()[i] = key.getElement(i); +} + +} // end anonymous namespace + +/// The uniquing structure for metadata packs. +static SimpleGlobalCache, + MetadataPackTag> MetadataPacks; + +SWIFT_RUNTIME_EXPORT SWIFT_CC(swift) +const Metadata * const * +swift_allocateMetadataPack(const Metadata * const *ptr, size_t count) { + if (MetadataPackPointer(reinterpret_cast(ptr)).getLifetime() + == PackLifetime::OnHeap) + return ptr; + + PackCacheEntry::Key key{ptr, count}; + auto bytes = MetadataPacks.getOrInsert(key).first->getElements(); + + MetadataPackPointer pack(bytes, PackLifetime::OnHeap); + return pack.getPointer(); +} + +/// The uniquing structure for witness table packs. +static SimpleGlobalCache, + WitnessTablePackTag> WitnessTablePacks; + +SWIFT_RUNTIME_EXPORT SWIFT_CC(swift) +const WitnessTable * const * +swift_allocateWitnessTablePack(const WitnessTable * const *ptr, size_t count) { + if (WitnessTablePackPointer(reinterpret_cast(ptr)).getLifetime() + == PackLifetime::OnHeap) + return ptr; + + PackCacheEntry::Key key{ptr, count}; + auto bytes = WitnessTablePacks.getOrInsert(key).first->getElements(); + + WitnessTablePackPointer pack(bytes, PackLifetime::OnHeap); + return pack.getPointer(); +} diff --git a/test/Constraints/one_element_tuple.swift b/test/Constraints/one_element_tuple.swift index b10e396c3d01b..16dd92e1ea1e3 100644 --- a/test/Constraints/one_element_tuple.swift +++ b/test/Constraints/one_element_tuple.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // REQUIRES: asserts diff --git a/test/Constraints/variadic_generic_types.swift b/test/Constraints/variadic_generic_types.swift index bf4c78a9d83d5..ddb5584ca7139 100644 --- a/test/Constraints/variadic_generic_types.swift +++ b/test/Constraints/variadic_generic_types.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // REQUIRES: asserts diff --git a/test/DebugInfo/variadic-generics-count.swift b/test/DebugInfo/variadic-generics-count.swift index ae17b7c422e48..7e487055d4e73 100644 --- a/test/DebugInfo/variadic-generics-count.swift +++ b/test/DebugInfo/variadic-generics-count.swift @@ -1,6 +1,6 @@ // REQUIRES: asserts // RUN: %target-swift-frontend -emit-ir %s -g -o - \ -// RUN: -parse-as-library -module-name a -enable-experimental-feature VariadicGenerics | %FileCheck %s +// RUN: -parse-as-library -module-name a -enable-experimental-feature VariadicGenerics -disable-availability-checking | %FileCheck %s public func f1(ts: repeat each T) { // CHECK: define {{.*}} @"$s1a2f12tsyxxQp_tRvzlF"(%swift.opaque** {{.*}}, i{{32|64}} [[COUNT1_1:.*]], %swift.type** {{.*}}) diff --git a/test/Driver/compatibility_packs.swift b/test/Driver/compatibility_packs.swift new file mode 100644 index 0000000000000..fa45cb9dcd147 --- /dev/null +++ b/test/Driver/compatibility_packs.swift @@ -0,0 +1,7 @@ +// RUN: %target-swift-frontend -print-target-info -runtime-compatibility-version 5.8 | %FileCheck %s + +// REQUIRES: OS=macosx + +// CHECK: "libraryName": "swiftCompatibilityPacks", +// CHECK-NEXT: "filter": "all", +// CHECK-NEXT: "forceLoad": false diff --git a/test/Generics/pack-shape-requirements.swift b/test/Generics/pack-shape-requirements.swift index 1ca228058e803..2fd8b908ca941 100644 --- a/test/Generics/pack-shape-requirements.swift +++ b/test/Generics/pack-shape-requirements.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -typecheck -enable-experimental-feature VariadicGenerics %s -debug-generic-signatures 2>&1 | %FileCheck %s +// RUN: %target-swift-frontend -typecheck -enable-experimental-feature VariadicGenerics %s -debug-generic-signatures -disable-availability-checking 2>&1 | %FileCheck %s // REQUIRES: asserts diff --git a/test/Generics/variadic_generic_requirements.swift b/test/Generics/variadic_generic_requirements.swift index e57346ae60e86..f1ed034ef5249 100644 --- a/test/Generics/variadic_generic_requirements.swift +++ b/test/Generics/variadic_generic_requirements.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // REQUIRES: asserts diff --git a/test/Generics/variadic_generic_types.swift b/test/Generics/variadic_generic_types.swift index 9414b434636e5..4a9bbf42cda73 100644 --- a/test/Generics/variadic_generic_types.swift +++ b/test/Generics/variadic_generic_types.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/Generics/variadic_generic_types_availability.swift b/test/Generics/variadic_generic_types_availability.swift new file mode 100644 index 0000000000000..94323fbfc9e65 --- /dev/null +++ b/test/Generics/variadic_generic_types_availability.swift @@ -0,0 +1,10 @@ +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics + +// Because of -enable-experimental-feature VariadicGenerics +// REQUIRES: asserts + +// REQUIRES: OS=macosx + +struct G {} +// expected-note@-1 {{add @available attribute to enclosing generic struct}} +// expected-error@-2 {{parameter packs in generic types are only available in macOS 99.99.0 or newer}} diff --git a/test/IRGen/pack_archetype_canonicalization.swift b/test/IRGen/pack_archetype_canonicalization.swift index 9be5dd15fea8a..eafb57a1188ba 100644 --- a/test/IRGen/pack_archetype_canonicalization.swift +++ b/test/IRGen/pack_archetype_canonicalization.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature VariadicGenerics +// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature VariadicGenerics -disable-availability-checking // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/IRGen/variadic_generic_fulfillment.swift b/test/IRGen/variadic_generic_fulfillment.swift index 6f24c7cf64144..164de8e094fe8 100644 --- a/test/IRGen/variadic_generic_fulfillment.swift +++ b/test/IRGen/variadic_generic_fulfillment.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature VariadicGenerics | %FileCheck %s -DINT=i%target-ptrsize +// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature VariadicGenerics -disable-availability-checking | %FileCheck %s -DINT=i%target-ptrsize // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/IRGen/variadic_generic_types.swift b/test/IRGen/variadic_generic_types.swift index 7f6ab4c46e3db..3376a7947e200 100644 --- a/test/IRGen/variadic_generic_types.swift +++ b/test/IRGen/variadic_generic_types.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir -primary-file %s -enable-experimental-feature VariadicGenerics | %FileCheck %s +// RUN: %target-swift-frontend -emit-ir -primary-file %s -enable-experimental-feature VariadicGenerics -disable-availability-checking | %FileCheck %s // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/Interpreter/variadic_generic_captures.swift b/test/Interpreter/variadic_generic_captures.swift index 88d118b5d7aa7..6ca7215b084c3 100644 --- a/test/Interpreter/variadic_generic_captures.swift +++ b/test/Interpreter/variadic_generic_captures.swift @@ -3,9 +3,6 @@ // REQUIRES: executable_test -// UNSUPPORTED: use_os_stdlib -// UNSUPPORTED: back_deployment_runtime - import StdlibUnittest var types = TestSuite("VariadicGenericCaptures") diff --git a/test/Interpreter/variadic_generic_conformances.swift b/test/Interpreter/variadic_generic_conformances.swift index e296cceb692f0..d1c27a87359a2 100644 --- a/test/Interpreter/variadic_generic_conformances.swift +++ b/test/Interpreter/variadic_generic_conformances.swift @@ -1,4 +1,4 @@ -// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics) +// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics -Xfrontend -disable-availability-checking) // REQUIRES: executable_test diff --git a/test/Interpreter/variadic_generic_types.swift b/test/Interpreter/variadic_generic_types.swift index c21f8f10111d0..5b909d39683a0 100644 --- a/test/Interpreter/variadic_generic_types.swift +++ b/test/Interpreter/variadic_generic_types.swift @@ -1,5 +1,5 @@ -// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics -Xfrontend -disable-concrete-type-metadata-mangled-name-accessors) -// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics) +// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics -Xfrontend -disable-concrete-type-metadata-mangled-name-accessors -Xfrontend -disable-availability-checking) +// RUN: %target-run-simple-swift(-enable-experimental-feature VariadicGenerics -Xfrontend -disable-availability-checking) // REQUIRES: executable_test diff --git a/test/ModuleInterface/pack_expansion_type.swift b/test/ModuleInterface/pack_expansion_type.swift index 59efe1a8fa829..9802859ee114d 100644 --- a/test/ModuleInterface/pack_expansion_type.swift +++ b/test/ModuleInterface/pack_expansion_type.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-emit-module-interface(%t/PackExpansionType.swiftinterface) %s -module-name PackExpansionType -enable-experimental-feature VariadicGenerics +// RUN: %target-swift-emit-module-interface(%t/PackExpansionType.swiftinterface) %s -module-name PackExpansionType -enable-experimental-feature VariadicGenerics -disable-availability-checking // RUN: %FileCheck %s < %t/PackExpansionType.swiftinterface // Experimental features require an asserts compiler diff --git a/test/Parse/type_parameter_packs.swift b/test/Parse/type_parameter_packs.swift index 131b1cac5fc96..8c66168617dbb 100644 --- a/test/Parse/type_parameter_packs.swift +++ b/test/Parse/type_parameter_packs.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // REQUIRES: asserts diff --git a/test/SILGen/pack_expansion_type.swift b/test/SILGen/pack_expansion_type.swift index 801dd1c85e914..2f705913ee2f1 100644 --- a/test/SILGen/pack_expansion_type.swift +++ b/test/SILGen/pack_expansion_type.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -enable-experimental-feature VariadicGenerics | %FileCheck %s +// RUN: %target-swift-emit-silgen %s -enable-experimental-feature VariadicGenerics -disable-availability-checking | %FileCheck %s // Experimental features require an asserts compiler // REQUIRES: asserts diff --git a/test/SILGen/variadic-generic-closures.swift b/test/SILGen/variadic-generic-closures.swift index 16cbb6c847b25..bdfdd0915e71d 100644 --- a/test/SILGen/variadic-generic-closures.swift +++ b/test/SILGen/variadic-generic-closures.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics %s | %FileCheck %s +// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics -disable-availability-checking %s | %FileCheck %s // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/SILGen/variadic-generic-tuples.swift b/test/SILGen/variadic-generic-tuples.swift index f5cc751fa71a5..c9994626642bd 100644 --- a/test/SILGen/variadic-generic-tuples.swift +++ b/test/SILGen/variadic-generic-tuples.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics %s | %FileCheck %s +// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics -disable-availability-checking %s | %FileCheck %s // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/SILGen/variadic-generic-vanishing-tuples.swift b/test/SILGen/variadic-generic-vanishing-tuples.swift index 4960044074df5..d5c578b761212 100644 --- a/test/SILGen/variadic-generic-vanishing-tuples.swift +++ b/test/SILGen/variadic-generic-vanishing-tuples.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics %s | %FileCheck %s +// RUN: %target-swift-emit-silgen -enable-experimental-feature VariadicGenerics -disable-availability-checking %s | %FileCheck %s // rdar://107459964 // rdar://107478603 diff --git a/test/SILGen/variadic_generic_types.swift b/test/SILGen/variadic_generic_types.swift index b5202a3c1fb7c..b65934b2f8abf 100644 --- a/test/SILGen/variadic_generic_types.swift +++ b/test/SILGen/variadic_generic_types.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-emit-silgen %s -enable-experimental-feature VariadicGenerics +// RUN: %target-swift-emit-silgen %s -enable-experimental-feature VariadicGenerics -disable-availability-checking // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/Serialization/pack_expansion_type.swift b/test/Serialization/pack_expansion_type.swift index 7a4a6ad38ac38..8b2cc2c48f7aa 100644 --- a/test/Serialization/pack_expansion_type.swift +++ b/test/Serialization/pack_expansion_type.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend %S/Inputs/pack_expansion_type_other.swift -emit-module -emit-module-path %t/pack_expansion_type_other.swiftmodule -enable-experimental-feature VariadicGenerics -// RUN: %target-typecheck-verify-swift -I %t -enable-experimental-feature VariadicGenerics +// RUN: %target-swift-frontend %S/Inputs/pack_expansion_type_other.swift -emit-module -emit-module-path %t/pack_expansion_type_other.swiftmodule -enable-experimental-feature VariadicGenerics -disable-availability-checking +// RUN: %target-typecheck-verify-swift -I %t -enable-experimental-feature VariadicGenerics -disable-availability-checking // Experimental features require an asserts compiler // REQUIRES: asserts diff --git a/test/TypeDecoder/variadic_nominal_types.swift b/test/TypeDecoder/variadic_nominal_types.swift index e1ba27f3b8936..51a03a29662e9 100644 --- a/test/TypeDecoder/variadic_nominal_types.swift +++ b/test/TypeDecoder/variadic_nominal_types.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-build-swift -emit-executable %s -g -o %t/variadic_nominal_types -emit-module -enable-experimental-feature VariadicGenerics +// RUN: %target-build-swift -emit-executable %s -g -o %t/variadic_nominal_types -emit-module -enable-experimental-feature VariadicGenerics -Xfrontend -disable-availability-checking // RUN: sed -ne '/\/\/ *DEMANGLE-TYPE: /s/\/\/ *DEMANGLE-TYPE: *//p' < %s > %t/input // RUN: %lldb-moduleimport-test-with-sdk %t/variadic_nominal_types -type-from-mangled=%t/input | %FileCheck %s --check-prefix=CHECK-TYPE diff --git a/test/decl/protocol/conforms/variadic_generic_type.swift b/test/decl/protocol/conforms/variadic_generic_type.swift index 5a62412650c74..f85fb3f32bb41 100644 --- a/test/decl/protocol/conforms/variadic_generic_type.swift +++ b/test/decl/protocol/conforms/variadic_generic_type.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts diff --git a/test/type/opaque.swift b/test/type/opaque.swift index b21731ddc5a91..92562d048ea54 100644 --- a/test/type/opaque.swift +++ b/test/type/opaque.swift @@ -85,7 +85,7 @@ typealias Foo = some P // expected-error{{'some' types are only permitted}} func blibble(blobble: some P) {} func blib() -> P & some Q { return 1 } // expected-error{{'some' should appear at the beginning}} -func blab() -> some P? { return 1 } // expected-error{{must specify only}} expected-note{{did you mean to write an optional of an 'opaque' type?}} +func blab() -> some P? { return 1 } // expected-error{{must specify only}} expected-note{{did you mean to write an optional of an 'some' type?}} func blorb(_: T) { } // expected-error{{'some' types are only permitted}} func blub() -> T where T == some P { return 1 } // expected-error{{'some' types are only permitted}} diff --git a/test/type/pack_expansion.swift b/test/type/pack_expansion.swift index 36068a79bb0ec..cf1293df19f03 100644 --- a/test/type/pack_expansion.swift +++ b/test/type/pack_expansion.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics +// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics -disable-availability-checking // REQUIRES: asserts