Skip to content

Commit 289b812

Browse files
author
Zak Kent
committed
[Immediate] Add frontend option for lazy compilation
1 parent 56ebd61 commit 289b812

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)", tru
129129
// Whether to enable @_used and @_section attributes
130130
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)
131131

132+
// Whether to compile scripts lazily in immediate mode
133+
EXPERIMENTAL_FEATURE(LazyImmediate, false)
134+
132135
// FIXME: MoveOnlyClasses is not intended to be in production,
133136
// but our tests currently rely on it, and we want to run those
134137
// tests in non-asserts builds too.

include/swift/Immediate/SwiftMaterializationUnit.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class SwiftJIT {
114114
/// Lazily JITs a Swift AST using function at a time compilation
115115
class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
116116
public:
117-
118117
/// Create a new `LazySwiftMaterializationUnit` with the associated
119118
/// JIT stack `JIT` and compiler instance `CI`
120119
static std::unique_ptr<LazySwiftMaterializationUnit>
@@ -140,7 +139,6 @@ class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
140139
/// Eagerly materializes a whole `SILModule`
141140
class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
142141
public:
143-
144142
/// Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT`
145143
/// and provided compiler options
146144
EagerSwiftMaterializationUnit(SwiftJIT &JIT, const CompilerInstance &CI,
@@ -153,7 +151,8 @@ class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
153151
void materialize(
154152
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override;
155153

156-
/// Get the linker-level interface defined by the `SILModule` being materialized
154+
/// Get the linker-level interface defined by the `SILModule` being
155+
/// materialized
157156
static MaterializationUnit::Interface
158157
getInterface(SwiftJIT &JIT, const CompilerInstance &CI);
159158

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,6 +3336,8 @@ static bool usesFeatureMoveOnly(Decl *decl) {
33363336
return false;
33373337
}
33383338

3339+
static bool usesFeatureLazyImmediate(Decl *D) { return false; }
3340+
33393341
static bool usesFeatureMoveOnlyClasses(Decl *decl) {
33403342
return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl);
33413343
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,17 @@ static bool performAction(CompilerInstance &Instance,
13651365
return Instance.getASTContext().hadError();
13661366
});
13671367
case FrontendOptions::ActionType::Immediate: {
1368-
return RunImmediatelyFromAST(Instance) != -1;
1368+
const auto &Ctx = Instance.getASTContext();
1369+
if (Ctx.LangOpts.hasFeature(Feature::LazyImmediate)) {
1370+
ReturnValue = RunImmediatelyFromAST(Instance);
1371+
return Ctx.hadError();
1372+
}
1373+
return withSemanticAnalysis(
1374+
Instance, observer, [&](CompilerInstance &Instance) {
1375+
assert(FrontendOptions::doesActionGenerateSIL(opts.RequestedAction) &&
1376+
"All actions not requiring SILGen must have been handled!");
1377+
return performCompileStepsPostSema(Instance, ReturnValue, observer);
1378+
});
13691379
}
13701380
case FrontendOptions::ActionType::EmitSILGen:
13711381
case FrontendOptions::ActionType::EmitSIBGen:

0 commit comments

Comments
 (0)