[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70528] Re: [Ruby trunk - Feature #11473] [Open] Immutabe String literal on Ruby 3

From: Eric Wong <normalperson@...>
Date: 2015-08-21 19:29:18 UTC
List: ruby-core #70528
I am against breaking compatibility; this can be a subtle change
that breaks old code in ways that may not be obvious.

However, I think we may be able to workaround transparently from Ruby
layer.  The C API will gets expanded, but should remain
backwards-compatible.

I propose a "half-frozen" state for strings:

1) string literals are created as "half-frozen" by default

2) eliminate "putstring" instruction from VM

3) Introduce "VALUE rb_str_modify_dup(str)" function:

	VALUE
	__attribute__((warn_unused_result)) /* important! */
	rb_str_modify_dup(VALUE str)
	{
		if (rb_str_half_frozen_p(str)) {
			/* like putstring */
			return rb_str_resurrect(str);
		}

		/* like current rb_str_modify: */
		rb_str_modify_internal(str);

		return str;
	}

4) modify rb_define_method (and rb_define_private_method, etc...)
   to flag and call rb_str_resurrect unconditionally for half-frozen
   strings before calling any old cfunc

5) deprecate rb_define_method and rb_str_modify, they will exist
   indefinitely for backwards compatibility

6) create rb_define_method_3_0 (temporary name) which assumes
   the cfunc is aware of half-frozen strings (e.g. rb_str_modify
   calls replaced with rb_str_modify_dup calls)

7) gradual transition of existing code to rb_define_method_3_0


Fwiw, I have a lot of legacy Perl 5 code written from many years ago
that work fine today.  Even nowadays, I still choose to do start new
projects with Perl 5 because I can expect it remain working in the
future.

I hope I can rely on Ruby to have similar stability someday.


Side note: I also propose we also skip (argc == -1 / rb_scan_args)
support from rb_define_method_3_0 because of [Feature #11339] (for
kwarg parsing speedups)

In This Thread

Prev Next