-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
function_cache
garbage collection bug (#6555)
## Description Fixes a bug that would crash the language server when a function node was part of the AST. #5967 added a function cache to the `QueryEngine`. Garbage collection needed to be called on this otherwise it returns references to types that have been cleared from the other engines during garbage collection. In the future, any other nodes that we decide to cache need to have GC applied to them or we will end up crashing the language server on the first key-pressed event. I've also removed the gc_frequency setting and now run GC on each keystroke. Without doing this, the spans stored in the TokenMap and what was returned from the compiler were falling out of sync. This ensures that everything is always up to date and the correct spans are used. closes #5260 Finally, I've added a `launch.json` that allows for attaching `lldb` to a live running `forc-lsp` process. This was a pretty cruical step for tracking down this bug so would be nice to have it easily accessible for future debugging sessions. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
- Loading branch information
1 parent
e82c72b
commit 1305b24
Showing
9 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Configuration for debugging the Sway Language Server (forc-lsp) | ||
// Usage instructions: | ||
// 1. Ensure you've built forc-lsp with debug symbols: | ||
// cargo build -p forc-lsp | ||
// 2. Install the debug version: | ||
// cargo install --path ./forc-plugins/forc-lsp --debug | ||
// 3. Open your Sway project in a separate VSCode window (this starts forc-lsp) | ||
// 4. In the forc-lsp project window, set breakpoints in the code | ||
// 5. Go to Run and Debug view, select "Attach to forc-lsp", and start debugging | ||
// 6. When prompted, select the forc-lsp process | ||
// 7. Debug forc-lsp as it responds to actions in your Sway project | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "attach", | ||
"name": "Attach to forc-lsp", | ||
"pid": "${command:pickProcess}", | ||
"program": "${env:HOME}/.cargo/bin/forc-lsp" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
sway-lsp/tests/fixtures/garbage_collection/minimal_script/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
target |
8 changes: 8 additions & 0 deletions
8
sway-lsp/tests/fixtures/garbage_collection/minimal_script/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "minimal_script" | ||
implicit-std = false | ||
|
||
[dependencies] |
14 changes: 14 additions & 0 deletions
14
sway-lsp/tests/fixtures/garbage_collection/minimal_script/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
script; | ||
|
||
struct MyStruct { | ||
field1: u16, | ||
} | ||
|
||
fn func(s: MyStruct) -> u16 { | ||
s.field1 | ||
} | ||
|
||
fn main() { | ||
let x = MyStruct { field1: 10 }; | ||
let y = func(x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters