Rubinius - Tales from the trenches @ Railsclub.ru 2012

Rubinius - Tales from the trenches @ Railsclub.ru 2012

B012094b37ab6946c44eaa41d7828478?s=128

Dirkjan Bussink

September 15, 2012
Tweet

Transcript

  1. Rubinius Tales from the trenches

  2. Dirkjan Bussink @dbussink

  3. None
  4. Huh?

  5. Class.stub!(:new).and_return(MyClass)

  6. Beyond imagination

  7. None
  8. None
  9. class Foo class << self class << self def foo;

    end end end end class Bar < Foo; end p Bar.singleton_class.foo
  10. Liskov Substitution Principle

  11. class SomeList < Array def push(value) value = Proxy.new(value) if

    value.is_a?(String) ... end end alias_method :<<, :push end Unmarshal uses Array#<<
  12. StackError

  13. None
  14. class PropertySet < Array alias_method :superclass_slice, :[]= private :superclass_slice def

    []=(name, property) self << property end def <<(property) found = named?(property.name) add_property(property) if found superclass_slice(index(property), property) else super end end end WUT? Ugh Oh, let’s change the meaning!
  15. class PropertySet def []=(name, property) add_property(property) end def <<(property) add_property(property)

    end def add_property(property) clear_cache @order << property unless @order.include?(@property) @properties[property.name] = property end end
  16. IDIOT

  17. GCC...

  18. vm/builtin/regexp.cpp:312: warning: control may reach end of non-void function

  19. None
  20. GCC is fucking stupid. Avoid inane gcc type punning warning

    Work around GCC's broken strict aliasing checks. gcc 4.2.1 on freebsd 9 wants a newline at the end Make the gcc gods happy Make the stupid compiler gods happy Appease GCC 4.3
  21. Ruby is weird

  22. class MyClass def to_ary puts "we're here" [1] end end

    def my_method arg yield arg end my_method(MyClass.new) do |*arg| p arg end we're here [#<MyClass:0xX>] we're here [1] we're here [[1]] [#<MyClass:0xX>] A B C D Call to_ary and ignore
  23. can't define singleton method "method" for Float obj = 2.0

    def obj.method puts "method on float instance" end obj.method No singleton methods on Numeric
  24. class Numeric def singleton_method_added(name) end end obj = 2.0 def

    obj.method puts "method on float instance" end obj.method method on float instance Singleton method on a Numeric!
  25. 3 4 5 6 Becomes true on first condition, false

    on second 10.times do |i| if (i == 3) .. (i == 6) puts i end end
  26. Ruby’s C-API

  27. There is no C-API just internals of MRI that people

    use
  28. VALUE rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) {

    NEWOBJ(data, struct RData); if (klass) Check_Type(klass, T_CLASS); OBJSETUP(data, klass, T_DATA); data->data = datap; data->dfree = dfree; data->dmark = dmark; return (VALUE)data; } MRI internals
  29. NotImplementedError: method `class' called on terminated object (0xXXXXXXXX) Inspect object

    created with rb_data_object_alloc
  30. None
  31. GC can be hard

  32. C Stack Object* Object* Heap 1 Object Object Heap 2

    Object Object GC moves objects
  33. None
  34. Old Young String Array Object String String Hash

  35. None
  36. Concurrency is tricky

  37. Out of order execution

  38. a = 0 b = 0 c = 0 d

    = 0 Core 1 Core 2 a = 1 c = 1 b = 2 d = 2 Statements can be executed in different order
  39. addr = Address.new addr.street = "Somestreet" addr.number = 1 shared_addr

    = addr shared_addr => nil shared_addr => #<Address:0x1c @street="Somestreet" @number=1> shared_addr => #<Address:0x1c> shared_addr => #<Address:0x1c @street="Somestreet"> shared_addr => #<Address:0x1c @number=1> shared_addr = addr executed before other assignments
  40. addr = Address.new addr.street = "Somestreet" addr.number = 1 Rubinius.memory_barrier

    shared_addr = addr
  41. Try your code We secretly love weird stuff

  42. спасибо