Skip to content
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

Add ExportImportResolutionBenchmark #10043

Merged
merged 29 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5bbd576
Move TestBase into a new project test-utils
Akirathan May 22, 2024
9e70f67
Add ExportImportResolutionBenchmark.
Akirathan May 22, 2024
99cad2e
Add unit test for exports symbol restrictions and module order
Akirathan May 27, 2024
4512650
Do not optimize symbols in ExportsResolution
Akirathan May 29, 2024
5c902bf
Revert "Add ExportImportResolutionBenchmark."
Akirathan May 30, 2024
0df3ceb
Revert "Move TestBase into a new project test-utils"
Akirathan May 30, 2024
06818be
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan May 30, 2024
b626421
Add ExportImportResolutionBenchmark
Akirathan May 30, 2024
b62d0d3
Revert "Do not optimize symbols in ExportsResolution"
Akirathan May 30, 2024
cc83ef0
Remove ExportResolutionTest
Akirathan May 30, 2024
f0a99fd
Add ExportedSymbolsTest
Akirathan May 30, 2024
820cfe8
Add ExportCycleDetectionTest
Akirathan May 30, 2024
0b8932d
ProjectUtils: Main module does not have to exist when creating a project
Akirathan Jun 4, 2024
6064dc4
Add test-utils to sbt aggregate
Akirathan Jun 4, 2024
5ca3735
fmt
Akirathan Jun 4, 2024
adc3815
Add test for symbol hiding
Akirathan Jun 4, 2024
b7fbb85
Remove ExportCycleDetectionTest
Akirathan Jun 6, 2024
e84a2f9
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan Jun 6, 2024
157df9c
Do not optimize symbols in ExportsResolution
Akirathan Jun 6, 2024
a66b6eb
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan Jun 11, 2024
6c2c1b5
Revert "Do not optimize symbols in ExportsResolution"
Akirathan Jun 11, 2024
a048114
Reintroduce ExportCycleDetectionTest
Akirathan Jun 11, 2024
35113c2
Add test for exported symbols in synthetic modules
Akirathan Jun 11, 2024
ab6d733
Add test for export cycle detection in three modules
Akirathan Jun 11, 2024
712d99b
Remove unnecessary imports from tests
Akirathan Jun 11, 2024
ed225d3
Minoc docs fix - remove non-existing link
Akirathan Jul 12, 2024
cb05246
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan Jul 12, 2024
aa722df
Fix of imports after merge with develop
Akirathan Jul 12, 2024
971ea6e
fmt
Akirathan Jul 12, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package org.enso.interpreter.test

import org.enso.common.CompilationStage
import org.enso.compiler.data.BindingsMap
import org.enso.compiler.data.BindingsMap.SymbolRestriction.{
AllowedResolution,
Intersect,
Only,
Union
}
import org.enso.compiler.phase.{ExportsResolution, ImportResolver}
import org.enso.pkg.QualifiedName
import org.enso.polyglot.{PolyglotContext, RuntimeOptions}
import org.enso.test.utils.{SourceModule, TestUtils}
import org.graalvm.polyglot.Context
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.BeforeAndAfter

import java.nio.file.{Files, Path}

class ExportResolutionTest
Copy link
Member

Choose a reason for hiding this comment

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

Scala. Eh!

extends AnyWordSpecLike
with Matchers
with BeforeAndAfter {

var ctx: Context = null
var projDir: Path = null
var importsResolver: ImportResolver = null
var exportsResolver: ExportsResolution = null
var mainMod: org.enso.compiler.context.CompilerContext.Module = null
var aMod: org.enso.compiler.context.CompilerContext.Module = null
var bMod: org.enso.compiler.context.CompilerContext.Module = null
var dataMod: org.enso.compiler.context.CompilerContext.Module = null
var aModAllowedRes: AllowedResolution = null
var dataModAllowedRes: AllowedResolution = null

before {
val aModSrc =
"""
|type T
|""".stripMargin
val aSrcMod =
new SourceModule(QualifiedName.fromString("Data.A_Module"), aModSrc)
val bModSrc =
"""
|from project.Data.A_Module export T
|""".stripMargin
val bSrcMod =
new SourceModule(QualifiedName.fromString("Data.B_Module"), bModSrc)
val mainSrc =
"""
|import project.Data
|import project.Data.B_Module
|export project.Data
|export project.Data.B_Module
|""".stripMargin
val mainSrcMod = new SourceModule(QualifiedName.fromString("Main"), mainSrc)
this.projDir = Files.createTempDirectory("export-resolution-test")
TestUtils.createProject(
"Proj",
java.util.Set.of(aSrcMod, bSrcMod, mainSrcMod),
projDir
)
this.ctx = TestUtils
.defaultContextBuilder()
.option(RuntimeOptions.PROJECT_ROOT, projDir.toAbsolutePath.toString)
.build()
val ensoCtx = TestUtils.leakContext(ctx)
val compiler = ensoCtx.getCompiler
this.importsResolver = new ImportResolver(compiler)
this.exportsResolver = new ExportsResolution(compiler.context)
this.mainMod =
ensoCtx.getPackageRepository.getLoadedModule("local.Proj.Main").get;
mainMod.getCompilationStage shouldEqual CompilationStage.INITIAL
val polyCtx = new PolyglotContext(ctx)
polyCtx.getTopScope.compile(true)
mainMod.getCompilationStage shouldEqual CompilationStage.AFTER_CODEGEN
this.aMod = ensoCtx.getPackageRepository
.getLoadedModule("local.Proj.Data.A_Module")
.get
this.bMod = ensoCtx.getPackageRepository
.getLoadedModule("local.Proj.Data.B_Module")
.get
this.dataMod = ensoCtx.getPackageRepository
.getLoadedModule("local.Proj.Data")
.get
aMod.getCompilationStage shouldEqual CompilationStage.AFTER_CODEGEN
bMod.getCompilationStage shouldEqual CompilationStage.AFTER_CODEGEN
dataMod.getCompilationStage shouldEqual CompilationStage.AFTER_CODEGEN

this.aModAllowedRes = AllowedResolution(
"a_module",
Some(
BindingsMap.ResolvedModule(
BindingsMap.ModuleReference.Concrete(aMod)
)
)
)
this.dataModAllowedRes = AllowedResolution(
"data",
Some(
BindingsMap.ResolvedModule(
BindingsMap.ModuleReference.Concrete(dataMod)
)
)
)
}

after {
TestUtils.deleteRecursively(projDir)
ctx.close()
}

"Symbol restrictions" should {
"union optimization" in {
val union = Union(
List(
Only(Set(aModAllowedRes))
)
)
val optimizedUnion = union.optimize
val allowedSyms = optimizedUnion.asInstanceOf[Only].symbols
allowedSyms.size shouldEqual 1
allowedSyms.head.symbol shouldEqual "a_module"
allowedSyms.head.resolution shouldBe defined
allowedSyms.head.resolution.get.qualifiedName.item shouldEqual "A_Module"
}

"union with two only syms optimization" in {
val union = Union(
List(
Only(Set(aModAllowedRes)),
Only(Set(dataModAllowedRes))
)
)
val optimizedUnion = union.optimize
optimizedUnion.isInstanceOf[Only] shouldBe true
val syms = optimizedUnion.asInstanceOf[Only].symbols
syms.size shouldBe 2
syms.head.symbol shouldEqual "a_module"
syms.last.symbol shouldEqual "data"
}

"empty intersect optimization" in {
val intersect = Intersect(
List(Only(Set(dataModAllowedRes)), Only(Set(aModAllowedRes)))
)
val optimized = intersect.optimize
optimized.isInstanceOf[Only] shouldBe true
optimized.asInstanceOf[Only].symbols.isEmpty shouldBe true
}
}

"Export resolution module order" should {
"correctly sort modules after export resolution" in {
// The import resolver has to run first. Without it, export resolution would not
// work at all.
val res =
importsResolver.mapImports(mainMod, bindingsCachingEnabled = false)
withClue("bindings caching is disabled") {
res._2.isEmpty shouldBe true
}
val modulesWithResolvedImps = res._1
val modulesToCompile = exportsResolver.run(modulesWithResolvedImps)
modulesToCompile.isEmpty shouldBe false
val modNames = modulesToCompile.map(_.getName.item)
// B_Module export A_Module
// Data export List(B_Module, A_Module)
// Main exports Data
modNames should contain theSameElementsInOrderAs List(
"A_Module",
"B_Module",
"Data",
"Main"
)
}
}

}
Loading