sway
sway copied to clipboard
Add a monomorphization cache to the declaration engine.
This introduces a cache to the declaration engine that keeps track of functions/structs that have been instantiated from a specific set of type parameters.
The approach here is relatively simple and relies on a linear search. I originally thought about having more maps to speed it up by keying on the type arguments, but since it adds a bit of complexity I opted for this for now. If it proves to be a bottleneck in the future we can always speed it up.
This was prototyped in https://github.com/tritao/declaration-engine-and-collection-context-demo/commit/c3aa5e718211ee1a88d7ebc51798280e8321e387, where these APIs where wired to the function application and struct expressions instantiation code.
However given the declaration engine is not hooked up yet here, this PR is just adding the APIs, and more proper testing will be added as we wire things up.
Closes https://github.com/FuelLabs/sway/issues/2636.
My recommendation is that we leave this PR as a draft until we have at least one feature already in
masterin that will allow us to test it (either #2631 or #2635)
I would rather get this now because it introduces new cache-aware APIs, the following PRs for those issues will depend on these APIs anyway and will build on top of this PR. I think your concerns around the stability of this makes sense though, so I've disabled the cache by default and we can enable it by default at a later stage.
so I've disabled the cache by default and we can enable it by default at a later stage
Good plan :+1:
Updated the PR with a more generic design, threaded some more error results throughout, added enum declarations to DeclarationWrapper as well for enum support.
@emilyaherbert I'm leaving the future improvements (caching generics called without type parameters) to a future issue (opening one), as right now this is blocking 2 other PRs and that can only be tested properly once the declarations are hooked to the engine anyway.
Closing this for now