-
Notifications
You must be signed in to change notification settings - Fork 323
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
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 9e70f67
Add ExportImportResolutionBenchmark.
Akirathan 99cad2e
Add unit test for exports symbol restrictions and module order
Akirathan 4512650
Do not optimize symbols in ExportsResolution
Akirathan 5c902bf
Revert "Add ExportImportResolutionBenchmark."
Akirathan 0df3ceb
Revert "Move TestBase into a new project test-utils"
Akirathan 06818be
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan b626421
Add ExportImportResolutionBenchmark
Akirathan b62d0d3
Revert "Do not optimize symbols in ExportsResolution"
Akirathan cc83ef0
Remove ExportResolutionTest
Akirathan f0a99fd
Add ExportedSymbolsTest
Akirathan 820cfe8
Add ExportCycleDetectionTest
Akirathan 0b8932d
ProjectUtils: Main module does not have to exist when creating a project
Akirathan 6064dc4
Add test-utils to sbt aggregate
Akirathan 5ca3735
fmt
Akirathan adc3815
Add test for symbol hiding
Akirathan b7fbb85
Remove ExportCycleDetectionTest
Akirathan e84a2f9
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan 157df9c
Do not optimize symbols in ExportsResolution
Akirathan a66b6eb
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan 6c2c1b5
Revert "Do not optimize symbols in ExportsResolution"
Akirathan a048114
Reintroduce ExportCycleDetectionTest
Akirathan 35113c2
Add test for exported symbols in synthetic modules
Akirathan ab6d733
Add test for export cycle detection in three modules
Akirathan 712d99b
Remove unnecessary imports from tests
Akirathan ed225d3
Minoc docs fix - remove non-existing link
Akirathan cb05246
Merge branch 'refs/heads/develop' into wip/akirathan/9236-improve-imp…
Akirathan aa722df
Fix of imports after merge with develop
Akirathan 971ea6e
fmt
Akirathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
180 changes: 180 additions & 0 deletions
180
...ime-integration-tests/src/test/scala/org/enso/interpreter/test/ExportResolutionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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" | ||
) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala. Eh!