starkware-libs / cairo

Cairo is the first Turing-complete language for creating provable programs for general computation.
Apache License 2.0
1.6k stars 495 forks source link

LS: Crashes of language server with corelib mismatch #6420

Closed Arcticae closed 2 weeks ago

Arcticae commented 1 month ago

Bug Report

Cairo version:

2.7.1

Current behavior: with cubit="1.3.0" dep and scarb = "2.7.1" the LS seems to crash in the corelib resolving stage (on goto/opening cubit's files only).

Scarb cache clean + restart does not help (neither does removing it manually)

Example Error message:

Error - 16:17:26] Request textDocument/semanticTokens/full failed.
  Message: Internal error
  Code: -32603 
thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cairo-lang-semantic-2.7.1/src/corelib.rs:703:32:
Core module `core` is missing an use item for trait `NumericLiteral`.
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: cairo_lang_semantic::corelib::get_core_trait
   3: cairo_lang_semantic::expr::inference::Inference::finalize_without_reporting
   4: cairo_lang_semantic::expr::inference::Inference::finalize
   5: cairo_lang_semantic::items::trt::trait_generic_params_data
   6: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   7: <DB as cairo_lang_semantic::db::SemanticGroup>::trait_generic_params_data
   8: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   9: <DB as cairo_lang_semantic::db::SemanticGroup>::priv_trait_declaration_data
  10: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  11: <DB as cairo_lang_semantic::db::SemanticGroup>::trait_resolver_data
  12: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  13: <DB as cairo_lang_semantic::db::SemanticGroup>::priv_trait_function_generic_params_data
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: <DB as cairo_lang_semantic::db::SemanticGroup>::priv_trait_function_declaration_data
  16: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  17: <DB as cairo_lang_semantic::db::SemanticGroup>::trait_function_resolver_data
  18: cairo_lang_semantic::db::get_resolver_data_options
  19: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  20: <DB as cairo_lang_semantic::db::SemanticGroup>::lookup_resolved_generic_item_by_ptr::__shim
  21: cairo_lang_language_server::find_definition
  22: cairo_lang_language_server::ide::hover::render::definition::definition
  23: cairo_lang_language_server::ide::hover::hover
  24: <cairo_lang_language_server::Backend as tower_lsp::LanguageServer>::hover::{{closure}}
  25: tower_lsp::jsonrpc::router::Router<S,E>::method::{{closure}}::{{closure}}::{{closure}}
  26: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
  27: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
  28: <tower_lsp::service::LspService<S> as tower_service::Service<tower_lsp::jsonrpc::request::Request>>::call::{{closure}}
  29: cairo_lang_language_server::start_with_tricks::{{closure}}
  30: cairo_lang_language_server::start_with_tricks
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
   0.709173209s DEBUG hover{uri=file:///Users/timelock/Library/Caches/com.swmansion.scarb/registry/src/scarbs.xyz-9djtpev4jug5q/cubit-1.3.0/src/f64/types/fixed.cairo}: cairo_lang_language_server::ide::hover: close time.busy=2.09ms time.idle=1.96µs

Upgrading to 2.8.0 solves this issue Expected behavior:

We should propose a solution or feasible workaround for this, or at least try to figure out what went wrong so this doesn't repeat itself in the future.

Steps to reproduce:

Setup explained above, generate a project, add

cubit = "1.3.0" 

to Scarb.toml deps

then in the code:

use cubit::f64::FixedTrait;
// ...
    let one_ln = FixedTrait::ONE().ln();
    one_ln.abs();

And try "goto" on the FixedTrait

mkaput commented 1 month ago

Check if this is fixed by #6395