-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add a recursion limit to background evaluation #1878
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -943,11 +943,14 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> { | |
/// fields and array elements, we keep evaluating subsequent elements even if one | ||
/// fails. | ||
/// - We only return the accumulated errors; we don't return the eval'ed term. | ||
pub fn eval_permissive(&mut self, rt: RichTerm) -> Vec<EvalError> { | ||
/// - We support a recursion limit, to limit the number of times we recurse into | ||
/// arrays or records. | ||
pub fn eval_permissive(&mut self, rt: RichTerm, recursion_limit: u64) -> Vec<EvalError> { | ||
fn inner<R: ImportResolver, C: Cache>( | ||
slf: &mut VirtualMachine<R, C>, | ||
acc: &mut Vec<EvalError>, | ||
rt: RichTerm, | ||
recursion_limit: u64, | ||
) { | ||
let pos = rt.pos; | ||
match slf.eval(rt) { | ||
|
@@ -966,7 +969,9 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> { | |
attrs.pending_contracts.iter().cloned(), | ||
t.pos, | ||
); | ||
inner(slf, acc, value_with_ctr); | ||
if let Some(r) = recursion_limit.checked_sub(1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: if we test at the very beginning of the function that |
||
inner(slf, acc, value_with_ctr, r) | ||
} | ||
} | ||
} | ||
Term::Record(data) => { | ||
|
@@ -977,7 +982,9 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> { | |
field.pending_contracts.iter().cloned(), | ||
v.pos, | ||
); | ||
inner(slf, acc, value_with_ctr); | ||
if let Some(r) = recursion_limit.checked_sub(1) { | ||
inner(slf, acc, value_with_ctr, r) | ||
} | ||
} else { | ||
acc.push(EvalError::MissingFieldDef { | ||
id: *id, | ||
|
@@ -993,7 +1000,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> { | |
} | ||
} | ||
let mut ret = Vec::new(); | ||
inner(self, &mut ret, rt); | ||
inner(self, &mut ret, rt, recursion_limit); | ||
ret | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### /diagnostics-recursion.ncl | ||
let rec foo = { bar = foo } in | ||
[ | ||
foo, | ||
foo.bar.bar.bar.bar.bar.baz | ||
] | ||
### diagnostic = ["file:///diagnostics-recursion.ncl"] |
8 changes: 8 additions & 0 deletions
8
lsp/nls/tests/snapshots/main__lsp__nls__tests__inputs__diagnostics-recursion.ncl.snap
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 @@ | ||
--- | ||
source: lsp/nls/tests/main.rs | ||
expression: output | ||
--- | ||
(file:///diagnostics-recursion.ncl, 0:14-0:27: this record lacks the field `baz`) | ||
(file:///diagnostics-recursion.ncl, 3:2-3:29: missing field `baz` | ||
Did you mean `bar`?) | ||
(file:///diagnostics-recursion.ncl, 3:2-3:29: this requires the field `baz` to exist) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: should we use
usize
instead ofu64
? I guess in practiceu16
is already amply sufficient, but you might prefer to use a word-aligned value. Usingu64
sounds like we need the guarantee to have larger values thanu32::MAX
.