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

Reporting source locations for errors #398

Merged
merged 13 commits into from
Aug 22, 2024
Merged

Conversation

yihozhang
Copy link
Collaborator

image

Base automatically changed from yihozhang-span-annotated-asts to main July 25, 2024 19:15
@yihozhang yihozhang marked this pull request as ready for review August 15, 2024 07:12
@yihozhang yihozhang requested a review from a team as a code owner August 15, 2024 07:12
@yihozhang yihozhang requested review from oflatt and removed request for a team August 15, 2024 07:12
@yihozhang yihozhang linked an issue Aug 22, 2024 that may be closed by this pull request
Copy link
Member

@oflatt oflatt left a comment

Choose a reason for hiding this comment

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

Great work! Super exciting to see these working! Had a couple minor changes, feel free to merge after fixing

@@ -339,6 +358,7 @@ pub(crate) fn desugar_command(
};

desugar.desugar_program(
// TODO: all spans should be that of the original query
desugar.parse_program(None, &desugaring).unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

We could panic when this unwrap fails, and point to the span for the query extract. It would be an okay way to fix the error message here

Copy link
Collaborator Author

@yihozhang yihozhang Aug 22, 2024

Choose a reason for hiding this comment

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

This would not work in a lot of cases since the failure usually happens at a later stage (typechecking or run time). One way to do it right is to write a subst_span : Command -> (Span -> Span) -> Command function that substitutes the spans. However, since this is the only case where we need to give spans right now manually, I just changed the implementation to build the AST directly. In the future we can implement this subst_span function if needed.

@@ -460,16 +481,7 @@ impl Desugar {
}

pub fn desugar_function(&mut self, fdecl: &FunctionDecl) -> Vec<NCommand> {
Copy link
Member

Choose a reason for hiding this comment

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

perhaps we don't need desugar_funciton anymore?

/// A [`Span`] contains the file name and a pair of offsets representing the start and the end.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Span(pub Arc<SrcFile>, pub usize, pub usize);

impl Span {
Copy link
Member

Choose a reason for hiding this comment

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

Why have Quote and Span? Why not just Span with a display that does the same thing as a Quote?
Looks like we don't build a quote manually anywhere

Copy link
Collaborator Author

@yihozhang yihozhang Aug 22, 2024

Choose a reason for hiding this comment

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

You're right no one should build a quote manually. However, computing Quote from Span takes O(N) time so fmt might not be the best place to do it. However, the original implementation needed to clone the program texts which is costly, so I changed the implementation to use a reference instead.

Output {
span: Span,
file: String,
exprs: Vec<GenericExpr<Head, Leaf>>,
},
Push(usize),
Copy link
Member

Choose a reason for hiding this comment

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

How did you decide what gets a span? Looks like Push doesn't have one. Perhaps because there are no error messages with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah there's no error message associated with push right now. For now I just added spans to commands that may report a TypeError.

@yihozhang yihozhang merged commit b04953f into main Aug 22, 2024
6 checks passed
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.

We need better error messages
2 participants