@@ -16,7 +16,6 @@ import scala.collection.JavaConverters._
16
16
import scala .tools .nsc .backend .jvm .BTypes .InternalName
17
17
import scala .tools .nsc .backend .jvm .BackendReporting ._
18
18
import scala .tools .nsc .backend .jvm .analysis ._
19
- import ByteCodeRepository .{Source , CompilationUnit }
20
19
import BytecodeUtils ._
21
20
22
21
class CallGraph [BT <: BTypes ](val btypes : BT ) {
@@ -128,17 +127,17 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
128
127
methodNode.instructions.iterator.asScala foreach {
129
128
case call : MethodInsnNode if a.frameAt(call) != null => // skips over unreachable code
130
129
val callee : Either [OptimizerWarning , Callee ] = for {
131
- (method, declarationClass) <- byteCodeRepository.methodNode(call.owner, call.name, call.desc): Either [OptimizerWarning , (MethodNode , InternalName )]
132
- (declarationClassNode, source ) <- byteCodeRepository.classNodeAndSource (declarationClass): Either [OptimizerWarning , (ClassNode , Source )]
130
+ (method, declarationClass) <- byteCodeRepository.methodNode(call.owner, call.name, call.desc): Either [OptimizerWarning , (MethodNode , InternalName )]
131
+ (declarationClassNode, calleeSourceFilePath ) <- byteCodeRepository.classNodeAndSourceFilePath (declarationClass): Either [OptimizerWarning , (ClassNode , Option [ String ] )]
133
132
} yield {
134
133
val declarationClassBType = classBTypeFromClassNode(declarationClassNode)
135
- val info = analyzeCallsite(method, declarationClassBType, call, source )
134
+ val info = analyzeCallsite(method, declarationClassBType, call, calleeSourceFilePath )
136
135
import info ._
137
136
Callee (
138
137
callee = method,
139
138
calleeDeclarationClass = declarationClassBType,
140
139
safeToInline = safeToInline,
141
- canInlineFromSource = canInlineFromSource ,
140
+ sourceFilePath = sourceFilePath ,
142
141
annotatedInline = annotatedInline,
143
142
annotatedNoInline = annotatedNoInline,
144
143
samParamTypes = info.samParamTypes,
@@ -256,15 +255,15 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
256
255
/**
257
256
* Just a named tuple used as return type of `analyzeCallsite`.
258
257
*/
259
- private case class CallsiteInfo (safeToInline : Boolean , canInlineFromSource : Boolean ,
258
+ private case class CallsiteInfo (safeToInline : Boolean , sourceFilePath : Option [ String ] ,
260
259
annotatedInline : Boolean , annotatedNoInline : Boolean ,
261
260
samParamTypes : IntMap [ClassBType ],
262
261
warning : Option [CalleeInfoWarning ])
263
262
264
263
/**
265
264
* Analyze a callsite and gather meta-data that can be used for inlining decisions.
266
265
*/
267
- private def analyzeCallsite (calleeMethodNode : MethodNode , calleeDeclarationClassBType : ClassBType , call : MethodInsnNode , calleeSource : Source ): CallsiteInfo = {
266
+ private def analyzeCallsite (calleeMethodNode : MethodNode , calleeDeclarationClassBType : ClassBType , call : MethodInsnNode , calleeSourceFilePath : Option [ String ] ): CallsiteInfo = {
268
267
val methodSignature = calleeMethodNode.name + calleeMethodNode.desc
269
268
270
269
try {
@@ -273,8 +272,6 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
273
272
// callee, we only check there for the methodInlineInfo, we should find it there.
274
273
calleeDeclarationClassBType.info.orThrow.inlineInfo.methodInfos.get(methodSignature) match {
275
274
case Some (methodInlineInfo) =>
276
- val canInlineFromSource = compilerSettings.optInlineGlobal || calleeSource == CompilationUnit
277
-
278
275
val isAbstract = BytecodeUtils .isAbstractMethod(calleeMethodNode)
279
276
280
277
val receiverType = classBTypeFromParsedClassfile(call.owner)
@@ -308,26 +305,26 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
308
305
// static impl method first (safeToRewrite).
309
306
CallsiteInfo (
310
307
safeToInline =
311
- canInlineFromSource &&
308
+ inlinerHeuristics. canInlineFromSource(calleeSourceFilePath) &&
312
309
isStaticallyResolved && // (1)
313
310
! isAbstract &&
314
311
! BytecodeUtils .isConstructor(calleeMethodNode) &&
315
312
! BytecodeUtils .isNativeMethod(calleeMethodNode) &&
316
313
! BytecodeUtils .hasCallerSensitiveAnnotation(calleeMethodNode),
317
- canInlineFromSource = canInlineFromSource ,
314
+ sourceFilePath = calleeSourceFilePath ,
318
315
annotatedInline = methodInlineInfo.annotatedInline,
319
316
annotatedNoInline = methodInlineInfo.annotatedNoInline,
320
317
samParamTypes = samParamTypes(calleeMethodNode, receiverType),
321
318
warning = warning)
322
319
323
320
case None =>
324
321
val warning = MethodInlineInfoMissing (calleeDeclarationClassBType.internalName, calleeMethodNode.name, calleeMethodNode.desc, calleeDeclarationClassBType.info.orThrow.inlineInfo.warning)
325
- CallsiteInfo (false , false , false , false , IntMap .empty, Some (warning))
322
+ CallsiteInfo (false , None , false , false , IntMap .empty, Some (warning))
326
323
}
327
324
} catch {
328
325
case Invalid (noInfo : NoClassBTypeInfo ) =>
329
326
val warning = MethodInlineInfoError (calleeDeclarationClassBType.internalName, calleeMethodNode.name, calleeMethodNode.desc, noInfo)
330
- CallsiteInfo (false , false , false , false , IntMap .empty, Some (warning))
327
+ CallsiteInfo (false , None , false , false , IntMap .empty, Some (warning))
331
328
}
332
329
}
333
330
@@ -389,7 +386,7 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
389
386
* gathering the information about this callee.
390
387
*/
391
388
final case class Callee (callee : MethodNode , calleeDeclarationClass : btypes.ClassBType ,
392
- safeToInline : Boolean , canInlineFromSource : Boolean ,
389
+ safeToInline : Boolean , sourceFilePath : Option [ String ] ,
393
390
annotatedInline : Boolean , annotatedNoInline : Boolean ,
394
391
samParamTypes : IntMap [btypes.ClassBType ],
395
392
calleeInfoWarning : Option [CalleeInfoWarning ]) {
0 commit comments