source: doc/proposals/nowarn.md @ df56e25

Last change on this file since df56e25 was d9162ec, checked in by Michael Brooks <mlbrooks@…>, 4 weeks ago

Fix test-classification commands to detect more strict-capable tests. Remove such tests from the lax list.

Nothing about how to use the document is different, just what to paste.

Also, add back tests that give warnings only on release mode.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1Making CFA compilation free of warnings
2=======================================
3
4Rationale
5---------
6
7A CS 343 student programming in CFA should be able to run our compiler with -Wall -Wextra, as the course standards mandate for uC++.  When doing so, all warnings seen should be caused by the student's choices.  At the close of 2024, about 70% of the CFA code written in the test suite produces warnings; anecdotally, about half of those are caused by CFA language features lowering to C code that does not satisfy strict warning rules.  So, CS 343 students are left swamped by warnings that they did not cause, and are powereless to prevent.  As a result they are more likely to ignore all the warnings and to be unable to learn from their real warnings about their real programming mistakes.
8
9We should ensure that known causes of transpiler-induced C warnings are reduced or eliminated.  The body of this document gives guidance for CFA maintainers about how to do so.
10
11
12Test Suite
13----------
14
15Test-suite compilation occurs in either strict or lax "wflags" mode.  Strict mode is -Wall -Wextra -Werror, so a test in strict mode cannot pass unless it is free of warnings.  Makefile.am owns a list of tests that opt for lax wflags (WFLGAS_OPT_LAX).  At the close of 2024, about 70% of the tests are on this list.
16
17The `tests/nowarn` folder contains tests targeted at individual languge features that once caused warnings, but were since fixed.  Each such language feature is probably also tested in a general test.  Still, the targeted test is also valuable because, in the event of a regression, the targeted test has the outcome of the analysis that first had to occur on the general test.  This test also ensures the regression continues to be checked even if libcfa code changes to avoid using the problematic language feature.
18
19
20Example fix
21-----------
22
23Upon this background, an example work cycle is now journaled.  The example change is committed along with the first draft of this proposal document.
24
25The goal is to eliminate warnings seen in `array-collections/array-basic`.  Before the change, this test appears on WFLGAS_OPT_LAX.
26
27To see the warning:
281. remove it from WFLGAS_OPT_LAX
292. run autogen.sh
303. rerun configure
314. remake cfa-cc/libcfa
325. run the test in test.py; expect failure, with the warning detail visible
33
34Some warnings are only seen in release mode or on alternate architectures.  Useful command arguments to access some of these setups from plg2 include:
35```
36    ../cfa-cc/configure --with-target-hosts=host:debug,host:nodebug,x86:nodebug ...
37    ./tests/test.py --arch x86 --debug no ...
38```
39
40Diagnosing the cause of the warning is not journaled.  In some cases, it is a programming mistake done directly in tests/foo.cfa; in such a case, the (part of the) fix is trivial.  The journaling follows a cause in cfa-cpp.
41
42The cause of the `array-collections/array-basic` warnings is that there was unnecessary special handling for `zero_t`, which when showing up inside a thunk, caused the thunk to ignore one of its arguments.  With the cfa-cpp fix in place, the array test (still absent from WFLGAS_OPT_LAX) passes.
43
44Consider adding a targeted `tests/nowarn` test, if there was nontrivial analysis involved in finding the cause of the warning.
45
46The fix is a contribution toward the goal of reducing the WFLGAS_OPT_LAX list.  But work so far has only reduced it by one entry, even though it is probable that fixing a transpiler-induced warning cleans up warnings from several tests.  So far, such tests would be using WFLGAS_OPT_LAX unnecessarily, which a test.py run does not detect.
47
48To identify the other tests now fixed:
491. Ensure that all tests pass.
502. Create a situation where all tests will be attempted with strict wflags.
51   1. Comment out the value of WFLGAS_OPT_LAX, leaving the variable defined as empty.
52   2. autogen, configure, make (as before)
533. Rerun all the tests, expecting many failures.  Each failure represents a test that cannot handle strict wflags.
54   1. `./tests/test.py --all ... 2>&1 | tee test-status.txt`
55   2. `grep 'PASSED  ' test-status.txt | sed -E 's/\s+([^ ]+).*$/\1/g' > test-passes.txt`
56   3. `grep 'FAILED with' test-status.txt | sed -E 's/\s+([^ ]+).*$/\1/g' > test-fails.txt`
574. Trim the WFLGAS_OPT_LAX list, reconciling with the pass/fail status just obtained.
58   1. Copy-paste just the WFLGAS_OPT_LAX items into `wflags-lax.txt`.  Keeping leading pounds and trailing backslashes is optional.
59   2. Print a list of tests found in `wflags-lax.txt` and also in `test-passes.txt`.  These tests were originally on WFLGAS_OPT_LAX, but can now pass without being on it.
60      - `sed -E 's/^([a-zA-Z])/(^|\\\\s|#)\1/g;s/\.\.\.//g;s/$/($|\\\\s|\\\\\\\\)/g' test-passes.txt | xargs -n 1 -I % echo "grep -E '%' wflags-lax.txt" | sh | sort`
61   3. Note that in the running array-basic example, the resulting list was:
62      - array-collections/array-sbscr-types (*)
63      - ctrl-flow/loopctrl
64      - userLiterals
65      - vector_math/vec2_int
66      - vector_math/vec2_float
67      - vector_math/vec3_float
68      - vector_math/vec4_float
69      - zero_one
70   4. Uncomment the official WFLGAS_OPT_LAX list.  Modify it to discard these tests.
71   5. autogen, configure, make (as before)
725. Ensure that all tests pass, now under the reduced WFLGAS_OPT_LAX list.  Be deliberate about release mode and alternate architectures; i.e. that you aren't claiming to have fixed a test that always worked in x64-debug, but failed on a different configuration.  (Note that the overnight build will still catch that.)
73
74(*) This test was found later, upon fixing a problem in these instructions, so the original commit does not show it as fixed, like it does for the others.
Note: See TracBrowser for help on using the repository browser.