Skip to content

Commit a2fda1d

Browse files
committed
[Embedded] Do not produce cannot_specialize_class for live issues
SourceKit explicitly disables WMO, silence the diagnostic in this case (but leave it enabled for explicit non-WMO builds otherwise).
1 parent ddfb26b commit a2fda1d

File tree

8 files changed

+30
-11
lines changed

8 files changed

+30
-11
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ extension Context {
4646

4747
var moduleIsSerialized: Bool { _bridged.moduleIsSerialized() }
4848

49+
/// Enable diagnostics requiring WMO (for @noLocks, @noAllocation
50+
/// annotations, Embedded Swift, and class specialization). SourceKit is the
51+
/// only consumer that has this disabled today (as it disables WMO
52+
/// explicitly).
53+
var enableWMORequiredDiagnostics: Bool {
54+
_bridged.enableWMORequiredDiagnostics()
55+
}
56+
4957
func canMakeStaticObjectReadOnly(objectType: Type) -> Bool {
5058
_bridged.canMakeStaticObjectReadOnly(objectType.bridged)
5159
}

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ private struct VTableSpecializer {
4949

5050
let classDecl = classType.nominal! as! ClassDecl
5151
guard let origVTable = context.lookupVTable(for: classDecl) else {
52-
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_class, classType)
52+
if context.enableWMORequiredDiagnostics {
53+
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_class, classType)
54+
}
5355
return
5456
}
5557

include/swift/AST/SILOptions.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ class SILOptions {
153153
/// Enables SIL-level diagnostics for NonescapableTypes.
154154
bool EnableLifetimeDependenceDiagnostics = true;
155155

156-
/// Enables SIL-level performance diagnostics (for @noLocks, @noAllocation
157-
/// annotations and for Embedded Swift).
158-
bool EnablePerformanceDiagnostics = true;
156+
/// Enable diagnostics requiring WMO (for @noLocks, @noAllocation
157+
/// annotations, Embedded Swift, and class specialization). SourceKit is the
158+
/// only consumer that has this disabled today (as it disables WMO
159+
/// explicitly).
160+
bool EnableWMORequiredDiagnostics = true;
159161

160162
/// Controls whether or not paranoid verification checks are run.
161163
bool VerifyAll = false;

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ struct BridgedPassContext {
381381
BRIDGED_INLINE bool enableMoveInoutStackProtection() const;
382382
BRIDGED_INLINE AssertConfiguration getAssertConfiguration() const;
383383
bool enableSimplificationFor(BridgedInstruction inst) const;
384+
BRIDGED_INLINE bool enableWMORequiredDiagnostics() const;
384385

385386
// Closure specializer
386387
SWIFT_IMPORT_UNSAFE BridgedFunction ClosureSpecializer_createEmptyFunctionWithSpecializedSignature(BridgedStringRef specializedName,

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ bool BridgedPassContext::shouldExpand(BridgedType ty) const {
571571
return swift::shouldExpand(mod, ty.unbridged());
572572
}
573573

574+
bool BridgedPassContext::enableWMORequiredDiagnostics() const {
575+
swift::SILModule *mod = invocation->getPassManager()->getModule();
576+
return mod->getOptions().EnableWMORequiredDiagnostics;
577+
}
578+
574579
static_assert((int)BridgedPassContext::SILStage::Raw == (int)swift::SILStage::Raw);
575580
static_assert((int)BridgedPassContext::SILStage::Canonical == (int)swift::SILStage::Canonical);
576581
static_assert((int)BridgedPassContext::SILStage::Lowered == (int)swift::SILStage::Lowered);

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ class PerformanceDiagnosticsPass : public SILModuleTransform {
792792
// Skip all performance/embedded diagnostics if asked. This is used from
793793
// SourceKit to avoid reporting false positives when WMO is turned off for
794794
// indexing purposes.
795-
if (!module->getOptions().EnablePerformanceDiagnostics) return;
795+
if (!module->getOptions().EnableWMORequiredDiagnostics) return;
796796

797797
PerformanceDiagnostics diagnoser(*module, getAnalysis<BasicCalleeAnalysis>());
798798

test/SourceKit/Diagnostics/embedded_non_wmo.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ func foo() {
1818

1919
@main
2020
struct Main {
21+
var someClass = SomeClass()
22+
2123
static func main() {
2224
foo()
2325
}
2426
}
2527

2628
//--- file2.swift
2729

28-
func bar<T>(_ T: T.Type) {
29-
30-
}
30+
final class SomeClass {}
31+
32+
func bar<T>(_ T: T.Type) {}
3133

3234
// CHECK: {
3335
// CHECK-NEXT: key.diagnostics: [

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,8 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
12151215
llvm::SaveAndRestore<std::shared_ptr<std::atomic<bool>>> DisableCancellationDuringSILGen(CompIns.getASTContext().CancellationFlag, nullptr);
12161216
SILOptions SILOpts = Invocation.getSILOptions();
12171217

1218-
// Disable PerformanceDiagnostics SIL pass, which in some cases requires
1219-
// WMO (e.g. for Embedded Swift diags) but SourceKit compiles without WMO.
1220-
SILOpts.EnablePerformanceDiagnostics = false;
1218+
// Disable diagnostics that require WMO (as SourceKit disables it).
1219+
SILOpts.EnableWMORequiredDiagnostics = false;
12211220

12221221
auto &TC = CompIns.getSILTypes();
12231222
std::unique_ptr<SILModule> SILMod = performASTLowering(*SF, TC, SILOpts);

0 commit comments

Comments
 (0)