Skip to content

Conversation

KacperFKorban
Copy link
Member

@KacperFKorban KacperFKorban commented Apr 11, 2025

Change tracked inference to simpler heuristic: always infer tracked for a parameter if its type has an abstract type member.

Tested it with modularity turned on and the only bug I noticed was eager typing of annotations, which I patched by not inferring tracked for annotated parameters.

@KacperFKorban KacperFKorban force-pushed the simple-tracked-inference branch from 3348b8f to 2dc8ada Compare August 10, 2025 13:19
@KacperFKorban KacperFKorban changed the title Experiment with simpler inference for tracked Simpler inference for tracked Aug 15, 2025
@KacperFKorban KacperFKorban requested a review from odersky August 15, 2025 08:55
@KacperFKorban KacperFKorban marked this pull request as ready for review August 15, 2025 08:55
lazy val isRefInSignatures =
psym.maybeOwner.isPrimaryConstructor
&& isReferencedInPublicSignatures(psym)
lazy val needsTrackedSimp = needsTrackedSimple(psym, param, owningSym)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why you need a lazy val here? A def would do as weell and be more efficient? Or just inline the rhs.

&& psym.info.memberNames(abstractTypeNameFilter).nonEmpty
&& !accessorSyms.exists(_.is(Mutable))
&& (param.hasAttachment(ContextBoundParam) || accessorSyms.exists(!_.isOneOf(PrivateLocal)))
&& psym.infoDontForceAnnotsAndInferred(param).memberNames(abstractTypeNameFilter).nonEmpty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not: abstractTypeNames.nonEmpty?

sym.infoOrCompleter match
case tpe if tree.mods.annotations.nonEmpty => tpe
case tpe: LazyType if tpe.isExplicit => sym.info
case tpe if sym.isType => sym.info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not rendundant wrt the last line?

acc(false, tpe)
private def infoDontForceAnnotsAndInferred(tree: DefTree)(using Context): Type =
sym.infoOrCompleter match
case tpe if tree.mods.annotations.nonEmpty => tpe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find a more finegrained exclusion that avoids the NoSymbol?

@@ -0,0 +1,6 @@
import scala.language.experimental.modularity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add some more tests that exercise the precise conditions that infer tracked.

@odersky odersky force-pushed the simple-tracked-inference branch 2 times, most recently from 606bfe9 to f1b836e Compare October 13, 2025 06:37
@odersky odersky force-pushed the simple-tracked-inference branch from f1b836e to 069dd61 Compare October 13, 2025 08:21
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some changes to simplify it further and update the doc page to reflect the new behavior.

@odersky
Copy link
Contributor

odersky commented Oct 14, 2025

Summary of changes over original PR:

  • drop isExplicitType logic
  • revise type completion logic so that we can compute the type without the annotations
  • update comments and doc page to reflect the new behavior
  • drop dead cases in distinctions

@odersky odersky merged commit 7057332 into scala:main Oct 15, 2025
51 checks passed
@odersky odersky deleted the simple-tracked-inference branch October 15, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants