Skip to content

Commit 8773be3

Browse files
Merge pull request #4579 from swiftwasm/katei/merge-main-2022-05-20
Merge main 2022-05-20
2 parents a84fafb + e1af515 commit 8773be3

File tree

57 files changed

+1272
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1272
-657
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ WARNING(nonmutating_without_mutable_fields,none,
117117

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

120+
WARNING(libstdcxx_not_found, none,
121+
"libstdc++ not found for '$0'; C++ stdlib may be unavailable",
122+
(StringRef))
123+
120124
NOTE(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
121125
NOTE(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))
122126
NOTE(macro_not_imported_invalid_string_literal, none, "invalid string literal", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5547,9 +5547,15 @@ ERROR(availability_decl_only_version_newer, none,
55475547
"%0 is only available in %1 %2 or newer",
55485548
(DeclName, StringRef, llvm::VersionTuple))
55495549

5550-
WARNING(availability_decl_only_version_newer_warn, none,
5551-
"%0 is only available in %1 %2 or newer",
5552-
(DeclName, StringRef, llvm::VersionTuple))
5550+
ERROR(availability_decl_only_version_newer_for_clients, none,
5551+
"%0 is only available in %1 %2 or newer; clients of %3 may have a lower"
5552+
" deployment target",
5553+
(DeclName, StringRef, llvm::VersionTuple, ModuleDecl *))
5554+
5555+
WARNING(availability_decl_only_version_newer_for_clients_warn, none,
5556+
"%0 is only available in %1 %2 or newer; clients of %3 may have a lower"
5557+
" deployment target",
5558+
(DeclName, StringRef, llvm::VersionTuple, ModuleDecl *))
55535559

55545560
ERROR(availability_opaque_types_only_version_newer, none,
55555561
"'some' return types are only available in %0 %1 or newer",

include/swift/AST/SearchPathOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,6 @@ class SearchPathOptions {
327327
/// would for a non-system header.
328328
bool DisableModulesValidateSystemDependencies = false;
329329

330-
/// Enforce loading only serialized modules built with the same SDK
331-
/// as the context loading it.
332-
bool EnableSameSDKCheck = true;
333-
334330
/// A set of compiled modules that may be ready to use.
335331
std::vector<std::string> CandidateCompiledModules;
336332

include/swift/Basic/Version.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion =
184184
/// this Swift was built.
185185
StringRef getSwiftRevision();
186186

187+
/// Is the running compiler built with a version tag for distribution?
188+
/// When true, \c Version::getCurrentCompilerVersion returns a valid version
189+
/// and \c getSwiftRevision returns the version tuple in string format.
190+
bool isCurrentCompilerTagged();
191+
187192
} // end namespace version
188193
} // end namespace swift
189194

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ class TypeRefBuilder {
855855
using ByteReader = std::function<remote::MemoryReader::ReadBytesResult (remote::RemoteAddress, unsigned)>;
856856
using StringReader = std::function<bool (remote::RemoteAddress, std::string &)>;
857857
using PointerReader = std::function<llvm::Optional<remote::RemoteAbsolutePointer> (remote::RemoteAddress, unsigned)>;
858+
using DynamicSymbolResolver = std::function<llvm::Optional<remote::RemoteAbsolutePointer> (remote::RemoteAddress)>;
858859
using IntVariableReader = std::function<llvm::Optional<uint64_t> (std::string, unsigned)>;
859860

860861
// These fields are captured from the MetadataReader template passed into the
@@ -868,6 +869,7 @@ class TypeRefBuilder {
868869
ByteReader OpaqueByteReader;
869870
StringReader OpaqueStringReader;
870871
PointerReader OpaquePointerReader;
872+
DynamicSymbolResolver OpaqueDynamicSymbolResolver;
871873
IntVariableReader OpaqueIntVariableReader;
872874

873875
public:
@@ -895,6 +897,9 @@ class TypeRefBuilder {
895897
OpaquePointerReader([&reader](remote::RemoteAddress address, unsigned size) -> llvm::Optional<remote::RemoteAbsolutePointer> {
896898
return reader.Reader->readPointer(address, size);
897899
}),
900+
OpaqueDynamicSymbolResolver([&reader](remote::RemoteAddress address) -> llvm::Optional<remote::RemoteAbsolutePointer> {
901+
return reader.Reader->getDynamicSymbol(address);
902+
}),
898903
OpaqueIntVariableReader(
899904
[&reader](std::string symbol, unsigned size) -> llvm::Optional<uint64_t> {
900905
llvm::Optional<uint64_t> result;
@@ -1019,13 +1024,16 @@ class TypeRefBuilder {
10191024
ByteReader OpaqueByteReader;
10201025
StringReader OpaqueStringReader;
10211026
PointerReader OpaquePointerReader;
1027+
DynamicSymbolResolver OpaqueDynamicSymbolResolver;
10221028

10231029
ProtocolConformanceDescriptorReader(ByteReader byteReader,
10241030
StringReader stringReader,
1025-
PointerReader pointerReader)
1031+
PointerReader pointerReader,
1032+
DynamicSymbolResolver dynamicSymbolResolver)
10261033
: Error(""), OpaqueByteReader(byteReader),
1027-
OpaqueStringReader(stringReader), OpaquePointerReader(pointerReader) {
1028-
}
1034+
OpaqueStringReader(stringReader),
1035+
OpaquePointerReader(pointerReader),
1036+
OpaqueDynamicSymbolResolver(dynamicSymbolResolver) {}
10291037

10301038
llvm::Optional<std::string>
10311039
getParentContextName(uintptr_t contextDescriptorAddress) {
@@ -1248,17 +1256,16 @@ class TypeRefBuilder {
12481256
return llvm::None;
12491257
}
12501258
auto contextDescriptorOffset =
1251-
(const uint32_t *)contextDescriptorOffsetBytes.get();
1259+
(const int32_t *)contextDescriptorOffsetBytes.get();
12521260

12531261
// Read the type descriptor itself using the address computed above
12541262
auto contextTypeDescriptorAddress = detail::applyRelativeOffset(
12551263
(const char *)contextDescriptorFieldAddress,
1256-
(int32_t)*contextDescriptorOffset);
1264+
*contextDescriptorOffset);
12571265

12581266
// Instead of a type descriptor this may just be a symbol reference, check that first
1259-
if (auto symbol = OpaquePointerReader(remote::RemoteAddress(contextTypeDescriptorAddress),
1260-
PointerSize)) {
1261-
if (!symbol->getSymbol().empty()) {
1267+
if (auto symbol = OpaqueDynamicSymbolResolver(remote::RemoteAddress(contextTypeDescriptorAddress))) {
1268+
if (!symbol->isResolved()) {
12621269
mangledTypeName = symbol->getSymbol().str();
12631270
Demangle::Context Ctx;
12641271
auto demangledRoot =
@@ -1267,6 +1274,9 @@ class TypeRefBuilder {
12671274
typeName =
12681275
nodeToString(demangledRoot->getChild(0)->getChild(0));
12691276
return std::make_pair(mangledTypeName, typeName);
1277+
} else if (symbol->getOffset()) {
1278+
// If symbol is empty and has an offset, this is the resolved remote address
1279+
contextTypeDescriptorAddress = symbol->getOffset();
12701280
}
12711281
}
12721282

@@ -1462,7 +1472,7 @@ class TypeRefBuilder {
14621472
std::unordered_map<std::string, std::vector<std::string>> typeConformances;
14631473
ProtocolConformanceDescriptorReader<ObjCInteropKind, PointerSize>
14641474
conformanceReader(OpaqueByteReader, OpaqueStringReader,
1465-
OpaquePointerReader);
1475+
OpaquePointerReader, OpaqueDynamicSymbolResolver);
14661476
for (const auto &section : ReflectionInfos) {
14671477
auto ConformanceBegin = section.Conformance.startAddress();
14681478
auto ConformanceEnd = section.Conformance.endAddress();

include/swift/Sema/CSFix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ class RelabelArguments final
536536

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

539+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override;
540+
539541
static RelabelArguments *create(ConstraintSystem &cs,
540542
llvm::ArrayRef<Identifier> correctLabels,
541543
ConstraintLocator *locator);

include/swift/Serialization/Validation.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ class ExtendedValidationInfo {
196196
/// refers directly into this buffer.
197197
/// \param requiresOSSAModules If true, necessitates the module to be
198198
/// compiled with -enable-ossa-modules.
199+
/// \param requiredSDK If not empty, only accept modules built with
200+
/// a compatible SDK. The StringRef represents the canonical SDK name.
199201
/// \param[out] extendedInfo If present, will be populated with additional
200202
/// compilation options serialized into the AST at build time that may be
201203
/// necessary to load it properly.
202204
/// \param[out] dependencies If present, will be populated with list of
203205
/// input files the module depends on, if present in INPUT_BLOCK.
204206
ValidationInfo validateSerializedAST(
205-
StringRef data, bool requiresOSSAModules,
207+
StringRef data, bool requiresOSSAModules, StringRef requiredSDK,
206208
ExtendedValidationInfo *extendedInfo = nullptr,
207209
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =
208210
nullptr);

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,10 +2419,6 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
24192419

24202420
auto &Ctx = CI.getASTContext();
24212421

2422-
// Don't check if the stdlib was build with the same SDK as what is loaded
2423-
// here as some tests rely on using a different stdlib.
2424-
Ctx.SearchPathOpts.EnableSameSDKCheck = false;
2425-
24262422
// Load standard library so that Clang importer can use it.
24272423
auto *Stdlib = Ctx.getStdlibModule(/*loadIfAbsent=*/true);
24282424
if (!Stdlib) {

lib/ASTSectionImporter/ASTSectionImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool swift::parseASTSection(MemoryBufferSerializedModuleLoader &Loader,
3636
// headers. Iterate over all AST modules.
3737
while (!buf.empty()) {
3838
auto info = serialization::validateSerializedAST(
39-
buf, Loader.isRequiredOSSAModules());
39+
buf, Loader.isRequiredOSSAModules(), /*requiredSDK*/StringRef());
4040

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

lib/Basic/Version.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,5 +446,13 @@ StringRef getSwiftRevision() {
446446
#endif
447447
}
448448

449+
bool isCurrentCompilerTagged() {
450+
#ifdef SWIFT_COMPILER_VERSION
451+
return true;
452+
#else
453+
return false;
454+
#endif
455+
}
456+
449457
} // end namespace version
450458
} // end namespace swift

lib/ClangImporter/ClangImporter.cpp

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "clang/Basic/TargetInfo.h"
5353
#include "clang/Basic/Version.h"
5454
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
55+
#include "clang/Driver/Driver.h"
5556
#include "clang/Frontend/FrontendActions.h"
5657
#include "clang/Frontend/Utils.h"
5758
#include "clang/Index/IndexingAction.h"
@@ -922,19 +923,27 @@ getClangInvocationFileMapping(ASTContext &ctx) {
922923
if (!triple.isOSLinux())
923924
return {};
924925

925-
SearchPathOptions &searchPathOpts = ctx.SearchPathOpts;
926-
927-
Path sdkPath(searchPathOpts.getSDKPath());
928-
if (sdkPath.empty())
929-
sdkPath = "/";
926+
auto clangDiags = clang::CompilerInstance::createDiagnostics(
927+
new clang::DiagnosticOptions());
928+
clang::driver::Driver clangDriver(ctx.ClangImporterOpts.clangPath,
929+
triple.str(), *clangDiags);
930+
auto cxxStdlibDirs =
931+
clangDriver.getLibStdCxxIncludePaths(llvm::opt::InputArgList(), triple);
932+
if (cxxStdlibDirs.empty()) {
933+
ctx.Diags.diagnose(SourceLoc(), diag::libstdcxx_not_found, triple.str());
934+
return {};
935+
}
936+
Path cxxStdlibDir(cxxStdlibDirs.front());
937+
// VFS does not allow mapping paths that contain `../` or `./`.
938+
llvm::sys::path::remove_dots(cxxStdlibDir, /*remove_dot_dot=*/true);
930939

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

935944
Path actualModuleMapPath;
936945
Path buffer;
937-
if (auto path = getLibStdCxxModuleMapPath(searchPathOpts, triple, buffer))
946+
if (auto path = getLibStdCxxModuleMapPath(ctx.SearchPathOpts, triple, buffer))
938947
actualModuleMapPath = path.getValue();
939948
else
940949
return {};
@@ -952,48 +961,26 @@ getClangInvocationFileMapping(ASTContext &ctx) {
952961
llvm::sys::path::remove_filename(actualHeaderPath);
953962
llvm::sys::path::append(actualHeaderPath, "libstdcxx.h");
954963

955-
Path cxxStdlibsRoot(sdkPath);
956-
llvm::sys::path::append(cxxStdlibsRoot, "usr", "include", "c++");
957-
if (!llvm::sys::fs::exists(cxxStdlibsRoot))
964+
// Inject a modulemap into VFS for the libstdc++ directory.
965+
// Only inject the module map if the module does not already exist at
966+
// {sysroot}/usr/include/module.{map,modulemap}.
967+
Path injectedModuleMapLegacyPath(cxxStdlibDir);
968+
llvm::sys::path::append(injectedModuleMapLegacyPath, "module.map");
969+
if (llvm::sys::fs::exists(injectedModuleMapLegacyPath))
958970
return {};
959971

960-
// Collect all installed versions of libstdc++. We currently have no way to
961-
// know which libstdc++ version will be used for this Clang invocation.
962-
// TODO: extract this information from the Clang driver.
963-
SmallVector<Path, 1> cxxStdlibDirs;
964-
std::error_code errorCode;
965-
for (llvm::vfs::directory_iterator
966-
iter = ctx.SourceMgr.getFileSystem()->dir_begin(cxxStdlibsRoot,
967-
errorCode),
968-
endIter;
969-
!errorCode && iter != endIter; iter = iter.increment(errorCode)) {
970-
cxxStdlibDirs.push_back(Path(iter->path()));
971-
}
972-
973-
SmallVector<std::pair<std::string, std::string>, 16> result;
974-
// Inject a modulemap into the VFS for each of the libstdc++ versions.
975-
for (const Path &cxxStdlibDir : cxxStdlibDirs) {
976-
// Only inject the module map if the module does not already exist at
977-
// {sysroot}/usr/include/module.{map,modulemap}.
978-
Path injectedModuleMapLegacyPath(cxxStdlibDir);
979-
llvm::sys::path::append(injectedModuleMapLegacyPath, "module.map");
980-
if (llvm::sys::fs::exists(injectedModuleMapLegacyPath))
981-
continue;
982-
983-
Path injectedModuleMapPath = cxxStdlibDir;
984-
llvm::sys::path::append(injectedModuleMapPath, "module.modulemap");
985-
if (llvm::sys::fs::exists(injectedModuleMapPath))
986-
continue;
972+
Path injectedModuleMapPath(cxxStdlibDir);
973+
llvm::sys::path::append(injectedModuleMapPath, "module.modulemap");
974+
if (llvm::sys::fs::exists(injectedModuleMapPath))
975+
return {};
987976

988-
Path injectedHeaderPath = cxxStdlibDir;
989-
llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h");
977+
Path injectedHeaderPath(cxxStdlibDir);
978+
llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h");
990979

991-
result.push_back(
992-
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)});
993-
result.push_back(
994-
{std::string(injectedHeaderPath), std::string(actualHeaderPath)});
995-
}
996-
return result;
980+
return {
981+
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)},
982+
{std::string(injectedHeaderPath), std::string(actualHeaderPath)},
983+
};
997984
}
998985

999986
bool ClangImporter::canReadPCH(StringRef PCHFilename) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ serialization::Status
25382538
CompilerInvocation::loadFromSerializedAST(StringRef data) {
25392539
serialization::ExtendedValidationInfo extendedInfo;
25402540
serialization::ValidationInfo info = serialization::validateSerializedAST(
2541-
data, getSILOptions().EnableOSSAModules, &extendedInfo);
2541+
data, getSILOptions().EnableOSSAModules, LangOpts.SDKName, &extendedInfo);
25422542

25432543
if (info.status != serialization::Status::Valid)
25442544
return info.status;
@@ -2574,7 +2574,7 @@ CompilerInvocation::setUpInputForSILTool(
25742574

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

25802580
if (hasSerializedAST) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ class DiscoveredModule {
200200
namespace path = llvm::sys::path;
201201

202202
static bool serializedASTLooksValid(const llvm::MemoryBuffer &buf,
203-
bool requiresOSSAModules) {
203+
bool requiresOSSAModules,
204+
StringRef requiredSDK) {
204205
auto VI = serialization::validateSerializedAST(buf.getBuffer(),
205-
requiresOSSAModules);
206+
requiresOSSAModules,
207+
requiredSDK);
206208
return VI.status == serialization::Status::Valid;
207209
}
208210

@@ -500,7 +502,7 @@ class ModuleInterfaceLoaderImpl {
500502

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

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

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

548551
// Next, check the dependencies in the forwarding file.

0 commit comments

Comments
 (0)