-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add the section to encode setters as a vec of setter interface #174
Conversation
ea46a46
to
59ef35a
Compare
e8fc0ae
to
bee0b50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with the topic commit, but consider the comments.
Requesting changes due to previous feedback on base rev - not mergable currently.
e489d56
to
3aff6fe
Compare
src/os/README.md
Outdated
probably shouldn't be in `OS\` | ||
- if the primary purpose of a set of functions is to create, mutate and | ||
destroy a C data structure, whose reference would not be held by C | ||
libraries, they should be exposed as a `vec`. See [Appendix: reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should be exposed as a vec
Is 'they' the C structure, or the functions?
This recommendation feels pretty specific to posix_spawn_file_actions - e.g. it doesn't feel like it would apply to anything related to sockaddr
. It shouldn't replace the previous item, but it does provide a specific exception in one case.
Perhaps s/a C data structure/a C data structure that represents a list/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that there is not a good definition of "represents a list". Technically a vec
can represent an arbitrary series of function calls, as long as they are setters, where "setter" is defined as a function that just changes the data structure and does not perform global side effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no setter functions for sockaddr
in the C header, I would rather not include its encoding in this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that there is not a good definition of "represents a list".
It doesn't need to be 100% unambiguous; refining the definition is definitely something that can be left for later - actually following anything in these documents will still require code review, so there will be human judgement later in the process.
Yes, it's possible to represent an arbitrary series of function calls, but as a general solution, it's not fitting with the idea of merely trying to map C idioms to the corresponding Hack ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 'they' the C structure, or the functions?
'They' include the C pointer or handle type, the constructor, the setters, and the destructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's possible to represent an arbitrary series of function calls, but as a general solution, it's not fitting with the idea of merely trying to map C idioms to the corresponding Hack ones.
I think it's not a problem to be general here, because this section describes the default encoding for setters. We can describe other special cases to map all C idioms to Hack in other sections, especially the shape
encoding for unordered setters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think our disagreement is that I consider the 'vec-like' thing to be the special case which should be an exception, rather than it being the general case with other things being exceptions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, the current PR + diff stack structure is a bit hard to review :) #175 still mentions 'long-lived' which I don't think is intentional.
I think this lines up with what you're writing and referential transparency, but to check: imagine 3 APIs:
C++ byref
FooStruct myFoo;
// void do_foo(FooStruct&)
do_foo(myFoo);
C pointer-to-value
FooStruct myFoo;
// void do_foo(FooStruct*)
do_foo(&myFoo);
C opaque handle
FooStruct* myFoo = foo_init();
// void do_foo(FooStruct*)
do_foo(myFoo);
foo_destroy(myFoo);
Assuming that all 3 only differ in terms of resource management and calling convention, these 3 approaches should be considered equivalent from the perspective of Hack API design; which approach the C library actually takes is an implementation detail. If libfoo changes between these approaches in v(X+1)
, we should not feel any need to change the corresponding Hack APIs.
Is this view compatible with your plans here?
Just a few small things left; once these are addressed, I'll merge, then follow up with suggetsed approachability/readability improvements. |
It might be worth splitting out the first 3 commits from this stack to a separate PR: those are just nits, but I don't think we're on the same page about whether this section in the top commit is valuable |
I created the top commit because |
Sorry, to clarify: 1 PR with all 3 of those commits -> quick merge :) |
Sorry I don't understand this. Would you mind if I squash all the commits in this PR? |
774ae78
to
55039d8
Compare
Can you make 1 PR which only contains the first 3 commits from this PR? On that's in, combining/squashing this with the shapes PR might be best |
Why? The first 3 commits include some problems and rest commits just fix these problems. It does not make sense to me to exclude these fixes. |
6078a38
to
52cdead
Compare
|
||
| C type | Hack type | | ||
|---|---| | ||
| Pointers to referential transparent C `struct`s | `vec` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which comment?
- A referential transparent C pointer type should be associated with a set of | ||
utility functions, including a constructor, a destructor and several setters. | ||
These utility functions must not perform any global side effects other than | ||
allocating memory that will be freed in the destructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File descriptors are used as an example, but this is not the case for file descriptors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment, because I think file descriptors are not referential transparent C pointers, and I did not use file descriptors as an example for the definition of referential transparent C pointers.
Close this PR because it has been squashed into #175 |
Summary: In addition to hhvm/hsl#174, I also added a section to encode unordered setters as a shape. Pull Request resolved: hhvm/hsl#175 Reviewed By: fredemmott Differential Revision: D34060442 Pulled By: Atry fbshipit-source-id: 5ea84559348de67b2e399e35208e2df8f5c3fdb6
This PR is expected to be squashed when merging into main branch. The commits in this PR is not supposed to be reviewed separately.