-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resource annotations #158
Comments
Better yet the void/u64 thing can be done by the compiler, and we can have a Then you don't even need the |
The name I chose the name If the (debug) runtime is tracking a stacktrace for where the resource was acquired, how about providing access to that? Anyway, those are my loop-d-loops and barrel rolls on this jetpack ride :D |
It seems like this is just a few steps from a built in reference count implementation. If you have it internally why not expose it so that programs can use it? To thejoshwolfe, reference counting on anything can be useful in some circumstances. It is usually associated with memory, but can be file handles, sockets etc. It is not a panacea, but it really gets useful when you have a lot of async code or lots of threading. Really anything that makes the order in which resources could be freed complicated. |
Whatever happened to this feature? |
It's a non-accepted proposal, which means it may or may not make it into the language. More to the point, the current milestone of 1.1.0 suggests that if this is eventually accepted, that might not be until after Zig 1.0. |
I'm curious whether there were any further discussion on this or if it's likely DOA |
This sounds pretty much like valgrind except that valgrind has in-build Kernel ressource annotations, whereas this annotation is user-based (possibly inside libstd). Open questions:
From my point of view, the MVP could be done once supported and non-supported use cases have been defined with the actual advantages to reusage of current tooling including generality, composability. |
For what its worth this seems somewhat like linear types |
Strap your jet pack on because we're going for a pie-in-the-sky adventure.
I propose a builtin function called
@resource_acquire()
which returns a u64. This is an opaque identifier which is probably just random bytes. Zig code may then store this identifier somewhere, like this:Now, in debug mode, Zig will add safety checks to catch the following scenarios:
The standard library would implement these semantics for all resources, for example file streams, network connections.
If the implementation is fast enough this could even be viable for detecting failure to flush a stream, such as stdout. When anything is written, acquire a resource, unless one is already acquired. When flush is called, release the resource, unless already released.
Depending on how advanced the safety checks are, this might not even need to be a builtin function. It could just be a standard library function.
In the event of an error we would want to print the stack trace of the resource being acquired, so we might want a
@get_stack_trace()
builtin function. We want that anyway. Separate issue.The text was updated successfully, but these errors were encountered: