Project

General

Profile

Actions

Bug #11247

closed

Should position of `using` affect the behavior?

Added by ko1 (Koichi Sasada) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-06-11 trunk 50798) [x86_64-linux]
[ruby-core:69518]

Description

The following script makes two refinements refine class C.

class C
  def foo
    p C
  end
end

module R1
  refine C do
    def foo
      p R1
      super
    end
  end
end

module R2
  refine C do
    def bar
      C.new.foo
    end

    using R1

    def baz
      C.new.foo
    end
  end
end

using R2

C.new.bar
C.new.baz

R2 refines C with methods bar and baz. The difference is the place of using. bar is located before using and baz is after.

Recent fix changed behavior of this script.

  • trunk in May: C and R1, C
  • current trunk: R1, C and R1, C

This change is caused by sharing CREF between methods in same CREF scope. It reduce memory consumption (before this fix, we need one CREF per one method).

Is it acceptable change or unacceptable?

Updated by shugo (Shugo Maeda) almost 9 years ago

  • Status changed from Open to Assigned
  • Assignee changed from shugo (Shugo Maeda) to ko1 (Koichi Sasada)

Koichi Sasada wrote:

Recent fix changed behavior of this script.

  • trunk in May: C and R1, C
  • current trunk: R1, C and R1, C

This change is caused by sharing CREF between methods in same CREF scope. It reduce memory consumption (before this fix, we need one CREF per one method).

Is it acceptable change or unacceptable?

It's unacceptable. CREF should be copied at least when refinements are activated in the context.

Actions #2

Updated by ko1 (Koichi Sasada) over 8 years ago

Okay, I'll fix it.
(I need to remember code about it...)

Actions #3

Updated by ko1 (Koichi Sasada) over 8 years ago

  • Status changed from Assigned to Closed

Applied in changeset r52677.


  • vm.c (rb_vm_cref_replace_with_duplicated_cref): added.

    CREFs should not be shared by methods between `using'.
    [Bug #11247]

  • vm_insnhelper.c (vm_cref_replace_with_duplicated_cref): ditto.

  • vm.c (vm_cref_dup): should copy refinements correctly.

  • eval.c: use rb_vm_cref_replace_with_duplicated_cref().

  • eval_intern.h: add a decl. of
    rb_vm_cref_replace_with_duplicated_cref().

  • vm_eval.c (eval_string_with_cref): do not need to pass
    scope's CREF because VM can find out CREF from stack frames.

  • test/ruby/test_refinement.rb: add a test.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0