#190 compat re-exports are abstract aliases: FormerHome.Ctor, FormerHome.field and type equations stop compiling (2,303 alias lines in blend 0.0.39-beta.4)

未关闭
#241 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start with test/module-move-compat.mjs and the acceptance criteria: it should cover an enum moved by an SCC merge and compile a constructor through the former home. Then trace the emitter that writes compat files and the type X = New.X alias lines, and find where moved-module information is recorded after #171 renames. Done means FormerHome.Ctor and type t = FormerHome.x = | … compile for enums, with shadowing handled in reused live homes.

由索引模型根据 Issue 内容生成。

描述

Summary

When #190 moves a type to another module, the former home gets a compatibility re-export of the form

type inputSizeV2 = HighchartsSharedSharedTypes.inputSizeV2

That keeps type annotations resolving, but it is an abstract alias, so everything else a consumer writes against the former home stops compiling:

  1. Constructors — FormerHome.Md → The variant constructor FormerHome.Md can't be found.
  2. Record fields — {FormerHome.name: …} / x.FormerHome.name no longer resolve.
  3. Type equations — type t = FormerHome.x = | A | B → This variant or record definition does not match that of type FormerHome.x. Their kinds differ.

So for variants and records the public path is only half preserved. The file header says "Old X.<name> annotations keep resolving", which is accurate, but most real usage of an enum is its constructors.

Evidence — @juspay/[email protected] (bindgen 1.4.0-beta.8)

Alias-only compat lines per module:

Module alias lines
ContextSharedTypes 1336
HighchartsSharedTypes 866
SidebarV2Types 30
DateRangePickerTypes 27
TopbarV2Types 15
ChartsV2Types 14
DirectoryTypes 8
InputsV2Types 7

Upgrading a consumer app from 0.0.38-beta.1 to 0.0.39-beta.4:

  • 60 references of the form ContextSharedTypes.Md / .Lg / .Count / DateRangePickerTypes.Right failed with "constructor can't be found", although every one of those paths has a compat line.
  • The app already carries ~270 hand-written lines of narrow re-exports (type menuAlignment = HighchartsSharedSharedTypes.menuAlignment = | @as("start") Start | …) to get constructors and fields back under the old module names. One of them broke again on this bump: it pointed at InputsV2Types.uploadStateInputsV22, which is now an alias, so the equation failed with "Their kinds differ".
  • The only alternative is referencing the 53k-line HighchartsSharedSharedTypes directly from app code.

Minimal repro

// New.res
type size = | @as("sm") Sm | @as("md") Md

// Old.res  (what bindgen emits today)
type size = New.size

// Consumer.res
let a: Old.size = Md        // ok (type-directed)
let b = Old.Md              // ✗ The variant constructor Old.Md can't be found
type mine = Old.size = | @as("sm") Sm | @as("md") Md   // ✗ Their kinds differ

Proposed fix

Re-export with the definition repeated, which ReScript accepts and which keeps type identity:

type size = New.size =
  | @as("sm") Sm
  | @as("md") Md

Suggested staging:

  • Part 1 — kind: 'enum': the body has no type references, so it can be emitted verbatim. This alone restores every FormerHome.Ctor path.
  • Part 2 — records / @unboxed / @tag variants: same idea, with field types resolved from the former home's point of view (qualified to the new module).

Two details to handle:

  • Constructor names must be final. #171 renames Class A collisions in place while the new home is emitted, so compat bodies have to be rendered after every live module has been emitted.
  • A former home reused as a live module must not have its own constructors shadowed. If a re-exported enum shares a constructor name with the live module's own types, an unannotated Host.Md would silently change type. Keep the abstract alias for that one type in that case.

Acceptance

  • FormerHome.Ctor compiles for every moved enum, in standalone compat files and in reused live homes (unless it would shadow).
  • type t = FormerHome.x = | … compiles.
  • test/module-move-compat.mjs covers an enum moved by an SCC merge, with a compile check that uses the constructor through the former home.
主要语言
ReScript
星标
11
派生
0
平均合并
7 小时 27 分钟
30 天内合并 PR
6

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

juspay/rescript-bindgen 的其他 Issue

查看 juspay/rescript-bindgen 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。