Skip to content

Review scala.collection public members #11433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lrytz opened this issue Feb 5, 2018 · 2 comments
Closed

Review scala.collection public members #11433

lrytz opened this issue Feb 5, 2018 · 2 comments

Comments

@lrytz
Copy link
Member

lrytz commented Feb 5, 2018

At some point before shipping we should review public types / methods in the collection package. The following can be pasted in the repl:

:power

import symtab.Flags

def packagesIn(p: Symbol): List[Symbol] = {
  val ps = p.info.membersBasedOnFlags(0, Flags.PACKAGE).toList
  ps ::: ps.flatMap(packagesIn)
}

val collP = rootMirror.getPackage(TermName("scala.collection"))
val allPackages = collP :: packagesIn(collP)

def packageMembers(p: Symbol) = {
  // removes non-existing members from the scope (List$)
  p.info.members.foreach(_.initialize)
  p.info.members.toList.filter(m => !m.isPackage)
}


val msInPackages = allPackages.map(p => (p, {
  val ms = packageMembers(p)
  ms.groupMap(m => m.accessString)(m => {
    val typeMs = m.info.decls.toList.filter(m => !m.isSynthetic)
    (m, typeMs.groupBy(m => m.accessString))
  })
}))

for ((p, packageMsByAccess) <- msInPackages) {
  println(s"${p.fullNameString}:")
  for ((pa, pms) <- packageMsByAccess) {
    val paa = if (pa.isEmpty) "<public>" else pa
    println(s"  $paa:")
    for ((m, typeMsByAccess) <- pms) {
      println(s"    $m:")
      for ((ta, tms) <- typeMsByAccess) {
        val taa = if (ta.isEmpty) "<public>" else ta
        println(s"      $taa:")
        println(tms.mkString("        ", "\n        ", ""))
      }
    }
  }
}

Example output: https://gist.github.com/lrytz/54a920d0025913aec4c544862dd74ea0 - can be improved :)

@lrytz
Copy link
Member Author

lrytz commented Feb 5, 2018

We should also convert the above code to a partest test to make sure no public members are added accidentially.

@SethTisue SethTisue self-assigned this Nov 16, 2018
@SethTisue SethTisue transferred this issue from scala/collection-strawman Feb 20, 2019
@adriaanm adriaanm transferred this issue from scala/scala-dev Mar 13, 2019
@adriaanm adriaanm changed the title Review public members Review scala.collection public members Mar 13, 2019
@adriaanm adriaanm added this to the 2.13.0-RC1 milestone Mar 13, 2019
@joshlemer
Copy link

It would also be handy to include the exposed type of each member, so that nobody accidentally exposes/commits to a return type that's more specific than it should be.

@SethTisue SethTisue modified the milestones: 2.13.0-RC1, 2.13.0 Apr 3, 2019
@SethTisue SethTisue removed their assignment Apr 6, 2019
@SethTisue SethTisue modified the milestones: 2.13.0, 2.13.0-RC3 May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants