Skip to content

Stamps of identifiers are not unique #13036

Open
@samsa1

Description

@samsa1

The documentation of Ident.rename function states that it returns a identifier with a fresh stamp.

ocaml/typing/ident.mli

Lines 37 to 40 in e72d835

val rename: t -> t
(** Creates an identifier with the same name as the input, a fresh
stamp, and no scope.
@raise [Fatal_error] if called on a persistent / predef ident. *)

However it is not the case because when compiling a module we use a certain stamp generator and another one is used when compiling another module. Thus we can have stamp collisions between different modules.

For example when modifying the function rename in ident.ml to

let rename = function
  | Local { name; stamp = _ }
  | Scoped { name; stamp; scope = _ } ->
      incr currentstamp;
      if name = "H" then Format.printf "H(%i -> %i)\n" stamp !currentstamp;
      Local { name; stamp = !currentstamp }
  | id ->
      Misc.fatal_errorf "Ident.rename %s" (name id)

We clearly see examples when compiling the whole compiler of modules being compiled with rename reducing the stamp of a identifier. Thus showing that the invariant for generating a fresh stamp is broken.

Is the fact that the stamp is not fresh (even if the documentation says so) an accepted behavior or something uncontrolled ?

PS : As a consequence, during the stap OCAMLOPT ocamldoc/odoc_ast.cmx of compilation the comparison function between identifiers is called on 2 identifiers with the same stamp and different names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions