Skip to content

Conversation

InsertCreativityHere
Copy link
Member

Currently, the ordering of files is non-deterministic.
ie. When you pass slicec a set of files to compile, the order you pass them in is completely discarded.
This PR changes this behavior, so slicec preserves the order of files; this makes compilation more deterministic, and repeatable.

It does this at two levels:

  • When performing file resolution (so taking command line input and finding the files on disk), we use a HashMap. Now we use a Vec. So we will resolve files in the order that the user supplied them.
  • The files field of CompilationState is a HashMap, now it's a Vec. So we will parse the files in the order they were resolved, we will validate the files in the order they were resolved, etc. (The keys of the map were just file.relative_path, so it was also just redundant information... the path is already stored in the SliceFile itself.)

The only downside is we now have to use Vec::iter().find() when looking for a file, instead of HashMap::get().

@InsertCreativityHere InsertCreativityHere changed the title Ordered compilation 1 Ordered Compilation Feb 21, 2024
@ReeceHumphreys ReeceHumphreys self-requested a review February 21, 2024 19:17
pub struct CompilationState {
pub ast: Ast,
pub diagnostics: Diagnostics,
pub files: HashMap<String, SliceFile>,
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth a comment to say why we're using a vec

Copy link
Contributor

@ReeceHumphreys ReeceHumphreys left a comment

Choose a reason for hiding this comment

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

Looks good!

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