diff --git a/engine/runtime/src/main/scala/org/enso/compiler/pass/analyse/BindingAnalysis.scala b/engine/runtime/src/main/scala/org/enso/compiler/pass/analyse/BindingAnalysis.scala index 6359047cb78c..a773c75868b1 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/pass/analyse/BindingAnalysis.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/pass/analyse/BindingAnalysis.scala @@ -105,10 +105,12 @@ case object BindingAnalysis extends IRPass { n.exportedSymbols = bp.exportedSymbols n } else { - BindingsMap( + val n = BindingsMap( definedSumTypes ++ importedPolyglot ++ moduleMethods, ModuleReference.Concrete(moduleContext.module) ) + moduleContext.module.bindings = n + n } ir.updateMetadata( diff --git a/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala b/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala index fdea377ed47e..0b26d9ce701a 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala @@ -53,10 +53,13 @@ case object GlobalNames extends IRPass { ir: IR.Module, moduleContext: ModuleContext ): IR.Module = { - val scopeMap = ir.unsafeGetMetadata( + var scopeMap = ir.unsafeGetMetadata( BindingAnalysis, "No binding analysis on the module" ) + if (moduleContext.module.bindings != null) { + scopeMap = moduleContext.module.bindings + } val freshNameSupply = moduleContext.freshNameSupply.getOrElse( throw new CompilerError( "No fresh name supply passed to GlobalNames resolver." diff --git a/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeNames.scala b/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeNames.scala index 56c0312cb575..b3cbcc6c9123 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeNames.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeNames.scala @@ -40,8 +40,11 @@ case object TypeNames extends IRPass { ir: IR.Module, moduleContext: ModuleContext ): IR.Module = { - val bindingsMap = + var bindingsMap = ir.unsafeGetMetadata(BindingAnalysis, "bindings analysis did not run") + if (moduleContext.module.bindings != null) { + bindingsMap = moduleContext.module.bindings + } ir.copy(bindings = ir.bindings.map { d => val mapped = d.mapExpressions(resolveExpression(bindingsMap, _)) doResolveType( diff --git a/engine/runtime/src/main/scala/org/enso/compiler/phase/ImportResolver.scala b/engine/runtime/src/main/scala/org/enso/compiler/phase/ImportResolver.scala index 1f4a492ec86d..1b7061abc8e8 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/phase/ImportResolver.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/phase/ImportResolver.scala @@ -99,8 +99,20 @@ class ImportResolver(compiler: Compiler) { .map { concreteBindings => concreteBindings } - current.bindings = converted.getOrElse(null) - current.bindings = converted.getOrElse(null) + if (converted.isDefined) { + if (current.bindings == null) { + current.bindings = converted.get + } else { + val update: BindingsMap = current.bindings + val imports = converted.get.resolvedImports ++ update.resolvedImports + val exports = converted.get.resolvedExports ++ update.resolvedExports + val symbols = converted.get.exportedSymbols ++ update.exportedSymbols + converted.get.resolvedImports = imports + converted.get.resolvedExports = exports + converted.get.exportedSymbols = symbols + current.bindings = converted.get + } + } ( converted .map(