Skip to content

Commit 9ec444b

Browse files
committed
Disable precise compiler invocations for playgrounds
1 parent 816ac8f commit 9ec444b

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ exe_scope = exe_ctx.GetBestExecutionContextScope();
733733

734734
const SymbolContext *sc =
735735
&frame->GetSymbolContext(lldb::eSymbolContextFunction);
736-
auto *swift_ast_ctx = m_swift_scratch_ctx->get()->GetSwiftASTContext(sc);
736+
auto *swift_ast_ctx =
737+
m_swift_scratch_ctx->get()->GetSwiftASTContext(sc, true);
737738
m_swift_ast_ctx =
738739
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(swift_ast_ctx);
739740

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,10 @@ class SwiftASTContext : public TypeSystemSwift {
223223

224224
bool SupportsLanguage(lldb::LanguageType language) override;
225225

226-
SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override {
227-
return GetTypeSystemSwiftTypeRef().GetSwiftASTContext(sc);
226+
SwiftASTContext *
227+
GetSwiftASTContext(const SymbolContext *sc,
228+
bool for_playground = false) const override {
229+
return GetTypeSystemSwiftTypeRef().GetSwiftASTContext(sc, for_playground);
228230
}
229231

230232
TypeSystemSwiftTypeRef &GetTypeSystemSwiftTypeRef() override {

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ class TypeSystemSwift : public TypeSystem {
115115

116116
const std::string &GetDescription() const { return m_description; }
117117
static LanguageSet GetSupportedLanguagesForTypes();
118-
virtual SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const = 0;
118+
virtual SwiftASTContext *
119+
GetSwiftASTContext(const SymbolContext *sc,
120+
bool for_playground = false) const = 0;
119121
virtual TypeSystemSwiftTypeRef &GetTypeSystemSwiftTypeRef() = 0;
120122
virtual const TypeSystemSwiftTypeRef &GetTypeSystemSwiftTypeRef() const = 0;
121123
virtual void SetTriple(const llvm::Triple triple) = 0;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ SwiftASTContext *TypeSystemSwiftTypeRef::GetSwiftASTContextFromExecutionContext(
18181818
}
18191819

18201820
SwiftASTContext *
1821-
TypeSystemSwiftTypeRef::GetSwiftASTContext(const SymbolContext *sc) const {
1821+
TypeSystemSwiftTypeRef::GetSwiftASTContext(const SymbolContext *sc,
1822+
bool for_playground) const {
18221823
std::lock_guard<std::mutex> guard(m_swift_ast_context_lock);
18231824
// There is only one per-module context.
18241825
const char *key = nullptr;
@@ -1843,12 +1844,16 @@ TypeSystemSwiftTypeRef::GetSwiftASTContext(const SymbolContext *sc) const {
18431844
}
18441845

18451846
SwiftASTContext *TypeSystemSwiftTypeRefForExpressions::GetSwiftASTContext(
1846-
const SymbolContext *sc) const {
1847+
const SymbolContext *sc, bool for_playground) const {
18471848
bool precise = false;
18481849
// Compute the cache key.
18491850
const char *key = nullptr;
1850-
if (sc && ModuleList::GetGlobalModuleListProperties()
1851-
.GetUseSwiftPreciseCompilerInvocation()) {
1851+
// Disable precise compiler invocations for playground expression evaluation.
1852+
// For playgrounds, the target triple should be used for expression
1853+
// evaluation, not the current module.
1854+
if (!for_playground && sc &&
1855+
ModuleList::GetGlobalModuleListProperties()
1856+
.GetUseSwiftPreciseCompilerInvocation()) {
18521857
ConstString module = GetSwiftModuleFor(sc);
18531858
key = module.GetCString();
18541859
precise = true;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
6868
~TypeSystemSwiftTypeRef();
6969
TypeSystemSwiftTypeRef(Module &module);
7070
/// Get the corresponding SwiftASTContext, and create one if necessary.
71-
SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override;
71+
SwiftASTContext *
72+
GetSwiftASTContext(const SymbolContext *sc,
73+
bool for_playground = false) const override;
7274
/// Convenience helpers.
7375
SwiftASTContext *
7476
GetSwiftASTContextFromExecutionScope(ExecutionContextScope *exe_scope) const;
@@ -529,7 +531,9 @@ class TypeSystemSwiftTypeRefForExpressions : public TypeSystemSwiftTypeRef {
529531
TypeSystemSwiftTypeRefForExpressions(lldb::LanguageType language,
530532
Target &target, Module &module);
531533

532-
SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override;
534+
SwiftASTContext *
535+
GetSwiftASTContext(const SymbolContext *sc,
536+
bool for_playground = false) const override;
533537
SwiftASTContext *
534538
GetSwiftASTContextOrNull(const SymbolContext *sc) const override;
535539
lldb::TargetWP GetTargetWP() const override { return m_target_wp; }

0 commit comments

Comments
 (0)