DataDog / datadog-static-analyzer

Datadog Static Analyzer
https://docs.datadoghq.com/static_analysis/
Apache License 2.0
100 stars 12 forks source link

[STAL-1960] Introduce patterns for refactored JavaScript modules #382

Closed jasonforal closed 4 months ago

jasonforal commented 4 months ago

What problem are you trying to solve?

To implement tight interop between Rust and JavaScript, both languages need to have the same model of the data. This PR addresses 3 problems that this introduces:

  1. Ensuring that even across future refactors, the Rust implementation and JavaScript implementation are always in sync (i.e. that they serialize/deserialize to the same v8 object shape).
  2. Ensuring high performance serialization/deserialization to/from v8.
  3. Doing all of this without requiring contributors to be experts in v8's lower level abstractions.

What is your solution?

1. Unit test canary: Ensuring parity without codegen is tricky, especially because JavaScript isn't strictly typed. For example, imagine as part of a large refactor, we are adding numerous properties to Fix, one of which is a "category" string field. If we implemented this in Rust, but forgot to add "category" on the JavaScript side, v8 is happy to send a v8::Value (undefined) in response to a lookup of this property category. Depending on how the developer writes their unit tests (and the nature of the business logic), there might be some subtle, uncaught edge-cases.

2. Manually-specified serialization/deserialization: serde_v8 is slow and does not provide APIs to amortize allocations (which we can/should do because we know the shapes of our objects ahead of time). Furthermore, the deno team plans to eventually deprecate this crate.

3. File organization This is still not "solved" in this PR, but the way I am trying to address this is to create consistent, logical structure to the file organization. Conceptually, what this PR proposes is:

Alternatives considered

What the reviewer should know

This is one of a chain of PRs fully implementing the ddsa_lib.

datadog-datadog-prod-us1[bot] commented 4 months ago

Software Composition Analysis

:white_check_mark: No library vulnerabilities found (compared 224f9bf against dc46f50).