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

Minor refactoring of assembler API #1426

Merged
merged 4 commits into from
Aug 6, 2024
Merged

Minor refactoring of assembler API #1426

merged 4 commits into from
Aug 6, 2024

Conversation

bobbinth
Copy link
Contributor

@bobbinth bobbinth commented Aug 6, 2024

This PR performs minor cleanup of the Assembler API (though, I think we can clean things up a bit more). It consist of mostly renaming things and moving code around - but there should be no changes which affect the overall functionality or semantics.

The main changes are:

  • Renamed Assembler::add_compiled_library() into Assembler::add_library().
  • Renamed Assembler::with_compiled_library() into Assembler::with_library().
  • Moved ModuleInfo and ProcedureInfo structs into a separate file and renamed some methods of ModuleInfo.
  • Renamed CompiledLibrary into Library.
  • Merged LibraryError with CompiledLibraryError and eliminated unused error variants.

@bobbinth bobbinth added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Aug 6, 2024
@@ -77,9 +80,9 @@ impl CompiledLibrary {
pub fn new(
mast_forest: MastForest,
exports: BTreeMap<QualifiedProcedureName, RpoDigest>,
) -> Result<Self, CompiledLibraryError> {
) -> Result<Self, LibraryError> {
if exports.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason, I never noticed this, but this check feels like something that should be an assertion, not an error that needs to be handled - by the time we're ever attempting to construct a library, we already would've raised errors due to the lack of modules/exports. The only exception to that is during deserialization, and it would make more sense to raise a deserialization error for that, since it is the only place where we can't assume that the library is well-formed.

Only reason I bring it up, is because Library::new feels like it should be infallible - it isn't actually a problem for the library to be empty, just sort of useless; and the assembler already handles validating that there is actually something to assemble before it ever calls this. It would also make it possible to construct a Library empty, and then extend it with MAST bit by bit.

It's not hugely important, but since we're cleaning up the API a bit, figured I'd mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to agree that it is probably fine to have empty libraries - but then we don't need an assertion here either. The user can create, serialize, deserialize etc. libraries without any export and it should be fine. Perhaps we may want to show warnings if this happens, but no need to error out.

One current exception is that we won't allow KernelLibrary to be empty. Technically, this doesn't have to be enforced either, but because of the way we set kernels in the ModuleGraph, it would be a bigger refactoring to remove this restriction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure the restriction is needed for KernelLibrary either, since the "default" kernel is empty - as far as I'm aware the ModuleGraph isn't opinionated on this, the only issue being whether or not any syscalls are made, in which case we'd raise an error about an undefined kernel procedure.

Copy link
Contributor

@bitwalker bitwalker 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! Just a couple suggestions, but nothing that is a blocker IMO.

@bobbinth bobbinth merged commit 2dcd51c into next Aug 6, 2024
9 checks passed
@bobbinth bobbinth deleted the bobbin-assembler-api branch August 6, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog This PR does not require an entry in the `CHANGELOG.md` file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants