Skip to content

Merge changes from 11.0_release into master #6650

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

Merged
merged 11 commits into from
Feb 27, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,22 @@ jobs:

runs-on: ${{matrix.os}}

container:
image: ghcr.io/rescript-lang/rescript-ci-build:alpine-3.19-ocaml-5.1.1-01

steps:
# See https://github.com/actions/runner/issues/801#issuecomment-1374967227.
- name: Workaround for Github actions runner on Alpine arm64
if: runner.arch == 'ARM64'
run: sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build compiler binaries
run: opam exec -- dune build --display quiet --profile static
uses: docker://ghcr.io/rescript-lang/rescript-ci-build:alpine-3.19-ocaml-5.1.1-01
with:
args: opam exec -- dune build --display quiet --profile static

- name: Build ninja binary
working-directory: ninja
env:
LDFLAGS: -static
run: python3 configure.py --bootstrap --verbose
uses: docker://ghcr.io/rescript-lang/rescript-ci-build:alpine-3.19-ocaml-5.1.1-01
with:
args: sh -c "cd ninja && LDFLAGS=-static python3 configure.py --bootstrap"

- name: "Upload artifacts"
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: static-binaries-linux-${{runner.arch}}
path: |
Expand All @@ -72,11 +65,11 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download static linux binaries
if: runner.os == 'Linux'
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: static-binaries-linux-${{ runner.arch }}

