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

Add WeakRef class #3276

Merged
merged 1 commit into from
Sep 8, 2016
Merged

Add WeakRef class #3276

merged 1 commit into from
Sep 8, 2016

Conversation

bcardiff
Copy link
Member

@bcardiff bcardiff commented Sep 7, 2016

Weak references are implemented by boehm's register_disappearing_link

@@ -0,0 +1,70 @@
require "spec"

class State
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State and Foo might eventually conflict with other specs. Maybe use names like WeakRefState and WeakRefFoo?

This is one of the reasons I want to implement file-private types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a spec-specific solution, of somehow being able to define helper classes and functions in the namespace of a describe Foo statement. This seems possible with macros, and I much prefer it as a solution than having file-private classes and methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file-private classes are a general solution, I don't understand why we should go with a less general solution. I also want to use it here, and this is not a spec. Sometimes there are some classes that only makes sense in a file, just like some functions that only make sense in a single file.

end

def self.allocate
GC.malloc_atomic(sizeof(WeakRef(T))).as(WeakRef(T))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using self instead of WeakRef(T) work? (shorter and maybe more clear)

@bcardiff
Copy link
Member Author

bcardiff commented Sep 8, 2016

I didn't update gc/null.cr to match gc/boehm.cr. Should I? They already differ on GC.add_root is missing in null.cr, but add_root seems to not be used.

@asterite
Copy link
Member

asterite commented Sep 8, 2016

I don't think gc/null.cr works anymore, and in any case it doesn't make much sense at this point :-)

@ozra
Copy link
Contributor

ozra commented Sep 8, 2016

It could be a pro to keep gc/null up to date - to maintain perspective, not unnecessarily naming/implementing funcs that are too tied to Boehm specifically (in this case, primarily the name), if a more general interface could easily be defined. For the future.

Weak references are implemented by boehm's register_disappearing_link
@bcardiff
Copy link
Member Author

bcardiff commented Sep 8, 2016

@ozra , any gc-agnostic terms you would suggest?
weak_ref_specs will fail with gc/null actually.
And due to LibGC.stackbottom in ./src/fiber.cr:68 the gc/null is not a drop-in replacement of gc/boehm .

Let's handle gc/null or rewording of the methods in a separate issue, if needed.
The api of weak_ref should not change while doing that.

@bcardiff bcardiff merged commit 7cd0fa6 into crystal-lang:master Sep 8, 2016
@bcardiff bcardiff deleted the feature/weakref branch September 8, 2016 18:41
@ozra
Copy link
Contributor

ozra commented Sep 8, 2016

Yes, I guess when the time comes, a few refactors in stdlib code won't be too much handle (not much user code should rely on GC-funcs anyway), so ignore my bike-shedding :-)

I started on a PoC-GC-experiment for Crystal a few months ago, but it's far down on my urgent list, otherwise I wouldn't even have blinked ;-) Until the parallelism model is settled, there's not much point making a hot rod anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants