Skip to content

Remove classic whole-project compiler invocations. #9332

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ class ModuleListProperties : public Properties {
bool GetUseSwiftClangImporter() const;
bool GetUseSwiftDWARFImporter() const;
bool SetUseSwiftDWARFImporter(bool new_value);
bool GetUseSwiftTypeRefTypeSystem() const;
bool SetUseSwiftTypeRefTypeSystem(bool new_value);
bool GetSwiftValidateTypeSystem() const;
SwiftModuleLoadingMode GetSwiftModuleLoadingMode() const;
bool SetSwiftModuleLoadingMode(SwiftModuleLoadingMode);

bool GetUseSwiftPreciseCompilerInvocation() const;
bool GetEnableSwiftMetadataCache() const;
uint64_t GetSwiftMetadataCacheMaxByteSize();
uint64_t GetSwiftMetadataCacheExpirationDays();
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,8 @@ class Target : public std::enable_shared_from_this<Target>,

std::optional<SwiftScratchContextReader>
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
bool create_on_demand = true);
bool create_on_demand = true,
bool for_playground = false);

/// Return whether this is the Swift REPL.
bool IsSwiftREPL();
Expand Down
6 changes: 0 additions & 6 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ let Definition = "modulelist" in {
def UseSwiftDWARFImporter: Property<"use-swift-dwarfimporter", "Boolean">,
DefaultTrue,
Desc<"Reconstruct Clang module dependencies from DWARF when debugging Swift code">;
def UseSwiftTypeRefTypeSystem: Property<"use-swift-typeref-typesystem", "Boolean">,
DefaultTrue,
Desc<"Prefer Swift Remote Mirrors over Remote AST">;
def SwiftValidateTypeSystem: Property<"swift-validate-typesystem", "Boolean">,
DefaultFalse,
Desc<"Validate all Swift typesystem queries. Used for testing an asserts-enabled LLDB only.">;
def UseSwiftPreciseCompilerInvocation: Property<"swift-precise-compiler-invocation", "Boolean">,
DefaultTrue,
Desc<"In the Swift expression evaluator, create many Swift compiler instances with the precise invocation for the current context, instead of a single compiler instance that merges all flags from the entire project.">;
def SwiftModuleLoadingMode: Property<"swift-module-loading-mode", "Enum">,
DefaultEnumValue<"eSwiftModuleLoadingModePreferSerialized">,
EnumValues<"OptionEnumValues(g_swift_module_loading_mode_enums)">,
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ bool Module::SetArchitecture(const ArchSpec &new_arch) {
#ifdef LLDB_ENABLE_SWIFT
if (auto ts =
llvm::dyn_cast_or_null<TypeSystemSwift>(type_system_or_err->get()))
ts->SetTriple(new_arch.GetTriple());
ts->SetTriple(SymbolContext(shared_from_this()), new_arch.GetTriple());
#endif // LLDB_ENABLE_SWIFT
return true;
}
Expand Down
17 changes: 0 additions & 17 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,12 @@ bool ModuleListProperties::SetUseSwiftDWARFImporter(bool new_value) {
return SetPropertyAtIndex(idx, new_value);
}

bool ModuleListProperties::GetUseSwiftTypeRefTypeSystem() const {
const uint32_t idx = ePropertyUseSwiftTypeRefTypeSystem;
return GetPropertyAtIndexAs<bool>(
idx, g_modulelist_properties[idx].default_uint_value != 0);
}

bool ModuleListProperties::GetSwiftValidateTypeSystem() const {
const uint32_t idx = ePropertySwiftValidateTypeSystem;
return GetPropertyAtIndexAs<bool>(
idx, g_modulelist_properties[idx].default_uint_value != 0);
}

bool ModuleListProperties::GetUseSwiftPreciseCompilerInvocation() const {
const uint32_t idx = ePropertyUseSwiftPreciseCompilerInvocation;
return GetPropertyAtIndexAs<bool>(
idx, g_modulelist_properties[idx].default_uint_value != 0);
}

bool ModuleListProperties::SetUseSwiftTypeRefTypeSystem(bool new_value) {
const uint32_t idx = ePropertyUseSwiftTypeRefTypeSystem;
return SetPropertyAtIndex(idx, new_value);
}

SwiftModuleLoadingMode ModuleListProperties::GetSwiftModuleLoadingMode() const {
const uint32_t idx = ePropertySwiftModuleLoadingMode;
return GetPropertyAtIndexAs<SwiftModuleLoadingMode>(
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Expression/IRExecutionUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
// BEGIN SWIFT
if (m_in_populate_symtab)
if (lldb::ModuleSP module_sp = m_jit_module_wp.lock())
images.Remove(module_sp);
images.Remove(module_sp);
// END SWIFT

SymbolContextList sc_list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ llvm::Expected<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
// When injecting a value pack or pack count into the outer
// lldb_expr function, treat it as an opaque raw pointer.
if (m_bind_generic_types == lldb::eDontBind && variable.IsUnboundPack()) {
auto swift_ast_ctx = type_system_swift->GetSwiftASTContext(&m_sc);
auto swift_ast_ctx = type_system_swift->GetSwiftASTContext(m_sc);
if (!swift_ast_ctx)
return llvm::createStringError("no typesystem for variable " +
variable.GetName().str());
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ void SwiftREPL::CompleteCode(const std::string &current_code,
type_system_or_err->get());
auto *target_swift_ast =
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
swift_ts->GetSwiftASTContext(nullptr));
swift_ts->GetSwiftASTContext(SymbolContext(
m_target.shared_from_this(), m_target.GetExecutableModule())));
m_swift_ast = target_swift_ast;
}
SwiftASTContextForExpressions *swift_ast = m_swift_ast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,25 +721,28 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
return error("couldn't start parsing - no stack frame");

ExecutionContextScope *exe_scope =
m_options.GetREPLEnabled() ? static_cast<ExecutionContextScope *>(target)
: static_cast<ExecutionContextScope *>(frame);
m_options.GetREPLEnabled() || m_options.GetPlaygroundTransformEnabled()
? static_cast<ExecutionContextScope *>(target)
: static_cast<ExecutionContextScope *>(frame);

exe_scope = exe_ctx.GetBestExecutionContextScope();
exe_scope = exe_ctx.GetBestExecutionContextScope();

m_swift_scratch_ctx = target->GetSwiftScratchContext(m_err, *exe_scope);
m_swift_scratch_ctx = target->GetSwiftScratchContext(
m_err, *exe_scope, /*create_on_demand=*/true,
m_options.GetPlaygroundTransformEnabled());
if (!m_swift_scratch_ctx)
return error("could not create a Swift scratch context: ",
m_err.AsCString());

// For playgrounds, the target triple should be used for expression
// evaluation, not the current module. This requires disabling precise
// compiler invocations.
//
// To disable precise compiler invocations, pass a null SymbolContext.
const SymbolContext *sc = nullptr;
if (!m_runs_in_playground_or_repl)
sc = &frame->GetSymbolContext(lldb::eSymbolContextFunction);

SymbolContext sc;
if (m_options.GetREPLEnabled() || m_options.GetPlaygroundTransformEnabled())
sc = SymbolContext(target->shared_from_this(),
target->GetExecutableModule());
else
sc = frame->GetSymbolContext(lldb::eSymbolContextFunction);
auto *swift_ast_ctx = m_swift_scratch_ctx->get()->GetSwiftASTContext(sc);
m_swift_ast_ctx =
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(swift_ast_ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ static std::string TranslateObjCNameToSwiftName(std::string className,
const SymbolContext *sc = nullptr;
if (swiftFrame)
sc = &swiftFrame->GetSymbolContext(eSymbolContextFunction);
auto *ctx = ts->GetSwiftASTContext(sc);
if (!sc)
return "";
auto *ctx = ts->GetSwiftASTContext(*sc);
if (!ctx)
return "";
swift::ClangImporter *imp = ctx->GetClangImporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SwiftRuntimeInstrumentedFrameRecognizer : public StackFrameRecognizer {
}
auto &sc = most_relevant_frame_sp->GetSymbolContext(
lldb::eSymbolContextFunction);
ConstString module_name = TypeSystemSwiftTypeRef::GetSwiftModuleFor(&sc);
ConstString module_name = TypeSystemSwiftTypeRef::GetSwiftModuleFor(sc);
if (!module_name)
continue;
if (module_name == swift::STDLIB_NAME)
Expand Down
166 changes: 84 additions & 82 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,22 +1350,23 @@ std::unique_ptr<Language::TypeScavenger> SwiftLanguage::GetTypeScavenger() {
std::optional<SwiftScratchContextReader> maybe_scratch_ctx =
target->GetSwiftScratchContext(error, *exe_scope,
create_on_demand);
const SymbolContext *sc = nullptr;
if (auto frame_sp = exe_scope->CalculateStackFrame())
sc = &frame_sp->GetSymbolContext(lldb::eSymbolContextFunction);
if (maybe_scratch_ctx)
if (auto scratch_ctx = maybe_scratch_ctx->get())
if (SwiftASTContext *ast_ctx =
scratch_ctx->GetSwiftASTContext(sc)) {
ConstString cs_input{input};
Mangled mangled(cs_input);
if (mangled.GuessLanguage() == eLanguageTypeSwift) {
auto candidate =
ast_ctx->GetTypeFromMangledTypename(cs_input);
if (candidate.IsValid())
results.insert(candidate);
if (auto frame_sp = exe_scope->CalculateStackFrame()) {
auto &sc =
frame_sp->GetSymbolContext(lldb::eSymbolContextFunction);
if (maybe_scratch_ctx)
if (auto scratch_ctx = maybe_scratch_ctx->get())
if (SwiftASTContext *ast_ctx =
scratch_ctx->GetSwiftASTContext(sc)) {
ConstString cs_input{input};
Mangled mangled(cs_input);
if (mangled.GuessLanguage() == eLanguageTypeSwift) {
auto candidate =
ast_ctx->GetTypeFromMangledTypename(cs_input);
if (candidate.IsValid())
results.insert(candidate);
}
}
}
}
}
}

Expand Down Expand Up @@ -1423,76 +1424,77 @@ std::unique_ptr<Language::TypeScavenger> SwiftLanguage::GetTypeScavenger() {
std::optional<SwiftScratchContextReader> maybe_scratch_ctx =
target->GetSwiftScratchContext(error, *exe_scope,
create_on_demand);
const SymbolContext *sc = nullptr;
if (auto frame_sp = exe_scope->CalculateStackFrame())
sc = &frame_sp->GetSymbolContext(lldb::eSymbolContextFunction);

if (maybe_scratch_ctx)
if (auto scratch_ctx = maybe_scratch_ctx->get())
if (SwiftASTContext *ast_ctx =
scratch_ctx->GetSwiftASTContext(sc)) {
auto iter = ast_ctx->GetModuleCache().begin(),
end = ast_ctx->GetModuleCache().end();

std::vector<llvm::StringRef> name_parts;
SplitDottedName(input, name_parts);

std::function<void(swift::ModuleDecl *)> lookup_func =
[&ast_ctx, input, name_parts,
&results](swift::ModuleDecl *module) -> void {
for (auto imported_module :
swift::namelookup::getAllImports(module)) {
auto module = imported_module.importedModule;
TypesOrDecls local_results;
ast_ctx->FindTypesOrDecls(input, module, local_results,
false);
std::optional<TypeOrDecl> candidate;
if (local_results.empty() && name_parts.size() > 1) {
size_t idx_of_deeper = 1;
// if you're looking for Swift.Int in module Swift,
// try looking for Int
if (name_parts.front() == module->getName().str()) {
candidate = ast_ctx->FindTypeOrDecl(
name_parts[1].str().c_str(), module);
idx_of_deeper = 2;
}
// this is probably the top-level name of a nested
// type String.UTF8View
else {
candidate = ast_ctx->FindTypeOrDecl(
name_parts[0].str().c_str(), module);
}
if (candidate.has_value()) {
TypesOrDecls candidates{candidate.value()};
for (; idx_of_deeper < name_parts.size();
idx_of_deeper++) {
TypesOrDecls new_candidates;
if (auto frame_sp = exe_scope->CalculateStackFrame()) {
const SymbolContext &sc =
frame_sp->GetSymbolContext(lldb::eSymbolContextFunction);
if (maybe_scratch_ctx)
if (auto scratch_ctx = maybe_scratch_ctx->get())
if (SwiftASTContext *ast_ctx =
scratch_ctx->GetSwiftASTContext(sc)) {
auto iter = ast_ctx->GetModuleCache().begin(),
end = ast_ctx->GetModuleCache().end();

std::vector<llvm::StringRef> name_parts;
SplitDottedName(input, name_parts);

std::function<void(swift::ModuleDecl *)> lookup_func =
[&ast_ctx, input, name_parts,
&results](swift::ModuleDecl *module) -> void {
for (auto imported_module :
swift::namelookup::getAllImports(module)) {
auto module = imported_module.importedModule;
TypesOrDecls local_results;
ast_ctx->FindTypesOrDecls(input, module, local_results,
false);
std::optional<TypeOrDecl> candidate;
if (local_results.empty() && name_parts.size() > 1) {
size_t idx_of_deeper = 1;
// if you're looking for Swift.Int in module Swift,
// try looking for Int
if (name_parts.front() == module->getName().str()) {
candidate = ast_ctx->FindTypeOrDecl(
name_parts[1].str().c_str(), module);
idx_of_deeper = 2;
}
// this is probably the top-level name of a nested
// type String.UTF8View
else {
candidate = ast_ctx->FindTypeOrDecl(
name_parts[0].str().c_str(), module);
}
if (candidate.has_value()) {
TypesOrDecls candidates{candidate.value()};
for (; idx_of_deeper < name_parts.size();
idx_of_deeper++) {
TypesOrDecls new_candidates;
for (auto candidate : candidates) {
ast_ctx->FindContainedTypeOrDecl(
name_parts[idx_of_deeper], candidate,
new_candidates);
}
candidates = new_candidates;
}
for (auto candidate : candidates) {
ast_ctx->FindContainedTypeOrDecl(
name_parts[idx_of_deeper], candidate,
new_candidates);
if (candidate)
results.insert(candidate);
}
candidates = new_candidates;
}
for (auto candidate : candidates) {
if (candidate)
results.insert(candidate);
}
}
} else if (local_results.size() > 0) {
for (const auto &result : local_results)
results.insert(result);
} else if (local_results.empty() && module &&
name_parts.size() == 1 &&
name_parts.front() == module->getName().str())
results.insert(
ToCompilerType(swift::ModuleType::get(module)));
}
};

for (; iter != end; iter++)
lookup_func(iter->second);
}
} else if (local_results.size() > 0) {
for (const auto &result : local_results)
results.insert(result);
} else if (local_results.empty() && module &&
name_parts.size() == 1 &&
name_parts.front() ==
module->getName().str())
results.insert(
ToCompilerType(swift::ModuleType::get(module)));
}
};

for (; iter != end; iter++)
lookup_func(iter->second);
}
}
}

return (results.size() - before);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ void SwiftLanguageRuntime::FindFunctionPointersInCall(
target.GetSwiftScratchContext(error, frame);
auto scratch_ctx = maybe_swift_ast->get();
if (scratch_ctx) {
if (SwiftASTContext *swift_ast = scratch_ctx->GetSwiftASTContext(&sc)) {
if (SwiftASTContext *swift_ast = scratch_ctx->GetSwiftASTContext(sc)) {
CompilerType function_type = swift_ast->GetTypeFromMangledTypename(
mangled_name.GetMangledName());
if (error.Success()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,7 @@ SwiftLanguageRuntimeImpl::GetConcreteType(ExecutionContextScope *exe_scope,
if (!promise_sp)
return CompilerType();

const SymbolContext *sc = &frame->GetSymbolContext(eSymbolContextFunction);
const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction);
return promise_sp->FulfillTypePromise(sc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ class SwiftLanguageRuntimeImpl {
std::optional<CompilerType> m_compiler_type;

public:
CompilerType FulfillTypePromise(const SymbolContext *sc,
CompilerType FulfillTypePromise(const SymbolContext &sc,
Status *error = nullptr);
};
typedef std::shared_ptr<MetadataPromise> MetadataPromiseSP;

MetadataPromiseSP GetMetadataPromise(const SymbolContext *sc,
MetadataPromiseSP GetMetadataPromise(const SymbolContext &sc,
lldb::addr_t addr,
ValueObject &for_object);
MetadataPromiseSP
Expand Down
Loading