Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support //> using dep "..." directives in Scala REPL #24131

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

Open
lihaoyi wants to merge 5 commits into scala:main
base: main
Choose a base branch
Loading
from lihaoyi:coursier-interface

Conversation

Copy link
Contributor

@lihaoyi lihaoyi commented Oct 3, 2025
edited
Loading

This PR is a proof-of-concept implementation porting over the Ammonite import $ivy functionality to the Scala REPL, using the Scala-CLI using dep syntax. Once this lands, along with other related PRs (#24127, #23849) we can probably deprecate Ammonite and refer people to the main Scala REPL since it'll have acquired all the important features

Tested manually:

$ JAVA_HOME=~/Library/Caches/Coursier/arc/https/cdn.azul.com/zulu/bin/zulu17.56.15-ca-jdk17.0.14-macosx_aarch64.tar.gz/zulu17.56.15-ca-jdk17.0.14-macosx_aarch64/ bin/scala
The `--offline` option is experimental
Please bear in mind that non-ideal user experience should be expected.
If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli
Welcome to Scala 3.8.0-RC1-bin-SNAPSHOT-git-17e82e6 (17.0.14, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
 
scala> import scalatags.Text.all._
-- [E006] Not Found Error: -----------------------------------------------------
1 |import scalatags.Text.all._
 | ^^^^^^^^^
 | Not found: scalatags
 |
 | longer explanation available when compiling with `-explain`
1 error found
 
scala> //> using dep "com.lihaoyi::scalatags:0.13.1"
Resolved 1 dependencies (5 JARs)
 
scala> import scalatags.Text.all._
 
scala> div("hello world").render
val res0: String = "<div>hello world</div>"

Both io.get-coursier:interface and org.virtuslab:using_directives are zero-dependency Java libraries, and so can be used directly without worrying about binary compatibility. Both libraries are widely used in the Scala ecosystem (SBT, Mill, ScalaCLI, Bazel, ...) and should be pretty trustworthy and reliable

Not sure if we want to put this into the compiler codebase, but that's where the REPL logic currently lives, and I figure anyone working on the compiler may find it useful as well. e.g. You can pull in third-party libraries when working in the REPL to see how a new language feature interacts with an existing library.

We can move the logic out of the compiler codebase if we want, but as a first pass this integration seems relatively straightforward. The "correct" way of re-organizing this would be to split the dotty.tools.repl into a separate subproject from the rest of compiler so programmatic non-REPL use cases (e.g. build tools) don't need to pull it in, but that would be a larger refactor beyond the scope of this PR

// Update both compiler classpath and classloader
val prevOutputDir = ctx.settings.outputDir.value
val prevClassLoader = rendering.classLoader()
rendering.myClassLoader = DependencyResolver.addToCompilerClasspath(
Copy link
Member

@bishabosha bishabosha Oct 3, 2025

Choose a reason for hiding this comment

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

just a nod to just a nod to #24119 which has sensitive state towards whatever the current classloader is.

Copy link
Contributor Author

lihaoyi commented Oct 3, 2025

The failure looks like a network flake

Copy link
Member

hamzaremmal commented Oct 4, 2025
edited
Loading

I think we should extract the repl to be its own artifact before accepting this change. @Gedochao lets add splitting the repl from the compiler to next week's core.

lihaoyi reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@bishabosha bishabosha bishabosha left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /