-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix infinite loops with recursive types.
Closes #1867 There are two different cases where infinite loops happen with recursive types. First, a type may reference itself (`type Data = Data`). Second, a type may reference itself inside some other type (`type Data = vector<Data>`). The first is fixed with a recursion limit. Since the type simply cannot resolve, it doesn't get anywhere near codegen. You could detect cycles, but that introduces some extra overhead and complexity that shouldn't be needed in a "simple" function. The second is fixed with an ad-hoc "occurs" check in type unification. That just detects cycles and aborts if one is present. This could be placed at some other place in the "resolve until convergence" loop, but it seems best put closest to the source of the issue.
- Loading branch information
1 parent
cd4bde3
commit cdd66ee
Showing
6 changed files
with
43 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. | ||
[error] <...>/recursive.hlt:6:15-6:20: type Direct cannot be resolved by its name | ||
[error] <...>/recursive.hlt:7:19-7:40: Invalid cycle detected in type | ||
[error] <...>/recursive.hlt:8:17-8:32: Invalid cycle detected in type | ||
[error] <...>/recursive.hlt:10:14-10:19: type Second cannot be resolved by its name | ||
[error] <...>/recursive.hlt:11:15-11:19: type First cannot be resolved by its name | ||
[error] hiltic: aborting after errors |
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 @@ | ||
# @TEST-EXEC-FAIL: ${HILTIC} -p %INPUT > output 2>&1 | ||
# @TEST-EXEC: btest-diff output | ||
|
||
module Test { | ||
|
||
type Direct = Direct; | ||
type Referenced = strong_ref<Referenced>; | ||
type InVector = vector<InVector>; | ||
|
||
type First = Second; | ||
type Second = First; | ||
|
||
} |