@@ -49,8 +49,13 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
4949 }
5050}
5151
52+ fileprivate struct PathFunctionTuple : Hashable {
53+ var path : SmallProjectionPath
54+ var function : Function
55+ }
56+
5257private func optimize( function: Function , _ context: FunctionPassContext ) {
53- var alreadyInlinedFunctions : [ SmallProjectionPath : Set < Function > ] = [ : ]
58+ var alreadyInlinedFunctions : Set < PathFunctionTuple > = Set ( )
5459
5560 var changed = true
5661 while changed {
@@ -79,7 +84,7 @@ private func optimize(function: Function, _ context: FunctionPassContext) {
7984 }
8085}
8186
82- private func inlineAndDevirtualize( apply: FullApplySite , alreadyInlinedFunctions: inout [ SmallProjectionPath : Set < Function > ] ,
87+ private func inlineAndDevirtualize( apply: FullApplySite , alreadyInlinedFunctions: inout Set < PathFunctionTuple > ,
8388 _ context: FunctionPassContext , _ simplifyCtxt: SimplifyContext ) {
8489 if simplifyCtxt. tryDevirtualize ( apply: apply, isMandatory: true ) != nil {
8590 return
@@ -116,7 +121,7 @@ private func removeUnusedMetatypeInstructions(in function: Function, _ context:
116121 }
117122}
118123
119- private func shouldInline( apply: FullApplySite , callee: Function , alreadyInlinedFunctions: inout [ SmallProjectionPath : Set < Function > ] ) -> Bool {
124+ private func shouldInline( apply: FullApplySite , callee: Function , alreadyInlinedFunctions: inout Set < PathFunctionTuple > ) -> Bool {
120125 if callee. isTransparent {
121126 return true
122127 }
@@ -134,8 +139,7 @@ private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlined
134139 global. mustBeInitializedStatically,
135140 let applyInst = apply as? ApplyInst ,
136141 let projectionPath = applyInst. isStored ( to: global) ,
137- !alreadyInlinedFunctions[ projectionPath, default: Set ( ) ] . contains ( callee) {
138- alreadyInlinedFunctions [ projectionPath, default: Set ( ) ] . insert ( callee)
142+ alreadyInlinedFunctions. insert ( PathFunctionTuple ( path: projectionPath, function: callee) ) . inserted {
139143 return true
140144 }
141145 return false
@@ -174,7 +178,7 @@ private extension Value {
174178 var singleUseValue : any Value = self
175179 var path = SmallProjectionPath ( )
176180 while true {
177- guard let use = singleUseValue. uses. singleUse else {
181+ guard let use = singleUseValue. uses. singleNonDebugUse else {
178182 return nil
179183 }
180184
@@ -185,8 +189,8 @@ private extension Value {
185189 case is TupleInst :
186190 path = path. push ( . tupleField, index: use. index)
187191 break
188- case is EnumInst :
189- path = path. push ( . enumCase, index: use . index )
192+ case let ei as EnumInst :
193+ path = path. push ( . enumCase, index: ei . caseIndex )
190194 break
191195 case let si as StoreInst :
192196 guard let storeDestination = si. destination as? GlobalAddrInst else {
@@ -199,7 +203,7 @@ private extension Value {
199203
200204 return path
201205 default :
202- break
206+ return nil
203207 }
204208
205209 guard let nextInstruction = use. instruction as? SingleValueInstruction else {
0 commit comments