Граф коммитов

55 Коммитов

Автор SHA1 Сообщение Дата
Yusuke Endoh 9438c99590 Rename error_squiggle to error_highlight 2021-06-29 23:45:49 +09:00
Yusuke Endoh e946049665 [WIP] add error_squiggle gem
```
$ ./local/bin/ruby -e '1.time {}'
-e:1:in `<main>': undefined method `time' for 1:Integer (NoMethodError)

1.time {}
 ^^^^^
Did you mean?  times
```

https://bugs.ruby-lang.org/issues/17930
2021-06-29 23:45:49 +09:00
Hiroshi SHIBATA c461b2405c
Removed needless .rb 2020-12-02 13:32:43 +09:00
Vít Ondruch 4bbb610011 Emit warning when 'RubyGems' were not properly loaded. 2020-12-02 12:46:17 +09:00
Vít Ondruch fbe37ff37a Emit warning when 'did_you_mean' was not properly loaded. 2020-12-02 12:46:17 +09:00
Vít Ondruch 0ad7f2dd19 Don't fail when 'RubyGems' are not available.
Although 'RubyGems' are always available in upstream Ruby, it might not
be available optionally when Ruby is delivered via packaging systems.
E.g. Linux distributions.
2020-12-02 12:46:17 +09:00
Vít Ondruch 55c9a95ac8 Don't fail when 'did_you_mean' is not available.
Although 'did_you_mean' is always available in upstream Ruby, it might
not be available when speed, memory, disk or network bandwidth is a
concern. This is typically the case for production environment, where
'did_you_mean' is of limited usage.

Also it might not be available optionally when Ruby is delivered via
packaging systems. E.g. Linux distributions.
2020-12-02 12:46:17 +09:00
Yuki Nishijima 0fef526606 Do not call 'gem "did_you_mean"' for now
This will slow down the time that the +require+ method takes to load DYM,
but this has caused a build failure in a certain situation:

  https://ci.appveyor.com/project/ruby/ruby/builds/29214253/job/r9u9c8p95tnlftt3#L24965

which is reported as a separate bug:

  https://bugs.ruby-lang.org/issues/16382?next_issue_id=16381

For now this commit should fix the builds, but we should come back and
add back the 'gem' call.
2019-11-30 21:08:19 -05:00
tenderlove 4102031164 Reduce system calls by activating the `did_you_mean` gem.
Activating the gem puts the gem on the load path, where simply requiring
the file will search every gem that's installed until it can find a gem
that contains the `did_you_mean` file.

Calling RubyGems' `require` will search each installed gem until it can
find one that contains the file it should require.  This means that the
more gems you have installed, the longer it can take to require that
gem.

To see this in action, lets compare the number of `stat` calls for a
"bare require" vs the number of `stat` calls for a require that follows
a gem activation by using these two programs:

```
[aaron@TC rubygems (master)]$ cat req_dym.rb
begin
  require 'did_you_mean'
rescue LoadError
end
[aaron@TC rubygems (master)]$ cat gem_dym.rb
begin
  gem 'did_you_mean'
  require 'did_you_mean'
rescue Gem::LoadError, LoadError
end
```

The first program just requires the `did_you_mean` gem, where the second
one activates the gem, then requires it.  We can count the number of
`stat` calls using `dtrace`:

```
[aaron@TC rubygems (master)]$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l

dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
     283
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l

dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
      13
```

The "bare require" version does over 10x the number of stat calls
compared to the "gem, then require" version.  Of course the number for
the first one depends on the number of gems you have installed that sort
before the `did_you_mean` gem.

Lets also look at trunk Ruby:

```
[aaron@TC rubygems (master)]$ ruby -v
ruby 2.4.0dev (2016-02-25 trunk 53940) [x86_64-darwin15]
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean req_dym.rb" | wc -l

dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
    2325
[aaron@TC rubygems (master)]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" --disable-did_you_mean gem_dym.rb" | wc -l

dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
dtrace: error on enabled probe ID 3 (ID 826: syscall::stat64:entry): invalid user access in action #1 at DIF offset 24
     685
```

This change will reduce the number of `stat` calls on trunk Ruby too,
but since this installation doesn't have the `did_you_mean` gem,
RubyGems is still reading every gem spec file so that it can raise a
`Gem::LoadError` exception with a nice error message.  If we can modify
RubyGems a little, it may be possible to drop the number of stat calls
even on a Ruby installation that doesn't have the `did_you_mean` gem.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-25 23:23:30 +00:00
usa 40f304e025 * ruby.c (usage, enable_option, disable_option, process_options): new
option `--disable_did_you_mean`.

* gem_prelude.rb: now requires did_you_mean gem by default if available.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-09 07:57:31 +00:00
nobu 8561ae195f * ruby.c (process_options): revert r30549.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-17 12:40:30 +00:00
nobu ca6a75cd38 * ruby.c (process_options): autoload rubygems.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-15 01:04:16 +00:00
nobu 7350562e5e * ruby.c (ruby_init_prelude): get rid of global namespace
pullution.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-15 00:48:16 +00:00
ryan f52c2cc24d Reduced gem_prelude to just require rubygems. Reviewed by Evan Phoenix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-14 02:02:12 +00:00
nobu 0afddf7b0a Tue Aug 17 07:38:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): include empty
	  suffix.  [ruby-core:31730]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-16 22:38:46 +00:00
nobu efbad5fa48 * gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): return truely
require-able suffixes only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-08 07:08:55 +00:00
evan 6113a5add0 Load gems properly. Fixes [ruby-core:31377]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-21 06:30:40 +00:00
evan bb43e6892c Pull rubygem's custom require into gem_prelude
This solves the gem loading issue by never touching $LOAD_PATH
in gem_prelude and instead loading all of rubygems more quickly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-20 18:30:46 +00:00
mame d1de97e0bc * gem_prelude.rb: provide workaround for gem activation. Currently,
gem activation does not work by default.  Now it can be worked
  around by requiring "rubygems" first.  [ruby-core:29486]
  a patch from Evan Phoenix in [ruby-core:31096].

* lib/rubygems.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-07 15:40:52 +00:00
naruse c659f40446 Revert r28200.
It caused many failures on test-all and following is SEGV.
./ruby -e 'require %!#{"foo/" * 10000}foo!'

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-10 04:31:08 +00:00
nobu 2b322524cd * gem_prelude.rb: load full rubygems at LoadError for activation
check.  [ruby-core:29486]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-07 21:27:16 +00:00
nobu a909ff22c8 * gem_prelude.rb (Gem::QuickLoader.load_full_rubygems_library):
suppress a warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-23 06:31:24 +00:00
nobu 80db78f51c * gem_prelude.rb (Gem::QuickLoader.load_full_rubygems_library):
get rid of creating same regexps many times.

* lib/rubygems/custom_require.rb (Kernel#require): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-23 05:37:26 +00:00
nobu 04e68d0107 * ruby.c (ruby_init_loadpath_safe): mark initial load paths.
* gem_prelude.rb (push_all_highest_version_gems_on_load_path):
  search insertion position by initial load path mark.

* lib/rubygems.rb (Gem.load_path_insert_index): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-12 15:11:10 +00:00
nobu 499bf746da * gem_prelude.rb (push_all_highest_version_gems_on_load_path):
simplified.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-30 08:59:16 +00:00
matz 0208837f08 * gem_prelude.rb (Kernel#gem): should make gem private. a patch
from Sho Hashimoto in [ruby-dev:39838].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-19 08:02:51 +00:00
naruse 303b1d7fad * gem_prelude.rb (Gem.set_home): must dup before force_encoding
and must force_encoding before gsub.
  cf. Yen Sign problem of SJIS [ruby-core:26910]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-26 11:22:44 +00:00
naruse e5b75da1fe * gem_prelude.rb (Gem.user_home): force_encoding(
Encoding.find('filesystem')). [ruby-core:26525]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-05 03:29:20 +00:00
naruse 7a884fe466 * encoding.c (get_filesystem_encoding): removed.
* encoding.c (rb_locale_encindex): added.

* encoding.c (rb_filesystem_encindex): added.

* encoding.c (rb_filesystem_encindex): add an alias 'filesystem'.
  [ruby-dev:39574]

* encoding.c (enc_find): add rdoc about special aliases.

* gem_prelude.rb (Gem.set_home): use Encoding.find('filesystem').

* gem_prelude.rb (Gem.set_paths): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-28 07:34:24 +00:00
naruse 6790c040df * gem_prelude.rb (Gem.set_home):
force_encoding(Encoding.filesystem_encoding)
  [ruby-dev:39546]

* gem_prelude.rb (Gem.set_paths): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-28 06:06:17 +00:00
yugui b5b8e5e0f4 * gem_prelude.rb (Gem.path): uses Gem.default_path as a default value
so that ruby finds gems in ~/.gem/.
  (Gem.user_home): reduced version of lib/rubygems.rb's.
  Gem.default_path needs it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-30 14:12:42 +00:00
yugui e60463034a * tool/compile_prelude.rb: replaces "require" with in-place evaluation
so that copy & paste for lib/rubygems/default.rb is not necessary.

* gem_prelude.rb: removes copied codes from lib/rubygems/defaults.rb.
  uses require instead.

* common.mk (prelude.c): adds dependency for lib/rubygems/defaults.rb.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-30 14:12:25 +00:00
yugui 618cb2cab0 * ext/purelib.rb: translates a fake path to rubygems in $" into
an alternative in $: so that Kernel.#require does not load
  more rubygems.rb.
  Resolves many failures in test/rubygems/*.

* gem_prelude.rb (Gem.load_full_rubygems_library): supports case 
  the rubygems to load is not in $(rubylibprefix).
  (Gem.path_to_full_rubygems_library): new method for the changes in
  purelib.rb and Gem.load_full_rubygems_library.
  (Gem.fake_rubygems_as_loaded): new method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-15 09:05:32 +00:00
yugui 4a1f1ba66e * gem_prelude.c (Gem.default_dir): follows the change on
lib/rubygems/default.rb in r23879

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-06-28 16:22:14 +00:00
drbrain 31c94ffeb5 Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-06-09 21:38:59 +00:00
yugui 8f1f47a072 * gem_prelude.rb (Gem.default_dir and misc.): use rubylibprefix.
follows the chagne in r23368.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-21 10:00:48 +00:00
nobu 53054c0ff6 * gem_prelude.rb (Gem::QuickLoader#push_gem_version_on_load_path):
check for requirement if the gem is installed.  a patch from
  Kyosuke MOROHASHI at [ruby-dev:38020].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-04-19 04:17:26 +00:00
drbrain 1bd7257dc8 Match full RubyGems behavior when a gem can't be found
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-23 06:47:44 +00:00
drbrain f2f3e60a8a Don't remove methods twice. [bug#555]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-22 23:06:47 +00:00
yugui aa06e69000 * encoding.c (enc_get_default_encoding): removed.
Generalizing rb_default_{external,internal}_encoding seems to be
  difficult. 
  default_external cannot be NULL even before detected. [ruby-dev:37390]

* encoding.c (rb_default_external_encoding): has its own
  implementation again.

* encoding.c (rb_default_internal_encoding): ditto.

* gem_prelude.rb: added notice.

* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): uses locale
  encoding but not ASCII-8BIT.

* ruby.c (process_options): refers less to default_external.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-12 05:25:39 +00:00
drbrain af0221e728 Don't require rubygems/defaults from gem_prelude.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-31 22:27:35 +00:00
yugui e3e645f43a merged r19975 and r19978 from ruby_1_9_1 into trunk.
* gem_prelude.rb: considers --program-suffix and prefix configure
  options.
* lib/rubygems/defaults.rb: ditto.
* test/rubygems/test_gem.rb (@default_dir_re): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-28 08:21:50 +00:00
nobu 945faf92e6 * gem_prelude.rb: disables debug and verbose flags to suppress failure
messages.  interpolation does not occur inside single quotes.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-26 10:18:39 +00:00
drbrain b61d8b6045 Update to RubyGems 1.3.1 r1909.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-10-25 22:58:43 +00:00
drbrain 215fbc639f Fix RubyGems for 1.9, r1780
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-17 23:59:31 +00:00
nobu 294a1d2270 * ruby.c (ruby_init_gems), gem_prelude.rb: check if Gem is defined
instead of Gem::Enable.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-12 01:52:53 +00:00
nobu 669d43780e * gem_prelude.rb (load_full_rubygems_library, const_missing): prevent
infinite recursion.  [ruby-dev:34539]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-12 01:51:47 +00:00
drbrain 8cc45aae94 Import RubyGems 1.1.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-31 22:40:06 +00:00
drbrain 5d613c83cc Import RubyGems r1601. [ruby-core:15381].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-10 08:00:19 +00:00
drbrain d0c819cf94 Remove methods from Gem, not QuickLoader, to fix warnings
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-24 01:38:43 +00:00