haskell-nix / hnix

A Haskell re-implementation of the Nix expression language
https://hackage.haskell.org/package/hnix
BSD 3-Clause "New" or "Revised" License
768 stars 115 forks source link

`--check` causes `<<loop>>` for basic expressions #1016

Open runeksvendsen opened 2 years ago

runeksvendsen commented 2 years ago

I get a <<loop>> when trying to evaluate many simple Nix expressions using --check, e.g. data/nix/tests/lang/eval-okay-let.nix:

./result/bin/hnix -v5 --trace --check ./data/nix/tests/lang/eval-okay-let.nix +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
  Data.Text.Internal.IO.readTextDevice,
  called from Nix.Utils.readFile,
  called from Nix.Parser.parseFromFileEx,
  called from Nix.Parser.parseNixFileLoc,
  called from Nix.Standard.runWithBasicEffects,
  called from Main.main
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
  Nix.Eval.evalBinds,
  called from Nix.Eval.evalSelect,
  called from Nix.Eval.eval,
  called from Data.Fix.foldFix,
  called from Nix.Type.Infer.inferTop,
  called from Nix.Standard.runWithBasicEffects,
  called from Main.main
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
  Nix.Eval.evalBinds,
  called from Nix.Eval.evalSelect,
  called from Nix.Eval.eval,
  called from Data.Fix.foldFix,
  called from Nix.Type.Infer.inferTop,
  called from Nix.Standard.runWithBasicEffects,
  called from Main.main
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
  Nix.Eval.evalBinds,
  called from Nix.Eval.evalSelect,
  called from Nix.Eval.eval,
  called from Data.Fix.foldFix,
  called from Nix.Type.Infer.inferTop,
  called from Nix.Standard.runWithBasicEffects,
  called from Main.main
hnix: <<loop>>

This applies to all of the following expressions:

data/nix/tests/build-hook.nix
data/nix/tests/check-refs.nix
data/nix/tests/check-reqs.nix
data/nix/tests/check.nix
data/nix/tests/config.nix
data/nix/tests/dependencies.nix
data/nix/tests/export-graph.nix
data/nix/tests/filter-source.nix
data/nix/tests/fixed.nix
data/nix/tests/gc-concurrent.nix
data/nix/tests/gc-runtime.nix
data/nix/tests/hash-check.nix
data/nix/tests/import-derivation.nix
data/nix/tests/lang/eval-fail-assert.nix
data/nix/tests/lang/eval-fail-blackhole.nix
data/nix/tests/lang/eval-fail-remove.nix
data/nix/tests/lang/eval-fail-scope-5.nix
data/nix/tests/lang/eval-okay-arithmetic.nix
data/nix/tests/lang/eval-okay-attrnames.nix
data/nix/tests/lang/eval-okay-attrs.nix
data/nix/tests/lang/eval-okay-attrs2.nix
data/nix/tests/lang/eval-okay-attrs5.nix
data/nix/tests/lang/eval-okay-builtins.nix
data/nix/tests/lang/eval-okay-closure.nix
data/nix/tests/lang/eval-okay-concatmap.nix
data/nix/tests/lang/eval-okay-context-introspection.nix
data/nix/tests/lang/eval-okay-deepseq.nix
data/nix/tests/lang/eval-okay-delayed-with-inherit.nix
data/nix/tests/lang/eval-okay-delayed-with.nix
data/nix/tests/lang/eval-okay-elem.nix
data/nix/tests/lang/eval-okay-eq-derivations.nix
data/nix/tests/lang/eval-okay-eq.nix
data/nix/tests/lang/eval-okay-filter.nix
data/nix/tests/lang/eval-okay-flatten.nix
data/nix/tests/lang/eval-okay-functionargs.nix
data/nix/tests/lang/eval-okay-getattrpos.nix
data/nix/tests/lang/eval-okay-import.nix
data/nix/tests/lang/eval-okay-let.nix
data/nix/tests/lang/eval-okay-list.nix
data/nix/tests/lang/eval-okay-listtoattrs.nix
data/nix/tests/lang/eval-okay-map.nix
data/nix/tests/lang/eval-okay-mapattrs.nix
data/nix/tests/lang/eval-okay-overrides.nix
data/nix/tests/lang/eval-okay-partition.nix
data/nix/tests/lang/eval-okay-patterns.nix
data/nix/tests/lang/eval-okay-redefine-builtin.nix
data/nix/tests/lang/eval-okay-regex-match.nix
data/nix/tests/lang/eval-okay-remove.nix
data/nix/tests/lang/eval-okay-scope-2.nix
data/nix/tests/lang/eval-okay-scope-3.nix
data/nix/tests/lang/eval-okay-scope-4.nix
data/nix/tests/lang/eval-okay-scope-6.nix
data/nix/tests/lang/eval-okay-scope-7.nix
data/nix/tests/lang/eval-okay-search-path.nix
data/nix/tests/lang/eval-okay-toxml2.nix
data/nix/tests/lang/eval-okay-versions.nix
data/nix/tests/lang/eval-okay-with.nix
data/nix/tests/lang/lib.nix
data/nix/tests/lang/parse-fail-dup-attrs-2.nix
data/nix/tests/lang/parse-fail-dup-attrs-3.nix
data/nix/tests/lang/parse-fail-dup-attrs-7.nix
data/nix/tests/lang/parse-fail-regression-20060610.nix
data/nix/tests/lang/parse-okay-crlf.nix
data/nix/tests/multiple-outputs.nix
data/nix/tests/nar-access.nix
data/nix/tests/nix-copy-closure.nix
data/nix/tests/parallel.nix
data/nix/tests/remote-builds.nix
data/nix/tests/run.nix
data/nix/tests/search.nix
data/nix/tests/secure-drv-outputs.nix
data/nix/tests/shell.nix
data/nix/tests/simple.nix
data/nix/tests/structured-attrs.nix
data/nix/tests/timeout.nix
data/nix/tests/user-envs.nix
tests/eval-compare/builtins.appendContext.nix
tests/eval-compare/builtins.eq-bottom-00.nix
tests/eval-compare/builtins.fetchurl-01.nix
tests/eval-compare/builtins.lessThan-01.nix
tests/eval-compare/builtins.replaceStrings-01.nix
tests/eval-compare/builtins.toJSON.nix
tests/eval-compare/ellipsis.nix
tests/files/attrs.nix
tests/files/callLibs.nix
tests/files/hello2.nix
tests/files/lint.nix
tests/files/test.nix

Is --check supposed to work?

I'm on master, building hnix using nix-build using the "Full debug info" options on macOS.

Anton-Latukha commented 2 years ago

Thanks for the report.

The initial hunch is that I kind of went wild along here & swapped cons into snocs in some places, which looking back probably shouldn't, but I had some ideas to find optimizations in mind, thou not finished that. Those changes may cause infinite loops. But also there are many other things that may cause it.

A bunch of reports need bisecting. Thankfully commits are good for that & https://github.com/Anton-Latukha/git-bisect-master-pr. Would look into it when would make a release from master. You are free to look into it.

The code that processes the --check starts here: https://github.com/haskell-nix/hnix/blob/d3d4356dd2588427a3a24fc8776aca42b472c472/main/Main.hs#L119-L128

runeksvendsen commented 2 years ago

Thank you @Anton-Latukha, I will look into it

runeksvendsen commented 2 years ago

@Anton-Latukha do you have a known good commit for the purpose of bisecting?

I am unable to build v0.13.1 because GHC simply hangs when compiling the Nix.Atoms module.

Trying to build v0.12.0 I get this error:

$ git checkout b93202fc125e54ecb898831b672fbb4f81f71af7
$ nix-build \
  --arg doCheck false --arg disableOptimization false \
  --arg enableDeadCodeElimination true \
  --arg doBenchmark true \
  --arg doStrip false \
  --arg enableLibraryProfiling true \
  --arg enableExecutableProfiling true \
  --arg doTracing true \
  --arg enableDWARFDebugging true
building '/nix/store/79bivh9vsgcx4ayxplc1rbcqp98cn8rk-cabal2nix-hnix.drv'...
installing
these derivations will be built:
  /nix/store/sw1n6md4a4c3fvb3lnhhgp2ajzg4hqpr-nanospec-0.2.2.drv
  /nix/store/w0slrbsx79k3wxd3ygln8a28y16nzfwz-call-stack-0.2.0.drv

[... SNIP]

building
Preprocessing library for linux-namespaces-0.1.3.0..
compiling dist/build/System/Linux/Namespaces_hsc_make.c failed (exit code 1)
rsp file was: "dist/build/System/Linux/hsc2hscall56182-0.rsp"
command was: /nix/store/0nlwbj5qbdf7r58x2iqz0a17az2j5fdn-clang-wrapper-7.1.0/bin/clang -c dist/build/System/Linux/Namespaces_hsc_make.c -o dist/build/System/Linux/Namespaces_hsc_make.o -D__GLASGOW_HASKELL__=810 -Ddarwin_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Ddarwin_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -I/nix/store/0jj05cyma647rywsqpq3darnzl6a520s-libc++-7.1.0/include -I/nix/store/ns7f13gldnk83l2fgjlzbx9bnfvc2g72-libc++abi-7.1.0/include -I/nix/store/6snmf1z43ay6m1b8jv8dr4h8im056a62-compiler-rt-7.1.0-dev/include -I/nix/store/q8xcp8hsa35wjki8mad0sbk4nzqrdkb5-libiconv-osx-10.12.6/include -I/nix/store/0jj05cyma647rywsqpq3darnzl6a520s-libc++-7.1.0/include -I/nix/store/ns7f13gldnk83l2fgjlzbx9bnfvc2g72-libc++abi-7.1.0/include -I/nix/store/6snmf1z43ay6m1b8jv8dr4h8im056a62-compiler-rt-7.1.0-dev/include -I/nix/store/q8xcp8hsa35wjki8mad0sbk4nzqrdkb5-libiconv-osx-10.12.6/include -Idist/build/autogen -Idist/build/global-autogen -include dist/build/autogen/cabal_macros.h -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/unix-2.7.2.2/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/time-1.9.3/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/bytestring-0.10.10.0/include -I/nix/store/q8xcp8hsa35wjki8mad0sbk4nzqrdkb5-libiconv-osx-10.12.6/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/base-4.14.0.0/include -I/nix/store/9m9q7bmn937d15p8q9m26fpxypi8vg92-gmp-6.2.1-dev/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/integer-gmp-1.0.3.0/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/include -I/nix/store/jikzfsnc21fsfzn991md0vi8j14p02sm-libffi-3.3-dev/include -I/nix/store/zb6p4jwcnn71l2wvr7zcgxjm5q10qgdc-ghc-8.10.1/lib/ghc-8.10.1/include/
error: Namespaces.hsc:79:16: error: use of undeclared identifier 'CLONE_NEWIPC'
    hsc_const (CLONE_NEWIPC);
               ^
Namespaces.hsc:79:16: error: use of undeclared identifier 'CLONE_NEWIPC'
Namespaces.hsc:79:16: error: use of undeclared identifier 'CLONE_NEWIPC'
Namespaces.hsc:80:16: error: use of undeclared identifier 'CLONE_NEWNET'
    hsc_const (CLONE_NEWNET);
               ^
Namespaces.hsc:80:16: error: use of undeclared identifier 'CLONE_NEWNET'
Namespaces.hsc:80:16: error: use of undeclared identifier 'CLONE_NEWNET'
Namespaces.hsc:81:16: error: use of undeclared identifier 'CLONE_NEWNS'
    hsc_const (CLONE_NEWNS);
               ^
Namespaces.hsc:81:16: error: use of undeclared identifier 'CLONE_NEWNS'
Namespaces.hsc:81:16: error: use of undeclared identifier 'CLONE_NEWNS'
Namespaces.hsc:82:16: error: use of undeclared identifier 'CLONE_NEWPID'
    hsc_const (CLONE_NEWPID);
               ^
