Forum: Ruby-core [ruby-trunk - Bug #7844][Assigned] include/prepend satisfiable module dependencies are not satisfied

F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-02-13 14:56
(Received via mailing list)
Issue #7844 has been reported by mame (Yusuke Endoh).

----------------------------------------
Bug #7844: include/prepend satisfiable module dependencies are not
satisfied
https://bugs.ruby-lang.org/issues/7844

Author: mame (Yusuke Endoh)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor
ruby -v: ruby 2.0.0dev (2013-02-13 trunk 39225) [x86_64-linux]


Hello,

  module P
    def m; puts "P"; super; end
  end
  module Q
    def m; puts "Q"; super; end
    include P
  end
  module R
    def m; puts "R"; super; end
    prepend Q
  end
  module S
    def m; puts "S"; super; end
    include R
  end
  class A
    def m; puts "A"; super; end
    prepend P
    include S
  end
  A.new.m #=> P, R, A, S, Q

This code has five module dependencies, but only two are satisfied.

- Q includes P, which is not satisfied: P#m precedes Q#m.
- R prepends Q, which is not satisfied: R#m precedes Q#m.
- S includes R, which is not satisfied: R#m precedes S#m.
- A prepends P, which is satisfied: P#m precedes A#m.
- A includes S, which is satisfied: A#m precedes S#m.

Note that all the dependencies can be satisfied at all:

  A.new.m #=> Q, P, A, S, R

--
Yusuke Endoh <mame@tsg.ne.jp>
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-02-13 15:23
(Received via mailing list)
Issue #7844 has been updated by matz (Yukihiro Matsumoto).


I believe the behavior is undefined (or implementation defined) when
module dependency has contradiction.
And preferably error should be raised when contradiction detected.

Matz.

----------------------------------------
Bug #7844: include/prepend satisfiable module dependencies are not
satisfied
https://bugs.ruby-lang.org/issues/7844#change-36235

Author: mame (Yusuke Endoh)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor
ruby -v: ruby 2.0.0dev (2013-02-13 trunk 39225) [x86_64-linux]


Hello,

  module P
    def m; puts "P"; super; end
  end
  module Q
    def m; puts "Q"; super; end
    include P
  end
  module R
    def m; puts "R"; super; end
    prepend Q
  end
  module S
    def m; puts "S"; super; end
    include R
  end
  class A
    def m; puts "A"; super; end
    prepend P
    include S
  end
  A.new.m #=> P, R, A, S, Q

This code has five module dependencies, but only two are satisfied.

- Q includes P, which is not satisfied: P#m precedes Q#m.
- R prepends Q, which is not satisfied: R#m precedes Q#m.
- S includes R, which is not satisfied: R#m precedes S#m.
- A prepends P, which is satisfied: P#m precedes A#m.
- A includes S, which is satisfied: A#m precedes S#m.

Note that all the dependencies can be satisfied at all:

  A.new.m #=> Q, P, A, S, R

--
Yusuke Endoh <mame@tsg.ne.jp>
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-02-13 15:39
(Received via mailing list)
Issue #7844 has been updated by mame (Yusuke Endoh).


matz (Yukihiro Matsumoto) wrote:
> I believe the behavior is undefined (or implementation defined) when module
dependency has contradiction.
> And preferably error should be raised when contradiction detected.

Thank you, I agree with the policy.

However, is there any 'contradiction' in this case?  No pair of these
dependencies conflicts.  There are no cycles.
Actually, they are satisfiable.  A solution can be found by using the
topological sorting.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #7844: include/prepend satisfiable module dependencies are not
satisfied
https://bugs.ruby-lang.org/issues/7844#change-36239

Author: mame (Yusuke Endoh)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor
ruby -v: ruby 2.0.0dev (2013-02-13 trunk 39225) [x86_64-linux]


Hello,

  module P
    def m; puts "P"; super; end
  end
  module Q
    def m; puts "Q"; super; end
    include P
  end
  module R
    def m; puts "R"; super; end
    prepend Q
  end
  module S
    def m; puts "S"; super; end
    include R
  end
  class A
    def m; puts "A"; super; end
    prepend P
    include S
  end
  A.new.m #=> P, R, A, S, Q

This code has five module dependencies, but only two are satisfied.

- Q includes P, which is not satisfied: P#m precedes Q#m.
- R prepends Q, which is not satisfied: R#m precedes Q#m.
- S includes R, which is not satisfied: R#m precedes S#m.
- A prepends P, which is satisfied: P#m precedes A#m.
- A includes S, which is satisfied: A#m precedes S#m.

Note that all the dependencies can be satisfied at all:

  A.new.m #=> Q, P, A, S, R

--
Yusuke Endoh <mame@tsg.ne.jp>
0e610136db92027148906c92d57fdb36?d=identicon&s=25 marcandre (Marc-Andre Lafortune) (Guest)
on 2013-02-14 17:25
(Received via mailing list)
Issue #7844 has been updated by marcandre (Marc-Andre Lafortune).


As I stated before (#1586), I feel that the solution is easy:

A.ancestors = [*A.prepended_modules.flat_map(&:ancestors), A,
*A.included_modules.flat_map(&:ancestors), *A.superclass.ancestors]

In the given example, this would be:

  P, A, S, Q, P, R, Object, Kernel, BasicObject

It makes absolutely no sense to me that R could come before A and
believe it is clearly a major problem. R is never prepended, nor
included in a prepended module!

Matz: how would you explain that R can be called before A in that
example?

----------------------------------------
Bug #7844: include/prepend satisfiable module dependencies are not
satisfied
https://bugs.ruby-lang.org/issues/7844#change-36294

Author: mame (Yusuke Endoh)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor
ruby -v: ruby 2.0.0dev (2013-02-13 trunk 39225) [x86_64-linux]


Hello,

  module P
    def m; puts "P"; super; end
  end
  module Q
    def m; puts "Q"; super; end
    include P
  end
  module R
    def m; puts "R"; super; end
    prepend Q
  end
  module S
    def m; puts "S"; super; end
    include R
  end
  class A
    def m; puts "A"; super; end
    prepend P
    include S
  end
  A.new.m #=> P, R, A, S, Q

This code has five module dependencies, but only two are satisfied.

- Q includes P, which is not satisfied: P#m precedes Q#m.
- R prepends Q, which is not satisfied: R#m precedes Q#m.
- S includes R, which is not satisfied: R#m precedes S#m.
- A prepends P, which is satisfied: P#m precedes A#m.
- A includes S, which is satisfied: A#m precedes S#m.

Note that all the dependencies can be satisfied at all:

  A.new.m #=> Q, P, A, S, R

--
Yusuke Endoh <mame@tsg.ne.jp>
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2014-06-02 02:34
(Received via mailing list)
Issue #7844 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Bug #7844: include/prepend satisfiable module dependencies are not
satisfied
https://bugs.ruby-lang.org/issues/7844#change-46992

* Author: Yusuke Endoh
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category:
* Target version: next minor
* ruby -v: ruby 2.0.0dev (2013-02-13 trunk 39225) [x86_64-linux]
* Backport:
----------------------------------------
Hello,

~~~ruby
module P
  def m; puts "P"; super; end
end
module Q
  def m; puts "Q"; super; end
  include P
end
module R
  def m; puts "R"; super; end
  prepend Q
end
module S
  def m; puts "S"; super; end
  include R
end
class A
  def m; puts "A"; super; end
  prepend P
  include S
end
A.new.m #=> P, R, A, S, Q
~~~

This code has five module dependencies, but only two are satisfied.

- `Q` includes `P`, which is not satisfied: `P#m` precedes `Q#m`.
- `R` prepends `Q`, which is not satisfied: `R#m` precedes `Q#m`.
- `S` includes `R`, which is not satisfied: `R#m` precedes `S#m`.
- `A` prepends `P`, which is satisfied: `P#m` precedes `A#m`.
- `A` includes `S`, which is satisfied: `A#m` precedes `S#m`.

Note that all the dependencies can be satisfied at all:

~~~ruby
A.new.m #=> Q, P, A, S, R
~~~

--
Yusuke Endoh <mame@tsg.ne.jp>
This topic is locked and can not be replied to.