Skip to content

SILCombine: fix an assert in the optimization which promotes a concrete type of an existential #20450

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
Nov 9, 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: 4 additions & 0 deletions lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,13 @@ static bool canReplaceCopiedArg(FullApplySite Apply,
if (!DT->properlyDominates(AI, user))
return false;
} else {
// The caller has to guarantee that there are no other instructions which
// use the address. This is done in findInitExistential called from
// the constructor of ConcreteExistentialInfo.
assert(isa<CopyAddrInst>(user) || isa<InitExistentialAddrInst>(user) ||
isa<OpenExistentialAddrInst>(user) ||
isa<DeallocStackInst>(user) ||
isa<ApplyInst>(user) || isa<TryApplyInst>(user) ||
user->isDebugInstruction() && "Unexpected instruction");
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/SILOptimizer/sil_combine_concrete_existential.sil
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,31 @@ bb0:
%v = tuple ()
return %v : $()
}

sil @takeany : $@convention(thin) (@in_guaranteed AnyP) -> ()

// CHECK-LABEL: sil @testWitnessCopiedSelfWithIndirectResult2 : $@convention(thin) () -> () {
// CHECK: [[IN:%[0-9]+]] = alloc_stack $AnyP
// CHECK: [[EA:%[0-9]+]] = init_existential_addr [[IN]]
// CHECK: [[OUT:%[0-9]+]] = alloc_stack $StructOfAnyP
// CHECK: witness_method $StructOfAnyP, #AnyP.returnsSelf!1 : <Self where Self : AnyP> (Self) -> () -> @dynamic_self Self : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
// CHECK: apply %{{.*}}<StructOfAnyP>([[OUT]], [[EA]]) : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
// CHECK-LABEL: } // end sil function 'testWitnessCopiedSelfWithIndirectResult2'
sil @testWitnessCopiedSelfWithIndirectResult2 : $() -> () {
bb0:
%a0 = alloc_stack $AnyP
%ie0 = init_existential_addr %a0 : $*AnyP, $StructOfAnyP
%f1 = function_ref @takeany : $@convention(thin) (@in_guaranteed AnyP) -> ()
%c1 = apply %f1(%a0) : $@convention(thin) (@in_guaranteed AnyP) -> ()
%a1 = alloc_stack $AnyP
copy_addr %a0 to [initialization] %a1 : $*AnyP
%o0 = open_existential_addr immutable_access %a1 : $*AnyP to $*@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP
%a2 = alloc_stack $StructOfAnyP
%w0 = witness_method $@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP, #AnyP.returnsSelf!1 : <Self where Self : AnyP> (Self) -> () -> @dynamic_self Self, %o0 : $*@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
%c0 = apply %w0<@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP>(%a2, %o0) : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
dealloc_stack %a2 : $*StructOfAnyP
dealloc_stack %a1 : $*AnyP
dealloc_stack %a0 : $*AnyP
%v = tuple ()
return %v : $()
}