Repository navigation
ruff_ruby_spo: ordered behavioral ore — a Ruby arm and a Rails arm #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4940c2c
ruff_ruby_spo: ordered behavioral ore — a Ruby arm and a Rails arm
claude 1abdbe5
ruff_ruby_spo: unlink private-item intra-doc links in events
claude beb9c01
ruff_ruby_spo: make the six-set gate literally six sets, and stop los…
claude e6f8e9f
ruff_ruby_spo: fix six real findings from the CodeRabbit + Codex reviews
claude bc8e25a
ruff_ruby_spo: narrow the traversal-receiver suppression to BARE rece…
claude 54c533d
AGENTS.md: document the session traps that cost time in this repo
claude b2a9e98
Fix the prek failure this file's own traps section caused
claude d860a5e
ruff_ruby_spo: document the walker's scope and interning helpers
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //! Census the ordered ore over a real Rails tree, so the arm is measured on | ||
| //! source it was not written against. | ||
| //! | ||
| //! `RAILS_SRC=/path/to/openproject cargo run -p ruff_ruby_spo --example ore_census` | ||
|
|
||
| #![expect( | ||
| clippy::print_stderr, | ||
| reason = "census CLI example (mirrors ruff_cpp_spo::harvest_events)" | ||
| )] | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| use ruff_ruby_spo::events::{EventKind, Symbols, source_ore}; | ||
|
|
||
| fn main() { | ||
| // Required, not defaulted. A machine-specific absolute default meant an | ||
| // unset variable produced a silent all-zero census with no diagnostic — | ||
| // measured once, in this session, and mistaken for a real result. | ||
| let Ok(root) = std::env::var("RAILS_SRC") else { | ||
| eprintln!("RAILS_SRC is unset — point it at a Rails source tree"); | ||
| return; | ||
| }; | ||
| let root = PathBuf::from(root); | ||
| let limit: usize = std::env::var("LIMIT") | ||
| .ok() | ||
| .and_then(|v| v.parse().ok()) | ||
| .unwrap_or(usize::MAX); | ||
|
|
||
| let mut files = Vec::new(); | ||
| for dir in ["app/models", "app/services", "app/contracts"] { | ||
| collect(&root.join(dir), &mut files); | ||
| } | ||
| files.sort(); | ||
| files.truncate(limit); | ||
|
|
||
| let mut syms = Symbols::default(); | ||
| let (mut classes, mut methods, mut events, mut scopes, mut decls) = | ||
| (0u64, 0u64, 0u64, 0u64, 0u64); | ||
| let (mut set_total, mut ev_facts) = (0u64, 0u64); | ||
| let mut with_multi_scope = 0u64; | ||
| let mut cb_with_options = 0u64; | ||
| let mut kinds: std::collections::BTreeMap<&'static str, u64> = | ||
| std::collections::BTreeMap::new(); | ||
|
|
||
| for path in &files { | ||
| let Ok(src) = std::fs::read_to_string(path) else { | ||
| continue; | ||
| }; | ||
| for c in source_ore(&src, "op", &mut syms) { | ||
| classes += 1; | ||
| decls += c.declarations.len() as u64; | ||
| for d in &c.declarations { | ||
| if let ruff_ruby_spo::Declaration::Callback(cb) = &d.decl | ||
| && !cb.options.is_empty() | ||
| { | ||
| cb_with_options += 1; | ||
| } | ||
| } | ||
| for m in &c.methods { | ||
| methods += 1; | ||
| events += m.events.len() as u64; | ||
| scopes += m.scopes.len() as u64; | ||
| if m.scopes.len() > 1 { | ||
| with_multi_scope += 1; | ||
| } | ||
| // All SIX, including `set_guarded`. Summing five made the | ||
| // denominator too small on any corpus containing a | ||
| // blank-guarded default, so the preservation ratio was | ||
| // overstated — while `MethodOre` carried the sixth count all | ||
| // along. | ||
| set_total += u64::from( | ||
| m.set_reads | ||
| + m.set_writes | ||
| + m.set_guarded | ||
| + m.set_raises | ||
| + m.set_calls | ||
| + m.set_traverses, | ||
| ); | ||
| for e in &m.events { | ||
| *kinds.entry(e.kind.as_str()).or_default() += 1; | ||
| if matches!( | ||
| e.kind, | ||
| EventKind::Read | ||
| | EventKind::Write | ||
| | EventKind::ReadWrite | ||
| | EventKind::Raise | ||
| | EventKind::Call | ||
| ) { | ||
| ev_facts += 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| eprintln!("files {}", files.len()); | ||
| eprintln!("classes {classes}"); | ||
| eprintln!("methods {methods}"); | ||
| eprintln!("declarations {decls} (callbacks carrying options: {cb_with_options})"); | ||
| eprintln!("events {events}"); | ||
| eprintln!("scopes {scopes} (methods with >1 scope: {with_multi_scope})"); | ||
| eprintln!("symbols {}", syms.len()); | ||
| eprintln!("--"); | ||
| eprintln!("shipped set entries {set_total}"); | ||
| eprintln!("ordered fact events {ev_facts}"); | ||
| if set_total > 0 { | ||
| // `f64::from(u32)` is lossless; the counts are corpus-sized, so the | ||
| // saturating narrowing is unreachable in practice and never silently | ||
| // rounds the way a bare `u64 as f64` would. | ||
| let num = f64::from(u32::try_from(ev_facts).unwrap_or(u32::MAX)); | ||
| let den = f64::from(u32::try_from(set_total).unwrap_or(u32::MAX)); | ||
| eprintln!("preservation ratio {:.2}x", num / den); | ||
| } | ||
| eprintln!("--\nevent kinds:"); | ||
| for (k, n) in &kinds { | ||
| eprintln!(" {k:<12} {n}"); | ||
| } | ||
| } | ||
|
|
||
| fn collect(dir: &std::path::Path, out: &mut Vec<PathBuf>) { | ||
| let Ok(rd) = std::fs::read_dir(dir) else { | ||
| return; | ||
| }; | ||
| for e in rd.flatten() { | ||
| let p = e.path(); | ||
| if p.is_dir() { | ||
| collect(&p, out); | ||
| } else if p.extension().is_some_and(|x| x == "rb") { | ||
| out.push(p); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.