https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-03-29T09:19:58ZRuby Issue Tracking SystemRuby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=639572017-03-29T09:19:58Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Modules/classes can be opened again.<br>
Your patch seems returning the last location instead of the first, is it intentional?</p>
<p>As for the implementation, it's not nice to keep iseq.<br>
It would be better to save them in (hidden) instance variable(s).</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=639962017-03-30T04:33:57Zsorah (Sorah Fukumori)her@sorah.jp
<ul></ul><p>it would be happier if we can get all of source locations where a class opened?</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=639972017-03-30T04:34:16Zsorah (Sorah Fukumori)her@sorah.jp
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li></ul><p>Turning this into a feature ticket.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=640012017-03-30T09:26:37Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>In modern Ruby, prior to actually requiring a library, its gemspec tends to be loaded. From what I understand, people require foo/version.rb from foo.gemspec, and this is the first time when namespace foo is opened.</p>
<p>Is this info that useful?</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=640032017-03-30T09:39:15ZEregon (Benoit Daloze)
<ul></ul><p>shyouhei (Shyouhei Urabe) wrote:</p>
<blockquote>
<p>In modern Ruby, prior to actually requiring a library, its gemspec tends to be loaded. From what I understand, people require foo/version.rb from foo.gemspec, and this is the first time when namespace foo is opened.</p>
<p>Is this info that useful?</p>
</blockquote>
<p>I think that's only the case of the development gemspec in the repository.<br>
If installed as a gem, the gemspec is a generated file from the metadata which does not require any other file.<br>
Example:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># -*- encoding: utf-8 -*-</span>
<span class="c1"># stub: concurrent-ruby 1.0.2 ruby lib</span>
<span class="no">Gem</span><span class="o">::</span><span class="no">Specification</span><span class="p">.</span><span class="nf">new</span> <span class="k">do</span> <span class="o">|</span><span class="n">s</span><span class="o">|</span>
<span class="n">s</span><span class="p">.</span><span class="nf">name</span> <span class="o">=</span> <span class="s2">"concurrent-ruby"</span>
<span class="n">s</span><span class="p">.</span><span class="nf">version</span> <span class="o">=</span> <span class="s2">"1.0.2"</span>
</code></pre>
<p>I agree it would be more useful to be able to collect all source locations where a Module was opened.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=640092017-03-31T06:03:20Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>shyouhei (Shyouhei Urabe) wrote:</p>
<blockquote>
<p>In modern Ruby, prior to actually requiring a library, its gemspec tends to be loaded. From what I understand, people require foo/version.rb from foo.gemspec, and this is the first time when namespace foo is opened.</p>
<p>Is this info that useful?</p>
</blockquote>
<p>I think that's only the case of the development gemspec in the repository.<br>
If installed as a gem, the gemspec is a generated file from the metadata which does not require any other file.</p>
</blockquote>
<p>Great. I didn't know this. Thank you.</p>
<blockquote>
<p>Example:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># -*- encoding: utf-8 -*-</span>
<span class="c1"># stub: concurrent-ruby 1.0.2 ruby lib</span>
<span class="no">Gem</span><span class="o">::</span><span class="no">Specification</span><span class="p">.</span><span class="nf">new</span> <span class="k">do</span> <span class="o">|</span><span class="n">s</span><span class="o">|</span>
<span class="n">s</span><span class="p">.</span><span class="nf">name</span> <span class="o">=</span> <span class="s2">"concurrent-ruby"</span>
<span class="n">s</span><span class="p">.</span><span class="nf">version</span> <span class="o">=</span> <span class="s2">"1.0.2"</span>
</code></pre>
<p>I agree it would be more useful to be able to collect all source locations where a Module was opened.</p>
</blockquote>
<p>Yes, I'm not against such feature.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=642182017-04-13T19:10:54Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I am also for this if it is easily possible.</p>
<p>I remember many years ago in the ruby 1.8.x days, before pry,<br>
I twiddled and played with the programming language Io.</p>
<p>I do not remember much about it, but one argument that it<br>
said in its favour (aside from being small/lightweight)<br>
was that it allowed introspection at run-time of pretty<br>
much everything. (I do not remember if this was correct<br>
or perhaps I may misremember.)</p>
<p>Since that, ruby got a lot more introspection support,<br>
pry, also .source_location and being able to pull in<br>
the method body and method comments (I think one of the<br>
gems of pry does that).</p>
<p>I always found this awesome.</p>
<p>Anyway to come back to the suggestion by Hidekazu Kobayashi,<br>
I agree. It would be nice to have full introspection of<br>
everything in ruby at run-time. We got a lot more access<br>
to all these various things these day, with the RubyVM and<br>
objectspace showing memory even of a "namespace" like:</p>
<p>Like in my irb:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'objspace'</span><span class="p">;</span> <span class="no">ObjectSpace</span><span class="p">.</span><span class="nf">memsize_of</span><span class="p">([])</span> <span class="c1"># => 20</span>
<span class="nb">require</span> <span class="s1">'objspace'</span><span class="p">;</span> <span class="no">ObjectSpace</span><span class="p">.</span><span class="nf">memsize_of</span><span class="p">(</span><span class="no">Kernel</span><span class="p">)</span> <span class="c1"># => 2340</span>
<span class="nb">require</span> <span class="s1">'objspace'</span><span class="p">;</span> <span class="no">ObjectSpace</span><span class="p">.</span><span class="nf">memsize_of</span><span class="p">(</span><span class="no">Object</span><span class="p">)</span> <span class="c1"># => 6484</span>
</code></pre>
<p>I think that all of this is very cool. :)</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=648542017-05-16T11:19:03Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul></ul><p>sorah (Sorah Fukumori) wrote:</p>
<blockquote>
<p>it would be happier if we can get all of source locations where a class opened?</p>
</blockquote>
<p>I hope <code>Module#source_locations</code>, too. Like below:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># Just a PoC</span>
<span class="k">class</span> <span class="nc">Module</span>
<span class="nb">attr_reader</span> <span class="ss">:source_locations</span>
<span class="k">end</span>
<span class="no">TracePoint</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:class</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">tp</span><span class="o">|</span>
<span class="n">tp</span><span class="p">.</span><span class="nf">self</span><span class="p">.</span><span class="nf">module_eval</span> <span class="k">do</span>
<span class="vi">@source_locations</span> <span class="o">||=</span> <span class="p">[]</span>
<span class="vi">@source_locations</span> <span class="o"><<</span> <span class="p">[</span><span class="n">tp</span><span class="p">.</span><span class="nf">path</span><span class="p">,</span> <span class="n">tp</span><span class="p">.</span><span class="nf">lineno</span><span class="p">]</span>
<span class="k">end</span>
<span class="k">end</span><span class="p">.</span><span class="nf">enable</span>
<span class="k">class</span> <span class="nc">Foo</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">Foo</span>
<span class="k">end</span>
<span class="nb">p</span> <span class="no">Foo</span><span class="p">.</span><span class="nf">source_locations</span> <span class="c1">#=> [["a.rb", 13], ["a.rb", 15]]</span>
</code></pre> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=711292018-03-20T17:30:43Zschneems (Richard Schneeman)
<ul></ul><p>What is the status of this proposal? I think this feature would be very nice for debugging. If being able to show all the locations of where the class is defined is not possible, I think pointing to the last location would be the most useful for me.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=837132020-01-09T03:59:13Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul><li><strong>Assignee</strong> set to <i>ioquatix (Samuel Williams)</i></li></ul><p>I might have a go at this over the next month or two.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=837152020-01-09T05:16:43Zsawa (Tsuyoshi Sawada)
<ul></ul><p>We now have <code>Module#const_source_location</code> <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: An easy way to get the source location of a constant (Closed)" href="https://bugs.ruby-lang.org/issues/10771">#10771</a>, which tells us where the module was named as a constant (which is usually the same as where the module was created). If that fulfills the purpose of this issue, then this issue should be closed as duplicate.</p>
<p>If you mean by "open a module" to use the <code>module Foo; ... end</code> construction, then notice that a module can be modified without being opened in that sense. For example,</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">module</span> <span class="nn">Foo</span><span class="p">;</span> <span class="k">end</span>
<span class="o">...</span>
<span class="no">Foo</span><span class="p">.</span><span class="nf">define_method</span><span class="p">(</span><span class="ss">:bar</span><span class="p">){}</span>
</code></pre>
<p>Hence it might make sense and be useful to ask for a feature that tells us all locations where a module was modified rather than where a module was opened. But that would mean listing all lines within a module body where a destructive operation was called, which would result in a flood of lines.</p>
<p>I don't think such feature is that much useful. It would be much more fruitful to look up the source of particular constants or methods of that module.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=915382021-04-14T04:50:08Zko1 (Koichi Sasada)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/17749">Feature #17749</a>: Const source location without name</i> added</li></ul> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=1056662023-12-13T19:05:57Zmatheusrich (Matheus Richard)matheusrichardt@gmail.com
<ul></ul><p>I want to bring this up again. This feature feels very natural to me, and it was surprising that <code>Module#source_locations</code> isn't implemented yet. What can we do to move this forward?</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=1057462023-12-20T04:19:22Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I don't think “natural” is not a good reason for adding a new method, especially regarding open class/module definitions.<br>
I am not against if the feature is proposed for the debugger.</p>
<p>Matz.</p> Ruby master - Feature #13383: [PATCH] Module#source_locationhttps://bugs.ruby-lang.org/issues/13383?journal_id=1060162024-01-04T23:44:46Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>If we decided to introduce this feature, I'm against using a plain Array. Let's use a well defined interface.</p>