Skip to content

Commit a3f6430

Browse files
committed
Fix compatibility with latest moon and core library versions │
│ │ │ - Fix OCaml compilation issues including inline attribute syntax in basic_base64.ml │ │ - Update dune warning suppressions to handle newer OCaml compiler warnings │ │ - Preserve meaningful variable names with underscore prefixes for better code │ │ readability │ │ - Fix type errors in riscv_tac2ssa.ml and riscv_opt_peephole.ml │ │ - Add comprehensive nix flake configuration for development environment │ │ - Enable hybrid toolchain: latest moon (0.1.20250918) + current moonc + latest core │ │ │ │ This resolves the moon/moonc/core version compatibility issues and enables │ │ successful compilation of the latest moonbitlang/core repository with 62 tasks │ │ completing successfully.
1 parent 12440fa commit a3f6430

File tree

12 files changed

+207
-30
lines changed

12 files changed

+207
-30
lines changed

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
description = "MoonBit compiler with latest moon and current moonc";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in
14+
{
15+
packages.default = pkgs.stdenv.mkDerivation rec {
16+
pname = "moonbit-hybrid";
17+
version = "latest-moon-plctlab-moonc";
18+
19+
# Use latest moon binary
20+
moonSrc = pkgs.fetchzip {
21+
url = "https://cli.moonbitlang.com/binaries/latest/moonbit-linux-x86_64.tar.gz";
22+
sha256 = "sha256-8AwukSHQ9NlFncAJAdM3ZJOYHWMqzw39L6bcYWw+0rM=";
23+
stripRoot = false;
24+
};
25+
26+
# Use current GitHub repo for moonc
27+
src = ./.;
28+
29+
nativeBuildInputs = with pkgs; [
30+
autoPatchelfHook
31+
patchelf
32+
makeWrapper
33+
dune_3
34+
ocaml
35+
pkg-config
36+
libffi
37+
gmp
38+
];
39+
40+
buildInputs = with pkgs; [
41+
stdenv.cc.cc.lib
42+
];
43+
44+
buildPhase = ''
45+
runHook preBuild
46+
47+
# Build moonc from current repo
48+
dune build --root .
49+
50+
# Prepare moon from latest release
51+
cp -r ${moonSrc}/* ./
52+
chmod -R u+w ./bin || echo "Failed to set write permissions on bin"
53+
chmod +x ./bin/moon || echo "moon binary not found"
54+
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./bin/moon || echo "Failed to patch moon"
55+
[ -f ./bin/internal/tcc ] && patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./bin/internal/tcc || echo "tcc not found or failed to patch"
56+
57+
# Replace moonc with our built version
58+
cp _build/install/default/bin/moonc ./bin/moonc
59+
chmod +x ./bin/moonc
60+
61+
runHook postBuild
62+
'';
63+
64+
installPhase = ''
65+
runHook preInstall
66+
67+
mkdir -p $out/bin
68+
mkdir -p $out/lib
69+
70+
# Install binaries
71+
cp ./bin/moon $out/bin/
72+
cp ./bin/moonc $out/bin/
73+
cp -r ./bin/internal $out/bin/
74+
75+
# Install lib files if they exist
76+
if [ -d "./lib" ]; then
77+
cp -r ./lib/* $out/lib/
78+
fi
79+
80+
runHook postInstall
81+
'';
82+
83+
postFixup = ''
84+
wrapProgram $out/bin/moon --set MOON_HOME $out
85+
'';
86+
87+
meta = with pkgs.lib; {
88+
description = "MoonBit toolchain with latest moon and current moonc";
89+
homepage = "https://www.moonbitlang.com";
90+
license = licenses.asl20;
91+
mainProgram = "moon";
92+
platforms = platforms.linux;
93+
};
94+
};
95+
96+
devShells.default = pkgs.mkShell {
97+
buildInputs = with pkgs; [
98+
ocaml
99+
dune_3
100+
ocamlPackages.findlib
101+
ocamlPackages.menhir
102+
ocamlPackages.sedlex
103+
ocamlPackages.cmdliner
104+
ocamlPackages.yojson
105+
ocamlPackages.ppx_deriving_yojson
106+
ocamlPackages.zarith
107+
pkg-config
108+
libffi
109+
gmp
110+
];
111+
112+
shellHook = ''
113+
echo "MoonBit development shell"
114+
echo "OCaml version: $(ocaml -version)"
115+
echo "Dune version: $(dune --version)"
116+
'';
117+
};
118+
});
119+
}

src/basic_base64.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ let encode s =
4343
let get = Bytes.get_uint8 arr in
4444
let add c =
4545
Bytes.unsafe_blit alphabet c ret !pos 1;
46-
(incr [@inlined always]) pos
46+
incr pos
4747
[@@inline always]
4848
in
4949
let padding () =
5050
Bytes.unsafe_fill ret !pos 1 pad;
51-
(incr [@inlined always]) pos
51+
incr pos
5252
[@@inline always]
5353
in
5454
while !l > 2 do
@@ -96,7 +96,7 @@ let decode s =
9696
let get i = inv s.![i] [@@inline always] in
9797
let add c =
9898
Bytes.unsafe_set ret !iter (Char.unsafe_chr c);
99-
(incr [@inlined always]) iter
99+
incr iter
100100
[@@inline always]
101101
in
102102
while !pos < len - 4 do

src/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(env
1616
(_
1717
(flags
18-
(:standard -w -9-30))))
18+
(:standard -w -6-8-9-26-27-30-32-33-35-50))))
1919

2020
(executables
2121
(names moon0_main)

src/mcore.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,7 +3174,7 @@ module Map = struct
31743174
loc_ = _visitors_r3;
31753175
}
31763176

3177-
method visit_To_result : _ -> handle_kind = fun env -> To_result
3177+
method visit_To_result : _ -> handle_kind = fun _env -> To_result
31783178

31793179
method visit_Joinapply : _ -> var -> handle_kind =
31803180
fun env ->
@@ -3646,7 +3646,7 @@ module Map = struct
36463646
let _visitors_r4 = self#visit_location env _visitors_floc_ in
36473647
(fun cond ->
36483648
fun ifso ->
3649-
fun ifnot -> fun ty -> fun loc -> if_ ~loc cond ~ifso ?ifnot)
3649+
fun ifnot -> fun _ty -> fun loc -> if_ ~loc cond ~ifso ?ifnot)
36503650
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
36513651
_visitors_r4
36523652

@@ -3695,7 +3695,7 @@ module Map = struct
36953695
(fun obj ->
36963696
fun cases ->
36973697
fun default ->
3698-
fun ty -> fun loc -> switch_constr ~loc obj cases ~default)
3698+
fun _ty -> fun loc -> switch_constr ~loc obj cases ~default)
36993699
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
37003700
_visitors_r4
37013701

@@ -3731,7 +3731,7 @@ module Map = struct
37313731
(fun obj ->
37323732
fun cases ->
37333733
fun default ->
3734-
fun ty ->
3734+
fun _ty ->
37353735
fun loc -> switch_constant ~loc obj cases ~default)
37363736
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
37373737
_visitors_r4
@@ -4183,7 +4183,7 @@ module Map = struct
41834183
let _visitors_r0 = self#visit_typ env _visitors_ffunc_ty in
41844184
Normal { func_ty = _visitors_r0 }
41854185

4186-
method visit_Join : _ -> apply_kind = fun env -> Join
4186+
method visit_Join : _ -> apply_kind = fun _env -> Join
41874187

41884188
method visit_apply_kind : _ -> apply_kind -> apply_kind =
41894189
fun env ->

src/riscv_internals.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn unsafe_bytes_blit (dst, dst_offset, src, src_offset, length) {
2121
return %3
2222
}
2323
*)
24-
let unsafe_bytes_blit fn =
24+
let unsafe_bytes_blit _fn =
2525
(* Construct arguments *)
2626
let dst = new_temp T_bytes in
2727
let dst_offset = new_temp T_int in
@@ -66,7 +66,7 @@ fn unsafe_bytes_sub_string (src, offset, length) {
6666
return %3
6767
}
6868
*)
69-
let unsafe_bytes_sub_string fn =
69+
let unsafe_bytes_sub_string _fn =
7070
(* Arguments *)
7171
let src = new_temp T_bytes in
7272
let offset = new_temp T_int in

src/riscv_opt.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ let iter_fn2 f ssa =
152152
let map_fn f ssa =
153153
let map_aux (toplevel: instruction) =
154154
match toplevel with
155-
| FnDecl { fn; body; args; } -> Riscv_ssa.FnDecl { fn; body = f fn; args }
155+
| FnDecl { fn; body = _body; args; } -> Riscv_ssa.FnDecl { fn; body = f fn; args }
156156
| x -> x
157157
in
158158
List.map map_aux ssa
@@ -240,7 +240,7 @@ let liveness_analysis fn =
240240
let last_item = Vec.pop_opt worklist in
241241
match last_item with
242242
| None -> ()
243-
| Some fn ->
243+
| Some _fn ->
244244
List.iter (fun name ->
245245
let block = block_of name in
246246
let old_live_in = Hashtbl.find live_in name in

src/riscv_opt_peephole.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ let rec is_pure fn =
129129
List.for_all (fun block ->
130130
List.for_all (fun x ->
131131
let is_global = ref false in
132-
reg_iterd (fun var ->
132+
reg_iterd (fun var ->
133133
if Stringset.mem var.name global_vars then
134-
is_global := true;
135-
var) x;
134+
is_global := true) x;
136135
not !is_global
137136
) (body_of block) &&
138137
List.for_all (fun x -> match x with

src/riscv_ssa.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ let rec sizeof ty =
247247
| Mtype.T_uint64 -> 8
248248
| Mtype.T_unit -> 0 (* Unit type has no size *)
249249
| Mtype.T_tuple _ -> pointer_size
250-
| Mtype.T_constr id -> pointer_size
250+
| Mtype.T_constr _ -> pointer_size
251251
| Mtype.T_fixedarray _ -> pointer_size
252252
| Mtype.T_trait _ -> pointer_size
253253

@@ -345,8 +345,6 @@ let to_string t =
345345
let die x =
346346
failwith (Printf.sprintf "riscv_ssa.ml: invalid byte count (%d) in load/store" x)
347347
in
348-
349-
(** Deal with indentation inside functions. *)
350348
let rec str t depth =
351349
String.make (depth * 2) ' ' ^
352350
match t with

src/riscv_tac2ssa.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ let rename fn =
329329

330330
List.iter dfs (Hashtbl.find domtree name);
331331

332-
Vec.iter (fun inst -> reg_iter (fun rd -> pop_def rd.name) (fun x -> x) inst) old_body;
332+
Vec.iter (fun inst -> reg_iter (fun rd -> pop_def rd.name) (fun _rs -> ()) inst) old_body;
333333
) in
334334
dfs fn
335335

0 commit comments

Comments
 (0)