-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
dlopen(), random, I/O, eval, and co-expressions (co-routines) #1843
base: master
Are you sure you want to change the base?
Conversation
bc8386a
to
a5cad96
Compare
I just wrote a little tool to extract function names and types from DWARF dumps, We probably don't want to run this from the build, as it would add a dependency on |
935d382
to
bc4e6a4
Compare
68c0890
to
a781366
Compare
@elric1 here's @muhmuhten maybe you'd like to take a look? Now we're not far from being able to have builtin modules. @joelpurra I notice you have a jq-coded PRNG. Maybe now you can have a proper RNG. |
This needs a way to say: don't export the C-coded builtins. Then we could actually have something like C-coded builtins that provide file I/O with file handles and all. The jq-coded wrappers can use
Here the file handle does not even leak, so this is very idiomatic. The value of
|
f49f803
to
2ffa9d6
Compare
And now we can haz private C-coded builtins. |
Huh. I would've expected private C-coded functions by tossing the corresponding C module on the libs list separately from the module's jq code. Then you'd always bind the jq code to the importer, you'd always bind the C module to the jq part, and optionally also bind the C functions to the importer based on the modulemeta. Granted, that gets less export granularity, but pulls the export-or-not check up two levels. Not actually sure whether that's an improvement... Another thought would be to add a significant "exported" key to the modulemeta and throw out non-exported top-level functions in bind_block_referenced where it sort of thematically belongs. The exported flag on cfunctions can be automatically added to that, perhaps. |
@muhmuhten Interesting idea. That would complicate the linker code a bit, since I'd have to add a pseudo-library with a name that cannot be imported in the middle of loading the shared object. The granularity, I think, is nice. I'll think about it. |
Third one sounded nice in my head but the real benefits out of it (unexported jq functions, building a list of exported functions for modulemeta to use) probably can't be realized until the builtins are a real module. I was looking into resolving library linking not being able to drop unuseds by deferring all binding until the end but that's a bit stalled on wrapping my head around import-as. dynamically-loaded modules as a solution for the I/O problem looks pretty neat, actually. (Seems like the easiest such interface to implement would basically be explicitly throwing around file descriptors, though, or reinventing them by passing around indices into a C-side array to make FILE pointers json-representable. That's not necessarily a bad thing if we can write multiple modules with the same high-level interface though.) |
Right, I'd want to use an object like so as a file handle: For co-routines the handle namespace would have be shared by all the related |
Actually, I too dislike the new bindflag I added. I think instead I'll also add a (We could also not include non-exported functions from a library's |
fb024cc
to
46fb339
Compare
I should point out that this has become a collaboration. @leonid-s-usov isn't just reviewing the code, but producing fixes. For example, in his branch he took my one-opcode-bytecoded-function-inliner and generalized it to support inlining of larger functions and even of functions that have params! That is truly fantastic! (Though, obviously, because of the 16-bit instruction count limit, this has to be used sparingly, and will be.) |
So the interesting case that
and we want So, |
when considering to add RET_JQ at the end of a block. currently two instructions backtrack: BACKTRACK and TAIL_OUT
In case a path gets deleted, we should iterate arrays backwards in path/1 context.
Could the non-I/O parts of this PR be split out to another PR that would be easier to review & get merged? |
What's blocking this PR? Does it have unfinished features? Does it have difficult merge conflicts? If it's too large too review, I could take a stab at splitting it into smaller, more focused PRs, via careful git rebase (I've done this kind of thing often). I'd also suggest an |
Mainly I think we need a careful review of the design (i.e., the signatures and semantics of the new builtins) and the code too, of course. And I need the energy to finish it, or someone who has that energy to step in.
Oh yes, that's on my list of wants, and all of |
I'm well familiar with the internals MT19937, the PRNG used by Python and many others. Although it's not cryptographically secure, I have context from its API design.
I think the API should be:
I think that Would it make sense to have a random API for jq's big decimals? How would that work with gojq? With it using Outside of random, I think there's plenty of room to improve the UTF-8 and byte APIs. I've been thinking about this in other contexts, so I have lots of thoughts here. If that would be welcome, I could open an issue. If splitting random off into a separate PR and polishing it would be welcome, I'd be willing. |
Besides random, the rest seems tightly intertwined. Why is Would coexpressions be useful broadly outside working with file handles? It might be able to be isolated from the IO changes. With the amount of new syntax it introduces, I think it would benefit from its own PR, to be able to discuss its syntax and semantics. |
Pretty much. I suppose One thing I've wondered is whether we should try to do a Haskell IO monad like thing where only the main program can "do I/O", and all modules that want to do I/O need to get utility closures from the main program. But... in jq that would just be very unwieldy.
To
Any time you want breadth-first recursive traversal you'll need coexpressions. Long ago when I used Icon I rarely used coexpressions, so they might not be that necessary most of the time. |
Also, consider some options for implementing
(1) would be too slow. |
Well, jq 1.7 does have something of a bignum feature, so we could make this better. I agree that it should probably be named |
It would be good to finish the
I agree. I should remove it completely. |
I've a branch that adds binary support :) fq-style. |
This PR adds:
/dev/urandom
) and Windows (via CNG)"jq/..."
"jq/io"
module that have more advanced I/O facilities using file handles (the user must use the-I
/--io
command-line option to enable this)"jq/proc"
module that has bindings forpopen(3)
andsystem(3)
(the user must use the-I
/--io
command-line option to enable this)unwind(protect)
-- basically afinally
try ... catch ...
#1608, and introduces a try-catch-finally as welleval
See README.plugins.md for details on how to write C-coded functions for jq modules.
Windows builds, but who knows if it works.
TBD: