-
Notifications
You must be signed in to change notification settings - Fork 419
Synchronization updates: final and volatile fields, immutable struct #284
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
Changes from 1 commit
6dbfa92
2a182b4
505d6dd
08c2423
41b7adf
5c4425f
1ba4f88
47cde7b
310b7df
2907026
b94357b
8c92b51
32162e0
3dc0e87
df217b2
cab6395
67a82f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,12 @@ class ImmutableStruct < Synchronization::Object | |
def self.with_fields(*names, &block) | ||
Class.new(self) do | ||
attr_reader(*names) | ||
|
||
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the advantage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only performance improvements in some cases, otherwise define_method is cleaner. I wanted to avoid storing instance variables using reflection (which is optimized only on Truffle AFAIK). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One eval removed in 3dbc08f. |
||
def initialize(#{names.join(', ')}) | ||
#{names.map { |n| '@' + n.to_s }.join(', ')} = #{names.join(', ')} | ||
ensure_ivar_visibility! | ||
end | ||
|
||
def members | ||
#{names.inspect} | ||
end | ||
|
||
def self.members | ||
#{names.inspect} | ||
end | ||
|
@@ -46,6 +41,10 @@ def self.[](*args) | |
new *args | ||
end | ||
|
||
def members | ||
self.class.members | ||
end | ||
|
||
include Enumerable | ||
|
||
def each(&block) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think construction and behavior of these should mirror Ruby's
Struct
class. Again, I'm a big fan of the concept but we should be aware of the user's expectations. This is similar to the conversation regardingAgent
.Struct
is part of the Ruby standard library so it's reasonable for a user to expect anImmutableStruct
to be "an immutable Struct."There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: I'd be happy to update this class after we merge. Having built similar classes in other projects I think it would be fun to work on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are right I should have made it to match in the first place. I'll appreciate your help, I am not sure how to deal with the
new
method, where it in one case constructs classes and in the second instances.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work on it tonight. I'll be in a hotel room looking for something productive to do (I'm attending Stir Trek tomorrow).