Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation of equality involving polymorphic variants not optimized #4555

Closed
vicuna opened this Issue May 19, 2008 · 2 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented May 19, 2008

Original bug ID: 4555
Reporter: pzimmer
Status: closed (set by @garrigue on 2008-08-27T10:24:31Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10.2
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: dvaillancourt BenediktGrundmann @mshinwell sweeks sds yminsky pzimmer @mmottl

Bug description

The following code:

let f x = x = `Test

generates a call to caml_equal for the comparison. Equivalent code using pattern matching or (==) generates optimized code with an integer comparison. This looks like one trivial optimization case is missing in the compiler.

Here is a proposed patch (contributed by Mark Shinwell) that seems to be correct and fixes the problem:

--- ocaml-3.10.2/bytecomp/translcore.ml 2007-02-09 08:31:15.000000000 -0500
+++ ocaml-3.10.2-patched/bytecomp/translcore.ml 2008-05-16 18:46:48.000076000 -0400
@@ -279,6 +279,12 @@ let transl_prim prim args =
| [{exp_desc = Texp_construct({cstr_tag = Cstr_constant _}, _)}; arg2]
when simplify_constant_constructor ->
intcomp

  • | [arg1; {exp_desc = Texp_variant(_, None)}]
  •  when simplify_constant_constructor ->
    
  •    intcomp
    
  • | [{exp_desc = Texp_variant(_, None)}; exp2]
  •  when simplify_constant_constructor ->
    
  •    intcomp
    
    | [arg1; arg2] when has_base_type arg1 Predef.path_int
    || has_base_type arg1 Predef.path_char ->
    intcomp
@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented May 28, 2008

Comment author: pzimmer

Note that I accidentally miscategorized this entry: it should be in "OCaml general" and not in "Caml-light". If one of the admins could fix it, that would be great. Thanks.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 27, 2008

Comment author: @garrigue

Fixed as suggested in CVS head (for 3.11)

@vicuna vicuna closed this Aug 27, 2008

@vicuna vicuna added the bug label Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.