Namespaces.hsc:82:16: error: use of undeclared identifier 'CLONE_NEWPID'
Namespaces.hsc:82:16: error: use of undeclared identifier 'CLONE_NEWPID'
Namespaces.hsc:83:16: error: use of undeclared identifier 'CLONE_NEWUSER'
    hsc_const (CLONE_NEWUSER);
               ^
Namespaces.hsc:83:16: error: use of undeclared identifier 'CLONE_NEWUSER'
Namespaces.hsc:83:16: error: use of undeclared identifier 'CLONE_NEWUSER'
Namespaces.hsc:84:16: error: use of undeclared identifier 'CLONE_NEWUTS'
    hsc_const (CLONE_NEWUTS);
               ^
Namespaces.hsc:84:16: error: use of undeclared identifier 'CLONE_NEWUTS'
Namespaces.hsc:84:16: error: use of undeclared identifier 'CLONE_NEWUTS'
18 errors generated.

builder for '/nix/store/nsvda6zhry4gpkahmynvjcj3cm31hr45-linux-namespaces-0.1.3.0.drv' failed with exit code 1
cannot build derivation '/nix/store/l1hsz44ra0wy5n4dn2dlhjh9npmbmxzf-hnix-store-remote-0.4.0.0.drv': 1 dependencies couldn't be built
building '/nix/store/i1grcahi7rv9a9s6dqvcnjn6xxb42nba-memory-0.15.0.drv'...
cannot build derivation '/nix/store/4s0dlpdsi68xc6125p5d1lmj48sma2bq-hnix-0.11.1.drv': 1 dependencies couldn't be built
error: build of '/nix/store/4s0dlpdsi68xc6125p5d1lmj48sma2bq-hnix-0.11.1.drv' failed

Trying to build v0.11.0 I get this error:

$ git checkout b21bb48bf5a4195cca78018b0db1e320f46535cd
$ nix-build \
  --arg doCheck false --arg disableOptimization false \
  --arg enableDeadCodeElimination true \
  --arg doBenchmark true \
  --arg doStrip false \
  --arg enableLibraryProfiling true \
  --arg enableExecutableProfiling true \
  --arg doTracing true \
  --arg enableDWARFDebugging true
building '/nix/store/akq78gfjkpfh0wdnriyys3sshi0ydp6v-cabal2nix-hnix.drv'...
installing
these derivations will be built:
  /nix/store/llqw561z1sba5hhhyx002gmjr37s27pc-hscolour-1.24.4.drv

[... SNIP ...]

building '/nix/store/llqw561z1sba5hhhyx002gmjr37s27pc-hscolour-1.24.4.drv'...
setupCompilerEnvironmentPhase
Build with /nix/store/379cjfvj3ngvh0j8hwn4akk4b2fl467b-ghc-8.10.1.
unpacking sources
unpacking source archive /nix/store/vbcisx90wrx657pa1iapmk38wvrv9p6p-hscolour-1.24.4.tar.gz
source root is hscolour-1.24.4
setting SOURCE_DATE_EPOCH to timestamp 1512069381 of file hscolour-1.24.4/hscolour.css
patching sources
compileBuildDriverPhase
setupCompileFlags: -package-db=/private/tmp/nix-build-hscolour-1.24.4.drv-0/setup-package.conf.d -j10 -threaded -rtsopts
[1 of 1] Compiling Main             ( Setup.hs, /private/tmp/nix-build-hscolour-1.24.4.drv-0/Main.o )
Linking Setup ...
ld: file not found: /usr/lib/system/libcache.dylib for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
`cc' failed in phase `Linker'. (Exit code: 1)
builder for '/nix/store/llqw561z1sba5hhhyx002gmjr37s27pc-hscolour-1.24.4.drv' failed with exit code 1
cannot build derivation '/nix/store/6217r2jzs4hx9r2wdy585kmdfjhpp1lb-hnix-0.11.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/6217r2jzs4hx9r2wdy585kmdfjhpp1lb-hnix-0.11.0.drv' failed

I'm on macOS 12.0.1, on a MacBook Pro M1 using Rosetta x86 emulation (which works perfectly well for building everything else I've tried so far).

runeksvendsen commented 2 years ago

Here's a spindump of GHC when it hangs building Nix.Atoms (which 200% CPU usage):

Date/Time:        2022-01-15 09:36:28.785 +0100
End time:         2022-01-15 09:36:38.787 +0100
OS Version:       macOS 12.0.1 (Build 21A559)
Architecture:     arm64e
Report Version:   35
Share With Devs:  Yes

Data Source:      Stackshots
Shared Cache:     A6162D66-93E3-3251-93CC-B11F7C8C830E slid base address 0x18fffc000, slide 0xfffc000
Shared Cache:     9A25B4E4-A552-32E4-BF1A-8E79EB176368 slid base address 0x1e0c1c000, slide 0x60c1c000
Shared Cache:     B5084610-AFE4-3485-BADE-628C4468B057 slid base address 0x7ff816da4000, slide 0x16da4000

Command:          ghc
Path:             /Library/Apple/usr/libexec/oah/libRosettaRuntime
Architecture:     x86_64 (translated)
Parent:           Setup [54745] [unique pid 1545346]
Responsible:      iTerm2 [724]
PID:              54747
Time Since Fork:  530s

Duration:         10.00s
Steps:            1001 (10ms sampling interval)

Hardware model:   MacBookPro18,4
Active cpus:      10
HW page size:     16384
VM page size:     16384

Time Awake Since Boot: 477587s
Time Since Wake:  1696s

Fan speed:        0 rpm
Total CPU Time:   25.747s (69.8G cycles, 98.5G instructions, 0.71c/i)
Advisory levels:  Battery -> 2, User -> 2, ThermalPressure -> 0, Combined -> 2
Free disk space:  762.78 GB/926.35 GB, low space threshold 3072 MB

