From 289b812a14c4035145ff20850d487e2bc0945b2a Mon Sep 17 00:00:00 2001 From: Zak Kent Date: Thu, 10 Aug 2023 12:59:42 -0700 Subject: [PATCH] [Immediate] Add frontend option for lazy compilation --- include/swift/Basic/Features.def | 3 +++ include/swift/Immediate/SwiftMaterializationUnit.h | 5 ++--- lib/AST/ASTPrinter.cpp | 2 ++ lib/FrontendTool/FrontendTool.cpp | 12 +++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/swift/Basic/Features.def b/include/swift/Basic/Features.def index 19855f7c6a3..7dc5ff58cc3 100644 --- a/include/swift/Basic/Features.def +++ b/include/swift/Basic/Features.def @@ -129,6 +129,9 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)", tru // Whether to enable @_used and @_section attributes EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true) +// Whether to compile scripts lazily in immediate mode +EXPERIMENTAL_FEATURE(LazyImmediate, false) + // FIXME: MoveOnlyClasses is not intended to be in production, // but our tests currently rely on it, and we want to run those // tests in non-asserts builds too. diff --git a/include/swift/Immediate/SwiftMaterializationUnit.h b/include/swift/Immediate/SwiftMaterializationUnit.h index e50e747cc6e..539de2f47a8 100644 --- a/include/swift/Immediate/SwiftMaterializationUnit.h +++ b/include/swift/Immediate/SwiftMaterializationUnit.h @@ -114,7 +114,6 @@ private: /// Lazily JITs a Swift AST using function at a time compilation class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit { public: - /// Create a new `LazySwiftMaterializationUnit` with the associated /// JIT stack `JIT` and compiler instance `CI` static std::unique_ptr @@ -140,7 +139,6 @@ private: /// Eagerly materializes a whole `SILModule` class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit { public: - /// Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT` /// and provided compiler options EagerSwiftMaterializationUnit(SwiftJIT &JIT, const CompilerInstance &CI, @@ -153,7 +151,8 @@ private: void materialize( std::unique_ptr MR) override; - /// Get the linker-level interface defined by the `SILModule` being materialized + /// Get the linker-level interface defined by the `SILModule` being + /// materialized static MaterializationUnit::Interface getInterface(SwiftJIT &JIT, const CompilerInstance &CI); diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index de81a27d6f1..bdd638bcfa2 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -3336,6 +3336,8 @@ static bool usesFeatureMoveOnly(Decl *decl) { return false; } +static bool usesFeatureLazyImmediate(Decl *D) { return false; } + static bool usesFeatureMoveOnlyClasses(Decl *decl) { return isa(decl) && usesFeatureMoveOnly(decl); } diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 281a8753169..1e358e91b62 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1365,7 +1365,17 @@ static bool performAction(CompilerInstance &Instance, return Instance.getASTContext().hadError(); }); case FrontendOptions::ActionType::Immediate: { - return RunImmediatelyFromAST(Instance) != -1; + const auto &Ctx = Instance.getASTContext(); + if (Ctx.LangOpts.hasFeature(Feature::LazyImmediate)) { + ReturnValue = RunImmediatelyFromAST(Instance); + return Ctx.hadError(); + } + return withSemanticAnalysis( + Instance, observer, [&](CompilerInstance &Instance) { + assert(FrontendOptions::doesActionGenerateSIL(opts.RequestedAction) && + "All actions not requiring SILGen must have been handled!"); + return performCompileStepsPostSema(Instance, ReturnValue, observer); + }); } case FrontendOptions::ActionType::EmitSILGen: case FrontendOptions::ActionType::EmitSIBGen: