Skip to content

[Swift Rebranch] Cherry-picking swift changes from next branch #38326

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 11 commits into from
Jul 12, 2021
2 changes: 1 addition & 1 deletion include/swift/AST/TBDGenRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TBDGenDescriptor final {
const TBDGenOptions &getOptions() const { return Opts; }
TBDGenOptions &getOptions() { return Opts; }

const llvm::DataLayout &getDataLayout() const;
const StringRef getDataLayoutString() const;
const llvm::Triple &getTarget() const;

bool operator==(const TBDGenDescriptor &other) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ ClangImporter::create(ASTContext &ctx,
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
instance.getTarget().adjust(instance.getLangOpts());
instance.getTarget().adjust(clangDiags, instance.getLangOpts());

if (importerOpts.Mode == ClangImporterOptions::Modes::EmbedBitcode)
return importer;
Expand Down
10 changes: 5 additions & 5 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,14 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,

auto cGetterSelfExpr = new (Ctx) clang::DeclRefExpr(Ctx, cGetterSelf, false,
recordType,
clang::VK_RValue,
clang::VK_PRValue,
clang::SourceLocation());
auto cGetterExpr = clang::MemberExpr::CreateImplicit(Ctx,
cGetterSelfExpr,
/*isarrow=*/ false,
fieldDecl,
fieldType,
clang::VK_RValue,
clang::VK_PRValue,
clang::OK_BitField);


Expand Down Expand Up @@ -1211,7 +1211,7 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,

auto cSetterSelfExpr = new (Ctx) clang::DeclRefExpr(Ctx, cSetterSelf, false,
recordPointerType,
clang::VK_RValue,
clang::VK_PRValue,
clang::SourceLocation());

auto cSetterMemberExpr = clang::MemberExpr::CreateImplicit(Ctx,
Expand All @@ -1224,15 +1224,15 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,

auto cSetterValueExpr = new (Ctx) clang::DeclRefExpr(Ctx, cSetterValue, false,
fieldType,
clang::VK_RValue,
clang::VK_PRValue,
clang::SourceLocation());

auto cSetterExpr = clang::BinaryOperator::Create(Ctx,
cSetterMemberExpr,
cSetterValueExpr,
clang::BO_Assign,
fieldType,
clang::VK_RValue,
clang::VK_PRValue,
clang::OK_Ordinary,
clang::SourceLocation(),
clang::FPOptionsOverride());
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,7 +3539,7 @@ void Driver::printHelp(bool ShowHidden) const {
if (!ShowHidden)
ExcludedFlagsBitmask |= HelpHidden;

getOpts().PrintHelp(llvm::outs(), Name.c_str(), "Swift compiler",
getOpts().printHelp(llvm::outs(), Name.c_str(), "Swift compiler",
IncludedFlagsBitmask, ExcludedFlagsBitmask,
/*ShowAllAliases*/false);

Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
Invocation.getFrontendOptions().PrintHelpHidden ? 0 :
llvm::opt::HelpHidden;
std::unique_ptr<llvm::opt::OptTable> Options(createSwiftOptTable());
Options->PrintHelp(llvm::outs(), displayName(MainExecutablePath).c_str(),
Options->printHelp(llvm::outs(), displayName(MainExecutablePath).c_str(),
"Swift frontend", IncludedFlagsBitmask,
ExcludedFlagsBitmask, /*ShowAllAliases*/false);
return finishDiagProcessing(0, /*verifierEnabled*/ false);
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)

// Save llvm.compiler.used and remove it.
SmallVector<llvm::Constant*, 2> UsedArray;
SmallSet<llvm::GlobalValue*, 4> UsedGlobals;
SmallVector<llvm::GlobalValue*, 4> UsedGlobals;
auto *UsedElementType =
llvm::Type::getInt8Ty(M->getContext())->getPointerTo(0);
llvm::GlobalVariable *Used =
Expand Down Expand Up @@ -1533,7 +1533,7 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,

auto *Clang = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
// Use clang's datalayout.
Module->setDataLayout(Clang->getTargetInfo().getDataLayout());
Module->setDataLayout(Clang->getTargetInfo().getDataLayoutString());

embedBitcode(Module, Opts);
if (::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, Module,
Expand Down
19 changes: 9 additions & 10 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,18 @@ static void sanityCheckStdlib(IRGenModule &IGM) {

IRGenModule::IRGenModule(IRGenerator &irgen,
std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF,
StringRef ModuleName, StringRef OutputFilename,
SourceFile *SF, StringRef ModuleName,
StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator)
: LLVMContext(new llvm::LLVMContext()),
IRGen(irgen), Context(irgen.SIL.getASTContext()),
: LLVMContext(new llvm::LLVMContext()), IRGen(irgen),
Context(irgen.SIL.getASTContext()),
// The LLVMContext (and the IGM itself) will get deleted by the IGMDeleter
// as long as the IGM is registered with the IRGenerator.
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext,
irgen.Opts,
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext, irgen.Opts,
ModuleName, PrivateDiscriminator)),
Module(*ClangCodeGen->GetModule()),
DataLayout(irgen.getClangDataLayout()),
DataLayout(irgen.getClangDataLayoutString()),
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
silConv(irgen.SIL), OutputFilename(OutputFilename),
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
Expand Down Expand Up @@ -1750,12 +1749,12 @@ llvm::Triple IRGenerator::getEffectiveClangTriple() {
return llvm::Triple(CI->getTargetInfo().getTargetOpts().Triple);
}

const llvm::DataLayout &IRGenerator::getClangDataLayout() {
const llvm::StringRef IRGenerator::getClangDataLayoutString() {
return static_cast<ClangImporter *>(
SIL.getASTContext().getClangModuleLoader())
->getTargetInfo()
.getDataLayout();
}
.getDataLayoutString();
}

TypeExpansionContext IRGenModule::getMaximalTypeExpansionContext() const {
return TypeExpansionContext::maximal(getSwiftModule(),
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class IRGenerator {
/// Return the effective triple used by clang.
llvm::Triple getEffectiveClangTriple();

const llvm::DataLayout &getClangDataLayout();
const llvm::StringRef getClangDataLayoutString();
};

class ConstantReference {
Expand Down
18 changes: 11 additions & 7 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ using llvm::BCBlockRAII;

ASTContext &SerializerBase::getASTContext() const { return M->getASTContext(); }

static StringRef withNullAsEmptyStringRef(const char *data) {
return StringRef(data ? data : "");
}

/// Used for static_assert.
static constexpr bool declIDFitsIn32Bits() {
using Int32Info = std::numeric_limits<uint32_t>;
Expand Down Expand Up @@ -5554,7 +5558,7 @@ void swift::serializeToBuffers(
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
const SILModule *M) {

assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
{
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftmodule, to buffer");
Expand All @@ -5575,7 +5579,7 @@ void swift::serializeToBuffers(
std::move(buf), options.OutputPath);
}

if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftdoc, to buffer");
llvm::SmallString<1024> buf;
Expand All @@ -5592,7 +5596,7 @@ void swift::serializeToBuffers(
std::move(buf), options.DocOutputPath);
}

if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftsourceinfo, to buffer");
llvm::SmallString<1024> buf;
Expand All @@ -5614,12 +5618,12 @@ void swift::serialize(ModuleOrSourceFile DC,
const SerializationOptions &options,
const SILModule *M,
const fine_grained_dependencies::SourceFileDepGraph *DG) {
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());

if (StringRef(options.OutputPath) == "-") {
// Special-case writing to stdout.
Serializer::writeToStream(llvm::outs(), DC, M, options, DG);
assert(StringRef::withNullAsEmpty(options.DocOutputPath).empty());
assert(withNullAsEmptyStringRef(options.DocOutputPath).empty());
return;
}

Expand All @@ -5634,7 +5638,7 @@ void swift::serialize(ModuleOrSourceFile DC,
if (hadError)
return;

if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
(void)withOutputFile(getContext(DC).Diags,
options.DocOutputPath,
[&](raw_ostream &out) {
Expand All @@ -5645,7 +5649,7 @@ void swift::serialize(ModuleOrSourceFile DC,
});
}

if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
(void)withOutputFile(getContext(DC).Diags,
options.SourceInfoOutputPath,
[&](raw_ostream &out) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
Ty = cast<IntegerLiteralInst>(&SI)->getType();
break;
case SILInstructionKind::FloatLiteralInst:
cast<IntegerLiteralInst>(&SI)->getValue().toString(Str, 16,
/*signed*/ true);
cast<FloatLiteralInst>(&SI)->getBits().toString(Str, 16,
/*signed*/ true);
Ty = cast<FloatLiteralInst>(&SI)->getType();
break;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {

TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
APIRecorder &recorder)
: TBDGenVisitor(desc.getTarget(), desc.getDataLayout(),
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
desc.getParentModule(), desc.getOptions(), recorder) {}

void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
Expand Down Expand Up @@ -390,7 +390,9 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
if (kind == SymbolKind::ObjectiveCClass) {
mangled = name;
} else {
llvm::Mangler::getNameWithPrefix(mangled, name, DataLayout);
if (!DataLayout)
DataLayout = llvm::DataLayout(DataLayoutDescription);
llvm::Mangler::getNameWithPrefix(mangled, name, *DataLayout);
}

addSymbolInternal(mangled, kind, source);
Expand Down
4 changes: 2 additions & 2 deletions lib/TBDGen/TBDGenRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ ModuleDecl *TBDGenDescriptor::getParentModule() const {
return Input.get<FileUnit *>()->getParentModule();
}

const llvm::DataLayout &TBDGenDescriptor::getDataLayout() const {
const StringRef TBDGenDescriptor::getDataLayoutString() const {
auto &ctx = getParentModule()->getASTContext();
auto *clang = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
return clang->getTargetInfo().getDataLayout();
return llvm::StringRef(clang->getTargetInfo().getDataLayoutString());
}

const llvm::Triple &TBDGenDescriptor::getTarget() const {
Expand Down
8 changes: 5 additions & 3 deletions lib/TBDGen/TBDGenVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
llvm::StringSet<> DuplicateSymbolChecker;
#endif

const llvm::DataLayout &DataLayout;
Optional<llvm::DataLayout> DataLayout = None;
const StringRef DataLayoutDescription;

UniversalLinkageInfo UniversalLinkInfo;
ModuleDecl *SwiftModule;
const TBDGenOptions &Opts;
Expand Down Expand Up @@ -167,10 +169,10 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
const AutoDiffConfig &config);

public:
TBDGenVisitor(const llvm::Triple &target, const llvm::DataLayout &dataLayout,
TBDGenVisitor(const llvm::Triple &target, const StringRef dataLayoutString,
ModuleDecl *swiftModule, const TBDGenOptions &opts,
APIRecorder &recorder)
: DataLayout(dataLayout),
: DataLayoutDescription(dataLayoutString),
UniversalLinkInfo(target, opts.HasMultipleIGMs, /*forcePublic*/ false),
SwiftModule(swiftModule), Opts(opts), recorder(recorder),
previousInstallNameMap(parsePreviousModuleInstallNameMap()) {}
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,6 @@ void TestOptions::printHelp(bool ShowHidden) const {

TestOptTable Table;

Table.PrintHelp(llvm::outs(), "sourcekitd-test [options] <inputs>",
Table.printHelp(llvm::outs(), "sourcekitd-test [options] <inputs>",
"SourceKit Testing Tool", ShowHidden);
}
2 changes: 1 addition & 1 deletion tools/driver/autolink_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AutolinkExtractInvocation {
if (ParsedArgs.getLastArg(OPT_help)) {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
"Swift Autolink Extract", options::AutolinkExtractOption,
0, /*ShowAllAliases*/false);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/modulewrap_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ModuleWrapInvocation {
if (ParsedArgs.getLastArg(OPT_help)) {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
"Swift Module Wrapper", options::ModuleWrapOption, 0,
/*ShowAllAliases*/false);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/swift_api_digester_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,7 @@ class SwiftAPIDigesterInvocation {
void printHelp() {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(), "Swift API Digester",
Table->printHelp(llvm::outs(), ExecutableName.c_str(), "Swift API Digester",
/*IncludedFlagsBitmask*/ SwiftAPIDigesterOption,
/*ExcludedFlagsBitmask*/ 0,
/*ShowAllAliases*/ false);
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/swift_api_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SwiftAPIExtractInvocation {
if (ParsedArgs.getLastArg(OPT_help)) {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
"Swift API Extract", options::SwiftAPIExtractOption, 0,
/*ShowAllAliases*/ false);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/swift_indent_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SwiftIndentInvocation {
if (ParsedArgs.getLastArg(OPT_help)) {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
"Swift Format Tool", options::SwiftIndentOption, 0,
/*ShowAllAliases*/false);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
if (ParsedArgs.getLastArg(OPT_help) || Args.empty()) {
std::string ExecutableName =
llvm::sys::path::stem(MainExecutablePath).str();
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
"Swift Symbol Graph Extractor",
SwiftSymbolGraphExtractOption, 0,
/*ShowAllAliases*/ false);
Expand Down
3 changes: 2 additions & 1 deletion tools/swift-syntax-parser-test/swift-syntax-parser-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#include "swift/Basic/LLVM.h"
#include "swift/Basic/LLVMInitialize.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Timer.h"

using namespace swift;
using namespace llvm;
Expand Down