mustermann icon indicating copy to clipboard operation
mustermann copied to clipboard

Use WeakRef instead of ObjectSpace::WeakMap?

Open nirvdrum opened this issue 5 years ago • 2 comments

Mustermann::EqualityMap uses ObjectSpace::WeakMap directly in its implementation. According to the docs for ObjectSpace::WeakMap, that class should not be used directly:

This class is mostly used internally by WeakRef, please use lib/weakref.rb for the public interface.

Of course, it exists and works, but using WeakRef instead looks like the safer option.

nirvdrum avatar Oct 17 '18 22:10 nirvdrum

It looks intentional. weaklef is a really thin wrapper for Object::Weakmap.

I'll let @rkh answer to this issue.

namusyaka avatar Nov 03 '18 12:11 namusyaka

I think that means you're relying on implementation details. TruffleRuby's WeakRef has a different implementation that adheres to the interface, for instance. We don't currently have ObjectSpace::WeakMap, so we fall back to the Array implementation in Mustermann. We'll add ObjectSpace::WeakMap, but this caught my eye as an issue that could also be addressed by using the suggested public interface.

nirvdrum avatar Nov 04 '18 16:11 nirvdrum