Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stdlib namespace for Core modules #7285

Merged
merged 13 commits into from
Feb 17, 2025
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
# matrix.ocaml_compiler may contain commas
- name: Get OPAM cache key
shell: bash
run: echo "opam_cache_key=opam-env-v6-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV

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

- name: "Install reanalyze"
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.run_reanalyze
run: opam install reanalyze

- name: Cache OPAM environment
if: steps.cache-opam-env.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
Expand Down Expand Up @@ -303,9 +307,7 @@ jobs:

- name: "Syntax: Run reanalyze"
if: matrix.run_reanalyze
run: |
opam install reanalyze
opam exec -- make reanalyze
run: opam exec -- make reanalyze

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

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

- name: Run gentype tests
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Fix completion for application with tagged template. https://github.com/rescript-lang/rescript/pull/7278
- Fix error message for arity in the presence of optional arguments. https://github.com/rescript-lang/rescript/pull/7284
- Fix issue in functors with more than one argument (which are curried): emit nested function always. https://github.com/rescript-lang/rescript/pull/7273
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
- Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript/pull/7292
- Stdlib namespace for Core modules (fixes name clashes with user modules). https://github.com/rescript-lang/rescript/pull/7285

#### :house: Internal

Expand Down
1 change: 1 addition & 0 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
let completionItems =
match path with
| Pdot (Pdot (Pident {name = "Js"}, "Re", _), "t", _)
| Pdot (Pdot (Pident {name = "Stdlib"}, "RegExp", _), "t", _)
| Pdot (Pident {name = "RegExp"}, "t", _) ->
(* regexps *)
create "/<regexp>/g" ~insertText:"/$0/g" ~includesSnippets:true
Expand Down
43 changes: 26 additions & 17 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,35 @@ let newBsPackage ~rootPath =
let path = [FindFiles.nameSpaceToName namespace] in
[path]
in
let bind f x = Option.bind x f in
let bsc_flags =
Json.get "bsc-flags" config
|> bind Json.array |> Option.value ~default:[]
in
let no_pervasives =
bsc_flags
|> List.exists (fun s -> Json.string s = Some "-nopervasives")
in
let opens_from_bsc_flags =
let bind f x = Option.bind x f in
match Json.get "bsc-flags" config |> bind Json.array with
| Some l ->
List.fold_left
(fun opens item ->
match item |> Json.string with
| None -> opens
| Some s -> (
let parts = String.split_on_char ' ' s in
match parts with
| "-open" :: name :: _ ->
let path = name |> String.split_on_char '.' in
path :: opens
| _ -> opens))
[] l
| None -> []
List.fold_left
(fun opens item ->
match item |> Json.string with
| None -> opens
| Some s -> (
let parts = String.split_on_char ' ' s in
match parts with
| "-open" :: name :: _ ->
let path = name |> String.split_on_char '.' in
path :: opens
| _ -> opens))
[] bsc_flags
in
let opens_from_pervasives =
if no_pervasives then []
else [["Stdlib"]; ["Pervasives"; "JsxModules"]]
in
let opens =
["Pervasives"; "JsxModules"] :: opens_from_namespace
opens_from_pervasives @ opens_from_namespace
|> List.rev_append opens_from_bsc_flags
|> List.map (fun path -> path @ ["place holder"])
in
Expand Down
20 changes: 10 additions & 10 deletions analysis/src/TypeUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,14 @@ let pathToBuiltin path =

