Skip to content

Conversation

@skabbes
Copy link
Contributor

@skabbes skabbes commented May 21, 2022

Previously discussed here: #2854

@skabbes skabbes changed the base branch from release to dev May 21, 2022 11:24
@skabbes
Copy link
Contributor Author

skabbes commented May 21, 2022

First putting up a test I expect to fail (to confirm test is testing something).

@skabbes skabbes force-pushed the alignof_zero_func_array_attempt_2 branch 2 times, most recently from 5420d78 to c30531a Compare May 21, 2022 11:53
@skabbes skabbes marked this pull request as ready for review May 21, 2022 16:00
@skabbes
Copy link
Contributor Author

skabbes commented May 21, 2022

FYI @deadprogram here is the PR you requested from me.

@deadprogram
Copy link
Member

The correction is simple enough. Is this how we want to write the tests for this? @aykevl what do you think?

@deadprogram deadprogram requested a review from aykevl May 23, 2022 10:51
Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

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

The code change looks fine to me. However, the tests seem far more complicated than they need to be. I'd like to keep the tests as simple and straightforward as possible, without unnecessary abstraction. So for example, I would much prefer these tests to be written like this:

v := struct {
    noCompare [0]func()
    data      byte
}{}
println("struct{[0]func(); byte}:", unsafe.Offsetof(v.data) == uintptr(unsafe.Pointer(&v.data)) - uintptr(unsafe.Pointer(&v)))

This is IMHO easier to read, because it only requires local reasoning. You don't need to look at any other code to verify whether it is correct.

Also, generally, I don't think replicating the calculations that are done in compiler/sizes.go in these tests is all that useful. It doesn't test whether these calculations are correct. What is useful is testing whether compiler/sizes.go and LLVM agree, via unsafe.Offsetof and comparing pointer differences for example (as I've done above).

This ensures that an embedded [0]func() never ends up being larger
than 1 pointer, which is requried by protobuf processing code.
@skabbes skabbes force-pushed the alignof_zero_func_array_attempt_2 branch from 737dee8 to 2f9379a Compare May 24, 2022 20:30
@skabbes
Copy link
Contributor Author

skabbes commented May 24, 2022

Changed pushed.

I (obviously) disagree with you regarding what is unnecessary abstraction and the merits of readable code and table-based testing vs non-local reasoning - but reasonable people will disagree with that - it's your codebase so 🤷 .

I do at least think that when there is a bug, there should be a regression test added that exhibits the bug (in this case, sizeof was broken). But again 🤷

Is there a way for me to read up on the philosophy of development in Tinygo? This kind of back and forth is like my least favorite part of contributing to open source, and would love to avoid it if possible.

Please just make whatever edits you want to this PR.

@skabbes skabbes requested a review from aykevl May 24, 2022 20:53
@deadprogram
Copy link
Member

Hi @skabbes

My own thought was mainly that we probably do not want to introduce different ways of testing in different parts of the code. Perhaps a proposed change to the testing patterns to be used overall in a separate PR could be looked at. But my interpretation of @aykevl feedback is to try to "write the simplest possible test, and add tests for only the code being changed".

when there is a bug, there should be a regression test added that exhibits the bug

Yes, absolutely. I also think that idea is compatible with the idea of writing a simpler test specific to this change.

Is there a way for me to read up on the philosophy of development in Tinygo?

I think the current contributing page at https://tinygo.org/docs/guides/contributing/ could use some additional philosophy, as it were, to try to explain this part of the process. At the moment it does not contain anything of the sort, and I can see where we can make it a lot easier for people like yourself who are so kind as to wish to help out.

Anyhow, thanks again both for the feedback and code contributions!

@deadprogram deadprogram merged commit 52c61de into tinygo-org:dev May 25, 2022
@skabbes skabbes deleted the alignof_zero_func_array_attempt_2 branch May 25, 2022 13:17
@skabbes
Copy link
Contributor Author

skabbes commented May 25, 2022

My own thought was mainly that we probably do not want to introduce different ways of testing in different parts of the code.

I would have really appreciated if you mentioned that in your review, along with some specificity. (mention why you thought what I did was "different" or conceptually too complex with respect to the Tinygo codebase). I cannot read your minds.

All I tried to do is take every subtlety and concern along with the actual user facing bug and test combinations of those. I did not see how it could be simpler and still cover those cases, - so I gave up and just copy-pasted the comment in the review (which was accepted and merged!?).

But my frustration is not with testing philosophy, my frustration is trying to read between the lines of the code review to figure out what needs to be changed, and why. It feels like if I don't type verbatim what is in your head, the code will not be accepted - and obviously that is just not very motivating for a programmer.

@deadprogram
Copy link
Member

All good points, I'm sure that we maintainers could have done a better job of trying to communicate specifics, which would have been a lot more helpful. We'll work on that.

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.

3 participants