[GSoC] Trying to find a good topic
Mike Franklin
slavo5150 at yahoo.com
Fri Mar 22 06:11:06 UTC 2019
On Thursday, 21 March 2019 at 21:54:12 UTC, Johannes Pfau wrote:
> I think what we should do for betterC is to first replace the
> extern(C) hooks with a defined API. Right now, the compiler
> does not know if a runtime has feature X, it simply calls an
> extern(C) function _featureX(). If this functions is not in the
> runtime, this fails at link time only. A better approach would
> be to use a D function featureX in object.d. The compiler can
> then import object.d and see if there is a function featureX.
> If not, the runtime does not support the used feature and the
> compiler should emit an error.
>
> This way, we can implement a truly modular runtime. Just
> implement some feature and the compiler will allow using it, do
> not implement it and the compiler will error if you try to use
> it. In the extreme case, this means we can use a D compiler
> without any runtime and it will gracefully degrade to a reduced
> subset.
Yes, this is very similar to what I've been thinking, with regard
to having the runtime inform the compiler about what features of
the language are and aren't supported by the imported runtime.
I've already implemented something very similar to that for
`ModuleInfo`, `TypeInfo`, and `Exception` and that code in the
compiler today.
https://github.com/dlang/dmd/pull/7395
https://github.com/dlang/dmd/pull/7768
https://github.com/dlang/dmd/pull/7799
https://github.com/dlang/dmd/pull/7786
It allows the compiler to use design by introspection to
determine what has and hasn't been imported, and generate code
accordingly, or emit an error if something is required but can't
be found.
It's no different than how we work with code and imported modules
in our editor. For example, if you write a call to a function,
but you failed to import it; the compiler emits an error telling
you it can't be found. If you try to use a language feature that
isn't implemented and imported from druntime, the compiler can
let you know, at compile-time, that you're trying to utilize a
feature that doesn't have an implementation.
But, it's more powerful than that. If the code passing through
the compiler isn't utilizing certain features like `ModuleInfo`,
`TypeInfo` and `Exceptions`, then there's no reason for the
compiler to complain if that stuff doesn't exist in the imported
runtime. That's what the above pull requests fixed. Prior to
those PRs we had to implement a bunch unused boilerplate just to
get a build, and none of that code ever ended up in the resulting
binary anyway. Ridiculous.
Best of all, Walter seemed to like it, which was a significant
morale boost.
https://github.com/dlang/dmd/pull/7395#issuecomment-349200847
Mike
More information about the Digitalmars-d
mailing list