Good first issue (one language per PR): teach the `tangle` steering-locals walk one more language — Kotlin, Swift, Dart, Lua, GDScript, PHP, Ruby, Bash

Aperta
#873 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
tooling

Direzione di ricerca

Start with src/ingest_metrics.h functions steer_noteDeclaration, steer_noteWrite, and steer_noteCondition, then inspect SteerDecl and the language row in src/langfacts.h. Mirror the matching fixtures in test/lib/tanglefixtures.py and regression arms in test/tanglecheck.sh; first verify the chosen language’s steerfar case has no steer= on main. Done means the far case reports steer="1", all three near misses omit steer=, and the listed regression, cache, identity, and quality checks pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement good first issue help wanted

Claim a language in a comment here first, one language per PR. Size: S each. Depends on: nothing. Good for a first contribution: one branch in one function, a fixture generated by a script that already exists, and a twin in a language that already works.

The problem, in user terms

--quality-delta's tangle kind scores a long function by its nesting, its deep share and its steering locals: a primitive local (a flag, a counter) rewritten in one place and then read in a branch condition ten or more statements later, so the reader has to carry it in their head. --metrics prints the count as steer=.

The walk that finds steering locals reads each language's declaration grammar, chosen by LangFacts::steerDecl (src/langfacts.h:141, SteerDecl). Eight shapes exist (C family, Python, JS/TS, Java, C#, Go, Rust). For Swift, Ruby, PHP, Lua, Elixir, Dart, Kotlin, GDScript, Clojure and Bash it is None, so steer is always 0 there and tangle is nesting and deep share only (src/langfacts.h:138-140).

Repro: the same 85-line function in each language (a flag set inside a loop, then tested 12 statements later; the shape of steerfar in test/lib/tanglefixtures.py). On main (e94757295), other attributes cut:

ripwire <dir> --no-cache --metrics --page-bytes=0
java    <s t="method" n="steerfar" cx="4" loc="85" nest="2" steer="1" tangle="0.9"
kt      <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"
swift   <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"
dart    <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"
lua     <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"
gd      <s t="fn"     n="steerfar" cx="4" loc="81" nest="2"
php     <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"
rb      <s t="method" n="steerfar" cx="4" loc="85" nest="2"
sh      <s t="fn"     n="steerfar" cx="4" loc="85" nest="2"

Expected after a language's PR: that language prints steer="1" on steerfar, as Java does, and no steer= on the near twin (the flag tested in the next statement, steernear).

Where to look

  • steer_noteDeclaration, src/ingest_metrics.h:914: one if( shape == SteerDecl::… ) branch per declaration grammar. Copy the closest one.
  • steer_noteWrite, src/ingest_metrics.h:1001: the write shapes (assignment_expression, augmented_assignment_expression, Go's assignment_statement, update_expression, …).
  • steer_declare (:742), steer_write (:760) and steer_noteCondition (:1286) accept a name only when its node kind is identifier. Some grammars spell a name differently (table below).
  • steer_noteCondition reads the branch's condition field, then its value field. One grammar below has no such field.
  • steer_scopeEndOf (:725): block-scoped languages close a slot at the end of the enclosing block; Python's never close. Pick the right one for your language.
  • SteerDecl (src/langfacts.h:141) and the language's row in kLangFacts (src/langfacts.h:596-648): add the enum value and set .steerDecl.
  • test/tanglecheck.sh arms (s1)-(s4) and test/lib/tanglefixtures.py (steer, steercursor, steerscope): the C++ fixtures to mirror.

The languages

Node names below come from --match on the repro fixture with the main binary. Check them again on yours.

  • Kotlin. Declaration: property_declaration (var / val; only var can steer). Write: assignment (covers +=). Names are simple_identifier, not identifier. if_expression has a condition: field. Block-scoped.
  • Swift. Declaration: property_declaration (var / let). Write: assignment (covers +=). Names are simple_identifier. if_statement has condition:. Block-scoped.
  • Dart. Declaration: local_variable_declaration (initialized_variable_definition name:). Write: assignment_expression, already handled. Names are identifier. if_statement has no condition: field: the condition is a plain child, so steer_noteCondition needs a fallback. Block-scoped.
  • Lua. Declaration: variable_declaration (local x = …, which wraps an assignment_statement). Write: assignment_statement with a variable_list child (no left: field, unlike Go's). Names are identifier. if_statement has condition:. Block-scoped.
  • GDScript. Declaration: variable_statement (var x = …, name: field). Writes: assignment, augmented_assignment. Names are identifier. if_statement has condition:. Indentation blocks are body nodes: check what steer_scopeEndOf sees.
  • PHP. No declaration statement: the first assignment_expression to a $name declares it, as in Python. Writes: assignment_expression, augmented_assignment_expression. Names are variable_name (with a name child). Function-scoped, like Python.
  • Ruby. No declaration statement, as in Python. Writes: assignment, operator_assignment. Names are identifier. if has condition:. Function-scoped for locals (a block's own new locals end with the block: say what you do).
  • Bash. Declaration: declaration_command (local x=…). Write: variable_assignment. Names are variable_name; a read in a test is a $x expansion inside a command ([ "$x" -eq 1 ]), not a condition field. Larger than the others: start only if you know the Bash grammar.
  • Not planned: Clojure (let locals cannot be rewritten, so the steering shape does not exist; say so in a comment if you disagree) and Elixir (a rebinding inside a branch does not leak out of it). If you have a measured counter-example, open a separate issue.

Suggested approach (per language)

  1. Write the language's steerfar / steernear pair (copy steer() in test/lib/tanglefixtures.py: 30 lines, a loop that sets a flag, N filler statements, then if flag). Show steerfar with no steer= on main.
  2. Add the SteerDecl value, set it in the language's kLangFacts row, and add one branch to steer_noteDeclaration (and to steer_noteWrite if the write node is new).
  3. If names are not identifier, teach the three name checks your spelling, gated on the shape, so other languages are byte-identical.
  4. Add the steercursor and steerscope near misses for your language: a cursor read only as a bound or an index does not steer, and a local whose block closed does not steer.

The test to add (red first)

A language section in test/tanglecheck.sh (or a small test/steer<lang>check.sh, registered in test/regression.sh in the same commit, or test/manifestcheck.sh fails): steerfar prints steer="1", steernear prints no steer=, and the cursor and scope near misses print no steer=. Red on main first. The metrics are cached: bump kParserVer (src/ingest_cache.h:409) and its mirror kIngestParserVerMirror (src/quality.h:3335) to any number above main's, and run bash test/qschemetripcheck.sh.

Acceptance criteria (per language)

  • steerfar steer="1"; the three near misses print no steer=.
  • bash test/tanglecheck.sh "$PWD/build/ripwire" passes, with the new arms red on main.
  • bash test/langidentitycheck.sh origin/main HEAD --langs=<your lang>,java,py,ts,cpp --repo=<lang>:<your clone>: every other language is SAME. Your language DIFFs only on steer / tangle (and the --quality-delta tangle rows built on them), waived by --intended rows naming the arm. Hand-check ten moved functions on the real repository and say how many were real steering locals.
  • ripwire . --quality-delta=origin/main..HEAD gates 0.

How to verify locally

cmake -S . -B build && cmake --build build -j      # plain build: no build type
./build/ripwire /path/to/your/fixture --no-cache --metrics --page-bytes=0 | grep -o '<s [^>]*n="steer[a-z]*"[^>]*'
bash test/tanglecheck.sh "$PWD/build/ripwire"
bash test/qschemetripcheck.sh
bash test/langidentitycheck.sh origin/main HEAD --langs=<lang>,java,py,ts,cpp --repo=<lang>:/path/to/a/real/repo
./build/ripwire . --quality-delta=origin/main..HEAD --legend=compact

Not in scope

Changing the steering rule itself (the 10-statement distance, the cursor and scope exclusions), or the tangle score formula.


Comment here with the language you are taking, then open one PR per language with Refs #<this issue>. Every contributor is credited by handle in the CHANGELOG entry and the release notes. Thank you!

Lingua principale
C++
Stelle
2.6k
Fork
182
Merge medio
21h 12m
PR unite (30g)
262

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di redhat-et/ripwire

Tutte le issue di redhat-et/ripwire

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.