Skip to content

Fix block preallocation and finer value block desc comparison - #4

Merged
let-def merged 2 commits into
introcaml-550from
introcaml-fix-sharing
Aug 5, 2026
Merged

let-def merged 2 commits into
introcaml-550from
introcaml-fix-sharing

Conversation

@let-def

@let-def let-def commented Aug 5, 2026

Copy link
Copy Markdown
Owner

This PR implements two changes.

First a bug fix in Cmm_helpers.preallocate_block which dropped block descriptions.
In particular, this broke cyclic constants:

 --- Cyclic List ---
-[1; <cycle>]
+(1, <cycle>)
 
 --- Prefixed cyclic list ---
-[0; 1; <cycle>]
+(0, (1, <cycle>))
 
 --- Indirect cycle ---
-[1; 2; 3; <cycle>]
+[1; 2<malformed list>]

The second fix is an attempt at making optimization passes "block_desc"-aware, but I am not sure whether this is a good idea or not.

@lthls: If you have some time to spare, I would be grateful if you could take a look ;)

@lthls

lthls commented Aug 5, 2026

Copy link
Copy Markdown

The Cmm_helpers part is obviously right (it should have been part of my Flambda PR, but I missed it).
The flambda changes are more subtle, but they both correspond to things that I thought about when writing my PR so I can give some context.

The code in Simple_value_approx was intentionally dropping block descriptions when encountering blocks with the same contents but different descriptions. This was meant to keep optimisations that share identical blocks (so that adding introspection would not degrade performance). But I think it was actually misguided: this code isn't involved in constant sharing, only when merging approximations coming from different branches (it should have been called join, not meet, but that's another story).
I don't know if it matters in practice: I think that we can only get matching tags and sizes but mismatched descriptions when GADTs are involved, and in that case it's probably fine to lose the approximation. So I think we can keep your patch (at least when introspection is enabled).

The code in Simplify_primitives looks more dangerous, as getting it wrong would be a soundness issue. We use structurally_different to prove physical difference, so if two blocks only differ in their descriptions I chose to err on the side of caution and assume that they might actually get shared (if the descriptions get dropped, for instance). I don't think there is a significant benefit to being more precise here, so I would advise to take the less risky road and leave the code as I wrote it.

let-def added 2 commits August 5, 2026 20:21
Comment by @lthls:

The code in Simple_value_approx was intentionally dropping block descriptions when encountering blocks with the same contents but different descriptions. This was meant to keep optimisations that share identical blocks (so that adding introspection would not degrade performance). But I think it was actually misguided: this code isn't involved in constant sharing, only when merging approximations coming from different branches (it should have been called join, not meet, but that's another story).
I don't know if it matters in practice: I think that we can only get matching tags and sizes but mismatched descriptions when GADTs are involved, and in that case it's probably fine to lose the approximation. So I think we can keep your patch (at least when introspection is enabled).
@let-def
let-def force-pushed the introcaml-fix-sharing branch from d37f641 to ebf7ea9 Compare August 5, 2026 11:23
@let-def

let-def commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

Thanks for your quick feedback. I have dropped the structurally_different part. The negative names should have tipped me off that it was a conservative approximation.

I will make a new release asap including your flambda changes.

@let-def
let-def merged commit 46daa81 into introcaml-550 Aug 5, 2026
11 of 21 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.

2 participants