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

Add the section to encode setters as a vec of setter interface #174

Closed
wants to merge 1 commit into from

Conversation

Atry
Copy link
Contributor

@Atry Atry commented Dec 15, 2021

This PR is expected to be squashed when merging into main branch. The commits in this PR is not supposed to be reviewed separately.

src/os/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@fredemmott fredemmott left a 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.

@Atry Atry force-pushed the setters-as-classes branch 5 times, most recently from e489d56 to 3aff6fe Compare January 28, 2022 22:16
@Atry Atry requested a review from fredemmott February 3, 2022 01:46
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
Copy link
Contributor

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/ ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@Atry Atry Feb 3, 2022

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@Atry Atry Feb 3, 2022

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

@Atry Atry Feb 4, 2022

Choose a reason for hiding this comment

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

In fact "they should be exposed as a vec" will be modified to "they should be exposed as a vec or shape." in #175 . So the disagreement would not be a problem once we have #175

Copy link
Contributor

@fredemmott fredemmott Feb 4, 2022

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?

src/os/README.md Outdated Show resolved Hide resolved
src/os/README.md Outdated Show resolved Hide resolved
@fredemmott
Copy link
Contributor

Just a few small things left; once these are addressed, I'll merge, then follow up with suggetsed approachability/readability improvements.

@fredemmott
Copy link
Contributor

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

@Atry
Copy link
Contributor Author

Atry commented Feb 3, 2022

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 readonly public is illegal to Hack parser.

@fredemmott
Copy link
Contributor

Sorry, to clarify: 1 PR with all 3 of those commits -> quick merge :)

@Atry
Copy link
Contributor Author

Atry commented Feb 4, 2022

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?

@fredemmott
Copy link
Contributor

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

@Atry
Copy link
Contributor Author

Atry commented Feb 5, 2022

Can you make 1 PR which only contains the first 3 commits from this PR?

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.

src/os/README.md Show resolved Hide resolved
src/os/README.md Show resolved Hide resolved

| C type | Hack type |
|---|---|
| Pointers to referential transparent C `struct`s | `vec` |
Copy link
Contributor

Choose a reason for hiding this comment

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

similar to previous comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which comment?

src/os/README.md Show resolved Hide resolved
src/os/README.md Show resolved Hide resolved
- 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

src/os/README.md Show resolved Hide resolved
@Atry
Copy link
Contributor Author

Atry commented Feb 8, 2022

Close this PR because it has been squashed into #175

@Atry Atry closed this Feb 8, 2022
facebook-github-bot pushed a commit that referenced this pull request Feb 16, 2022
Summary:
In addition to #174, I also added a section to encode unordered setters as a shape.

Pull Request resolved: #175

Reviewed By: fredemmott

Differential Revision: D34060442

Pulled By: Atry

fbshipit-source-id: 5ea84559348de67b2e399e35208e2df8f5c3fdb6
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Feb 16, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants