Skip to content

[6.1][Embedded] Do not produce cannot_specialize_class for live issues #78333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ extension Context {

var moduleIsSerialized: Bool { _bridged.moduleIsSerialized() }

/// Enable diagnostics requiring WMO (for @noLocks, @noAllocation
/// annotations, Embedded Swift, and class specialization). SourceKit is the
/// only consumer that has this disabled today (as it disables WMO
/// explicitly).
var enableWMORequiredDiagnostics: Bool {
_bridged.enableWMORequiredDiagnostics()
}

func canMakeStaticObjectReadOnly(objectType: Type) -> Bool {
_bridged.canMakeStaticObjectReadOnly(objectType.bridged)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ private struct VTableSpecializer {

let classDecl = classType.nominal! as! ClassDecl
guard let origVTable = context.lookupVTable(for: classDecl) else {
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_class, classType)
if context.enableWMORequiredDiagnostics {
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_class, classType)
}
return
}

Expand Down
8 changes: 5 additions & 3 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ class SILOptions {
/// Enables SIL-level diagnostics for NonescapableTypes.
bool EnableLifetimeDependenceDiagnostics = true;

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

/// Controls whether or not paranoid verification checks are run.
bool VerifyAll = false;
Expand Down
1 change: 1 addition & 0 deletions include/swift/SILOptimizer/OptimizerBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ struct BridgedPassContext {
BRIDGED_INLINE bool enableMoveInoutStackProtection() const;
BRIDGED_INLINE AssertConfiguration getAssertConfiguration() const;
bool enableSimplificationFor(BridgedInstruction inst) const;
BRIDGED_INLINE bool enableWMORequiredDiagnostics() const;

// Closure specializer
SWIFT_IMPORT_UNSAFE BridgedFunction ClosureSpecializer_createEmptyFunctionWithSpecializedSignature(BridgedStringRef specializedName,
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SILOptimizer/OptimizerBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ bool BridgedPassContext::shouldExpand(BridgedType ty) const {
return swift::shouldExpand(mod, ty.unbridged());
}

bool BridgedPassContext::enableWMORequiredDiagnostics() const {
swift::SILModule *mod = invocation->getPassManager()->getModule();
return mod->getOptions().EnableWMORequiredDiagnostics;
}

static_assert((int)BridgedPassContext::SILStage::Raw == (int)swift::SILStage::Raw);
static_assert((int)BridgedPassContext::SILStage::Canonical == (int)swift::SILStage::Canonical);
static_assert((int)BridgedPassContext::SILStage::Lowered == (int)swift::SILStage::Lowered);
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ class PerformanceDiagnosticsPass : public SILModuleTransform {
// Skip all performance/embedded diagnostics if asked. This is used from
// SourceKit to avoid reporting false positives when WMO is turned off for
// indexing purposes.
if (!module->getOptions().EnablePerformanceDiagnostics) return;
if (!module->getOptions().EnableWMORequiredDiagnostics) return;

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

Expand Down
8 changes: 5 additions & 3 deletions test/SourceKit/Diagnostics/embedded_non_wmo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ func foo() {

@main
struct Main {
var someClass = SomeClass()

static func main() {
foo()
}
}

//--- file2.swift

func bar<T>(_ T: T.Type) {
}
final class SomeClass {}

func bar<T>(_ T: T.Type) {}

// CHECK: {
// CHECK-NEXT: key.diagnostics: [
Expand Down
5 changes: 2 additions & 3 deletions tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,8 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
llvm::SaveAndRestore<std::shared_ptr<std::atomic<bool>>> DisableCancellationDuringSILGen(CompIns.getASTContext().CancellationFlag, nullptr);
SILOptions SILOpts = Invocation.getSILOptions();

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

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