-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
fix Issue 17798 - [2.076] "static foreach" not documented #1884
Conversation
|
Thanks for your pull request, @tgehr! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla references
|
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.
grammar.dd needs an update too.
|
If I recall correctly, this is a problem with Github sometimes sending the wrong commit hash. I can't remember what the workaround is... I think closing and re-opening this PR will re-run the doc tester. |
|
okay thanks, looks good but i want to see the build now, it's not up to you @tgehr, you 've done the job, it's up to the build to success. |
|
@tgehr you need to rebase and it will work. |
|
@bbasile There are no new commits in stable. Am I missing something? |
|
@bbasile: That pull request went to master, not stable. I guess this was accidental? |
Argh. Oops. |
|
@tgehr I think that the rebase makes more sense now. Sorry for the previous failure but since i 'm the reporter on bugzilla i feel implicated in a way. |
| @@ -537,6 +538,127 @@ INT!(17) c; // error, static assert trips | |||
| ) | |||
| ) | |||
|
|
|||
| $(H2 $(LNAME2 staticforeach, Static Foreach)) | |||
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's an error here i think because of the case
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.
StaticForeach
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 is also this line in the file, from which it is derived.
$(H2 $(LNAME2 staticif, Static If Condition))
I don't think whatever error there is is actually in this line.
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.
Yeah, i may have misinterpreted the log, sorry.
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.
Once it passes the autotester, of course.
| @@ -680,6 +684,7 @@ $(GNAME ForeachTypeList): | |||
| $(GNAME ForeachType): | |||
| $(GLINK ForeachTypeAttributes)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK2 declaration, Declarator) | |||
| $(GLINK ForeachTypeAttributes)$(OPT) $(I Identifier) | |||
| $(GLINK ForeachTypeAttributes)$(OPT) $(D alias) $(I Identifier) | |||
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.
It looks like static foreach (enum ref alias T; TypeList) is valid syntax. Is this correct?
Ditto for foreach (enum ref x; someRange).
In general, I'm wondering if we should have a separate grammar rule for [static] foreach over sequences vs the other "runtime" aggregates.
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.
(Should ForeachTypeAttributes be allowed before alias?)
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 think that separating grammar rules to complicate the parser makes sense. It's good for the parser to be lenient. Semantic analysis should catch it (the resulting error messages are better).
It might however be sensible to not allow ForeachTypeAttributes before alias (the reasoning was that global alias allows (some) storage classes, but it turns out that local declarations also do not allow storage classes before alias), but this pull request documents existing behaviour. You might want to open an enhancement request.
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 think we need to change the compiler if we restructure the grammar so it is a bit harder to produce semantically invalid code.
Yes, you can (and most likely you already do) catch this during semantic analysis, however I feel it would be better for the reader of the spec if the grammar rules match more closely what is semantically valid.
Presently, the reader wouldn't have any clue that foreach (shared ref enum inout alias x; aggregate) should be rejected by the compiler - the intended semantics are not specified.
| @@ -688,20 +693,24 @@ $(GNAME ForeachTypeAttributes) | |||
| $(GNAME ForeachTypeAttribute): | |||
| $(D ref) | |||
| $(GLINK2 declaration, TypeCtor) | |||
| $(D enum) | |||
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 wonder if enum should not be a ForeachTypeAttribute, but instead listed as a separate ForeachType entry, similar to alias.
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.
enum is a storage class, so it would be inconsistent not to allow it.
|
|
||
| $(GNAME StaticForeachDeclaration): | ||
| $(GLINK StaticForeach) $(GLINK2 attribute, DeclarationBlock) | ||
| $(GLINK StaticForeach) $(D :) $(GLINK2 module, DeclDefs)$(OPT) |
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.
Can you give an example for this grammar rule? Since static if doesn't support trailing colon, I'm wondering if static foreach should not support it too.
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.
static if supports trailing colon.
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.
Hmm, I missed that even though I searched for it, nevermind then.
(It's derived from the ConditionalDeclaration rule. For some reason I misread the spec as if it only applies for VersionCondition and DebugCondition. Sorry for the noise.)
spec/version.dd
Outdated
|
|
||
| $(P The aggregate/range bounds are evaluated at compile time and | ||
| turned into a sequence of compile-time entities by evaluating | ||
| corresponding code with a $(GLINK2 statement |
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.
Missing comma at the end of the line (the link to ForeachStatement is broken).
| $(GNAME StaticForeachStatement): | ||
| $(GLINK StaticForeach) $(GLINK2 statement, NoScopeNonEmptyStatement) | ||
| ) | ||
|
|
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.
Perhaps you should specify what happens with Ddoc when StaticForeachDeclaration declares functions preceded by a ddoc comment. Is documentation generated for each function, or is there only once instance? With static if I think there's a trick that goes along the lines of static if (condition || generatingDoc) /** This function is available iff ... */ void foo();. Another question is whether you can generate documentation and mix it in in for each declaration (e.g. declare an overload set where each function has the same documentation, save for the parameters section).
spec/version.dd
Outdated
| import std.conv : text; | ||
| static foreach(i; iota(0, 3).map!text) | ||
| { | ||
| mixin(`enum x`~i~`=i;`); |
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.
Currently the coding style of the spec is all over the place, but AFAIK the goal is for new code to be formatted according to DStyle (where applicable), so in this case you would need to add a space around operators (https://dlang.org/dstyle.html#phobos_whitespace).
spec/version.dd
Outdated
| } | ||
| ------- | ||
|
|
||
| $(P An explicit $(D break)/$(D continue) label can be used to avoid this limitation. |
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.
Maybe also worth making explicit is that you can't (at least you shouldn't be able to?) put a label before static foreach or any of the other conditional statement / declarations (e.g. static if).
|
@tgehr FYI, now that CyberShadow's DAutoTest is green you can see a preview of your changes by clicking on the respective "Details" button. |
|
Does this need to be squashed before merge? I remember someone saying that commits are squashed for this repo on merge but I don't know if that's actually true. |
You can select the merge type once on merging (press the tiny arrow next to the merge button to switch the method) - and FWIW this is enabled for D all repos. |
|
Right, but then what's the point of the auto-merge tag? Just to make sure nobody merges something broken? |
Well you can't merge anything broken (GitHub won't allow this). The point of auto-merge is that you don't need to wait until the CIs have run. There's also been auto-merge-squash, but due to "abuse" this has been temporarily removed. Squashed it an rebased to @ZombineDev you are still on "Requesting changes" - anything from your side that blocks this PR or can we move ahead? |
|
Let me check again |
Note: I was not able to build stable with
make -fposix.mak. Therefore this is untested.