Skip to content

module: extend_object, const_source_location, const_added, cvar ancestry, Module.constants & definition hooks (core/module +19) - #595

Merged
tannevaled merged 1 commit into
mainfrom
wave20/module
Sep 8, 2026
Merged

tannevaled merged 1 commit into
mainfrom
wave20/module

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances MRI-4.0.x conformance of the Module/Class surface. Measured against
the frozen ruby/spec corpus with a consistent harness, core/module goes
790 → 809 pass (+19)
, with errors dropping 102 → 66 (const_source_location
alone converts 35 errors into resolved/nil results). Every behaviour was checked
byte-for-byte against local MRI 4.0.5 and cited to ruby/ruby v3_4_0 sources.

Changes

  • Module#extend_object — the private primitive Object#extend dispatches to.
    Mixes the module into the object's singleton class (methods and constants);
    raises TypeError when the receiver is a Class (rb_include_module), and
    FrozenError for a frozen object; undefined on Class. Ref object.c
    rb_mod_extend_object / rb_extend_object. (extend_object_spec +4)
  • Module#const_source_location — rbgo records no per-constant source
    position, so it returns nil for a resolvable name (the value MRI gives an
    absent constant) while honouring MRI's full name-validation contract
    (NameError for a malformed name or a Symbol carrying a scope path, TypeError
    for a failed #to_str). Ref variable.c rb_const_source_location. (+6)
  • Module#const_set — fires const_added on every set (ref variable.c
    rb_const_set) and warns already initialized constant on redefining a real
    value, gated by $VERBOSE non-nil (rb_warn; a pending autoload does not warn).
  • class_variable_get / _set / _defined? and #class_variables now search
    the whole ancestry (included modules), not only the superclass chain; _set
    writes through to the owning module. Ref variable.c rb_cvar_get / rb_cvar_set.
  • Module.constants (singleton) — no argument returns every top-level constant
    (equal to Object.constants); with an argument behaves like Module#constants.
    Ref variable.c rb_mod_s_constants.
  • Module#remove_const made private (rb_define_private_method).
  • remove_method / undef_method fire method_removed / method_undefined
    on an ordinary class; singleton classes keep routing to the singleton hooks.
  • Module.new / Class.new yield the new module/class to their block. Ref
    object.c rb_mod_initialize / rb_class_initialize → rb_mod_module_exec(module, 1, &module).

Testing

  • New whitebox suite internal/vm/module_wave20_test.go covers every new branch;
    go tool cover -func shows 100% on all introduced code (the pre-existing
    bootstrap 99.7% / cloneSingleton 79.2% are untouched).
  • go build ./..., full GOWORK=off go test ./..., and the wasip1 build all pass;
    gofmt -l internal/vm/ is clean.
  • Regression-checked against the origin/main binary: core/class, core/kernel,
    core/struct, core/data unchanged.

🤖 Generated with Claude Code

…arn, cvar ancestry, Module.constants, def hooks, .new block arg (core/module +19)

Advance MRI-4.0.x conformance of Module/Class (core/module). Each change is
byte-for-byte checked against local MRI 4.0.5 and cited to ruby/ruby v3_4_0.

- Module#extend_object: the private primitive Object#extend dispatches to. Mixes
  self into the object's singleton class (methods + constants); TypeError when
  self is a Class (rb_include_module), FrozenError for a frozen object; undefined
  on Class. Ref object.c rb_mod_extend_object / rb_extend_object.
- Module#const_source_location: rbgo tracks no per-constant source position, so
  it returns nil for a resolvable name (as MRI does for an absent one) while
  honouring the full NameError/TypeError name-validation contract. Ref
  variable.c rb_const_source_location. (+6, errors 35->1)
- Module#const_set: fire const_added on every set (ref variable.c rb_const_set)
  and warn "already initialized constant" on redefining a real value, gated by
  $VERBOSE non-nil (rb_warn semantics; a pending autoload does not warn).
- class_variable_get/_set/_defined? and #class_variables now search the whole
  ancestry (included modules), not only the superclass chain; _set writes through
  to the owning module. Ref variable.c rb_cvar_get / rb_cvar_set.
- Module.constants (singleton): no-arg returns every top-level constant (equal to
  Object.constants); with an argument behaves like Module#constants. Ref
  variable.c rb_mod_s_constants.
- Module#remove_const made private (rb_define_private_method).
- remove_method / undef_method fire method_removed / method_undefined on an
  ordinary class (singleton classes keep routing to the singleton hooks).
- Module.new / Class.new yield the new module/class to their block. Ref object.c
  rb_mod_initialize / rb_class_initialize -> rb_mod_module_exec(module,1,&module).

Whitebox tests in module_wave20_test.go cover every new branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 320a3ee into main Sep 8, 2026
7 checks passed
@tannevaled
tannevaled deleted the wave20/module branch September 8, 2026 11:58
tannevaled added a commit that referenced this pull request Sep 8, 2026
…598)

Wave-20 merged three bibliography-first conformance PRs:
- #596 core/io: File.open/new trailing-Hash options, IO#read/readchar/gets
  external->internal transcoding, IO#set_encoding_by_bom, BOM stripping — +62
  (and core/file +8 incidental).
- #597 core/enumerator: Enumerator::Product class, Chain/ArithmeticSequence
  constructors, Enumerator#take_while break-early (clearing the produce_spec
  hang) — +49.
- #595 core/module: extend_object, const_source_location, const_set const_added
  + redefinition warning, class_variable ancestry search, Module.constants
  singleton, remove/undef_method hooks — +19.

Measured total on merged main: 19915 passing (2172 files load, +1 that was a
hang). Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant