This PR changes macro scope numbering from per-module to per-command, ensuring that unrelated changes to other commands do not affect macro scopes generated by a command, which improves `prefer_native` hit rates on bootstrapping as well as avoids further rebuilds under the module system. In detail, instead of always using the current module name as a macro scope prefix, each command now introduces a new macro scope prefix (called "context") of the shape `<main module>._hygCtx_<uniq>` where `uniq` is a `UInt32` derived from the command but automatically incremented in case of conflicts (which must be local to the current module). In the current implementation, `uniq` is the hash of the declaration name, if any, or else the hash of the full command's syntax. Thus, it is always independent of syntactic changes to other commands (except in case of hash conflicts, which should only happen in practice for syntactically identical commands) and, in the case of declarations, also independent of syntactic changes to any private parts of the declaration.
59 lines
1.3 KiB
Bash
Executable file
59 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euxo pipefail
|
|
|
|
source ../../../src/lake/tests/common.sh
|
|
|
|
rm -rf .lake/build
|
|
|
|
mkdir -p Rebuild
|
|
cat <<EOF > Rebuild/Basic.lean
|
|
-- File autocreated by test.sh
|
|
|
|
module
|
|
|
|
set_option compiler.small 0
|
|
|
|
public def hello := "world"
|
|
|
|
public def testSpec (xs : List Nat) : List Nat := xs.map (fun x => x + 1)
|
|
|
|
-- Public macro scopes such as from unnamed parameters and deriving handlers should not cause
|
|
-- rebuilds on changes above.
|
|
public def macroScopes : Nat -> Nat := id
|
|
|
|
public inductive Foo
|
|
deriving Repr
|
|
EOF
|
|
|
|
lake build
|
|
|
|
function test_unchanged() {
|
|
# Keep around previous version for easier diffing.
|
|
cp .lake/build/lib/lean/Rebuild/Basic.olean .lake
|
|
lake build Rebuild.Basic
|
|
lake build --no-build
|
|
}
|
|
|
|
# Whitespace does not matter.
|
|
echo "-- test" >> Rebuild/Basic.lean
|
|
test_unchanged
|
|
|
|
# Closed terms do not matter.
|
|
sed_i 's/"world"/"wodd"/' Rebuild/Basic.lean
|
|
test_unchanged
|
|
|
|
# Private declarations do not matter.
|
|
echo 'theorem priv : True := .intro' >> Rebuild/Basic.lean
|
|
test_unchanged
|
|
|
|
# Lambdas do not matter.
|
|
sed_i 's/"wodd"/dbg_trace "typo"; "wodd"/' Rebuild/Basic.lean
|
|
test_unchanged
|
|
|
|
# Private definitions do not matter.
|
|
echo 'def privd : Nat := 0' >> Rebuild/Basic.lean
|
|
test_unchanged
|
|
|
|
# Specializations do not matter.
|
|
sed_i 's/x + 1/x + 2/' Rebuild/Basic.lean
|
|
test_unchanged
|