Skip to content

WIP another swing and lazy package object loading #117

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

Draft
wants to merge 1 commit into
base: 2.12.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ abstract class SymbolLoaders {

protected def enterIfNew(owner: Symbol, member: Symbol, completer: SymbolLoader): Symbol = {
assert(owner.info.decls.lookup(member.name) == NoSymbol, owner.fullName + "." + member.name)
owner.info.decls enter member
owner.rawInfo match {
case loader: PackageObjectLoader =>
loader.scope enter member
case _ =>
owner.info.decls enter member
}
member
}

Expand Down Expand Up @@ -286,14 +291,43 @@ abstract class SymbolLoaders {
* Loads contents of a package
*/
class PackageLoader(packageName: String, classPath: ClassPath) extends SymbolLoader with FlagAgnosticCompleter {
private val decls: Scope = newScope
protected def description = {
val shownPackageName = if (packageName == ClassPath.RootPackage) "<root package>" else packageName
s"package loader $shownPackageName"
s"package loader ${shownPackageName(packageName)}"
}

protected def doComplete(root: Symbol) {
assert(root.isPackageClass, root)
root.setInfo(new PackageClassInfoType(newScope, root))
val scope = newScope
root.setInfo(new PackageObjectLoader(packageName, root, scope)

val classPathEntries = classPath.list(packageName)

if (!root.isRoot)
for (entry <- classPathEntries.classesAndSources) initializeFromClassPath(root, entry)
if (!root.isEmptyPackageClass) {
for (pkg <- classPathEntries.packages) {
val fullName = pkg.name

val name =
if (packageName == ClassPath.RootPackage) fullName
else fullName.substring(packageName.length + 1)
val packageLoader = new PackageLoader(fullName, classPath)
enterPackage(root, name, packageLoader)
}

openPackageModule(root)
}
}
}
class PackageObjectLoader(packageName: String, root: Symbol, val scope: Scope) extends SymbolLoader with FlagAgnosticCompleter {
protected def description = {
s"package object loader ${shownPackageName(packageName)}"
}
protected def doComplete(root: Symbol) {
assert(root.isPackageClass, root)
val scope = newScope
Copy link

Choose a reason for hiding this comment

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

A new scope? Or the new scope it's constructed with?

root.setInfo(new PackageObjectLoader(packageName, root, scope)

val classPathEntries = classPath.list(packageName)

Expand All @@ -314,6 +348,7 @@ abstract class SymbolLoaders {
}
}
}
private def shownPackageName(packageName: String) = if (packageName == ClassPath.RootPackage) "<root package>" else packageName
private lazy val classFileDataReader: ReusableInstance[ReusableDataReader] = new ReusableInstance[ReusableDataReader](() => new ReusableDataReader(), enabled = isCompilerUniverse)
class ClassfileLoader(val classfile: AbstractFile, clazz: ClassSymbol, module: ModuleSymbol) extends SymbolLoader with FlagAssigningCompleter {
private object classfileParser extends {
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Namers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,11 @@ trait Namers extends MethodSynthesis {
def enterPackage(tree: PackageDef) {
val sym = createPackageSymbol(tree.pos, tree.pid)
tree.symbol = sym
newNamer(context.make(tree, sym.moduleClass, sym.info.decls)) enterSyms tree.stats
val scope = sym.rawInfo match {
case loader: loaders.PackageObjectLoader => loader.scope
case _ => sym.info.decls
}
newNamer(context.make(tree, sym.moduleClass, scope)) enterSyms tree.stats
}

private def enterImport(tree: Import) = {
Expand Down