Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
> - :nail_care: [Polish]
> - :house: [Internal]

# 12.3.1 (Unreleased)

#### :bug: Bug fix

- Fix rewatch warning replay after early compile errors. https://github.com/rescript-lang/rescript/pull/8408
- Fix formatting of trailing comments before `=` in let bindings. https://github.com/rescript-lang/rescript/pull/8444
- Fix namespaced reference lookup in editor analysis. https://github.com/rescript-lang/rescript/pull/8455
- Fix build crash when the compiler emits output that is not valid UTF-8, such as a truncated multibyte character in a code frame. https://github.com/rescript-lang/rescript/pull/8482
- Preserve multibyte characters when wrapping long source lines in compiler code frames. https://github.com/rescript-lang/rescript/pull/8520
- Preserve parentheses around multiplication, division, and modulo expressions used as exponents. https://github.com/rescript-lang/rescript/pull/8550
- Enforce function arity in interface/module inclusion, type equality, and coercion. https://github.com/rescript-lang/rescript/pull/8559
- Fix bare labeled arrow types (`~x: int => string`) getting no arity and failing to unify with their parenthesized form. https://github.com/rescript-lang/rescript/pull/8563

# 12.3.0

No changes compared to 12.3.0-beta.1.
Expand Down
60 changes: 40 additions & 20 deletions analysis/src/Cmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ let fullForCmt ~moduleName ~package ~uri cmt =
let extra = ProcessExtra.getExtra ~file ~infos in
Some {file; extra; package}

let fullForIncrementalCmt ~package ~moduleName ~uri =
if !Cfg.inIncrementalTypecheckingMode then
let path = Uri.toPath uri in
let incrementalCmtPath =
package.rootPath ^ "/lib/bs/___incremental" ^ "/" ^ moduleName
^
match Files.classifySourceFile path with
| Resi -> ".cmti"
| _ -> ".cmt"
in
match fullForCmt ~moduleName ~package ~uri incrementalCmtPath with
| Some cmtInfo ->
if Debug.verbose () then
Printf.printf "[cmt] Found incremental cmt: %s\n"
(Filename.basename incrementalCmtPath);
Some cmtInfo
| None -> None
else None

let fullFromModuleUri ~package ~moduleName ~uri ~paths =
match fullForIncrementalCmt ~package ~moduleName ~uri with
| Some cmtInfo -> Some cmtInfo
| None ->
let cmt = getCmtPath ~uri paths in
fullForCmt ~moduleName ~package ~uri cmt

let fullFromUri ~uri =
let path = Uri.toPath uri in
match Packages.getPackage ~uri with
Expand All @@ -16,22 +42,8 @@ let fullFromUri ~uri =
let moduleName =
BuildSystem.namespacedName package.namespace (FindFiles.getName path)
in
let incremental =
if !Cfg.inIncrementalTypecheckingMode then
let incrementalCmtPath =
package.rootPath ^ "/lib/bs/___incremental" ^ "/" ^ moduleName
^
match Files.classifySourceFile path with
| Resi -> ".cmti"
| _ -> ".cmt"
in
fullForCmt ~moduleName ~package ~uri incrementalCmtPath
else None
in
match incremental with
| Some cmtInfo ->
if Debug.verbose () then Printf.printf "[cmt] Found incremental cmt\n";
Some cmtInfo
match fullForIncrementalCmt ~package ~moduleName ~uri with
| Some cmtInfo -> Some cmtInfo
| None -> (
match Hashtbl.find_opt package.pathsForModule moduleName with
| Some paths ->
Expand All @@ -41,12 +53,20 @@ let fullFromUri ~uri =
prerr_endline ("can't find module " ^ moduleName);
None))

let fullFromModule ~package ~moduleName =
Option.bind (Hashtbl.find_opt package.pathsForModule moduleName)
@@ fun paths ->
let uri = getUri paths in
fullFromModuleUri ~package ~moduleName ~uri ~paths

let fullsFromModule ~package ~moduleName =
if Hashtbl.mem package.pathsForModule moduleName then
let paths = Hashtbl.find package.pathsForModule moduleName in
match Hashtbl.find_opt package.pathsForModule moduleName with
| None -> []
| Some paths ->
let uris = getUris paths in
uris |> List.filter_map (fun uri -> fullFromUri ~uri)
else []
uris
|> List.filter_map (fun uri ->
fullFromModuleUri ~package ~moduleName ~uri ~paths)

let loadFullCmtFromPath ~path =
let uri = Uri.fromPath path in
Expand Down
31 changes: 24 additions & 7 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ let locItemsForPos ~extra pos =

let lineColToCmtLoc ~pos:(line, col) = (line + 1, col)

(** External references in namespaced projects are indexed by the public
* namespace path, e.g. MyNamespace.MyModule1.myFunc1, while definitions live
* in hidden compiled modules like MyModule1-MyNamespace.
* We return the lookup key pair used by the external reference index.
*)
let normalizeExternalReferenceKey ~namespace ~moduleName ~path =
match namespace with
| Some namespace when Utils.endsWith moduleName ("-" ^ namespace) ->
let suffixLen = String.length namespace + 1 in
let sourceModuleLen = String.length moduleName - suffixLen in
let sourceModule = String.sub moduleName 0 sourceModuleLen in
(namespace, sourceModule :: path)
| _ -> (moduleName, path)

let getLocItem ~full ~pos ~debug =
let log n msg = if debug then Printf.printf "getLocItem #%d: %s\n" n msg in
let pos = lineColToCmtLoc ~pos in
Expand Down Expand Up @@ -485,6 +499,10 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
in
maybeLog ("Now checking path " ^ pathToString path);
let thisModuleName = file.moduleName in
let normalizedModuleName, normalizedPath =
normalizeExternalReferenceKey ~namespace:package.namespace
~moduleName:thisModuleName ~path
in
let externals =
package.projectFiles |> FileSet.elements
|> List.filter (fun name -> name <> file.moduleName)
Expand All @@ -493,14 +511,15 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
|> List.map (fun {file; extra} ->
match
Hashtbl.find_opt extra.externalReferences
thisModuleName
normalizedModuleName
with
| None -> []
| Some refs ->
let locs =
refs
|> Utils.filterMap (fun (p, t, locs) ->
if p = path && t = tip then Some locs
if p = normalizedPath && t = tip then
Some locs
else None)
in
locs
Expand All @@ -522,10 +541,8 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
| TopLevelModule moduleName ->
let otherModulesReferences =
package.projectFiles |> FileSet.elements
|> Utils.filterMap (fun name ->
match ProcessCmt.fileForModule ~package name with
| None -> None
| Some file -> Cmt.fullFromUri ~uri:file.uri)
|> Utils.filterMap (fun moduleName ->
Cmt.fullFromModule ~package ~moduleName)
|> List.map (fun full ->
match Hashtbl.find_opt full.extra.fileReferences moduleName with
| None -> []
Expand Down Expand Up @@ -563,7 +580,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
match exportedForTip ~env ~path ~package ~tip with
| None -> []
| Some (env, _name, stamp) -> (
match Cmt.fullFromUri ~uri:env.file.uri with
match Cmt.fullFromModule ~package ~moduleName:env.file.moduleName with
| None -> []
| Some full ->
maybeLog
Expand Down
2 changes: 1 addition & 1 deletion compiler/common/bs_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "12.3.0"
let version = "12.3.1"
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
2 changes: 1 addition & 1 deletion compiler/core/js_op_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let op_prec (op : Js_op.binop) =
| Lsl | Lsr | Asr -> (10, 10, 11)
| Bnot | Plus | Minus -> (11, 11, 12)
| Mul | Div | Mod -> (12, 12, 13)
| Pow -> (13, 14, 12)
| Pow -> (13, 14, 13)

let op_int_prec (op : Js_op.int_op) =
match op with
Expand Down
19 changes: 14 additions & 5 deletions compiler/ml/code_frame.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ let leading_space_count str =
loop 0 0

let break_long_line max_width line =
let line_length = String.length line in
let rec find_chunk_end pos remaining_width =
if pos = line_length || remaining_width = 0 then pos
else
let char_length =
String.get_utf_8_uchar line pos |> Uchar.utf_decode_length
in
find_chunk_end (pos + char_length) (remaining_width - 1)
in
let rec loop pos accum =
if pos = String.length line then accum
if pos = line_length then List.rev accum
else
let chunk_length = min max_width (String.length line - pos) in
let chunk = String.sub line pos chunk_length in
loop (pos + chunk_length) (chunk :: accum)
let chunk_end = find_chunk_end pos max_width in
let chunk = String.sub line pos (chunk_end - pos) in
loop chunk_end (chunk :: accum)
in
loop 0 [] |> List.rev
loop 0 []

let filter_mapi f l =
let rec loop f l i accum =
Expand Down
12 changes: 6 additions & 6 deletions compiler/ml/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2914,8 +2914,8 @@ let rec moregen inst_nongen type_pairs env t1 t2 =
| Tvar _, _ when may_instantiate inst_nongen t1' ->
moregen_occur env t1'.level t2;
link_type t1' t2
| Tarrow (arg1, ret1, _, _), Tarrow (arg2, ret2, _, _)
when Asttypes.same_arg_label arg1.lbl arg2.lbl ->
| Tarrow (arg1, ret1, _, a1), Tarrow (arg2, ret2, _, a2)
when a1 = a2 && Asttypes.same_arg_label arg1.lbl arg2.lbl ->
moregen inst_nongen type_pairs env arg1.typ arg2.typ;
moregen inst_nongen type_pairs env ret1 ret2
| Ttuple tl1, Ttuple tl2 ->
Expand Down Expand Up @@ -3184,8 +3184,8 @@ let rec eqtype rename type_pairs subst env t1 t2 =
if List.exists (fun (_, t) -> t == t2') !subst then
raise (Unify []);
subst := (t1', t2') :: !subst)
| Tarrow (arg1, ret1, _, _), Tarrow (arg2, ret2, _, _)
when Asttypes.same_arg_label arg1.lbl arg2.lbl ->
| Tarrow (arg1, ret1, _, a1), Tarrow (arg2, ret2, _, a2)
when a1 = a2 && Asttypes.same_arg_label arg1.lbl arg2.lbl ->
eqtype rename type_pairs subst env arg1.typ arg2.typ;
eqtype rename type_pairs subst env ret1 ret2
| Ttuple tl1, Ttuple tl2 ->
Expand Down Expand Up @@ -3597,8 +3597,8 @@ let rec subtype_rec env trace t1 t2 cstrs =
TypePairs.add subtypes (t1, t2) ();
match (t1.desc, t2.desc) with
| Tvar _, _ | _, Tvar _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs
| Tarrow (arg1, ret1, _, _), Tarrow (arg2, ret2, _, _)
when Asttypes.same_arg_label arg1.lbl arg2.lbl ->
| Tarrow (arg1, ret1, _, a1), Tarrow (arg2, ret2, _, a2)
when a1 = a2 && Asttypes.same_arg_label arg1.lbl arg2.lbl ->
let cstrs =
subtype_rec env
((arg2.typ, arg1.typ) :: trace)
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4726,7 +4726,7 @@ and parse_es6_arrow_type ~attrs p =
Parser.expect EqualGreater p;
let return_type = parse_typ_expr ~alias:false p in
let loc = mk_loc start_pos p.prev_end_pos in
Ast_helper.Typ.arrow ~loc ~arity:None {attrs; lbl; typ} return_type
Ast_helper.Typ.arrow ~loc ~arity:(Some 1) {attrs; lbl; typ} return_type
| DocComment _ -> assert false
| _ ->
let parameters = parse_type_parameters p in
Expand Down
26 changes: 16 additions & 10 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ let has_trailing_single_line_comment tbl loc =
| Some (comment :: _) -> Comment.is_single_line_comment comment
| _ -> false

let has_any_trailing_line_comment tbl loc =
match Hashtbl.find_opt tbl.CommentTable.trailing loc with
| Some comments -> List.exists Comment.is_single_line_comment comments
| None -> false

let has_comment_below tbl loc =
match Hashtbl.find tbl.CommentTable.trailing loc with
| comment :: _ ->
Expand Down Expand Up @@ -2230,7 +2235,15 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
| Braced braces -> print_braces doc expr braces
| Nothing -> doc
in
let pattern_has_trailing_line_comment =
has_any_trailing_line_comment cmt_tbl vb.pvb_pat.ppat_loc
in
let pattern_doc = print_pattern ~state vb.pvb_pat cmt_tbl in
let equal_doc =
if pattern_has_trailing_line_comment then
Doc.indent (Doc.concat [Doc.hard_line; Doc.equal])
else Doc.text " ="
in
(*
* we want to optimize the layout of one pipe:
* let tbl = data->Js.Array2.reduce((map, curr) => {
Expand All @@ -2248,21 +2261,14 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
[
Doc.group
(Doc.concat
[
attrs;
header;
pattern_doc;
Doc.text " =";
Doc.space;
printed_expr;
]);
[attrs; header; pattern_doc; equal_doc; Doc.space; printed_expr]);
Doc.group
(Doc.concat
[
attrs;
header;
pattern_doc;
Doc.text " =";
equal_doc;
Doc.indent (Doc.concat [Doc.line; printed_expr]);
]);
]
Expand Down Expand Up @@ -2294,7 +2300,7 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
attrs;
header;
pattern_doc;
Doc.text " =";
equal_doc;
(if should_indent then
Doc.indent (Doc.concat [Doc.line; printed_expr])
else Doc.concat [Doc.space; printed_expr]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript toolchain",
"type": "module",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/darwin-arm64",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript binaries for MacOS ARM64",
"type": "module",
"license": "(LGPL-3.0-or-later AND MIT)",
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/darwin-x64",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript binaries for MacOS x86_64",
"type": "module",
"license": "(LGPL-3.0-or-later AND MIT)",
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/linux-arm64",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript binaries for Linux ARM64",
"type": "module",
"license": "(LGPL-3.0-or-later AND MIT)",
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/linux-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/linux-x64",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript binaries for Linux x86_64",
"type": "module",
"license": "(LGPL-3.0-or-later AND MIT)",
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/runtime",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript runtime modules",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/win32-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/win32-x64",
"version": "12.3.0",
"version": "12.3.1",
"description": "ReScript binaries for Windows x86_64",
"type": "module",
"license": "(LGPL-3.0-or-later AND MIT)",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rewatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rescript"
version = "12.3.0"
version = "12.3.1"
edition = "2024"
rust-version = "1.91"

Expand Down
Loading
Loading