Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered Compilation #694

Merged

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

#[derive(Debug, Default)]
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.

None yet

3 participants