----------------------------------------
Heavy format: stacks are sorted by count
----------------------------------------

Process:          ghc [54747] [unique pid 1545348]
UUID:             CD33190D-E59E-34D3-8D36-4A5AF77A8859
Path:             /Library/Apple/usr/libexec/oah/libRosettaRuntime
Shared Cache:     B5084610-AFE4-3485-BADE-628C4468B057 slid base address 0x7ff816da4000, slide 0x16da4000
Architecture:     x86_64 (translated)
Parent:           Setup [54745] [unique pid 1545346]
Responsible:      iTerm2 [724]
UID:              501
Footprint:        213.60 MB
Time Since Fork:  530s
Num samples:      1001 (1-1001)
CPU Time:         18.465s (50.7G cycles, 48.0G instructions, 1.06c/i)
Note:             Suspended for 6 samples

  Thread 0x6e719c    DispatchQueue 140704613793240    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de44f66]
    1001  ??? [0x7ff8a7546940]
     *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
     *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e719d    Thread name "com.apple.rosetta.exceptionserver"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? (runtime + 18660) [0x7ff7ffbd68e4]
   *995   ??? (kernel.release.t6000 + 217788) [0xfffffe00079492bc]
   *6     ??? (kernel.release.t6000 + 217788) [0xfffffe00079492bc] (suspended)

  Thread 0x6e719e    1001 samples (1-1001)    priority 31 (base 31)
  1001  thread_start + 15 (libsystem_pthread.dylib + 8239) [0x7ff8170bd02f]
    1001  ??? [0x10de44f66]
      1001  ??? [0x7ff8a7546940]
       *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
       *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e719f    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x7006235fa9]
    1001  ??? [0x7ff8a7546940]
     *995   ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08]
     *6     ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08] (suspended)

  Thread 0x6e71a0    1001 samples (1-1001)    priority 31 (base 31)
  1001  <truncated backtrace>
    1001  ??? [0x7ff8a7546940]
     *1001  ??? (kernel.release.t6000 + 30712) [0xfffffe000791b7f8]
       *1001  ??? (kernel.release.t6000 + 1568628) [0xfffffe0007a92f74]
         *1001  ??? (kernel.release.t6000 + 6937348) [0xfffffe0007fb1b04]
           *1001  ??? (kernel.release.t6000 + 5999556) [0xfffffe0007eccbc4]
             *1001  ??? (kernel.release.t6000 + 5669360) [0xfffffe0007e7c1f0]
               *1001  ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
                 *995   ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8]
                 *6     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (suspended)

  Thread 0x6e71a1    Thread name "ghc_worker"    1001 samples (1-1001)    priority 0-31 (base 31)    cpu time 9.399s (26.8G cycles, 10.3G instructions, 2.60c/i)
  712   ??? [0x7ff8a78bfe50]
    705   <patched truncated backtrace>
      705   ??? [0x10de1d111] (running)
    7     <patched truncated backtrace>
      7     ??? [0x10de1d111]
       *6     ??? (kernel.release.t6000 + 657820) [0xfffffe00079b499c] (suspended)
       *1     ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
  182   <truncated backtrace>
    141   ??? [0x10de1d11a] (running)
    24    ??? [0x10de1d121] (running)
    13    ??? [0x10de1d11a]
     *11    ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
     *2     ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78]
       *2     ??? (kernel.release.t6000 + 308312) [0xfffffe000795f458] (running)
    4     ??? [0x10de1d10c] (running)
  107   ??? [0x10de1d10a]
    101   ??? [0x7ff8a7546940]
     *47    ??? (kernel.release.t6000 + 578512) [0xfffffe00079a13d0] (runnable)
     *26    ??? (kernel.release.t6000 + 30712) [0xfffffe000791b7f8]
       *17    ??? (kernel.release.t6000 + 1569120) [0xfffffe0007a93160]
         *16    ??? (kernel.release.t6000 + 1524396) [0xfffffe0007a882ac]
           *15    ??? (kernel.release.t6000 + 578292) [0xfffffe00079a12f4]
             *15    ??? (kernel.release.t6000 + 578068) [0xfffffe00079a1214] (running)
           *1     ??? (kernel.release.t6000 + 578192) [0xfffffe00079a1290]
             *1     ??? (kernel.release.t6000 + 502540) [0xfffffe000798eb0c] (running)
         *1     ??? (kernel.release.t6000 + 1524396) [0xfffffe0007a882ac] (running)
       *8     ??? (kernel.release.t6000 + 1567848) [0xfffffe0007a92c68] (running)
       *1     ??? (kernel.release.t6000 + 1568072) [0xfffffe0007a92d48]
         *1     ??? (kernel.release.t6000 + 1568072) [0xfffffe0007a92d48] (running)
     *14    ??? (kernel.release.t6000 + 69224) [0xfffffe0007924e68] (running)
     *11    ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78]
       *6     ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78] (running)
       *4     ??? (kernel.release.t6000 + 578568) [0xfffffe00079a1408]
         *3     ??? (kernel.release.t6000 + 578568) [0xfffffe00079a1408] (running)
         *1     ??? (kernel.release.t6000 + 502540) [0xfffffe000798eb0c] (running)
       *1     ??? (kernel.release.t6000 + 578540) [0xfffffe00079a13ec]
         *1     ??? (kernel.release.t6000 + 578776) [0xfffffe00079a14d8] (running)
     *2     ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
     *1     ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78] (running)
    5     ??? [0x7ff8a7546940] (running)
    1     swtch_pri + 10 (libsystem_kernel.dylib + 3010) [0x7ff817084bc2]
     *1     ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)

  Thread 0x6e73e3    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x70074b0003]
    1001  ??? [0x7ff8a7546940]
     *995   ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08]
     *6     ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08] (suspended)

  Thread 0x6e73e4    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  <truncated backtrace>
    1001  ??? [0x7ff8a7546940]
     *995   ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08]
     *6     ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08] (suspended)

  Thread 0x6e73e5    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x700732648b]
    1001  ??? [0x7ff8a7546940]
     *995   ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08]
     *6     ??? (kernel.release.t6000 + 5671432) [0xfffffe0007e7ca08] (suspended)

  Thread 0x6e73e6    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0xffffc83277000003]
    1001  ??? [0x10f87a9b8]
      1001  <patched truncated backtrace>
        1001  ??? [0x10de101a9]
          1001  dyld4::APIs::dlopen_from(char const*, int, void*) + 544 (dyld + 145826) [0x2033729a2]
            1001  dyld4::RuntimeState::notifyLoad(dyld3::Array<dyld4::Loader const*> const&) + 335 (dyld + 59273) [0x20335d789]
              1001  dyld4::RuntimeState::withNotifiersReadLock(void () block_pointer) + 45 (dyld + 44299) [0x203359d0b]
                1001  invocation function for block in dyld4::RuntimeState::notifyLoad(dyld3::Array<dyld4::Loader const*> const&) + 1023 (dyld + 60817) [0x20335dd91]
                  1001  -[OS_xpc_object dealloc] + 47 (libxpc.dylib + 20693) [0x7ff816dfb0d5]
                    1001  _objc_rootDealloc + 62 (libobjc.A.dylib + 48991) [0x7ff816f57f5f]
                      1001  objc_destructInstance + 113 (libobjc.A.dylib + 49114) [0x7ff816f57fda]
                        1001  _object_remove_assocations + 60 (libobjc.A.dylib + 49235) [0x7ff816f58053]
                          1001  ??? [0x7ff8a7546940]
                           *995   ??? (kernel.release.t6000 + 6022604) [0xfffffe0007ed25cc] (blocked by turnstile waiting for ghc [54747] [unique pid 1545348] thread 0x6e73e8)
                           *6     ??? (kernel.release.t6000 + 6022604) [0xfffffe0007ed25cc] (suspended, blocked by turnstile waiting for ghc [54747] [unique pid 1545348] thread 0x6e73e8)

  Thread 0x6e73e7    Thread name "ghc_worker"    1001 samples (1-1001)    priority 0-31 (base 31)    cpu time 9.066s (23.9G cycles, 37.7G instructions, 0.63c/i)
  908   ??? [0x10de30629]
    672   ??? [0x7ff8a7546940]
     *446   ??? (kernel.release.t6000 + 30712) [0xfffffe000791b7f8]
       *222   ??? (kernel.release.t6000 + 1567848) [0xfffffe0007a92c68] (running)
       *116   ??? (kernel.release.t6000 + 1568072) [0xfffffe0007a92d48]
         *114   ??? (kernel.release.t6000 + 1568072) [0xfffffe0007a92d48] (running)
         *1     current_proc + 108 (kernel.release.t6000 + 6953288) [0xfffffe0007fb5948] (running)
         *1     current_proc + 108 (kernel.release.t6000 + 6953288) [0xfffffe0007fb5948]
           *1     current_proc + 108 (kernel.release.t6000 + 6953288) [0xfffffe0007fb5948] (running)
       *86    ??? (kernel.release.t6000 + 1569120) [0xfffffe0007a93160]
         *70    ??? (kernel.release.t6000 + 1524396) [0xfffffe0007a882ac]
           *38    ??? (kernel.release.t6000 + 578192) [0xfffffe00079a1290]
             *23    ??? (kernel.release.t6000 + 578192) [0xfffffe00079a1290] (running)
             *15    ??? (kernel.release.t6000 + 502540) [0xfffffe000798eb0c] (running)
           *13    ??? (kernel.release.t6000 + 578224) [0xfffffe00079a12b0]
             *12    ??? (kernel.release.t6000 + 578224) [0xfffffe00079a12b0] (running)
             *1     ??? (kernel.release.t6000 + 1562128) [0xfffffe0007a91610]
               *1     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
                 *1     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
                   *1     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
           *7     ??? (kernel.release.t6000 + 578292) [0xfffffe00079a12f4]
             *7     ??? (kernel.release.t6000 + 578068) [0xfffffe00079a1214] (running)
           *7     ??? (kernel.release.t6000 + 578264) [0xfffffe00079a12d8] (running)
           *2     ??? (kernel.release.t6000 + 578264) [0xfffffe00079a12d8]
             *2     ??? (kernel.release.t6000 + 31424) [0xfffffe000791bac0]
               *2     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
                 *2     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
                   *2     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
           *2     ??? (kernel.release.t6000 + 578192) [0xfffffe00079a1290] (running)
           *1     ??? (kernel.release.t6000 + 578224) [0xfffffe00079a12b0] (running)
         *9     ??? (kernel.release.t6000 + 1569120) [0xfffffe0007a93160] (running)
         *3     ??? (kernel.release.t6000 + 1524444) [0xfffffe0007a882dc]
           *3     ??? (kernel.release.t6000 + 1524444) [0xfffffe0007a882dc] (running)
         *2     ??? (kernel.release.t6000 + 1524444) [0xfffffe0007a882dc] (running)
         *2     ??? (kernel.release.t6000 + 1524396) [0xfffffe0007a882ac] (running)
       *10    ??? (kernel.release.t6000 + 1568084) [0xfffffe0007a92d54]
         *10    ??? (kernel.release.t6000 + 1568084) [0xfffffe0007a92d54] (running)
       *8     ??? (kernel.release.t6000 + 1568084) [0xfffffe0007a92d54] (running)
       *4     ??? (kernel.release.t6000 + 1567848) [0xfffffe0007a92c68]
         *4     ??? (kernel.release.t6000 + 31424) [0xfffffe000791bac0]
           *4     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
             *4     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
               *4     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
     *93    ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78]
       *54    ??? (kernel.release.t6000 + 578540) [0xfffffe00079a13ec]
         *38    ??? (kernel.release.t6000 + 578776) [0xfffffe00079a14d8] (running)
         *15    ??? (kernel.release.t6000 + 578540) [0xfffffe00079a13ec] (running)
         *1     ??? (kernel.release.t6000 + 578776) [0xfffffe00079a14d8]
           *1     ??? (kernel.release.t6000 + 31424) [0xfffffe000791bac0]
             *1     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
               *1     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
                 *1     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
       *18    ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78] (running)
       *8     ??? (kernel.release.t6000 + 578540) [0xfffffe00079a13ec] (running)
       *5     ??? (kernel.release.t6000 + 578568) [0xfffffe00079a1408]
         *4     ??? (kernel.release.t6000 + 578568) [0xfffffe00079a1408] (running)
         *1     ??? (kernel.release.t6000 + 502540) [0xfffffe000798eb0c] (running)
       *4     ??? (kernel.release.t6000 + 578584) [0xfffffe00079a1418]
         *3     ??? (kernel.release.t6000 + 1581936) [0xfffffe0007a96370]
           *3     ??? (kernel.release.t6000 + 1567480) [0xfffffe0007a92af8] (running)
         *1     ??? (kernel.release.t6000 + 578584) [0xfffffe00079a1418] (running)
       *3     ??? (kernel.release.t6000 + 308312) [0xfffffe000795f458] (running)
       *1     ??? (kernel.release.t6000 + 578576) [0xfffffe00079a1410]
         *1     ??? (kernel.release.t6000 + 1562040) [0xfffffe0007a915b8]
           *1     ??? (kernel.release.t6000 + 1562128) [0xfffffe0007a91610]
             *1     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
               *1     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
                 *1     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
     *58    ??? (kernel.release.t6000 + 578512) [0xfffffe00079a13d0] (runnable)
     *40    ??? (kernel.release.t6000 + 69224) [0xfffffe0007924e68] (running)
     *22    ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
     *6     ??? (kernel.release.t6000 + 657820) [0xfffffe00079b499c] (suspended)
     *4     ??? (kernel.release.t6000 + 69224) [0xfffffe0007924e68]
       *3     ??? (kernel.release.t6000 + 31424) [0xfffffe000791bac0]
         *3     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
           *3     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
             *3     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
       *1     ml_set_interrupts_enabled + 52 (kernel.release.t6000 + 1587968) [0xfffffe0007a97b00]
         *1     ??? (kernel.release.t6000 + 307544) [0xfffffe000795f158]
           *1     ??? (kernel.release.t6000 + 525236) [0xfffffe00079943b4]
             *1     ??? (kernel.release.t6000 + 531624) [0xfffffe0007995ca8] (runnable)
     *3     ??? (kernel.release.t6000 + 69240) [0xfffffe0007924e78] (running)
    207   ??? [0x7ff8a7546940] (running)
    7     ??? [0x7ff8a754693c] (running)
    4     ??? [0x7ff8a7546910] (running)
    4     ??? [0x7ff8a75440e4] (running)
    3     ??? [0x7ff8a75468d0] (running)
    2     ??? [0x7ff8a7546900] (running)
    2     ??? [0x7ff8a7546578] (running)
    2     DYLD-STUB$$swtch_pri + 0 (libsystem_pthread.dylib + 39314) [0x7ff8170c4992] (running)
    2     swtch_pri + 10 (libsystem_kernel.dylib + 3010) [0x7ff817084bc2] (running)
    1     ??? [0x7ff8a7546574] (running)
    1     ??? [0x7ff8a75464a8] (running)
    1     ??? [0x7ff8a75440c8] (running)
  80    <truncated backtrace>
    61    ??? [0x10de30610] (running)
    3     ??? [0x10de30610]
     *3     ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
    3     ??? [0x10de305f7] (running)
    2     pthread_mutex_unlock + 0 (libsystem_pthread.dylib + 7602) [0x7ff8170bcdb2] (running)
    2     ??? [0x10de54e96] (running)
    2     ??? [0x10de305ec] (running)
    1     ??? [0x10de44f70] (running)
    1     ??? [0x10de30636] (running)
    1     ??? [0x10de30624] (running)
    1     ??? [0x10de305e1] (running)
    1     ??? [0x10de305c0] (running)
    1     ??? [0x10de3056d]
     *1     ??? (kernel.release.t6000 + 308296) [0xfffffe000795f448] (runnable)
    1     ??? [0x10de08a95] (running)
  7     ??? [0x10de305a0] (running)
  3     ??? [0x10de44273]
    2     clock_gettime + 184 (libsystem_c.dylib + 71538) [0x7ff816f9d772]
      1     _mach_boottime_usec + 116 (libsystem_c.dylib + 241884) [0x7ff816fc70dc]
        1     gettimeofday + 45 (libsystem_c.dylib + 38474) [0x7ff816f9564a]
          1     __commpage_gettimeofday_internal + 36 (libsystem_kernel.dylib + 8896) [0x7ff8170862c0]
            1     ??? [0x7ff8a754414c] (running)
      1     _mach_boottime_usec + 103 (libsystem_c.dylib + 241871) [0x7ff816fc70cf] (running)
    1     clock_gettime + 236 (libsystem_c.dylib + 71590) [0x7ff816f9d7a6] (running)
  2     ??? [0x10de08a9a]
    1     ??? [0x7ff8a75452f0] (running)
    1     pthread_mutex_lock + 13 (libsystem_pthread.dylib + 6519) [0x7ff8170bc977] (running)
  1     ??? [0x10de08ac5]
    1     pthread_mutex_unlock + 78 (libsystem_pthread.dylib + 7680) [0x7ff8170bce00] (running)

  Thread 0x6e73e8    Thread name "ghc_worker"    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x63870f000003]
    1001  ??? [0]
      1001  <patched truncated backtrace>
        1001  ??? [0x10b9f371e]
          1001  ??? [0x10b9fab7c]
            1001  vfork + 27 (libsystem_c.dylib + 280514) [0x7ff816fd07c2]
              1001  libSystem_atfork_prepare + 37 (libSystem.B.dylib + 5984) [0x7ff8222dd760]
                1001  dyld4::RuntimeState::takeLockBeforeFork() + 50 (dyld + 68720) [0x20335fc70]
                  1001  ??? [0x7ff8a7546940]
                   *995   ??? (kernel.release.t6000 + 6022604) [0xfffffe0007ed25cc] (blocked by turnstile waiting for ghc [54747] [unique pid 1545348] thread 0x6e73e6)
                   *6     ??? (kernel.release.t6000 + 6022604) [0xfffffe0007ed25cc] (suspended, blocked by turnstile waiting for ghc [54747] [unique pid 1545348] thread 0x6e73e6)

  Thread 0x6e73e9    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de44f66]
    1001  ??? [0x7ff8a7546940]
     *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
     *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e73ea    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de47d48]
    1001  ??? [0x10de44f66]
      1001  ??? [0x7ff8a7546940]
       *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
       *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e73eb    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de44f66]
    1001  ??? [0x7ff8a7546940]
     *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
     *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e73ec    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de44f66]
    1001  ??? [0x7ff8a7546940]
     *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
     *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Thread 0x6e73ed    1001 samples (1-1001)    priority 31 (base 31)
  1001  ??? [0x10de44f66]
    1001  ??? [0x7ff8a7546940]
     *995   psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18]
     *6     psynch_cvcontinue + 0 (pthread + 18008) [0xfffffe000a508a18] (suspended)

  Binary Images:
           0x10b361000 -        0x10b3bcfff  libRosettaRuntime                  <CD33190D-E59E-34D3-8D36-4A5AF77A8859>              /Library/Apple/usr/libexec/oah/libRosettaRuntime
           0x20334f000 -        0x2033cafff  dyld (940)                         <1A6AE033-9438-33C0-8077-988FD885250A>              /usr/lib/dyld
        0x7ff7ffbd2000 -     0x7ff7ffc11fff  runtime (254.5.3)                  <9F5D65BE-D8D0-3979-BB05-E651A67E785C>              /usr/libexec/rosetta/runtime
        0x7ff816df6000 -     0x7ff816e2cfff  libxpc.dylib (2235.40.11)          <900E1F8B-6333-3E4D-B64C-751264BB7223>              /usr/lib/system/libxpc.dylib
        0x7ff816f4c000 -     0x7ff816f88fff  libobjc.A.dylib (838)              <6B22EFE4-18CC-3551-90BA-D18236104790>              /usr/lib/libobjc.A.dylib
        0x7ff816f8c000 -     0x7ff817014fff  libsystem_c.dylib (1506.40.4)      <991F58B7-B4C0-3C3A-84A8-C9C571DE5A27>              /usr/lib/system/libsystem_c.dylib
        0x7ff817084000 -     0x7ff8170bafff  libsystem_kernel.dylib (8019.41.5) <12BD6F13-C452-35EE-9069-51BEFEF29F1A>              /usr/lib/system/libsystem_kernel.dylib
        0x7ff8170bb000 -     0x7ff8170c6fff  libsystem_pthread.dylib (485.40.4) <29A2750E-F31B-3630-8761-242A6BC3E99E>              /usr/lib/system/libsystem_pthread.dylib
        0x7ff8222dc000 -     0x7ff8222ddfff  libSystem.B.dylib (1311)           <234AB609-FE3D-38A2-9D1A-DB639349EB94>              /usr/lib/libSystem.B.dylib
   *0xfffffe0007914000 - 0xfffffe000816ffff  kernel.release.t6000 (8019.41.5)   <67BCB41B-BAA4-3634-8E51-B0210457E324>__TEXT_EXEC   /System/Library/Kernels/kernel.release.t6000
   *0xfffffe000a5043c0 - 0xfffffe000a50a45f  com.apple.kec.pthread 1.0 (1)      <F144B772-9DC5-3334-8143-2D4A673B01E6>__TEXT_EXEC   /System/Library/Extensions/pthread.kext/Contents/MacOS/pthread
