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

8.3: Document Random\IntervalBoundary #3419

Merged
merged 4 commits into from
Nov 20, 2024
Merged

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 27, 2024

Part of: #2796

Fixes:

Requires:

I kinda wish I could use a <refentry> tag instead, but we need to insert this into a <book> element which requires an intermediate tag anyway, so steal the suboptimal markup from classes.

@haszi do you think this makes sense, and is this not too complicated to add support to PhD for it?

@Girgias Girgias requested a review from TimWolla as a code owner May 27, 2024 23:57
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

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

Can't comment on the Docbook specifics, but here's some words for you to include to make the page useful right from the start.

reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
@haszi
Copy link
Contributor

haszi commented May 28, 2024

@haszi do you think this makes sense, and is this not too complicated to add support to PhD for it?

This is very much in line with the new class markup you used which is great. PhD support should not be an issue and most of the work will be done when the new class markup is converted.

I assume the rendered enum synopsis would look something like this:

enum_synopsis

@TimWolla
Copy link
Member

@haszi Note that related to #3405, enum cases can also have attributes (they are class constants internally). So it's probably to take that into account right away.

</enumitemdescription>
</enumitem>

</enumsynopsis>
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so far classsynopsis elements only contained the signature itself, but not the descriptions. Is it intentional that it's different for enumsynopsis elements?

Copy link
Member Author

Choose a reason for hiding this comment

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

The DocBook 5.2 markup describes the markup in that manner: https://tdg.docbook.org/tdg/5.2/enumsynopsis (via the <enumitem> tag) so yes.

For reference, the <classsynopsis> description is located here: https://tdg.docbook.org/tdg/5.2/classsynopsis

Copy link
Member

Choose a reason for hiding this comment

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

That's a pity, because this way automatic replacement is going to be much more difficult, since there are free form values in the generated enumsynopsis item, and we should somehow try to preserve them.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a pity, because this way automatic replacement is going to be much more difficult, since there are free form values in the generated enumsynopsis item, and we should somehow try to preserve them.

I'm not sure whether that's difficult? One just needs to ignore the <enumitemdescription> tag, but also, I don't see how an enum would change after it has been introduced.

Copy link
Member

Choose a reason for hiding this comment

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

classsynopsis elements are generated based on the current stub definitions for each class/interface/enum signature which are encountered on class synopses pages (https://github.com/php/php-src/blob/0ad2e4d997549c85aac61120a94ea3da0b709339/build/gen_stub.php#L5560) and then the respective elements are replaced altogether one by one (the replaceAndCompareXmls() call a few lines below).

This means that if there is anything inside classsynopsis elements which are not generatable based on the definitions in stubs, then those things will be removed. A workaround for enums could be that the enum case descriptions are retrieved from the manual pages and they are inserted into the generated elements... This complicates the process, but maybe it's not that difficult if this is going to be the preferred approach.

Also, It has just came to my mind that these descriptions would result in enum definitions which are completely not valid PHP code 🤔 while for the rest of the symbols, we generate at least a remotely valid PHP code since a few years.

<!-- TODO New Reftitle entity -->
&reftitle.classsynopsis;

<enumsynopsis>
Copy link
Member

Choose a reason for hiding this comment

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

Just a FYI: we should also think about the markup for implemented interfaces, enum constants, methods

Copy link
Member Author

Choose a reason for hiding this comment

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

Right... I forgot that PHP enums can do this sort of stuff...

Copy link
Member

@kocsismate kocsismate May 29, 2024

Choose a reason for hiding this comment

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

Yeah, and I've just realized that e.g. fieldsynopsis elements inside enumsynopsis are not even allowed in DocBook. :/ (Or are they?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, they are not, because DocBook (rightfully) assumes that enums are just that, and not our weird thing based on objects.

I think we might need to use the <classsynopsis> tags when an enum has constants, properties, or methods. However, I would imagine this to be rare for internal enums.

<enumname>IntervalBoundary</enumname>
<!-- <modifier role="enum_backing_type">string|int</modifier> -->

<enumitem>
Copy link
Member

Choose a reason for hiding this comment

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

Other types of symbols have a dedicated section title for classes and interfaces. Would it be a good idea to add them for enums as well?

@kocsismate
Copy link
Member

I've just drafted a PR which adds support for this feature in stubs: php/php-src#14369 I intentionally modified Random\IntervalBoundary and also checked in the generated result for testing purposes.

@haszi
Copy link
Contributor

haszi commented Jun 22, 2024

Since all enums implement either the UnitEnum or the BackedEnum interface and inherit their default method implementation, all enum markup will have to include both an <enumsynopsis> and a <classsynopsis> element. Neither of these can have the other as its child but we could have one after the other in the synopsis <section> like this (I think this is valid DocBook 5.2 markup):

 <section xml:id="enum.intervalboundary.synopsis">
   &reftitle.classsynopsis;

  <enumsynopsis>
   ... // enum (cases) markup
  </enumsynopsis>

  <classsynopsis>
   ... // regular class markup
  </classsynopsis>
 </section>

<enumname> in the <enumsynopsis> element would define the enum's name and any class/interface name in the <classynopsis> element would be ignored.

What do you think?

@kocsismate
Copy link
Member

in the element would define the enum's name and any class/interface name in the element would be ignored.

Hmm, interesting option... I wouldn't have thought about it. But I think I'd prefer to just have one element which has to be classynopsis because of the restrictions we face.

@TimWolla
Copy link
Member

This will now also be required for RoundingMode (and some other enums) in 8.4.

@cmb69
Copy link
Member

cmb69 commented Oct 22, 2024

Hmm, this is ugly. We can't use <enumsynopsis> due to its limitation, and we can't use <classsynopsis> because its class attribute only supports "class" and "interface". I'm afraid we need to redesign enums altogether. ;)

Okay, let's be pragmatic and use <classsynopsis> (and role="enum" if necessary).

@Girgias
Copy link
Member Author

Girgias commented Oct 22, 2024

Hmm, this is ugly. We can't use <enumsynopsis> due to its limitation, and we can't use <classsynopsis> because its class attribute only supports "class" and "interface". I'm afraid we need to redesign enums altogether. ;)

Okay, let's be pragmatic and use <classsynopsis> (and role="enum" if necessary).

We will need the role="enum" as otherwise the generated markup by PhD will make it look like classes.

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

@cmb69
Copy link
Member

cmb69 commented Oct 22, 2024

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

I'm a bit worried about translations. If we have a number of enum documented with <enumsynopsis>, and later need to change everything …

On the other hand, maybe we will never need more, and I'm overthinking.

@Girgias
Copy link
Member Author

Girgias commented Oct 23, 2024

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

I'm a bit worried about translations. If we have a number of enum documented with <enumsynopsis>, and later need to change everything …

On the other hand, maybe we will never need more, and I'm overthinking.

What I meant, is that it would be perfectly fine for both markups to coexist, where the <classsynopsis class="class" role="enum"> usage would be reserved for "complex" enums that actually behave like classes.

reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
Comment on lines 9 to 13
<simpara>
The <enumname>Random\IntervalBoundary</enumname> cases determines if the
boundary values can be returned or not by
<methodname>Random\Randomizer::getFloat</methodname>.
</simpara>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if I would make it specific to Randomizer::getFloat(). It's the only current use case and it will likely remain the only use case, but technically the enum would be reusable for other things. The detail that it will determine whether the boundaries can be returned is already explained in the $boundary parameter of getFloat().

Perhaps something like:

The Random\IntervalBoundary enum specifies whether or not an interval includes the boundary values within the set of values lying in the interval.

Comment on lines 24 to 27
<enumitemdescription>
The <parameter>min</parameter> value may be returned.
However, the <parameter>max</parameter> value will never be returned.
</enumitemdescription>
Copy link
Member

Choose a reason for hiding this comment

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

A left-open interval. The lower boundary is included in the interval, the upper boundary is not.

<enumitem>
<enumidentifier>ClosedClosed</enumidentifier>
<enumitemdescription>
Both the <parameter>min</parameter> and <parameter>max</parameter> value may be returned.
Copy link
Member

Choose a reason for hiding this comment

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

A closed interval. Both boundary values are included in the interval.

<enumitem>
<enumidentifier>OpenClosed</enumidentifier>
<enumitemdescription>
The <parameter>max</parameter> value may be returned.
Copy link
Member

Choose a reason for hiding this comment

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

A right-open interval. The upper boundary is included in the interval, the lower boundary is not.

<enumitem>
<enumidentifier>OpenOpen</enumidentifier>
<enumitemdescription>
Neither the <parameter>min</parameter> or <parameter>max</parameter> will ever be returned.
Copy link
Member

Choose a reason for hiding this comment

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

An open interval. Neither boundary value is included in the interval.

@TimWolla
Copy link
Member

Ah and: Should the PR be renamed? It's not just a proposal at this point, no?

@Girgias Girgias changed the title Proposal for Enum markup 8.3: Document Random\IntervalBoundary Nov 20, 2024
@Girgias Girgias requested a review from TimWolla November 20, 2024 16:50
@Girgias Girgias merged commit 550b9c3 into php:master Nov 20, 2024
2 checks passed
@Girgias Girgias deleted the enum-markup branch November 20, 2024 16:59
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.

5 participants