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
spec: some way to analyze or enforce data lifetimes #9743
Comments
I think reliably checking this is equivalent to solving the halting problem. And unreliable checking will probably annoy the user. (Trivial cases |
Indeed, such analysis isn't tractable in the general case. Even in specific cases, it can be difficult in practice: for example, lifetime requirements can be maintained even when sending a []byte down a channel as long as the slice is no longer used by the time the return from, i.e., Write, occurs. Because of the practical need for such a tool to strike some balance between accuracy and usefulness, it'd likely have to be a 3rd party tool with some kind of annotations or hinting (preferably outside of the Go code, perhaps similar to the API checking tool). |
A dynamic checking tool for this is possible, but I'm not sure if it could |
A rough idea: |
@alandonovan, are there existing checkers using your guru fanciness? |
/cc @josharian |
@bradfitz nope. A static analysis for this problem would need to understand both control flow and aliasing, which makes it basically intractible. You could do it if the user supplied lots of information about ownership, but then you'd be programming in Rust, not Go. |
This is not a Go 2 issue. It is a request for a different sort of tool. It might require some way to annotate the program, but if so that could be discussed separately as a general issue, not specific to this idea. |
This is a wish, not a proposal. Nothing concrete is being proposed. I would love to have this too, but I don't know how to do it. Removing the proposal label again, and the prefix too, so gopherbot doesn't put the label back. |
On second thought I don't think this is appropriate as an open issue. There's no concrete next action. |
I wish -race or oracle or a new tool in the spirit of errcheck could help prevent these kinds of mistakes:
func (db *DB) View(fn func(*Tx) error) error
where the function passed in can doval := txn.Bucket(b).Get(key)
and the val []byte is only valid inside that View transaction. It's quite easy to accidentally writebut the database is free to reuse the memory pointed to by
result
immediately afterget
returns.The text was updated successfully, but these errors were encountered: