ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: ko1@atdot.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:90302] [Ruby trunk Feature#15287] New TracePoint events to support loading features
Date: Wed, 05 Dec 2018 07:24:03 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-75409.20181205072401.190ca9d5414d1e86@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15287.20181107051954@ruby-lang.org

Issue #15287 has been updated by ko1 (Koichi Sasada).


Matz agreed about naming of "script_compiled".

If others especially English natives have ideas, please tell me.
If no, I'll commit "script_compiled" event some days later.

----

I'm reconsidering "method_added" event because there are several other points we change the class/module methods. We already has several hooks provided by method hook:

```C
    rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "prepended", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
    rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
```

Maybe other events we want to introduce. But (this is internal reason) we don't have enough bits to represent them.

There are several ideas:

* (1) add all events above (change internal)
* (2) add one event (`extended`, for example) and add new method to recognize which kind of extension Ruby did (for example, `tp.extension_type #=> :undef`)

Maybe we have no time to conclude this spec so I think it is difficult to introduce this feature (method_added) in Ruby 2.6.


----------------------------------------
Feature #15287: New TracePoint events to support loading features
https://bugs.ruby-lang.org/issues/15287#change-75409

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 2.6
----------------------------------------
# Abstract

I propose the following new TracePoint events:

* `loaded` (invoked after `require`/`load`)
* `method_added` (invoked after method definition)

# Background

Sometimes we need to hook loading iseq. For example, checking loading files and so on.
Also we want to know what kind of methods are defined.

For both purpose, we can use some hook methods such as `Module#method_added` and so on.
However, defining methods we can override this features.
So that if we have two tools/libraries using this feature, they can be conflicted.

# Proposal

Introduce new TracePoint events:

* `loaded` (invoked after `require`/`load`)
* `method_added` (invoked after method definition)

Also the following methods can be added:

* Active only `loaded` event:
  * `TracePoint#loaded_feature` returns feature name.
  * `TracePoint#loaded_iseq` returns `RubyVM::InstructionSequence` object (MRI only, internal feature)

# Optional proposal

Add `class_added` alias name for `class` event.




-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2018-12-05  7:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15287.20181107051954@ruby-lang.org>
2018-11-07  5:19 ` [ruby-core:89742] [Ruby trunk Feature#15287] New TracePoint events to support loading features ko1
2018-11-07  8:15 ` [ruby-core:89744] " shevegen
2018-11-22  8:02 ` [ruby-core:89959] " ko1
2018-12-05  7:24 ` ko1 [this message]
2018-12-10  7:36 ` [ruby-core:90401] " ko1
2018-12-10 13:38 ` [ruby-core:90405] " eregontp
2018-12-10 19:48 ` [ruby-core:90407] " tenderlove
2018-12-10 21:11 ` [ruby-core:90410] " ko1
2018-12-12  5:52 ` [ruby-core:90436] " ko1
2018-12-27 22:10 ` [ruby-core:90754] " eregontp
2019-02-06 23:27 ` [ruby-core:91443] " eregontp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-75409.20181205072401.190ca9d5414d1e86@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).