bsc crashes with `Fatal error: exception Not_found` on `Some(x)` when the type of `x` comes from a transitive dependency
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- compilers
调研方向
Start in compiler/ml/typeopt.ml at type_cannot_contain_undefined and inspect the Env.find_type lookup, then compare the related code from ReScript 11.1.4 and the call path through compiler/ml/env.ml. Reproduce with the provided npm workspace using npm install and npx rescript build. Done means the transitive-dependency example compiles without Fatal error: exception Not_found and preserves the existing successful cases.
由索引模型根据 Issue 内容生成。
描述
Thank you for filing! Check list:
- Is it a bug? Usage questions should often be asked in the forum instead.
- Concise, focused, friendly issue title & description.
- A minimal, reproducible example.
- OS and browser versions, if relevant.
- Is it already fixed in master? Instructions
bsc exits with a bare Fatal error: exception Not_found (exit code 2) when it compiles Some(x) and the type of x is declared in a package that is only a transitive dependency.
The message names no file, so it is hard to find the module that fails.
Snippet
Three packages in npm workspaces: app (the root) depends on facade, and facade depends on lib-a.
package.json:
{
"name": "app",
"private": true,
"workspaces": ["packages/*"],
"dependencies": {"rescript": "12.3.1"}
}
rescript.json:
{
"name": "app",
"sources": [{"dir": "src"}],
"dependencies": ["facade"]
}
src/App.res:
let x = Some(Facade.v)
packages/facade/package.json:
{"name": "facade", "version": "1.0.0", "dependencies": {"lib-a": "1.0.0"}}
packages/facade/rescript.json:
{"name": "facade", "sources": [{"dir": "src"}], "dependencies": ["lib-a"]}
packages/facade/src/Facade.res:
let v = A.v
packages/lib-a/package.json:
{"name": "lib-a", "version": "1.0.0"}
packages/lib-a/rescript.json:
{"name": "lib-a", "sources": [{"dir": "src"}]}
packages/lib-a/src/A.res:
type t = X
let v = X
npm install
npx rescript build
Actual
Cleaned 0/0
Parsed 3 source files
Compiled 3 modules
Fatal error: exception Not_found
Incremental build failed. Error: Failed to Compile. See Errors Above
The same with the bsc command line from npx rescript compiler-args src/App.res (paths made relative) and a backtrace:
cd lib/bs
OCAMLRUNPARAM=b ../../node_modules/@rescript/linux-x64/bin/bsc.exe -I ../ocaml -runtime-path ../../node_modules/@rescript/runtime -I ../../packages/facade/lib/ocaml -bs-package-name app -bs-package-output commonjs:src:.js src/App.ast
Fatal error: exception Not_found
Raised at Env.find_pers_struct in file "compiler/ml/env.ml", line 699, characters 12-27
Called from Env.find_pers_struct in file "compiler/ml/env.ml" (inlined), line 740, characters 28-54
Called from Env.find_module_descr in file "compiler/ml/env.ml", line 787, characters 8-42
Called from Env.find in file "compiler/ml/env.ml", line 804, characters 25-50
Called from Env.find_type in file "compiler/ml/env.ml" (inlined), line 862, characters 26-48
Called from Typeopt.type_cannot_contain_undefined in file "compiler/ml/typeopt.ml", line 51, characters 17-36
Called from Translcore.transl_exp0 in file "compiler/ml/translcore.ml", lines 829-830, characters 19-32
Called from Translcore.transl_let.transl in file "compiler/ml/translcore.ml", line 1081, characters 18-33
Called from Translmod.transl_structure in file "compiler/ml/translmod.ml", line 371, characters 7-56
Called from Translmod.transl_struct in file "compiler/ml/translmod.ml" (inlined), line 288, characters 2-73
Called from Translmod.transl_implementation in file "compiler/ml/translmod.ml", line 463, characters 16-77
Called from Js_implementation.after_parsing_impl in file "compiler/core/js_implementation.ml", line 147, characters 11-72
Called from Dune__exe__Rescript_compiler_main in file "compiler/bsc/rescript_compiler_main.ml", line 447, characters 6-75
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Re-raised at Location.report_exception_rec in file "compiler/ml/location.ml", line 282, characters 14-25
Called from Location.report_exception in file "compiler/ml/location.ml" (inlined), line 288, characters 31-61
Called from Dune__exe__Rescript_compiler_main in file "compiler/bsc/rescript_compiler_main.ml", line 452, characters 4-35
With -I ../../packages/lib-a/lib/ocaml added, the same command exits with 0 and emits let x = Facade.v;.
It crashes the same way when A.t is a record, an abstract type, an @unboxed variant, or type t = int.
It also crashes when Facade re-exports a function of A with an optional labeled argument, and App.res passes Facade.v to it: Facade.f(~a=Facade.v) for let f = (~a: option<t>=?) => a.
It compiles when App.res uses Facade.v without Some: let x = Facade.v or let x = [Facade.v].
Expected
App.res compiles, as it did with ReScript 11.1.4 (see below).
Possible cause: in type_cannot_contain_undefined (compiler/ml/typeopt.ml), Env.find_type p env runs before match decl.type_kind with, so the | exception _ -> false case does not catch its Not_found.
In 11.1.4, the lookup was inside the match expression; it moved out in #7458.
Worked in ReScript 11
The same files with ReScript 11.1.4, and bs-dependencies instead of dependencies in both rescript.json files, build without errors.
lib/js/src/App.js:
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Facade = require("facade/lib/js/src/Facade.js");
var Caml_option = require("rescript/lib/js/caml_option.js");
var x = Caml_option.some(Facade.v);
exports.x = x;
/* No side effect */
Environment
- ReScript 12.3.1, 13.0.0-alpha.6, and master
58c6c89(from pkg.pr.new, reports13.0.0-alpha.7): the same crash on all three. - Node.js 24.9.0
- Linux x86_64
Context
We hit it in a test file: a package with test helpers re-exports a test library with include (Lib: module type of Lib), and the test passed a value of an @unboxed variant type from that library to an optional labeled argument.
The tested package lists only the helper package in its dependencies.
Workaround
Add the package that declares the type (lib-a) to the dependencies of the package that fails to compile (app).
- 主要语言
- ReScript
- 星标
- 7.5k
- 派生
- 483
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 120
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript#8833 · 1 个 reaction ·
维护者通常 1 天内回复
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.json可能已有人在做 @cknitt 于 3 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 35/100
rescript-lang/rescript#8825 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8806 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8798 ·
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 58/100
rescript-lang/rescript#8757 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
A `--symbolic` entry binding `𝑛3` and `!n3` passes the load check, since `once` compares spellings, and fails mid-run with a `user error`可能已有人在做 @sherenkov 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
objectionary/phino#1929 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
FuRongJun-1999/dsh-memory#402 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
-
Graph decomposition passes multi-register wires to compiled rules in the wrong order (wrong SemiAdder results)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug frontend
难度 2/5 1-3 小时 新手友好度 68/100
PennyLaneAI/catalyst#3337 ·
维护者通常 1 天内回复