Skip to content

ppx can generate code that assumes stdlib/pervasives are in scope #591

Description

@davesnx

Problem

ppx authors frequently encounter issues where code generated implicitly relies on Stdlib modules and functions being in scope. This creates problems for users who:

  • Use alternative standard libraries (Base, Core, etc.)
  • Want explicit control over what's in scope
  • Compile with -nopervasives or similar flags

It's not rare to generate code that relies on Array, List, String Printf or even raise, invalid_arg, etc.

Current workarounds

Right now I track down each stdlib dependency in generated code (easy to lose cases such as |> or <=)
I have used a cram test with (flags -nopervasives) to catch assumptions (but it is unreliable since nopervasives propagate to all dependencies).

Potential solution

Could ppxlib/metaquote provide:

  1. Fully qualified generation - Generate Stdlib.List.map instead of List.map
  2. Configuration option - Allow PPX authors to specify whether to generate qualified names
  3. Lint/warning system - Warn when generated code assumes stdlib availability
  4. Some utilities - A way to test ppx output without stdlib assumptions (nopervasives seems not useful)

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