let completionPathFromMaybeBuiltin path =
match pathToBuiltin path with
| Some ("array", _) -> Some ["Array"]
| Some ("option", _) -> Some ["Option"]
| Some ("string", _) -> Some ["String"]
| Some ("int", _) -> Some ["Int"]
| Some ("float", _) -> Some ["Float"]
| Some ("promise", _) -> Some ["Promise"]
| Some ("list", _) -> Some ["List"]
| Some ("result", _) -> Some ["Result"]
| Some ("dict", _) -> Some ["Dict"]
| Some ("char", _) -> Some ["Char"]
| Some ("array", _) -> Some ["Stdlib"; "Array"]
| Some ("option", _) -> Some ["Stdlib"; "Option"]
| Some ("string", _) -> Some ["Stdlib"; "String"]
| Some ("int", _) -> Some ["Stdlib"; "Int"]
| Some ("float", _) -> Some ["Stdlib"; "Float"]
| Some ("promise", _) -> Some ["Stdlib"; "Promise"]
| Some ("list", _) -> Some ["Stdlib"; "List"]
| Some ("result", _) -> Some ["Stdlib"; "Result"]
| Some ("dict", _) -> Some ["Stdlib"; "Dict"]
| Some ("char", _) -> Some ["Stdlib"; "Char"]
| _ -> None
5 changes: 4 additions & 1 deletion compiler/core/res_compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ let initial_env ?modulename () =
let initial = Env.initial_safe_string in
let env =
if !Clflags.nopervasives then initial
else open_implicit_module "Pervasives" initial
else
initial
|> open_implicit_module "Pervasives"
|> open_implicit_module "Stdlib"
in
List.fold_left
(fun env m -> open_implicit_module m env)
Expand Down
43 changes: 30 additions & 13 deletions compiler/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,42 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
| ( ( ["FB"; "string"]
| ["string"]
| ["String"; "t"]
| ["Stdlib"; "String"; "t"]
| ["Js"; ("String" | "String2"); "t"] ),
[] ) ->
{dependencies = []; type_ = string_t}
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
| ( ( ["Js"; "Types"; "bigint_val"]
| ["BigInt"; "t"]
| ["Stdlib"; "BigInt"; "t"] ),
[] ) ->
{dependencies = []; type_ = bigint_t}
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib"; "Date"; "t"]), [] ->
{dependencies = []; type_ = date_t}
| ["Map"; "t"], [param_translation1; param_translation2] ->
| ( (["Map"; "t"] | ["Stdlib"; "Map"; "t"]),
[param_translation1; param_translation2] ) ->
{
dependencies =
param_translation1.dependencies @ param_translation2.dependencies;
type_ = map_t (param_translation1.type_, param_translation2.type_);
}
| ["WeakMap"; "t"], [param_translation1; param_translation2] ->
| ( (["WeakMap"; "t"] | ["Stdlib"; "WeakMap"; "t"]),
[param_translation1; param_translation2] ) ->
{
dependencies =
param_translation1.dependencies @ param_translation2.dependencies;
type_ = weakmap_t (param_translation1.type_, param_translation2.type_);
}
| ["Set"; "t"], [param_translation] ->
| (["Set"; "t"] | ["Stdlib"; "Set"; "t"]), [param_translation] ->
{
dependencies = param_translation.dependencies;
type_ = set_t param_translation.type_;
}
| ["WeakSet"; "t"], [param_translation] ->
| (["WeakSet"; "t"] | ["Stdlib"; "WeakSet"; "t"]), [param_translation] ->
{
dependencies = param_translation.dependencies;
type_ = weakset_t param_translation.type_;
}
| (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] ->
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] ->
{dependencies = []; type_ = regexp_t}
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),
Expand All @@ -134,7 +140,10 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
};
] );
}
| ( (["Pervasives"; "result"] | ["Belt"; "Result"; "t"] | ["result"]),
| ( ( ["Pervasives"; "result"]
| ["Belt"; "Result"; "t"]
| ["result"]
| ["Stdlib"; "Result"; "t"] ),
[param_translation1; param_translation2] ) ->
let case name type_ = {case = {label_js = StringLabel name}; t = type_} in
let variant =
Expand Down Expand Up @@ -216,20 +225,28 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
[param_translation] ) ->
{param_translation with type_ = Option param_translation.type_}
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
->
| ( ( ["Js"; "Null"; "t"]
| ["Null"; "t"]
| ["Js"; "null"]
| ["Stdlib"; "Null"; "t"] ),
[param_translation] ) ->
{param_translation with type_ = Null param_translation.type_}
| ( ( ["Js"; "Nullable"; "t"]
| ["Nullable"; "t"]
| ["Js"; "nullable"]
| ["Js"; "Null_undefined"; "t"]
| ["Js"; "null_undefined"] ),
| ["Js"; "null_undefined"]
| ["Stdlib"; "Nullable"; "t"] ),
[param_translation] ) ->
{param_translation with type_ = Nullable param_translation.type_}
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),
| ( ( ["Js"; "Promise"; "t"]
| ["Promise"; "t"]
| ["promise"]
| ["Stdlib"; "Promise"; "t"] ),
[param_translation] ) ->
{param_translation with type_ = Promise param_translation.type_}
| (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"]), [param_translation] ->
| ( (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"] | ["Stdlib"; "Dict"; "t"]),
[param_translation] ) ->
{param_translation with type_ = Dict param_translation.type_}
| _ -> default_case ()

Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/ast_untagged_variants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
| Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array
| Tconstr (path, _, _) -> (
match Path.name path with
| "Js_date.t" -> Some Date
| "Js_re.t" -> Some RegExp
| "Stdlib_Date.t" -> Some Date
| "Stdlib_RegExp.t" -> Some RegExp
| "Js_file.t" -> Some File
| "Js_blob.t" -> Some Blob
| _ -> None)
Expand Down
21 changes: 0 additions & 21 deletions lib/es6/Pervasives.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


import * as $$Error from "./Error.js";
import * as Primitive_object from "./Primitive_object.js";
import * as Primitive_exceptions from "./Primitive_exceptions.js";

function failwith(s) {
Expand Down Expand Up @@ -117,21 +115,6 @@ function $at(l1, l2) {
}
}

function assertEqual(a, b) {
if (!Primitive_object.notequal(a, b)) {
return;
}
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"Pervasives.res",
596,
4
],
Error: new Error()
};
}

let max_int = 2147483647;

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

let epsilon_float = 2.22044604925031308e-16;

let panic = $$Error.panic;

export {
failwith,
invalid_arg,
Expand All @@ -166,7 +147,5 @@ export {
bool_of_string_opt,
int_of_string_opt,
$at,
panic,
assertEqual,
}
/* No side effect */
Loading
Loading