Skip to content

Commit b7d6c21

Browse files
committed
Fix memory audit
1 parent ded4f96 commit b7d6c21

3 files changed

Lines changed: 3 additions & 42 deletions

File tree

docs/todo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ unlikely to move the needle for most users.
114114
| D15 | [Unused parameter diagnostic](todo/diagnostics.md#d15-unused-parameter-diagnostic) | Low | Low |
115115
| | **[Bug Fixes](todo/bugs.md)** | | |
116116
| B1 | [Rename can build edits from a symbol map that predates the buffer](todo/bugs.md#b1-rename-can-build-edits-from-a-symbol-map-that-predates-the-buffer) | Medium-High | Low-Medium |
117-
| B2 | [`mem-audit` feature build fails: `Ustr::capacity()` does not exist](todo/bugs.md#b2-mem-audit-feature-build-fails-ustrcapacity-does-not-exist) | Low | Low |
118117
| | **[Code Actions](todo/actions.md)** | | |
119118
| A40 | [Generate method from call](todo/actions.md#a40-generate-method-from-call) | Medium-High | Medium |
120119
| A41 | [Create class from non-existing name](todo/actions.md#a41-create-class-from-non-existing-name) | Medium | Medium |

docs/todo/bugs.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,3 @@ Note that the cross-file paths need slightly more than linked editing
4141
did: they read maps for files other than the request URI, so each one
4242
must be checked against *that* file's content, not the buffer the
4343
request arrived on.
44-
45-
## B2 `mem-audit` feature build fails: `Ustr::capacity()` does not exist
46-
47-
`cargo build --features mem-audit` fails on `main` (reproduced before
48-
any local changes, via `git stash`):
49-
50-
```
51-
error[E0599]: no method named `capacity` found for reference `&Ustr` in the current scope
52-
--> src/mem_audit.rs:1269:27
53-
|
54-
1269 | sym.add(k.capacity());
55-
| ^^^^^^^^ method not found in `&Ustr`
56-
57-
error[E0599]: no method named `capacity` found for reference `&Ustr` in the current scope
58-
--> src/mem_audit.rs:1271:34
59-
|
60-
1271 | member_idx.add(k.capacity());
61-
| ^^^^^^^^ method not found in `&Ustr`
62-
```
63-
64-
`k` in both call sites is a `Ustr` (interned string handle from the
65-
`ustr` crate) used as a hash map key, and the audit code is calling
66-
`.capacity()` on it to account for heap bytes the way it does for
67-
`String`/`Box<str>` keys elsewhere in the same file. `Ustr` has no
68-
`capacity()` method — it is a pointer into a global intern table, not
69-
an owned allocation, so the right accounting is either to treat it as
70-
zero marginal heap cost (the string data is shared and already counted
71-
once wherever it's interned) or to look up whatever `ustr` exposes for
72-
the underlying byte length, not capacity.
73-
74-
The current profile (dev, `cargo build --lib`) never builds this
75-
feature, so normal development and `cargo test` are unaffected. It only
76-
surfaces when actually running the memory-audit binary, which is
77-
presumably why it went unnoticed. Fix by correcting the two call sites
78-
in `src/mem_audit.rs` to match whatever the installed `ustr` version's
79-
API actually provides.

src/mem_audit.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,12 +1263,10 @@ pub(crate) fn report(backend: &Backend, runner_content_bytes: usize) {
12631263
for sp in &sm.spans {
12641264
sym.add(sp.kind.audit_heap());
12651265
}
1266-
sym += map_buckets::<String, Vec<usize>>(sm.member_access_indices.capacity());
1267-
member_idx += map_buckets::<String, Vec<usize>>(sm.member_access_indices.capacity());
1268-
for (k, v) in &sm.member_access_indices {
1269-
sym.add(k.capacity());
1266+
sym += map_buckets::<Atom, Vec<usize>>(sm.member_access_indices.capacity());
1267+
member_idx += map_buckets::<Atom, Vec<usize>>(sm.member_access_indices.capacity());
1268+
for v in sm.member_access_indices.values() {
12701269
sym.add(v.capacity() * size_of::<usize>());
1271-
member_idx.add(k.capacity());
12721270
member_idx.add(v.capacity() * size_of::<usize>());
12731271
}
12741272
sym.add(sm.var_defs.capacity() * size_of::<crate::symbol_map::VarDefSite>());

0 commit comments

Comments
 (0)