Issue 17814 - bad output of "static foreach" with -vcg-ast
Summary: bad output of "static foreach" with -vcg-ast
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-07 07:46 UTC by Rainer Schuetze
Modified: 2017-10-01 20:41 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2017-09-07 07:46:13 UTC
Dumping the AST of

static foreach(enum i; 0..3)
	mixin("int a" ~ i.stringof ~ " = 1;");

with "dmd -c -vcg-ast test.d" yields:

import object;
mixin("int a" ~ i.stringof ~ " = 1;");


I'd rather expect:

import object;
int a0 = 1;
int a1 = 1;
int a2 = 1;
Comment 1 uplink.coder 2017-09-07 11:02:24 UTC
Ah yes. -vcg-ast has not been updated for static foreach I think.
.....
It seems like it has been already though .... 
Maybe the created AST-Nodes are non-persistent .... which would make static foreach quite volatile after all
Comment 2 timon.gehr 2017-09-07 19:59:26 UTC
Dumping the AST of:

static if(true){
    enum a = 1;
}

with "dmd -c -vcg-ast test.d" yields:

import object;
static if (true)
{
	enum int a = 1;
}


Therefore, shouldn't the expected output be:

static foreach(enum i; 0..3)
{
	mixin("int a" ~ i.stringof ~ " = 1;");
}

?
Comment 3 Rainer Schuetze 2017-09-07 20:15:31 UTC
If it correctly represents the original code, it should be ok, too.

I expected the dump to have expanded all compile time transformations and lowerings, but obviously it does not. I just tried -vcg-ast on:

mixin("int a" ~ 1.stringof ~ " = 1;");

and it yields

import object;
mixin("int a1" ~ " = 1;");

so it's at some random intermediate step.
Comment 4 timon.gehr 2017-09-07 20:16:41 UTC
https://github.com/dlang/dmd/pull/7126
Comment 5 github-bugzilla 2017-09-16 00:59:07 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/4317772a132873b9b0cf527312fe8b35e8b11265
fix Issue 17814 - bad output of "static foreach" with -vcg-ast

https://github.com/dlang/dmd/commit/591c7bbfae7fa0781222dcb15a91a40214fc2976
Merge pull request #7126 from tgehr/fix17814

fix Issue 17814 - bad output of "static foreach" with -vcg-ast
Comment 6 github-bugzilla 2017-10-01 20:41:04 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/4317772a132873b9b0cf527312fe8b35e8b11265
fix Issue 17814 - bad output of "static foreach" with -vcg-ast

https://github.com/dlang/dmd/commit/591c7bbfae7fa0781222dcb15a91a40214fc2976
Merge pull request #7126 from tgehr/fix17814