Anton-Latukha commented 2 years ago

I plan to look into this in nearest days before doing the release.

There are two things to address before release, one of it is this one.


default.nix was constructed to use either Left: local nixpkgs channel, Right: pinned nixpkgs version.

So the first thing to look, if that time pin is set/used/passed.

I think not compiling Atom in old code states - is a related report, since that is a particilar infrastructural syndrome - be able to travel back with nix-build.

Do be honest, Haskell development is easier to do relying on Cabal, because Nixpkgs has constant design inconsistency with Hackage which are further exgregated by Nixpkgs designs, which requires constant overriding overhead. Instead of developing Haskell code - configuring Nix files. Especially at that time - there was no tooling to overcome that. So in limited human resources I simplified situation, using Cabal dev loop only & .nix package configuarations was checked to work at the times of CI runs & merges (hence using current Nixpkgs state during merge), build.sh sets & passes default into default.nix.

Anton-Latukha commented 2 years ago

Currently seems it was "always" present. (at least, an old bug). It is present in 0.12.0.1 version. One of the things that prevented the travel back in versions is hnix-store frivolous open bounds, saltine 0.2 released & changed the internal modules, which expectedly broke the hnix-store-core compilations. So I went back in time and made a number of Hackage revisions for hnix-store-core bounds. During the next lookup into/release of hnix-store, one of the things would be to set those bounds https://github.com/haskell-nix/hnix-store/issues/175.

Currently waiting for when Hackage would update with the new snapshot.

Anton-Latukha commented 2 years ago

Well, it goes beyond 0.9.1.

Anton-Latukha commented 2 years ago

Before 0.8.0.

Anton-Latukha commented 2 years ago

It is pre 0.7.1 at this point it essentially - it means it is before I become a maintainer.

Before, 0.6.1 - it is a long time ago.

Anton-Latukha commented 2 years ago

Syndrome is:

Works great:

cabal run hnix -- --check --expr '
                               let {
                                 x = "foo";
                                 y = "bar";
                               }
                               '
Up to date
Type of expression: [ Forall [ TV "a" ] (TVar (TV "a")) ]
rec {
  x = "foo";
  y = "bar";
  }.body⏎       

Referencing set - nope:

cabal run hnix -- --check --expr '
                               let {
                                 x = "foo";
                                 y = "bar";
                                 body = x + y;
                               }
                               '
Up to date
hnix: <<loop>>
runeksvendsen commented 2 years ago

@Anton-Latukha thank you for looking into this.

I did a bit of debugging. The <<loop>> occurs in the type inference stage inside Nix.Scope.lookupVarReader when Nix.Scope.lexicalScopes is evaluated for the current scope. I inserted some traceM statements to deduce this.

The following diff against 4321e7d6563ff9d8d15c056c4fabcd9f69bf798e

diff --git a/main/Main.hs b/main/Main.hs
index 378fa468..00f487bd 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -32,6 +32,7 @@ import           Prettyprinter           hiding ( list )
 import           Prettyprinter.Render.Text      ( renderIO )
 import qualified Repl
 import           Nix.Eval
+import qualified Debug.Trace

 main :: IO ()
 main =
@@ -124,7 +125,7 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
                 (liftIO . putStrLn . (<>) "Type of expression: " .
                   ppShow . maybeToMonoid . Map.lookup @VarName @[Scheme] "it" . coerce
                 )
-                $ HM.inferTop mempty $ curry one "it" $ stripAnnotation expr'
+                $ HM.inferTop mempty $ (\expr'' -> ("inferTop: " <> show expr) `Debug.Trace.trace` expr'') $ curry one "it" $ stripAnnotation expr'

                 -- liftIO $ putStrLn $ runST $
                 --     runLintM opts . renderSymbolic =<< lint opts expr
diff --git a/src/Nix/Scope.hs b/src/Nix/Scope.hs
index d9de14a3..70248725 100644
--- a/src/Nix/Scope.hs
+++ b/src/Nix/Scope.hs
@@ -10,6 +10,7 @@ import qualified Data.HashMap.Lazy             as M
 import qualified Text.Show
 import           Lens.Family2
 import           Nix.Expr.Types
