Skip to content

Commit e24a199

Browse files
Encapsulate access to resolvedImports and exportedSymbols
1 parent ecaee13 commit e24a199

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

engine/runtime-compiler/src/main/scala/org/enso/compiler/data/BindingsMap.scala

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import scala.collection.mutable.ArrayBuffer
2626
* @param currentModule the module holding these bindings
2727
*/
2828
case class BindingsMap(
29-
definedEntities: List[DefinedEntity],
30-
currentModule: ModuleReference
29+
private val _definedEntities: List[DefinedEntity],
30+
private val _currentModule: ModuleReference
3131
) extends IRPass.IRMetadata {
3232
import BindingsMap._
3333

@@ -37,11 +37,23 @@ case class BindingsMap(
3737

3838
/** Other modules, imported by [[currentModule]].
3939
*/
40-
var resolvedImports: List[ResolvedImport] = List()
40+
private var _resolvedImports: List[ResolvedImport] = List()
41+
42+
def definedEntities: List[DefinedEntity] = _definedEntities
43+
def currentModule: ModuleReference = _currentModule
44+
def resolvedImports: List[ResolvedImport] = _resolvedImports
45+
def resolvedImports_(v: List[ResolvedImport]): Unit = {
46+
_resolvedImports = v
47+
}
4148

4249
/** Symbols exported by [[currentModule]].
4350
*/
44-
var exportedSymbols: Map[String, List[ResolvedName]] = Map()
51+
private var _exportedSymbols: Map[String, List[ResolvedName]] = Map()
52+
53+
def exportedSymbols: Map[String, List[ResolvedName]] = _exportedSymbols
54+
def exportedSymbols_(v: Map[String, List[ResolvedName]]): Unit = {
55+
_exportedSymbols = v
56+
}
4557

4658
/** @inheritdoc */
4759
override def prepareForSerialization(
@@ -63,9 +75,9 @@ case class BindingsMap(
6375
* @return `this` with module references converted to abstract
6476
*/
6577
def toAbstract: BindingsMap = {
66-
val copy = this.copy(currentModule = currentModule.toAbstract)
67-
copy.resolvedImports = this.resolvedImports.map(_.toAbstract)
68-
copy.exportedSymbols = this.exportedSymbols.map { case (key, value) =>
78+
val copy = this.copy(_currentModule = _currentModule.toAbstract)
79+
copy._resolvedImports = this._resolvedImports.map(_.toAbstract)
80+
copy._exportedSymbols = this._exportedSymbols.map { case (key, value) =>
6981
key -> value.map(name => name.toAbstract)
7082
}
7183
copy
@@ -77,23 +89,25 @@ case class BindingsMap(
7789
* instances
7890
* @return `this` with module references converted to concrete
7991
*/
80-
def toConcrete(moduleMap: ModuleMap): Option[BindingsMap] = {
92+
private def toConcrete(moduleMap: ModuleMap): Option[BindingsMap] = {
8193
val newMap = this.currentModule.toConcrete(moduleMap).map { module =>
82-
this.copy(currentModule = module)
94+
this.copy(_currentModule = module)
8395
}
8496

8597
val withImports: Option[BindingsMap] = newMap.flatMap { bindings =>
86-
val newImports = this.resolvedImports.map(_.toConcrete(moduleMap))
98+
val newImports = this._resolvedImports.map(
99+
_.toConcrete(moduleMap)
100+
)
87101
if (newImports.exists(_.isEmpty)) {
88102
None
89103
} else {
90-
bindings.resolvedImports = newImports.map(_.get)
104+
bindings._resolvedImports = newImports.map(_.get)
91105
Some(bindings)
92106
}
93107
}
94108

95109
val withSymbols: Option[BindingsMap] = withImports.flatMap { bindings =>
96-
val newSymbols = this.exportedSymbols.map { case (key, value) =>
110+
val newSymbols = this._exportedSymbols.map { case (key, value) =>
97111
val newValue = value.map(_.toConcrete(moduleMap))
98112
if (newValue.exists(_.isEmpty)) {
99113
key -> None
@@ -105,7 +119,7 @@ case class BindingsMap(
105119
if (newSymbols.exists { case (_, v) => v.isEmpty }) {
106120
None
107121
} else {
108-
bindings.exportedSymbols = newSymbols.map { case (k, v) =>
122+
bindings._exportedSymbols = newSymbols.map { case (k, v) =>
109123
k -> v.get
110124
}
111125
Some(bindings)

engine/runtime-compiler/src/main/scala/org/enso/compiler/phase/ImportResolver.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.enso.common.CompilationStage
1111

1212
import scala.collection.mutable
1313
import java.io.IOException
14+
import java.util.logging.Level
1415

1516
/** Runs imports resolution. Starts from a given module and then recursively
1617
* collects all modules that are reachable from it.
@@ -46,7 +47,12 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR {
4647
)
4748
(ir, currentLocal)
4849
} catch {
49-
case _: IOException =>
50+
case ex: IOException =>
51+
context.logSerializationManager(
52+
Level.WARNING,
53+
"Deserialization of " + module.getName() + " failed",
54+
ex
55+
)
5056
context.updateModule(
5157
current,
5258
u => {
@@ -83,8 +89,9 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR {
8389
val newImportIRs =
8490
importedModules.map(_._1) ++ syntheticImports.map(_._1)
8591

86-
currentLocal.resolvedImports =
92+
currentLocal.resolvedImports_(
8793
resolvedImports ++ resolvedSyntheticImports
94+
)
8895
val newIr = ir.copy(imports = newImportIRs)
8996
context.updateModule(
9097
current,

engine/runtime-compiler/src/main/scala/org/enso/compiler/phase/exports/ExportsResolution.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class ExportsResolution(private val context: CompilerContext) {
166166
.flatten
167167
.distinct
168168

169-
bindings.exportedSymbols = List(
169+
val newSymbols = List(
170170
ownEntities,
171171
expSymbolsFromResolvedImps
172172
).flatten.distinct
@@ -179,6 +179,7 @@ class ExportsResolution(private val context: CompilerContext) {
179179
}
180180
(symbolName, resolvedNames)
181181
}
182+
bindings.exportedSymbols_(newSymbols)
182183
}
183184
}
184185

engine/runtime/src/main/java/org/enso/interpreter/caches/ImportExportCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ protected BindingsMap readObject(Input in) throws IOException, ClassNotFoundExce
237237
var imp = in.readInline(scala.collection.immutable.List.class);
238238
var sym = in.readInline(scala.collection.immutable.Map.class);
239239
var map = new BindingsMap(de, cm);
240-
map.resolvedImports_$eq(imp);
241-
map.exportedSymbols_$eq(sym);
240+
map.resolvedImports_(imp);
241+
map.exportedSymbols_(sym);
242242
return map;
243243
}
244244
}

0 commit comments

Comments
 (0)