-
Notifications
You must be signed in to change notification settings - Fork 370
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
Bypass validity checks when quoting Symbols and Keywords #2496
Conversation
The idea is to tell users to use Instead of putting the constructors off-limits, how about changing the code generated by quotation? I think the |
Yeah, the intention was that users should use I'm also not totally clear on what makes these symbols dangerous? Since |
If you want them to skip the check, too, you need to be sure that syntactically illegal symbols can't get there in the first place. If they can, then we still need the check.
You can see #2064 for the original PR. As an example, what should |
Well... the reasoning for #2064 banning invalid symbols is that they're unlikely to be used, and so banning them is easier -- but now the validation is imposing a runtime penalty on the very-likely path.
Going back to #1117, we can add a syntax for string-literal-Symbols (and string-literal-Keywords), and it should be pretty easy with the new reader. Then we could have something like the following: => (print (hy.repr (hy.models.Symbol "foo bar")))
#"foo bar"
=> (print (hy.repr (hy.models.Keyword "foo bar")))
:"foo bar" |
Sure, I see the problem, and I think what I've proposed, of enabling speedups when we know the input can't be syntactically illegal (because e.g. we really did read it as a symbol originally) is a viable way forward. #1117 remains possible, but unmotivated. |
I think a reasonable motivation for this is "I created a weirdly-named Symbol and now I'm trying to access/debug/repr it", as well as allowing (almost) all valid strings to also be Symbols and Keywords. |
But you can't make a symbol of this sort in the first place, under the status quo. By preventing the problem to start with, we avoid the need to add more features to the language to cope with it. This is feeling kinda circular, and a bit outside the scope of speeding up |
daf2ab5
to
42ef7e0
Compare
Well, keeping the PR to just the quoted forms still gets us most of the speedup, so I'm still happy with this. |
So it was that easy, after all. I guess I guessed correctly. |
I mean, this was one of the first things I did in my initial experimentation, it's just that I got (maybe too) focused on chasing the last bits of perf and also I always end up jumping at the chance to muck around with new syntax features |
Well, the beauty of reader macros is that you can muck around with new syntax features entirely in userland. Or in Hyrule. |
Moves checked creation of Symbols and Keywords to new functions
hy.sym()
andhy.kw()
.Without speedsym (best of 5 runs):
With speedsym (best of 5 runs):
I've been using Hy as part of an x86 instruction simulator, where we're hooking every instruction and running a bit of Hy code; the slowdown from creating Symbols (because of quoted forms) is enough to get our simulator to time out.