digitalmars.D - trick to avoid limits on run.dlang.io all compilers
- Steven Schveighoffer (34/34) Jan 31 I use run.dlang.io often to test things, and then when I see they
- matheus (26/27) Jan 31 Nice trick indeed, I'd make just a little change for:
- Steven Schveighoffer (4/33) Jan 31 The std/package.d module was added in 2.086.0:
- matheus (8/11) Jan 31 Interesting I used to write "import std.stdio;" (For
- Anonymouse (15/21) Jan 31 I also use it very often and I can relate.
- Steven Schveighoffer (7/19) Jan 31 Ah, very nice! Easy to paste this in at the top! I'll have to
I use run.dlang.io often to test things, and then when I see they are broken, I change to "all compilers" to see when it might have broken/changed. However, there are two limits that frustrate this process: 1. There is a limit to the amount of output that can be shown. If your test case spits out a bunch of text that changes from version to version (i.e. a big exception trace with differing line numbers), then it will truncate the result, potentially hiding the place where the issue lies. 2. There is a limit to the time your request can take. The reasons for this are obvious. However, I have discovered a trick to avoid these limits while still testing multiple versions. D has a `__VERSION__` special token that identifies the version of the compiler. For 2.100, `__VERSION__ == 2100`. Great, how can we use this? ```d static if(__VERSION__ >= 2100) { // real test code } else void main() {} ``` Now, the test code only builds on versions 2.100 and above, and a quick basic program which can build and run very quickly and outputs nothing will build on prior versions. What if the change occurred before 2.100? Simply change the range: ```d static if(__VERSION__ >= 2090 && __VERSION__ < 2100) { // real test code } else void main() {} ``` Basically, this avoids the limitations, and still allows you to test simple problems with a range of D versions without having to download them locally. -Steve
Jan 31
On Wednesday, 31 January 2024 at 19:54:24 UTC, Steven Schveighoffer wrote:...Nice trick indeed, I'd make just a little change for: import std; void main(){ static if(__VERSION__ < 2100) { return; } // Your code here writeln("Hello D"); } By the way running this returns: 2.079.1 to 2.085.1: Failure with output: ----- onlineapp.d(1): Error: module `std` is in file 'std.d' which cannot be read import path[0] = /path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos import path[1] = /path/to/dmd.linux/dmd2/linux/bin64/../../src/druntime/import ----- 2.086.1 to 2.099.1: Success and no output Since 2.100.2: Success with output: Hello D Those errors on 2.079.1 to 2.085.1 are regarded to the configuration of those compilers? Matheus.
Jan 31
On Wednesday, 31 January 2024 at 20:33:26 UTC, matheus wrote:On Wednesday, 31 January 2024 at 19:54:24 UTC, Steven Schveighoffer wrote:The std/package.d module was added in 2.086.0: https://dlang.org/changelog/2.086.0.html#std-all -Steve...Nice trick indeed, I'd make just a little change for: import std; void main(){ static if(__VERSION__ < 2100) { return; } // Your code here writeln("Hello D"); } By the way running this returns: ``` 2.079.1 to 2.085.1: Failure with output: ----- onlineapp.d(1): Error: module `std` is in file 'std.d' which cannot be read import path[0] = /path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos import path[1] = /path/to/dmd.linux/dmd2/linux/bin64/../../src/druntime/import ----- 2.086.1 to 2.099.1: Success and no output Since 2.100.2: Success with output: Hello D ``` Those errors on 2.079.1 to 2.085.1 are regarded to the configuration of those compilers?
Jan 31
On Wednesday, 31 January 2024 at 20:52:51 UTC, Steven Schveighoffer wrote:... The std/package.d module was added in 2.086.0: https://dlang.org/changelog/2.086.0.html#std-allInteresting I used to write "import std.stdio;" (For input/output) until one day like less than a year I just wrote "import std;" without realizing that was a "new feature" (2019 but anyway...) as you mentioned. xD Thanks, Matheus.
Jan 31
On Wednesday, 31 January 2024 at 19:54:24 UTC, Steven Schveighoffer wrote:[...]I also use it very often and I can relate.```d static if(__VERSION__ >= 2100) { // real test code } else void main() {} ```This is what I generally do (at the very top of the file): ```d static if (__VERSION__ < 2100) void main() {} else: import std; void main() { // ... } ``` The `else:` looks *really* awkward and hacky, but it works.
Jan 31
On Wednesday, 31 January 2024 at 20:56:49 UTC, Anonymouse wrote:This is what I generally do (at the very top of the file): ```d static if (__VERSION__ < 2100) void main() {} else: import std; void main() { // ... } ```Ah, very nice! Easy to paste this in at the top! I'll have to remember that.The `else:` looks *really* awkward and hacky, but it works.It's a nice feature of `static if` and `version` that works at declaration level. This is what it is intended for (to avoid indentation issues). -Steve
Jan 31