Skip to content

Structured resolver errors#2482

Open
PhoebeSzmucer wants to merge 19 commits intobytecodealliance:mainfrom
PhoebeSzmucer:structured-resolver-errors
Open

Structured resolver errors#2482
PhoebeSzmucer wants to merge 19 commits intobytecodealliance:mainfrom
PhoebeSzmucer:structured-resolver-errors

Conversation

@PhoebeSzmucer
Copy link
Copy Markdown
Contributor

Part of #2460 (part 1 was here).

This PR replaces most of anyhow usages in the resolver with structured ParserError type, which carries structured error information (with spans).

@alexcrichton
Copy link
Copy Markdown
Member

Happy to take a look when you feel this is ready, but I'm interpreting the draft state as "come back later" for now -- just wanted to note this

@PhoebeSzmucer
Copy link
Copy Markdown
Contributor Author

Thanks @alexcrichton. No review needed just yet - I'm still cleaning up some final things and do one more self review, and I'll mark it as ready soon.

@@ -1,11 +1,15 @@
//! Error types for WIT parsing.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added some missing docs

Resolve::default()
}

/// Parse WIT packages from the input `path`.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doc was very out of date.

return Err(arbitrary::Error::IncorrectFormat);
}
let err = e.to_string();
if err.contains("shadows previously") || err.contains("mismatch in stability") {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both of these are ResolveErrorKind::Semantic. We could introduce a dedicated type for them to prevent string matching, either now or in a follow up PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Although wit-smith is just a fuzzer so idk if it's worth it.

/// Merge `main` and `deps` into this [`Resolve`], topologically sorting
/// them internally. Returns the [`PackageId`] of `main` and a
/// [`PackageSources`] covering all groups.
fn sort_unresolved_packages(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note - this function was restructured to do upfront merging so that if a DuplicatePackage or PackageCycle error happens, we already have valid spans in the error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added some tests for this

/// The returned [`PackageId`] corresponds to `main`.
///
/// On error, `self` may be partially modified and should not be reused.
pub fn push_groups(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This function is something I will want to use in the WIT LSP. I was going to add it in a separate PR, but having this function now makes it much easier to test the behavior of sort_unresolved_packages.

);
}

assert!(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note we went from bail! to assert!, but this is a programmer error (pushing the same package twice), not a WIT source error. So I think panic is more appropriate here.

@PhoebeSzmucer PhoebeSzmucer marked this pull request as ready for review April 10, 2026 10:04
@PhoebeSzmucer PhoebeSzmucer requested a review from a team as a code owner April 10, 2026 10:04
@PhoebeSzmucer PhoebeSzmucer requested review from fitzgen and removed request for a team April 10, 2026 10:04
@PhoebeSzmucer
Copy link
Copy Markdown
Contributor Author

@alexcrichton this is ready for a review now. I left some inline comments on the PR

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.

2 participants