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

c#: Use stack when the list is smaller than a given value #1144

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

jsturtevant
Copy link
Collaborator

fixes #1012

@jsturtevant
Copy link
Collaborator Author

/cc @AaronRobinsonMSFT @pavelsavara

{{
var {buffer_size} = {size} * (nuint){list}.Count;
{address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
cleanups.Add(()=> NativeMemory.AlignedFree({address}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wishful thinking - not blocked for this PR:

It would be awesome if we could see this in context of some generated sample.
Maybe we can have wit->C# integration test in which the C# file is committed into git ?
That would show up as delta in the generated code in the PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are tons of integration tests in https://github.com/bytecodealliance/wit-bindgen/tree/main/tests

Currently we don't check any into source, but having something like the that does have some value. I typically pull a PR and take a look at the source changes if I am unsure so would find this useful.

@alexcrichton any thoughts on this? I suppose the Rust version is a macro so you don't really have source to check in?

Copy link
Member

Choose a reason for hiding this comment

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

It's possible to finagle but would require some frobbing of the infrastructure. We do this in Wasmtime for example for the output of the wasmtime::component::bindgen! macro and we could do something similar for the generators in this repository. Most generators are already running "codegen tests" to ensure the output compiles and we could probably update that all to save/restore snapshots in-tree. Probably wouldn't run the tests themselves but you'd still be able to see diffs in PRs.

Personally I like having "golden snapshot" tests like that in-tree and I also like to review output changes as opposed to changes-of-how-to-output-code. The only downside is "big PRs" but I find it pretty easy to skim over the generated code changes.

Basically that's a long-winded way of saying that I think it'd be quite reasonable to add this to the repo. Basically run bindings generation for everything in tests/codegen and check in the results in-tree.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking that we didn't need to have every test in tests/codegen but maybe something like the flavorful example checked in? I think it might be overwhelming to have to many files changed in a PR. Anyways I will open an issue to track.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alexcrichton
Copy link
Member

I'm happy to rubber-stamp these (or ask @dicej) to rubber stamp them, but @jsturtevant do you have someone else in mind to review C#-related PRs? I'm happy to add someone else to this repository for reviewing things to assist with assignment/merging/etc.

(mostly want to clarify your expectations around reviewing since I'm not able to review C# code myself)

@jsturtevant jsturtevant self-assigned this Jan 27, 2025
@jsturtevant jsturtevant requested review from yowl and silesmo January 27, 2025 22:14
@jsturtevant
Copy link
Collaborator Author

I'm happy to rubber-stamp these (or ask @dicej) to rubber stamp them, but @jsturtevant do you have someone else in mind to review C#-related PRs? I'm happy to add someone else to this repository for reviewing things to assist with assignment/merging/etc.

(mostly want to clarify your expectations around reviewing since I'm not able to review C# code myself)

Typically try to get a review from the C# maintainers: @silesmo, @yowl or @dicej.

@pavelsavara is our upstream .NET contributor that could offer C#/.net advice too. @pavelsavara are you interested in joining the repo for c# reviews?

@alexcrichton
Copy link
Member

Ok sounds good 👍

Mostly wanted to make sure you weren't blocking on my and I wasn't aware of it!

@pavelsavara
Copy link
Collaborator

@pavelsavara are you interested in joining the repo for c# reviews?

Yes

@jsturtevant jsturtevant added this pull request to the merge queue Jan 30, 2025
Merged via the queue into bytecodealliance:main with commit cae738d Jan 30, 2025
25 checks passed
@jsturtevant jsturtevant deleted the stackalloc-when-can branch January 30, 2025 21:20
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.

C#: use stackalloc where appropriate for caller-allocated buffers
3 participants