Fixed a perf regression by removing system calls and improving the reachability graph and the callee lookup#556
Conversation
| (* Elixir: &func/n - ShortLambda wrapping a call to the named function. | ||
| Structure: OtherExpr("ShortLambda", [Params[&1,...]; S(ExprStmt(Call(func, args)))]) | ||
| Create a _tmp node to match what AST_to_IL creates for the anonymous wrapper. *) | ||
| | G.OtherExpr (("ShortLambda", shortlambda_tok), [G.Params _; G.S { G.s = G.ExprStmt (inner_e, _); _ }]) -> |
There was a problem hiding this comment.
In places like AST_to_IL we have a way to specify the language, for example:
G.OtherExpr (("ShortLambda", _), _) when env.lang =*= Lang.Elixir
We also have short lambdas in Clojure, are these covered?
There was a problem hiding this comment.
will write a clojure test
There was a problem hiding this comment.
I think Clojure is not yet supported
| |> List.find_opt (fun edge -> | ||
| let label = G.E.label edge in | ||
| (* Implicit edges have line 0 - match by callee name if call is to same function *) | ||
| Int.equal label.call_site.Pos.line 0) | ||
| |> Option.map G.E.src | ||
| Pos.equal label.call_site call_pos) | ||
| in | ||
| match exact_match with | ||
| | Some edge -> | ||
| Some (G.E.src edge) | ||
| | None -> | ||
| (* Fallback: check for implicit/HOF edges by matching line 0 *) | ||
| incoming_edges | ||
| |> List.find_opt (fun edge -> | ||
| let label = G.E.label edge in | ||
| Int.equal label.call_site.Pos.line 0) | ||
| |> Option.map G.E.src |
There was a problem hiding this comment.
In fact one can do find_opt only once right?
And return a type Explicit _ | Fallback _ or whatever.
Not so important for now.
There was a problem hiding this comment.
yes but then you need to worry about whioch came first I agreee it might be mildly cheaper though I still have to convince myself wether the fallback ever happens
| in | ||
| (* Combine and deduplicate *) | ||
| all_callback_args @ configured_callbacks |> dedup_fn_ids | ||
| (* Combine - dedup would need to handle the tmp_opt too, skip for now *) |
There was a problem hiding this comment.
Why do we skip dedup? Because _tmp are identified?
There was a problem hiding this comment.
bc the dedup is already done by the graph
| let tmp_tok = Tok.fake_tok shortlambda_tok "_tmp" in | ||
| let tmp_name = IL.{ | ||
| ident = ("_tmp", tmp_tok); | ||
| sid = G.SId.unsafe_default; |
There was a problem hiding this comment.
But AST_to_IL.fresh_var has a proper sid:
let i = G.SId.mk () in
which I guess does not matter here?
There was a problem hiding this comment.
yes the sids are irrelevant here
|
Gentle reminder to change PR title to something more informative like: Fix performance regression in intrafile (system calls) |
| let from_sources = reachable_vertices_batch graph sources in | ||
| let from_sinks = reachable_vertices_batch graph sinks in | ||
| (* Fast set intersection *) | ||
| let common = VSet.inter from_sources from_sinks in |
There was a problem hiding this comment.
How about the situation when the input graph is:
src -> foo <- snk
|
v
bar
My understanding is that it will add bar to the relevant graph, although it is not really necessary
There was a problem hiding this comment.
true, this my plan for today, the graph lib has some trick for that, you need to look at SCC's that have no predecesors.
There was a problem hiding this comment.
we agreed we will keep the filtering for now, In principle things like this will be a problem but our HOF technology is not yet sophisticated enough to catch them anyway now:
def f():
return source()
def g(x):
# ruleid: test-tuple-unpacking-taint
sink(x)
return x
def h(x):
return (f(), lambda y: g(y))
def k(x):
a, b = h(x)
z, w = b(a)ed4d71c to
ddf7d35
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [opengrep/opengrep](https://github.com/opengrep/opengrep) | minor | `v1.15.1` → `v1.16.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>opengrep/opengrep (opengrep/opengrep)</summary> ### [`v1.16.0`](https://github.com/opengrep/opengrep/releases/tag/v1.16.0): Opengrep 1.16.0 [Compare Source](opengrep/opengrep@v1.15.1...v1.16.0) #### Improvements - Dart: Add typed metavariabless by [@​maciejpirog](https://github.com/maciejpirog) in [#​551](opengrep/opengrep#551) - Dart: Use case of identifier to guess call vs new by [@​maciejpirog](https://github.com/maciejpirog) in [#​555](opengrep/opengrep#555) - Go: Enable goroutines in taint tracking by [@​maciejpirog](https://github.com/maciejpirog) in [#​559](opengrep/opengrep#559) - Add taint propagation via "for" comprehensions by [@​maciejpirog](https://github.com/maciejpirog) in [#​564](opengrep/opengrep#564) #### Bug Fixes - Rust: Missing Rust type alias translation by [@​smith-xyz](https://github.com/smith-xyz) in [#​549](opengrep/opengrep#549) - Fix: Ensure that linux binaries have 8mb stack size (musl) by [@​dimitris-m](https://github.com/dimitris-m) in [#​563](opengrep/opengrep#563) - Fixed a perf regression by removing system calls and improving the reachability graph and the callee lookup by [@​corneliuhoffman](https://github.com/corneliuhoffman) in [#​556](opengrep/opengrep#556) - Fixed intrafile bug introduced by a superfluous fallback by [@​corneliuhoffman](https://github.com/corneliuhoffman) in [#​567](opengrep/opengrep#567) - Ruby: Always translate `or` and `and` to expression by [@​maciejpirog](https://github.com/maciejpirog) in [#​562](opengrep/opengrep#562) - Bash: Allow redirects before command arguments by [@​maciejpirog](https://github.com/maciejpirog) in [#​548](opengrep/opengrep#548) #### Internal Improvements - Add `show dump-intrafile-graph` and `show dump-taint-signatures` commands by [@​corneliuhoffman](https://github.com/corneliuhoffman) in [#​552](opengrep/opengrep#552) - Improve tainting code by [@​maciejpirog](https://github.com/maciejpirog) in [#​546](opengrep/opengrep#546) - Graph refactoring by [@​corneliuhoffman](https://github.com/corneliuhoffman) in [#​553](opengrep/opengrep#553) #### New Contributors - [@​smith-xyz](https://github.com/smith-xyz) made their first contribution in [#​549](opengrep/opengrep#549) **Full Changelog**: <opengrep/opengrep@v1.15.1...v1.16.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Ni4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTYuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
This PR introduces 4 changes