Comment by SkiFire13
3 days ago
> Then I thought: how hard is it to write this C++ static analyzer? Conceptually, I think it’s not hard. It requires going through the AST. And since the static analysis is mostly statically scoped, it doesn’t require heavy cross-file analysis.
How do you handle function lifetimes then? Those are generally non-local to infer, and Rust requires annotating functions with informations for that. I tried taking a look at the mako db's refactor but I didn't see any lifetime annotation being added there.
It need new annotations. (see the paragraph under "Comment-Based Syntax")
The article doesn't show any function lifetime annotations, only @safe and @unsafe.
Functions need annotations like "return value lives as long as argument 1" or "return value lives as long as both arguments are alive"
> The article doesn't show any function lifetime annotations, only @safe and @unsafe.
It does, but it's under the "External Annotations" section:
> The where clause specifies lifetime relationships—like where stmt: 'a, return: 'a means the returned pointer lives as long as the statement handle. This lets the analyzer catch dangling pointers from external APIs.
The GitHub repo also has an annotations guide with some more info [0]. The general syntax appears to be:
[0]: https://github.com/shuaimu/rusty-cpp/blob/main/docs/annotati...
3 replies →