Skip to content

Generalizing check_local_application_complete#2818

Merged
riaqn merged 3 commits intomainfrom
split-curried-application
Jul 18, 2024
Merged

Generalizing check_local_application_complete#2818
riaqn merged 3 commits intomainfrom
split-curried-application

Conversation

@riaqn
Copy link
Copy Markdown
Contributor

@riaqn riaqn commented Jul 18, 2024

Background

Consider the example below - what should be the type for f?

let f ~g x = g (x: _ @@ local) x [@nontail]

Ideally it should be something like g:(x @ local -> x -> y) -> x -> y. (Both x and y are both types and variables names, for easier reading). Note that g could also be of type x @ local -> (x -> y), but this is undesirable because it has extra parentheses. However, for printing and generating mli-less .cmi files, the defaulting will push modes on arrows to legacy (global), giving the undesirable type.

The original check_local_application_complete solves this problem by enforcing currying constraint in a single application. For the above example, x being local forces the partially-applied g x to be local as well.

The improvement

This PR does two things:

  • The function was intended only for the locality axis, for which mode_fun <= mode_ret and mode_arg <= mode_ret. In general we have monadic and comonadic axes, for which the constraints should be partial_apply mode_fun <= mode_ret and close_over mode_arg <= mode_ret.

  • The constraint is not for soundness but just for better types. Therefore, failed constraints should be warning instead of error.

Please review by commits.

@riaqn riaqn force-pushed the split-curried-application branch from 1fb2284 to 654e74d Compare July 18, 2024 13:59
@riaqn riaqn marked this pull request as ready for review July 18, 2024 14:34
@riaqn riaqn requested a review from lpw25 July 18, 2024 14:35
@lpw25
Copy link
Copy Markdown
Collaborator

lpw25 commented Jul 18, 2024

The constraint is not for soundness but just for better types. Therefore, failed constraints should be warning instead of error.

As discussed offline, making this a warning makes things order dependent, so it's best to go back to an error.

@riaqn riaqn force-pushed the split-curried-application branch from 654e74d to 6885bb8 Compare July 18, 2024 15:02
@riaqn riaqn force-pushed the split-curried-application branch from 6885bb8 to 9c965ba Compare July 18, 2024 15:19
Copy link
Copy Markdown
Collaborator

@lpw25 lpw25 left a comment

Choose a reason for hiding this comment

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

LGTM

@riaqn riaqn merged commit 679ed42 into main Jul 18, 2024
@riaqn riaqn deleted the split-curried-application branch July 18, 2024 16:18
lukemaurer pushed a commit to lukemaurer/flambda-backend that referenced this pull request Oct 23, 2024
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