checker: fix autofree crash with option/result method chains#26694
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a90e1143d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| if arg.expr in [ast.Ident, ast.StringLiteral, ast.SelectorExpr, ast.ComptimeSelector] | ||
| || (arg.expr is ast.CallExpr && arg.expr.or_block.kind != .absent) { | ||
| || autofree_expr_has_or_block_in_chain(arg.expr) { |
There was a problem hiding this comment.
Keep freeing chained option/result string arguments
When -autofree is enabled, this new guard skips setting is_tmp_autofree for string args like process(get_str()!.to_upper()), so cgen no longer materializes/freees the temp argument for that expression. In vlib/v/gen/c/fn.v the post-call cleanup path is gated on arg.is_tmp_autofree (use_tmp_var_autofree and temp-var emission), so these chained option/result method calls now leak the allocated string result instead of being freed after the call; this affects any hot path using option/result propagation in string argument chains.
Useful? React with 👍 / 👎.
|
And now after |
|
Lesson learned. The strategic purpose of this Yes, there is leak in test, I was able to reproduce them manually on my own stand, so in the future it will be easier to deal with them, but for now just disable. |
This is preliminary preparation for fixing
examples/toml.vin-autofreemode.Finally found a situation in which
Claude Codeis a bad assistant — making a test based on a diff — they all work on the master branch :), it hallucinates and goes in circles.In this case, it was possible to create tests in semi-manual mode and make a minimal meaningful fix. In the future, I will try to always create test files for
-autofreemode.All
vlib/tests passed.