r/Compilers • u/ibuki420 • Sep 10 '26
An experimental C-like language with a different approach to memory safety (no GC, no borrow checker)
I wanted something that feels as simple as C while making memory bugs fail predictably instead of turning into undefined behavior.
That's why I started building hc2.
hc2 is a small experimental programming language with runtime-checked pointers. Every pointer carries its bounds, mutability, and allocation it belongs to. Out-of-bounds accesses, use-after-free trap immediately instead of silently corrupting memory. The cost is a few extra instructions per memory access.
There is no GC, no borrow checker, and no lifetime annotations. Rather than preventing these bugs at compile time, hc2 detects them when they occur and turns undefined behavior into runtime failures.
I'd like to hear your thoughts and feedback.
GitHub: https://github.com/hc2lang/hc2
66
u/FloweyTheFlower420 Sep 10 '26
thanks claude, but also -fsanitize=address
60
u/Yoolainna Sep 10 '26
>first commit is +1,547,427 changes
no thanks
26
u/vmcrash Sep 10 '26
C is not very easy.
Better than nothing, but I'd much rather prefer a language that complains already at compile time, because fixing bugs later is much more expensive.
11
u/jesseschalken Sep 10 '26
Isn't this basically Fil-C or ASAN?
10
u/particlemanwavegirl Sep 10 '26
So you may only be able to detect some memory bugs by fuzzing? No offense but personally I think compile time checks seem like less trouble.
9
u/TheChief275 Sep 10 '26
I've never found anything as ugly as capitalized short integer names. Holy C does this as well and it looks baaad
8
u/SV-97 Sep 10 '26
This can't guarantee thread-safety, can it?
4
u/tstanisl Sep 10 '26
Ok. But don't sanitizers do the job?
Moreover, CLANG adds extensions which let one specify pointer bounds. Similar effects can be achieved with VLA-types from C99.
3
u/Trending_Boss_333 Sep 10 '26
No matter how i think about it, runtime checks just seem like a problem. I really dont see a point I'm sorry.
4
u/Late_Performer5575 Sep 10 '26
great now every read, every write everything is slower now.
and no, that doesnt make your software safe
2
u/Bahatur Sep 10 '26
Trawling the GitHub, this is a better-looking project than OP lets on. Some unrelated things of casual interest:
* Written in Assembly.
* Has the program-as-directory thing similar to Odin.
* Seems to default to arenas as the memory management method.
* Does appear to be a small C-like in truth, as distinct from a literal C clone with one weird feature, which is what I would expect from slop.
So while I have not actually tested it, and AI coded it may be, it looks like an intentional project. My verdict: not slop.
An aside for those asking why ever do runtime vs compile-time: compile-time checks are best for memory stability, but they do not succeed for memory security. The security challenge motivating Fil-C for example is what happens if there is a compromise elsewhere in memory, like another program in userspace, and then it does a jump from its rightfully-addressed memory + 100 and lands in yours. With only the compiler checks, your program could still do arbitrary behavior because once they are inside your memory boundary nothing will stop further jumps/address corruptions/etc. The only options to stop this are hardware enforcement (like CHERI) or runtime checks (like Fil-C and OP).
Granted, that might not be OP’s motivation because they did not specify, but it’s a concrete situation.
1
u/Similar_Wealth_1850 Sep 10 '26
is it interpreter like python or compiled like c? and if compiled like c shouldn't the structure of the code be slightly different at least c code instead of hc2 where it shows the compiler backend?
idk i am not that experienced in compilers but just asking out of curiosity
1
u/RoyBellingan Sep 10 '26
Some those are already catched at compile time tbh...
While the rest "with runtime-checked pointer" is what .at do in std::vector
1
u/smashedshanky Sep 10 '26
Just use rust bro… pls don’t waste water on this
1
u/vmcrash Sep 11 '26
What's cool about this experimental compiler: it is self-hosting.
1
u/KindCppCoach Sep 11 '26
why would you design a new language that has no scoped resource management, meaning, you don't call free, that happens when the scope ends. How do you prevent or detect memory leaks?
1
u/perrrm Sep 10 '26
What font are you using in the screenshot?