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

fix Issue 17798 - [2.076] "static foreach" not documented #1884

Merged
merged 1 commit into from
Oct 7, 2017

Conversation

tgehr
Copy link
Contributor

@tgehr tgehr commented Sep 4, 2017

Note: I was not able to build stable with make -fposix.mak. Therefore this is untested.

@dlang-bot
Copy link
Contributor

dlang-bot commented Sep 4, 2017

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:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

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

Auto-close Bugzilla Description
17798 [2.076] "static foreach" not documented

@tgehr tgehr changed the base branch from master to stable September 4, 2017 13:17
Copy link

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

@MetaLang
Copy link
Member

MetaLang commented Sep 4, 2017

fatal: 'refs/ae-sys-d-cache/website-865504ca7123aa6b75c71a5f783b02a5e26dbcae-7bad98e9d56422f52983962526ed878a' - not a valid ref

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.

@tgehr
Copy link
Contributor Author

tgehr commented Sep 4, 2017

@bbasile @MetaLang Thanks!

@ghost
Copy link

ghost commented Sep 4, 2017

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.

@ghost
Copy link

ghost commented Sep 4, 2017

@tgehr you need to rebase and it will work. Or close reopen.

@tgehr
Copy link
Contributor Author

tgehr commented Sep 4, 2017

@bbasile There are no new commits in stable. Am I missing something?

@ghost
Copy link

ghost commented Sep 4, 2017

@tgehr yes, indeed you are missing #1885 which should solve the failure.

@tgehr
Copy link
Contributor Author

tgehr commented Sep 4, 2017

@bbasile: That pull request went to master, not stable. I guess this was accidental?

@CyberShadow
Copy link
Member

That pull request went to master, not stable. I guess this was accidental?

Argh. Oops.

@ghost
Copy link

ghost commented Sep 4, 2017

@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))
Copy link

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

Copy link

Choose a reason for hiding this comment

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

StaticForeach

Copy link
Contributor Author

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.

Copy link

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.

Copy link
Member

@WalterBright WalterBright left a 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)
Copy link
Member

@PetarKirov PetarKirov Sep 7, 2017

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.

Copy link
Member

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

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 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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

@tgehr tgehr Sep 7, 2017

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.

Copy link
Member

@PetarKirov PetarKirov Sep 8, 2017

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
Copy link
Member

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

Copy link
Member

@PetarKirov PetarKirov Sep 7, 2017

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;`);
Copy link
Member

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.
Copy link
Member

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

@PetarKirov
Copy link
Member

PetarKirov commented Sep 7, 2017

@tgehr FYI, now that CyberShadow's DAutoTest is green you can see a preview of your changes by clicking on the respective "Details" button.

@MetaLang
Copy link
Member

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.

@wilzbach
Copy link
Member

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.

@MetaLang
Copy link
Member

Right, but then what's the point of the auto-merge tag? Just to make sure nobody merges something broken?

@wilzbach wilzbach changed the base branch from stable to master October 5, 2017 17:35
@wilzbach
Copy link
Member

wilzbach commented Oct 5, 2017

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 master (that's the branch which gets auto-deployed on dlang.org - it is a constant point of confusion :S).

@ZombineDev you are still on "Requesting changes" - anything from your side that blocks this PR or can we move ahead?

@PetarKirov
Copy link
Member

Let me check again

@dlang-bot dlang-bot merged commit c190c0c into dlang:master Oct 7, 2017
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.

7 participants