APrioriInvestments / typed_python

An llvm-based framework for generating and calling into high-performance native code from Python.
Apache License 2.0
198 stars 8 forks source link

Partially load modules from compiler cache, handling possible race condition #440

Open wllgrnt opened 1 year ago

wllgrnt commented 1 year ago

Motivation and Context

See #414 for motivation behind commits 65b622c, f0747ba, 12e35a8.

These commits introduced an issue where if two processes working in parallel generated the same function in different cache modules, our assumptions about the module -> function mapping would break and the functions would not be properly linked. (Previously this would be dealt with by marking one of the modules invalid). Commit ffd7492 handles this by maintaining a function name and a (realized name / link name / instance name), and using the latter internally.

Approach

Key approach here was ensuring that the concept of a link name did not leak outside the cache - cache users should not need to have any notion of which modules a given function is in.

How Has This Been Tested?

We use a MockDirectory class (written by @guslonergan ) to generate versions of the cache with multiple modules containing the same function, approximating the state of the cache following a race.

Types of changes

Checklist: