Skip to content
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

Simplify mem cell alloc usage #207

Merged
merged 2 commits into from
May 19, 2024
Merged

Simplify mem cell alloc usage #207

merged 2 commits into from
May 19, 2024

Conversation

nyurik
Copy link
Contributor

@nyurik nyurik commented May 13, 2024

Introduce several helper memory allocation functions to reduce boilerplate code. This will help in the future to further simplify allocation, esp when alloc module becomes part of stdlib. The helper functions allow far simpler usage with a generic type as the first param.

I began with this replacement:

\<([a-zA-Z0-9_]+) as Allocator\<([a-zA-Z0-9_]+)\>\>\:\:AllocatedMemory\:\:default\(\s*\)

with

alloc_default::<$2, $1>()

In a few cases, I was able to use alloc.alloc_cell(...) directly (compiler was able to figure out which type to use automatically).

Afterward, found all conditional allocations and replaced them with alloc_if(condition, ...), and fixed the imports

Introduce several helper memory allocation functions to reduce boilerplate code.  This will help in the future to further simplify allocation, esp when alloc module becomes part of stdlib.  The helper functions allow far simpler usage with a generic type as the first param.

I began with this replacement:

```
\<([a-zA-Z0-9_]+) as Allocator\<([a-zA-Z0-9_]+)\>\>\:\:AllocatedMemory\:\:default\(\s*\)
```
with
```
alloc_default::<$2, $1>()
```

In a few cases, I was able to use `alloc.alloc_cell(...)` directly (compiler was able to figure out which type to use automatically).

Afterward, found all conditional allocations and replaced them with `alloc_if(condition, ...)`, and fixed the imports
@nyurik nyurik mentioned this pull request May 13, 2024
@nyurik
Copy link
Contributor Author

nyurik commented May 13, 2024

@danielrh when you have a chance, please merge this one early on because it might conflict with some other PRs. It should be fairly straight to review, as most changes were search/replaced

},
// FIXME: makes little sense to test if N+2 > 0 -- always true unless wrapping. Perhaps use allocate() instead?
literal_costs_: alloc_or_default::<floatX, _>(m, num_bytes + 2),
// FIXME: possible bug because allocation size is different from the condition
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem to be a bug per https://chromium.googlesource.com/chromium/src/third_party/+/refs/heads/main/brotli/enc/backward_references_hq.c#109
but lets fix it in a subsequent PR and test it carefully

@danielrh danielrh merged commit 1730d38 into dropbox:master May 19, 2024
1 of 2 checks passed
@nyurik nyurik deleted the alloc-util branch May 20, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants