Skip to content

Spurious links in source rendering when using deriving #1456

Description

@klakplok

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 ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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