Skip to content

Commit 01fc3e6

Browse files
committed
Ignore known safe method calls
1 parent 89a0845 commit 01fc3e6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ class Semantic {
209209
else
210210
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
211211
eval(rhs, thisRef, target.owner.asClass, cacheResult = true)
212+
else if thisRef.canIgnoreMethodCall(target) then
213+
Result(Hot, Nil)
212214
else
213215
val error = CallUnknown(target, source, trace)
214216
Result(Hot, error :: Nil)
@@ -235,6 +237,8 @@ class Semantic {
235237
else
236238
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
237239
eval(rhs, warm, target.owner.asClass, cacheResult = true)
240+
else if warm.canIgnoreMethodCall(target) then
241+
Result(Hot, Nil)
238242
else
239243
val error = CallUnknown(target, source, trace)
240244
Result(Hot, error :: Nil)
@@ -385,6 +389,17 @@ class Semantic {
385389
case warm: Warm => // ignore
386390
end extension
387391

392+
// ----- Policies ------------------------------------------------------
393+
extension (value: Warm | ThisRef)
394+
/** Can the method call on `value` be ignored?
395+
*
396+
* Note: assume overriding resolution has been performed.
397+
*/
398+
def canIgnoreMethodCall(meth: Symbol)(using Context): Boolean =
399+
val cls = meth.owner
400+
cls == defn.AnyClass ||
401+
cls == defn.AnyValClass ||
402+
cls == defn.ObjectClass
388403

389404
// ----- Semantic definition --------------------------------
390405

0 commit comments

Comments
 (0)