On 17 February 2014 21:03, Martin Sucha <[email protected]> wrote:
> I would add some compiler features:
> - ability to tell the compiler to generate several compiled versions of
> the same code with different compiler hints and switch between them at
> runtime (using arbitrary expression to decide which variant to use),
> i.e. speed vs. power-saving optimized code [inspired by one of the
> LLVM talks @ FOSDEM]
>
>
That is an interesting possibility. Using the same package with different
compiled-in "hints"/"traits"/"flags" would allow for all kinds of neat
stuff.
> I guess it could something like:
> switch_hints {
> if (is_powersave_on()) powersave
> else default
> }
> {
> // some code
> }
>
> It could be defined such that a compiler that totally ignores the
> hints, generates a single variant and just executes the expression(s)
> is conformant
>
For that definition to work sanely, you would have to ensure that the
alternatives are functionally equivalent. In contrast to C, I don't want to
put any expectations into the semantics that depend solely on the
programmers attention to nasty details and corner cases. And requiring
compiler to check the equivalence would cripple the expressiveness of the
hinted code possibly much more than boolean expression contracts do for all
the other code.
However, I can see this mechanism used to swap non-equivalent
implementations. Not with such a switch though. That would be kind of ugly.
The Go solution is to tag entire files, and only include in a build the
files that match the build tags. A similar solution could be devised on a
more fine-grain scale (the tags would be defined as part of import instead
of just once during the build).
-- Jirka Z.
_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/listinfo/helenos-devel