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

Implement main expressions #168

Merged
merged 1 commit into from
Mar 25, 2024
Merged

Implement main expressions #168

merged 1 commit into from
Mar 25, 2024

Conversation

BinderDavid
Copy link
Collaborator

@BinderDavid BinderDavid commented Mar 22, 2024

david@anaxes ~/polarity/polarity (add-main-functions)$ pol run examples/vect.pol 
examples/vect.pol typechecked successfully!
Cons(S(S(S(Z))), Z, Cons(S(S(Z)), Z, Cons(S(Z), Z, Cons(Z, Z, Nil))))

@BinderDavid BinderDavid marked this pull request as ready for review March 22, 2024 15:27
match nf {
Some(nf) => print_nf(&nf),
None => {
println!("No \"main\" expression was found in the program.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

eprintln! to print to stderr or better return Err(...) to print to stderr and exit with status code 1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed, we should split pol run into pol check and pol run. I can do that in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have implemented both check and run in this PR, and use a miette error to report if a main expression wasn't found.

impl<P: Phase> Let<P> {
/// Returns whether the declaration is the "main" expression of the module.
pub fn is_main(&self) -> bool {
self.name == "main" && self.params.is_empty()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably forbid parameters on let bindings called main during lowering.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reasoning: otherwise it is confusing for users because they will see the error message "main not found" but they have a main expression with a different signature.

lang/syntax/src/trees/generic/def.rs Outdated Show resolved Hide resolved
@BinderDavid BinderDavid force-pushed the add-main-functions branch 3 times, most recently from daf2d40 to c95d53f Compare March 24, 2024 15:57
Copy link
Collaborator

@timsueberkrueb timsueberkrueb 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, but I advocate for throwing a different error if main has an unexpected signature.

impl<P: Phase> Let<P> {
/// Returns whether the declaration is the "main" expression of the module.
pub fn is_main(&self) -> bool {
self.name == "main" && self.params.is_empty()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reasoning: otherwise it is confusing for users because they will see the error message "main not found" but they have a main expression with a different signature.

Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

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

I suggest throwing a different error when the main signature is unexpected because otherwise the error message of not being able to find the main expression will confuse users if they have a main expression with parameters.

- `pol run` executes the main expression in a file
- `pol check` only typechecks a file
@BinderDavid
Copy link
Collaborator Author

I have added a help message to the error:

david@anaxes ~/polarity/polarity (add-main-functions)$ pol run examples/example.pol
Error:   × Main expression was not found
  help: Main expressions must be called "main" and not take any arguments.

@BinderDavid BinderDavid merged commit 321276b into main Mar 25, 2024
6 checks passed
@BinderDavid BinderDavid deleted the add-main-functions branch April 16, 2024 16:07
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