Skip to content

Merge 2020-06-30 into swift/tensorflow #1399

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 28 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
212faae
Remove the caching from DWARFImporterDelegate::lookupValue()
adrian-prantl Jun 20, 2020
e0b15d0
Merge pull request #1369 from adrian-prantl/64169273
adrian-prantl Jun 23, 2020
fad167d
Add a missing nullptr check.
adrian-prantl Jun 23, 2020
86a3087
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 23, 2020
781c30c
lldb tests: disable two test to unblock swift PR testing.
eeckstein Jun 24, 2020
827f16c
[CMake] Fix unified builds after swift #28003
davezarzycki Jun 24, 2020
fd7c62e
Merge pull request #1375 from eeckstein/disable-test
eeckstein Jun 24, 2020
8d19c42
Merge pull request #1377 from davezarzycki/fix_unified_builds_after_s…
davezarzycki Jun 24, 2020
2e24a46
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 24, 2020
a190d14
Merge pull request #1373 from adrian-prantl/64566000
adrian-prantl Jun 24, 2020
f9957f0
Merge commit 'a190d147ce89' from swift/release/5.3 into swift/master
Jun 24, 2020
0d03c65
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 24, 2020
6166749
Merge remote-tracking branch 'github/swift/tensorflow' into HEAD
ainu-bot Jun 25, 2020
7de78fc
[compiler-rt] Add support for arm64 macOS
cachemeifyoucan Jun 25, 2020
d110a84
Merge pull request #1384 from cachemeifyoucan/PR-compiler-rt-apple-si…
DougGregor Jun 26, 2020
4f80f3f
Merge commit '5c776495ab61' from swift/release/5.3 into swift/master
Jun 30, 2020
5c77649
Merge commit 'd110a843c5b0' from apple/stable/20200108 into swift/rel…
Jun 30, 2020
21acf0e
Don't create a Module SwiftASTContext when the stdlib is missing
vedantk Jun 29, 2020
bfa15ed
[lldb] Update DependencyTracker constructor call
hamishknight Jun 29, 2020
a1bb7ac
Merge pull request #1391 from vedantk/check-for-stdlib
vedantk Jun 30, 2020
b58f554
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 30, 2020
cfe1174
Don't create a Module SwiftASTContext when the stdlib is missing
vedantk Jun 29, 2020
224b735
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 30, 2020
4fe637e
Merge pull request #1392 from hamishknight/not-yet-over-and-out
hamishknight Jun 30, 2020
5130205
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 30, 2020
ba37712
Merge pull request #1395 from vedantk/eng/PR-57695158
vedantk Jun 30, 2020
d571ac3
Merge commit 'ba37712bb8ce' from swift/release/5.3 into swift/master
Jun 30, 2020
eb53200
Merge remote-tracking branch 'github/swift/master' into HEAD
ainu-bot Jun 30, 2020
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
47 changes: 34 additions & 13 deletions compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,46 @@ function(darwin_test_archs os valid_archs)
CACHE STRING "List of valid architectures for platform ${os}." FORCE)
endfunction()

# This function checks the host cpusubtype to see if it is post-haswell. Haswell
# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
# This function checks the host cputype/cpusubtype to filter supported
# architecture for the host OS. This is used to determine which tests are
# available for the host.
function(darwin_filter_host_archs input output)
list_intersect(tmp_var DARWIN_osx_ARCHS ${input})
execute_process(
COMMAND sysctl hw.cpusubtype
OUTPUT_VARIABLE SUBTYPE)

string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
SUBTYPE_MATCHED "${SUBTYPE}")
set(HASWELL_SUPPORTED Off)
if(SUBTYPE_MATCHED)
if(${CMAKE_MATCH_1} GREATER 7)
set(HASWELL_SUPPORTED On)
COMMAND sysctl hw.cputype
OUTPUT_VARIABLE CPUTYPE)
string(REGEX MATCH "hw.cputype: ([0-9]*)"
CPUTYPE_MATCHED "${CPUTYPE}")
set(ARM_HOST Off)
if(CPUTYPE_MATCHED)
# ARM cputype is (0x01000000 | 12) and X86(_64) is always 7.
if(${CMAKE_MATCH_1} GREATER 11)
set(ARM_HOST On)
endif()
endif()
if(NOT HASWELL_SUPPORTED)
list(REMOVE_ITEM tmp_var x86_64h)

if(ARM_HOST)
list(REMOVE_ITEM tmp_var i386)
else()
list(REMOVE_ITEM tmp_var arm64)
list(REMOVE_ITEM tmp_var arm64e)
execute_process(
COMMAND sysctl hw.cpusubtype
OUTPUT_VARIABLE SUBTYPE)
string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
SUBTYPE_MATCHED "${SUBTYPE}")

set(HASWELL_SUPPORTED Off)
if(SUBTYPE_MATCHED)
if(${CMAKE_MATCH_1} GREATER 7)
set(HASWELL_SUPPORTED On)
endif()
endif()
if(NOT HASWELL_SUPPORTED)
list(REMOVE_ITEM tmp_var x86_64h)
endif()
endif()

set(${output} ${tmp_var} PARENT_SCOPE)
endfunction()

Expand Down
23 changes: 23 additions & 0 deletions compiler-rt/cmake/builtin-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,34 @@ if(APPLE)
find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)

# Get supported architecture from SDKSettings.
function(sdk_has_arch_support sdk_path os arch has_support)
execute_process(COMMAND
/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
OUTPUT_VARIABLE SDK_SUPPORTED_ARCHS
RESULT_VARIABLE PLIST_ERROR)
if (PLIST_ERROR EQUAL 0 AND
SDK_SUPPORTED_ARCHS MATCHES " ${arch}\n")
message(STATUS "Found ${arch} support in ${sdk_path}/SDKSettings.plist")
set("${has_support}" On PARENT_SCOPE)
else()
message(STATUS "No ${arch} support in ${sdk_path}/SDKSettings.plist")
set("${has_support}" Off PARENT_SCOPE)
endif()
endfunction()

set(DARWIN_EMBEDDED_PLATFORMS)
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
# Add support for arm64 macOS if available in SDK.
foreach(arch ${ARM64})
sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
if (MACOS_ARM_SUPPORT)
list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
endif()
endforeach(arch)

if(COMPILER_RT_ENABLE_IOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
#define SANITIZER_INTERCEPT_STATFS \
(SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
#define SANITIZER_INTERCEPT_STATFS64 \
((SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID)
(((SI_MAC && !TARGET_CPU_ARM64) && !SI_IOS) || SI_LINUX_NOT_ANDROID)
#define SANITIZER_INTERCEPT_STATVFS \
(SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID)
#define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef struct user_fpregs elf_fpregset_t;
namespace __sanitizer {
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
#if !SANITIZER_IOS
#if !SANITIZER_IOS && !(SANITIZER_MAC && TARGET_CPU_ARM64)
unsigned struct_stat64_sz = sizeof(struct stat64);
#endif // !SANITIZER_IOS
unsigned struct_rusage_sz = sizeof(struct rusage);
Expand All @@ -196,7 +196,7 @@ namespace __sanitizer {
unsigned struct_regex_sz = sizeof(regex_t);
unsigned struct_regmatch_sz = sizeof(regmatch_t);

#if SANITIZER_MAC && !SANITIZER_IOS
#if (SANITIZER_MAC && !TARGET_CPU_ARM64) && !SANITIZER_IOS
unsigned struct_statfs64_sz = sizeof(struct statfs64);
#endif // SANITIZER_MAC && !SANITIZER_IOS

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ class SwiftASTContext : public TypeSystemSwift {
bool m_initialized_clang_importer_options = false;
bool m_reported_fatal_error = false;

// Whether this is a scratch or a module AST context.
/// Whether this is a scratch or a module AST context.
bool m_is_scratch_context = false;

Status m_fatal_errors;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/Swift/SwiftOptional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ lldb::ValueObjectSP lldb_private::formatters::swift::
if (IsEmpty())
return nullptr;
auto child = m_some->GetChildAtIndex(idx, true);
if (m_some->IsSyntheticChildrenGenerated())
if (child && m_some->IsSyntheticChildrenGenerated())
child->SetSyntheticChildrenGenerated(true);
return child;
}
Expand Down
111 changes: 67 additions & 44 deletions lldb/source/Symbol/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,9 @@ SwiftASTContext::SwiftASTContext(std::string description, llvm::Triple triple,
// Set the dependency tracker.
if (auto g = repro::Reproducer::Instance().GetGenerator()) {
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
m_dependency_tracker =
std::make_unique<swift::DependencyTracker>(true, fp.GetFileCollector());
m_dependency_tracker = std::make_unique<swift::DependencyTracker>(
swift::IntermoduleDepTrackingMode::IncludeSystem,
fp.GetFileCollector());
}
// rdar://53971116
m_compiler_invocation_ap->disableASTScopeLookup();
Expand Down Expand Up @@ -1556,13 +1557,21 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
return dsym;
}

/// Detect whether a Swift module was "imported" by DWARFImporter.
/// All this *really* means is that it couldn't be loaded through any
/// other mechanism.
static bool IsDWARFImported(swift::ModuleDecl &module) {
return std::any_of(module.getFiles().begin(), module.getFiles().end(),
[](swift::FileUnit *file_unit) {
return (file_unit->getKind() ==
swift::FileUnitKind::DWARFModule);
});
}

lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
Module &module,
Target *target,
bool fallback) {
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;

if (!SwiftASTContextSupportsLanguage(language))
return lldb::TypeSystemSP();

Expand All @@ -1576,16 +1585,33 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
module.GetDescription(ss, eDescriptionLevelBrief);
ss << '"' << ')';
}
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;

LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Module)");

auto logError = [&](const char *message) {
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Failed to create module context - %s",
message);
};

ArchSpec arch = module.GetArchitecture();
if (!arch.IsValid()) {
logError("invalid module architecture");
return TypeSystemSP();
}

ObjectFile *objfile = module.GetObjectFile();
if (!objfile)
return {};
if (!objfile) {
logError("no object file for module");
return TypeSystemSP();
}

ArchSpec object_arch = objfile->GetArchitecture();
if (!object_arch.IsValid())
return {};
if (!object_arch.IsValid()) {
logError("invalid objfile architecture");
return TypeSystemSP();
}

lldb::CompUnitSP main_compile_unit_sp = module.GetCompileUnitAtIndex(0);

Expand Down Expand Up @@ -1641,9 +1667,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
swift_ast_sp->GetLanguageOptions().EnableAccessControl = false;
swift_ast_sp->GetLanguageOptions().EnableTargetOSChecking = false;

if (!arch.IsValid())
return TypeSystemSP();

swift_ast_sp->SetTriple(triple, &module);

bool set_triple = false;
Expand All @@ -1654,7 +1677,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
std::string target_triple;

if (sym_file) {
bool got_serialized_options;
bool got_serialized_options = false;
llvm::SmallString<0> error;
llvm::raw_svector_ostream errs(error);
if (DeserializeAllCompilerFlags(*swift_ast_sp, module, m_description, errs,
Expand All @@ -1681,7 +1704,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
//
// This step is skipped for modules that don't have any Swift
// debug info. (We assume that a module without a .swift_ast
// section has not debuggable Swift code). This skips looking
// section has no debuggable Swift code). This skips looking
// through all the shared cache dylibs when they don't have debug
// info.
if (found_swift_modules) {
Expand Down Expand Up @@ -1784,6 +1807,20 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
swift_ast_sp->LogConfiguration();
}
}

if (swift_ast_sp->HasFatalErrors()) {
logError(swift_ast_sp->GetFatalErrors().AsCString());
return {};
}

const bool can_create = true;
swift::ModuleDecl *stdlib =
swift_ast_sp->m_ast_context_ap->getStdlibModule(can_create);
if (!stdlib || IsDWARFImported(*stdlib)) {
logError("couldn't load the Swift stdlib");
return {};
}

return swift_ast_sp;
}

Expand Down Expand Up @@ -1840,17 +1877,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
return ModuleSP();
}

/// Detect whether a Swift module was "imported" by DWARFImporter.
/// All this *really* means is that it couldn't be loaded through any
/// other mechanism.
static bool IsDWARFImported(swift::ModuleDecl &module) {
return std::any_of(module.getFiles().begin(), module.getFiles().end(),
[](swift::FileUnit *file_unit) {
return (file_unit->getKind() ==
swift::FileUnitKind::DWARFModule);
});
}

lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
Target &target,
const char *extra_options) {
Expand Down Expand Up @@ -2894,9 +2920,6 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
SwiftASTContext &m_swift_ast_ctx;
using ModuleAndName = std::pair<const char *, const char *>;
/// Caches successful lookups for the scratch context.
llvm::DenseMap<ModuleAndName, llvm::SmallVector<clang::QualType, 1>>
m_decl_cache;
std::string m_description;

/// Used to filter out types with mismatching kinds.
Expand Down Expand Up @@ -3106,27 +3129,32 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
auto *swift_ast_ctx = static_cast<SwiftASTContext *>(&*ts);
auto *dwarf_imp = static_cast<SwiftDWARFImporterDelegate *>(
swift_ast_ctx->GetDWARFImporterDelegate());
if (!dwarf_imp)
if (!dwarf_imp || dwarf_imp == this)
continue;
auto it = dwarf_imp->m_decl_cache.find(
{module_cs.GetCString(), name_cs.GetCString()});
if (it == dwarf_imp->m_decl_cache.end())

llvm::SmallVector<clang::Decl *, 2> module_results;
dwarf_imp->lookupValue(name, kind, inModule, module_results);
if (!module_results.size())
continue;

auto *from_clang_importer = swift_ast_ctx->GetClangImporter();
if (!from_clang_importer)
continue;
auto &from_ctx = from_clang_importer->getClangASTContext();
auto &to_ctx = clang_importer->getClangASTContext();
for (clang::QualType qual_type : it->second)
for (clang::Decl *decl : module_results) {
clang::QualType qual_type;
if (auto *interface = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
qual_type = {interface->getTypeForDecl(), 0};
if (auto *type = llvm::dyn_cast<clang::TypeDecl>(decl))
qual_type = {type->getTypeForDecl(), 0};
importType(qual_type, from_ctx, to_ctx, kind, results);
}
// Cut the search short after we found the first result.
if (results.size())
break;
}
LOG_PRINTF(LIBLLDB_LOG_TYPES, "%d types found in cache.", results.size());

// TODO: Otherwise, the correct thing to do is to invoke
// search() on all modules. In practice, however, this is
// prohibitively expensive, so we need to do something
// more targeted.
LOG_PRINTF(LIBLLDB_LOG_TYPES, "%d types collected.", results.size());
return;
}

Expand Down Expand Up @@ -3154,11 +3182,6 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
clang::QualType qual_type = ClangUtil::GetQualType(compiler_type);
importType(qual_type, from_ctx, to_ctx, kind, results);

// If this is a module context, cache the result for the scratch context.
if (m_swift_ast_ctx.GetModule())
m_decl_cache[{module_cs.GetCString(), name_cs.GetCString()}].push_back(
qual_type);

return true;
});

Expand Down
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/dwarfimporter/from_dylib/Foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct FromDylib {
int i;
};

9 changes: 9 additions & 0 deletions lldb/test/API/lang/swift/dwarfimporter/from_dylib/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CFoo

public struct WrappingFromDylib {
let s : FromDylib = FromDylib(i: 23)
}

private let anchor = WrappingFromDylib()

public func foo() {}
10 changes: 10 additions & 0 deletions lldb/test/API/lang/swift/dwarfimporter/from_dylib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
LD_EXTRAS = -L$(BUILDDIR) -lFoo

all: libFoo.dylib $(EXE)

include Makefile.rules

libFoo.dylib: Foo.swift
$(MAKE) MAKE_DSYM=NO VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import os

class TestSwiftDWARFImporterC(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
# This test needs a working Remote Mirrors implementation.
@skipIf(oslist=['linux', 'windows'])
def test_dwarf_importer(self):
self.build()
#os.remove(self.getBuildArtifact('Foo.swiftmodule'))
lldbutil.run_to_source_breakpoint(self, 'break here',
lldb.SBFileSpec('main.swift'))
# This type can only be imported into Swift via DWARFImporter
# and is not visible from the main module at all.
self.expect("expr -- WrappingFromDylib()", substrs=['23'])
Loading