Skip to content

WIP: Unified IO layer - #26512

Draft
SolalPirelli wants to merge 4 commits into
scala:mainfrom
dotty-staging:solal/nio
Draft

WIP: Unified IO layer#26512
SolalPirelli wants to merge 4 commits into
scala:mainfrom
dotty-staging:solal/nio

Conversation

@SolalPirelli

@SolalPirelli SolalPirelli commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Part of #26492

Adds a new IO package (nio, which will eventually be renamed io) and replaces all uses of java.io, java.nio, dotty.tools.io.AbstractFile, and dotty.tools.io.Path in the compiler tests with it (except interacting with the compiler and tests for the old IO stuff)

The new IO package:

  • Has File and FileContainer as separate types
    • this ensures one can't call methods that make no sense, e.g., writing to a directory or getting a file's subfiles
    • a directory is a file container, but it's not the only kind, ZIPs and JARs are also containers
    • for ZIPs and JARs one can get a File representing the file and then obtain a FileContainer from that representing its insides (but they cannot be confused)
  • Does not expose java.io.File nor java.nio.file.Path at all
  • Ensures all operations to read/write text require a Codec
  • Supports multi-release JARs, with an API that requires a version always
  • Provides convenience methods to read/write as text, as lines, etc. (that subclasses can override if they have a faster way to do it)
  • Encapsulates all implementations completely (so the rest of the code never needs to special case on disk files vs in-memory files etc.)

No other changes for now.

Have you relied on LLM-based tools in this contribution?

No

How was the solution tested?

Covered by existing tests (this is a refactoring)

Comment thread compiler/src/dotty/tools/nio/DiskDirectory.scala
Comment thread compiler/src/dotty/tools/nio/JarContainer.scala Outdated
Comment thread compiler/src/dotty/tools/nio/JarContainer.scala Outdated
Comment thread compiler/src/dotty/tools/nio/JarContainer.scala Outdated
Comment thread compiler/src/dotty/tools/nio/JarContainer.scala Outdated
Comment thread compiler/src/dotty/tools/nio/JarContainer.scala Outdated
@SolalPirelli
SolalPirelli force-pushed the solal/nio branch 5 times, most recently from 04eca90 to 8a43af1 Compare August 4, 2026 14:30

override def size(): Long = contents match
case (s: String, c: Codec) =>
-1 // TODO: remove size() ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reminder for myself

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants