move-language / move

Apache License 2.0
2.25k stars 679 forks source link

[loader] Canonicalize type identity across relinked modules #1003

Closed amnn closed 1 year ago

amnn commented 1 year ago

Store loaded structs in a BinaryCache rather than a vector so that we can look them up by their fully qualified runtime ID and name. This enables us to canonicalize the global struct index we output for a given struct even if it appears as a definition in multiple modules which can happen due to relinking).

For now, the canonical identity of a package references its runtime ID, not its defining ID. This will change in an upcoming PR.

This also simplifies struct resolution by name (which can use this cache directly rather than going via the loaded module cache, which requires access to a link context) and type loading which does not need a special code path for loading types during a module load anymore.

There is some additional complexity in the reset operation that must happen if a module load fails, which now needs to clean-up (Runtime ID, Name) -> Global Index mappings in the structs cache (as well as truncate the list of loaded structs).

Test Plan

New loader test:

$ cargo nextest -- loader_tests::relink_type_identity