Use forward slash as the path separator on all platforms

All paths in the files package and the compiler internals now use / as the separator on every platform, including Windows.
23 files changed +293 −306

Motivation

Cross-platform path code required every layer to normalize separators independently. The C runtime, the compiler, the stdlib, and each tool all had their own #ifdef blocks choosing \ on Windows and / elsewhere. Missing one meant backslashes leaking through on Windows, causing silent lookup failures when one layer stored a path with \ and another searched for it with /.

This PR makes / the canonical separator everywhere: the C runtime normalizes at ingress, the compiler does the same, Path.sep() returns "/" unconditionally, and Path.clean() converts any remaining \ on Windows.

File Map

▶ Stdlib: files package 3 files
▶ Release notes and CHANGELOG 2 files

Behavioral Changes

Paths are /-separated on all platforms

Path.sep() returns "/" on Windows (previously "\\"). Path.cwd(), Path.canonical(), Path.join(), Path.clean(), and all other path operations produce /-separated paths. Windows code that compared paths against string literals with \ will stop matching.

Path.normcase() only lowercases

On Windows, normcase() previously replaced / with \ and lowercased the path. It now only lowercases.

Path.from_slash() and Path.to_slash() removed

These functions served no purpose when all paths are already /-separated. Any code calling them will fail to compile.

Path.to_os() added

Converts / to \ on Windows. Returns the path unchanged on other platforms.

Windows cmd.exe footgun: cmd.exe interprets / as an option flag, not a path separator. Code that passes paths to cmd.exe or .bat files must wrap them with Path.to_os() to convert back to \. Win32 API calls accept / without issue — the footgun is specifically at the shell boundary.

dir(), base(), ext(), split() handle both separators on Windows

These functions now use an internal _rfind_sep helper that finds both / and \ on Windows. Paths from external sources (e.g. __loc.file()) that still contain \ are handled correctly without requiring a prior clean().

API Changes

▶ Changed Path.sep() — now returns "/" on all platforms
fun tag sep(): String =>
  ifdef windows then "\\" else "/" end
fun tag sep(): String =>
  "/"
▶ Changed Path.normcase() — no longer replaces / with \
fun normcase(path: String): String =>
  if Platform.windows() or Platform.osx() then
    var p = path.lower()
    ifdef windows then
      p = Path.from_slash(p)
    end
    p
  else
    path
  end
fun normcase(path: String): String =>
  if Platform.windows() or Platform.osx() then
    path.lower()
  else
    path
  end
▶ Removed Path.from_slash() and Path.to_slash()
fun from_slash(path: String): String =>
  ifdef windows then
    path.clone() .> replace("/", "\\")
  else
    path
  end

fun to_slash(path: String): String =>
  ifdef windows then
    path.clone() .> replace("\\", "/")
  else
    path
  end
// Removed. Delete any calls to these functions.
▶ Added Path.to_os() — convert to OS-native separators
// No equivalent. Code that needed backslash paths
// on Windows used Path.from_slash().
fun to_os(path: String): String =>
  ifdef windows then
    // replaces '/' with '\\' byte by byte
    let s = path.clone()
    // ...
    s
  else
    path
  end
▶ Changed Path.split() — now finds both separators on Windows
fun split(path: String,
  separator: String = Path.sep()
): (String, String) =>
  try
    let i = path.rfind(separator)?.usize()
    (clean(path.trim(0, i)),
     path.trim(i + 1))
  else
    ("", path)
  end
fun split(path: String,
  separator: String = Path.sep()
): (String, String) =>
  try
    let i = _rfind_sep(path)?.usize()
    (clean(path.trim(0, i)),
     path.trim(i + 1))
  else
    ("", path)
  end

Public API Surface

Changed primitive Path
Operations on paths that do not require a capability. All paths use / as the separator on every platform.
  • fun is_sep(c: U8): Bool
  • fun tag sep(): String
  • fun is_abs(path: String): Bool
  • fun join(path: String, next_path: String): String
  • fun clean(path: String): String
  • fun normcase(path: String): String
  • fun cwd(): String
  • fun abs(path: String): String
  • fun rel(to: String, target: String): String ?
  • fun split(path: String, separator: String = Path.sep()): (String, String)
  • fun base(path: String, with_ext: Bool = true): String
  • fun dir(path: String): String
  • fun ext(path: String): String
  • fun volume(path: String): String
  • fun to_os(path: String): String
  • fun canonical(path: String): String ?
  • fun is_list_sep(c: U8): Bool
  • fun list_sep(): String
  • fun split_list(path: String): Array[String] iso^
  • fun random(len: USize = 6): String

Architecture

The change normalizes paths at four ingress points. Everything downstream receives /-separated paths without needing its own normalization.

Normalization Points GetFullPathName GetModuleFileName getcwd (Win32) return \ paths pony_realpath \ → / get_compiler_exe_path \ → / pony_os_cwd \ → / Compiler (package.c) Compiler (codegen) Stdlib (Path.*) PATH_SLASH Macro (all files) Before: ifdef → '\' or '/' 4 separate #ifdef blocks → After: unconditional '/' no #ifdef needed Escape hatch: Path.to_os() Converts / → \ when passing paths to cmd.exe or .bat files

Release Notes

Use forward slash as the path separator on all platforms

All paths in the files package now use / as the separator on every platform, including Windows. Paths from Path.cwd() and Path.canonical() are /-separated, Path.sep() returns "/" unconditionally, and Path.clean() converts \ to / on Windows.

Path.is_sep() still accepts \ on Windows for parsing external input. Use Path.to_os() when a backslash path is needed for Windows shell commands.

Path.normcase() now only lowercases the path on case-insensitive platforms. It no longer replaces / with \ on Windows.

Before:

if path == "C:\\Users\\me\\project" then
  // ...
end

After:

if path == "C:/Users/me/project" then
  // ...
end

Code that passes paths to Windows shell commands should use Path.to_os():

let os_path = Path.to_os(path)

Remove Path.from_slash and Path.to_slash

Path.from_slash() and Path.to_slash() have been removed. All paths use / as the separator on every platform, so these functions served no purpose. Remove any calls to them.

CHANGELOG

Changed

  • Use forward slash as the path separator on all platforms (PR #6276)
  • Remove Path.from_slash and Path.to_slash (PR #6276)