Merge remote-tracking branch 'origin/main' into rebranch

This commit is contained in:
swift-ci
2022-05-18 15:18:15 -07:00
22 changed files with 139 additions and 59 deletions

View File

@@ -327,10 +327,6 @@ public:
/// would for a non-system header. /// would for a non-system header.
bool DisableModulesValidateSystemDependencies = false; bool DisableModulesValidateSystemDependencies = false;
/// Enforce loading only serialized modules built with the same SDK
/// as the context loading it.
bool EnableSameSDKCheck = true;
/// A set of compiled modules that may be ready to use. /// A set of compiled modules that may be ready to use.
std::vector<std::string> CandidateCompiledModules; std::vector<std::string> CandidateCompiledModules;

View File

@@ -184,6 +184,11 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion =
/// this Swift was built. /// this Swift was built.
StringRef getSwiftRevision(); StringRef getSwiftRevision();
/// Is the running compiler built with a version tag for distribution?
/// When true, \c Version::getCurrentCompilerVersion returns a valid version
/// and \c getSwiftRevision returns the version tuple in string format.
bool isCurrentCompilerTagged();
} // end namespace version } // end namespace version
} // end namespace swift } // end namespace swift

View File

@@ -536,6 +536,8 @@ public:
bool diagnose(const Solution &solution, bool asNote = false) const override; bool diagnose(const Solution &solution, bool asNote = false) const override;
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override;
static RelabelArguments *create(ConstraintSystem &cs, static RelabelArguments *create(ConstraintSystem &cs,
llvm::ArrayRef<Identifier> correctLabels, llvm::ArrayRef<Identifier> correctLabels,
ConstraintLocator *locator); ConstraintLocator *locator);

View File

@@ -196,13 +196,15 @@ public:
/// refers directly into this buffer. /// refers directly into this buffer.
/// \param requiresOSSAModules If true, necessitates the module to be /// \param requiresOSSAModules If true, necessitates the module to be
/// compiled with -enable-ossa-modules. /// compiled with -enable-ossa-modules.
/// \param requiredSDK If not empty, only accept modules built with
/// a compatible SDK. The StringRef represents the canonical SDK name.
/// \param[out] extendedInfo If present, will be populated with additional /// \param[out] extendedInfo If present, will be populated with additional
/// compilation options serialized into the AST at build time that may be /// compilation options serialized into the AST at build time that may be
/// necessary to load it properly. /// necessary to load it properly.
/// \param[out] dependencies If present, will be populated with list of /// \param[out] dependencies If present, will be populated with list of
/// input files the module depends on, if present in INPUT_BLOCK. /// input files the module depends on, if present in INPUT_BLOCK.
ValidationInfo validateSerializedAST( ValidationInfo validateSerializedAST(
StringRef data, bool requiresOSSAModules, StringRef data, bool requiresOSSAModules, StringRef requiredSDK,
ExtendedValidationInfo *extendedInfo = nullptr, ExtendedValidationInfo *extendedInfo = nullptr,
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies = SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =
nullptr); nullptr);

View File

@@ -2419,10 +2419,6 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
auto &Ctx = CI.getASTContext(); auto &Ctx = CI.getASTContext();
// Don't check if the stdlib was build with the same SDK as what is loaded
// here as some tests rely on using a different stdlib.
Ctx.SearchPathOpts.EnableSameSDKCheck = false;
// Load standard library so that Clang importer can use it. // Load standard library so that Clang importer can use it.
auto *Stdlib = Ctx.getStdlibModule(/*loadIfAbsent=*/true); auto *Stdlib = Ctx.getStdlibModule(/*loadIfAbsent=*/true);
if (!Stdlib) { if (!Stdlib) {

View File

@@ -36,7 +36,7 @@ bool swift::parseASTSection(MemoryBufferSerializedModuleLoader &Loader,
// headers. Iterate over all AST modules. // headers. Iterate over all AST modules.
while (!buf.empty()) { while (!buf.empty()) {
auto info = serialization::validateSerializedAST( auto info = serialization::validateSerializedAST(
buf, Loader.isRequiredOSSAModules()); buf, Loader.isRequiredOSSAModules(), /*requiredSDK*/StringRef());
assert(info.name.size() < (2 << 10) && "name failed sanity check"); assert(info.name.size() < (2 << 10) && "name failed sanity check");

View File

@@ -446,5 +446,13 @@ StringRef getSwiftRevision() {
#endif #endif
} }
bool isCurrentCompilerTagged() {
#ifdef SWIFT_COMPILER_VERSION
return true;
#else
return false;
#endif
}
} // end namespace version } // end namespace version
} // end namespace swift } // end namespace swift

View File

@@ -2537,7 +2537,7 @@ serialization::Status
CompilerInvocation::loadFromSerializedAST(StringRef data) { CompilerInvocation::loadFromSerializedAST(StringRef data) {
serialization::ExtendedValidationInfo extendedInfo; serialization::ExtendedValidationInfo extendedInfo;
serialization::ValidationInfo info = serialization::validateSerializedAST( serialization::ValidationInfo info = serialization::validateSerializedAST(
data, getSILOptions().EnableOSSAModules, &extendedInfo); data, getSILOptions().EnableOSSAModules, LangOpts.SDKName, &extendedInfo);
if (info.status != serialization::Status::Valid) if (info.status != serialization::Status::Valid)
return info.status; return info.status;
@@ -2573,7 +2573,7 @@ CompilerInvocation::setUpInputForSILTool(
auto result = serialization::validateSerializedAST( auto result = serialization::validateSerializedAST(
fileBufOrErr.get()->getBuffer(), getSILOptions().EnableOSSAModules, fileBufOrErr.get()->getBuffer(), getSILOptions().EnableOSSAModules,
&extendedInfo); LangOpts.SDKName, &extendedInfo);
bool hasSerializedAST = result.status == serialization::Status::Valid; bool hasSerializedAST = result.status == serialization::Status::Valid;
if (hasSerializedAST) { if (hasSerializedAST) {

View File

@@ -200,9 +200,11 @@ public:
namespace path = llvm::sys::path; namespace path = llvm::sys::path;
static bool serializedASTLooksValid(const llvm::MemoryBuffer &buf, static bool serializedASTLooksValid(const llvm::MemoryBuffer &buf,
bool requiresOSSAModules) { bool requiresOSSAModules,
StringRef requiredSDK) {
auto VI = serialization::validateSerializedAST(buf.getBuffer(), auto VI = serialization::validateSerializedAST(buf.getBuffer(),
requiresOSSAModules); requiresOSSAModules,
requiredSDK);
return VI.status == serialization::Status::Valid; return VI.status == serialization::Status::Valid;
} }
@@ -500,7 +502,7 @@ class ModuleInterfaceLoaderImpl {
LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n"); LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
auto validationInfo = serialization::validateSerializedAST( auto validationInfo = serialization::validateSerializedAST(
buf.getBuffer(), requiresOSSAModules, buf.getBuffer(), requiresOSSAModules, ctx.LangOpts.SDKName,
/*ExtendedValidationInfo=*/nullptr, &allDeps); /*ExtendedValidationInfo=*/nullptr, &allDeps);
if (validationInfo.status != serialization::Status::Valid) { if (validationInfo.status != serialization::Status::Valid) {
@@ -542,7 +544,8 @@ class ModuleInterfaceLoaderImpl {
// First, make sure the underlying module path exists and is valid. // First, make sure the underlying module path exists and is valid.
auto modBuf = fs.getBufferForFile(fwd.underlyingModulePath); auto modBuf = fs.getBufferForFile(fwd.underlyingModulePath);
if (!modBuf || !serializedASTLooksValid(*modBuf.get(), requiresOSSAModules)) if (!modBuf || !serializedASTLooksValid(*modBuf.get(), requiresOSSAModules,
ctx.LangOpts.SDKName))
return false; return false;
// Next, check the dependencies in the forwarding file. // Next, check the dependencies in the forwarding file.

View File

@@ -1189,10 +1189,6 @@ private:
if (isa<IfConfigDecl>(decl)) if (isa<IfConfigDecl>(decl))
return; return;
// Variable declaration would be handled by a pattern binding.
if (isa<VarDecl>(decl))
return;
// Generate constraints for pattern binding declarations. // Generate constraints for pattern binding declarations.
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) { if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
SolutionApplicationTarget target(patternBinding); SolutionApplicationTarget target(patternBinding);

View File

@@ -241,6 +241,38 @@ bool RelabelArguments::diagnose(const Solution &solution, bool asNote) const {
return failure.diagnose(asNote); return failure.diagnose(asNote);
} }
bool RelabelArguments::diagnoseForAmbiguity(
CommonFixesArray commonFixes) const {
SmallPtrSet<ValueDecl *, 4> overloadChoices;
// First, let's find overload choice associated with each
// re-labeling fix.
for (const auto &fix : commonFixes) {
auto &solution = *fix.first;
auto calleeLocator = solution.getCalleeLocator(getLocator());
if (!calleeLocator)
return false;
auto overloadChoice = solution.getOverloadChoiceIfAvailable(calleeLocator);
if (!overloadChoice)
return false;
auto *decl = overloadChoice->choice.getDeclOrNull();
if (!decl)
return false;
(void)overloadChoices.insert(decl);
}
// If all of the fixes point to the same overload choice then it's
// exactly the same issue since the call site is static.
if (overloadChoices.size() == 1)
return diagnose(*commonFixes.front().first);
return false;
}
RelabelArguments * RelabelArguments *
RelabelArguments::create(ConstraintSystem &cs, RelabelArguments::create(ConstraintSystem &cs,
llvm::ArrayRef<Identifier> correctLabels, llvm::ArrayRef<Identifier> correctLabels,

View File

@@ -156,22 +156,6 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
return error(status); return error(status);
} }
// The loaded module was built with a compatible SDK if either:
// * it was the same SDK
// * or one who's name is a prefix of the clients' SDK name. This expects
// that a module built with macOS11 can be used with the macOS11.secret SDK.
// This is generally the case as SDKs with suffixes are a superset of the
// short SDK name equivalent. While this is accepted, this is still not a
// recommended configuration and may lead to unreadable swiftmodules.
StringRef moduleSDK = Core->SDKName;
StringRef clientSDK = ctx.LangOpts.SDKName;
if (ctx.SearchPathOpts.EnableSameSDKCheck &&
!moduleSDK.empty() && !clientSDK.empty() &&
!clientSDK.startswith(moduleSDK)) {
status = Status::SDKMismatch;
return error(status);
}
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath(); StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
if (SDKPath.empty() || if (SDKPath.empty() ||
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) { !Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
@@ -372,7 +356,7 @@ ModuleFile::getModuleName(ASTContext &Ctx, StringRef modulePath,
bool isFramework = false; bool isFramework = false;
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load( serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
modulePath.str(), std::move(newBuf), nullptr, nullptr, modulePath.str(), std::move(newBuf), nullptr, nullptr,
/*isFramework*/ isFramework, Ctx.SILOpts.EnableOSSAModules, /*isFramework*/ isFramework, Ctx.SILOpts.EnableOSSAModules, Ctx.LangOpts.SDKName,
Ctx.SearchPathOpts.DeserializedPathRecoverer, Ctx.SearchPathOpts.DeserializedPathRecoverer,
loadedModuleFile); loadedModuleFile);
Name = loadedModuleFile->Name.str(); Name = loadedModuleFile->Name.str();

View File

@@ -173,6 +173,7 @@ static ValidationInfo validateControlBlock(
llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t> &scratch, llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t> &scratch,
std::pair<uint16_t, uint16_t> expectedVersion, bool requiresOSSAModules, std::pair<uint16_t, uint16_t> expectedVersion, bool requiresOSSAModules,
bool requiresRevisionMatch, bool requiresRevisionMatch,
StringRef requiredSDK,
ExtendedValidationInfo *extendedInfo, ExtendedValidationInfo *extendedInfo,
PathObfuscator &pathRecoverer) { PathObfuscator &pathRecoverer) {
// The control block is malformed until we've at least read a major version // The control block is malformed until we've at least read a major version
@@ -307,6 +308,30 @@ static ValidationInfo validateControlBlock(
break; break;
case control_block::SDK_NAME: { case control_block::SDK_NAME: {
result.sdkName = blobData; result.sdkName = blobData;
// Enable this check for tagged compiler or when the
// env var is set (for testing).
static const char* forceDebugPreSDKRestriction =
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK");
if (!version::isCurrentCompilerTagged() &&
!forceDebugPreSDKRestriction) {
break;
}
// The loaded module was built with a compatible SDK if either:
// * it was the same SDK
// * or one who's name is a prefix of the clients' SDK name. This expects
// that a module built with macOS11 can be used with the macOS11.secret SDK.
// This is generally the case as SDKs with suffixes are a superset of the
// short SDK name equivalent. While this is accepted, this is still not a
// recommended configuration and may lead to unreadable swiftmodules.
StringRef moduleSDK = blobData;
if (!moduleSDK.empty() && !requiredSDK.empty() &&
!requiredSDK.startswith(moduleSDK)) {
result.status = Status::SDKMismatch;
return result;
}
break; break;
} }
case control_block::REVISION: { case control_block::REVISION: {
@@ -329,7 +354,7 @@ static ValidationInfo validateControlBlock(
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION"); ::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION");
bool isCompilerTagged = forcedDebugRevision || bool isCompilerTagged = forcedDebugRevision ||
!version::Version::getCurrentCompilerVersion().empty(); version::isCurrentCompilerTagged();
StringRef moduleRevision = blobData; StringRef moduleRevision = blobData;
if (isCompilerTagged) { if (isCompilerTagged) {
@@ -443,7 +468,7 @@ bool serialization::isSerializedAST(StringRef data) {
} }
ValidationInfo serialization::validateSerializedAST( ValidationInfo serialization::validateSerializedAST(
StringRef data, bool requiresOSSAModules, StringRef data, bool requiresOSSAModules, StringRef requiredSDK,
ExtendedValidationInfo *extendedInfo, ExtendedValidationInfo *extendedInfo,
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies) { SmallVectorImpl<SerializationOptions::FileDependency> *dependencies) {
ValidationInfo result; ValidationInfo result;
@@ -487,6 +512,7 @@ ValidationInfo serialization::validateSerializedAST(
cursor, scratch, cursor, scratch,
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR}, {SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
requiresOSSAModules, /*requiresRevisionMatch=*/true, requiresOSSAModules, /*requiresRevisionMatch=*/true,
requiredSDK,
extendedInfo, localObfuscator); extendedInfo, localObfuscator);
if (result.status == Status::Malformed) if (result.status == Status::Malformed)
return result; return result;
@@ -995,8 +1021,8 @@ bool ModuleFileSharedCore::readModuleDocIfPresent(PathObfuscator &pathRecoverer)
info = validateControlBlock( info = validateControlBlock(
docCursor, scratch, {SWIFTDOC_VERSION_MAJOR, SWIFTDOC_VERSION_MINOR}, docCursor, scratch, {SWIFTDOC_VERSION_MAJOR, SWIFTDOC_VERSION_MINOR},
RequiresOSSAModules, /*requiresRevisionMatch=*/false, RequiresOSSAModules, /*requiresRevisionMatch*/false,
/*extendedInfo*/ nullptr, pathRecoverer); /*requiredSDK*/StringRef(), /*extendedInfo*/nullptr, pathRecoverer);
if (info.status != Status::Valid) if (info.status != Status::Valid)
return false; return false;
// Check that the swiftdoc is actually for this module. // Check that the swiftdoc is actually for this module.
@@ -1139,9 +1165,8 @@ bool ModuleFileSharedCore::readModuleSourceInfoIfPresent(PathObfuscator &pathRec
info = validateControlBlock( info = validateControlBlock(
infoCursor, scratch, infoCursor, scratch,
{SWIFTSOURCEINFO_VERSION_MAJOR, SWIFTSOURCEINFO_VERSION_MINOR}, {SWIFTSOURCEINFO_VERSION_MAJOR, SWIFTSOURCEINFO_VERSION_MINOR},
RequiresOSSAModules, /*requiresRevisionMatch=*/false, RequiresOSSAModules, /*requiresRevisionMatch*/false,
/*extendedInfo*/ nullptr, /*requiredSDK*/StringRef(), /*extendedInfo*/nullptr, pathRecoverer);
pathRecoverer);
if (info.status != Status::Valid) if (info.status != Status::Valid)
return false; return false;
// Check that the swiftsourceinfo is actually for this module. // Check that the swiftsourceinfo is actually for this module.
@@ -1215,7 +1240,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules, bool isFramework, bool requiresOSSAModules, StringRef requiredSDK,
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer) serialization::ValidationInfo &info, PathObfuscator &pathRecoverer)
: ModuleInputBuffer(std::move(moduleInputBuffer)), : ModuleInputBuffer(std::move(moduleInputBuffer)),
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)), ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
@@ -1267,7 +1292,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
info = validateControlBlock( info = validateControlBlock(
cursor, scratch, cursor, scratch,
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR}, {SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
RequiresOSSAModules, /*requiresRevisionMatch=*/true, RequiresOSSAModules, /*requiresRevisionMatch=*/true, requiredSDK,
&extInfo, pathRecoverer); &extInfo, pathRecoverer);
if (info.status != Status::Valid) { if (info.status != Status::Valid) {
error(info.status); error(info.status);

View File

@@ -373,7 +373,7 @@ private:
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules, bool isFramework, bool requiresOSSAModules, StringRef requiredSDK,
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer); serialization::ValidationInfo &info, PathObfuscator &pathRecoverer);
/// Change the status of the current module. /// Change the status of the current module.
@@ -510,13 +510,13 @@ public:
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules, bool isFramework, bool requiresOSSAModules,
PathObfuscator &pathRecoverer, StringRef requiredSDK, PathObfuscator &pathRecoverer,
std::shared_ptr<const ModuleFileSharedCore> &theModule) { std::shared_ptr<const ModuleFileSharedCore> &theModule) {
serialization::ValidationInfo info; serialization::ValidationInfo info;
auto *core = new ModuleFileSharedCore( auto *core = new ModuleFileSharedCore(
std::move(moduleInputBuffer), std::move(moduleDocInputBuffer), std::move(moduleInputBuffer), std::move(moduleDocInputBuffer),
std::move(moduleSourceInfoInputBuffer), isFramework, std::move(moduleSourceInfoInputBuffer), isFramework,
requiresOSSAModules, info, pathRecoverer); requiresOSSAModules, requiredSDK, info, pathRecoverer);
if (!moduleInterfacePath.empty()) { if (!moduleInterfacePath.empty()) {
ArrayRef<char> path; ArrayRef<char> path;
core->allocateBuffer(path, moduleInterfacePath); core->allocateBuffer(path, moduleInterfacePath);

View File

@@ -402,7 +402,7 @@ llvm::ErrorOr<ModuleDependencies> SerializedModuleLoaderBase::scanModuleFile(
bool isFramework = false; bool isFramework = false;
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load( serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
modulePath.str(), std::move(moduleBuf.get()), nullptr, nullptr, modulePath.str(), std::move(moduleBuf.get()), nullptr, nullptr,
isFramework, isRequiredOSSAModules(), isFramework, isRequiredOSSAModules(), Ctx.LangOpts.SDKName,
Ctx.SearchPathOpts.DeserializedPathRecoverer, Ctx.SearchPathOpts.DeserializedPathRecoverer,
loadedModuleFile); loadedModuleFile);
@@ -748,7 +748,7 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load( serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
moduleInterfacePath, std::move(moduleInputBuffer), moduleInterfacePath, std::move(moduleInputBuffer),
std::move(moduleDocInputBuffer), std::move(moduleSourceInfoInputBuffer), std::move(moduleDocInputBuffer), std::move(moduleSourceInfoInputBuffer),
isFramework, isRequiredOSSAModules(), isFramework, isRequiredOSSAModules(), Ctx.LangOpts.SDKName,
Ctx.SearchPathOpts.DeserializedPathRecoverer, Ctx.SearchPathOpts.DeserializedPathRecoverer,
loadedModuleFileCore); loadedModuleFileCore);
SerializedASTFile *fileUnit = nullptr; SerializedASTFile *fileUnit = nullptr;
@@ -1171,7 +1171,8 @@ bool SerializedModuleLoaderBase::canImportModule(ImportPath::Module path,
// format, if present. // format, if present.
if (currentVersion.empty() && *unusedModuleBuffer) { if (currentVersion.empty() && *unusedModuleBuffer) {
auto metaData = serialization::validateSerializedAST( auto metaData = serialization::validateSerializedAST(
(*unusedModuleBuffer)->getBuffer(), Ctx.SILOpts.EnableOSSAModules); (*unusedModuleBuffer)->getBuffer(), Ctx.SILOpts.EnableOSSAModules,
Ctx.LangOpts.SDKName);
currentVersion = metaData.userModuleVersion; currentVersion = metaData.userModuleVersion;
} }

View File

@@ -1170,7 +1170,6 @@ func test(arr: [[Int]]) {
} }
arr.map { ($0 as? [Int]).map { A($0) } } // expected-error {{missing argument label 'arg:' in call}} {{36-36=arg: }} arr.map { ($0 as? [Int]).map { A($0) } } // expected-error {{missing argument label 'arg:' in call}} {{36-36=arg: }}
// expected-warning@-1 {{conditional cast from '[Int]' to '[Int]' always succeeds}}
} }
func closureWithCaseArchetype<T>(_: T.Type) { func closureWithCaseArchetype<T>(_: T.Type) {

View File

@@ -902,7 +902,8 @@ func rdar78781552() {
// expected-error@-1 {{generic struct 'Test' requires that '(((Int) throws -> Bool) throws -> [Int])?' conform to 'RandomAccessCollection'}} // expected-error@-1 {{generic struct 'Test' requires that '(((Int) throws -> Bool) throws -> [Int])?' conform to 'RandomAccessCollection'}}
// expected-error@-2 {{generic parameter 'Content' could not be inferred}} expected-note@-2 {{explicitly specify the generic arguments to fix this issue}} // expected-error@-2 {{generic parameter 'Content' could not be inferred}} expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}
// expected-error@-3 {{cannot convert value of type '(((Int) throws -> Bool) throws -> [Int])?' to expected argument type '[(((Int) throws -> Bool) throws -> [Int])?]'}} // expected-error@-3 {{cannot convert value of type '(((Int) throws -> Bool) throws -> [Int])?' to expected argument type '[(((Int) throws -> Bool) throws -> [Int])?]'}}
// expected-error@-4 {{missing argument for parameter 'filter' in call}} // expected-error@-4 {{missing argument label 'data:' in call}}
// expected-error@-5 {{missing argument for parameter 'filter' in call}}
} }
} }

View File

@@ -6,20 +6,34 @@
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name A -o %t/build -parse-stdlib -module-cache-path %t/cache // RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name A -o %t/build -parse-stdlib -module-cache-path %t/cache
/// Building Client against SDK A should work fine as expected. /// Building Client against SDK A should work fine as expected.
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A -I %t/build -parse-stdlib -module-cache-path %t/cache // RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A -I %t/build -parse-stdlib -module-cache-path %t/cache
/// Build Client against SDK B, this should fail at loading Lib against a different SDK than A. /// Build Client against SDK B, this should fail at loading Lib against a different SDK than A.
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB // RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB
// CHECK-AvsB: cannot load module 'Lib' built with SDK 'A' when using SDK 'B': {{.*}}Lib.swiftmodule // CHECK-AvsB: cannot load module 'Lib' built with SDK 'A' when using SDK 'B': {{.*}}Lib.swiftmodule
/// Build Client against SDK A.Secret, this should accept the SDK as being a super set of A. /// Build Client against SDK A.Secret, this should accept the SDK as being a super set of A.
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A.Secret -I %t/build -parse-stdlib -module-cache-path %t/cache // RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A.Secret -I %t/build -parse-stdlib -module-cache-path %t/cache
/// Build Lib against SDK C.Secret and Client against SDK C, this should be rejected. /// Build Lib against SDK C.Secret and Client against SDK C, this should be rejected.
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name C.Secret -o %t/build -parse-stdlib -module-cache-path %t/cache // RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name C.Secret -o %t/build -parse-stdlib -module-cache-path %t/cache
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name C -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-C // RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name C -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-C
// CHECK-C: cannot load module 'Lib' built with SDK 'C.Secret' when using SDK 'C': {{.*}}Lib.swiftmodule // CHECK-C: cannot load module 'Lib' built with SDK 'C.Secret' when using SDK 'C': {{.*}}Lib.swiftmodule
/// Build a resilient Lib against SDK A, and a client against SDK B.
/// This should succeed after rebuilding from the swiftinterface.
// RUN: %empty-directory(%t/cache)
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name A -o %t/build -parse-stdlib -module-cache-path %t/cache \
// RUN: -enable-library-evolution -emit-module-interface-path %t/build/Lib.swiftinterface
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache \
// RUN: -Rmodule-interface-rebuild 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB-REBUILD
// CHECK-AvsB-REBUILD: remark: rebuilding module 'Lib' from interface
// BEGIN Lib.swift // BEGIN Lib.swift
public func foo() {} public func foo() {}

View File

@@ -234,6 +234,20 @@ func test_local_function_capturing_vars() {
} }
} }
func test_test_invalid_redeclaration() {
func test(_: () -> Void) {
}
test {
let foo = 0 // expected-note {{'foo' previously declared here}}
let foo = foo // expected-error {{invalid redeclaration of 'foo'}}
}
test {
let (foo, foo) = (5, 6) // expected-error {{invalid redeclaration of 'foo'}} expected-note {{'foo' previously declared here}}
}
}
func test_pattern_ambiguity_doesnot_crash_compiler() { func test_pattern_ambiguity_doesnot_crash_compiler() {
enum E { enum E {
case hello(result: Int) // expected-note 2 {{found this candidate}} case hello(result: Int) // expected-note 2 {{found this candidate}}

View File

@@ -507,6 +507,7 @@ func testLabeledSubscript() {
// TODO: These ought to work without errors. // TODO: These ought to work without errors.
let _ = \AA.[keyPath: k] let _ = \AA.[keyPath: k]
// expected-error@-1 {{cannot convert value of type 'KeyPath<AA, Int>' to expected argument type 'Int'}} // expected-error@-1 {{cannot convert value of type 'KeyPath<AA, Int>' to expected argument type 'Int'}}
// expected-error@-2 {{extraneous argument label 'keyPath:' in call}}
let _ = \AA.[keyPath: \AA.[labeled: 0]] // expected-error {{extraneous argument label 'keyPath:' in call}} let _ = \AA.[keyPath: \AA.[labeled: 0]] // expected-error {{extraneous argument label 'keyPath:' in call}}
// expected-error@-1 {{cannot convert value of type 'KeyPath<AA, Int>' to expected argument type 'Int'}} // expected-error@-1 {{cannot convert value of type 'KeyPath<AA, Int>' to expected argument type 'Int'}}

View File

@@ -49,6 +49,7 @@ validateModule(llvm::StringRef data, bool Verbose, bool requiresOSSAModules,
swift::serialization::ValidationInfo &info, swift::serialization::ValidationInfo &info,
swift::serialization::ExtendedValidationInfo &extendedInfo) { swift::serialization::ExtendedValidationInfo &extendedInfo) {
info = swift::serialization::validateSerializedAST(data, requiresOSSAModules, info = swift::serialization::validateSerializedAST(data, requiresOSSAModules,
/*requiredSDK*/StringRef(),
&extendedInfo); &extendedInfo);
if (info.status != swift::serialization::Status::Valid) { if (info.status != swift::serialization::Status::Valid) {
llvm::outs() << "error: validateSerializedAST() failed\n"; llvm::outs() << "error: validateSerializedAST() failed\n";

View File

@@ -149,7 +149,7 @@ protected:
auto bufData = (*bufOrErr)->getBuffer(); auto bufData = (*bufOrErr)->getBuffer();
auto validationInfo = serialization::validateSerializedAST( auto validationInfo = serialization::validateSerializedAST(
bufData, silOpts.EnableOSSAModules); bufData, silOpts.EnableOSSAModules, /*requiredSDK*/StringRef());
ASSERT_EQ(serialization::Status::Valid, validationInfo.status); ASSERT_EQ(serialization::Status::Valid, validationInfo.status);
ASSERT_EQ(bufData, moduleBuffer->getBuffer()); ASSERT_EQ(bufData, moduleBuffer->getBuffer());
} }