Skip to content

Commit b1edca0

Browse files
committed
fix: patch fypp to emit resync linemarker after single-line $: calls
Single-line $:GPU_PARALLEL_LOOP() and similar macros expand to leaving the next Fortran statement attributed to the macro call-site line rather than the following source line. This causes off-by-1 errors in all backtraces, compiler error messages, and debugger line info for every GPU-macro-wrapped loop body in the codebase (~2188 affected call sites). Root cause: fypp's _postprocess_eval_line only emits a trailing resync linemarker when the $: call spans >1 source lines (multiline) or when line-folding splits output (unsync). Single-line calls that produce multi-line output hit neither condition. Fix: always emit the resync marker after any $: call that ends its line. Implemented as a patch applied to the installed fypp.py after venv setup in toolchain/bootstrap/python.sh, with a sentinel check so it is idempotent across reinstalls.
1 parent e16c79c commit b1edca0

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/common/include/2dHardcodedIC.fpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@
292292
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**1.4
293293
q_prim_vf(eqn_idx%mom%beg + 0)%sf(i, j, &
294294
& 0) = patch_icpp(1)%vel(1) + (y_cc(j) - patch_icpp(1)%y_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) &
295-
& - patch_icpp(1) %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
295+
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
296296
q_prim_vf(eqn_idx%mom%beg + 1)%sf(i, j, &
297297
& 0) = patch_icpp(1)%vel(2) - (x_cc(i) - patch_icpp(1)%x_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) &
298-
& - patch_icpp(1) %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
298+
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
299299
end if
300300
case (281) ! Acoustic pulse
301301
! This is patch is hard-coded for test suite optimization used in the 2D_acoustic_pulse case: This analytic patch uses

toolchain/bootstrap/python.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,20 @@ if ! cmp "$(pwd)/toolchain/pyproject.toml" "$(pwd)/build/pyproject.toml" > /dev/
408408

409409
fi # end of USE_UV=0 (pip) block
410410
fi
411+
412+
413+
# Apply patches to installed packages.
414+
# fypp: always emit a resync linemarker after single-line $: macro calls so
415+
# that the compiler attributes the following Fortran statement to the correct
416+
# source line rather than the call-site line (off-by-1 in backtraces).
417+
FYPP_PY="$(python3 -c "import fypp; print(fypp.__file__)" 2>/dev/null)"
418+
FYPP_PATCH="$(pwd)/toolchain/patches/fypp-linemarker-resync.patch"
419+
if [ -n "$FYPP_PY" ] && [ -f "$FYPP_PATCH" ]; then
420+
if ! grep -q "or True" "$FYPP_PY" 2>/dev/null; then
421+
if patch -p1 --forward --silent "$FYPP_PY" < "$FYPP_PATCH" 2>/dev/null; then
422+
ok "(venv) Applied$MAGENTA fypp$COLOR_RESET linemarker-resync patch."
423+
else
424+
warn "(venv) Failed to apply$MAGENTA fypp$COLOR_RESET linemarker-resync patch (fypp version may have changed)."
425+
fi
426+
fi
427+
fi
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--- a/fypp.py
2+
+++ b/fypp.py
3+
@@ -1842,11 +1842,16 @@ class _Renderer:
4+
if self._linenums:
5+
# Last line was folded, but no linenums were generated for
6+
# the continuation lines -> current line position is not
7+
# in sync with the one calculated from the last line number
8+
unsync = (
9+
len(foldedlines) and len(foldedlines[-1]) > 1
10+
and not self._contlinenums)
11+
# Eval directive in source consists of more than one line
12+
multiline = span[1] - span[0] > 1
13+
- if unsync or multiline:
14+
+ # Always emit a resync marker after a $: call. Without this,
15+
+ # single-line $: calls that expand to multi-line #if/#endif
16+
+ # blocks (e.g. GPU_PARALLEL_LOOP) cause the compiler to
17+
+ # attribute the next Fortran statement to the call-site line
18+
+ # rather than the following source line, producing off-by-1
19+
+ # errors in backtraces and debugger line info.
20+
+ if unsync or multiline or True:
21+
# For inline eval directives span[0] == span[1]
22+
# -> next line is span[0] + 1 and not span[1] as for
23+
# line eval directives
24+
nextline = max(span[1], span[0] + 1)
25+
trailing += self._linenumdir(nextline, fname)

0 commit comments

Comments
 (0)