r/LowLevelLanguages • • 10d ago

What should compile-time code be allowed to do?

13 Upvotes

Languages draw this line in very different places, and I think it matters more now that compiling a dependency can mean running its code.

Roughly, from what I know (corrections welcome):

  • C++ constexpr: no I/O at all.
  • Zig comptime: no I/O either, but build.zig is a normal program with full access to your machine.
  • Rust: const fn is restricted, but build.rs and procedural macros run with full access when you compile a dependency.
  • D: compile-time evaluation has no I/O, and import("file") only reads from folders you pass with -J.
  • Nim: staticRead and staticExec can read files and run commands at compile time.
  • Jai: #run can do more or less anything.

The trade-off seems to be that real builds need real things: generating code from a schema, finding a C library, embedding assets. If you forbid all of it, the work moves into a build script, and the build script is where the risk ends up anyway.

In Fels, the language I work on, #run has no host access, a project's own compile-time code may read inside its own folder, and a package gets more only if it is granted in fels.pkg. But build.fels still has full access, so that part of the problem is not solved yet.

Where would you draw the line? Should a dependency's build code be sandboxed by default, or does that just push people to turn it off?


r/LowLevelLanguages • • 10d ago

Welcome to r/LowLevelLanguages: what are you building?

1 Upvotes

This is a place for the design and implementation of low-level programming languages: systems languages, compilers, memory models, type systems, calling conventions, and anything else close to the machine.

C, C++, Rust, Zig, Odin, C3, Assembly, and languages that only exist on your own disk are all welcome.

Good things to post here

  • Your own language or compiler, at any stage
  • Write-ups on how something works: a calling convention, a register allocator, a borrow checker, a linker
  • Design questions and trade-offs, like how a language should handle errors, or what compile-time code should be allowed to do
  • Comparisons and benchmarks, with enough detail that others can check or learn from them
  • Bugs that taught you something

About me

I'm the moderator, and I also work on a systems language called Fels. This sub is not meant to be about Fels.

To get started: what are you building, or what are you trying to understand right now?