-
Notifications
You must be signed in to change notification settings - Fork 15
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
Turn the builtins into a .007 file; compile and cache it #185
Comments
Or how about this: add a test that compiles the built-ins and compares the result against Yes, I like that a lot better than compiling at startup. I keep forgetting that we have a good solution for mitigating the drawbacks of code duplication. |
I'm also thinking we might leave the normal grammar alone, and subclass to shove in the extra rules. Feels like that'd also make abuse of the ⦃...⦄ parsing (or accidental contact with it in any way) a lot less likely. |
This method also — I think; this kind of hurts to consider in depth — gets us out of a bootstrapping problem that I hadn't anticipated at all. Namely that, the more realistic This is a non-issue if we load |
Having started down the path of this change in local code, I can now state that initiating the built-in opscope is
The good news is that this looks very doable. Even better, it feels like a best-of-both worlds kind of thing: we get to mix together these two concerns in the source file ( |
We can do this in stages:
|
Here are some loose timings for how long it takes right now to populate the built-ins:
(8% time saving on the master branch, just from not loading the builtins at all.)
(24% time savings on the #242 branch. That's quite a lot; might account for at least some of the slowdown we're seeing on that branch.) It strikes me that one perhaps simple way to reduce the startup cost for the builtins is simply to run all the builtin-building code at But I suspect that'll also run us straight into the rakudobug where subs don't survive well in constants. (RT #127089) |
At the cost of intercepting their calls in the runtime, this change makes the builtins() sub independent of $input and $output parameters, and therefore independent of the input/output objects injected into the runtime altogether. This is a first step in making the builtins more static/constant, in line with the vision outlined in #185.
The builtins currently get installed in quite a clumsy way:
...by iterating through a list of pairs and running
declare-var
on each of them.Experience with debugging that bit of 007 (which often happens when frames and scopes break in some unpleasant way) tells me that it's not at all useful that the builtins get manually declared in this way. To be honest, I'd prefer it if they were just miraculously available somehow.
(Also,
declare-var
contains some frame-displacing logic that we don't use at all.)What we probably want is to simply replace the "setting pad" with the right stuff, all in one simple assignment. What's the "setting pad"? In
_007::Runtime
'sBUILD
, we create a new artificial block, and enter it:Shortly after, we load the builtins in that painstaking way.
But
.enter
has created a frame for us, and that frame has a pad:What we should be doing is simply put a
Val::Object
there which, as nearly as possible, already comes pre-filled with all the setting stuff.Which tells me
Builtins.pm
's actual job should be to create thisVal::Object
and return it to the runtime. Not, as it currently does, return a list of pairs of things for the runtime to put together bit by bit, like IKEA furniture.It would perhaps be fun to build such a version of
Builtins.pm
... once. But the fact is that we already have a component that can build pads for us: the compiler. All we need to do is create a 007 version of the builtins.Some of the built-in subs (and methods) can probably even be expressed as 007 code!
say
andprompt
can't, butmin
andmax
certainly can (update: these are now gone), and probably a fair number of the operators. For those that can't, I propose using some special kind of block, like ⦃...⦄, to embed Perl 6 code nicely intobuiltins.007
. (And then try really hard to make sure that this mechanism can only be used on that file.) Then we parse through everything, and finally extract theVal::Object
that was generated, and serialize it toBuiltins.pm
.This should happen at
bin/007
startup, I think. Or some similarly early place.Builtins.pm
should be considered a projection, and if it's blown away or made obsolete by a newerbuiltins.007
, things should still work in the sense that a new betterBuiltins.pm
will just be written behind the scenes without any fuss. Of course, the lower the extra startup cost for just checking this, the better.The text was updated successfully, but these errors were encountered: