Project

General

Profile

Actions

Feature #16294

closed

Make MatchData frozen and forbid MatchData.allocate

Added by Eregon (Benoit Daloze) over 4 years ago. Updated 6 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:95699]

Description

Currently, MatchData.allocate is allowed, but almost every MatchData method called on it raise TypeError, 'uninitialized Match'.

I think MatchData should be frozen, none of its internal fields are mutable and I don't see any use case for storing instance variables on it.
Once frozen, we can implement MatchData#dup and #clone as just return self, and we don't need to check for the uninitialized case.
And Marshal can have special treatment to create an initialized MatchData directly.

My main motivation is looking at the code in TruffleRuby required to implement MatchData.allocate and check if it's initialized in so many places:
https://github.com/oracle/truffleruby/pull/1792/files

Thoughts? Anyone against?
cc @alanwu (Alan Wu)

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Subject changed from Make MatchData frozen and forbid MatchData#allocate to Make MatchData frozen and forbid MatchData.allocate
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|aa94245a09887f95bc0cd353b3462108d76d13ed.


Undefine MatchData.allocate [Feature #16294]

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

It would be OK to remove MatchData.allocate, I think.
And Regexp.allocate too, but rubyspec has a couple of code using Regexp.allocate.

Updated by mame (Yusuke Endoh) over 4 years ago

I'm not against the proposal itself, but is it okay to introduce an incompatibility at this time? cc: @naruse (Yui NARUSE)

Updated by Eregon (Benoit Daloze) over 4 years ago

@nobu (Nobuyoshi Nakada) Thanks for the change! I'll adapt the specs.

Updated by nobu (Nobuyoshi Nakada) 7 months ago

I've forgot this for years, and just happened to discover this branch.
https://github.com/ruby/ruby/pull/8624

Updated by Eregon (Benoit Daloze) 7 months ago

Looks good, I think we should merge it.
(and this is already the case on TruffleRuby)

Updated by nobu (Nobuyoshi Nakada) 6 months ago

At the latest dev-meeting, there was a suggestion that whereas MatchData cannot be dumped, Regexp.allocate might be used by serializer libraries.

Updated by Eregon (Benoit Daloze) 6 months ago

nobu (Nobuyoshi Nakada) wrote in #note-8:

At the latest dev-meeting, there was a suggestion that whereas MatchData cannot be dumped, Regexp.allocate might be used by serializer libraries.

That does not seem used in practice.
TruffleRuby already does not define Regexp.allocate, and there seems to be no compatibility issue with that except some ruby/spec specs.
Regexp.new (or eval) is good enough for deserializing regexps.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0