Skip to content

The SourceName and SourceFile structures for identifying files#260

Open
LesterEvSe wants to merge 1 commit intoBlockstreamResearch:dev/importsfrom
LesterEvSe:feature/imports-resolution-strategy
Open

The SourceName and SourceFile structures for identifying files#260
LesterEvSe wants to merge 1 commit intoBlockstreamResearch:dev/importsfrom
LesterEvSe:feature/imports-resolution-strategy

Conversation

@LesterEvSe
Copy link
Copy Markdown
Collaborator

This PR introduces the SourceName and SourceFile abstractions to track the origin of parsed code. With the help of these two structures, we can accurately identify source files and lay the groundwork for proper error diagnostics across multiple files in the future.

@LesterEvSe LesterEvSe requested a review from KyrylR March 27, 2026 19:07
@LesterEvSe LesterEvSe self-assigned this Mar 27, 2026
@LesterEvSe LesterEvSe requested a review from delta1 as a code owner March 27, 2026 19:07
@LesterEvSe LesterEvSe added the enhancement New feature or request label Mar 27, 2026
Comment on lines +5 to +10
/// Identifies the origin of a piece of source code.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum SourceName {
/// A physical file located on the filesystem.
Real(Arc<Path>),
/// An in-memory or virtual source (e.g., `<repl>`, `<unknown>`, or test data).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you elaborate more on what is your vision for using this?

I do not understand what virtual is

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It can be used for error handling in tests or in one-file programs passed as a raw string. It could also be useful in the future if our libraries were in a GH repo rather than on a local disk, as we would not be able to write a real path for them and would need a virtual one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should include this explanation to docs as well then

Comment on lines +14 to +23
impl SourceName {
/// Returns a new `SourceName` with the file extension removed.
/// Virtual sources are returned unchanged.
pub fn without_extension(&self) -> SourceName {
match self {
SourceName::Real(path) => SourceName::Real(Arc::from(path.with_extension(""))),
SourceName::Virtual(name) => SourceName::Virtual(name.clone()),
}
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's add this block when it is actually used

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok

@LesterEvSe LesterEvSe force-pushed the feature/imports-resolution-strategy branch 2 times, most recently from f1432c8 to 4f0f9a1 Compare March 31, 2026 12:17
@LesterEvSe LesterEvSe requested a review from KyrylR March 31, 2026 12:17
@LesterEvSe LesterEvSe force-pushed the feature/imports-resolution-strategy branch from 4f0f9a1 to 5383d35 Compare March 31, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants