Project

General

Profile

Actions

Misc #18059

open

Which FL_USERx are open to extension libraries?

Added by nobu (Nobuyoshi Nakada) about 2 months ago. Updated about 2 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
[ruby-core:104758]

Description

Often the following failure occurs in test-spec.

RBasic support for regular objects supports copying the flags from one object over to the other FAILED
Expected 81920 == 33636352
to be truthy but was false
/tmp/ruby/v3/src/trunk/spec/ruby/optional/capi/shared/rbasic.rb:71:in `block (2 levels) in <top (required)>'
/tmp/ruby/v3/src/trunk/spec/ruby/optional/capi/rbasic_spec.rb:8:in `<top (required)>'

81920 == 0x14000
33636352 == 0x2014000
The difference 0x2000000 is FL_USER13, which is used as ROBJECT_TRANSIENT_FLAG.
This flag is set when any Object instance has some amount of instance variables.

In this particular case, it is possible to fix just by excluding the bit.
But, the question is which flags are open to extension libraries.

My guess is these flags are available for T_DATA classes, but not for T_OBJECT.
Any thoughts?

Updated by shyouhei (Shyouhei Urabe) about 2 months ago

I guess none of them are open for extension libraries. For instance FL_USER0 is FL_SINGLETON. It is obvious that the flag cannot be abused in any other ways than how we currently use it.

The "USER" terminology never seriously meant anything I guess. Extension libraries are the safest when they leave those bits untouched.

Updated by Eregon (Benoit Daloze) about 2 months ago

Those specs were added because gems rely on it (https://github.com/oracle/truffleruby/issues/1884).
rbtree3 is an example: https://github.com/kyrylo/rbtree3/blob/850e9d76c22b0766bc2bc36987b11aed05eb2bb4/rbtree.c#L19
gem-codesearch '\bFL_SET\b' | grep -v vendor | grep -v '/ruby/' gives:
https://gist.github.com/eregon/efb1cb7c9ec88dba1cc6ebcfeb24288a
Some of them are from internal Ruby headers, but not all.

Also the terminology "FL_USER" intuitively indicates it is meant for gem-specific flags.
And of course the fact that RB_FL_ABLE/RB_FL_TEST/RB_FL_SET/RB_FL_UNSET/etc are exposed.

My guess is these flags are available for T_DATA classes, but not for T_OBJECT.

That seems reasonable to me.
I think it should be reflected in RB_FL_ABLE then, and internally some other macros should be used to deal with non-T_DATA (e.g., T_STRING, T_ARRAY, etc).

Updated by Eregon (Benoit Daloze) about 2 months ago

I think it could also make sense to deprecate those macros (e.g., by making them use functions marked as deprecated) and eventually remove them, if no C extension should use them.
That would also mean that e.g. the date gem cannot use e.g. FL_TEST anymore either:
https://github.com/ruby/date/blob/404f9d2096b8f86431666b7d8edb99461b77c2e7/ext/date/date_core.c#L7157-L7160

Updated by Dan0042 (Daniel DeLorme) about 2 months ago

shyouhei (Shyouhei Urabe) wrote in #note-1:

The "USER" terminology never seriously meant anything I guess.

I thought it meant those flags have a different usage for each class. No?

Actually I have so many questions about flags, like why are they limited to 32 even though the flags field is a 64-bit value (instead of wasting 32 bits, why not use either 32 or 64 bits on all architectures?) It would be nice if there was some documentation somewhere about flags and how they are used. Even just comments in the code. I haven't found much so far.

Updated by nobu (Nobuyoshi Nakada) about 2 months ago

Dan0042 (Daniel DeLorme) wrote in #note-4:

I thought it meant those flags have a different usage for each class. No?

Correct.

Actually I have so many questions about flags, like why are they limited to 32 even though the flags field is a 64-bit value (instead of wasting 32 bits, why not use either 32 or 64 bits on all architectures?)

Upper 32 bits are not available on 32-bit system of course.
We didn't think those bits were needed yet.

Updated by duerst (Martin Dürst) about 2 months ago

Dan0042 (Daniel DeLorme) wrote in #note-4:

Actually I have so many questions about flags,...
It would be nice if there was some documentation somewhere about flags and how they are used. Even just comments in the code. I haven't found much so far.

Yes, please!

Updated by duerst (Martin Dürst) about 2 months ago

duerst (Martin Dürst) wrote in #note-6:

Dan0042 (Daniel DeLorme) wrote in #note-4:

Actually I have so many questions about flags,...
It would be nice if there was some documentation somewhere about flags and how they are used. Even just comments in the code. I haven't found much so far.

Yes, please!

Sorry, I should have been more specific the first time round. One question is whether extension libraries are allowed to use some flags. The other question is what flags may still be free for new work on Ruby internals.

Actions

Also available in: Atom PDF