Skip to content

fix: keep helpers added after v0.0.23 off Kernel - #67

Merged
AdamMusa merged 13 commits into
mainfrom
fix/no-new-kernel-helper-shadowing
Nov 17, 2026
Merged

AdamMusa merged 13 commits into
mainfrom
fix/no-new-kernel-helper-shadowing

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Problem

The v0.0.23 vs main compatibility audit found that every bare helper added since v0.0.23 became a private method of every object in the process. Ruflet::UI::SharedControlForwarders is included into Kernel, so each method added to it lands on Kernel.

On current main (742a000) that is 63 names:

A Kernel method wins over any other library's method_missing builder with the same name. After require "ruflet_core":

tree Nokogiri::HTML::Builder.new { table { tr { td "cell" } } } Nokogiri::HTML::Builder.new { form(action: "/x") { input(type: "text") } }
v0.0.23 <table><tr><td>cell</td></tr></table> <form action="/x"><input type="text"></form>
main nil (a Ruflet Table was built instead) ArgumentError: unknown keywords: action (from FormControl)
this PR <table><tr><td>cell</td></tr></table> <form action="/x"><input type="text"></form>

Why it matters for existing apps

rails_integration.md loads ruflet_core into Rails apps, so upgrading Ruflet changed code that is not Ruflet's: Nokogiri, Builder and Jbuilder-style DSLs, and any object whose method_missing handles table, form, stepper or the other names.

Names that were already Kernel methods at v0.0.23 (map, option, column, row, image, ...) are left exactly as they were, because v0.0.23 apps call them bare. That set is 406 names, now pinned in test/fixtures/kernel_helpers_v0_0_23.txt.

Fix

The 63 forwarders move from SharedControlForwarders to a new module, Ruflet::UI::ScopedControlForwarders, in the same file.

  • Only the Ruflet and Ruflet::UI singletons include it, so Ruflet.table, Ruflet::UI.stepper, Ruflet.form and the rest still work.
  • It is included before SharedControlForwarders, so SharedControlForwarders is looked up first. That is where Ruflet::Extensions.register_control defines a registered helper, so an extension registered under one of these names still wins (see "Extension contract").
  • Builder blocks (WidgetBuilder, DSL::App, Ruflet.column { ... }) already get the names from UI::ControlMethods.

Kernel#method_missing answers these names first, in one branch. This is how v0.0.23 already reached registry names that had no forwarder, such as elevatedbutton. An object with its own method_missing is asked first and keeps the name, which is what fixes Nokogiri. The branch has three steps, and they are the same on CRuby and on the embedded VM:

  1. owned_call?: a call with arguments, keywords or a block on an object ControlFactory.dsl_receiver? accepts builds, with or without a receiver. That object is a script's top level or a Ruflet::* object. v0.0.23 built a generic control there for any name. dsl_receiver? is always false on the VM, which has no TOPLEVEL_BINDING, as at v0.0.23.
  2. receiverless?: any other call asks Ruby, through super, how it was written. It builds only when the call had no explicit receiver, which is exactly when a private Kernel method would have answered it.
    • Builds: a bare word, name(), self.name, send(:name, ...) and __send__.
    • Raises: anything else re-raises the NoMethodError that super raised, with v0.0.23's message and private_call? false. Examples: record.table(1), record.table, Ruflet.text("x").table.
    • CRuby: a bare word raises a plain NameError, and any other call form is read from NoMethodError#private_call?.
    • Embedded VM: there is no private_call?. An explicit call never gets this far, because mruby 449627d raises "private method 'table' called" before Kernel#method_missing runs, as at v0.0.23. So a call that reaches Kernel#method_missing on an object whose method_missing is Kernel's had no receiver, or was send/__send__/public_send. One that came through another class's method_missing and super re-raises. That check uses Kernel.instance_method(:method).bind_call, because some classes, such as HTTP requests, define their own method. When even that cannot look method_missing up on the receiver, the call is taken as one that reached Kernel's directly.
  3. build: builds Ruflet::DSL.<name>, the method the Kernel helper called, with the same positional meaning (steps, rows, slivers, controls, content). There is one argument rule: when no keywords were passed and the last argument is a non-empty Hash whose keys are all Symbols, that Hash is the keywords.
    • The VM passes the keywords of send, __send__ and public_send to method_missing this way. So does any method_missing written without keywords that calls super, including Ruflet::Page, Ruflet::Event, Ruflet::DeviceInfo and a Ruflet::* class of an extension gem.
    • Nothing at that point tells such a Hash from one written positionally. So both are read the same way, on CRuby too, and the two runtimes build the same control.
    • None of these helpers takes a Hash as its content, rows or children. A Hash with any non-Symbol key, an empty Hash, and a Hash passed beside keywords are all passed on as written.

Ruflet::Page leaves the 63 names to Kernel#method_missing. Its "Use x(...) as a free widget helper" hint now covers v0.0.23's helper set again, which is exactly main's set minus these 63. So a bare stepper(current_step: 1) inside a page block builds, page.stepper = x sets a page property, and page.respond_to?(:stepper) is false, all as on v0.0.23. The hint for v0.0.23 helpers such as page.text("x") is unchanged.

SharedControlForwarders#method_missing declines these names. The super call in step 2 reaches it, because the module is included into Kernel. Its generic known_control? branch would otherwise answer an explicit call. Removing the decline makes tests fail; see "Planted bugs".

When an extension registers one of these names, the name is a Kernel method again, so this branch stands aside for it. That is the v0.0.23 behaviour.

Changes in this round (7f6a0c3)

This round changes tests, test comments and this description. No line under lib/ changes. packages/ruflet_core/lib is byte-identical to 3a7ca07's, and the VM's compiled framework (gem_init.c, sha256 825ef63e…) built from this head is the one round 5 built from 3a7ca07 and from ad7a3d5. origin/main (742a000, CI-only since 51bea9b) is merged in.

1. Correction: on the embedded VM, a splat-forwarded call can build with another call's keywords

Round 5 said that on this head's VM, a scoped helper forwarded with a positional splat and keywords either drops its keywords or raises. That was incomplete. It can also build, with no error, using the keyword Hash of an earlier, unrelated call. So another call's property values, possibly including handlers, can reach the wire.

The round-5 reviewer's repro, run as embedded_mruby --preload repro.rb:

require "ruflet_core"
def outcome
  value = yield
  value.respond_to?(:to_patch) ? value.to_patch["key"].inspect : value.class.to_s
rescue Exception => e
  "RAISE #{e.class}"
end
def row(label, got) = puts("#{label}: #{got}")
class Fwd
  def splat_carouselview(*a, **k, &b) = carouselview(*a, **k, &b)
end
F = Fwd.new
args = []
kw = { key: "k" }
outcome { Ruflet::DSL.public_send(:carouselview, *args, key: "lit") }
row("F.splat_carouselview(key: \"k\") -> key", outcome { F.splat_carouselview(*args, **kw) })
runtime prints (3 of 3 runs each)
VM, this head (unpatched mruby 449627d) key: "lit"
VM, this head + #81 key: "k"
VM, main key: "k"
committed prebuilt VM key: RAISE NoMethodError (the name does not exist there)
CRuby, this head key: "k"

What such a call gets depends on what earlier calls left on the VM stack. Two small rewrites of this script print nil (keywords dropped) and raise TypeError instead.

In the forwarding matrix (below), the 258 rows round 5 called "build without their keywords" are two kinds:

  • 234 build without them;
  • 24 build with key: "lit", the literal keyword of the direct Ruflet::DSL call made just before. The call itself passed key: "k". These are the *a, **k, &b wrapper for carouselview, customscrollview, draggablescrollablesheet, indexedstack, listsection, slivergrid, sliverlist, sliverpadding and tablerow.

The cause and the fix are in draft #81, which carries upstream mruby 550d10adb7 as a VM build patch. #81 must ship in the same runtime rebuild that first compiles this branch's ruflet_core into the VMs, not later. See "Limits" and "Release coupling".

2. New test: the moved forwarders' output is pinned

The 63 forwarders this PR moved into ScopedControlForwarders are now reached only through Ruflet.* and Ruflet::UI.*. Before this round, respond_to? pinned every name but output pinned only a few. The round-5 reviewer planted two bugs that the full ruflet_core and ruflet_rails suites missed:

  • sliverpadding dropping its keywords;
  • nestedscrollview dropping its block.

test_ruflet_and_ruflet_ui_build_what_ruflet_dsl_builds now compares Ruflet.<name> and Ruflet::UI.<name> with Ruflet::DSL.<name>:

  • Coverage: every scoped name over four shapes: keywords only, [], a control as the positional argument, and a block that adds a child.
  • Required keywords: it adds the keywords a helper needs to build (body: for nested_scroll_view, title: for stepper_step).
  • The comparison can fail: it checks that each built patch shows key:, the positional control and the block's child, so a dropped keyword, argument or block changes what is compared.

Plants, one at a time, in each of the 63 forwarder lines: 63 dropping the keywords, 23 dropping the block, 55 dropping the positional argument, and 58 routing to another control's helper with the same parameters. The reviewer's two plants, exactly as written, make 201.

  • This test alone fails on all 201 of 201.
  • 3a7ca07's whole shadowing test file fails on 11 of them.

3. scoped_helper_test.rb (the VM harness test)

runtime scoped_helper_test.rb
CRuby 4.0.5 and 3.2.9, this head all 87 checks pass
VM, this head 76 pass, 11 splat-forwarding checks skipped as KNOWN LIMIT (identical over 3 runs)
VM, this head + #81 (fe1bd60) all 87 pass, 0 skipped (identical over 3 runs)
VM, main 742a000 64 fail: the 63 names are Kernel methods, and the tag builder gets ArgumentError from FormControl (11 skipped)
VM built from v0.0.23's Ruby, and the committed prebuilt VM stop with NoMethodError at Ruflet::DSL.stepper_step, which does not exist there

4. Description corrections

  • The failure mode is corrected everywhere it is described: the forwarding table, the call-matrix row, the "VM, main → this PR" bullet and the first Limits bullet now include the calls that build with another call's keywords.
  • The mruby cause and patch are no longer restated or pointed at scratch files. They live in fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81.
  • Every result below was re-run this round on fresh builds, except where a section says it comes from round 4 or 5. Those rounds' scripts were in scratchpads that have since been cleared. The forwarding-matrix generator is round 5's, recovered verbatim.

Call matrix, CRuby and embedded VM side by side

The rows below come from two sources:

No executable line under lib/ has changed since ad7a3d5, so round 4's results still describe this head.

Representative rows (k is key: "k"; generic is v0.0.23's generic control named after the method):

call CRuby v0.0.23 CRuby main CRuby this PR VM v0.0.23 VM main VM this PR
bare stepper(k) / about_dialog / self.about_dialog in an object, component, app or test NoMethodError / NameError builds builds NoMethodError builds builds
top level table(k) / about_dialog generic / NameError builds builds NoMethodError builds builds
forwarded through *a, **k, *a plus a literal keyword, or ... (def st(*a, **k, &b) = stepper(*a, **k, &b)) NoMethodError builds builds NoMethodError builds keywords dropped, another call's keywords used, or a garbage TypeError/ArgumentError/NoMethodError (VM-only, mruby bug, see Limits); builds correctly with #81
forwarded through a named parameter (def st(steps = nil, **k) = stepper(steps, **k)) or **k only NoMethodError builds builds NoMethodError builds builds
obj.table(k), nil.table(1), app.stepper(k) NoMethodError builds or ArgumentError NoMethodError NoMethodError ("private method") same same
obj.about_dialog, Ruflet.text("x").about_dialog, TOPLEVEL_BINDING.receiver.about_dialog NoMethodError NoMethodError NoMethodError NoMethodError ("private method") same same
Ruflet.text("x").table(1), .table { }, .about_dialog(k), TOPLEVEL_BINDING.receiver.table(k) generic ArgumentError or builds builds NoMethodError ("private method") same same
obj.send(:about_dialog, k), obj.send(:table, k), obj.__send__(:table, k), top-level send(:stepper, k) NoMethodError (generic at top level) builds builds NoMethodError builds builds, same control as main
obj.public_send(:table, k) NoMethodError builds NoMethodError NoMethodError NoMethodError ("private method") builds (VM-only, see below)
bare stepper(k) / about_dialog in a class whose own method_missing calls super (with or without **kw) NoMethodError builds builds NoMethodError builds NoMethodError (VM-only, see below)
obj.stepper(k) on such a class NoMethodError ArgumentError NoMethodError NoMethodError NoMethodError NoMethodError
bare stepper(k) in Ruflet::Event / Ruflet::Page / a Ruflet::* class with keywordless method_missing generic builds builds NoMethodError builds NoMethodError (same limit)
event.stepper(k), page.stepper(k) generic ArgumentError / Page hint builds NoMethodError NoMethodError NoMethodError
page.stepper = 1, then page.stepper page property Page hint page property page property Page hint page property
TagBuilder/Nokogiri form(k), table builder gets the name Ruflet control builder gets the name builder gets it Ruflet control builder gets it
bare table({ key: "k" }), about_dialog({ key: "k" }) (positional Symbol-keyed Hash) NoMethodError malformed Table / ArgumentError Table(key: "k") / AboutDialog NoMethodError malformed / ArgumentError same as CRuby
bare table({ a: 1 }) NoMethodError (generic at top level) malformed Table ArgumentError (unknown keywords: a) NoMethodError malformed same as CRuby
bare table({ "key" => "k" }), table({ rows: [], "border_width" => 1 }) NoMethodError rows = that Hash unchanged: rows = that Hash NoMethodError same same
Ruflet.column { table(k) }, Ruflet.table(k) generic / NoMethodError builds builds NoMethodError builds builds

Every difference, counted

These counts are from round 4's matrices on ad7a3d5, except the forwarding-matrix figures, which are this round's.

VM, v0.0.23 → this PR: 5,007 calls go from raising to building and 1,589 raise differently. 2 build differently: page.local_auth and page.local_authentication after a setter, which are real Page methods added by #72. No call goes from building to raising. The forwarding matrix agrees: the committed prebuilt VM and a VM built from v0.0.23's Ruby build none of its 1,260 calls.

VM, main → this PR: building-to-raising, or building differently, happens in three places:

send and __send__ with keywords match main's VM on every name.

CRuby, v0.0.23 → this PR (on the 18,585-call CRuby matrix, which adds ruby2_keywords and SimpleDelegator contexts):

  • 5,027 calls go from raising to building and 1,592 raise differently.
  • 4,236 go from a generic control to the real one. For example, local_auth(key: "k") at the top level gives the LocalAuthentication service, and Ruflet.column { clip_oval(text("o")) } holds a ClipOval.
  • 2 build differently: page.local_auth and page.local_authentication after a setter, as on the VM.
  • 2,001 go from building to raising. All of them are argument shapes the real control rejects, and all are at the top level, on a Ruflet-owned receiver or in a builder block, where v0.0.23 built a generic control for any name:
count shape example
693 two positional arguments table(1, 2), form(1, 2)
626 a positional Symbol-keyed Hash read as keywords, with a key the control does not take table({ a: 1 }): unknown keywords: a
376 a positional argument to a keyword-only helper about_dialog(1), local_auth([]), sliver_app_bar(nil, key: "k"), stepper_step({ "key" => "k" })
156 nested_scroll_view without body: nested_scroll_view(key: "k"), nested_scroll_view { }
86 form_row without content form_row(key: "k"), form_row { }
64 stepper_step without title: stepper_step(key: "k")

Builder blocks (Ruflet.column { ... }), Ruflet.* and Ruflet::DSL.* behave exactly as on main.

  • Explicit receivers, public_send, delegators and method_missing builders behave exactly as on v0.0.23. Every call is identical in the plain.recv, nil.recv, app.recv, kwless.recv, deleg.bare, deleg.recv and tag.bare contexts (693 of 693 each), in public_send (126 of 126) and in page.respond_to? (63 of 63).

CRuby, main → this PR:

  • 2,167 calls go from building to raising:
    • 1,536 are explicit receivers, public_send and SimpleDelegator, which now raise as on v0.0.23.
    • 587 built a malformed control from a positional { a: 1 } and now raise ArgumentError.
    • 24 are form_row({ key: "k" }), now read as keywords and so "requires content", as form_row(key: "k") already was.
    • 20 are local_auth with positional arguments on an explicit Ruflet-owned receiver, such as Ruflet.text("x").local_auth(1) or .local_auth(1, 2). main built a generic LocalAuth there, and v0.0.23 a generic control. They are counted in the v0.0.23 table above.
  • In the forwarding matrix, 224 *a-only wrapper calls (def w(*a) = table(*a) called with keywords) now read the trailing Hash as keywords, by the same rule, and so give what the direct Ruflet::DSL call gives. 118 go from raising to building and 102 build differently. 4 go from building to raising: form_row/formrow with only key:, which "requires content", as form_row(key: "k") already did. main's VM and this head's VM give the same split.

CRuby this PR vs VM this PR: they agree, apart from error message wording, on bare calls in objects without a method_missing of their own, on send and __send__, at the top level (including top-level public_send), in builder blocks and on Ruflet.*/Ruflet::DSL.*. The exception is calls that splat positional arguments and pass keywords, which lose their keywords on a VM without #81. With #81, all 1,260 forwarding-matrix rows are identical to CRuby's. The VM-only differences are listed below.

Limits, stated rather than special-cased

  • VM without fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81: a scoped helper called with a positional splat and keywords loses its keywords. This covers stepper(*args, **opts), table(*rows, border_width: 1) and table(...).
  • VM: obj.public_send(:table, ...) builds. mruby hands public_send of an undefined name to method_missing with no visibility check and no record of the call form, so it cannot be told from send. v0.0.23's VM and CRuby raise. This is raise-to-build only.
  • VM: a call that reaches Kernel#method_missing through another class's method_missing and super raises, whether it was bare or explicit. That covers a user class with its own method_missing, and instance_eval on a Ruflet::Page, Ruflet::Event or Ruflet::DeviceInfo. The VM cannot tell a bare call there from an explicit one, so the explicit-receiver rule wins, as on v0.0.23's VM. CRuby builds the bare call. No Ruflet API runs user blocks with instance_eval on those objects: it does so only on DSL::App and builders, which have no method_missing of their own.
  • VM: explicit calls on a Ruflet-owned object raise, as on v0.0.23's VM, because dsl_receiver? is always false there. CRuby builds Ruflet.text("x").table(1), as v0.0.23's CRuby built a generic control.
  • VM: the explicit-call stop is mruby 449627d's visibility check. Later mruby (9aaa7ce5fb) drops it, so explicit calls would then reach Kernel#method_missing. Any mruby update must re-run the VM matrix. The receiverless? comment says so. fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81 does not move the mruby pin; it adds only the one prepare_missing hunk.
  • CRuby: private_call? is per-thread VM state. CRuby fills it from the thread's last method miss. A method_missing that hits and rescues another miss before calling super therefore changes the answer for the call it passes on. In round 3's probe:
    • Clobber.new.table(1) and Clobber.new.about_dialog build here, where v0.0.23 and main raised;
    • with an inner explicit miss instead, a bare table(rows: []) in that class raises, as on v0.0.23, where main built.
    • Neither outcome breaks a call that works on v0.0.23.

Embedded VM: splat-forwarded keywords need #81

Forwarding matrix: 63 names × 5 wrappers × 4 shapes = 1,260 calls.

  • Wrappers: *a, **k, &b; *a with a literal key: "lit"; ...; a named positional parameter with **k; *a only.
  • Shapes: (key: "k"), ([], key: "k"), (text, key: "k"), (key: "k") { }.
  • Each call is compared with the direct Ruflet::DSL call on the same runtime.
  • Every VM run below was repeated and gave byte-identical output. Each figure matches round 5's and the round-5 reviewer's.
runtime builds same as the direct Ruflet::DSL call
committed prebuilt VM 0 (all 1,260 raise: the names do not exist there) 1,260 (both raise)
VM built from v0.0.23's Ruby 0 (all 1,260 raise NoMethodError) 1,260 (both raise)
main's VM, 742a000 986 1,036, row for row identical to CRuby main. The 224 others are *a-only wrappers, where a keyword Hash stays positional on a Kernel method.
this head's VM, unpatched 698 526. The other 734 are all calls through the 3 wrappers that splat and pass keywords: 234 build without their keywords, 24 build with another call's keywords (key: "lit"), 402 raise where the direct call builds, and 74 raise a different error where it raises too. The other 504 rows (named parameter, *a only) are identical to CRuby this head.
this head's VM + #81 1,100 1,260, row for row identical to CRuby this head
CRuby, this head 1,100 1,260
CRuby, main 986 1,036 (the same 224 *a-only rows)

Release coupling

  • The runtime release that first rebuilds the VMs from a tree containing this PR also contains fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81, and its build applied the patch (ruby ruby_runtime/vm/patches/mruby_patches.rb --check exits 0, or git -C ruby_runtime/third_party/mruby diff --stat shows src/vm.c).
  • tools/embedded_vm_harness/tests/scoped_helper_test.rb on that VM prints all checks passed with nothing skipped. A KNOWN LIMIT line means the patch is missing.

Nothing else here needs a runtime or template release. The template and the prebuilt VM binaries are untouched.

Extension contract

extension_authoring.md says a helper registered with Ruflet::Extensions.register_control works in the bare DSL, Ruflet, Ruflet::UI, Ruflet::DSL and widget builders. Registering a missing Flutter widget under its own name, such as :stepper, :table or :form, was the natural thing to do before these were built in.

extension_helper_collision_test registers all 63 names in a child process and calls each at 12 entry points:

  • Ruflet.*, Ruflet::UI.*, Ruflet::DSL.*, WidgetBuilder#*;
  • Ruflet.column { name(...) }, DSL.app { name(...) };
  • a top-level call, with and without arguments;
  • App#view, and a component with and without arguments;
  • Object.new.name(...).

Of the 756 calls, 0 miss the extension on v0.0.23, on main and on this branch. On 3912c13, the head before the include-order fix, 52 miss. In round 4, the VM extension probe gave output identical to v0.0.23's VM on a VM built from this branch.

Tests

packages/ruflet_core/test/kernel_helper_shadowing_test.rb (24 tests) checks:

  • Kernel surface: loading Ruflet adds no method to every object beyond v0.0.23's 406 names, apart from extensions an app registers at runtime, and removes none. None of the 63 names is a Kernel method or visible through respond_to?(name, true).
  • Other builders: a method_missing builder gets every name as a bare word, with arguments and with a block. A real Nokogiri::HTML::Builder builds <table> and <form action="/x">.
  • Explicit receivers:
    • 10 call forms × 6 receivers, including public_send;
    • 7 names on 7 receivers with no arguments, including Ruflet.text("x") and the top-level object;
    • with arguments or a block alone on Ruflet-owned objects, which still build, including TOPLEVEL_BINDING.receiver, a page and an event.
  • Bare calls: every name, as a bare word, name() and self.name, in a plain object, a component, an app and a test, gives what Ruflet::DSL.<name> gives.
  • New this round: test_ruflet_and_ruflet_ui_build_what_ruflet_dsl_builds. Every name through Ruflet.* and Ruflet::UI.*, over 4 shapes, builds what Ruflet::DSL builds, and each built patch shows the keyword, the positional control and the block's child.
  • test_forwarded_calls_build_what_the_direct_call_builds. Every name, forwarded through *args, **props, &block, a literal keyword after a splat, and ..., with 4 argument shapes, builds what Ruflet::DSL builds.
  • test_keywords_that_arrive_as_a_trailing_hash_are_keywords. Seven calls run in a keywordless user class, a Ruflet::*-named keywordless class, Ruflet::Event and Ruflet::Page, and as send, __send__ and TOPLEVEL_BINDING.receiver.send with the keywords written as a trailing Hash. Each must equal Ruflet::DSL's patch with real keywords.
  • test_other_trailing_hashes_are_passed_as_written. A String-keyed Hash, a mixed-key Hash, an empty Hash and a Hash beside keywords stay positional.
  • test_without_private_call_a_call_that_reaches_kernel_directly_had_no_receiver. This runs receiverless? on CRuby with a VM-like error that has no private_call?. It covers an object with its own method, a class with its own method_missing (with and without its own method), another name, a bare-word NameError, an unrelated constant NameError, and a receiver Kernel#method cannot look method_missing up on.
  • test_an_unrelated_name_error_behind_kernel_propagates. In a child process, a module included into Kernel after Ruflet raises a NameError for another name. That error propagates instead of being taken for the helper's miss.
  • test_page_leaves_the_new_helpers_to_kernel. It checks the bare stepper(current_step: 1) and about_dialog in a page block, page.table(rows: []), page.about_dialog raising, respond_to?, the setter, and the unchanged page.text("x") hint.
  • Lookup order, wire output inside Ruflet.run, apps and components, and the builder entry points, as before.

tools/embedded_vm_harness/tests/scoped_helper_test.rb is the same contract on the VM: no Kernel methods, bare calls, send/__send__ keywords, explicit receivers, another builder's method_missing, forwarding through named parameters, and 11 splat-forwarding checks gated on the probe described in "Changes in this round". Results are in the table there. The file is valid mruby and CRuby.

packages/ruflet_core/test/extension_helper_collision_test.rb covers all 63 names at 12 entry points, as described above.

packages/ruflet_rails/test/html_dsl_helpers_test.rb checks:

  • every scoped name except local_auth is an ActionView helper, and none is a Kernel method;
  • local_auth is only the Ruby DSL's short name for the local_authentication service, and views get helpers from the control registry;
  • markup round-trips.

How the tests were checked:

  • Planted bugs, this round: 201 forwarder plants, all caught by the new test; see "Changes in this round".

  • Planted bugs, earlier rounds (from round 5, on 3a7ca07): 22 implementer plants and 18 reviewer plants in lib/, each caught by at least one of the PR's test files. There were also 6 VM-path plants overlaid on the compiled framework, each failing scoped_helper_test.rb on the unpatched and the patched VM. Among them:

    • owned_call?: ignoring the block, keywords or positional arguments; never, always;
    • build: keys.any?, dropping keywords or the block, no keyword restoration, the Symbol-key or non-empty check dropped, the last Hash taken despite keywords;
    • receiverless? and kernel_method_missing?: the name check dropped, always true, private_call? ignored, the VM fallback using receiver.method or rescuing to false;
    • the NameError handling: rescuing only NoMethodError, never re-raising, the NameError branch dropped;
    • the module: not included into Ruflet or Ruflet::UI, the include order swapped, HELPERS missing names, a forwarder removed;
    • Kernel: form or stepper back on Kernel, a keywordless Kernel#method_missing, the generic build path;
    • earlier fixes: the SharedControlForwarders decline, the Page exclusion, helper? ignoring extensions.

    This round removes no check or assertion and changes no lib/ line, so those plants are still caught. The scoped_helper_test.rb probe changed, so the gated checks were re-checked with the gate forced open on the unpatched VM (all 11 fail).

  • Copied onto other trees (this round's test files, CRuby 4.0.5):

    • On 3a7ca07, all 24 pass, the new test included: it pins behaviour the previous head already had.
    • On ecc394a, 6 of 24 fail (2 failures, 4 errors), as in round 5.
    • On main 742a000, 13 fail (6 failures, 7 errors), as in round 5. The new test passes there: main has the same 63 forwarder lines, on SharedControlForwarders.
    • On v0.0.23, 17 fail (3 failures, 14 errors): round 5's 16 plus the new test, because the names do not exist there.
    • The collision test passes on all four.
  • Ruby 3.2.9: the shadowing test gives 24 runs, 0 failures, 1 skip (Nokogiri is not installed for that Ruby). The collision test and scoped_helper_test.rb (87 checks) pass.

  • Random seeds: the shadowing test passes on 10 random seeds.

Suites

On head 7f6a0c37, every file run in its own process with Homebrew Ruby 4.0.5:

  • ruflet_core: 189/189 files.
  • ruflet_server: 13/13.
  • ruflet: 13/13, with no rerun needed.
  • ruflet_rails: 17/17, run with -I to the sibling packages. Gemfile.lock is untouched.
  • ruflet_record: 5/5 (not touched by this PR; run for completeness).

That is 1,608 runs (1,584 without ruflet_record), 0 failures and 1 skip (the gated dsl_presented_controls test). The shadowing test ran its Nokogiri test (0 skips), and the worktree was clean afterwards.

ruby -w on the shadowing test shows only the existing page.rb CGI warning.

H1 goldens: the harness (packages/ruflet/test/compat/compat.rb) is not on main yet. Overlaid from the current origin/test/cli-compat-goldens (c6085a7, #73) with git merge-tree onto this head, ruby test/compat/compat.rb checked 234 goldens with 0 differences.

Other open PRs: this head merges with each of #71, #81, #82, #83, #84, #86, #87, #88, #89 and #90 with no conflict (git merge-tree). On each merged tree except #81, these all pass:

  • the Ruby test files that PR changes under ruflet_core, ruflet_rails, ruflet_server and ruflet;
  • this PR's shadowing, collision and html_dsl_helpers tests;
  • scoped_helper_test.rb on CRuby.

#81 changes only VM build files. The "this head + #81" VM above is built from that merge.

Embedded mruby VM: verified on current sources

These are scratch macOS arm64 builds made this round with the vendored mruby 449627d, the same steps as tools/build_apple_vm_artifacts.sh (arm64 slice only: this Mac has no Rosetta) and tools/embedded_vm_harness/build.sh. The probes ran under embedded_mruby --preload:

Results:

From round 4, on a VM built from ad7a3d5 (same executable code as this head):

  • the send-family probe prints output identical to main's VM;
  • the 17,073-call matrix has no call going from building to raising against v0.0.23's VM;
  • explicit receivers raise as on v0.0.23's VM;
  • the extension probe output is identical to v0.0.23's VM.

Doc-harness result

From round 5, on 3a7ca07, which has the same lib/ as this head. The harness lived in a scratchpad that has since been cleared and was not re-run this round. All 183 documented examples were run with compat/harness/run.rb and compared with the v0.0.23 baseline, ignoring tree_probe:

  • 183 of 183 are identical to v0.0.23.
  • 8 raise, identically on v0.0.23, and belong to other audit areas: control_dropdown__3, control_floating_action_button__2, control_switch__2, rails_api_reference__3, rails_assets__3, rails_integration__5, rails_native_html__1 and rails_native_html__2.

Cost

Measured in round 4 on ad7a3d5, which has the same executable code as this head. CRuby 4.0.5, 20,000 calls, process CPU time, best of 7 rounds, each tree run twice. The machine's load average was above 400 throughout, so treat these as rough. Times are in µs per call.

call main previous head ecc394a7 ad7a3d5 (= this head)
bare text("x") (a v0.0.23 Kernel helper) 18.4 / 19.8 18.8 / 22.9 20.3 / 20.3
Ruflet.table_row([]) 10.8 / 10.8 13.1 / 12.3 11.6 / 13.0
bare table_row([]) in a component 10.4 / 9.6 14.3 / 11.8 15.6 / 13.9
bare stepper(current_step: 1) 21.5 / 23.2 27.6 / 29.2 30.8 / 29.6
bare ignore_pointer 13.7 / 13.6 18.1 / 20.8 20.4 / 18.4
stepper(current_step: 1) through a keywordless method_missing 21.3 / 24.2 32.3 / 31.6 33.2 / 29.5

A bare call to a scoped name costs about 4 to 8 µs more than on main. That is one method_missing dispatch plus the NameError that super raises and that is rescued. Calls to the 406 v0.0.23 helpers and to Ruflet.* do not go through this path.

Not in scope

  • The mruby fix itself. Draft fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81 carries it as a VM build patch. It must ship with the runtime rebuild that first carries this PR's Ruby; see "Release coupling".
  • Extension helpers stay on Kernel. Helpers registered at runtime through Ruflet::Extensions.register_control still go onto Kernel, as at v0.0.23. That includes one registered under a scoped name.
  • Pre-existing at v0.0.23 (extensions.rb is identical): on the embedded VM, register_control raises TypeError: wrong argument type String (expected Symbol). define_control_helper calls Kernel.send(:private, <String>).
  • Prebuilt VM binaries: the ones in ruby_runtime are not rebuilt here, matching how feature PRs are merged.
  • ERB table: the ERB table helper still emits <table>, which maps to DataTable. This is an audit side note.
  • page.local_auth / page.local_authentication: these are real Page methods added by New controls and their protocol, client actions, local auth, and review follow-ups #72 and are unchanged.

SharedControlForwarders is included into Kernel, so every helper added to
it becomes a private method of every object in the process. The 32 names
added since v0.0.23 (table, table_row, stepper, stepper_step, form_row,
list_section, carousel_view, fitted_box, indexed_stack, custom_scroll_view,
sliver_*, draggable_scrollable_sheet, about_dialog and compact spellings)
therefore won over other libraries' method_missing builders: in a Rails app
that loads ruflet_core, Nokogiri::HTML::Builder.new { table { ... } } built
a Ruflet Table and left the document empty.

Move those forwarders to Ruflet::UI::ScopedControlForwarders, included into
the Ruflet and Ruflet::UI singletons only. Builder blocks keep them through
UI::ControlMethods, and a bare call that falls through to Kernel#method_missing
is forwarded to the same Ruflet::DSL helper the Kernel method called, so
stepper(...) in a Ruflet.run block, an app's view or a component builds the
same control as before. Without arguments the call is only taken at a
script's top level or in a Ruflet::App/Ruflet-owned object; elsewhere Ruby
raises as it did at v0.0.23. The top-level object is captured at load
because the embedded mruby VM has no TOPLEVEL_BINDING.

The Kernel surface is pinned to v0.0.23's list in
test/fixtures/kernel_helpers_v0_0_23.txt so later helpers cannot land on
Kernel again.
…rs raising

Two regressions from the previous commit on this branch.

Ruflet and Ruflet::UI included ScopedControlForwarders after
SharedControlForwarders, which put the built-in scoped helpers ahead of it in
lookup. Ruflet::Extensions defines a registered helper on
SharedControlForwarders, so an extension registered under one of the new
names (stepper, table, carousel_view, ...) was shadowed by the built-in on
Ruflet.<name> and Ruflet::UI.<name>: 52 of 64 such calls raised
ArgumentError. v0.0.23, where those names were not built in, sent all of
them to the extension. The include order is swapped so
SharedControlForwarders is looked up first.

Kernel#method_missing built a control for any call with arguments whatever
the receiver, so Object.new.stepper([1]), Struct#table(1), nil.table(1) and
app.about_dialog returned controls where v0.0.23 raised NoMethodError. A
scoped name now builds only where a private Kernel method could have been
called: without an explicit receiver. CRuby reports that through
NoMethodError#private_call? on the error super raises; on the embedded VM an
explicit call cannot reach the private Kernel#method_missing on its own, so a
call is treated as implicit only when Kernel#method_missing is the
receiver's own. Explicit calls re-raise the exact NoMethodError v0.0.23
raised. SharedControlForwarders#method_missing declines the scoped names so
its generic known_control? path no longer builds them for explicit
receivers either. Names an extension has registered keep the generic path,
as at v0.0.23.

extension_helper_collision_test registers all 32 names as extensions in a
child process and checks 11 entry points; it fails on the previous head with
52 wrong calls. kernel_helper_shadowing_test gains explicit- and
implicit-receiver cases and a lookup-order check.
…d helpers

The comment on ScopedControlForwarders.implicit_call? said a call with an
explicit receiver can reach Kernel#method_missing on the embedded VM only
through another class's method_missing calling super. mruby's send and
public_send also hand an undefined method to method_missing without the
visibility check, so record.public_send(:table, rows: []) builds a control
there while CRuby raises. Say so. No code change.
…sing

Two changes to which calls of a scoped helper (stepper, table, about_dialog,
...) build a control, so the newer helpers are called the way every helper
v0.0.23 shipped is.

Without arguments. A scoped helper built with no arguments only at the top
level, in a Ruflet::App or on a Ruflet-owned object, and raised NameError
elsewhere: `about_dialog` or `sliver_app_bar` in a component class or a test
failed while `divider` worked. Every v0.0.23 helper is a private Kernel
method and answers a bare word in any object, so a scoped helper now does
too: a call without an explicit receiver builds, with or without arguments.
Explicit calls still raise as at v0.0.23 (`record.table` and
`record.table(1)`), and an object with its own method_missing is still
asked first, so Nokogiri-style builders keep the names.

Ruflet-owned receivers. Kernel#method_missing built for any call on a
Ruflet-owned object, so `Ruflet.text("x").table` and `.about_dialog`
returned controls on CRuby where v0.0.23 and main raise NoMethodError.
v0.0.23 built a generic control there only for a call with arguments, a
block or keywords; that is the rule again. The embedded VM already raised
there.

kernel_helper_shadowing_test checks every scoped name as a bare word,
name() and self.name in a plain object, a component, an app and a test
against Ruflet::DSL.<name>, and zero-argument explicit calls on plain and
Ruflet-owned receivers. extension_helper_collision_test adds a zero-argument
component entry point.
…per-shadowing

Conflict in shared_control_forwarders.rb, resolved by meaning rather than
by side: #72 added 31 bare helpers to SharedControlForwarders, which is
included into Kernel, so each became a method of every object in the
process (absorb_pointer, fractionally_sized_box, ignore_pointer,
intrinsic_height, intrinsic_width, sliver_padding, clip_oval,
clip_rsuperellipse, the five *_transition helpers, form, nested_scroll_view,
their compact spellings, and the local_auth/local_authentication service).
Keeping main's lines would have failed this branch's v0.0.23 surface test
and brought the audit regression back for `form`:
Nokogiri::HTML::Builder.new { form(action: "/x") { input(type: "text") } }
raised ArgumentError from FormControl instead of building <form>.

All 31 move to ScopedControlForwarders and HELPERS, so Kernel keeps exactly
the v0.0.23 set and every entry point #72 tests (Ruflet.*, Ruflet::UI.*,
Ruflet::DSL.*, WidgetBuilder, DSL.app, builder blocks, bare calls with or
without arguments) still builds the same control. #72's tests pass
unchanged.

Tests: NEW_HELPERS and the extension collision NAMES list all 63 scoped
names; the Nokogiri probe also builds a <form>; a test builds every #72
helper bare inside Ruflet.run; explicit-receiver cases cover form,
ignore_pointer, fade_transition and local_auth. The Rails test now expects
local_auth to be the one scoped name that is not a view helper: views get
helpers from the control registry, where the service is
local_authentication, as on main.
The decline in SharedControlForwarders#method_missing is reached through
Kernel#method_missing's own super, not by a separate path, and the :build
branch applies to owned receivers with arguments only on CRuby; the
comments now say so. No code change.
… helper

A class whose own method_missing takes no keywords
(def method_missing(name, *args, &block) ... super) hands a call's keywords
on to Kernel#method_missing as a trailing Hash. A scoped helper then took
that Hash as its content: stepper(current_step: 1) in such a class built a
Stepper whose steps were {current_step: 1}, and about_dialog(...) raised
ArgumentError. v0.0.23 raised NoMethodError there; on main the helper was a
Kernel method, found before that method_missing, and got the keywords as
written.

For a call that passed through another method_missing, a trailing Hash of
Symbol keys is read as keywords again, so the helper builds what main
built. Anywhere else arguments are passed as written, and explicit
receivers still raise.

kernel_helper_shadowing_test checks stepper, table, about_dialog,
local_auth and form through such a class against Ruflet::DSL, that an
explicit call on it still raises, and that a positional Hash in an
ordinary object is still positional.
The embedded VM hands method_missing the keywords of send, __send__ and
public_send as a trailing Hash, so `send(:table, rows: [])` built a Table
whose rows were that Hash and `send(:about_dialog, application_name: "A")`
raised ArgumentError, where main's VM built both. On CRuby the same
happened on the path for Ruflet-owned receivers (Ruflet::Event, Page,
DeviceInfo, a Ruflet::* class of an extension gem) whose method_missing
takes no keywords.

Kernel#method_missing now decides a scoped helper in one place and builds
it through ScopedControlForwarders.build, which reads a trailing non-empty
Hash of Symbol keys, when no keywords were passed, as the keywords. That
rule is the same on CRuby and the VM and on every path, so dispatch,
call_arguments and own_method_missing? are gone. SCRIPT_MAIN is gone too:
a top-level call with arguments is already a dsl_receiver? call, and an
explicit `main.table` with no arguments now raises NoMethodError as on
v0.0.23 and main instead of building.

Ruflet::Page no longer answers the 63 scoped names with its "free widget
helper" hint (its helper set is v0.0.23's again), so a bare
`stepper(current_step: 1)` in a page block builds, `page.stepper = x` sets
a page property and `page.respond_to?(:stepper)` is false, as on v0.0.23.
…shes

On the embedded VM, a scoped helper called with a positional splat and
keywords (`stepper(*args, **opts)`, `table(*rows, border_width: 1)`,
`table(...)`) loses the keywords before Kernel#method_missing runs, or
raises a TypeError about whatever was on the stack. That is a heap
over-read in the vendored mruby 449627d: prepare_missing() in src/vm.c
reads a splat call's keyword Hash from argv[ci->n], past the frame,
instead of argv[1]. It already hit v0.0.23 names reached through
method_missing (`elevatedbutton(*a, **k)`); routing the 63 scoped names
there exposes it for them, where main's VM had Kernel methods. Upstream
mruby fixed it in 550d10adb7 (mruby PR #6598), which is not in 449627d.
Nothing in Ruby can restore the keywords, so the fix belongs to the VM
build; build's comment now says so.

tools/embedded_vm_harness/tests/scoped_helper_test.rb checks the scoped
helpers on the VM: no Kernel methods, bare calls, send keywords, explicit
receivers, another builder's method_missing, and forwarding through named
parameters. A pure-Ruby probe tells whether the VM has the mruby bug; the
10 splat-forwarding checks run where it does not and are reported as a
known limit where it does. The file is valid mruby and CRuby.

kernel_helper_shadowing_test now also checks:
- every scoped name forwarded through `*args, **props, &block`, a literal
  keyword after a splat, and `...` builds what Ruflet::DSL builds;
- block-only explicit calls on Ruflet-owned receivers (`Ruflet.text("x").table { }`,
  `event.stepper { }`, `main.form { }`) still build;
- a Hash with mixed Symbol and String keys stays positional;
- receiverless? treats a receiver Kernel#method cannot inspect as one
  whose method_missing is Kernel's.

The receiverless? comment also notes that the VM's explicit-call stop is
mruby 449627d's visibility check, which later mruby drops.
kernel_helper_shadowing_test gains
test_ruflet_and_ruflet_ui_build_what_ruflet_dsl_builds. The 63
ScopedControlForwarders methods are now reached only through Ruflet.*
and Ruflet::UI.*, and before this only respond_to? and a few names
pinned them. The test compares Ruflet.<name> and Ruflet::UI.<name> with
Ruflet::DSL.<name> for every scoped name over four shapes: keywords only,
an empty positional, a control positional, and a block that adds a
child. It adds the keywords a helper needs to build (body: for
nested_scroll_view, title: for stepper_step). It also checks that each
built patch shows key:, the positional control and the block's child,
so a dropped keyword, argument or block changes what is compared.

scoped_helper_test.rb now describes the mruby 449627d limit correctly.
A splat-forwarded call to a missing method can build without its
keywords, build with an earlier call's keywords, or raise. It names the
fix, upstream 550d10adb7, which #81 carries as a VM build
patch.

The probe now runs all three forms the gated checks use: `*a, **k`,
`*a` plus a literal keyword, and `...`. It runs them after a call that
leaves other keywords behind, and compares positional arguments and
keywords exactly. A VM built with the patch runs every check.

A new gated check covers the stale case: carouselview forwarded right
after a call with key: "earlier" must build with its own key: "k".

No lib change.
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