Skip to content

Enforce the external boundary for native binding functors #417

Open

Description

@jderochervlk

Goal

Close the external-consumer boundary around reusable native binding functors without requiring the private-record construction/write migration in #404 to wait on a broader API redesign.

This is follow-up work to #403/#404, not a claim that #404 provides package-wide native-instance soundness. Private records and alpha.7 reject record construction/update/coercion into protected native types; public generic FFI functors are a separate escape route.

Reproduction on ReScript 13.0.0-alpha.7

module Receiver = {type t = {getRootNode: unit => string}}
module FakeNode = WebAPI.Node.Impl(Receiver)
let forged: WebAPI.Node.t =
  FakeNode.getRootNode({getRootNode: () => "not a node"})

This compiles against the packed package and produces a string at runtime, without consumer unsafe casts, raw JavaScript, externals, or :>. Removing unrestricted identity upcasts closes those shortcuts but does not constrain generic native-returning methods.

Investigation before implementation

Prefer preserving internal reuse and the existing concrete module API over generating inherited bindings if a smaller enforceable boundary exists. Investigate sealed family modules/interfaces, real package-level visibility, and sound receiver constraints. Use packed consumer probes, not naming conventions or source-text checks.

The existing sources.public configuration is documented as visibility but is unimplemented in Rewatch, including alpha.7. See rescript-lang/rescript#6760 and the upstream rewatch/CompilerConfigurationSpec.md. A .resi hides declarations from library siblings as well as consumers. Investigate compiler-enforced project/package-scoped visibility separately; do not assume an unreleased compiler feature is available. allowed-dependents is another candidate for a separate internal-package design, subject to transitive access/type identity/packaging validation.

Build-time specialization into concrete bindings remains a fallback, not an approved design. Current baseline has 18 Impl definitions and 150 top-level applications.

Acceptance

  • Consumers cannot instantiate native bindings over arbitrary receivers through public or helper-module routes.
  • Concrete inherited methods, private record field reads, typed setters, base conversions, helper types, generics and feature selection remain usable.
  • Native representation is retained, preferably with direct JS calls and no wrappers/new unsafe casts.
  • Positive library-internal and negative external-consumer cases cover packed installs, normal and feature-only builds, and relevant monorepo layouts.
  • Event callback payload typing and unknown native unions/results remain separately tracked in Make native Web API object types private #403 unless explicitly added to this scope.

No implementation strategy, compiler change, merge or release is authorized by this issue alone.

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