Skip to content

Conversation

@brianush1
Copy link

In wasm, a struct that wraps a single value is treated differently than just that single value by itself in the calling convention. This was causing issues when functions such as _aaLen would be called with an Impl* value, which was then trying to be re-interpreted as an AA, meaning that the function would get garbage input.

This PR removes the struct AA definition, since it was just a wrapper around a single value, and thus fixes these issues.

@skoppe
Copy link
Owner

skoppe commented Dec 27, 2020

Hi thanks for submitting this.

Interesting... I was actually just looking at those pesky AA's myself.

I do wonder if this shouldn't be fixed language-wide. There are likely more places where people use single field structs. In any case, let me try it out over the next few days.

@skoppe
Copy link
Owner

skoppe commented Jan 3, 2021

I had a look at this. It indeed seems that in some cases the calling convention doesn't add up. I did a quick tests with some standalone functions and a little struct with a pointer to replicate the invalid calling convention, but could not. It seems to be a problem specific to the AA's, likely because of separate compilation and extern(C).

I worked around it by replacing all AA aa parameters with Impl* impl in aaA.d. Then I added a little AA aa = AA(impl); at the top of each function.

I intend to fix it by diving deeper into the calling convention mismatch, but I first want to finish passing all (applicable) druntime and phobos tests first, as well as updating to the latest version of druntime/phobos/ldc.

When I have the code pass the tests I will push here.

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