Repository navigation
A top-level return with a value, and ruby's warning of it (round 65) - #257
Merged
Merged
Conversation
The native compiler compiles a file's own return with a value, and counts it. ruby says "argument of top-level return is ignored" as it compiles a file, before it runs, once a return, with the file and no line: said so now on both executions, for the main script, a required file and a loaded one. The evaluator read a comment that only mentions shareable_constant_value as the magic comment; it reads the comment's key now. One of round 63's comments in the Ruby compiler warned each time that compiler was loaded. m_pathname_lib.mere, the embedded copy of the Ruby compiler, is generated again: round 63 changed the lib and not the copy. Corpus 823.
284km
commented
Nov 25, 2026
284km
left a comment
Owner
Author
There was a problem hiding this comment.
Reviewed 699f0ae. No Critical / Major / Minor findings that block.
- What changed:
- The native compiler compiles a top-level
returnwith a value. - "argument of top-level return is ignored" is reported as ruby does: at compile time, once per such return, and with the file name only. This covers main scripts,
requireandload, on both modes. - The evaluator reads a magic comment only at a key position, so a comment line that merely mentions
shareable_constant_value:no longer sets it. - The embedded copy of the Ruby compiler (m_pathname_lib.mere) is regenerated. It had missed round 63's shareable compile.
- The native compiler compiles a top-level
- Probe on the author's build at this head (clean tree, binary newer than the sources), against ruby 4.0.10, the evaluator,
MERE_RUBY_VM=1, and main 323706a + #253 on both modes. The script requires a file containingreturn 1 if trueand another with a barereturn, thenloads the first. It also requires a file whose first line is# foo shareable_constant_value: literalunder-*- frozen_string_literal: true -*-, and ends withreturn 2.- The warnings (which, how many, in what order, file names only), the outputs and the frozen states match ruby on both modes.
- main's evaluator printed one warning at the end and treated the commented line as a magic comment.
- main's VM added line numbers.
- Follow-up, the same on main's evaluator:
# frozen_string_literal: false; shareable_constant_value: literalon a plain#line (no-*- … -*-) makesY = [1]frozen on the evaluator. ruby honours only the first key there, and the VM agrees with ruby (false). ruby reads;-separated keys only inside the emacs-style-*- … -*-form. git merge-treeagainst current main (44aa511): clean. No mere-pr-review-watch inline comments.- Local results in the description meet the merge criteria:
Merging.
This was referenced Nov 25, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round 65 of the VM stream (note 558, item 1). The native compiler compiles a top-level
returnwith a value, and ruby's warning of it is said as ruby says it on both executions. Two things found on the way are in it too: the evaluator read a comment that only mentionsshareable_constant_valueas the magic comment, and round 63 left mere-ruby's embedded copy of the Ruby compiler stale.The CI checks of #232 follow this PR: one of them checks that the embedded copy is current, and fails on main until this is merged.
The record is
loop/2026-11-25-stage10-r65.md; what follows is it.After round 64 the native compiler declined nothing in the corpus's main scripts. Among the files those programs require, it declined two reasons: a BEGIN block, the evaluator's by design, and a top-level
returnwith a value. This round compiles the second.What ruby does
A file's own
returnends the file, and a value given to it goes nowhere. ruby says so as it compiles the file, before any of it runs:returnof the top level, a rescue or an ensure clause's included (one in a method or a block is another scope);-W0.The compiled sequence is the plain return's: the value is pushed and the frame left.
What it was here
The change
ic_vm_nativesays the warning that many times once the file is loaded.top_ret_args, which now looks through a rescue clause,and/orand a statement's wrapping) and says the warning before the file runs: the main script, a required file the VM does not take, and a loaded file. A file the VM takes is told of by its compiler.Found on the way: a magic comment that was only a mention
With the Ruby compiler in use (
MERE_RUBY_IC=ruby), every run saidThat line is a comment of round 63's:
# pm_compile_shareable_constant_value: a literal is pushed.... The evaluator's lexer took the name anywhere in a comment for the magic comment. ruby takes it only as the comment's key: right after the#, or after a;or the-*-of the emacs form. So# a-shareable_constant_value: literaland# foo shareable_constant_value: literalare no magic comment, and here they were. The lexer reads the key's place now.And the embedded copy was stale. mere-ruby carries the Ruby compiler as a string, generated from
lib/iseq_compiler_ext.rbintom_pathname_lib.merebytools/gen_pathname_lib.rb. Round 63 (#233) changed the lib and did not regenerate the copy. So on main the Ruby compiler that mere-ruby runs still declined the shareable constant writes that round 63 taught it, andcompare_files.rb, which runs the lib under ruby, could not see it. The copy is regenerated here, and the CI checks #232 proposed, in a PR that follows this one, check that it is current.Numbers
The native compiler now declines, among every file the corpus's programs require or load, only the BEGIN blocks: three files.
Corpus 823 runs children and reads their two streams as one: a main script, two required files with returns in an
if, abeginwithrescue,elseandensure, a block, a method and anand, a loaded file, a bare return; under no flag,-W0and-w. And the magic comment's forms. It matches ruby on both executions, and on the VM through the Ruby compiler too; on main's build it differs on both.Recorded, as on main: the VM through the Ruby compiler
The Ruby compiler is the VM's when the native one declines a file, which in the corpus is nowhere now, and under Coverage's branch mode, where it is the one that compiles the branches in. With it forced for every file (
MERE_RUBY_IC=ruby), three corpus programs differ from ruby: 675, 725 and 819. They differ the same way on main's build. 819 is round 62's literal Hash key, which the native compiler's values intern and the Ruby compiler's do not. Four more fall back there, the sources in other encodings, which the Ruby compiler does not take.Checked
Against ruby 4.0.10 (tools/ref_ruby.sh), built with Mere 9dec2ff6, on main 66a7afd (#235; main has moved since by #232 and #236, which change no code this touches):
tools/iseq/native/check.shover the corpus and four files of returns: 882 the same as the Ruby compiler, 0 refused, 0 different.compare_files.rbover the same: 882 the same as ruby.compare_with_ruby.rb: 460 the same.tools/gen_pathname_lib.rbgivesm_pathname_lib.mereas committed.m_pathname_lib.mereas generated.🤖 Generated with Claude Code