Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006726OCamlback end (clambda to assembly)public2014-12-18 16:462016-12-07 11:37
Reporterchambart 
Assigned Togarrigue 
PrioritynormalSeveritycrashReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version4.03.0+dev / +beta1 
Target VersionFixed in Version4.03.0+dev / +beta1 
Summary0006726: Access to the wrong field of aliased module
DescriptionThe problem was introduced by the commit 15405 "Fix PR#6465: allow incremental weakening of module aliases"

When compiling the example containing 3 files: extUnixAll.ml, extUnix.ml, test_endian_string.ml

ExtUnixAll.ml is

  external unused : unit -> unit = "caml_blit_string"
  module BigEndian = struct
    let get_uint8 str off = 33
  end

ExtUnix.ml is
  module All = ExtUnixAll

test_endian_string.ml is
  open ExtUnix.All
  let test_endian_string x =
    let module B = BigEndian in
    B.get_uint8 x 0
  let v = test_endian_string 1

The module ExtUnixAll compiles to this lambda code:

  (seq
    (seq
      (let (get_uint8/1009 = (function str/1010 off/1011 33))
        (setfield_imm 1 (global ExtUnixAll!) get_uint8/1009))
      0a)
    (let (BigEndian/1012 = (makeblock 0 (field 1 (global ExtUnixAll!))))
      (seq (setfield_imm 0 (global ExtUnixAll!) BigEndian/1012) 0a)))

i.e. the module "BigEndian" is at field 0

With the trunk, test_string_endian compiles to:

  (seq
    (let
      (test_endian_string/1201 =
         (function x/1202
           (let
             (B/1204 = (let (let/1208 =a 0a) (field 1 (global ExtUnixAll!))))
             (apply (field 0 B/1204) x/1202 0))))
      (setfield_imm 0 (global Test_endian_string!) test_endian_string/1201))
    (let (v/1205 = (apply (field 0 (global Test_endian_string!)) 1))
      (setfield_imm 1 (global Test_endian_string!) v/1205))
    0a)

i.e. it tries to access to the module at field 1

When looking at the typedtree, before 15405:

                Pexp_letmodule "B/1012"
                module_expr
                  Pmod_ident "ExtUnix!.All.BigEndian"

after 15405:

                Pexp_letmodule "B/1204"
                module_expr
                  module_expr
                    Pmod_ident "ExtUnix!.All.BigEndian"

i.e. there is an additionnal Tmod_constraint.

My conclusion would be that the external in ExtUnixAll is considered as a regular function when coercing hence shifting the field access.
Steps To Reproduceocamlc -c extUnixAll.ml
ocamlc -c extUnix.ml
ocamlc -c -no-alias-deps test_endian_string.ml
ocamlc -o test.byte extUnixAll.cmo test_endian_string.cmo
./test.byte
TagsNo tags attached.
Attached Filestar file icon bug.tar [^] (10,240 bytes) 2014-12-18 16:46

- Relationships

-  Notes
(0012884)
garrigue (manager)
2014-12-19 08:21

Fix in trunk at revision 15681.
Mtype.strengthen was not computing offsets correctly.
Should probably create a central point to solve this offset thing...

- Issue History
Date Modified Username Field Change
2014-12-18 16:46 chambart New Issue
2014-12-18 16:46 chambart File Added: bug.tar
2014-12-19 08:20 garrigue Status new => resolved
2014-12-19 08:20 garrigue Fixed in Version => 4.03.0+dev / +beta1
2014-12-19 08:20 garrigue Resolution open => fixed
2014-12-19 08:20 garrigue Assigned To => garrigue
2014-12-19 08:21 garrigue Note Added: 0012884
2016-12-07 11:37 xleroy Status resolved => closed
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker