Nim: Adding a ".nogc." pragma

Created on 14 Jan 2018  路  4Comments  路  Source: nim-lang/Nim

Functions annotated with ".nogc." can't do any operations that rely on garbage collection.

Similar to how nogc works in D lang:

https://wiki.dlang.org/DIP60

Implementation would probably be similar to how the ".noSideEffect." pragma already works in Nim.

Feature

Most helpful comment

That may be useful for e.g. games, where you want to avoid gc in rendering logic, but ok with gc in game logic. noSideEffect is a nice analogy. You don't want to compile all program with noSideEffect.

All 4 comments

And then what? What's the point? We have --gc:none and looking at the compiler warnings.

The point - A larger subset of Nim stdlib and ecosystem being usable in environments where GC is not acceptable. eg, domains where only C, C++, Rust or Ada may be used.

It would be like "--gc:none" that always becomes a compile error if a given function has that pragma.

But you're right, given that "--gc:none" is available, it's a lot less relevant. People can make github pull requests, or make their own modules where "--gc:none" doesn't give any warnings, for those kinds of environments.

Thanks for the reminder!

That may be useful for e.g. games, where you want to avoid gc in rendering logic, but ok with gc in game logic. noSideEffect is a nice analogy. You don't want to compile all program with noSideEffect.

Not gonna happen anytime soon.

Was this page helpful?
0 / 5 - 0 ratings