Skip to content

Commit 8ce38c6

Browse files
committed
[Playgrounds] Restore the performPlaygroundTransform() variant that takes a high-perf flag
Temporarily restore the old variant of the `performPlaygroundTransform()` that takes a boolean to determine whether to only apply high-performance playground transforms. This function is still used by LLDB and possibly other clients, and should continue to work. It can be removed once all clients have switched over to the more generic variant that takes a `PlaygroundOptionSet`.
1 parent 23f35cf commit 8ce38c6

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

include/swift/Subsystems.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,19 @@ namespace swift {
132132
void performDebuggerTestingTransform(SourceFile &SF);
133133

134134
/// Once type checking is complete, this optionally transforms the ASTs to
135-
/// insert calls to external logging functions. The specific transforms that
136-
/// are performed are controlled by `LangOptions.PlaygroundOptions`.
137-
void performPlaygroundTransform(SourceFile &SF);
135+
/// insert calls to external logging functions.
136+
///
137+
/// \param Opts The specific set of transforms that should be applied.
138+
void performPlaygroundTransform(SourceFile &SF, PlaygroundOptionSet Opts);
139+
140+
/// Once type checking is complete, this optionally transforms the ASTs to
141+
/// insert calls to external logging functions. This function is provided
142+
/// for backward compatibility with existing code; for new code, the variant
143+
/// that takes an `PlaygroundOptionSet` parameter should be used.
144+
///
145+
/// \param HighPerformance True if the playground transform should omit
146+
/// instrumentation that has a high runtime performance impact.
147+
void performPlaygroundTransform(SourceFile &SF, bool HighPerformance);
138148

139149
/// Once type checking is complete this optionally walks the ASTs to add calls
140150
/// to externally provided functions that simulate "program counter"-like

lib/Sema/PlaygroundTransform.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ class Instrumenter : InstrumenterBase {
904904

905905
} // end anonymous namespace
906906

907-
void swift::performPlaygroundTransform(SourceFile &SF) {
907+
void swift::performPlaygroundTransform(SourceFile &SF, PlaygroundOptionSet Opts) {
908908
class ExpressionFinder : public ASTWalker {
909909
private:
910910
ASTContext &ctx;
@@ -913,8 +913,8 @@ void swift::performPlaygroundTransform(SourceFile &SF) {
913913
unsigned TmpNameIndex = 0;
914914

915915
public:
916-
ExpressionFinder(ASTContext &ctx) :
917-
ctx(ctx), Options(ctx.LangOpts.PlaygroundOptions) {}
916+
ExpressionFinder(ASTContext &ctx, PlaygroundOptionSet Opts) :
917+
ctx(ctx), Options(Opts) {}
918918

919919
// FIXME: Remove this
920920
bool shouldWalkAccessorsTheOldWay() override { return true; }
@@ -954,6 +954,20 @@ void swift::performPlaygroundTransform(SourceFile &SF) {
954954
}
955955
};
956956

957-
ExpressionFinder EF(SF.getASTContext());
957+
ExpressionFinder EF(SF.getASTContext(), Opts);
958958
SF.walk(EF);
959959
}
960+
961+
/// This function is provided for backward compatibility with the old API, since
962+
/// LLDB and others call it directly, passing it a boolean to control whether to
963+
/// only apply "high performance" options. We emulate that here.
964+
void swift::performPlaygroundTransform(SourceFile &SF, bool HighPerformance) {
965+
PlaygroundOptionSet HighPerfTransformOpts;
966+
// Enable any playground options that are marked as being applicable to high
967+
// performance mode.
968+
#define PLAYGROUND_OPTION(OptionName, Description, DefaultOn, HighPerfOn) \
969+
if (HighPerfOn) \
970+
HighPerfTransformOpts.insert(PlaygroundOption::OptionName);
971+
#include "swift/Basic/PlaygroundOptions.def"
972+
swift::performPlaygroundTransform(SF, HighPerfTransformOpts);
973+
}

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
337337
// Playground transform knows to look out for PCMacro's changes and not
338338
// to playground log them.
339339
if (!Ctx.hadError() && Ctx.LangOpts.PlaygroundTransform)
340-
performPlaygroundTransform(*SF);
340+
performPlaygroundTransform(*SF, Ctx.LangOpts.PlaygroundOptions);
341341

342342
return std::make_tuple<>();
343343
}

0 commit comments

Comments
 (0)