Skip to content

Add an opaque identity to Obj.is_int#747

Closed
lthls wants to merge 2 commits intooxcaml:mainfrom
lthls:obj-is-int-opaque
Closed

Add an opaque identity to Obj.is_int#747
lthls wants to merge 2 commits intooxcaml:mainfrom
lthls:obj-is-int-opaque

Conversation

@lthls
Copy link
Copy Markdown
Contributor

@lthls lthls commented Jul 26, 2022

Flambda 2 interprets the Is_int primitive as being for variants only.
So on the following example:

let str_len x =
  if Obj.is_int x then
    None
  else if Obj.tag x = Obj.string_tag then
    Some (String.length (Obj.obj x : string))
  else None

The String.length primitive sees an input that has gone through Is_int, so assumes it must be a variant, and simplifies to Invalid.
This occurs in practice in the ExtLib library: https://github.com/ygrek/ocaml-extlib/blob/0779f7a881c76f9aca3d5445e2f063ba38a76167/src/std.ml#L165

@lthls lthls marked this pull request as ready for review July 26, 2022 15:34
@lthls lthls requested a review from mshinwell as a code owner July 26, 2022 15:34
@mshinwell
Copy link
Copy Markdown
Collaborator

Superceded by #749

@mshinwell mshinwell closed this Jul 29, 2022
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