-
Notifications
You must be signed in to change notification settings - Fork 196
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
Library auto-generation for non-root Modules #2319
Comments
fixed typos / error in the speudo code |
MUD now supports public/linked libraries (#1910) which might help with some of this. |
An interesting idea, I made a little proof of concept in #2461 |
Very cool to see it so soon ! We can keep the discussion there from now on, as you mentioned, there are a few technical limitations like Thank you for this PoC it's looking good already 🙌 |
We added system libraries in #3374 (still considered experimental)! You can check the docs here: https://mud.dev/world/systems#system-libraries. |
Below, a proposal for a steamlined way to call non-root Systems in a way that abstracts away the namespace it's deployed onto:
One of the main concern I have with registering some System methods as World-function selectors are the following:
First, registering those methods as World-function selectors has limits since the available space is only bytes4 (~4,294,967,295 possible function selectors), and so by the time we reach 65536 registered method in the World, the collision chance will be about 50% (birthday paradox). Even though this number seems high, it's really not that high once a given World's "builder" scene takes off.
So, if we had a way that makes not registering function selectors at the World level a viable alternative to build and interact with it, e.g., libraries to inline
world.call(SystemId, abi.encodeCall(...))
for them, it would be a preferable approach.Secondly, calling methods through World-function selectors implies that, in the event a Module is registered more than once, it will break that interface. Right now, MUD's CLI auto-generates name-spaced method (
myNamespace__foo()
), so if someone was building on top of those methods, and the module ends up being redeployed somewhere else, it will break the interface.Transforming a System interface into it's
world.call(..)
equivalent is pretty straightforward, right now it needs to be done by hand, which could lead to mismatching errors if said interfaces have to be updated; so following that logic we need something likemud worldgen
ormud tablegen
, so that libraries can be auto-generated in one command line.mud modulegen
perhaps ?Let's study a dummy system
DummySystem
to see how it plays out :From there, is is possible to import
DummyLib
anywhere, and call our DummySystem methods like this:Granted, it needs a little bit of setting things up, but it's fairly straightforward once that's done.
The issue boils down to this: come up with a code-generation script to make a library out of a given System contract ( or its interface), in the same way as shown above
The biggest advantage of doing this is that the interface for
Dummy
(or rather, the syntax to callDummy
's methods) becomes decoupled from the namespace it's deployed onto, which makes that system fully reusable. It's just a matter of deploying the module on your namespace, and initializing yourDummyLib.World
structure with the rightIBaseWorld
andnamespace
parameters.Instead of having to use the
worldgen
interfaces, which are constructed with an appendednamespace
to each methods (which breaks it if you decide to re-deploy it on anothernamespace
), this bypasses completely World-level function selectors, since we make a direct call to the related system insteadThe text was updated successfully, but these errors were encountered: