r/Compilers • u/chbeyondC • 22d ago
What should compile-time code be allowed to do?
/r/LowLevelLanguages/comments/1xqu7ii/what_should_compiletime_code_be_allowed_to_do/4
u/Physical_Dare8553 22d ago
I'm leaning more and more on the side of everything including io. Obviously letting programmers program can be good and bad
1
1
u/og_hylyx 22d ago edited 22d ago
Anything. See https://github.com/kvthweatt/IDEKA for example
Ideka lets you use the entire language at comptime and inspect compiler/arch state to write portable code by accessing the `compiler.` namespace
1
u/EggplantExtra4946 22d ago
I think both unrestricted system access (within the bounds of what the OS user has permissions for) and fully restricted access (no I/O, no file system access, no networking, no launching processes, etc..) are desirable in different situations.
It would also suck to need to use 2 different languages just to have one or the other, which is also true for other things, for example memory safety.
Therefore IMO the solution is to have full safety by default and opt-in the unsafe features with a capability system, e.g. the caller function or the importer module must give the permission for that specific feature (having 2 modes, one fully safe and one fully unsafe is stupid).
1
u/flatfinger 21d ago
Sometimes it may be useful to have a compiler process untrusted code which will be executed in a sandbox, without requiring that the compiler itself be in a sandbox.
2
u/EggplantExtra4946 21d ago
Yes? I already acknowledged that safety is desirable and that it should even be the default behavior.
7
u/SwedishFindecanor 22d ago edited 22d ago
In many environments, it is important to have builds be reproducible. That means no I/O with the outside world. A build script/description should of course create files. One aspect of that is having builds be idempotent, i.e. the same intended result if you run the build process again. On the extreme end of reproducible builds, timestamps are faked, but that is going too far, and at the expense of provenance tracking -- which is also becoming more important.
I have sometimes had to write scripts to create source code because the main programming language hadn't been up to the task. Most of these have been complex static data structures created from higher-level descriptions. For embedded systems, you'd place static data structures in read-only memory sections so they don't occupy precious RAM. One extreme example of that we encounter here is compiler-compilers, such as lexer generators, parser generators and machine description language compilers. For example, machine descriptions for my compiler are in C++, but separate programs that produce C.
I'd prefer to have everything in the same language as much as possible, but also to retain a view of the build system at a high level. I don't want any source file to create lots of intermediary files that go as input into other source files: that is something that belongs at the build level.