sway icon indicating copy to clipboard operation
sway copied to clipboard

Add a monomorphization cache to the declaration engine.

Open tritao opened this issue 3 years ago • 3 comments
trafficstars

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.

tritao avatar Aug 29 '22 13:08 tritao

My recommendation is that we leave this PR as a draft until we have at least one feature already in master in 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.

tritao avatar Aug 29 '22 16:08 tritao

so I've disabled the cache by default and we can enable it by default at a later stage

Good plan :+1:

emilyaherbert avatar Aug 29 '22 22:08 emilyaherbert

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.

tritao avatar Sep 05 '22 12:09 tritao

Closing this for now

tritao avatar Oct 27 '22 11:10 tritao