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

Add positions to events (issue #37) #69

Merged
merged 15 commits into from
Nov 13, 2023

Conversation

wzwywx
Copy link
Contributor

@wzwywx wzwywx commented Oct 21, 2023

This is a draft PR to improve the diagnostics message as indicated in issue 37.

I've managed to add the position of the return to the ReturnedTypeDoesNotMatch error.

If the solution is acceptable, I can do the same for the other variants.

@wzwywx wzwywx marked this pull request as ready for review October 21, 2023 08:09
@wzwywx wzwywx marked this pull request as draft October 24, 2023 07:33
@wzwywx wzwywx marked this pull request as ready for review October 24, 2023 07:35
@kaleidawave
Copy link
Owner

Hey, was away, so checking back in now.

This looks great!

image

Would be great to add positions to the rest of the Event variants. Unlike the return, they don't have any use in diagnostics/errors right now but will come in very useful in the future.

BTW if the conditional event variant is difficult then you can skip it.

@wzwywx
Copy link
Contributor Author

wzwywx commented Oct 29, 2023 via email

@kaleidawave
Copy link
Owner

Awesome, lmk the time frame you are thinking of. Also #71 changed a lot of files, so remember to update/fast-forward the branch before any changes

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 2, 2023

Thanks for the heads up on the change.

At the moment, no concrete time frame I'm afraid.

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 2, 2023

I'm working on the ReadsReference variant right now and after tracing all the errors once a position is added, I realised that the synthesise_class_fields function is linked to that event and can potentially pass more than one position i.e. one for each field.

pub(super) fn synthesise_class_fields<T: crate::ReadFromFS>(
fields: Vec<(TypeId, PublicityKind, Expression)>,
environment: &mut Environment,
checking_data: &mut CheckingData<T, super::EznoParser>,
) {

Should the event store the positions of all the fields?

@kaleidawave
Copy link
Owner

Ah interesting. Classes aren't fully implemented at the moment, I got 70% through then got stuck so there might be some unused non fully finished functions around. I would put a todo!("get event position") where the position is needed and I can figure out that part when I finish and fix classes.

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 2, 2023 via email

Copy link
Owner

@kaleidawave kaleidawave left a comment

Choose a reason for hiding this comment

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

Looking great so far. So just Event::Setter left? Left a few minor suggestions around the diagnostic messaging. I have some good ideas for how to use these new getter and setter positions 👀 .

reason: format!(
"Function is expected to return {expected_return_type} but returned {returned_type}",
),
labels: vec![(
Copy link
Owner

Choose a reason for hiding this comment

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

Thinking about this, I think returned_position should be the main diagnostic position. Could we swap the values for the main position and label?

Then the main reason should be "Cannot return {returned type} from function expected to return {expected_return_type}" and the label one should be "function annotated to return {expected_return_type} here"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it, let me swap them and see how the new message looks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does this look?

Screenshot 2023-11-04 150607

Copy link
Owner

Choose a reason for hiding this comment

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

@@ -55,8 +55,9 @@ pub(crate) fn get_return_from_events<'a, T: crate::ReadFromFS, M: crate::ASTImpl
&checking_data.types,
false,
),
position: annotation_span,
// TODO event position here #37
position: annotation_span.clone(),
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe rename position to annotation_position

// TODO event position here #37
position: annotation_span.clone(),
// TODO test with return_position
returned_position: position.clone(), // TODO event position here #37
Copy link
Owner

@kaleidawave kaleidawave Nov 3, 2023

Choose a reason for hiding this comment

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

Looking perfect 🤩, can remove the // TODO #37 comment now!

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 4, 2023

Looking great so far. So just Event::Setter left? Left a few minor suggestions around the diagnostic messaging. I have some good ideas for how to use these new getter and setter positions 👀 .

I believe Setter, CallsType, Throw, Conditionally, and CreateObject are left.

Thanks for the suggestions! I'll look into those first before implementing the position for Setter.

Two positions - returned and annotation positions - are given their own names instead of a generic name of `position` for one of them
This implementation needs a closer look because adding a position to Event::Setter requires a lot more work to fix the resulting broken code compared to other events.

The method `register_property` can optionally push the Event::Setter event provided that the argument `register_setter_event` is `true`.
But because Event::Setter requires a position, it needs `register_property` to require a position as well as its parameter since the current parameters have no way to access position.

This introduces certain problems because even though some properties needs `register_setter_event` to be true, they don't have a clear position that can be passed to Event::Setter.
How should we handle the case when a property needs a setter event registered but has no position? For now, because of the existence of some properties with non-obvious (or perhaps absent) positions,
the position in Event::Setter will be optional i.e. `Option<SpanWithSource>`.
@kaleidawave
Copy link
Owner

ignore the test issue, that is something I broke

Replying to setter position:

For now, because of the existence of some properties with non-obvious (or perhaps absent) positions,
the position in Event::Setter will be optional i.e. Option<SpanWithSource>

Yes that's perfect. The register_property function is a bit WIP and has some problems with it. If it is possible put a comment next to any Nones passed as positions to the setter and I will have a think if positions are even needed in that case.

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 8, 2023 via email

This implementation is partially in the sense that `Event::Conditionally` now has a position (albeit optional), but functions/methods that rely on the event only passes None as the position.

There are two places where positions are unclear:
1. Else evaluation (`new_conditional_context()` - it might be possible to get a position from `SynthesisableConditional` but it does not have a `get_position` implemented yet
2. `create_this` - not sure if a position is needed here
@kaleidawave kaleidawave added checking Issues around checking diagnostics related to outputting code errors labels Nov 10, 2023
Also incomplete because I'm not sure how to get a position from `func` (`SynthesisableFunction`). Every position is `None` for now.
@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 11, 2023

I believe all event variants have positions now. Unfortunately, wiring up the positions for Setter, Conditionally, and CreateObject are difficult for me to implement so at the moment, most of them only have None.

@kaleidawave kaleidawave linked an issue Nov 13, 2023 that may be closed by this pull request
@kaleidawave kaleidawave merged commit 4bc8be5 into kaleidawave:main Nov 13, 2023
7 checks passed
@kaleidawave
Copy link
Owner

Awesome just adjusted to use the new return diagnostics message in the tests 071ce96

Apart from that all the other tests pass, so you haven't broken anything!!! and have just merged!

Thanks for the informative comments and commit messages. They will be useful for using the new positions on events.

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 13, 2023

Nice! Thank you for the merge.

I’m happy to have helped, and also thank you for your patience in guiding me throughout the whole process.

@kaleidawave
Copy link
Owner

kaleidawave commented Nov 13, 2023

Awesome. You are also the first to PR to the type checker part of Ezno and implemented something really deep in the core! If you have any feedback on what is messy, difficult or could be made clearer that would be really helpful for me to help future contributors!

Also might post this change on Twitter, let me know if/how you want a shout out :)

@wzwywx
Copy link
Contributor Author

wzwywx commented Nov 13, 2023 via email

@kaleidawave kaleidawave mentioned this pull request Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checking Issues around checking diagnostics related to outputting code errors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add positions to events
2 participants