ssvb's blog

By ssvb, history, 4 years ago, In English

DMD compiler is expected to support import std; directive starting from version v2.086.0, as documented in its changelog. This may be very useful for competitive programming because just a single line of code can provide access to the whole standard library. Similar to how just a single line #include <bits/stdc++.h> is often used in C++ solutions instead of multiple include directives.

But something seems to be wrong with the D compiler used by the codeforces platform, as can be checked via https://codeforces.net/problemset/customtest

This code gets stuck:

import std;
void main() { printf("hello\n"); }

OUTPUT:

Replacing import std; with import std.stdio; helps:

import std.stdio;
void main() { printf("hello\n"); }

OUTPUT:

MikeMirzayanov, could you please check what's wrong? Thanks!

PS. I would also appreciate if my solution 114610491 submitted during Educational Codeforces Round 108 (рейтинговый для Див. 2) could be re-judged after fixing the compiler. But that's not super important in the grand scheme of things.

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Something has changed since then. The test program still fails, but the error message is different now:

Aborting from 
object.Error@(0): Access Violation

Runtime error: exit code is 1
=====
Used: 31 ms, 60 KB

Does it mean that the codeforces admins are upgrading/tweaking/debugging something?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +18 Vote: I do not like it

    Looks like problem is resolved now. Updates are apparently happening behind the scene, sometimes without any announcements. Resubmitting exactly the same old code 114610491 as 142670681 now gives me "Happy New Year!" instead of "Idleness limit exceeded on test 1".

    Thanks a lot for the fix! Even though the experienced D language users probably wouldn't acknowledge this, the problem used to be a major trap for any beginner. That's because even the most trivial programs in D language require importing a bunch of modules ("import std.stdio" for printing to stdout, "import std.array" for dealing with arrays, "import std.algorithm" for sorting, "import std.string" for dealing with strings and so on). Figuring out what exactly needs to be imported is tedious for beginners, so it's tempting to just "import std" for everything and be done with that. Not getting unexpectedly killed by the "idleness limit" is a much better user experience.

    Now I wonder if we can also ask MikeMirzayanov for a 64-bit LDC compiler on Codeforces in order to achieve performance parity with C++ and Rust languages? The currently used DMD compiler is notorious for generating significantly slower code than GDC and LDC compilers (this can be easily confirmed on AtCoder, which supports all 3 compilers for D language). Should I write a new blog with this request?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      Yeah, at some point of time, import std; started to just work here. Thanks to Mike!

      The performance of DMD-compiled binaries is not the end of the world, enough for most contest problems. But yeah, LDC would be best. For example, I often see hos.lyric switching from DMD (D) to GCC (C++) for harder problems, and I guess one reason is to be sure of the performance.