Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[tool]: update VarAccess pickle implementation (#4270)
fix a bug where unpickling `annotated_vyper_module` would lead to a crash: ``` AttributeError: 'VarAccess' object has no attribute 'variable' ``` this is a blocker for tooling, for instance, titanoboa relies on pickle/unpickle to cache `CompilerData` objects: https://github.com/vyperlang/titanoboa/blob/86df8936654db2068641/boa/util/disk_cache.py#L65-L66 the underlying issue is that `pickle.loads()` calls `obj.__hash__()` for objects that are keys in a hashed data structure - namely, dicts, sets and frozensets. this causes a crash when there is a cycle in the object graph, because the object is not fully instantiated at the time that `__hash__()` is called. this is a cpython issue, reported at python/cpython#124937. @serhiy-storchaka suggested the approach taken in this PR, which breaks the loop before pickling: python/cpython#124937 (comment) note that the implementation of `__reduce__()` in this PR is safe, since there is no cycle in the hash function itself, since the recursion breaks in `VarInfo.__hash__()`. in other words, there is no possibility of `VarAccess.__hash__()` changing mid-way through reconstructing the object.
- Loading branch information