Skip to content

Commit 5010005

Browse files
[GR-28021] Backports for 21.0.0 batch1
PullRequest: truffleruby/2244
2 parents bdacac1 + 64f17ff commit 5010005

File tree

29 files changed

+5020
-4886
lines changed

29 files changed

+5020
-4886
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ Compatibility:
3434
* `**kwargs` now accept non-Symbol keys like Ruby 2.7.
3535
* Updated the Unicode Emoji version (#2173, @wildmaples).
3636
* Added `Enumerator::Yielder#to_proc`.
37+
* Implemented `Enumerator::Lazy#eager`.
3738

3839
Performance:
3940

4041
* Refactor and implement more performant `MatchData#length` (#2147, @LillianZ).
4142
* Refactor and implement more performant `Array#sample` (#2148, @LillianZ).
43+
* `String#inspect` is now more efficient.
4244

4345
Changes:
4446

bench/micro/string/inspect.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
result = ""
10+
simple = "abcdefghij\nklmnopqrst\nuvwxyz"
11+
utf8 = "abçdéfghîĵ\nklmñöpqrst\nuvwxyz"
12+
13+
benchmark "core-string-inspect-simple" do
14+
result = simple.inspect
15+
end
16+
17+
benchmark "core-string-inspect-utf8" do
18+
result = utf8.inspect
19+
end

spec/tags/command_line/dash_upper_w_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ slow:The -W command line option with 1 sets $VERBOSE to false
33
slow:The -W command line option with 2 sets $VERBOSE to true
44
slow:The -W command line option with :no-deprecated suppresses deprecation warnings
55
slow:The -W command line option with :no-experimental suppresses experimental warnings
6-
fails:The -W command line option with :no-deprecated suppresses deprecation warnings
76
fails:The -W command line option with :no-experimental suppresses experimental warnings

spec/tags/core/enumerator/lazy/eager_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
slow:Warning.[]= emits and suppresses warnings for :deprecated
22
slow:Warning.[]= emits and suppresses warnings for :experimental
3-
fails:Warning.[]= emits and suppresses warnings for :deprecated
43
fails:Warning.[]= emits and suppresses warnings for :experimental
54
slow:Warning.[]= :experimental emits and suppresses warnings for :experimental
65
fails:Warning.[]= :experimental emits and suppresses warnings for :experimental

spec/tags/language/predefined_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ slow:The predefined global constant ARGV contains Strings encoded in locale Enco
66
slow:Global variable $0 is the path given as the main script and the same as __FILE__
77
slow:Global variable $? is thread-local
88
slow:Global variable $0 actually sets the program name
9-
fails:Predefined global $, warns if assigned non-nil
10-
fails:Predefined global $; warns if assigned non-nil
119
fails:$LOAD_PATH.resolve_feature_path returns what will be loaded without actual loading, .rb file
1210
fails:$LOAD_PATH.resolve_feature_path returns what will be loaded without actual loading, .so file
1311
fails:$LOAD_PATH.resolve_feature_path raises LoadError if feature cannot be found

spec/tags/language/rescue_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
fails:The rescue keyword raises SyntaxError when else is used without rescue and ensure
2-
fails:The rescue keyword inline form rescues with multiple assignment

src/launcher/java/org/truffleruby/launcher/CommandLineParser.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,46 @@ private void processArgument() throws CommandLineException {
340340
break;
341341
case 'w':
342342
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.TRUE);
343+
setAllWarningCategories(true);
343344
break;
344345
case 'W': {
345346
String temp = grabOptionalValue();
346347
if (temp == null) {
347-
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.TRUE);
348+
temp = "2";
349+
}
350+
if (temp.startsWith(":")) {
351+
switch (temp) {
352+
case ":deprecated":
353+
config.setOption(OptionsCatalog.WARN_DEPRECATED, true);
354+
break;
355+
case ":no-deprecated":
356+
config.setOption(OptionsCatalog.WARN_DEPRECATED, false);
357+
break;
358+
case ":experimental":
359+
config.setOption(OptionsCatalog.WARN_EXPERIMENTAL, true);
360+
break;
361+
case ":no-experimental":
362+
config.setOption(OptionsCatalog.WARN_EXPERIMENTAL, false);
363+
break;
364+
default:
365+
LOGGER.warning("unknown warning category: `" + temp.substring(1) + "'");
366+
break;
367+
}
348368
} else {
349369
switch (temp) {
350370
case "0":
351371
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.NIL);
352-
break;
353-
case "1":
354-
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.FALSE);
372+
setAllWarningCategories(false);
355373
break;
356374
case "2":
357375
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.TRUE);
376+
setAllWarningCategories(true);
358377
break;
378+
case "1":
359379
default:
360-
throw new CommandLineException(
361-
getArgumentError(" -W must be followed by either 0, 1, 2 or nothing"),
362-
true);
380+
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.FALSE);
381+
config.setOption(OptionsCatalog.WARN_DEPRECATED, false);
382+
break;
363383
}
364384
}
365385
break FOR;
@@ -466,6 +486,11 @@ private void processArgument() throws CommandLineException {
466486
}
467487
}
468488

489+
private void setAllWarningCategories(boolean value) {
490+
config.setOption(OptionsCatalog.WARN_DEPRECATED, value);
491+
config.setOption(OptionsCatalog.WARN_EXPERIMENTAL, value);
492+
}
493+
469494
private void enableDisableFeature(String name, boolean enable) {
470495
final BiConsumer<CommandLineParser, Boolean> feature = FEATURES.get(name);
471496

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
import org.truffleruby.shared.TruffleRuby;
8383
import org.truffleruby.shared.options.OptionsCatalog;
8484
import org.truffleruby.shared.options.RubyOptionTypes;
85-
import org.truffleruby.shared.options.Verbosity;
8685
import org.truffleruby.stdlib.CoverageManager;
8786
import org.truffleruby.stdlib.readline.ConsoleHolder;
8887

@@ -177,8 +176,8 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
177176

178177
options = createOptions(env, language.options);
179178

180-
warningCategoryDeprecated = new AssumedValue<>(options.VERBOSITY == Verbosity.TRUE);
181-
warningCategoryExperimental = new AssumedValue<>(options.VERBOSITY != Verbosity.NIL);
179+
warningCategoryDeprecated = new AssumedValue<>(options.WARN_DEPRECATED);
180+
warningCategoryExperimental = new AssumedValue<>(options.WARN_EXPERIMENTAL);
182181

183182
safepointManager = new SafepointManager(this, language);
184183
coreExceptions = new CoreExceptions(this, language);
@@ -294,6 +293,12 @@ protected boolean patch(Env newEnv) {
294293
return false;
295294
}
296295
this.options = newOptions;
296+
if (newOptions.WARN_DEPRECATED != oldOptions.WARN_DEPRECATED) {
297+
warningCategoryDeprecated.set(newOptions.WARN_DEPRECATED);
298+
}
299+
if (newOptions.WARN_EXPERIMENTAL != oldOptions.WARN_EXPERIMENTAL) {
300+
warningCategoryExperimental.set(newOptions.WARN_EXPERIMENTAL);
301+
}
297302
this.rubyHome = newHome;
298303
this.rubyHomeTruffleFile = newHome == null ? null : newEnv.getInternalTruffleFile(newHome);
299304

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,15 @@ protected long endHash(long hash) {
529529

530530
}
531531

532+
@Primitive(name = "should_not_reach_here")
533+
public abstract static class ShouldNotReachHereNode extends PrimitiveArrayArgumentsNode {
534+
535+
@Specialization(guards = "libString.isRubyString(message)")
536+
protected Object shouldNotReachHere(Object message,
537+
@CachedLibrary(limit = "2") RubyStringLibrary libString) {
538+
throw CompilerDirectives.shouldNotReachHere(libString.getJavaString(message));
539+
}
540+
541+
}
542+
532543
}

src/main/java/org/truffleruby/options/Options.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public class Options {
121121
public final boolean CEXTS_LOG_LOAD;
122122
/** --cexts-log-warnings=false */
123123
public final boolean CEXTS_LOG_WARNINGS;
124+
/** --warn-deprecated=false */
125+
public final boolean WARN_DEPRECATED;
126+
/** --warn-experimental=true */
127+
public final boolean WARN_EXPERIMENTAL;
124128
/** --argv-globals=false */
125129
public final boolean ARGV_GLOBALS;
126130
/** --chomp-loop=false */
@@ -300,6 +304,8 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
300304
METRICS_PROFILE_REQUIRE = options.get(OptionsCatalog.METRICS_PROFILE_REQUIRE_KEY);
301305
CEXTS_LOG_LOAD = options.get(OptionsCatalog.CEXTS_LOG_LOAD_KEY);
302306
CEXTS_LOG_WARNINGS = options.get(OptionsCatalog.CEXTS_LOG_WARNINGS_KEY);
307+
WARN_DEPRECATED = options.get(OptionsCatalog.WARN_DEPRECATED_KEY);
308+
WARN_EXPERIMENTAL = options.get(OptionsCatalog.WARN_EXPERIMENTAL_KEY);
303309
ARGV_GLOBALS = options.get(OptionsCatalog.ARGV_GLOBALS_KEY);
304310
CHOMP_LOOP = options.get(OptionsCatalog.CHOMP_LOOP_KEY);
305311
GETS_LOOP = options.get(OptionsCatalog.GETS_LOOP_KEY);
@@ -466,6 +472,10 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
466472
return CEXTS_LOG_LOAD;
467473
case "ruby.cexts-log-warnings":
468474
return CEXTS_LOG_WARNINGS;
475+
case "ruby.warn-deprecated":
476+
return WARN_DEPRECATED;
477+
case "ruby.warn-experimental":
478+
return WARN_EXPERIMENTAL;
469479
case "ruby.argv-globals":
470480
return ARGV_GLOBALS;
471481
case "ruby.chomp-loop":

0 commit comments

Comments
 (0)