Recursion bug due to module.build() connection tracing
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start at Module.build() and the _checkPortConnectionsRecursively entry point, then reproduce the cycle with the test case shown in the issue. Add a regression test for the cyclic hierarchy and verify that build() reports InvalidHierarchyException for the bad parent-to-child connection instead of StackOverflow.
Written by the indexing model from the issue text.
Description
Describe the bug
With some module miswirings we can get a StackOverflow due to infinite recursion.
To Reproduce
Run the following test:
import 'package:rohd/rohd.dart';
import 'package:test/test.dart';
class EmptyModule extends Module {
EmptyModule({super.name});
}
class RecursivePortCheckRepro extends Module {
RecursivePortCheckRepro() : super(name: 'top') {
final driver = Logic();
final topA = addInput('a', driver);
final child = EmptyModule(name: 'child');
final childA = child.addInput('a', topA);
// The `and()` avoids Logic's immediate direct self-connection rejection
// while closing the signal graph.
driver <= childA.and();
}
}
void main() {
test('discovers a cyclic hierarchy', () async {
await expectLater(
RecursivePortCheckRepro().build(),
throwsA(isA<InvalidHierarchyException>()),
);
});
}
Expected behavior
An error reported on the bad connection in the parent to a child Logic.
Actual behavior
StackOverflow
Additional: Dart SDK info
No response
Additional: pubspec.yaml
Additional: Context
The simplest fix would look like:
void _checkPortConnectionsRecursively({
Set<Module>? visited,
}) {
final marked = visited ?? <Module>{};
// Mark before descending. This breaks cycles such as top -> child -> top.
if (!marked.add(this)) {
return;
}
_checkPortConnections();
for (final subModule in _subModules) {
subModule._checkPortConnectionsRecursively(visited: marked);
}
}
- Dominant language
- Dart
- Stars
- 489
- Forks
- 88
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from intel/rohd
-
documentation enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
ROHD linter Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
bug
Difficulty 5/5 Over a week Newbie friendliness 45/100
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
code quality good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Suwayomi/Suwayomi-Tsumiru#479 ·
-
Build Failure: agora_rtc_engine compiled against android-31 while dependencies require android-34+ Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
conceptadev/noir#95 ·