Skip to content

Commit 4ca8e3f

Browse files
eregonandrykonchin
authored andcommitted
Enable pattern matching by default and remove the option
1 parent f3cad5f commit 4ca8e3f

File tree

8 files changed

+1
-43
lines changed

8 files changed

+1
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
New features:
44

55
* C/C++ extensions are now compiled using the system toolchain and executed natively instead of using GraalVM LLVM (Sulong). This leads to faster startup, no warmup, better compatibility, smaller distribution and faster installation for C/C++ extensions (#3118, @eregon).
6+
* Pattern matching is now fully supported, with the exception of Find pattern (`in [*, a, *]`) (#3332, #2683, @eregon, @razetime).
67

78
Bug fixes:
89

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public final class Options {
6767
public final boolean HOST_INTEROP;
6868
/** --trace-calls=true */
6969
public final boolean TRACE_CALLS;
70-
/** --pattern-matching=false */
71-
public final boolean PATTERN_MATCHING;
7270
/** --patching=true */
7371
public final boolean PATCHING;
7472
/** --hashing-deterministic=false */
@@ -230,7 +228,6 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
230228
POLYGLOT_STDIO = options.hasBeenSet(OptionsCatalog.POLYGLOT_STDIO_KEY) ? options.get(OptionsCatalog.POLYGLOT_STDIO_KEY) : EMBEDDED || !NATIVE_PLATFORM;
231229
HOST_INTEROP = env.isHostLookupAllowed() && (options.get(OptionsCatalog.HOST_INTEROP_KEY));
232230
TRACE_CALLS = options.get(OptionsCatalog.TRACE_CALLS_KEY);
233-
PATTERN_MATCHING = options.get(OptionsCatalog.PATTERN_MATCHING_KEY);
234231
PATCHING = options.get(OptionsCatalog.PATCHING_KEY);
235232
HASHING_DETERMINISTIC = options.get(OptionsCatalog.HASHING_DETERMINISTIC_KEY);
236233
VIRTUAL_THREAD_FIBERS = options.get(OptionsCatalog.VIRTUAL_THREAD_FIBERS_KEY);
@@ -346,8 +343,6 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
346343
return HOST_INTEROP;
347344
case "ruby.trace-calls":
348345
return TRACE_CALLS;
349-
case "ruby.pattern-matching":
350-
return PATTERN_MATCHING;
351346
case "ruby.patching":
352347
return PATCHING;
353348
case "ruby.hashing-deterministic":

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,6 @@ public RubyNode visitCaseNode(CaseParseNode node) {
782782
public RubyNode visitCaseInNode(CaseInParseNode node) {
783783
final SourceIndexLength sourceSection = node.getPosition();
784784

785-
if (!RubyLanguage.getCurrentContext().getOptions().PATTERN_MATCHING) {
786-
final RubyContext context = RubyLanguage.getCurrentContext();
787-
throw new RaiseException(
788-
context,
789-
context.getCoreExceptions().syntaxError(
790-
"syntax error, unexpected keyword_in",
791-
currentNode,
792-
sourceSection.toSourceSection(source)));
793-
}
794-
795785
PatternMatchingTranslator translator = new PatternMatchingTranslator(language, source, parserContext,
796786
currentNode, environment, this);
797787

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,6 @@ public RubyNode visitCapturePatternNode(Nodes.CapturePatternNode node) {
922922

923923
@Override
924924
public RubyNode visitCaseMatchNode(Nodes.CaseMatchNode node) {
925-
var context = RubyLanguage.getCurrentContext();
926-
if (!context.getOptions().PATTERN_MATCHING) {
927-
throw new RaiseException(context, context.getCoreExceptions().syntaxError(
928-
"`case/in` pattern matching not yet implemented", currentNode, getSourceSection(node)));
929-
}
930-
931925
var translator = new YARPPatternMatchingTranslator(language, environment, rubySource, this);
932926

933927
// Evaluate the case expression and store it in a local
@@ -2569,12 +2563,6 @@ public RubyNode visitMatchPredicateNode(Nodes.MatchPredicateNode node) {
25692563

25702564
@Override
25712565
public RubyNode visitMatchRequiredNode(Nodes.MatchRequiredNode node) {
2572-
var context = RubyLanguage.getCurrentContext();
2573-
if (!context.getOptions().PATTERN_MATCHING) {
2574-
throw new RaiseException(context, context.getCoreExceptions()
2575-
.syntaxError("`=>` pattern matching not yet implemented", currentNode, getSourceSection(node)));
2576-
}
2577-
25782566
var translator = new YARPPatternMatchingTranslator(language, environment, rubySource, this);
25792567

25802568
// Evaluate the expression and store it in a local

src/options.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ EXPERT:
9797
# Ruby-level features
9898
TRACE_CALLS: [trace-calls, boolean, true, 'Support tracing (set_trace_func, TracePoint) of method calls']
9999
COVERAGE_GLOBAL: [coverage-global, boolean, false, Run coverage for all code and print results on exit]
100-
PATTERN_MATCHING: [pattern-matching, boolean, false, Enable pattern matching syntax]
101100

102101
# Options helpful for debugging, potentially also for user code
103102
CORE_AS_INTERNAL: [core-as-internal, boolean, false, 'Mark core library sources as internal']

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public final class OptionsCatalog {
4646
public static final OptionKey<Boolean> HOST_INTEROP_KEY = new OptionKey<>(true);
4747
public static final OptionKey<Boolean> TRACE_CALLS_KEY = new OptionKey<>(true);
4848
public static final OptionKey<Boolean> COVERAGE_GLOBAL_KEY = new OptionKey<>(false);
49-
public static final OptionKey<Boolean> PATTERN_MATCHING_KEY = new OptionKey<>(false);
5049
public static final OptionKey<Boolean> CORE_AS_INTERNAL_KEY = new OptionKey<>(false);
5150
public static final OptionKey<Boolean> STDLIB_AS_INTERNAL_KEY = new OptionKey<>(false);
5251
public static final OptionKey<Boolean> LAZY_TRANSLATION_USER_KEY = new OptionKey<>(LAZY_CALLTARGETS_KEY.getDefaultValue());
@@ -375,14 +374,6 @@ public final class OptionsCatalog {
375374
.usageSyntax("")
376375
.build();
377376

378-
public static final OptionDescriptor PATTERN_MATCHING = OptionDescriptor
379-
.newBuilder(PATTERN_MATCHING_KEY, "ruby.pattern-matching")
380-
.help("Enable pattern matching syntax")
381-
.category(OptionCategory.EXPERT)
382-
.stability(OptionStability.EXPERIMENTAL)
383-
.usageSyntax("")
384-
.build();
385-
386377
public static final OptionDescriptor CORE_AS_INTERNAL = OptionDescriptor
387378
.newBuilder(CORE_AS_INTERNAL_KEY, "ruby.core-as-internal")
388379
.help("Mark core library sources as internal")
@@ -1389,8 +1380,6 @@ public static OptionDescriptor fromName(String name) {
13891380
return TRACE_CALLS;
13901381
case "ruby.coverage-global":
13911382
return COVERAGE_GLOBAL;
1392-
case "ruby.pattern-matching":
1393-
return PATTERN_MATCHING;
13941383
case "ruby.core-as-internal":
13951384
return CORE_AS_INTERNAL;
13961385
case "ruby.stdlib-as-internal":
@@ -1662,7 +1651,6 @@ public static OptionDescriptor[] allDescriptors() {
16621651
HOST_INTEROP,
16631652
TRACE_CALLS,
16641653
COVERAGE_GLOBAL,
1665-
PATTERN_MATCHING,
16661654
CORE_AS_INTERNAL,
16671655
STDLIB_AS_INTERNAL,
16681656
LAZY_TRANSLATION_USER,

tool/docker.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def docker(*args)
259259

260260
%w[:command_line :security :language :core :tracepoint :library :capi :library_cext :truffle :truffle_capi].each do |set|
261261
t_config = c.empty? ? '' : '-T' + c
262-
t_config += ' -T--experimental-options -T--pattern-matching'
263262
t_excludes = excludes.map { |e| '--excl-tag ' + e }.join(' ')
264263
lines << "RUN ruby spec/mspec/bin/mspec -t #{ruby_bin}/ruby #{t_config} #{t_excludes} #{set}"
265264
end

tool/jt.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,8 +1706,6 @@ def mspec(*args)
17061706

17071707

17081708
vm_args << '--polyglot' if truffleruby_jvm?
1709-
# Until pattern matching is complete, we enable it in specs but not globally
1710-
vm_args << '--experimental-options' << '--pattern-matching'
17111709

17121710
raise "unsupported options #{parsed_options}" unless parsed_options.empty?
17131711

0 commit comments

Comments
 (0)