The recent discussion of NamedTuple in #22194 and here on Discourse reminded me of a question I continue to ponder for getfield overloading: how could we make it general enough to allow modules to be implemented as a user-level feature?
For example, can the Module resolution optimizations in codegen (and inference) be generalized a little bit without destroying compiler performance.
Jeff touched on this in the 1974 thread:
The biggest issue is that modules have special behavior with respect to … In theory, this would just be another method of getfield, but the problem is that we need to resolve module references earlier since they basically behave like global variables. I think we will have to keep this a special case in the behavior of … There is also a bit of a compiler efficiency concern, due to analyzing (# types) * (# fields) extra function definitions. But for that we will just see what happens.
but I think that comment was mainly considering the cost of a full method lookup everywhere – obviously that would be prohibitive. However, the “deferred binding” aspect of getfield keeps leading me to look for an analogy with reader macros. It might not be too expensive to add one more binding table specific to getfield, akin to *readtable* – which apparently isn’t too expensive to query token-wise in many Lisps?