Skip to content

BasicCalleeAnalysis: fix a problem with witness method visibility. #15355

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
Mar 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
25 changes: 19 additions & 6 deletions lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,25 @@ void CalleeCache::computeWitnessMethodCalleesForWitnessTable(
continue;
}

auto Witness = WT.getConformance()->getWitness(Requirement.getDecl(),
nullptr);
auto DeclRef = SILDeclRef(Witness.getDecl());

bool canCallUnknown = !calleesAreStaticallyKnowable(M, DeclRef);

bool canCallUnknown = false;

auto Conf = WT.getConformance();
switch (Conf->getProtocol()->getEffectiveAccess()) {
case AccessLevel::Open:
llvm_unreachable("protocols cannot have open access level");
case AccessLevel::Public:
canCallUnknown = true;
break;
case AccessLevel::Internal:
canCallUnknown = !M.isWholeModule();
break;
case AccessLevel::FilePrivate:
case AccessLevel::Private: {
auto Witness = Conf->getWitness(Requirement.getDecl(), nullptr);
auto DeclRef = SILDeclRef(Witness.getDecl());
canCallUnknown = !calleesAreStaticallyKnowable(M, DeclRef);
}
}
if (canCallUnknown)
TheCallees.setInt(true);
}
Expand Down
37 changes: 37 additions & 0 deletions test/SILOptimizer/basic-callee-printer.sil
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,40 @@ sil_vtable SomeChildItem {
#SomeItem.init!initializer.1: @SomeChildItem_initializer
#SomeChildItem.deinit!deallocator: @SomeChildItem_destructor
}

public protocol PublicProtocol {
func foo()
}

struct SingleConformance : PublicProtocol {
func foo()
}

public func testit(p: PublicProtocol)

sil private [transparent] [thunk] @$foo_impl : $@convention(witness_method: PublicProtocol) (@in_guaranteed SingleConformance) -> () {
bb0(%0 : $*SingleConformance):
%4 = tuple ()
return %4 : $()
}

// CHECK: Function call site:
// CHECK: witness_method $@opened{{.*}} PublicProtocol
// CHECK: apply {{.*}} PublicProtocol
// CHECK-NOWMO: Incomplete callee list? : Yes
// CHECK-WMO: Incomplete callee list? : Yes
// CHECK: Known callees:
sil @$call_foo : $@convention(thin) (@in PublicProtocol) -> () {
bb0(%0 : $*PublicProtocol):
%5 = open_existential_addr immutable_access %0 : $*PublicProtocol to $*@opened("2226A1AC-2B95-11E8-BDF4-D0817AD3F637") PublicProtocol
%6 = witness_method $@opened("2226A1AC-2B95-11E8-BDF4-D0817AD3F637") PublicProtocol, #PublicProtocol.foo!1 : <Self where Self : PublicProtocol> (Self) -> () -> (), %5 : $*@opened("2226A1AC-2B95-11E8-BDF4-D0817AD3F637") PublicProtocol : $@convention(witness_method: PublicProtocol) <τ_0_0 where τ_0_0 : PublicProtocol> (@in_guaranteed τ_0_0) -> ()
%7 = apply %6<@opened("2226A1AC-2B95-11E8-BDF4-D0817AD3F637") PublicProtocol>(%5) : $@convention(witness_method: PublicProtocol) <τ_0_0 where τ_0_0 : PublicProtocol> (@in_guaranteed τ_0_0) -> ()
destroy_addr %0 : $*PublicProtocol
%10 = tuple ()
return %10 : $()
}

sil_witness_table hidden SingleConformance: PublicProtocol module nix {
method #PublicProtocol.foo!1: <Self where Self : PublicProtocol> (Self) -> () -> () : @$foo_impl
}