Looking at https://ocaml.org/p/core/v0.17.1/doc/src/core/char.ml.html on line 16 we have a link from "type " to the definition of type int, then "t" links to some internal definition from deriving.
Tentative analysis and suggestion:
From what I understand, the root cause is that deriving typerep generates code not marked as ghost whose nodes have the whole toplevel phrase as location.
As a result, Typedtree_traverse collects annotations in the generated code, that are mislocated at the toplevel phrase.
The generator for source files thus outputs nested <a> around the toplevel phrase, one for each annotation. Some generated elements also use the location of the t in type t = ....
In the end, we get something like <a href=...>...<a href=...><a href=...>type <a href=...>t</a> = <a href=...>char</a> ... </a></a>...</a>.
The HTML renderer will auto-close <a> tags, resulting in the observed behaviour (clickable type , t and char to spurious targets).
I suppose the proper fix belongs in deriving (or maybe one of the deriving modules) that does not follow the ppxlib good pratices about ghost locations.
But maybe it would not hurt to have an extra heuristics to detect ill-marked ghost code and either warn, fail or discard? For instance, we could compare the parse tree with the actual contents of the source at the declared location when collecting annotations in the typed tree ?
Looking at https://ocaml.org/p/core/v0.17.1/doc/src/core/char.ml.html on line 16 we have a link from
"type "to the definition oftype int, then"t"links to some internal definition fromderiving.Tentative analysis and suggestion:
From what I understand, the root cause is that
deriving typerepgenerates code not marked as ghost whose nodes have the whole toplevel phrase as location.As a result,
Typedtree_traversecollects annotations in the generated code, that are mislocated at the toplevel phrase.The generator for source files thus outputs nested
<a>around the toplevel phrase, one for each annotation. Some generated elements also use the location of thetintype t = ....In the end, we get something like
<a href=...>...<a href=...><a href=...>type <a href=...>t</a> = <a href=...>char</a> ... </a></a>...</a>.The HTML renderer will auto-close
<a>tags, resulting in the observed behaviour (clickabletype,tandcharto spurious targets).I suppose the proper fix belongs in
deriving(or maybe one of thederivingmodules) that does not follow the ppxlib good pratices about ghost locations.But maybe it would not hurt to have an extra heuristics to detect ill-marked ghost code and either warn, fail or discard? For instance, we could compare the parse tree with the actual contents of the source at the declared location when collecting annotations in the typed tree ?