Skip to content

Fix flambda issues following multicore merge#10909

Merged
xavierleroy merged 11 commits intoocaml:trunkfrom
lthls:multicore-flambda-testsuite-fixes
Jan 17, 2022
Merged

Fix flambda issues following multicore merge#10909
xavierleroy merged 11 commits intoocaml:trunkfrom
lthls:multicore-flambda-testsuite-fixes

Conversation

@lthls
Copy link
Copy Markdown
Contributor

@lthls lthls commented Jan 15, 2022

As discussed in #10878.

The only change from what has been discussed there is that I haven't removed warning 59, but made it conditional on flambda invariant checks (@chambart thinks the check can still be useful).
As a consequence, I've also added a Sys.opaque_identity call in CamlinternalLazy to prevent the warning from triggering there even if it is enabled.

Closes #10878.

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

In general this looks fine, but I have more comments/questions on the lazy-related parts, sorry.

(* Assumes [blk] is a block with tag forcing *)
let do_force_block blk =
let b = Obj.repr blk in
let b = Obj.repr (Sys.opaque_identity blk) in
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This use of Sys.opaque_identity is not explained by a comment. Could you add a comment to explain what is going on?

In fact, the comment you added in 0f30379 has disappeared from trunk, probably dropped during the Multicore rebases. Could you add it back? (I think it makes sense to add the two comments at the same time, they will be more consistent with each other this way.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the right place to call Sys.opaque_identity? (And if it is, why isn't do_force_val_block handled in the same way?) My understanding is that this function is consistent with the idea that blk is a mutable block, and that it is only called on values that do respect this assumption -- same thing with force_gen_lazy_block, which would have as precondition that the input is a mutable block, as it unconditionally calls update_to_forcing.

Where is the actual move from "possibly immutable" to "certainly mutable" going on? I think it takes place within the code of force_gen, so this is where Sys.opaque_identity should be placed. But there is one already. Maybe we should add a Popaque primitive in inline_lazy_force_* instead of here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where is the actual move from "possibly immutable" to "certainly mutable" going on? I think it takes place within the code of force_gen, so this is where Sys.opaque_identity should be placed. But there is one already. Maybe we should add a Popaque primitive in inline_lazy_force_* instead of here?

That's a good idea. I'll push an update with that solution.

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks!

(I assume that @lthls tested that flambda works well in trunk with this PR applied, I did not.)

let call_force_lazy_block varg loc =
(* The argument is wrapped with [Popaque] to prevent the compiler from making
any assumptions on its contents. Alternatively, [ap_inlined] could be set
to [Never_inline]. *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to add a reference here to the PRs #9998 and #10909 that go into the details of why we need Popaque.

(I spend a good share of my review energy asking people to explain decisions more in comments. Maybe I'm more often than most in the position of reading year-old compiler code that I'm unfamiliar with, trying to reverse-engineer detailed justifications for the non-obvious things that are going on?)

@lthls
Copy link
Copy Markdown
Contributor Author

lthls commented Jan 16, 2022

I've added a Changes entry with only the user-visible change (the restriction on warning 59), because I'm not sure where the rest would fit (the testsuite fixes could be considered part of the multicore PR, and I guess the lazy stuff could have an entry in Internal/compiler-libs changes).

I think it should be safe to re-enable a flambda build in the CI, but it's not part of this PR.

Copy link
Copy Markdown
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for this flambda resurrection. Merging ASAP.

@xavierleroy xavierleroy merged commit e188c9a into ocaml:trunk Jan 17, 2022
@xavierleroy
Copy link
Copy Markdown
Contributor

You may need to fix the reference output of one of the tests, now that the EffectHandlers stdlib module was renamed to Effect.

@lthls
Copy link
Copy Markdown
Contributor Author

lthls commented Jan 17, 2022

You're right. I also forgot to adapt the test for warning 59, so I've opened #10912 with these fixes.

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.

Flambda + Multicore

3 participants