Skip to content

[RFC] Remove internal parser API used by atdgen #151

@Leonidas-from-XIV

Description

@Leonidas-from-XIV

Current state & Rationale

Yojson currently has a semi-secret undocumented API that allows controlling the parser - when you know what the structure of the JSON is you can tell the parser what you expect and it will give you the values in a somewhat more streaming way.

The downside is that this exposes the internals of Yojson which is not great because this locks us into our current implementation. Another issue is that this code is under-used and most importantly under-tested, so improvements sometimes can break code and it doesn't get detected before the release.

Proposal

The proposal is to remove the internal code. Initially this can be just hidden from the interface and then we can shake down and rewrite the unused code.

A possible replacement for the API could be to use the Yojson.Safe.t API. Given there are a number of consumers that convert a predefined structure from JSON to OCaml (like atdgen, ppx_deriving_yojson, ppx_yojson_conv) we could consider adding some optimized API that avoids creating a full AST but rather allows libraries to get JSON to parse with lower overhead while not exposing the internals too much.

Impact

This is under-researched at the moment, but the major consumer of this API is atdgen. mjambon suggests that atdgen could be changed to use the Yojson.Safe.t AST.

Roadmap

This is another breaking change, so would need a dependency bump. Given a lot of code uses atdgen, a number of packages would be impacted, but once atdgen is adjusted it could generate new code that would Just Work(TM).

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcRequest for Comments on future direction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions