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

functoria: Constraint the start function to 'unit Lwt.t' #1524

Merged
merged 2 commits into from May 5, 2024

Conversation

Julow
Copy link
Contributor

@Julow Julow commented Apr 26, 2024

This allows to catch subtle bugs caused by partial applications or by returning 'unit Lwt.t Lwt.t' using the type-system.

@hannesm
Copy link
Member

hannesm commented Apr 26, 2024

the CI reports:

File "applications/dhcp/mirage/main.ml", line 190, characters 8-10:
Error: This variant pattern is expected to have type
         (unit, Netif.error) result
       There is no constructor () within type result

And indeed, the toplevel "Mirage_net.listen" returns a "(unit, error) result Lwt.t", while now "unit Lwt.t" is demanded. The error message is unfortunately slightly confusing. Any chance we come up with a better one?

@hannesm
Copy link
Member

hannesm commented Apr 26, 2024

Let me rephrase my comment: I'm in favour of merging this as is (and fix the mirage-skeleton dhcp example). It improves the current situation (and the struggle you had for nearly a day).

@Julow
Copy link
Contributor Author

Julow commented Apr 26, 2024

I've found a way to have a better error message. Let's see if that also works in the CI.

@hannesm
Copy link
Member

hannesm commented Apr 26, 2024

The error message is now:

File "applications/dhcp/mirage/main.ml", line 190, characters 8-18:
Error: This pattern matches values of type unit
       but a pattern was expected which matches values of type
         (unit, Netif.error) result

@Julow Julow force-pushed the functoria-constr-main-start branch from e4d5a5c to 60d5a6f Compare April 26, 2024 11:54
@Julow
Copy link
Contributor Author

Julow commented Apr 26, 2024

Right! I had other type constraint in my local test that interfered with my testing. I'm out of ideas of how to locate the error into user code.
With the last commit, the error is no longer about the pattern, which feels clearer, but that requires a new type definition in the prelude. Happy to revert that if the previous message was good enough and changing the prelude is problematic.

@hannesm
Copy link
Member

hannesm commented Apr 26, 2024

the latest error is:

File "applications/dhcp/mirage/main.ml", line 190, characters 3-67:
Error: This expression has type (unit, Netif.error) result start
       but an expression was expected of type unit start
       Type (unit, Netif.error) result is not compatible with type unit 

could you run a dune build @fmt --auto?

The start in type unit start looks slightly strange, maybe it should be type unit io for better readability?

@Julow Julow force-pushed the functoria-constr-main-start branch 2 times, most recently from 7fee732 to c048550 Compare April 26, 2024 21:18
@Julow
Copy link
Contributor Author

Julow commented Apr 26, 2024

I amended the last commit to use io instead. I propose to keep the two commits in case the io type have to be reverted later.

@hannesm
Copy link
Member

hannesm commented Apr 28, 2024

I opened mirage/mirage-skeleton#393 to fix the mirage-skeleton issue

@hannesm
Copy link
Member

hannesm commented Apr 28, 2024

I'm happy with this change, the mirage-skeleton has been fixed. I don't understand why the CI doesn't catch up (I clicked on rebuild, but it reused the old mirage-skeleton). Any help is appreciated, maybe a force-push will solve something?

Julow added 2 commits May 1, 2024 16:37
This allows to catch subtle bugs caused by partial applications or by
returning 'unit Lwt.t Lwt.t' using the type-system.
With this change, the error message is no longer about the pattern and
looks clearer.

Unfortunately, the location is still within generated code. This also
requires adding the `'a io` type in the prelude.

    File "bin/mirage/mirage/main.ml", lines 300-305, characters 3-12:
    Error: This expression has type (unit, 'a) result Lwt.t
           but an expression was expected of type unit start = unit Lwt.t
           Type (unit, 'a) result is not compatible with type unit
@Julow Julow force-pushed the functoria-constr-main-start branch from c048550 to 2f9ed65 Compare May 1, 2024 14:37
@Julow
Copy link
Contributor Author

Julow commented May 2, 2024

The CI is still failing after a rebase and a force push. I've run all the steps locally in the latest mirage-skeleton and it's building fine.

@hannesm
Copy link
Member

hannesm commented May 3, 2024

I think I remember, the CI system uses the dev branch of mirage-skeleton for the main branch of mirage. I pushed the change to dhcp onto the dev branch as well, so if you could trigger the CI another time here, we may see green checkmarks.

Thanks so much.

EDIT: no need to do anything, CI kicked in automatically :)

@Julow
Copy link
Contributor Author

Julow commented May 5, 2024

The checks are passing!

@hannesm hannesm merged commit dceedf1 into mirage:main May 5, 2024
3 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.

None yet

2 participants