Skip to content

Commit 80744a5

Browse files
cknittzth
andauthored
Stdlib namespace for Core modules (rescript-lang#7285)
* Stdlib namespace for Core modules * fix gentype output * commit another test * commit new test output (that has errors) * pipe completion for stdlib * pick up another regex completion * handle nopervasives, and open Stdlib by default * commit more tests * Reanalyze tests working again * Fix Gentype for real * Do not run analysis tests on Linux * Cache reanalyze, too * CHANGELOG --------- Co-authored-by: Gabriel Nordeborn <[email protected]>
1 parent 70a73ed commit 80744a5

File tree

311 files changed

+3089
-2230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+3089
-2230
lines changed

.github/workflows/ci.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
# matrix.ocaml_compiler may contain commas
154154
- name: Get OPAM cache key
155155
shell: bash
156-
run: echo "opam_cache_key=opam-env-v6-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
156+
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
157157

158158
- name: Restore OPAM environment
159159
id: cache-opam-env
@@ -191,6 +191,10 @@ jobs:
191191
if: steps.cache-opam-env.outputs.cache-hit != 'true'
192192
run: opam install . --deps-only --with-test
193193

194+
- name: "Install reanalyze"
195+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.run_reanalyze
196+
run: opam install reanalyze
197+
194198
- name: Cache OPAM environment
195199
if: steps.cache-opam-env.outputs.cache-hit != 'true'
196200
uses: actions/cache/save@v4
@@ -303,9 +307,7 @@ jobs:
303307

304308
- name: "Syntax: Run reanalyze"
305309
if: matrix.run_reanalyze
306-
run: |
307-
opam install reanalyze
308-
opam exec -- make reanalyze
310+
run: opam exec -- make reanalyze
309311

310312
- name: Build runtime/stdlib
311313
run: ./scripts/buildRuntime.sh
@@ -324,7 +326,7 @@ jobs:
324326
run: git diff --ignore-cr-at-eol --exit-code tests
325327

326328
- name: Run analysis / tools tests
327-
if: runner.os != 'Windows' && matrix.os != 'ubuntu-24.04-arm'
329+
if: runner.os != 'Windows' && runner.os != 'Linux'
328330
run: opam exec -- make -C tests/analysis_tests test && make -C tests/tools_tests test
329331

330332
- name: Run gentype tests

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
- Fix completion for application with tagged template. https://github.com/rescript-lang/rescript/pull/7278
2626
- Fix error message for arity in the presence of optional arguments. https://github.com/rescript-lang/rescript/pull/7284
2727
- Fix issue in functors with more than one argument (which are curried): emit nested function always. https://github.com/rescript-lang/rescript/pull/7273
28-
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
28+
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
29+
- Stdlib namespace for Core modules (fixes name clashes with user modules). https://github.com/rescript-lang/rescript/pull/7285
2930

3031
#### :house: Internal
3132

analysis/src/CompletionBackEnd.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
14521452
let completionItems =
14531453
match path with
14541454
| Pdot (Pdot (Pident {name = "Js"}, "Re", _), "t", _)
1455+
| Pdot (Pdot (Pident {name = "Stdlib"}, "RegExp", _), "t", _)
14551456
| Pdot (Pident {name = "RegExp"}, "t", _) ->
14561457
(* regexps *)
14571458
create "/<regexp>/g" ~insertText:"/$0/g" ~includesSnippets:true

analysis/src/Packages.ml

+26-17
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,35 @@ let newBsPackage ~rootPath =
115115
let path = [FindFiles.nameSpaceToName namespace] in
116116
[path]
117117
in
118+
let bind f x = Option.bind x f in
119+
let bsc_flags =
120+
Json.get "bsc-flags" config
121+
|> bind Json.array |> Option.value ~default:[]
122+
in
123+
let no_pervasives =
124+
bsc_flags
125+
|> List.exists (fun s -> Json.string s = Some "-nopervasives")
126+
in
118127
let opens_from_bsc_flags =
119-
let bind f x = Option.bind x f in
120-
match Json.get "bsc-flags" config |> bind Json.array with
121-
| Some l ->
122-
List.fold_left
123-
(fun opens item ->
124-
match item |> Json.string with
125-
| None -> opens
126-
| Some s -> (
127-
let parts = String.split_on_char ' ' s in
128-
match parts with
129-
| "-open" :: name :: _ ->
130-
let path = name |> String.split_on_char '.' in
131-
path :: opens
132-
| _ -> opens))
133-
[] l
134-
| None -> []
128+
List.fold_left
129+
(fun opens item ->
130+
match item |> Json.string with
131+
| None -> opens
132+
| Some s -> (
133+
let parts = String.split_on_char ' ' s in
134+
match parts with
135+
| "-open" :: name :: _ ->
136+
let path = name |> String.split_on_char '.' in
137+
path :: opens
138+
| _ -> opens))
139+
[] bsc_flags
140+
in
141+
let opens_from_pervasives =
142+
if no_pervasives then []
143+
else [["Stdlib"]; ["Pervasives"; "JsxModules"]]
135144
in
136145
let opens =
137-
["Pervasives"; "JsxModules"] :: opens_from_namespace
146+
opens_from_pervasives @ opens_from_namespace
138147
|> List.rev_append opens_from_bsc_flags
139148
|> List.map (fun path -> path @ ["place holder"])
140149
in

analysis/src/TypeUtils.ml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,14 @@ let pathToBuiltin path =
12551255

12561256
let completionPathFromMaybeBuiltin path =
12571257
match pathToBuiltin path with
1258-
| Some ("array", _) -> Some ["Array"]
1259-
| Some ("option", _) -> Some ["Option"]
1260-
| Some ("string", _) -> Some ["String"]
1261-
| Some ("int", _) -> Some ["Int"]
1262-
| Some ("float", _) -> Some ["Float"]
1263-
| Some ("promise", _) -> Some ["Promise"]
1264-
| Some ("list", _) -> Some ["List"]
1265-
| Some ("result", _) -> Some ["Result"]
1266-
| Some ("dict", _) -> Some ["Dict"]
1267-
| Some ("char", _) -> Some ["Char"]
1258+
| Some ("array", _) -> Some ["Stdlib"; "Array"]
1259+
| Some ("option", _) -> Some ["Stdlib"; "Option"]
1260+
| Some ("string", _) -> Some ["Stdlib"; "String"]
1261+
| Some ("int", _) -> Some ["Stdlib"; "Int"]
1262+
| Some ("float", _) -> Some ["Stdlib"; "Float"]
1263+
| Some ("promise", _) -> Some ["Stdlib"; "Promise"]
1264+
| Some ("list", _) -> Some ["Stdlib"; "List"]
1265+
| Some ("result", _) -> Some ["Stdlib"; "Result"]
1266+
| Some ("dict", _) -> Some ["Stdlib"; "Dict"]
1267+
| Some ("char", _) -> Some ["Stdlib"; "Char"]
12681268
| _ -> None

compiler/core/res_compmisc.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ let initial_env ?modulename () =
5454
let initial = Env.initial_safe_string in
5555
let env =
5656
if !Clflags.nopervasives then initial
57-
else open_implicit_module "Pervasives" initial
57+
else
58+
initial
59+
|> open_implicit_module "Pervasives"
60+
|> open_implicit_module "Stdlib"
5861
in
5962
List.fold_left
6063
(fun env m -> open_implicit_module m env)

compiler/gentype/TranslateTypeExprFromTypes.ml

+30-13
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,42 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
8181
| ( ( ["FB"; "string"]
8282
| ["string"]
8383
| ["String"; "t"]
84+
| ["Stdlib"; "String"; "t"]
8485
| ["Js"; ("String" | "String2"); "t"] ),
8586
[] ) ->
8687
{dependencies = []; type_ = string_t}
87-
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
88+
| ( ( ["Js"; "Types"; "bigint_val"]
89+
| ["BigInt"; "t"]
90+
| ["Stdlib"; "BigInt"; "t"] ),
91+
[] ) ->
8892
{dependencies = []; type_ = bigint_t}
89-
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
93+
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib"; "Date"; "t"]), [] ->
9094
{dependencies = []; type_ = date_t}
91-
| ["Map"; "t"], [param_translation1; param_translation2] ->
95+
| ( (["Map"; "t"] | ["Stdlib"; "Map"; "t"]),
96+
[param_translation1; param_translation2] ) ->
9297
{
9398
dependencies =
9499
param_translation1.dependencies @ param_translation2.dependencies;
95100
type_ = map_t (param_translation1.type_, param_translation2.type_);
96101
}
97-
| ["WeakMap"; "t"], [param_translation1; param_translation2] ->
102+
| ( (["WeakMap"; "t"] | ["Stdlib"; "WeakMap"; "t"]),
103+
[param_translation1; param_translation2] ) ->
98104
{
99105
dependencies =
100106
param_translation1.dependencies @ param_translation2.dependencies;
101107
type_ = weakmap_t (param_translation1.type_, param_translation2.type_);
102108
}
103-
| ["Set"; "t"], [param_translation] ->
109+
| (["Set"; "t"] | ["Stdlib"; "Set"; "t"]), [param_translation] ->
104110
{
105111
dependencies = param_translation.dependencies;
106112
type_ = set_t param_translation.type_;
107113
}
108-
| ["WeakSet"; "t"], [param_translation] ->
114+
| (["WeakSet"; "t"] | ["Stdlib"; "WeakSet"; "t"]), [param_translation] ->
109115
{
110116
dependencies = param_translation.dependencies;
111117
type_ = weakset_t param_translation.type_;
112118
}
113-
| (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] ->
119+
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] ->
114120
{dependencies = []; type_ = regexp_t}
115121
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
116122
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),
@@ -134,7 +140,10 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
134140
};
135141
] );
136142
}
137-
| ( (["Pervasives"; "result"] | ["Belt"; "Result"; "t"] | ["result"]),
143+
| ( ( ["Pervasives"; "result"]
144+
| ["Belt"; "Result"; "t"]
145+
| ["result"]
146+
| ["Stdlib"; "Result"; "t"] ),
138147
[param_translation1; param_translation2] ) ->
139148
let case name type_ = {case = {label_js = StringLabel name}; t = type_} in
140149
let variant =
@@ -216,20 +225,28 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
216225
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
217226
[param_translation] ) ->
218227
{param_translation with type_ = Option param_translation.type_}
219-
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
220-
->
228+
| ( ( ["Js"; "Null"; "t"]
229+
| ["Null"; "t"]
230+
| ["Js"; "null"]
231+
| ["Stdlib"; "Null"; "t"] ),
232+
[param_translation] ) ->
221233
{param_translation with type_ = Null param_translation.type_}
222234
| ( ( ["Js"; "Nullable"; "t"]
223235
| ["Nullable"; "t"]
224236
| ["Js"; "nullable"]
225237
| ["Js"; "Null_undefined"; "t"]
226-
| ["Js"; "null_undefined"] ),
238+
| ["Js"; "null_undefined"]
239+
| ["Stdlib"; "Nullable"; "t"] ),
227240
[param_translation] ) ->
228241
{param_translation with type_ = Nullable param_translation.type_}
229-
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),
242+
| ( ( ["Js"; "Promise"; "t"]
243+
| ["Promise"; "t"]
244+
| ["promise"]
245+
| ["Stdlib"; "Promise"; "t"] ),
230246
[param_translation] ) ->
231247
{param_translation with type_ = Promise param_translation.type_}
232-
| (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"]), [param_translation] ->
248+
| ( (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"] | ["Stdlib"; "Dict"; "t"]),
249+
[param_translation] ) ->
233250
{param_translation with type_ = Dict param_translation.type_}
234251
| _ -> default_case ()
235252

compiler/ml/ast_untagged_variants.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
179179
| Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array
180180
| Tconstr (path, _, _) -> (
181181
match Path.name path with
182-
| "Js_date.t" -> Some Date
183-
| "Js_re.t" -> Some RegExp
182+
| "Stdlib_Date.t" -> Some Date
183+
| "Stdlib_RegExp.t" -> Some RegExp
184184
| "Js_file.t" -> Some File
185185
| "Js_blob.t" -> Some Blob
186186
| _ -> None)

lib/es6/Pervasives.js

-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

22

3-
import * as $$Error from "./Error.js";
4-
import * as Primitive_object from "./Primitive_object.js";
53
import * as Primitive_exceptions from "./Primitive_exceptions.js";
64

75
function failwith(s) {
@@ -117,21 +115,6 @@ function $at(l1, l2) {
117115
}
118116
}
119117

120-
function assertEqual(a, b) {
121-
if (!Primitive_object.notequal(a, b)) {
122-
return;
123-
}
124-
throw {
125-
RE_EXN_ID: "Assert_failure",
126-
_1: [
127-
"Pervasives.res",
128-
596,
129-
4
130-
],
131-
Error: new Error()
132-
};
133-
}
134-
135118
let max_int = 2147483647;
136119

137120
let infinity = Infinity;
@@ -144,8 +127,6 @@ let min_float = 2.22507385850720138e-308;
144127

145128
let epsilon_float = 2.22044604925031308e-16;
146129

147-
let panic = $$Error.panic;
148-
149130
export {
150131
failwith,
151132
invalid_arg,
@@ -166,7 +147,5 @@ export {
166147
bool_of_string_opt,
167148
int_of_string_opt,
168149
$at,
169-
panic,
170-
assertEqual,
171150
}
172151
/* No side effect */

0 commit comments

Comments
 (0)