Expand All @@ -87,7 +80,7 @@ jobs:
chmod +x _build/install/default/bin/*

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16

Expand All @@ -98,7 +91,7 @@ jobs:
run: node .github/workflows/get_artifact_info.js

- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}
Expand Down Expand Up @@ -130,13 +123,13 @@ jobs:
git config --global core.eol lf

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2 # to be able to check for changes in subfolder jscomp/syntax later

- name: Download static linux binaries
if: runner.os == 'Linux'
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: static-binaries-linux-${{ runner.arch }}

Expand Down Expand Up @@ -174,7 +167,7 @@ jobs:
run: opam exec -- dune build --display quiet --profile release

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16

Expand All @@ -183,7 +176,7 @@ jobs:

- name: "Windows: Use MSVC for ninja build"
if: runner.os == 'Windows'
uses: TheMrMilchmann/setup-msvc-dev@v2
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64

Expand Down Expand Up @@ -263,14 +256,14 @@ jobs:
run: node .github/workflows/get_artifact_info.js

- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}

- name: "Upload artifacts: lib/ocaml"
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lib-ocaml
path: lib/ocaml
Expand All @@ -281,18 +274,18 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16

- name: NPM install
run: npm ci --ignore-scripts

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Move artifacts
run: ./scripts/moveArtifacts.sh
Expand All @@ -315,7 +308,7 @@ jobs:
run: node .github/workflows/prepare_package_upload.js ${{ github.event.pull_request.head.sha }}

- name: "Upload artifact: npm packages"
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: npm-packages
path: |
Expand All @@ -342,15 +335,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: npm-packages
path: packages/test
Expand All @@ -374,16 +367,16 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
registry-url: https://registry.npmjs.org # Needed to make auth work for publishing

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: npm-packages

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@

- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641

# 11.1.0-rc.3

#### :nail_care: Polish

- No parens around tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6639
- Allow identifier with modules in tagged template literals (e.g. Pg.sql`select * from ${table} where id = ${id}`). https://github.com/rescript-lang/rescript-compiler/pull/6645

#### :bug: Bug Fix

- Fix compiler crash when reexporting tagged template literal externals. https://github.com/rescript-lang/rescript-compiler/pull/6645

# 11.1.0-rc.2

#### :rocket: New Feature
Expand All @@ -38,6 +49,7 @@
- Generic JSX transform: Handle namespaced names. https://github.com/rescript-lang/rescript-compiler/pull/6606
- Fix issue with doc comment in recursive module. https://github.com/rescript-lang/rescript-compiler/pull/6613
- Fix issue with Exceptions and Extensible types runtime generation. https://github.com/rescript-lang/rescript-compiler/pull/6570
- Fix inline comment before spread syntax in record. https://github.com/rescript-lang/rescript-compiler/pull/6615

#### :house: Internal

Expand Down
15 changes: 7 additions & 8 deletions jscomp/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,15 @@ let translate_scoped_access scopes obj =
let translate_ffi (cxt : Lam_compile_context.t) arg_types
(ffi : External_ffi_types.external_spec) (args : J.expression list) =
match ffi with
| Js_call { external_module_name; name; splice; scopes; tagged_template = true } ->
| Js_call { external_module_name; name; splice: _; scopes; tagged_template = true } ->
let fn = translate_scoped_module_val external_module_name name scopes in
(match args with
| [ stringArgs; valueArgs ] -> (
match (stringArgs, valueArgs) with
| ({expression_desc = Array (strings, _); _}, {expression_desc = Array (values, _); _}) ->
E.tagged_template fn strings values
| _ -> assert false
)
| _ -> assert false)
| [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] ->
E.tagged_template fn strings values
| _ -> let args, eff, dynamic = assemble_args_has_splice arg_types args in
add_eff eff
(if dynamic then splice_apply fn args
else E.call ~info:{ arity = Full; call_info = Call_na } fn args))
| Js_call { external_module_name = module_name; name = fn; splice; scopes; tagged_template = false } ->
let fn = translate_scoped_module_val module_name fn scopes in
if splice then
Expand Down
19 changes: 10 additions & 9 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,8 +2066,7 @@ and parsePrimaryExpr ~operand ?(noCall = false) p =
| Backtick
when noCall = false && p.prevEndPos.pos_lnum == p.startPos.pos_lnum -> (
match expr.pexp_desc with
| Pexp_ident {txt = Longident.Lident ident} ->
parseTemplateExpr ~prefix:ident p
| Pexp_ident long_ident -> parseTemplateExpr ~prefix:long_ident p
| _ ->
Parser.err ~startPos:expr.pexp_loc.loc_start
~endPos:expr.pexp_loc.loc_end p
Expand Down Expand Up @@ -2243,13 +2242,15 @@ and parseBinaryExpr ?(context = OrdinaryExpr) ?a p prec =
(* | _ -> false *)
(* ) *)

and parseTemplateExpr ?(prefix = "js") p =
and parseTemplateExpr ?prefix p =
let partPrefix =
(* we could stop treating js and j prefix as something special
for json, we would first need to remove @as(json`true`) feature *)
match prefix with
| "js" | "j" | "json" -> Some prefix
| _ -> None
| Some {txt = Longident.Lident (("js" | "j" | "json") as prefix); _} ->
Some prefix
| Some _ -> None
| None -> Some "js"
in
let startPos = p.Parser.startPos in

Expand Down Expand Up @@ -2286,8 +2287,7 @@ and parseTemplateExpr ?(prefix = "js") p =
let values = Ext_list.filter_map parts snd in
let endPos = p.Parser.endPos in

let genTaggedTemplateCall () =
let lident = Longident.Lident prefix in
let genTaggedTemplateCall lident =
let ident =
Ast_helper.Exp.ident ~attrs:[] ~loc:Location.none
(Location.mknoloc lident)
Expand Down Expand Up @@ -2338,8 +2338,9 @@ and parseTemplateExpr ?(prefix = "js") p =
in

match prefix with
| "js" | "j" | "json" -> genInterpolatedString ()
| _ -> genTaggedTemplateCall ()
| Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None ->
genInterpolatedString ()
| Some {txt = lident} -> genTaggedTemplateCall lident

(* Overparse: let f = a : int => a + 1, is it (a : int) => or (a): int =>
* Also overparse constraints:
Expand Down
3 changes: 2 additions & 1 deletion jscomp/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ let filterParsingAttrs attrs =
Location.txt =
( "bs" | "res.uapp" | "res.arity" | "res.braces" | "ns.braces"
| "res.iflet" | "res.namedArgLoc" | "res.optional" | "res.ternary"
| "res.async" | "res.await" | "res.template" );
| "res.async" | "res.await" | "res.template"
| "res.taggedTemplate" );
},
_ ) ->
false
Expand Down
24 changes: 17 additions & 7 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2921,15 +2921,25 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
let spread =
match spreadExpr with
| None -> Doc.nil
| Some expr ->
| Some ({pexp_desc} as expr) ->
let doc =
match pexp_desc with
| Pexp_ident {txt = expr} -> printLident expr
| _ -> printExpression ~state expr cmtTbl
in
let docWithSpread =
Doc.concat
[
Doc.dotdotdot;
(match Parens.expr expr with
| Parens.Parenthesized -> addParens doc
| Braced braces -> printBraces doc expr braces
| Nothing -> doc);
]
in
Doc.concat
[
Doc.dotdotdot;
(let doc = printExpressionWithComments ~state expr cmtTbl in
match Parens.expr expr with
| Parens.Parenthesized -> addParens doc
| Braced braces -> printBraces doc expr braces
| Nothing -> doc);
printComments docWithSpread cmtTbl expr.Parsetree.pexp_loc;
Doc.comma;
Doc.line;
]
Expand Down
42 changes: 41 additions & 1 deletion jscomp/syntax/tests/printer/comments/expected/expr.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let user = /* before */ {
} // after

let spreadUser = {
.../* before */ user1 /* after */,
/* before */ ...user1 /* after */,
/* c0 */ age /* c1 */: /* c2 */ 32 /* c3 */,
}

Expand Down Expand Up @@ -281,3 +281,43 @@ Doc.concat(list{
rows,
/* a */
})

// More record spread test
type b = {
// spread a
...a,
// spread c
...c,
// no spread
b: string,
}

type a = {
// spread from different module
...M.a,
// spread c
...c,
// no spread
b: string,
}

let b = {
// exotic
...\"let",
// foo
bar: "foo",
}

let b = {
// quote
..."let",
// foo
bar: "foo",
}

let c = {
// from different module
...M.a,
// foo
bar: "foo",
}
Loading