1 #!/bin/bash
2 # Phase 0c: the compiler must be correct on a COLD package cache.
3 #
4 # Every other phase shares the tree's package cache, so every build it makes is
5 # warm, and round 369 found exactly what that hid. pkgHash - the OBJECT key -
6 # folds in the dispatch fingerprint, which exists only after
7 # measureDispFingerprints has run. The export blob (mxh) was named from that
8 # same key, so the dependency pre-pass wrote it under the pre-measurement name
9 # (link-set fallback) and the compile phase read the post-measurement one. On a
10 # cache generation that had never been written - the first build after any
11 # compiler upgrade, since the generation directory is per compiler build - the
12 # read missed, a worker compiled with an empty sub-registry, and the interface
13 # dispatch table it emitted was missing every impl from the root package (fmt
14 # carried 78 of the 86 impls). The symptom is that fmt prints '?' for every
15 # Stringer, which the fixture below makes a hard failure.
16 #
17 # MOXIEPATH moves the package cache, so a cold cache is one directory away and
18 # this phase does not depend on what the rest of the suite has warmed.
19 set -euo pipefail
20 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
21 ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
22 source "$SCRIPT_DIR/util.sh"
23 24 echo ""
25 echo "=== Phase 0c: cold package cache ==="
26 27 FIXTURE="$SCRIPT_DIR/regressions/should_compile/builtin_string_render.mx"
28 if [ ! -f "$FIXTURE" ]; then
29 log_fail "coldcache:fixture" "missing fixture: $FIXTURE"
30 exit 1
31 fi
32 td="$(tempdir "coldcache")"; rm -rf "$td"; mkdir -p "$td/pkg"
33 cp "$FIXTURE" "$td/pkg/main.mx"
34 35 # -j 4 on purpose: the loss happened in the worker processes' registry, and a
36 # serial build has a whole-link pre-pass in one process and does not need the
37 # mxh to be found at all.
38 case_one() { # case_one <label> <MOXIEPATH> <extra build args...>
39 local label="$1" mpath="$2"; shift 2
40 local log="$td/$label.log" out="$td/$label.out" brc=0 rrc=0
41 mkdir -p "$mpath"
42 if ! MOXIEPATH="$mpath" MOXIEROOT="$ROOT" "$MOXIE" build -j 4 "$@" \
43 -o "$td/$label.bin" "$td/pkg" >"$log" 2>&1; then
44 brc=1
45 fi
46 if [ "$brc" -ne 0 ]; then
47 log_fail "coldcache:$label" "build failed: $(first_error "$log")"
48 return 1
49 fi
50 "$td/$label.bin" >"$out" 2>&1 || rrc=$?
51 if [ "$rrc" -ne 0 ] || grep -q '^FAIL ' "$out"; then
52 log_fail "coldcache:$label" "$(grep '^FAIL ' "$out" | head -1)"
53 return 1
54 fi
55 log_pass "coldcache:$label" "printed every Stringer correctly"
56 }
57 58 fail=0
59 # 1. Nothing in the cache: the pre-pass writes the export blob, the workers read
60 # it back. This is the exact configuration that was broken.
61 case_one cold "$td/cache-cold" || fail=1
62 # 2. The same cache again, forced rebuild so the workers still do the work.
63 case_one warm "$td/cache-cold" -a || fail=1
64 # 3. A second, independent cold cache. A name that is only stable because a file
65 # already exists is the bug, so the pass must not depend on run order.
66 case_one cold2 "$td/cache-cold2" || fail=1
67 68 exit "$fail"
69