Skip to content

Merge main 2022-05-20 #4579

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d7eada4
[SourceKit] Resolve a nondeterministic deadlock in SourceKit while ca…
ahoppen Apr 8, 2022
854f64e
[CSClosure] Diagnose invalid re-declarations in multi-statement closures
xedin May 9, 2022
f3ff87b
[Diagnostics] Diagnose re-labeling failures in ambiguity conditions
xedin May 12, 2022
a63f071
[Serialization] Remove 'EnableSameSDKCheck' it's not needed with the …
xymus May 13, 2022
c8059a0
[Serialization] Soft-reject swiftmodules built against a different SDK
xymus May 11, 2022
3523adb
[Serialization] Limit per-SDK swiftmodule restriction to tagged compi…
xymus May 16, 2022
c341010
[Basic][Serialization] Intro and use `isCurrentCompilerTagged`
xymus May 17, 2022
50c2399
[stdlib] Work around binary compatibility issues with String index va…
lorentey May 18, 2022
609b3e5
[CSStep] Conjunction: Tranform all unbound outer variables into place…
xedin May 10, 2022
dfadee3
[CSDiagnostics] Attach missing member diagnostic to a pattern/statement
xedin May 9, 2022
4debf30
[CSStep] Conjunction: Propagate fix and hole scores to outer solution
xedin May 13, 2022
f210442
[CSClosure] Anchor `for-in` sequence constraints on sequence expression
xedin May 9, 2022
07ffdde
Merge pull request #58954 from lorentey/string-bincompat-workarounds
lorentey May 18, 2022
abf56bc
[cxx-interop] Extract libstdc++ installation path from Clang
egorzhdan May 18, 2022
7435c93
Merge pull request #58915 from xedin/multi-statement-closure-improvem…
xedin May 18, 2022
ddd7e49
[CSClosure] Fix per-element variable finder to correctly handle retur…
xedin May 11, 2022
95dff4d
[stdlib] Define version 5.8 of the stdlib
lorentey May 18, 2022
979afdd
[Serialization] Bump SWIFTMODULE_VERSION_MINOR to avoid conflict with…
mikeash May 18, 2022
c7b1505
Merge pull request #58905 from xedin/improve-relabeling-diagnostic
xedin May 18, 2022
5693331
Merge pull request #58768 from xedin/redecl-check-in-multi-closures
xedin May 18, 2022
6c287b2
Merge pull request #58935 from xymus/swiftmodule-per-sdk-soft-reject
xymus May 18, 2022
5747bc4
Tests: Update `attr_inlinable_available.swift` to require macOS and r…
tshortli May 18, 2022
497619e
Tests: Add test cases for potential unavailability in class inheritan…
tshortli May 18, 2022
a0bf64f
Sema: Reword diagnostics about potentially unavailable decls to impro…
tshortli May 18, 2022
06fd9be
Merge pull request #58970 from mikeash/bump-swiftmodule-version
swift-ci May 18, 2022
ba52537
[wrangler] Unconditionally disable test/Distributed/Runtime/distribut…
lorentey May 19, 2022
0e8ece6
Merge pull request #58834 from xedin/var-finder-return-handling
xedin May 19, 2022
b52257e
Merge pull request #58963 from tshortli/diagnose-potentially-unavaila…
tshortli May 19, 2022
025e919
Merge pull request #42258 from ahoppen/pr/no-deadlock-cancellation
ahoppen May 19, 2022
93415f9
Merge pull request #58962 from apple/egorzhdan/libstdcxx-path
egorzhdan May 19, 2022
d4baf0a
Merge pull request #58974 from lorentey/wrangler-disable-distributed_…
aschwaighofer May 19, 2022
8d66336
[Static Mirror] Gather local type extension conformance infos correctly
artemcm May 19, 2022
55fb3d1
Merge pull request #58982 from artemcm/ExtensionConformanceExtraction
artemcm May 19, 2022
de47a77
Merge pull request #58969 from lorentey/define-5.8-in-the-stdlib
lorentey May 19, 2022
d465edc
Merge remote-tracking branch 'apple/main' into katei/merge-main-2022-…
kateinoigakukun May 20, 2022
e1af515
Wasm: add test harness script to propagate environment variables
kateinoigakukun May 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ WARNING(nonmutating_without_mutable_fields,none,

ERROR(module_map_not_found, none, "module map file '%0' not found", (StringRef))

WARNING(libstdcxx_not_found, none,
"libstdc++ not found for '$0'; C++ stdlib may be unavailable",
(StringRef))

NOTE(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
NOTE(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))
NOTE(macro_not_imported_invalid_string_literal, none, "invalid string literal", ())
Expand Down
12 changes: 9 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -5547,9 +5547,15 @@ ERROR(availability_decl_only_version_newer, none,
"%0 is only available in %1 %2 or newer",
(DeclName, StringRef, llvm::VersionTuple))

WARNING(availability_decl_only_version_newer_warn, none,
"%0 is only available in %1 %2 or newer",
(DeclName, StringRef, llvm::VersionTuple))
ERROR(availability_decl_only_version_newer_for_clients, none,
"%0 is only available in %1 %2 or newer; clients of %3 may have a lower"
" deployment target",
(DeclName, StringRef, llvm::VersionTuple, ModuleDecl *))

WARNING(availability_decl_only_version_newer_for_clients_warn, none,
"%0 is only available in %1 %2 or newer; clients of %3 may have a lower"
" deployment target",
(DeclName, StringRef, llvm::VersionTuple, ModuleDecl *))

ERROR(availability_opaque_types_only_version_newer, none,
"'some' return types are only available in %0 %1 or newer",
Expand Down
4 changes: 0 additions & 4 deletions include/swift/AST/SearchPathOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ class SearchPathOptions {
/// would for a non-system header.
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.
std::vector<std::string> CandidateCompiledModules;

Expand Down
5 changes: 5 additions & 0 deletions include/swift/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion =
/// this Swift was built.
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 swift

Expand Down
28 changes: 19 additions & 9 deletions include/swift/Reflection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ class TypeRefBuilder {
using ByteReader = std::function<remote::MemoryReader::ReadBytesResult (remote::RemoteAddress, unsigned)>;
using StringReader = std::function<bool (remote::RemoteAddress, std::string &)>;
using PointerReader = std::function<llvm::Optional<remote::RemoteAbsolutePointer> (remote::RemoteAddress, unsigned)>;
using DynamicSymbolResolver = std::function<llvm::Optional<remote::RemoteAbsolutePointer> (remote::RemoteAddress)>;
using IntVariableReader = std::function<llvm::Optional<uint64_t> (std::string, unsigned)>;

// These fields are captured from the MetadataReader template passed into the
Expand All @@ -868,6 +869,7 @@ class TypeRefBuilder {
ByteReader OpaqueByteReader;
StringReader OpaqueStringReader;
PointerReader OpaquePointerReader;
DynamicSymbolResolver OpaqueDynamicSymbolResolver;
IntVariableReader OpaqueIntVariableReader;

public:
Expand Down Expand Up @@ -895,6 +897,9 @@ class TypeRefBuilder {
OpaquePointerReader([&reader](remote::RemoteAddress address, unsigned size) -> llvm::Optional<remote::RemoteAbsolutePointer> {
return reader.Reader->readPointer(address, size);
}),
OpaqueDynamicSymbolResolver([&reader](remote::RemoteAddress address) -> llvm::Optional<remote::RemoteAbsolutePointer> {
return reader.Reader->getDynamicSymbol(address);
}),
OpaqueIntVariableReader(
[&reader](std::string symbol, unsigned size) -> llvm::Optional<uint64_t> {
llvm::Optional<uint64_t> result;
Expand Down Expand Up @@ -1019,13 +1024,16 @@ class TypeRefBuilder {
ByteReader OpaqueByteReader;
StringReader OpaqueStringReader;
PointerReader OpaquePointerReader;
DynamicSymbolResolver OpaqueDynamicSymbolResolver;

ProtocolConformanceDescriptorReader(ByteReader byteReader,
StringReader stringReader,
PointerReader pointerReader)
PointerReader pointerReader,
DynamicSymbolResolver dynamicSymbolResolver)
: Error(""), OpaqueByteReader(byteReader),
OpaqueStringReader(stringReader), OpaquePointerReader(pointerReader) {
}
OpaqueStringReader(stringReader),
OpaquePointerReader(pointerReader),
OpaqueDynamicSymbolResolver(dynamicSymbolResolver) {}

llvm::Optional<std::string>
getParentContextName(uintptr_t contextDescriptorAddress) {
Expand Down Expand Up @@ -1248,17 +1256,16 @@ class TypeRefBuilder {
return llvm::None;
}
auto contextDescriptorOffset =
(const uint32_t *)contextDescriptorOffsetBytes.get();
(const int32_t *)contextDescriptorOffsetBytes.get();

// Read the type descriptor itself using the address computed above
auto contextTypeDescriptorAddress = detail::applyRelativeOffset(
(const char *)contextDescriptorFieldAddress,
(int32_t)*contextDescriptorOffset);
*contextDescriptorOffset);

// Instead of a type descriptor this may just be a symbol reference, check that first
if (auto symbol = OpaquePointerReader(remote::RemoteAddress(contextTypeDescriptorAddress),
PointerSize)) {
if (!symbol->getSymbol().empty()) {
if (auto symbol = OpaqueDynamicSymbolResolver(remote::RemoteAddress(contextTypeDescriptorAddress))) {
if (!symbol->isResolved()) {
mangledTypeName = symbol->getSymbol().str();
Demangle::Context Ctx;
auto demangledRoot =
Expand All @@ -1267,6 +1274,9 @@ class TypeRefBuilder {
typeName =
nodeToString(demangledRoot->getChild(0)->getChild(0));
return std::make_pair(mangledTypeName, typeName);
} else if (symbol->getOffset()) {
// If symbol is empty and has an offset, this is the resolved remote address
contextTypeDescriptorAddress = symbol->getOffset();
}
}

Expand Down Expand Up @@ -1462,7 +1472,7 @@ class TypeRefBuilder {
std::unordered_map<std::string, std::vector<std::string>> typeConformances;
ProtocolConformanceDescriptorReader<ObjCInteropKind, PointerSize>
conformanceReader(OpaqueByteReader, OpaqueStringReader,
OpaquePointerReader);
OpaquePointerReader, OpaqueDynamicSymbolResolver);
for (const auto &section : ReflectionInfos) {
auto ConformanceBegin = section.Conformance.startAddress();
auto ConformanceEnd = section.Conformance.endAddress();
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ class RelabelArguments final

bool diagnose(const Solution &solution, bool asNote = false) const override;

bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override;

static RelabelArguments *create(ConstraintSystem &cs,
llvm::ArrayRef<Identifier> correctLabels,
ConstraintLocator *locator);
Expand Down
4 changes: 3 additions & 1 deletion include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,15 @@ class ExtendedValidationInfo {
/// refers directly into this buffer.
/// \param requiresOSSAModules If true, necessitates the module to be
/// 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
/// compilation options serialized into the AST at build time that may be
/// necessary to load it properly.
/// \param[out] dependencies If present, will be populated with list of
/// input files the module depends on, if present in INPUT_BLOCK.
ValidationInfo validateSerializedAST(
StringRef data, bool requiresOSSAModules,
StringRef data, bool requiresOSSAModules, StringRef requiredSDK,
ExtendedValidationInfo *extendedInfo = nullptr,
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =
nullptr);
Expand Down
4 changes: 0 additions & 4 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2419,10 +2419,6 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,

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.
auto *Stdlib = Ctx.getStdlibModule(/*loadIfAbsent=*/true);
if (!Stdlib) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ASTSectionImporter/ASTSectionImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool swift::parseASTSection(MemoryBufferSerializedModuleLoader &Loader,
// headers. Iterate over all AST modules.
while (!buf.empty()) {
auto info = serialization::validateSerializedAST(
buf, Loader.isRequiredOSSAModules());
buf, Loader.isRequiredOSSAModules(), /*requiredSDK*/StringRef());

assert(info.name.size() < (2 << 10) && "name failed sanity check");

Expand Down
8 changes: 8 additions & 0 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,13 @@ StringRef getSwiftRevision() {
#endif
}

bool isCurrentCompilerTagged() {
#ifdef SWIFT_COMPILER_VERSION
return true;
#else
return false;
#endif
}

} // end namespace version
} // end namespace swift
75 changes: 31 additions & 44 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
#include "clang/Driver/Driver.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/Utils.h"
#include "clang/Index/IndexingAction.h"
Expand Down Expand Up @@ -922,19 +923,27 @@ getClangInvocationFileMapping(ASTContext &ctx) {
if (!triple.isOSLinux())
return {};

SearchPathOptions &searchPathOpts = ctx.SearchPathOpts;

Path sdkPath(searchPathOpts.getSDKPath());
if (sdkPath.empty())
sdkPath = "/";
auto clangDiags = clang::CompilerInstance::createDiagnostics(
new clang::DiagnosticOptions());
clang::driver::Driver clangDriver(ctx.ClangImporterOpts.clangPath,
triple.str(), *clangDiags);
auto cxxStdlibDirs =
clangDriver.getLibStdCxxIncludePaths(llvm::opt::InputArgList(), triple);
if (cxxStdlibDirs.empty()) {
ctx.Diags.diagnose(SourceLoc(), diag::libstdcxx_not_found, triple.str());
return {};
}
Path cxxStdlibDir(cxxStdlibDirs.front());
// VFS does not allow mapping paths that contain `../` or `./`.
llvm::sys::path::remove_dots(cxxStdlibDir, /*remove_dot_dot=*/true);

// Currently only a modulemap for libstdc++ is injected.
if (!ctx.LangOpts.EnableCXXInterop)
return {};

Path actualModuleMapPath;
Path buffer;
if (auto path = getLibStdCxxModuleMapPath(searchPathOpts, triple, buffer))
if (auto path = getLibStdCxxModuleMapPath(ctx.SearchPathOpts, triple, buffer))
actualModuleMapPath = path.getValue();
else
return {};
Expand All @@ -952,48 +961,26 @@ getClangInvocationFileMapping(ASTContext &ctx) {
llvm::sys::path::remove_filename(actualHeaderPath);
llvm::sys::path::append(actualHeaderPath, "libstdcxx.h");

Path cxxStdlibsRoot(sdkPath);
llvm::sys::path::append(cxxStdlibsRoot, "usr", "include", "c++");
if (!llvm::sys::fs::exists(cxxStdlibsRoot))
// Inject a modulemap into VFS for the libstdc++ directory.
// Only inject the module map if the module does not already exist at
// {sysroot}/usr/include/module.{map,modulemap}.
Path injectedModuleMapLegacyPath(cxxStdlibDir);
llvm::sys::path::append(injectedModuleMapLegacyPath, "module.map");
if (llvm::sys::fs::exists(injectedModuleMapLegacyPath))
return {};

// Collect all installed versions of libstdc++. We currently have no way to
// know which libstdc++ version will be used for this Clang invocation.
// TODO: extract this information from the Clang driver.
SmallVector<Path, 1> cxxStdlibDirs;
std::error_code errorCode;
for (llvm::vfs::directory_iterator
iter = ctx.SourceMgr.getFileSystem()->dir_begin(cxxStdlibsRoot,
errorCode),
endIter;
!errorCode && iter != endIter; iter = iter.increment(errorCode)) {
cxxStdlibDirs.push_back(Path(iter->path()));
}

SmallVector<std::pair<std::string, std::string>, 16> result;
// Inject a modulemap into the VFS for each of the libstdc++ versions.
for (const Path &cxxStdlibDir : cxxStdlibDirs) {
// Only inject the module map if the module does not already exist at
// {sysroot}/usr/include/module.{map,modulemap}.
Path injectedModuleMapLegacyPath(cxxStdlibDir);
llvm::sys::path::append(injectedModuleMapLegacyPath, "module.map");
if (llvm::sys::fs::exists(injectedModuleMapLegacyPath))
continue;

Path injectedModuleMapPath = cxxStdlibDir;
llvm::sys::path::append(injectedModuleMapPath, "module.modulemap");
if (llvm::sys::fs::exists(injectedModuleMapPath))
continue;
Path injectedModuleMapPath(cxxStdlibDir);
llvm::sys::path::append(injectedModuleMapPath, "module.modulemap");
if (llvm::sys::fs::exists(injectedModuleMapPath))
return {};

Path injectedHeaderPath = cxxStdlibDir;
llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h");
Path injectedHeaderPath(cxxStdlibDir);
llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h");

result.push_back(
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)});
result.push_back(
{std::string(injectedHeaderPath), std::string(actualHeaderPath)});
}
return result;
return {
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)},
{std::string(injectedHeaderPath), std::string(actualHeaderPath)},
};
}

bool ClangImporter::canReadPCH(StringRef PCHFilename) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ serialization::Status
CompilerInvocation::loadFromSerializedAST(StringRef data) {
serialization::ExtendedValidationInfo extendedInfo;
serialization::ValidationInfo info = serialization::validateSerializedAST(
data, getSILOptions().EnableOSSAModules, &extendedInfo);
data, getSILOptions().EnableOSSAModules, LangOpts.SDKName, &extendedInfo);

if (info.status != serialization::Status::Valid)
return info.status;
Expand Down Expand Up @@ -2574,7 +2574,7 @@ CompilerInvocation::setUpInputForSILTool(

auto result = serialization::validateSerializedAST(
fileBufOrErr.get()->getBuffer(), getSILOptions().EnableOSSAModules,
&extendedInfo);
LangOpts.SDKName, &extendedInfo);
bool hasSerializedAST = result.status == serialization::Status::Valid;

if (hasSerializedAST) {
Expand Down
11 changes: 7 additions & 4 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ class DiscoveredModule {
namespace path = llvm::sys::path;

static bool serializedASTLooksValid(const llvm::MemoryBuffer &buf,
bool requiresOSSAModules) {
bool requiresOSSAModules,
StringRef requiredSDK) {
auto VI = serialization::validateSerializedAST(buf.getBuffer(),
requiresOSSAModules);
requiresOSSAModules,
requiredSDK);
return VI.status == serialization::Status::Valid;
}

Expand Down Expand Up @@ -500,7 +502,7 @@ class ModuleInterfaceLoaderImpl {

LLVM_DEBUG(llvm::dbgs() << "Validating deps of " << path << "\n");
auto validationInfo = serialization::validateSerializedAST(
buf.getBuffer(), requiresOSSAModules,
buf.getBuffer(), requiresOSSAModules, ctx.LangOpts.SDKName,
/*ExtendedValidationInfo=*/nullptr, &allDeps);

if (validationInfo.status != serialization::Status::Valid) {
Expand Down Expand Up @@ -542,7 +544,8 @@ class ModuleInterfaceLoaderImpl {

// First, make sure the underlying module path exists and is valid.
auto modBuf = fs.getBufferForFile(fwd.underlyingModulePath);
if (!modBuf || !serializedASTLooksValid(*modBuf.get(), requiresOSSAModules))
if (!modBuf || !serializedASTLooksValid(*modBuf.get(), requiresOSSAModules,
ctx.LangOpts.SDKName))
return false;

// Next, check the dependencies in the forwarding file.
Expand Down
Loading