|
| 1 | +#!/usr/bin/env bash |
| 2 | +source ../common.sh |
| 3 | + |
| 4 | +./clean.sh |
| 5 | + |
| 6 | +# --- |
| 7 | +# This test covers `compiler.postponeCompile`, under which Lake defers a module system module's |
| 8 | +# code generation to a separate `leanir` step producing its `.ir.sig`, `.ir`, and `.c`. |
| 9 | +# --- |
| 10 | + |
| 11 | +# The rebuild tests below edit the sources, so work on a copy |
| 12 | +copy_to_work lakefile.toml Main.lean Test.lean Test Eval.lean |
| 13 | + |
| 14 | +# Elaboration alone does not generate code |
| 15 | +test_run build Test.A |
| 16 | +test_cmd_fails test -f .lake/build/ir/Test/A.c |
| 17 | + |
| 18 | +# Each module's code generation is a job of its own |
| 19 | +echo "# TEST: code generation" |
| 20 | +test_out "Built Test.A:irArts" build Test.A:c -v |
| 21 | +test_cmd test -f .lake/build/lib/lean/Test/A.ir.sig |
| 22 | +test_cmd test -f .lake/build/lib/lean/Test/A.ir |
| 23 | +test_out "Built Test.B:irArts" build Test.B:c -v |
| 24 | +test_run build Test.C:c |
| 25 | + |
| 26 | +# An import's IR must be provided even for a plain `import`, as the language server loads it |
| 27 | +test_cmd grep -F 'Test/A.ir"' .lake/build/ir/Test/B.setup.json |
| 28 | +test_cmd grep -F 'Test/A.ir"' .lake/build/ir/Test/B.irsetup.json |
| 29 | + |
| 30 | +# The server allows `#eval` on a plainly imported definition, so it must be able to run it |
| 31 | +echo "# TEST: server eval across a plain import" |
| 32 | +echo '$' lake setup-file Eval.lean |
| 33 | +"$LAKE" setup-file Eval.lean > eval.setup.json |
| 34 | +test_cmd_eq 42 lean --setup eval.setup.json -DElab.inServer=true Eval.lean |
| 35 | + |
| 36 | +# The generated code links and runs |
| 37 | +echo "# TEST: link and run" |
| 38 | +test_run build codegen |
| 39 | +test_cmd_eq 42 ./.lake/build/bin/codegen |
| 40 | + |
| 41 | +# --- |
| 42 | +# Tests that `leanir` is only rerun when needed |
| 43 | +# --- |
| 44 | + |
| 45 | +test_run build Test.A:c Test.B:c Test.C:c --no-build |
| 46 | + |
| 47 | +# A non-inlinable definition's body is part of the module's IR, but not of its `.ir.sig` |
| 48 | +echo "# TEST: irArts on a value edit" |
| 49 | +test_cmd sed_i 's/n + n/n + n + 0/' Test/A.lean |
| 50 | +test_out "Built Test.A:irArts" build Test.A:c -v |
| 51 | +# importers read only the `.ir.sig`, so their own IR is unaffected |
| 52 | +test_run build Test.B:c Test.C:c --no-build |
| 53 | + |
| 54 | +# A new public definition changes the `.ir.sig` as well |
| 55 | +echo "# TEST: irArts on an interface edit" |
| 56 | +test_run build Test.A:c Test.B:c Test.C:c |
| 57 | +test_cmd sed_i 's/^private def offset/public def extra : Nat := 7\nprivate def offset/' Test/A.lean |
| 58 | +test_out "Built Test.A:irArts" build Test.A:c -v |
| 59 | +test_out "Built Test.B:irArts" build Test.B:c -v |
| 60 | + |
0 commit comments