-
Notifications
You must be signed in to change notification settings - Fork 324
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
Refactor import resolver to allow for dynamic loading of modules. #1822
Merged
Merged
Changes from all commits
Commits
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
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
engine/runtime/src/main/scala/org/enso/compiler/PackageRepository.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,55 @@ | ||
package org.enso.compiler | ||
|
||
import org.enso.interpreter.runtime.Context | ||
import org.enso.interpreter.runtime.builtin.Builtins | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
trait PackageRepository { | ||
|
||
/** Informs the repository that it should populate the top scope with modules | ||
* belonging to a given package. | ||
* | ||
* @param namespace the namespace of the package. | ||
* @param name the package name. | ||
* @return `Right(())` if the package was already loaded or successfully | ||
* downloaded. A `Left` containing an error otherwise. | ||
*/ | ||
def ensurePackageIsLoaded( | ||
namespace: String, | ||
name: String | ||
): Either[PackageRepository.Error, Unit] | ||
} | ||
|
||
object PackageRepository { | ||
|
||
/** A trait representing errors reported by this system */ | ||
sealed trait Error | ||
|
||
object Error { | ||
|
||
/** An error reported when the requested package does not exist. | ||
*/ | ||
case object PackageDoesNotExist extends Error | ||
} | ||
|
||
/** A temporary package repository, only able to resolve packages known | ||
* upfront to the language context. | ||
* | ||
* @param context the language context | ||
*/ | ||
class Default(context: Context) extends PackageRepository { | ||
|
||
/** @inheritdoc */ | ||
override def ensurePackageIsLoaded( | ||
namespace: String, | ||
name: String | ||
): Either[PackageRepository.Error, Unit] = | ||
if ( | ||
(name == Builtins.PACKAGE_NAME && namespace == Builtins.NAMESPACE) || | ||
context.getPackages.asScala | ||
.exists(p => p.name == name && p.namespace == namespace) | ||
) Right(()) | ||
else Left(Error.PackageDoesNotExist) | ||
} | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
engine/runtime/src/test/resources/Test_Bad_Imports/package.yaml
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,7 @@ | ||
name: Test_Bad_Imports | ||
namespace: Enso_Test | ||
license: APLv2 | ||
enso-version: default | ||
version: "0.0.1" | ||
author: "Enso Team <[email protected]>" | ||
maintainer: "Enso Team <[email protected]>" |
4 changes: 4 additions & 0 deletions
4
engine/runtime/src/test/resources/Test_Bad_Imports/src/Main.enso
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,4 @@ | ||
import Surely_This.Does_Not_Exist.My_Module | ||
import Enso_Test.Test_Bad_Imports.Oopsie | ||
|
||
main = 10 |
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
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.
I'd suggest renaming to
getPreloadedPackages
or something like that and indicating in the doc comment that this will be removed in the next iteration. Just to avoid someone using it in a wrong place by mistake.