+import qualified Debug.Trace

 --  2021-07-19: NOTE: Scopes can gain from sequentiality, HashMap (aka AttrSet) may not be proper to it.
 newtype Scope a = Scope (AttrSet a)
@@ -110,6 +111,11 @@ lookupVarReader
   -> m (Maybe a)
 lookupVarReader k =
   do
+    Debug.Trace.traceM $ "lookupVarReader: " <> show k
+    lexicalScopes' <- asks $ lexicalScopes @m . view hasLens
+    Debug.Trace.traceM $ "lexicalScopes length: " <> show (length lexicalScopes')
+    Debug.Trace.traceM $ "lexicalScopes: " <> show (lexicalScopes' :: [Scope a])
+
     mres <- asks $ scopeLookup k . lexicalScopes @m . view hasLens

     maybe

will produce this output:

$ cabal run hnix -- --check --expr '
                               let {
                                 x = 2;
                                 y = 1;
                                 body = x + y;
                               }
                               '
Up to date
lookupVarReader: VarName "x"
lexicalScopes length: 0
lexicalScopes: []
lookupVarReader: VarName "y"
lexicalScopes length: 0
lexicalScopes: []
lexicalScopes length: 0
lexicalScopes: []
lexicalScopes length: 0
lexicalScopes: []
inferTop: Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 2, sourceColumn = Pos 32}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 6, sourceColumn = Pos 33}}, annotated = NSelect Nothing (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 2, sourceColumn = Pos 36}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 6, sourceColumn = Pos 33}}, annotated = NSet Recursive [NamedVar (StaticKey (VarName "x") :| []) (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 3, sourceColumn = Pos 38}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 3, sourceColumn = Pos 39}}, annotated = NConstant (NInt 2)}))) (SourcePos {sourceName = "<string>", sourceLine = Pos 3, sourceColumn = Pos 34}),NamedVar (StaticKey (VarName "y") :| []) (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 4, sourceColumn = Pos 38}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 4, sourceColumn = Pos 39}}, annotated = NConstant (NInt 1)}))) (SourcePos {sourceName = "<string>", sourceLine = Pos 4, sourceColumn = Pos 34}),NamedVar (StaticKey (VarName "body") :| []) (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 41}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 46}}, annotated = NBinary NPlus (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 41}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 42}}, annotated = NSym (VarName "x")}))) (Fix (Compose (AnnUnit {annotation = SrcSpan {spanBegin = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 45}, spanEnd = SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 46}}, annotated = NSym (VarName "y")})))}))) (SourcePos {sourceName = "<string>", sourceLine = Pos 5, sourceColumn = Pos 34})]}))) (StaticKey (VarName "body") :| [])}))
lookupVarReader: VarName "x"
lexicalScopes length: 1
hnix: <<loop>>

So first a pass runs prior to inferTop which uses lookupVarReader without issues to produce the NExprLoc value. Then, inferTop runs and ultimate calls lookupVarReader for the x variable. Here, the length of lexicalScopes is equal to 1 and it crashes with a <<loop>> when trying to show the lexicalScopes value.

Anton-Latukha commented 2 years ago

Looked into the lookupVarReader code semantically.

So far not found the cause, but the process definitely approaches closer.

If to use only the dynamic scope search - the process terminates:

cabal run hnix -- --check --expr '
                                                                   let {
                                                                     x = "foo";
                                                                     y = "bar";
                                                                     body = x + y;
                                                                   }
                                                                   '
...
Type of expression: [ Forall [ TV "a" ] (TVar (TV "a")) ]

rec {
  x = "foo";
  y = "bar";
  body = x + y;
  }.body

Soon would ship the simplified version of the code & it would be easier to look further. Maybe/probably in asks $ view hasLens for lexical scope the lens happens to be an infinite one, that is a guess, but since lexicalScopes is simple getter & body is involved in the lens...