Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are partially loaded classes visible? #6

Closed
pitr-ch opened this issue Jan 26, 2019 · 3 comments
Closed

Are partially loaded classes visible? #6

pitr-ch opened this issue Jan 26, 2019 · 3 comments

Comments

@pitr-ch
Copy link

pitr-ch commented Jan 26, 2019

Very interestingly looking project! I am curios, does the thread-safety property also guaranty that no other thread will see partially loaded class? Consider thread A, which triggers loading of a file defining class C. Then can a thread B which evaluates constant C while A is still lading the file defining C see the class C partially defined? As I read the code I think it might happen. Did you consider providing thread-safety for this as well?

Why does the project require ruby 2.4 and above? Are there technical difficulties to make it work with older Ruby versions?

@fxn
Copy link
Owner

fxn commented Jan 26, 2019

There are several thread-safety concerns addressed in the library. Some are solved with mutexes, others by using CRuby's Hash or Array. When Zeitwerk supports JRuby or TruffleRuby it will probably use Concurrent::* classes instead.

Regarding autoloading, that safety is inherited from the thread-safety of autoload and require themselves. Those are thread-safe in Ruby. The test suite has coverage precisely for the use case you're mentioning.

The version of Ruby depends on a few things. We need that Kernel#autoload calls Kernel#require, for example. In the past it called a private internal C function that was not reachable to be decorated, and that is still the case in JRuby.

Also, the library assumes that $LOADED_FEATURES stores real paths. In particular, that it resolves symlinks in UNIX. This was a change introduced in 2.4.4. Could be relaxed by programming for boths cases, real and not real, but for this version I want to get Zeitwerk right first, then perhaps add that kind of complexity. Not sure I'll want the code base to have that kind of logic right now, however, Ruby moves forward and releases are left behind. Time will tell.

@fxn
Copy link
Owner

fxn commented Jan 26, 2019

BTW, since you're are working on TruffleRuby, it might be of your interest to know the test suite has a file with some Ruby compatibility properties. I need to add code comments to document how does the library depend on each one of them. Not sure if the suite is exhastive as of today, should do a pass.

@pitr-ch
Copy link
Author

pitr-ch commented Jan 29, 2019

Right, I've forgot autoload will block other threads accessing the constant until it's fully loaded. Thanks for the answer.

The 'Ruby compatibility properties' test is very useful thanks. I'll have look later how compatible we are.

@pitr-ch pitr-ch closed this as completed Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants