mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-01 23:57:21 +00:00
* fix(ruby): a block parameter stops the receiver type walk — it no longer takes a same-named outer local's type (RUBY-03)
The shared receiver walk stops at the nearest scope that owns the
receiver's name, and a scope owns a name it holds no type for only through
Scope.lexicalNames. Ruby published none, so an untyped parameter was
invisible to the walk, which climbed past it to a same-named outer binding:
`user = User.new; items.each { |user| user.save }` resolved the block's
`user.save` to User#save.
- emitRubyScopeCaptures attaches @scope.lexical-names to every scope that
declares parameters: a do/end or brace block (its |...| names, block
locals included; this covers lambda { |x| }, proc { |x| } and
Proc.new { |x| }), the body block of a stabby lambda (its parameter list
is a sibling of the body), and a method or singleton method. Blocks
already had scopes; none is added. Numbered and `it` parameters are not
declared names and are not listed.
- The YARD @param decline (RUBY-01) no longer fires for a block, lambda or
nested-def parameter of the tagged name: the shadow now stops the walk on
its own scope, so the tagged use beside it keeps its type. A stabby lambda
whose parameter default reads the name still declines, because the
parameter list sits outside the lambda body.
Fixed shapes, each pinned against exact owner IDs with a decoy: block and
lambda/proc parameters shadowing a typed local or a YARD-typed parameter,
nested blocks, every block-parameter form, an untyped method parameter named
like a typed reader, an attr_reader @return type or a top-level local, a
nested def parameter under a tagged method, and a bare read of a parameter
(a read, not a call). Recall cost: an explicit target() / target(1) /
target 1 beside a same-named block parameter now resolves to nothing, as it
already did beside a same-named method parameter.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* test(bench): gate Ruby block-parameter stop correctness and scaling (RUBY-03)
Block, lambda and method parameters are published as lexical names on the
scope that declares them, so the receiver walk stops at a block parameter
instead of taking a same-named outer local's type.
bench/ruby-block-param-stop pins what that produces and checks how its
cost grows, in the format of bench/ruby-gem-resolution.
Each file holds class Svc<i> with m(items): `user = User.new`, K blocks
rotating `|x| user.run` (the nearest `user`), `|user| user.save` and
`|user, i| user.save` (no edge), side by side or nested, then `user.save`.
Each method's CALLS must equal the expected multiset; main gives the
rebinding blocks wrong User#save edges. One class per file, because Ruby
resolution on main is already super-linear in the classes of ONE file
(measured with `--shape crowded`, not gated).
--check runs a CI profile (about 15 s locally); --full keeps min of 15
after 2 warmups and a fresh process per shape. Every budget is 1.5.
Re-running the scope query over the method for every block scope fails
the nested block gate (2.242 > 1.5).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* test(bench): ruby-block-param-stop — fixed-width indent, input bytes per cell, 16x side-by-side blocks
Three defects the scaling-bench review found in the other benches apply
here too:
- the nested generator indented each level two spaces deeper, so the
input grew 6.1x for 4x depth; every line now has a fixed-width indent
and each shape pins its input_bytes beside its groups and edges;
- the gate could not see a known O(blocks^2) edit: walking the enclosing
method once per block scope measured 1.410 on the 4x side-by-side
range and passed. Side-by-side blocks now grow 16x (6 -> 96), where
the same edit fails sibling_capture_block_scaling_ratio 3.596 > 1.5
(nested 1.778) with unchanged fingerprints;
- the ratio divides by each shape's own growth factor.
Nesting depth stays 4x: over 6 -> 96 it measures 2.57 (capture) and 2.46
(resolution) from two terms that predate #3905 (the shared callable-flow
fallback that searches a block-taking call's subtree for an argument
list, and the shared lexical lookup climbing from each reference to its
binder); baseline.json `_nested_depth_note` records both. Three CI-profile
runs and one --full run pass, every ratio at most 1.202.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(ruby): resolve PR #3905 feedback
Preserve outer YARD types across lambda defaults and explicit self calls beside parameters. Add parameter-order regressions and a four-size scaling sweep.
Note: pre-existing failure in scenario-map/consolidation.test.ts (jscpd 5.4.2 installed; 5.4.3 expected) not addressed by this PR.
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
/**
|
|
* Explicit calls dispatch on self even beside same-named parameters.
|
|
* Ruby invokes callable locals with `.call` or `.()`, never with `target()`.
|
|
*/
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import path from 'path';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import {
|
|
getRelationships,
|
|
runPipelineFromRepo,
|
|
writeFixtureRepo,
|
|
type PipelineResult,
|
|
} from './helpers.js';
|
|
|
|
describe('Ruby explicit target() beside a same-named parameter', () => {
|
|
let result: PipelineResult;
|
|
let tmpDir: string;
|
|
let hostTargetId: string;
|
|
|
|
const targetsFrom = (source: string): string[] =>
|
|
getRelationships(result, 'CALLS')
|
|
.filter((c) => c.source === source && c.target === 'target')
|
|
.map((e) => e.rel.targetId);
|
|
|
|
beforeAll(async () => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ruby-param-shadow-call-'));
|
|
writeFixtureRepo(tmpDir, {
|
|
'host.rb': `class Host
|
|
def target
|
|
true
|
|
end
|
|
|
|
def run(target)
|
|
target()
|
|
end
|
|
|
|
def run_in_block(target)
|
|
[1].each { |target| target() }
|
|
end
|
|
|
|
def run_plain(other)
|
|
target()
|
|
end
|
|
end
|
|
`,
|
|
});
|
|
result = await runPipelineFromRepo(tmpDir, () => {});
|
|
const edge = getRelationships(result, 'HAS_METHOD').find(
|
|
(e) => e.source === 'Host' && e.target === 'target',
|
|
);
|
|
if (edge === undefined) throw new Error('fixture lost Host#target');
|
|
hostTargetId = edge.rel.targetId;
|
|
}, 60000);
|
|
|
|
afterAll(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it.each(['run', 'run_in_block'] as const)(
|
|
'%s: explicit target() beside a same-named parameter calls Host#target',
|
|
(fn) => {
|
|
expect(targetsFrom(fn)).toEqual([hostTargetId]);
|
|
},
|
|
);
|
|
|
|
it('run_plain: explicit target() beside an unrelated parameter calls Host#target', () => {
|
|
expect(targetsFrom('run_plain')).toEqual([hostTargetId]);
|
|
});
|
|
});
|