Skip to content

Devirtualizer: disable the “effectively final” optimization if the caller is serialized #17327

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
Jun 19, 2018
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
4 changes: 3 additions & 1 deletion lib/SILOptimizer/Utils/Devirtualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ bool swift::canDevirtualizeClassMethod(FullApplySite AI,

// We need to disable the “effectively final” opt if a function is inlinable
if (isEffectivelyFinalMethod &&
F->getResilienceExpansion() == ResilienceExpansion::Minimal) {
((F->getResilienceExpansion() == ResilienceExpansion::Minimal) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the first check even necessary? It seems like this is always about the call site. cc @slavapestov

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @jrose-apple. It's always OK to inline an inlinable function into a non-inlinable function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the first check: #17337

AI.getFunction()->getResilienceExpansion() ==
ResilienceExpansion::Minimal)) {
DEBUG(llvm::dbgs() << " FAIL: Could not optimize function because "
"it is an effectively-final inlinable: "
<< F->getName() << "\n");
Expand Down
13 changes: 13 additions & 0 deletions test/SILOptimizer/devirtualize_inlinable_mandatory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %target-swift-frontend %s -whole-module-optimization -emit-sil | %FileCheck %s

public class C {
public func f() {}
}

//CHECK-LABEL: sil [serialized] @$S32devirtualize_inlinable_mandatory1gyyAA1CCF : $@convention(thin) (@guaranteed C) -> () {
//CHECK: class_method %0 : $C, #C.f!1 : (C) -> () -> (), $@convention(method) (@guaranteed C) -> ()
//CHECK-NOT: function_ref
//CHECK: return
@inlinable public func g(_ x: C) {
x.f()
}