HaxeFoundation / HaxeFoundation/haxe
[cpp] Infinite loop in compiler when inheriting from cpp.Pointer
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```haxe
// MyPointer.hx
class MyPointer extends cpp.Pointer {}
```
```hxml
# build.hxml
MyPointer
--cpp out
```
This has always generated broken code, however, it has only started triggering an infinite loop since: 145e55f0c007498513ef4024fb2f963fb95501f6.
Prior to that change, it seems ids didn't get added for extern classes, however, now they are added. Since `cpp.ConstPointer` and `cpp.Pointer` both point to the same native type, the same id is added twice, which breaks an assumption made by this dump_classes function and causes the code to loop forever.
https://github.com/HaxeFoundation/haxe/blob/aa3ecc55029f14444960b4b1b0818a0fdb6082d9/src/generators/cpp/gen/cppGenClassImplementation.ml#L372-L388
@Aidan63 Do you think we should exclude @:nativeGen and extern classes from the id generation?
Contributor guide
Research direction
Start with the MyPointer.hx and build.hxml reproducer, then inspect dump_classes in src/generators/cpp/gen/cppGenClassImplementation.ml at the linked lines. Trace how cpp.Pointer and cpp.ConstPointer receive duplicate ids and confirm the infinite loop. Done means the reproducer no longer loops and the id-generation behavior for extern or @:nativeGen classes is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100