Skip to content

nimsuggest2: thin proxy that runs each query as a one-shot IC process (PoC) - #26494

Draft
nitely wants to merge 30 commits into
nim-lang:develfrom
nitely:ns_nif_spawn
Draft

nitely wants to merge 30 commits into
nim-lang:develfrom
nitely:ns_nif_spawn

Conversation

@nitely

@nitely nitely commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Based on #26439 (comment)

Adds nimsuggest2: a thin, long-lived proxy compatible with nimsuggest's socket protocol (v4). Each query runs nimsuggest2 --one-shot in a fresh process. That process loads the project's modules from the IC NIFs built by the new nim ns command, and compiles the queried file as a regular module (not as main module). changed reruns nim ns, which only rebuilds what changed.

Most of the code is in nsoneshot.nim which is a "cleaned up" copy of nimsuggest.nim

Compared to nimsuggest

  • Each query runs in a fresh process.
  • Startup is 0.12 s with fresh NIFs (warm ic), instead of an initial compile of the whole project.
  • Any file is the root: the queried file is compiled like an import, never as the main module.
  • A one-shot peaks at 155–360 MB (ORC); tested in nim-lang/langserver.
  • Saved-file highlight/def/use/dus are answered from the NIFs without compiling. Fallback to compiling unsaved file (~2x-8x slower IIRC).
  • Same command line and protocol. v4 only; no --maxMemory, no exception inlay hints, no outline.
  • Uses ORC.

Compared to nim track

  • supports all nimsuggests commands (sug, con, chk, chkFile, highlight, outline2, type, declaration, expand, inlayHints, globalSymbols, …), on unsaved buffers too, with full symbols, so hover works.
  • Both use the same IC frontend: nim ns is nim track's build step plus a report of which modules it checked.

Performance is sub-second for every query on langserver repository.

this is just a PoC.

@Araq

Araq commented Oct 17, 2026

Copy link
Copy Markdown
Member

this is just a PoC.

No, it's the future! :D

@nitely
nitely force-pushed the ns_nif_spawn branch 2 times, most recently from 06519a9 to d6ed144 Compare October 28, 2026 05:51
Araq pushed a commit that referenced this pull request Nov 11, 2026
`materializeReexportedModule` created a new module symbol every time an
interface referenced a re-exported module (import x; export x). Projects
that re-export heavily, like nimbus, end up with thousands of copies per
module. This caches them by module and name. `icQualIfaces` is replaced
by a private `icQualModules`.

nimbus-eth2 beacon_chain/nimbus_beacon_node.nim, cold nim ic
--parallelBuild:3:
  | Metric | devel | This PR |
  |:--|--:|--:|
  | Wall time | 20:16 | 16:02 |
  | Peak RSS | 6.5 GB | 1.6 GB |
  | `.s.bif` size | 919 MB | 619 MB |
  | All NIFs | 2,123 MB | 1,522 MB |

Split from #26494
Araq pushed a commit to nim-lang/nimony that referenced this pull request Nov 11, 2026
Add `-k` / `--keepgoing` to `nifmake run`. When a command fails, nifmake
keeps building everything that doesn't depend on it, instead of stopping
at the first failure. The commands that depend on the failed one are
skipped, and the run still exits non-zero.

Without the flag, behavior is unchanged.

`failed` now also flushes stdout; the `nifmake: command failed` line
would otherwise stay buffered while later jobs write their output.

`tests/nifmake/setup.nim` adds a `keepgoing` scenario and an `after` job
that depends only on the job still running when the other one fails:
- with `--keepgoing`, `after` runs (`total=3`) and the failed job's
dependent doesn't;
- without it, `after` isn't launched (`total=2`), which also covers the
existing stop-after-failure behavior.

Needed by [nimsuggest2](nim-lang/Nim#26494) so
an unknown file/root that fails to compile does not break the rest of
roots.
@Araq

Araq commented Nov 12, 2026

Copy link
Copy Markdown
Member

@nitely can we base/merge this with nim track?

Araq pushed a commit that referenced this pull request Nov 12, 2026
Saving a nim.cfg without changing it made every later nim ic and nim
track run start the nim icconfig producer again, until the content
changed.

The precompiled config is written only when its content changes, so its
mtime stayed older than the saved source, and sourcesChanged compared
against that mtime. The driver now sets the config's mtime to when the
producer started, after every producer run. That also catches a config
source saved while the producer was running.

Split from #26494
@nitely

nitely commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@Araq maybe it would make sense for nim track to simply run nimsuggest2 --one-shot, then you gain sug, etc. I think the main issue is nimsuggest2 requires -d:nimsuggest, so nimsuggest2 --one-shot cannot be replaced by nim track. Also, nim track shares ic cache and treats root as main module (in nimsuggest2 isMainModule is always false, but a flag could be added to make it true).

@Araq

Araq commented Nov 13, 2026

Copy link
Copy Markdown
Member

nim track to simply run nimsuggest2 --one-shot

Works for me too.

- works the same as before for single project file
- extra projects are loaded with their config instead of the main project config; if they have one
- unknown files are resolved to the right project
- fix find all usages and rename
Araq pushed a commit that referenced this pull request Nov 28, 2026
…info (#26828)

Under `nim ic`, fields of a generic instance created in another module
get line info `<module>(0, 0)`. Only `loadSym` set `infoImpl`; fields
loaded through `loadSymFromCursor` never got it.

Split from #26494

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants