Issue 23989 - Regression in rdmd when running an empty eval
Summary: Regression in rdmd when running an empty eval
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: tools (show other issues)
Version: D2
Hardware: All All
: P3 regression
Assignee: No Owner
URL: http://dlang.org/
Keywords: pull
Depends on:
Blocks:
 
Reported: 2023-06-13 12:56 UTC by deadalnix
Modified: 2023-06-14 14:50 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 deadalnix 2023-06-13 12:56:46 UTC
We run unit tests for modules in the following way:

rdmd -m64 -Isrc -w -debug -g -unittest -i --extra-file=src/d/object.d --eval="/* Do nothing */"

With an extra-file per file. These command are generated automatically by the build and this used to work great.

With the latest rdmd, we have the following error message:

/tmp/.rdmd-1001/eval.73D1BDC8D7573E2DF9EF23CD86830110.d(18): Error: use `{ }` for an empty statement, not `;`
Failed: ["/usr/bin/dmd", "-m64", "-Isrc", "-w", "-debug", "-g", "-unittest", "-i", "-d", "-v", "-o-", "/tmp/.rdmd-1001/eval.73D1BDC8D7573E2DF9EF23CD86830110.d", "-I/tmp/.rdmd-1001"]
make: *** [src/libd.mak:33: check-libd-d] Error 1

This is because the generated file is as follow:

module temporary;
import std.stdio, std.algorithm, std.array, std.ascii, std.base64,
    std.bigint, std.bitmanip,
    std.compiler, std.complex, std.concurrency, std.container, std.conv,
    std.csv,
    std.datetime, std.demangle, std.digest.md, std.encoding, std.exception,
    std.file,
    std.format, std.functional, std.getopt, std.json,
    std.math, std.mathspecial, std.mmfile,
    std.numeric, std.outbuffer, std.parallelism, std.path, std.process,
    std.random, std.range, std.regex, std.signals, std.socket,
    std.stdint, std.stdio,
    std.string, std.windows.syserror, std.system, std.traits, std.typecons,
    std.typetuple, std.uni, std.uri, std.utf, std.variant, std.zip,
    std.zlib;
void main(char[][] args) {
/* Do nothing */;
}
Comment 1 Richard (Rikki) Andrew Cattermole 2023-06-13 13:15:02 UTC
Not a regression in rdmd.

In dmd 2.104.0 empty statements with semicolons now error.

https://dlang.org/changelog/2.104.0.html#dmd.empty-statement-error

You do not need anything passed to the eval flag and it would not emit the semicolon.

However in saying that, rdmd in innerEvalCode should be made smarter so that it checks if last character is either a semicolon or a close brace, rather than just a semicolon. That way loops can work.

https://github.com/dlang/tools/blob/master/rdmd.d#L875

I suppose making it even smarter with comment detection ext. would be good too.
Comment 2 deadalnix 2023-06-13 13:41:12 UTC
Something used to work.

Now it doesn't work.

None of the input provided contains either a `{}` or a `;`, so clearly the the user supplied code isn't at fault.

If rdmd generates something that is now invalid, then this is rdmd's problem.

It's 100% a regression.
Comment 3 mhh 2023-06-13 14:13:21 UTC
--eval containing a comment is pretty niche. Not entirely sure how to work around the empty statement problem. I assume it's to force evaluation because of the cache or something like that? If so then you might as well just s/rdmd/dmd because you basically gain 0 from rdmd other than it being slower.

rdmd does seem to have a test-suite though so we can add this to it.
Comment 4 Dlang Bot 2023-06-14 12:54:40 UTC
@RazvanN7 created dlang/tools pull request #460 "Fix Issue 23989 - Regression in rdmd when running an empty eval" fixing this issue:

- Fix Issue 23989 - Regression in rdmd when running an empty eval

https://github.com/dlang/tools/pull/460
Comment 5 Vladimir Panteleev 2023-06-14 14:50:39 UTC
(In reply to deadalnix from comment #0)
> We run unit tests for modules in the following way:

Do you need a fix for this specific case? I don't think we can fix this general bug; we could add a hack that fixes this particular variation, but I think it only makes sense to do so if it helps someone in practice (see PR discussion).