aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
Commit message (Collapse)AuthorAgeFilesLines
* Skip freezing check on setting temporary class path [Bug #17563]Nobuyoshi Nakada2021-01-201-1/+1
| | | | Co-authored-by: ryannevell (Ryan Nevell) <ryan.nevell@gmail.com>
* Replace "iff" with "if and only if"Gannon McGibbon2021-01-191-1/+1
| | | | | | | iff means if and only if, but readers without that knowledge might assume this to be a spelling mistake. To me, this seems like exclusionary language that is unnecessary. Simply using "if and only if" instead should suffice.
* Introduce Ractor::IsolationErrorKoichi Sasada2020-12-211-9/+8
| | | | | | | | | | | Ractor has several restrictions to keep each ractor being isolated and some operation such as `CONST="foo"` in non-main ractor raises an exception. This kind of operation raises an error but there is confusion (some code raises RuntimeError and some code raises NameError). To make clear we introduce Ractor::IsolationError which is raised when the isolation between ractors is violated.
* sync RCLASS_CONST_TBL()Koichi Sasada2020-12-201-29/+62
| | | | | RCLASS_CONST_TBL() is shared resource so we need to sync with other ractors.
* Use category: :deprecated in warnings that are related to deprecationJeremy Evans2020-12-181-2/+2
| | | | | | | | | | | | | | | | | Also document that both :deprecated and :experimental are supported :category option values. The locations where warnings were marked as deprecation warnings was previously reviewed by shyouhei. Comment a couple locations where deprecation warnings should probably be used but are not currently used because deprecation warning enablement has not occurred at the time they are called (RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K). Add assert_deprecated_warn to test assertions. Use this to simplify some tests, and fix failing tests after marking some warnings with deprecated category.
* tuning ivar setKoichi Sasada2020-12-161-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * make rb_init_iv_list() simple * introduce vm_setivar_slowpath() for cache miss cases ../clean/miniruby is 647ee6f091. Calculating ------------------------------------- ./miniruby ../clean/miniruby ../ruby_2_7/miniruby vm_ivar_init 7.388M 6.814M 5.771M i/s - 30.000M times in 4.060420s 4.402534s 5.198781s vm_ivar_init_subclass 2.158M 2.147M 1.974M i/s - 3.000M times in 1.390328s 1.397587s 1.519951s vm_ivar_set 128.607M 97.931M 140.668M i/s - 30.000M times in 0.233269s 0.306338s 0.213268s vm_ivar 144.315M 151.722M 117.734M i/s - 30.000M times in 0.207879s 0.197730s 0.254811s Comparison: vm_ivar_init ./miniruby: 7388398.8 i/s ../clean/miniruby: 6814257.1 i/s - 1.08x slower ../ruby_2_7/miniruby: 5770583.9 i/s - 1.28x slower vm_ivar_init_subclass ./miniruby: 2157763.6 i/s ../clean/miniruby: 2146557.0 i/s - 1.01x slower ../ruby_2_7/miniruby: 1973747.9 i/s - 1.09x slower vm_ivar_set ../ruby_2_7/miniruby: 140668063.8 i/s ./miniruby: 128606912.1 i/s - 1.09x slower ../clean/miniruby: 97931027.8 i/s - 1.44x slower vm_ivar ../clean/miniruby: 151722121.9 i/s ./miniruby: 144314526.5 i/s - 1.05x slower ../ruby_2_7/miniruby: 117734305.5 i/s - 1.29x slower
* fix ivar with shareable objects issueKoichi Sasada2020-12-121-0/+17
| | | | | Instance variables of sharable objects are accessible only from main ractor, so we need to check it correctly.
* Remove the uninitialized instance variable verbose mode warningJeremy Evans2020-12-101-9/+1
| | | | | | | | | This speeds up all instance variable access, even when not in verbose mode. Uninitialized instance variable warnings were rarely helpful, and resulted in slower code if you wanted to avoid warnings when run in verbose mode. Implements [Feature #17055]
* fix public interfaceKoichi Sasada2020-11-181-1/+1
| | | | | | | | | | | | | | | | | | To make some kind of Ractor related extensions, some functions should be exposed. * include/ruby/thread_native.h * rb_native_mutex_* * rb_native_cond_* * include/ruby/ractor.h * RB_OBJ_SHAREABLE_P(obj) * rb_ractor_shareable_p(obj) * rb_ractor_std*() * rb_cRactor and rm ractor_pub.h and rename srcdir/ractor.h to srcdir/ractor_core.h (to avoid conflict with include/ruby/ractor.h)
* refactoring.Koichi Sasada2020-11-101-5/+5
| | | | | iv_index_tbl_newsize() usually returns iv_index_tbl->num_entries because ivup->iv_extended is usually false.
* eagerly initialize ivar table when index is small enoughAaron Patterson2020-11-091-18/+23
| | | | | | | | | | | | | When the inline cache is written, the iv table will contain an entry for the instance variable. If we get an inline cache hit, then we know the iv table must contain a value for the index written to the inline cache. If the index in the inline cache is larger than the list on the object, but *smaller* than the iv index table on the class, then we can just eagerly allocate the iv list to be the same size as the iv index table. This avoids duplicate work of checking frozen as well as looking up the index for the particular instance variable name.
* Simplify setting instance variablesAaron Patterson2020-11-041-24/+15
| | | | | | | | | Since T_OBJECT objects come to life as embedded objects, that means that ROBJECT_NUMIV will always return a _minimum_ of ROBJECT_EMBED_LEN_MAX. If ivup.index is *greater* than ROBJECT_NUMIV, then we know that the object *must not* be an embedded object. Thus we can skip the ROBJECT_EMBED_LEN_MAX check as well as initializing internals of embedded objects.
* suppport Ractor.send(move: true) for more detaKoichi Sasada2020-11-021-0/+21
| | | | This patch allows to move more data types.
* Fix bootstrap-test error in previous commitJeremy Evans2020-10-251-1/+1
|
* allow to access ivars of frozen shareable objectsKoichi Sasada2020-10-221-1/+2
| | | | | | Accessing a shareable object is prohibitted because it can cause race condition, but if the shareable object is frozen, there is no problem to access ivars.
* check main-ractor or not firstKoichi Sasada2020-10-211-2/+3
| | | | | On non-multi-ractor-mode, the cost of rb_ractor_main_p() is low so check it first.
* sync RClass::ext::iv_index_tblKoichi Sasada2020-10-171-122/+168
| | | | | | | | | | | | iv_index_tbl manages instance variable indexes (ID -> index). This data structure should be synchronized with other ractors so introduce some VM locks. This patch also introduced atomic ivar cache used by set/getinlinecache instructions. To make updating ivar cache (IVC), we changed iv_index_tbl data structure to manage (ID -> entry) and an entry points serial and index. IVC points to this entry so that cache update becomes atomically.
* sync generic_ivtblKoichi Sasada2020-10-141-14/+32
| | | | | | | | | generic_ivtbl is a process global table to maintain instance variables for non T_OBJECT/T_CLASS/... objects. So we need to protect them for multi-Ractor exection. Hint: we can make them Ractor local for unshareable objects, but now it is premature optimization.
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-43/+112
| | | | | | | | | | | | | | | | This commit introduces Ractor mechanism to run Ruby program in parallel. See doc/ractor.md for more details about Ractor. See ticket [Feature #17100] to see the implementation details and discussions. [Feature #17100] This commit does not complete the implementation. You can find many bugs on using Ractor. Also the specification will be changed so that this feature is experimental. You will see a warning when you make the first Ractor with `Ractor.new`. I hope this feature can help programmers from thread-safety issues.
* Don't call to_s in const_setAlan Wu2020-09-031-1/+2
| | | | | | | Follow up for 5e16857315bf55307c5fc887ca6f03bfa0630a93. Calling a method in the middle of const_set adds a way that it would fail. It also makes it inconsistent with declaring a constant using `::`, which doesn't call `to_s`.
* Fix constant names set using const_set on a singleton classMarc-Andre Lafortune2020-09-021-8/+9
| | | | Fixes [Bug #14895]
* ROBJECT_IV_INDEX_TBL: convert into an inline function卜部昌平2020-08-191-0/+1
| | | | | | | Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is not disclosed to extension libraies. The macro was kind of broken. Why not just deprecate it, and convert the internal use into an inline function.
* Ensure the shortcut cached in the classNobuyoshi Nakada2020-08-171-2/+2
| | | | | | As well as the other places using RCLASS_IV_INDEX_TBL. `IO#reopen` seems the only case that the class of an object can be changed.
* Improve docs for Module#remove_class_variable [ci skip]Alan Wu2020-08-021-5/+4
|
* Remove trailing spaces [ci skip]Nobuyoshi Nakada2020-07-201-1/+1
|
* Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada2020-07-031-33/+48
| | | | | | | | | | | | Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development.
* add UNREACHABLE_RETURN卜部昌平2020-06-291-0/+2
| | | | | | Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities.
* rb_mod_remove_cvar: do not goto into a branch卜部昌平2020-06-291-4/+4
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* rb_copy_generic_ivar: do not goto into a branch卜部昌平2020-06-291-6/+8
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* generic_ivar_update: do not goto into a branch卜部昌平2020-06-291-17/+10
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* rb_path_to_class: do not goto into a branch卜部昌平2020-06-291-3/+5
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* Raise RuntimeError for class variable overtaken in nonverbose modeJeremy Evans2020-06-181-1/+1
| | | | | | | | | | | | | | | | | | 900e83b50115afda3f79712310e4cb95e4508972 changed from a warning to an error in this case, but the warning was only issued in verbose mode, and therefore the error was only raised in verbose mode. That was not intentional, verbose mode should only change whether warnings are emitted, not other behavior. This issues the RuntimeError in all cases. This change broke a couple tests, as the tests actually issued the warning and therefore now raise an error. This wasn't caught earlier as test_variable suppressed the warning in this case, effectively setting $VERBOSE = false around the code that warned. basictest isn't run in verbose mode and therefore didn't expose the issue previously. Fix these tests. Fixes [Bug #14541]
* Prohibit setting class variable on frozen module through inheritanceAlan Wu2020-06-111-0/+3
| | | | | | | | Setting class varibles goes through the ancestor list which can contain iclasses. Iclasses share a lot of information with the module they are made from, but not the frozen status. Check the frozen status of the module instead of the iclass.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-2/+2
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-2/+2
| | | | This shall fix compile errors.
* Allow global variables to moveAaron Patterson2020-05-071-1/+43
| | | | | | | | | | This patch allows global variables that have been assigned in Ruby to move. I added a new function for the GC to call that will update global references and introduced a new callback in the global variable struct for updating references. Only pure Ruby global variables are supported right now, other references will be pinned.
* Turn class variable warnings into exceptionsJeremy Evans2020-04-101-1/+2
| | | | | | | | | | | | | | | | | | This changes the following warnings: * warning: class variable access from toplevel * warning: class variable @foo of D is overtaken by C into RuntimeErrors. Handle defined?(@@foo) at toplevel by returning nil instead of raising an exception (the previous behavior warned before returning nil when defined? was used). Refactor the specs to avoid the warnings even in older versions. The specs were checking for the warnings, but the purpose of the related specs as evidenced from their description is to test for behavior, not for warnings. Fixes [Bug #14541]
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+1
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-3/+3
| | | Split ruby.h
* Fix source location of autoloaded constant [Bug #16764]Nobuyoshi Nakada2020-04-071-8/+19
|
* Removed unnecessary castNobuyoshi Nakada2020-04-071-3/+2
|
* Workaround of instance variable on hidden objectNobuyoshi Nakada2020-02-121-2/+5
| | | | | | | | Since 9d9aea7fe50f6340829faa105d9ffe08ebaee658, generic instance variables need `iv_index_tbl` in the object's class. As hidden objects, however, have no class, access to the variables causes a segfault. Get rid of that segfault by raising an exception, for the time being.
* Removed unused variableNobuyoshi Nakada2020-02-111-8/+0
| | | | `generic_iv_tbl_compat` has not been utilized since 14d61a94ff01.
* Use `rb_gc_mark` when marking globalsAaron Patterson2020-01-301-1/+1
| | | | | | I think global references should either be 0 or valid heap pointers. `rb_gc_mark_maybe` checks to see if the pointer is a valid heap pointer, but I believe we already know they are valid addresses
* always expand ivar arrays to max widthAaron Patterson2020-01-061-2/+1
| | | | | | | If the instance variable table hasn't been "expanded", allocate the maximum size of the ivar table. This operates under the assumption that most objects will eventually expand their ivar array to the maximum width anyway, so we may as well avoid realloc calls.
* decouple internal.h headers卜部昌平2019-12-261-8/+19
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* Enhance docs for Module#deprecate_constantzverok2019-12-221-1/+13
|
* Made the warning for deprecated constants follow the category flagNobuyoshi Nakada2019-12-191-1/+2
|
* Do not lose existing constant visibility when autoloadingJeremy Evans2019-12-031-0/+9
| | | | | | | | | | This copies the private/deprecate constant visibility across the autoload. It still is backwards compatible with setting the private/deprecate constant visibility in the autoloaded file. However, if you explicitly set public constant in the autoloaded file, that will be reset after the autoload. Fixes [Bug #11055]
* Supress class variable overtaken warning when original modules are the sameJeremy Evans2019-11-291-1/+1
| | | | | This issue was exposed by recent commits to better support including refined modules.