Skip to content

Commit

Permalink
Remove LoadedModuleName
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Jun 21, 2024
1 parent 9f73cf3 commit a93cc3f
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions src/ghci/loaded_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use crate::normal_path::NormalPath;
/// Hashing and equality are determined by the module's path alone.
#[derive(Debug, Clone, Eq)]
pub struct LoadedModule {
/// The module's source file.
/// The module's source file, like `src/My/Cool/Module.hs`.
path: NormalPath,

/// The module's name.
/// The module's dotted name, like `My.Cool.Module`.
///
/// This is present if and only if the module is loaded by name.
///
Expand All @@ -41,14 +41,6 @@ impl LoadedModule {
}
}

/// Get the name to use to refer to this module.
pub fn name(&self) -> LoadedModuleName {
match self.name.as_deref() {
Some(name) => LoadedModuleName::Name(name),
None => LoadedModuleName::Path(&self.path),
}
}

/// Get the module's source path.
pub fn path(&self) -> &NormalPath {
&self.path
Expand All @@ -57,7 +49,13 @@ impl LoadedModule {

impl Display for LoadedModule {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name())
write!(
f,
"{}",
self.name
.as_deref()
.unwrap_or_else(|| self.path.relative().as_str())
)
}
}

Expand Down Expand Up @@ -96,27 +94,3 @@ impl Borrow<Utf8Path> for LoadedModule {
&self.path
}
}

/// The name to use to refer to a module loaded into a GHCi session.
///
/// Entries in `:show targets` can be one of two types: module paths or module names (with `.` in
/// place of path separators). Due to a `ghci` bug, the module can only be referred to as whichever
/// form it was originally added as (see below), so we use this to track how we refer to modules.
///
/// See: <https://gitlab.haskell.org/ghc/ghc/-/issues/13254#note_525037>
#[derive(Debug)]
pub enum LoadedModuleName<'a> {
/// A path to a Haskell source file, like `src/My/Cool/Module.hs`.
Path(&'a Utf8Path),
/// A dotted module name, like `My.Cool.Module`.
Name(&'a str),
}

impl<'a> Display for LoadedModuleName<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LoadedModuleName::Path(path) => write!(f, "{path}"),
LoadedModuleName::Name(name) => write!(f, "{name}"),
}
}
}

0 comments on commit a93cc3f

Please sign in to comment.