-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect infinite recursions in
nickel doc
This commit fixes an issue where legit recursive configurations cause infinite recursion when trying to extract their documentation. Indeed, `nickel doc` calls to `eval_record_spine`, which is unable to detect loops that span multiple evaluation step (an evaluation step is evaluating one field to a weak head normal form). This commit changes `eval_record_spine` and related methods to lock (in practice just flip a bit in the thunk's state) the active thunks, that is the thunks of parents of the field that we are currently evaluating. If we ever come across a thunk that is already locked, the field is left unevaluated, avoiding infinite recursion.
- Loading branch information
Showing
7 changed files
with
216 additions
and
38 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,11 @@ | ||
# capture = 'stdout' | ||
# command = ['doc', '--stdout'] | ||
|
||
# Regression test for https://github.com/tweag/nickel/issues/1967 (`nickel doc` | ||
# shouldn't overflow the stack on recursive data) | ||
{ | ||
Recursive = { | ||
foo | Number, | ||
bar | Recursive | optional | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
cli/tests/snapshot/inputs/docs/recursive_false_positive.ncl
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,12 @@ | ||
# capture = 'stdout' | ||
# command = ['doc', '--stdout'] | ||
|
||
# Companion test for the `recursive` regression test | ||
# Check that the infinite recursion detection of `nickel doc` doesn't have | ||
# obvious false positive | ||
{ | ||
outer = { | ||
mid = { inner | doc "this is inner" }, | ||
z | doc "this is z" = outer.mid, | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
cli/tests/snapshot/snapshots/snapshot__doc_stdout_recursive.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,13 @@ | ||
--- | ||
source: cli/tests/snapshot/main.rs | ||
expression: out | ||
--- | ||
# `Recursive` | ||
|
||
## `bar` | ||
|
||
- `bar | Recursive` | ||
|
||
## `foo` | ||
|
||
- `foo | Number` |
19 changes: 19 additions & 0 deletions
19
cli/tests/snapshot/snapshots/snapshot__doc_stdout_recursive_false_positive.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,19 @@ | ||
--- | ||
source: cli/tests/snapshot/main.rs | ||
expression: out | ||
--- | ||
# `outer` | ||
|
||
## `mid` | ||
|
||
### `inner` | ||
|
||
this is inner | ||
|
||
## `z` | ||
|
||
this is z | ||
|
||
### `inner` | ||
|
||
this is inner |
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
Oops, something went wrong.