Skip to content

Commit 101cf49

Browse files
committed
Use -enable-resilience for IRGen super_method tests
We've already got -enable-resilience and @_fixed_layout to compare IRGen differences when lowering super_method instructions, so nuke the -force-resilient-super-dispatch testing flag. While we're at it, consolidate the super tests a bit.
1 parent 811bdb4 commit 101cf49

17 files changed

+540
-862
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ class IRGenOptions {
126126
/// Whether we should embed the bitcode file.
127127
IRGenEmbedMode EmbedMode : 2;
128128

129-
/// For resilient access to super's members for testing.
130-
unsigned ForceResilientSuperDispatch: 1;
131-
132129
/// List of backend command-line options for -embed-bitcode.
133130
std::vector<uint8_t> CmdArgs;
134131

@@ -138,8 +135,7 @@ class IRGenOptions {
138135
DisableLLVMARCOpts(false), DisableLLVMSLPVectorizer(false),
139136
DisableFPElim(true), Playground(false),
140137
EmitStackPromotionChecks(false), GenerateProfile(false),
141-
EmbedMode(IRGenEmbedMode::None),
142-
ForceResilientSuperDispatch(false)
138+
EmbedMode(IRGenEmbedMode::None)
143139
{}
144140

145141
/// Gets the name of the specified output filename.

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
190190
def use_native_super_method : Flag<["-"], "use-native-super-method">,
191191
HelpText<"Use super_method for super calls in native classes">;
192192

193-
def force_resilient_super_dispatch: Flag<["-"], "force-resilient-super-dispatch">,
194-
HelpText<"Assume all super member accesses are resilient">;
195-
196193
def disable_self_type_mangling : Flag<["-"], "disable-self-type-mangling">,
197194
HelpText<"Disable including Self type in method type manglings">;
198195

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
11551155
}
11561156
}
11571157

1158-
Opts.ForceResilientSuperDispatch |=
1159-
Args.hasArg(OPT_force_resilient_super_dispatch);
1160-
11611158
return false;
11621159
}
11631160

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,8 +4300,7 @@ llvm::Value *irgen::emitVirtualMethodValue(IRGenFunction &IGF,
43004300
instanceTy = SILType::getPrimitiveObjectType(metaTy.getInstanceType());
43014301

43024302
if (IGF.IGM.isResilient(instanceTy.getClassOrBoundGenericClass(),
4303-
ResilienceScope::Component) ||
4304-
IGF.IGM.Opts.ForceResilientSuperDispatch) {
4303+
ResilienceScope::Component)) {
43054304
// The derived type that is making the super call is resilient,
43064305
// for example we may be in an extension of a class outside of our
43074306
// resilience domain. So, we need to load the superclass metadata

test/IRGen/super.sil

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: %target-swift-frontend -emit-module -enable-resilience -module-name resilient_class -o %t %S/../Inputs/resilient_class.swift
4+
// RUN: %target-swift-frontend -use-native-super-method -enable-resilience -parse-sil -parse-as-library -emit-ir -I %t %s | FileCheck %s
5+
6+
sil_stage canonical
7+
8+
import Builtin
9+
import Swift
10+
import SwiftShims
11+
import resilient_class
12+
13+
public class ChildToResilientParent : ResilientOutsideParent {
14+
public override func method()
15+
public override class func classMethod()
16+
deinit
17+
override init()
18+
}
19+
20+
public class ChildToFixedParent : OutsideParent {
21+
public override func method()
22+
public override class func classMethod()
23+
deinit
24+
override init()
25+
}
26+
27+
public extension ResilientOutsideChild {
28+
public func callSuperMethod()
29+
public class func callSuperClassMethod()
30+
}
31+
32+
// resilient_class.ResilientOutsideParent.method () -> ()
33+
sil @_TFC15resilient_class22ResilientOutsideParent6methodfT_T_ : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
34+
35+
// static resilient_class.ResilientOutsideParent.classMethod () -> ()
36+
sil @_TZFC15resilient_class22ResilientOutsideParent11classMethodfT_T_ : $@convention(thin) (@thick ResilientOutsideParent.Type) -> ()
37+
38+
// super.ChildToResilientParent.method () -> ()
39+
sil @_TFC5super22ChildToResilientParent6methodfT_T_ : $@convention(method) (@guaranteed ChildToResilientParent) -> () {
40+
// %0
41+
bb0(%0 : $ChildToResilientParent):
42+
debug_value %0 : $ChildToResilientParent, let, name "self", argno 1
43+
strong_retain %0 : $ChildToResilientParent
44+
%3 = upcast %0 : $ChildToResilientParent to $ResilientOutsideParent
45+
%4 = super_method %0 : $ChildToResilientParent, #ResilientOutsideParent.method!1 : ResilientOutsideParent -> () -> () , $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
46+
%5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
47+
strong_release %3 : $ResilientOutsideParent
48+
%7 = tuple ()
49+
return %7 : $()
50+
}
51+
52+
// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
53+
// CHECK-LABEL: define void @_TFC5super22ChildToResilientParent6methodfT_T_(%C5super22ChildToResilientParent*)
54+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class22ResilientOutsideParent()
55+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class22ResilientOutsideParent*)**
56+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[OPAQUE_SUPER_METADATA]]
57+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[VTABLE_SLOT]]
58+
// CHECK: call void
59+
60+
// static super.ChildToResilientParent.classMethod () -> ()
61+
sil @_TZFC5super22ChildToResilientParent11classMethodfT_T_ : $@convention(thin) (@thick ChildToResilientParent.Type) -> () {
62+
bb0(%0 : $@thick ChildToResilientParent.Type):
63+
debug_value %0 : $@thick ChildToResilientParent.Type, let, name "self", argno 1
64+
%2 = upcast %0 : $@thick ChildToResilientParent.Type to $@thick ResilientOutsideParent.Type
65+
%3 = super_method %0 : $@thick ChildToResilientParent.Type, #ResilientOutsideParent.classMethod!1 : ResilientOutsideParent.Type -> () -> () , $@convention(thin) (@thick ResilientOutsideParent.Type) -> ()
66+
%4 = apply %3(%2) : $@convention(thin) (@thick ResilientOutsideParent.Type) -> ()
67+
%5 = tuple ()
68+
return %5 : $()
69+
}
70+
71+
// ChildToResilientParent is in our resilience domain - can load the superclass's metadata directly.
72+
// CHECK-LABEL: define void @_TZFC5super22ChildToResilientParent11classMethodfT_T_(%swift.type*)
73+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class22ResilientOutsideParent()
74+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
75+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
76+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
77+
// CHECK: call void
78+
79+
// resilient_class.OutsideParent.method () -> ()
80+
sil @_TFC15resilient_class13OutsideParent6methodfT_T_ : $@convention(method) (@guaranteed OutsideParent) -> ()
81+
82+
// static resilient_class.OutsideParent.classMethod () -> ()
83+
sil @_TZFC15resilient_class13OutsideParent11classMethodfT_T_ : $@convention(thin) (@thick OutsideParent.Type) -> ()
84+
85+
// super.ChildToFixedParent.method () -> ()
86+
sil @_TFC5super18ChildToFixedParent6methodfT_T_ : $@convention(method) (@guaranteed ChildToFixedParent) -> () {
87+
// %0
88+
bb0(%0 : $ChildToFixedParent):
89+
debug_value %0 : $ChildToFixedParent, let, name "self", argno 1
90+
strong_retain %0 : $ChildToFixedParent
91+
%3 = upcast %0 : $ChildToFixedParent to $OutsideParent
92+
%4 = super_method %0 : $ChildToFixedParent, #OutsideParent.method!1 : OutsideParent -> () -> () , $@convention(method) (@guaranteed OutsideParent) -> ()
93+
%5 = apply %4(%3) : $@convention(method) (@guaranteed OutsideParent) -> ()
94+
strong_release %3 : $OutsideParent
95+
%7 = tuple ()
96+
return %7 : $()
97+
}
98+
99+
// CHECK-LABEL: define void @_TFC5super18ChildToFixedParent6methodfT_T_(%C5super18ChildToFixedParent*)
100+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class13OutsideParent()
101+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class13OutsideParent*)**
102+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class13OutsideParent*)*, void (%C15resilient_class13OutsideParent*)** [[OPAQUE_SUPER_METADATA]]
103+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class13OutsideParent*)*, void (%C15resilient_class13OutsideParent*)** [[VTABLE_SLOT]]
104+
// CHECK: call void
105+
106+
// static super.ChildToFixedParent.classMethod () -> ()
107+
sil @_TZFC5super18ChildToFixedParent11classMethodfT_T_ : $@convention(thin) (@thick ChildToFixedParent.Type) -> () {
108+
// %0
109+
bb0(%0 : $@thick ChildToFixedParent.Type):
110+
debug_value %0 : $@thick ChildToFixedParent.Type, let, name "self", argno 1
111+
%2 = upcast %0 : $@thick ChildToFixedParent.Type to $@thick OutsideParent.Type
112+
%3 = super_method %0 : $@thick ChildToFixedParent.Type, #OutsideParent.classMethod!1 : OutsideParent.Type -> () -> () , $@convention(thin) (@thick OutsideParent.Type) -> ()
113+
%4 = apply %3(%2) : $@convention(thin) (@thick OutsideParent.Type) -> ()
114+
%5 = tuple ()
115+
return %5 : $()
116+
}
117+
118+
// ChildToFixedParent is in our resilience domain - load super metadata directly.
119+
// CHECK-LABEL: define void @_TZFC5super18ChildToFixedParent11classMethodfT_T_(%swift.type*)
120+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class13OutsideParent()
121+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
122+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
123+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
124+
// CHECK: call void
125+
126+
// ext.super.resilient_class.ResilientOutsideChild.callSuperMethod () -> ()
127+
sil @_TFE5superC15resilient_class21ResilientOutsideChild15callSuperMethodfT_T_ : $@convention(method) (@guaranteed ResilientOutsideChild) -> () {
128+
// %0
129+
bb0(%0 : $ResilientOutsideChild):
130+
debug_value %0 : $ResilientOutsideChild, let, name "self", argno 1
131+
strong_retain %0 : $ResilientOutsideChild
132+
%3 = upcast %0 : $ResilientOutsideChild to $ResilientOutsideParent
133+
%4 = super_method %0 : $ResilientOutsideChild, #ResilientOutsideParent.method!1 : ResilientOutsideParent -> () -> () , $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
134+
%5 = apply %4(%3) : $@convention(method) (@guaranteed ResilientOutsideParent) -> ()
135+
strong_release %3 : $ResilientOutsideParent
136+
%7 = tuple ()
137+
return %7 : $()
138+
}
139+
140+
// Extending a resilient class - load super metadata indirectly.
141+
// CHECK-LABEL: define void @_TFE5superC15resilient_class21ResilientOutsideChild15callSuperMethodfT_T_(%C15resilient_class21ResilientOutsideChild*)
142+
// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class21ResilientOutsideChild()
143+
// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type**
144+
// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1
145+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]]
146+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%C15resilient_class22ResilientOutsideParent*)**
147+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[OPAQUE_SUPER_METADATA]]
148+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%C15resilient_class22ResilientOutsideParent*)*, void (%C15resilient_class22ResilientOutsideParent*)** [[VTABLE_SLOT]]
149+
// CHECK: call void
150+
151+
// static ext.super.resilient_class.ResilientOutsideChild.callSuperClassMethod () -> ()
152+
sil @_TZFE5superC15resilient_class21ResilientOutsideChild20callSuperClassMethodfT_T_ : $@convention(thin) (@thick ResilientOutsideChild.Type) -> () {
153+
// %0
154+
bb0(%0 : $@thick ResilientOutsideChild.Type):
155+
debug_value %0 : $@thick ResilientOutsideChild.Type, let, name "self", argno 1
156+
%2 = upcast %0 : $@thick ResilientOutsideChild.Type to $@thick ResilientOutsideParent.Type
157+
%3 = super_method %0 : $@thick ResilientOutsideChild.Type, #ResilientOutsideParent.classMethod!1 : ResilientOutsideParent.Type -> () -> () , $@convention(thin) (@thick ResilientOutsideParent.Type) -> ()
158+
%4 = apply %3(%2) : $@convention(thin) (@thick ResilientOutsideParent.Type) -> ()
159+
%5 = tuple ()
160+
return %5 : $()
161+
}
162+
163+
// Extending a resilient class - load super metadata indirectly.
164+
// CHECK-LABEL: define void @_TZFE5superC15resilient_class21ResilientOutsideChild20callSuperClassMethodfT_T_(%swift.type*)
165+
// CHECK: [[METADATA:%[0-9]+]] = call %swift.type* @_TMaC15resilient_class21ResilientOutsideChild()
166+
// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[METADATA]] to %swift.type**
167+
// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1
168+
// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]]
169+
// CHECK: [[OPAQUE_SUPER_METADATA:%[0-9]+]] = bitcast %swift.type* [[SUPER_METADATA]] to void (%swift.type*)**
170+
// CHECK: [[VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[OPAQUE_SUPER_METADATA]]
171+
// CHECK: [[FN_PTR:%[0-9]+]] = load void (%swift.type*)*, void (%swift.type*)** [[VTABLE_SLOT]]
172+
// CHECK: call void
173+
174+
sil_vtable ChildToResilientParent {
175+
#ResilientOutsideParent.method!1: _TFC5super22ChildToResilientParent6methodfT_T_ // super.ChildToResilientParent.method () -> ()
176+
#ResilientOutsideParent.classMethod!1: _TZFC5super22ChildToResilientParent11classMethodfT_T_ // static super.ChildToResilientParent.classMethod () -> ()
177+
}
178+
179+
sil_vtable ChildToFixedParent {
180+
#OutsideParent.method!1: _TFC5super18ChildToFixedParent6methodfT_T_ // super.ChildToFixedParent.method () -> ()
181+
#OutsideParent.classMethod!1: _TZFC5super18ChildToFixedParent11classMethodfT_T_ // static super.ChildToFixedParent.classMethod () -> ()
182+
}
183+

0 commit comments

Comments
 (0)