diff --git a/crates/moon/tests/test_cases/cond_comp.in/moon.test b/crates/moon/tests/test_cases/cond_comp.in/moon.test index ff050ccc..96a3c6c8 100644 --- a/crates/moon/tests/test_cases/cond_comp.in/moon.test +++ b/crates/moon/tests/test_cases/cond_comp.in/moon.test @@ -57,3 +57,212 @@ moonc build-package ./src/main/main.mbt -o ./target/native/debug/build/main/main.core -pkg username/hello/main -is-main -i ./target/native/debug/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target native -g moonc link-core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main username/hello/main -o ./target/native/debug/build/main/main.exe -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target native -g + $ moon check + + Warning: [1002] + ╭─[${WORK_DIR}/src/lib/all.mbt:2:7] + │ + 2 │ let a = 1 + │ ┬ + │ ╰── Warning: Unused variable 'a' + ───╯ + Finished. moon: ran 3 tasks, now up to date + + $ xcat target/wasm-gc/release/check/packages.json + { + "source_dir": "${WORK_DIR}", + "name": "username/hello", + "packages": [ + { + "is-main": false, + "is-third-party": false, + "root-path": "${WORK_DIR}/src/lib", + "root": "username/hello", + "rel": "lib", + "files": { + "${WORK_DIR}/src/lib/only_debug.mbt": { + "backend": [ + "Wasm", + "WasmGC", + "Js", + "Native" + ], + "optlevel": [ + "Debug" + ] + }, + "${WORK_DIR}/src/lib/all.mbt": { + "backend": [ + "Wasm", + "WasmGC", + "Js", + "Native" + ], + "optlevel": [ + "Debug", + "Release" + ] + }, + "${WORK_DIR}/src/lib/only_wasm.mbt": { + "backend": [ + "Wasm" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/native_only.mbt": { + "backend": [ + "Native" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/only_js.mbt": { + "backend": [ + "Js" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/js_or_wasm.mbt": { + "backend": [ + "Wasm", + "Js" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/only_wasm_gc.mbt": { + "backend": [ + "WasmGC" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/all_wasm.mbt": { + "backend": [ + "Wasm", + "WasmGC" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/not_js.mbt": { + "backend": [ + "Wasm", + "WasmGC", + "Native" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/native_and_wasm.mbt": { + "backend": [ + "Wasm", + "Native" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/js_and_release.mbt": { + "backend": [ + "Js" + ], + "optlevel": [ + "Release" + ] + }, + "${WORK_DIR}/src/lib/wasm_release_or_js_debug.mbt": { + "backend": [ + "Wasm", + "Js" + ], + "optlevel": [ + "Release", + "Debug" + ] + } + }, + "wbtest-files": {}, + "test-files": { + "${WORK_DIR}/src/lib/js_only_test.mbt": { + "backend": [ + "Js" + ], + "optlevel": [ + "Release", + "Debug" + ] + }, + "${WORK_DIR}/src/lib/hello_test.mbt": { + "backend": [ + "Wasm", + "WasmGC", + "Js", + "Native" + ], + "optlevel": [ + "Debug", + "Release" + ] + } + }, + "deps": [], + "wbtest-deps": [], + "test-deps": [], + "artifact": "${WORK_DIR}/target/wasm-gc/release/check/lib/lib.mi" + }, + { + "is-main": true, + "is-third-party": false, + "root-path": "${WORK_DIR}/src/main", + "root": "username/hello", + "rel": "main", + "files": { + "${WORK_DIR}/src/main/main.mbt": { + "backend": [ + "Wasm", + "WasmGC", + "Js", + "Native" + ], + "optlevel": [ + "Debug", + "Release" + ] + } + }, + "wbtest-files": {}, + "test-files": {}, + "deps": [ + { + "path": "username/hello/lib", + "alias": "lib" + } + ], + "wbtest-deps": [], + "test-deps": [], + "artifact": "${WORK_DIR}/target/wasm-gc/release/check/main/main.mi" + } + ], + "deps": [], + "backend": "wasm-gc", + "opt_level": "release", + "source": "src" + } diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 2c0e1a3b..dbcf8aae 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -2433,8 +2433,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y.wasm-gc.mbt": { @@ -2442,8 +2442,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y.wasm.mbt": { @@ -2451,8 +2451,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2462,8 +2462,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y_wbtest.mbt": { @@ -2483,8 +2483,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y_wbtest.wasm.mbt": { @@ -2492,8 +2492,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2527,8 +2527,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/1/x.wasm-gc.mbt": { @@ -2536,8 +2536,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/1/x.wasm.mbt": { @@ -2545,8 +2545,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2556,8 +2556,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2704,8 +2704,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y.wasm-gc.mbt": { @@ -2713,8 +2713,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y.wasm.mbt": { @@ -2722,8 +2722,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2733,8 +2733,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y_wbtest.mbt": { @@ -2754,8 +2754,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/0/y_wbtest.wasm.mbt": { @@ -2763,8 +2763,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2798,8 +2798,8 @@ fn test_dummy_core() { "Js" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/1/x.wasm-gc.mbt": { @@ -2807,8 +2807,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] }, "$ROOT/1/x.wasm.mbt": { @@ -2816,8 +2816,8 @@ fn test_dummy_core() { "Wasm" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, @@ -2827,8 +2827,8 @@ fn test_dummy_core() { "WasmGC" ], "optlevel": [ - "Debug", - "Release" + "Release", + "Debug" ] } }, diff --git a/crates/moonutil/src/cond_expr.rs b/crates/moonutil/src/cond_expr.rs index 5cbfec60..dc3118de 100644 --- a/crates/moonutil/src/cond_expr.rs +++ b/crates/moonutil/src/cond_expr.rs @@ -74,8 +74,10 @@ impl CondExpr { } pub fn to_compile_condition(&self) -> CompileCondition { - let mut backend = vec![]; - let mut optlevel = vec![]; + use std::collections::HashSet; + + let mut backend_set = HashSet::new(); + let mut optlevel_set = HashSet::new(); for (t, o) in [ (TargetBackend::Wasm, OptLevel::Debug), (TargetBackend::Wasm, OptLevel::Release), @@ -87,13 +89,17 @@ impl CondExpr { (TargetBackend::Native, OptLevel::Release), ] { if self.eval(o, t) { - optlevel.push(o); - backend.push(t); + optlevel_set.insert(o); + backend_set.insert(t); } } - backend.dedup(); - optlevel.dedup(); + let mut backend: Vec<_> = backend_set.into_iter().collect(); + let mut optlevel: Vec<_> = optlevel_set.into_iter().collect(); + + // to keep a stable order + backend.sort(); + optlevel.sort(); CompileCondition { backend, optlevel } } }