Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Time Function Execution #114

Open
1 of 3 tasks
Herringway opened this issue Feb 8, 2024 · 2 comments
Open
1 of 3 tasks

Run Time Function Execution #114

Herringway opened this issue Feb 8, 2024 · 2 comments

Comments

@Herringway
Copy link

Description

Now that DMD and druntime are in the same repository and DMD-as-a-library is taking shape, it should be possible to expose CTFE for use at runtime through druntime. RTFE!

What are rough milestones of this project?

  • Merge DMD and druntime
  • Improve DMD-as-a-library for better embeddability
  • Expose CTFE in druntime

How does this project help the D community?

We can enable D to be used as not just an efficient, compilable language, but also as an embeddable scripting language. This gives D a rather unique edge over its competition.

Recommended skills

  • Experience with DMD

Point of Contact

  • TBD?

References

  • TBD?
@quickfur
Copy link
Member

quickfur commented Feb 8, 2024

Honestly I don't see what this would actually accomplish in practice. What would this achieve that you can't already achieve with launching dmd via std.process to create a shared library, and loading the generated binary (with dlopen, et al, or their equivalents on other OSes) and running the result?

I actually did this in one of my projects, btw; dmd actually runs fast enough that you generally don't notice that it's actually compiling a mini subprogram at runtime. All you need is to ship dmd with your program and you're ready to go. Arguably one could encapsulate this in a neat little library and put it on dub or something so that people could do the same thing with just a couple of lines of code. It doesn't require changing the language at all.

This is not going to let you introspect the current program, of course, but for that what you really need is RTTI, which D already has. Maybe it could be expanded, but then that defeats the entire purpose of compile-time introspection, where the whole point is that it's done at compile-time without the runtime cost. Runtime introspection is indeed possible ala Java, but it comes with compile-time costs. Is that really better than what we already have now?

@Herringway
Copy link
Author

Honestly I don't see what this would actually accomplish in practice. What would this achieve that you can't already achieve with launching dmd via std.process to create a shared library, and loading the generated binary (with dlopen, et al, or their equivalents on other OSes) and running the result?

I actually did this in one of my projects, btw; dmd actually runs fast enough that you generally don't notice that it's actually compiling a mini subprogram at runtime. All you need is to ship dmd with your program and you're ready to go. Arguably one could encapsulate this in a neat little library and put it on dub or something so that people could do the same thing with just a couple of lines of code. It doesn't require changing the language at all.

This is not going to let you introspect the current program, of course, but for that what you really need is RTTI, which D already has. Maybe it could be expanded, but then that defeats the entire purpose of compile-time introspection, where the whole point is that it's done at compile-time without the runtime cost. Runtime introspection is indeed possible ala Java, but it comes with compile-time costs. Is that really better than what we already have now?

That solution is not just unnecessarily high-overhead, but it's completely unfeasible on platforms where executing binaries isn't possible. Game consoles, certain app stores, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants