ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
92 stars 65 forks source link

Add `[@no_mutable_implied_modalities]` #2716

Closed riaqn closed 1 week ago

riaqn commented 1 week ago

This PR recognizes [@no_mutable_implied_modalities] on mutable fields, so that the modalities global many shared will not be implicited applied.

EDIT: a bit of context: In the old days, mutable implies global many shared modalites. This is needed to prevent (for example) a pointer from global to local.

2369 refines the type-checking. In particular, it allows constructing a local record from a local mutable field. On the other hand, mutable field projected out of a local record can only be local, as opposed to global provided by the global modality. Much existing code relies on that old behaviour, and as a result #2369 still makes mutable imply the modalities just for compatibility.

But in the long run we want to remove the coupling. This attribute allows individual mutable fields to opt out of the coupling, so that programmers can experiment with the new behaviour of mutable.

goldfirere commented 1 week ago

I went to review, but actually I don't know what the specification of this PR is. There have been lots of designs floated around mutability modes. What's the one we're going with? It might be helpful just to make a small diff to the doc, which can then help me review the rest.

riaqn commented 1 week ago

@goldfirere I've amended the description. WRT document - I imagine this is a short-term workaround so we probably don't need to document that?

goldfirere commented 1 week ago

Happy with new tests. Merge when ready.