From eae455521307a2588d324c3acd8277f0dfa77f41 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 31 Oct 2025 10:56:36 -0700 Subject: [PATCH] [CAS] Add `-no-cache-compile-job` frontend option Add a negative frontend to turn off compilation caching. This allows turn off compilation caching by just appending argument. rdar://162547707 --- include/swift/Option/Options.td | 4 ++++ lib/Frontend/CompilerInvocation.cpp | 20 ++++++++++++-------- test/CAS/cas_output_backend.swift | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 85a11d114d03b..293824a27dca2 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -2275,6 +2275,10 @@ def cache_compile_job: Flag<["-"], "cache-compile-job">, Flags<[FrontendOption, NewDriverOnlyOption]>, HelpText<"Enable compiler caching">; +def no_cache_compile_job: Flag<["-"], "no-cache-compile-job">, + Flags<[FrontendOption, NoDriverOption, HelpHidden]>, + HelpText<"Disable compiler caching">; + def cache_remarks: Flag<["-"], "Rcache-compile-job">, Flags<[FrontendOption, NewDriverOnlyOption, CacheInvariant]>, HelpText<"Show remarks for compiler caching">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 568105785a041..929652d2b47c8 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -782,7 +782,8 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, const FrontendOptions &FrontendOpts) { using namespace options; - Opts.EnableCaching |= Args.hasArg(OPT_cache_compile_job); + Opts.EnableCaching |= Args.hasFlag( + OPT_cache_compile_job, OPT_no_cache_compile_job, /*Default=*/false); Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks); Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay); if (const Arg *A = Args.getLastArg(OPT_cas_path)) @@ -2637,9 +2638,11 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, // If no style options are specified, default to Swift style, unless it is // under swift caching, which llvm style is preferred because LLVM style // replays a lot faster. - Opts.PrintedFormattingStyle = Args.hasArg(OPT_cache_compile_job) - ? DiagnosticOptions::FormattingStyle::LLVM - : DiagnosticOptions::FormattingStyle::Swift; + Opts.PrintedFormattingStyle = + Args.hasFlag(OPT_cache_compile_job, OPT_no_cache_compile_job, + /*Default=*/false) + ? DiagnosticOptions::FormattingStyle::LLVM + : DiagnosticOptions::FormattingStyle::Swift; if (const Arg *arg = Args.getLastArg(OPT_diagnostic_style)) { StringRef contents = arg->getValue(); if (contents == "llvm") { @@ -3389,6 +3392,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, const FrontendOptions &FrontendOpts, const SILOptions &SILOpts, const LangOptions &LangOpts, + const CASOptions &CASOpts, StringRef SDKPath, StringRef ResourceDir, const llvm::Triple &Triple) { @@ -3628,8 +3632,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, Opts.PrintInlineTree |= Args.hasArg(OPT_print_llvm_inline_tree); // Always producing all outputs when caching is enabled. - Opts.AlwaysCompile |= Args.hasArg(OPT_always_compile_output_files) || - Args.hasArg(OPT_cache_compile_job); + Opts.AlwaysCompile |= + Args.hasArg(OPT_always_compile_output_files) || CASOpts.EnableCaching; Opts.EnableDynamicReplacementChaining |= Args.hasArg(OPT_enable_dynamic_replacement_chaining); @@ -4204,8 +4208,8 @@ bool CompilerInvocation::parseArgs( } if (ParseIRGenArgs(IRGenOpts, ParsedArgs, Diags, FrontendOpts, SILOpts, - LangOpts, getSDKPath(), SearchPathOpts.RuntimeResourcePath, - LangOpts.Target)) { + LangOpts, CASOpts, getSDKPath(), + SearchPathOpts.RuntimeResourcePath, LangOpts.Target)) { return true; } diff --git a/test/CAS/cas_output_backend.swift b/test/CAS/cas_output_backend.swift index 0120ea00174be..65fdd212da4d5 100644 --- a/test/CAS/cas_output_backend.swift +++ b/test/CAS/cas_output_backend.swift @@ -2,6 +2,7 @@ // RUN: mkdir -p %t/cas // RUN: not %target-swift-frontend -c -cache-compile-job -cas-path %t/cas %s -o %t/test.o 2>&1 | %FileCheck %s --check-prefix=NO-CASFS +// RUN: not %target-swift-frontend -c -no-cache-compile-job -cache-compile-job -cas-path %t/cas %s -o %t/test.o 2>&1 | %FileCheck %s --check-prefix=NO-CASFS // NO-CASFS: caching is enabled without CAS file-system options // RUN: %target-swift-frontend -scan-dependencies -module-name Test -O \