close
Skip to content

feat(compiler): Enable single-file compilation#2105

Merged
ospencer merged 3 commits into
mainfrom
oscar/dependency-refactor
Feb 16, 2025
Merged

feat(compiler): Enable single-file compilation#2105
ospencer merged 3 commits into
mainfrom
oscar/dependency-refactor

Conversation

@ospencer
Copy link
Copy Markdown
Member

@ospencer ospencer commented May 4, 2024

Refactors the DependenciesCompiled, ObjectsLinked, Compiled, and Assembled states out of compile.re and introduces the grainc flag --single-file to compile a single dependency. The linker is now completely separate from the process of compilation—compiling a file now only means converting source code into an object file. Linking is the combining a number of object files into a wasm file (and grainc will still do both compiling and linking). This allows build tools to handle compilation and linking separately.

The future plan is to make single file mode the default once we have a build tool managing building projects (silo). I'm not sure that we should get rid of the dependency compilation entirely since it would be useful for development, but that's a decision for later.

@ospencer ospencer self-assigned this May 4, 2024
@ospencer ospencer marked this pull request as draft May 4, 2024 00:43
@ospencer ospencer force-pushed the oscar/gro-linking branch 2 times, most recently from 92e6423 to 89fcb11 Compare May 4, 2024 16:15
@ospencer ospencer force-pushed the oscar/dependency-refactor branch 4 times, most recently from 7039e88 to 6e314ce Compare May 10, 2024 01:18
@ospencer ospencer marked this pull request as ready for review May 10, 2024 01:35
Copy link
Copy Markdown
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

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

I read this all through, it made sense, code was clear, LGTM!

@ospencer ospencer requested a review from jozanza as a code owner September 22, 2024 14:25
@ospencer ospencer force-pushed the oscar/gro-linking branch 3 times, most recently from d6920a8 to e4632f3 Compare December 13, 2024 00:58
@ospencer ospencer force-pushed the oscar/dependency-refactor branch from 6e314ce to 9ffb741 Compare January 2, 2025 20:33
Base automatically changed from oscar/gro-linking to main January 13, 2025 22:56
@ospencer ospencer force-pushed the oscar/dependency-refactor branch from 9ffb741 to 3e88dac Compare January 17, 2025 03:49
Copy link
Copy Markdown
Member

@alex-snezhko alex-snezhko left a comment

Choose a reason for hiding this comment

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

Was a bit unclear about some of the changes to the type checking but LGTM overall

Filepath.to_string(input),
)
) {
let compile_typed = file => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This logic with compiling the out of date deps seems to be copy-pasted several times, can move to generic helper? Maybe could also re-instate the boolean flags you removed for resetting compiler state/setting root config in there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They're all slightly different between the hooks (which are parametrizable) and compile functions (which aren't really). We could try to find some commonality, but it's mostly just the load_dependency_graph and get_out_of_date_dependencies; after that the caller is responsible for compiling those any way they see fit. I think it's fine that they're separate, personally.

~name=filename,
source,
);
compile(filename, source);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would reset_compiler_state not be needed here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question. It wasn't before, presumably with the idea that while the LSP is running it's compiling the same stuff. We should probably look into that, but that's a separate issue.

Comment on lines -117 to -121
let stop_found =
switch (stop) {
| Some(d) when DV.equal(d, dep) => true
| _ => false
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume the code you removed here was due to the stop_found not being used but is it not important?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was necessary before because it would iterate to find the next dependency that was out of date so it could be worked on. Now, we just grab all of them at once.

Comment thread compiler/src/typed/env.re Outdated
let clear_persistent_structures = () => {
Consistbl.clear(crc_units);
Hashtbl.clear(persistent_structures);
imported_units := StringSet.empty;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: clear_imports

Comment thread compiler/src/typed/env.re
imported_units := StringSet.add(s, imported_units^);
};

let imported_opaque_units = ref(StringSet.empty);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you explain why you removed these opaque unit imports?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's just old cruft from back in the day.

let type_implementation = (prog: Parsetree.parsed_program) => {
let sourcefile = prog.prog_loc.loc_start.pos_fname;
let module_name = prog.module_name.txt;
Env.clear_imports();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this needed now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This basically used to happen as a part of the full compile pipeline, but now that things are moved around, we reset it where it's relevant.

@ospencer ospencer enabled auto-merge February 16, 2025 18:26
@ospencer ospencer force-pushed the oscar/dependency-refactor branch from 160be30 to 43c64f0 Compare February 16, 2025 20:47
@ospencer ospencer added this pull request to the merge queue Feb 16, 2025
Merged via the queue into main with commit 824b365 Feb 16, 2025
@ospencer ospencer deleted the oscar/dependency-refactor branch February 16, 2025 21:50
@github-actions github-actions Bot mentioned this pull request Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants