Skip to content

Commit 4b676ad

Browse files
authored
Merge pull request #31377 from hamishknight/move-reduce
2 parents c51b86e + 9fe475f commit 4b676ad

File tree

8 files changed

+70
-80
lines changed

8 files changed

+70
-80
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,27 @@ namespace swift {
139139
/// Allow throwing call expressions without annotation with 'try'.
140140
bool EnableThrowWithoutTry = false;
141141

142+
/// If set, inserts instrumentation useful for testing the debugger.
143+
bool DebuggerTestingTransform = false;
144+
145+
/// Indicates whether the AST should be instrumented to simulate a
146+
/// debugger's program counter. Similar to the PlaygroundTransform, this
147+
/// will instrument the AST with function calls that get called when you
148+
/// would see a program counter move in a debugger. To adopt this implement
149+
/// the __builtin_pc_before and __builtin_pc_after functions.
150+
bool PCMacro = false;
151+
142152
/// Enable features useful for running playgrounds.
143153
// FIXME: This should probably be limited to the particular SourceFile.
144154
bool Playground = false;
145155

156+
/// Indicates whether the playground transformation should be applied.
157+
bool PlaygroundTransform = false;
158+
159+
/// Indicates whether the playground transformation should omit
160+
/// instrumentation that has a high runtime performance impact.
161+
bool PlaygroundHighPerformance = false;
162+
146163
/// Keep comments during lexing and attach them to declarations.
147164
bool AttachCommentsToDecls = false;
148165

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ class CompilerInstance {
671671
ImplicitImportInfo getImplicitImportInfo() const;
672672

673673
void performSemaUpTo(SourceFile::ASTStage_t LimitStage);
674-
void parseAndCheckTypesUpTo(SourceFile::ASTStage_t LimitStage);
675674

676675
/// Return true if had load error
677676
bool parsePartialModulesAndInputFiles();

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ class FrontendOptions {
154154
/// the module.
155155
bool CheckOnoneSupportCompleteness = false;
156156

157-
/// If set, inserts instrumentation useful for testing the debugger.
158-
bool DebuggerTestingTransform = false;
159-
160157
/// If set, dumps wall time taken to check each function body to llvm::errs().
161158
bool DebugTimeFunctionBodies = false;
162159

@@ -223,20 +220,6 @@ class FrontendOptions {
223220
/// termination.
224221
bool PrintClangStats = false;
225222

226-
/// Indicates whether the playground transformation should be applied.
227-
bool PlaygroundTransform = false;
228-
229-
/// Indicates whether the AST should be instrumented to simulate a debugger's
230-
/// program counter. Similar to the PlaygroundTransform, this will instrument
231-
/// the AST with function calls that get called when you would see a program
232-
/// counter move in a debugger. To adopt this implement the
233-
/// __builtin_pc_before and __builtin_pc_after functions.
234-
bool PCMacro = false;
235-
236-
/// Indicates whether the playground transformation should omit
237-
/// instrumentation that has a high runtime performance impact.
238-
bool PlaygroundHighPerformance = false;
239-
240223
/// Indicates whether standard help should be shown.
241224
bool PrintHelp = false;
242225

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ bool ArgsToFrontendOptionsConverter::convert(
103103

104104
Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);
105105

106-
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
107-
108-
computePlaygroundOptions();
109-
110-
// This can be enabled independently of the playground transform.
111-
Opts.PCMacro |= Args.hasArg(OPT_pc_macro);
112-
113106
Opts.ParseStdlib |= Args.hasArg(OPT_parse_stdlib);
114107

115108
Opts.IgnoreSwiftSourceInfo |= Args.hasArg(OPT_ignore_module_source_info);
@@ -261,15 +254,6 @@ void ArgsToFrontendOptionsConverter::computeTBDOptions() {
261254
}
262255
}
263256

264-
void ArgsToFrontendOptionsConverter::computePlaygroundOptions() {
265-
using namespace options;
266-
Opts.PlaygroundTransform |= Args.hasArg(OPT_playground);
267-
if (Args.hasArg(OPT_disable_playground_transform))
268-
Opts.PlaygroundTransform = false;
269-
Opts.PlaygroundHighPerformance |=
270-
Args.hasArg(OPT_playground_high_performance);
271-
}
272-
273257
void ArgsToFrontendOptionsConverter::computeHelpOptions() {
274258
using namespace options;
275259
if (const Arg *A = Args.getLastArg(OPT_help, OPT_help_hidden)) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,19 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
451451
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
452452
if (Opts.DebuggerSupport)
453453
Opts.EnableDollarIdentifiers = true;
454+
455+
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
456+
454457
Opts.Playground |= Args.hasArg(OPT_playground);
458+
Opts.PlaygroundTransform |= Args.hasArg(OPT_playground);
459+
if (Args.hasArg(OPT_disable_playground_transform))
460+
Opts.PlaygroundTransform = false;
461+
Opts.PlaygroundHighPerformance |=
462+
Args.hasArg(OPT_playground_high_performance);
463+
464+
// This can be enabled independently of the playground transform.
465+
Opts.PCMacro |= Args.hasArg(OPT_pc_macro);
466+
455467
Opts.InferImportAsMember |= Args.hasArg(OPT_enable_infer_import_as_member);
456468

457469
Opts.EnableThrowWithoutTry |= Args.hasArg(OPT_enable_throw_without_try);

lib/Frontend/Frontend.cpp

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -794,32 +794,6 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
794794
MainBufferID);
795795
}
796796

797-
parseAndCheckTypesUpTo(LimitStage);
798-
}
799-
800-
bool CompilerInstance::loadStdlib() {
801-
FrontendStatsTracer tracer(getStatsReporter(), "load-stdlib");
802-
ModuleDecl *M = Context->getStdlibModule(true);
803-
804-
if (!M) {
805-
Diagnostics.diagnose(SourceLoc(), diag::error_stdlib_not_found,
806-
Invocation.getTargetTriple());
807-
return false;
808-
}
809-
810-
// If we failed to load, we should have already diagnosed
811-
if (M->failedToLoad()) {
812-
assert(Diagnostics.hadAnyError() &&
813-
"Module failed to load but nothing was diagnosed?");
814-
return false;
815-
}
816-
return true;
817-
}
818-
819-
void CompilerInstance::parseAndCheckTypesUpTo(
820-
SourceFile::ASTStage_t limitStage) {
821-
FrontendStatsTracer tracer(getStatsReporter(), "parse-and-check-types");
822-
823797
bool hadLoadError = parsePartialModulesAndInputFiles();
824798
if (hadLoadError)
825799
return;
@@ -833,7 +807,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
833807
MainModule->setHasResolvedImports();
834808

835809
forEachFileToTypeCheck([&](SourceFile &SF) {
836-
if (limitStage == SourceFile::ImportsResolved) {
810+
if (LimitStage == SourceFile::ImportsResolved) {
837811
bindExtensions(SF);
838812
return;
839813
}
@@ -846,28 +820,35 @@ void CompilerInstance::parseAndCheckTypesUpTo(
846820
SILParserState SILContext(TheSILModule.get());
847821
parseSourceFileSIL(SF, &SILContext);
848822
}
849-
850-
auto &opts = Invocation.getFrontendOptions();
851-
if (!Context->hadError() && opts.DebuggerTestingTransform)
852-
performDebuggerTestingTransform(SF);
853-
854-
if (!Context->hadError() && opts.PCMacro)
855-
performPCMacro(SF);
856-
857-
// Playground transform knows to look out for PCMacro's changes and not
858-
// to playground log them.
859-
if (!Context->hadError() && opts.PlaygroundTransform)
860-
performPlaygroundTransform(SF, opts.PlaygroundHighPerformance);
861823
});
862824

863825
// If the limiting AST stage is import resolution, we're done.
864-
if (limitStage <= SourceFile::ImportsResolved) {
826+
if (LimitStage <= SourceFile::ImportsResolved) {
865827
return;
866828
}
867829

868830
finishTypeChecking();
869831
}
870832

833+
bool CompilerInstance::loadStdlib() {
834+
FrontendStatsTracer tracer(getStatsReporter(), "load-stdlib");
835+
ModuleDecl *M = Context->getStdlibModule(true);
836+
837+
if (!M) {
838+
Diagnostics.diagnose(SourceLoc(), diag::error_stdlib_not_found,
839+
Invocation.getTargetTriple());
840+
return false;
841+
}
842+
843+
// If we failed to load, we should have already diagnosed
844+
if (M->failedToLoad()) {
845+
assert(Diagnostics.hadAnyError() &&
846+
"Module failed to load but nothing was diagnosed?");
847+
return false;
848+
}
849+
return true;
850+
}
851+
871852
bool CompilerInstance::parsePartialModulesAndInputFiles() {
872853
FrontendStatsTracer tracer(getStatsReporter(),
873854
"parse-partial-modules-and-input-files");

lib/Sema/TypeChecker.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
382382
performWholeModuleTypeChecking(*SF);
383383
}
384384

385+
// Perform various AST transforms we've been asked to perform.
386+
if (!Ctx.hadError() && Ctx.LangOpts.DebuggerTestingTransform)
387+
performDebuggerTestingTransform(*SF);
388+
389+
if (!Ctx.hadError() && Ctx.LangOpts.PCMacro)
390+
performPCMacro(*SF);
391+
392+
// Playground transform knows to look out for PCMacro's changes and not
393+
// to playground log them.
394+
if (!Ctx.hadError() && Ctx.LangOpts.PlaygroundTransform)
395+
performPlaygroundTransform(*SF, Ctx.LangOpts.PlaygroundHighPerformance);
396+
385397
return std::make_tuple<>();
386398
}
387399

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,21 @@ bool SwiftASTManager::initCompilerInvocation(
520520
ImporterOpts.DetailedPreprocessingRecord = true;
521521

522522
assert(!Invocation.getModuleName().empty());
523-
Invocation.getLangOptions().AttachCommentsToDecls = true;
524-
Invocation.getLangOptions().DiagnosticsEditorMode = true;
525-
Invocation.getLangOptions().CollectParsedToken = true;
526-
auto &FrontendOpts = Invocation.getFrontendOptions();
527-
if (FrontendOpts.PlaygroundTransform) {
523+
524+
auto &LangOpts = Invocation.getLangOptions();
525+
LangOpts.AttachCommentsToDecls = true;
526+
LangOpts.DiagnosticsEditorMode = true;
527+
LangOpts.CollectParsedToken = true;
528+
if (LangOpts.PlaygroundTransform) {
528529
// The playground instrumenter changes the AST in ways that disrupt the
529530
// SourceKit functionality. Since we don't need the instrumenter, and all we
530531
// actually need is the playground semantics visible to the user, like
531532
// silencing the "expression resolves to an unused l-value" error, disable it.
532-
FrontendOpts.PlaygroundTransform = false;
533+
LangOpts.PlaygroundTransform = false;
533534
}
534535

535536
// Disable the index-store functionality for the sourcekitd requests.
537+
auto &FrontendOpts = Invocation.getFrontendOptions();
536538
FrontendOpts.IndexStorePath.clear();
537539
ImporterOpts.IndexStorePath.clear();
538540

0 commit comments

Comments
 (0)