Persistent linter log embeds absolute source file paths into `.olean.server` (and `.olean`), breaking build reproducibility across directories

Aperta
#16,811 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
build-system

Direzione di ricerca

Start with the cited path flow in src/lake/Lake/Build/Module.lean and Actions.lean, then inspect how src/Lean/Linter/PersistentLintLog.lean records and serializes source paths. Reproduce with the supplied three-directory Lake build and compare the listed artifacts. Done when identical source builds produce byte-for-byte identical compiled artifacts across checkout paths while preserving useful lint locations.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

When a module triggers any linter diagnostic (e.g. the default linter.unusedVariables), lake build produces directory-dependent .olean.server files (and, when path lengths differ enough to shift compacted-region offsets, .olean.private as well; in non-module files, .olean directly).

The root cause is that Lake passes the absolute source path to lean, and Lean.Linter.recordLints persists the raw m.fileName into lintLogExt (PersistentLintLog) without normalizing it to a project-relative path (unlike Lake's diagnostic output formatting, which already rewrites the filename to relSrcFile).

Related context: this mechanism was also observed in leanprover-community/riemann-hypothesis#6 / #40 on v4.33.1; it still reproduces on v4.35.0, v4.36.0 (611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9), and master (0e511b3aa1e6af4f6eaf98838db22801466af7b9).


Minimal Reproduction

Tested on Linux x86-64 with stock leanprover/lean4:v4.36.0 (611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9):

set -euo pipefail
base=$(mktemp -d /tmp/lean-path-repro.XXXXXX)
cd "$base"
mkdir dir_alpha dir_beta dir_beta_with_a_longer_absolute_path

cat > dir_alpha/PathAudit.lean <<'LEAN'
module

namespace PathAudit

public def answer (unused : Nat) : Nat := 42

end PathAudit
LEAN

cat > dir_alpha/lakefile.toml <<'TOML'
name = "path_audit"
defaultTargets = ["PathAudit"]
enableArtifactCache = false

[[lean_lib]]
name = "PathAudit"
TOML

printf 'leanprover/lean4:v4.36.0\n' > dir_alpha/lean-toolchain
for d in dir_beta dir_beta_with_a_longer_absolute_path; do
  cp dir_alpha/{PathAudit.lean,lakefile.toml,lean-toolchain} "$d/"
done

for d in dir_alpha dir_beta dir_beta_with_a_longer_absolute_path; do
  (cd "$d" && LAKE_NO_CACHE=1 lake build +PathAudit:leanArts)
done

# Compare all 7 compiled artifacts across directories
for ext in olean olean.server olean.private ir ir.sig ilean; do
  sha256sum dir_*/.lake/build/lib/lean/PathAudit."$ext"
done
sha256sum dir_*/.lake/build/ir/PathAudit.c

# Inspect embedded absolute path in .olean.server
strings -a -t d dir_alpha/.lake/build/lib/lean/PathAudit.olean.server | grep PathAudit.lean
Observed Behavior
Artifact dir_alpha vs dir_beta dir_alpha vs dir_beta_with_a_longer_absolute_path Notes
.olean Identical Identical No path string (in module mode)
.olean.server Differs Differs Embeds full /tmp/.../dir_*/PathAudit.lean under lintLogExt
.olean.private Identical Differs (1 byte) Cross-part compacted-region pointer into .olean.server shifts by 24 bytes when server region grows (1640 → 1664 bytes)
.ir, .ir.sig, .ilean, .c Identical Identical No absolute paths

Control checks confirming the cause:

  1. Passing -Dlinter.unusedVariables=false (eliminating the lint entry) makes all 7 artifacts byte-for-byte identical across all three directories.
  2. Replaying Lake's exact lean command with --setup preserved, changing only the source argument from /tmp/.../dir_*/PathAudit.lean to the relative path PathAudit.lean, also makes all 7 artifacts byte-for-byte identical across directories (recording PathAudit.lean instead of an absolute path).

Root Cause in Source (v4.36.0, commit 611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9)
  1. Lake computes relSrcFile but passes the absolute srcFile to lean:
  2. lean records the raw fileName into lintLogExt:
  3. Serialization into .olean.server / .olean.private (and .olean in non-module mode):
    • Lean/Linter/PersistentLintLog.lean#L19-L33 exports lintLogExt entries at server and private levels.
    • Because saveModuleDataParts (Lean/Environment.lean#L2113-L2123) shares a single object_compactor across parts, a longer absolute path in .olean.server shifts serialized object offsets referenced from .olean.private. In legacy non-module builds, writeModule serializes at private level into a single .olean, embedding the absolute path directly in .olean.

Expected Behavior / Possible Fixes

Compiled .olean* artifacts for identical source files should be invariant to the build checkout directory path (for reproducible builds, content-addressed caches, and artifact deduplication).

Possible approaches:

  1. Normalize the source path passed to lean / stored in PersistentLintLog: either have Lake pass relSrcFile (with cwd = mod.pkg.dir) or provide a relative/canonical display path in ModuleSetup / recordLints so persisted LintEntry.file and SerialMessage.fileName never contain machine-local absolute directory prefixes; or
  2. Omit the redundant file / fileName path prefix in PersistentLintLog entries when it matches the owning module's source file (since lintLogExt is already keyed per module and consumers can resolve the module's source file from the module name / package root).
Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
16h 45m
PR unite (30g)
361

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Build System

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.