From 76867501a790dbd6458b97092f1f34374af291a2 Mon Sep 17 00:00:00 2001 From: Jake Bailey Date: Tue, 18 Oct 2022 12:33:56 -0700 Subject: [PATCH] Create naming_local_changes table in Rust naming table builder Summary: hh_server and hh_single_type_check will read the single value from this table when loading a saved state. It contains the naming table delta from a previously-loaded saved state, as an OCaml-marshaled blob. Since we are building the table from scratch in the naming table builder (and our Rust never attempts to save a naming table with a delta), the delta will always be empty. Create the table and write an empty delta upon creation. The local changes table also contains a BASE_CONTENT_VERSION column. This column needs only be unique, as per this comment from [naming_table.ml](https://www.internalfb.com/code/fbsource/[a9b2544fea81]/fbcode/hphp/hack/src/naming/naming_table.ml?lines=406): ``` (* Ideally, we would have a commit hash, which would result in the same content version given the same version of source files. However, using a unique version every time we save the naming table from scratch is good enough to enable us to check that the local changes diff provided as an argument to load_from_sqlite_with_changes_since_baseline is compatible with the underlying SQLite table. *) ``` Reviewed By: shayne-fletcher Differential Revision: D40479834 fbshipit-source-id: 7f6cac170d4503ae5be3958e261c58e3e393206d --- hphp/hack/src/Cargo.lock | 1 + hphp/hack/src/naming/names_rust/Cargo.toml | 1 + hphp/hack/src/naming/names_rust/naming_sqlite.rs | 32 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/hphp/hack/src/Cargo.lock b/hphp/hack/src/Cargo.lock index 334631c42ab..1739cd15f64 100644 --- a/hphp/hack/src/Cargo.lock +++ b/hphp/hack/src/Cargo.lock @@ -2623,6 +2623,7 @@ dependencies = [ "hh_hash", "oxidized", "oxidized_by_ref", + "rand 0.8.5", "relative_path", "rusqlite", "slog", diff --git a/hphp/hack/src/naming/names_rust/Cargo.toml b/hphp/hack/src/naming/names_rust/Cargo.toml index 83880dc3a06..95cffecedaa 100644 --- a/hphp/hack/src/naming/names_rust/Cargo.toml +++ b/hphp/hack/src/naming/names_rust/Cargo.toml @@ -15,6 +15,7 @@ hh24_types = { path = "../../utils/hh24_types" } hh_hash = { path = "../../utils/hh_hash" } oxidized = { path = "../../oxidized" } oxidized_by_ref = { path = "../../oxidized_by_ref" } +rand = { version = "0.8", features = ["small_rng"] } relative_path = { path = "../../utils/rust/relative_path" } rusqlite = { version = "0.28.0", features = ["backup", "blob", "column_decltype"] } slog = { version = "2.7", features = ["max_level_trace", "nested-values"] } diff --git a/hphp/hack/src/naming/names_rust/naming_sqlite.rs b/hphp/hack/src/naming/names_rust/naming_sqlite.rs index 6448b046ce5..63ce19eca51 100644 --- a/hphp/hack/src/naming/names_rust/naming_sqlite.rs +++ b/hphp/hack/src/naming/names_rust/naming_sqlite.rs @@ -127,6 +127,38 @@ impl Names { params![], )?; + // This table contains a single dummy value and is here only to satisfy + // hh_server and hh_single_type_check. + conn.execute( + " + CREATE TABLE IF NOT EXISTS NAMING_LOCAL_CHANGES( + ID INTEGER PRIMARY KEY, + LOCAL_CHANGES BLOB NOT NULL, + BASE_CONTENT_VERSION TEXT + );", + params![], + )?; + + // The blob here is Relative_path.Map.empty as an OCaml-marshaled blob. + // The base_content_version (computed from the unix timestamp and a + // random ID) needs only be unique. + conn.execute( + " + INSERT OR IGNORE INTO NAMING_LOCAL_CHANGES + VALUES(0,X'8495a6be0000000100000000000000000000000040',?);", + params![format!( + "{}-{}", + std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .expect("SystemTime::now() before UNIX_EPOCH") + .as_secs(), + { + use rand::distributions::DistString; + rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 10) + }, + )], + )?; + Ok(()) } -- 2.11.4.GIT