[Immediate] Add frontend option for lazy compilation

This commit is contained in:
Zak Kent
2023-08-10 12:59:42 -07:00
parent 56ebd612b6
commit 289b812a14
4 changed files with 18 additions and 4 deletions

View File

@@ -129,6 +129,9 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)", tru
// Whether to enable @_used and @_section attributes // Whether to enable @_used and @_section attributes
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true) 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, // FIXME: MoveOnlyClasses is not intended to be in production,
// but our tests currently rely on it, and we want to run those // but our tests currently rely on it, and we want to run those
// tests in non-asserts builds too. // tests in non-asserts builds too.

View File

@@ -114,7 +114,6 @@ private:
/// Lazily JITs a Swift AST using function at a time compilation /// Lazily JITs a Swift AST using function at a time compilation
class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit { class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
public: public:
/// Create a new `LazySwiftMaterializationUnit` with the associated /// Create a new `LazySwiftMaterializationUnit` with the associated
/// JIT stack `JIT` and compiler instance `CI` /// JIT stack `JIT` and compiler instance `CI`
static std::unique_ptr<LazySwiftMaterializationUnit> static std::unique_ptr<LazySwiftMaterializationUnit>
@@ -140,7 +139,6 @@ private:
/// Eagerly materializes a whole `SILModule` /// Eagerly materializes a whole `SILModule`
class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit { class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
public: public:
/// Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT` /// Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT`
/// and provided compiler options /// and provided compiler options
EagerSwiftMaterializationUnit(SwiftJIT &JIT, const CompilerInstance &CI, EagerSwiftMaterializationUnit(SwiftJIT &JIT, const CompilerInstance &CI,
@@ -153,7 +151,8 @@ private:
void materialize( void materialize(
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override; std::unique_ptr<llvm::orc::MaterializationResponsibility> 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 static MaterializationUnit::Interface
getInterface(SwiftJIT &JIT, const CompilerInstance &CI); getInterface(SwiftJIT &JIT, const CompilerInstance &CI);

View File

@@ -3336,6 +3336,8 @@ static bool usesFeatureMoveOnly(Decl *decl) {
return false; return false;
} }
static bool usesFeatureLazyImmediate(Decl *D) { return false; }
static bool usesFeatureMoveOnlyClasses(Decl *decl) { static bool usesFeatureMoveOnlyClasses(Decl *decl) {
return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl); return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl);
} }

View File

@@ -1365,7 +1365,17 @@ static bool performAction(CompilerInstance &Instance,
return Instance.getASTContext().hadError(); return Instance.getASTContext().hadError();
}); });
case FrontendOptions::ActionType::Immediate: { 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::EmitSILGen:
case FrontendOptions::ActionType::EmitSIBGen: case FrontendOptions::ActionType::EmitSIBGen: