Skip to content

Make sure closures which are statically allocated by the compiler use black infix headers.#9735

Closed
jhjourdan wants to merge 1 commit intoocaml:trunkfrom
jhjourdan:black_infix_static
Closed

Make sure closures which are statically allocated by the compiler use black infix headers.#9735
jhjourdan wants to merge 1 commit intoocaml:trunkfrom
jhjourdan:black_infix_static

Conversation

@jhjourdan
Copy link
Copy Markdown
Contributor

Indeed, we now rely on this in the no-naked-pointers mode, for example in weak.c since #9698. The compactor will also rely on this if #9728 gets merged.

I hope there are no other places where infix headers are created outside of the heap.

… black infix headers.

Indeed, we now rely on this in the no-naked-pointers mode, for example
in weak.c.
@jhjourdan
Copy link
Copy Markdown
Contributor Author

Cc @xavierleroy.

@jhjourdan
Copy link
Copy Markdown
Contributor Author

Concerning the Changes file : I was tempted to add this PR to the Change entry corresponding to #9698, but there does not seem to be one.

What do you think is the best to do?

@jhjourdan
Copy link
Copy Markdown
Contributor Author

As @damiendoligez mentioned in #9698, we will need to also adapt the ancient library.

An alternative solution would be to special-case the infix header in all the places of the runtime where we rely on the fact that out-of-heap headers are black. @xavierleroy: apart from the code in weak.c and the compactor (where we already plan to add this special case), do you see other places?

@xavierleroy
Copy link
Copy Markdown
Contributor

It's up to @damiendoligez to decide whether the compactor can tolerate white infix headers in out-of-heap closures.

Personally I'm reminded of Postel's robustness principle: it is more consistent and less surprising to color infix headers like we color closure headers: black for statically-allocated closures, white for dynamically-allocated closures.

@xavierleroy
Copy link
Copy Markdown
Contributor

@xavierleroy: apart from the code in weak.c and the compactor (where we already plan to add this special case), do you see other places?

Not off the top of my head. Generic primitives (comparison, etc) do not check colors.

@stedolan
Copy link
Copy Markdown
Contributor

stedolan commented Jul 6, 2020

I must have missed something in #9698. Where is the color of an infix header inspected? That seems like it is always a bug.

@jhjourdan
Copy link
Copy Markdown
Contributor Author

In weak.h, we have currently:

  ephemeron_again:
    if (child != caml_ephe_none
        && Is_block (child) && Is_in_value_area (child)){
      /* ... */
      if (Is_white_val (child) && !Is_young (child)){
      /* ... */
      }
    }

Where child can be any OCaml value (possibly an infix pointer).

@jhjourdan
Copy link
Copy Markdown
Contributor Author

And indeed, you are right, this is a bug.

@stedolan
Copy link
Copy Markdown
Contributor

stedolan commented Jul 6, 2020

That looks very much like it is a bug, probably a variant of #7810.

The Is_white_val(child) && !Is_young(child) looks like it's trying to detect whether child is an unmarked major heap block, but will incorrectly return true on an infix part of a marked major heap blcok (since infix headers are not mutated when the block changes color)

@jhjourdan
Copy link
Copy Markdown
Contributor Author

Ok, let me try to propose a fix for this.

@xavierleroy
Copy link
Copy Markdown
Contributor

will incorrectly return true on an infix part of a marked major heap blcok (since infix headers are not mutated when the block changes color

Well spotted!

Coming back to the present PR: what is the conclusion concerning infix headers in statically-allocated closures? Black or white?

@stedolan
Copy link
Copy Markdown
Contributor

stedolan commented Jul 6, 2020

Coming back to the present PR: what is the conclusion concerning infix headers in statically-allocated closures? Black or white?

My position is that infix headers do not in fact have a color, much like blocks on the minor heap. For consistency, the GC color bits should have a consistent value, and all-bits-zero is the obvious choice, matching what the native compiler and bytecode interpreter currently do. (I think that all translates to a vote for "white", since Caml_white == 0)

@jhjourdan
Copy link
Copy Markdown
Contributor Author

As @stedolan explained, it is always a bug to read the color of infix pointers, in the runtime and elsewhere. So this PR is pointless. Closing.

The issue concerning infix pointer in ephemerons has a tentative fix in #9742.

@jhjourdan jhjourdan closed this Jul 6, 2020
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.

3 participants