Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang: parse nix file using libexpr on document open #3

Closed
wants to merge 1 commit into from

Conversation

inclyc
Copy link
Member

@inclyc inclyc commented May 11, 2023

No description provided.

@inclyc inclyc marked this pull request as draft May 11, 2023 03:43
@inclyc inclyc changed the base branch from main to lsp/doc-sync May 11, 2023 03:43
try {
State->parseExprFromFile(File.str());
} catch (const nix::ParseError &PE) {
lspserver::elog("got nix parse error! {0}", PE.msg());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we can catch nix exceptions & retrieve backtrace in this exception (provided by nix itself).

@@ -44,6 +56,20 @@ void Server::onDocumentDidOpen(
const std::string &Contents = Params.textDocument.text;

addDocument(File, Contents, encodeVersion(Params.textDocument.version));
lspserver::elog("nix settings: {0}", nix::settings.storeUri.get());
auto NixStore = nix::openStore();
auto State = std::make_unique<nix::EvalState>(nix::Strings(), NixStore);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, this statement is throwing exceptions in EvalState constructor?

@@ -9,10 +9,6 @@

int main() {
std::error_code EC;
auto DebugOut = llvm::raw_fd_ostream("/tmp/nixd.out", EC,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we have initialized with the VSCode extension. So logging into stderr could be transferred into extension outputs. So delete hard-coded log file. (This should be another patch though)

@inclyc inclyc requested a review from junaire May 11, 2023 03:48
Base automatically changed from lsp/doc-sync to main May 12, 2023 10:10
@inclyc inclyc closed this May 12, 2023
@inclyc
Copy link
Member Author

inclyc commented May 12, 2023

We need to update the build system to include config.h. Otherwise record declarations are different from "nix vendored" version.

@inclyc inclyc deleted the lang/content branch May 13, 2023 08:22
inclyc pushed a commit that referenced this pull request Apr 21, 2024
While bumping my system flake I ran into a test failing due to an
out-of-bounds access. It got caught by `_GLIBCXX_ASSERTIONS`. I guess
the not-so-recent
[bump](https://www.github.com/NixOS/nixpkgs/pull/298047) of meson in
nixpkgs brought in this
[commit](https://www.github.com/mesonbuild/meson/pull/12683) from meson
1.4.0.

Here's the failing test logs and a backtrace:

```bash
nixd-nightly> >>> MALLOC_PERTURB_=222 LD_LIBRARY_PATH=/build/3gwj8jwd4ypvcahxqv3cn2fq617fm7v2-source/build/libnixbc:/build/3gwj8jwd4ypvcahxqv3cn2fq617fm7v2-source/build/libnixf:/build/3gwj8jwd4ypvcahxqv3cn2fq617fm7v2-source/build/libbc ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 /build/3gwj8jwd4ypvcahxqv3cn2fq617fm7v2-source/build/libnixf/unit-libnixf-parse
nixd-nightly>  ✀
nixd-nightly> stdout:
nixd-nightly> Running main() from /build/source/googletest/src/gtest_main.cc
nixd-nightly> [==========] Running 90 tests from 2 test suites.
nixd-nightly> [----------] Global test environment set-up.
nixd-nightly> [----------] 15 tests from LexerTest
nixd-nightly> [ RUN      ] LexerTest.Integer
nixd-nightly> stderr:
nixd-nightly> /nix/store/NN152MGPDFCW92B3B03G9KMNLPD9JRIS-gcc-13.2.0/include/c++/13.2.0/string_view:258: constexpr const std::basic_string_view<_CharT, _Traits>::value_type& std::basic_string_view<_CharT, _Traits>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; const_reference = const char&; size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
```

lldb backtrace:
```c++
(lldb) process launch --environment LD_LIBRARY_PATH=/home/xokdvium/Work/Programming/nixd/build/libnixf:/home/xokdvium/Work/Programming/nixd/build/libbc:/home/xokdvium/Work/Programming/nixd/build/libnixbc:/nix/store/fivm0vvpkfm933fd5gqj3dzni0pp50cg-pipewire-1.0.4-jack/lib ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 MALLOC_PERTURB_=239 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1
Process 433026 launched: '/home/xokdvium/Work/Programming/nixd/build/libnixf/unit-libnixf-parse' (x86_64)
Running main() from /build/source/googletest/src/gtest_main.cc
[==========] Running 90 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 15 tests from LexerTest
[ RUN      ] LexerTest.Integer
/nix/store/NN152MGPDFCW92B3B03G9KMNLPD9JRIS-gcc-13.2.0/include/c++/13.2.0/string_view:258: constexpr const std::basic_string_view<_CharT, _Traits>::value_type& std::basic_string_view<_CharT, _Traits>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; const_reference = const char&; size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
Process 433026 stopped
* thread #1, name = 'unit-libnixf-pa', stop reason = signal SIGABRT
    frame #0: 0x00007ffff7abfefc libc.so.6`__pthread_kill_implementation + 268
libc.so.6`__pthread_kill_implementation:
->  0x7ffff7abfefc <+268>: movl   %eax, %ebx
    0x7ffff7abfefe <+270>: negl   %ebx
    0x7ffff7abff00 <+272>: cmpl   $0xfffff000, %eax         ; imm = 0xFFFFF000
    0x7ffff7abff05 <+277>: movl   $0x0, %eax
(lldb) bt
* thread #1, name = 'unit-libnixf-pa', stop reason = signal SIGABRT
  * frame #0: 0x00007ffff7abfefc libc.so.6`__pthread_kill_implementation + 268
    frame #1: 0x00007ffff7a6fe86 libc.so.6`raise + 22
    frame #2: 0x00007ffff7a58935 libc.so.6`abort + 215
    frame #3: 0x00007ffff7d289fe libstdc++.so.6`std::__glibcxx_assert_fail(char const*, int, char const*, char const*) + 94
    frame #4: 0x00007ffff7f79f60 libnixf.so`std::basic_string_view<char, std::char_traits<char>>::operator[](this=<unavailable>, __pos=<unavailable>) const at string_view:258:2
    frame #5: 0x00007ffff7f782d6 libnixf.so`nixf::Lexer::consumeManyOf(std::basic_string_view<char, std::char_traits<char>>) [inlined] nixf::Lexer::peekUnwrap(this=0x00007fffffff73b0) const at Lexer.h:113:64
    frame #6: 0x00007ffff7f782ca libnixf.so`nixf::Lexer::consumeManyOf(this=0x00007fffffff73b0, Chars=<unavailable>) at Lexer.cpp:57:33
    frame #7: 0x00007ffff7f79258 libnixf.so`nixf::Lexer::lexNumbers() [inlined] nixf::Lexer::consumeManyDigits(this=0x00007fffffff73b0) at Lexer.h:81:25
    frame #8: 0x00007ffff7f7923f libnixf.so`nixf::Lexer::lexNumbers(this=0x00007fffffff73b0) at Lexer.cpp:195:30
    frame #9: 0x00007ffff7f79587 libnixf.so`nixf::Lexer::lex(this=0x00007fffffff73b0) at Lexer.cpp:471:15
    frame #10: 0x0000000000408a77 unit-libnixf-parse`(anonymous namespace)::LexerTest_Integer_Test::TestBody(this=0x00000000004844b0) const at Lexer.cpp:32:21
    frame #11: 0x00007ffff7f0625d libgtest.so.1.14.0`void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) + 77
    frame #12: 0x00007ffff7eed06e libgtest.so.1.14.0`testing::Test::Run() + 206
    frame #13: 0x00007ffff7eed225 libgtest.so.1.14.0`testing::TestInfo::Run() + 405
    frame #14: 0x00007ffff7eed457 libgtest.so.1.14.0`testing::TestSuite::Run() + 519
    frame #15: 0x00007ffff7efc9e7 libgtest.so.1.14.0`testing::internal::UnitTestImpl::RunAllTests() + 1143
    frame #16: 0x00007ffff7eed65b libgtest.so.1.14.0`testing::UnitTest::Run() + 123
    frame #17: 0x00007ffff7f230c0 libgtest_main.so.1.14.0`main + 64
    frame #18: 0x00007ffff7a5a10e libc.so.6`__libc_start_call_main + 126
    frame #19: 0x00007ffff7a5a1c9 libc.so.6`__libc_start_main@@GLIBC_2.34 + 137
    frame #20: 0x00000000004073a5 unit-libnixf-parse`_start + 37
```

Maybe it's a good idea to bump nixpkgs for the new default meson
behavior
or enable stdlib assertions with bounds-checking explicitly?
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.

None yet

1 participant