From 4fa87bd57d5e673e280c987a75cd8129ff349f43 Mon Sep 17 00:00:00 2001
From: Jubilee <46493976+workingjubilee@users.noreply.github.com>
Date: Wed, 17 Jan 2024 14:12:15 -0800
Subject: [PATCH] Unbox types properly from arrays (#1476)
Introducing `Datum<'src>` allows using it with HRTB fns in schema
generation to persist lifetimes all the way through `#[pg_extern]`'s
wrapper-fn infrastructure without compromising the integrity of lifetime
annotations. This is immediately implemented to prevent many types from
exceeding the lifetime of the Array they are unboxed from, unless they
are already "self-owned" and thus 'static.
Unfortunately, this does not fix all instances using `pg_getarg`, and
those simply are left unsolved for now in some cases. I reorganized the
UI tests to make it easier to notice these problems and when they get
solved.
---
pgrx-examples/bad_ideas/src/lib.rs | 2 +-
pgrx-macros/src/lib.rs | 16 +
pgrx-macros/src/rewriter.rs | 2 +-
pgrx-sql-entity-graph/src/lifetimes.rs | 70 --
.../src/metadata/function_metadata.rs | 54 +-
pgrx-sql-entity-graph/src/pg_extern/mod.rs | 27 +-
.../src/postgres_type/mod.rs | 47 +-
pgrx-sql-entity-graph/src/used_type.rs | 91 +--
pgrx-tests/src/tests/array_tests.rs | 53 +-
pgrx-tests/src/tests/heap_tuple.rs | 686 +++++++++---------
pgrx-tests/src/tests/roundtrip_tests.rs | 92 ++-
pgrx-tests/src/tests/variadic_tests.rs | 5 +-
.../tests/compile-fail/arrays-dont-leak.rs | 39 +
.../compile-fail/arrays-dont-leak.stderr | 108 +++
.../eq-for-postgres_hash.rs} | 0
.../eq-for-postgres_hash.stderr} | 4 +-
.../escaping-spiclient-1209-cursor.rs | 0
.../escaping-spiclient-1209-cursor.stderr | 8 +-
.../escaping-spiclient-1209-prep-stmt.rs | 0
.../escaping-spiclient-1209-prep-stmt.stderr | 2 +-
.../compile-fail/heap-tuples-dont-leak.rs | 29 +
.../compile-fail/heap-tuples-dont-leak.stderr | 26 +
.../total-eq-for-postgres_eq.rs} | 0
.../total-eq-for-postgres_eq.stderr} | 2 +-
.../total-ord-for-postgres_ord.rs} | 0
.../total-ord-for-postgres_ord.stderr} | 2 +-
pgrx-tests/tests/todo/array-serialize-json.rs | 32 +
.../tests/todo/array-serialize-json.stderr | 22 +
.../tests/todo/busted-exotic-signature.rs | 38 +
.../tests/todo/busted-exotic-signature.stderr | 15 +
.../todo/composite-types-broken-on-spi.rs | 252 +++++++
.../todo/composite-types-broken-on-spi.stderr | 71 ++
pgrx-tests/tests/todo/for-dog-in-dogs.rs | 109 +++
pgrx-tests/tests/todo/for-dog-in-dogs.stderr | 47 ++
.../tests/todo/random-vec-strs-arent-okay.rs | 28 +
.../todo/random-vec-strs-arent-okay.stderr | 15 +
pgrx-tests/tests/todo/roundtrip-tests.rs | 86 +++
pgrx-tests/tests/todo/roundtrip-tests.stderr | 161 ++++
...-option-composite_type-nesting-problems.rs | 102 +++
...ion-composite_type-nesting-problems.stderr | 47 ++
pgrx-tests/tests/ui.rs | 12 +-
pgrx/src/datum/array.rs | 178 +++--
pgrx/src/datum/mod.rs | 185 +++--
pgrx/src/datum/unbox.rs | 345 +++++++++
pgrx/src/fcinfo.rs | 1 +
pgrx/src/heap_tuple.rs | 66 +-
pgrx/src/pgbox.rs | 2 +-
pgrx/src/spi.rs | 8 +-
48 files changed, 2427 insertions(+), 760 deletions(-)
create mode 100644 pgrx-tests/tests/compile-fail/arrays-dont-leak.rs
create mode 100644 pgrx-tests/tests/compile-fail/arrays-dont-leak.stderr
rename pgrx-tests/tests/{ui/eq_for_postgres_hash.rs => compile-fail/eq-for-postgres_hash.rs} (100%)
rename pgrx-tests/tests/{ui/eq_for_postgres_hash.stderr => compile-fail/eq-for-postgres_hash.stderr} (91%)
rename pgrx-tests/tests/{ui => compile-fail}/escaping-spiclient-1209-cursor.rs (100%)
rename pgrx-tests/tests/{ui => compile-fail}/escaping-spiclient-1209-cursor.stderr (88%)
rename pgrx-tests/tests/{ui => compile-fail}/escaping-spiclient-1209-prep-stmt.rs (100%)
rename pgrx-tests/tests/{ui => compile-fail}/escaping-spiclient-1209-prep-stmt.stderr (87%)
create mode 100644 pgrx-tests/tests/compile-fail/heap-tuples-dont-leak.rs
create mode 100644 pgrx-tests/tests/compile-fail/heap-tuples-dont-leak.stderr
rename pgrx-tests/tests/{ui/total_eq_for_postgres_eq.rs => compile-fail/total-eq-for-postgres_eq.rs} (100%)
rename pgrx-tests/tests/{ui/total_eq_for_postgres_eq.stderr => compile-fail/total-eq-for-postgres_eq.stderr} (90%)
rename pgrx-tests/tests/{ui/total_ord_for_postgres_ord.rs => compile-fail/total-ord-for-postgres_ord.rs} (100%)
rename pgrx-tests/tests/{ui/total_ord_for_postgres_ord.stderr => compile-fail/total-ord-for-postgres_ord.stderr} (90%)
create mode 100644 pgrx-tests/tests/todo/array-serialize-json.rs
create mode 100644 pgrx-tests/tests/todo/array-serialize-json.stderr
create mode 100644 pgrx-tests/tests/todo/busted-exotic-signature.rs
create mode 100644 pgrx-tests/tests/todo/busted-exotic-signature.stderr
create mode 100644 pgrx-tests/tests/todo/composite-types-broken-on-spi.rs
create mode 100644 pgrx-tests/tests/todo/composite-types-broken-on-spi.stderr
create mode 100644 pgrx-tests/tests/todo/for-dog-in-dogs.rs
create mode 100644 pgrx-tests/tests/todo/for-dog-in-dogs.stderr
create mode 100644 pgrx-tests/tests/todo/random-vec-strs-arent-okay.rs
create mode 100644 pgrx-tests/tests/todo/random-vec-strs-arent-okay.stderr
create mode 100644 pgrx-tests/tests/todo/roundtrip-tests.rs
create mode 100644 pgrx-tests/tests/todo/roundtrip-tests.stderr
create mode 100644 pgrx-tests/tests/todo/vec-option-composite_type-nesting-problems.rs
create mode 100644 pgrx-tests/tests/todo/vec-option-composite_type-nesting-problems.stderr
create mode 100644 pgrx/src/datum/unbox.rs
diff --git a/pgrx-examples/bad_ideas/src/lib.rs b/pgrx-examples/bad_ideas/src/lib.rs
index 976083510..3394fe823 100644
--- a/pgrx-examples/bad_ideas/src/lib.rs
+++ b/pgrx-examples/bad_ideas/src/lib.rs
@@ -55,7 +55,7 @@ fn warning(s: &str) -> bool {
#[pg_extern]
fn exec<'a>(
command: &'a str,
- args: default!(Vec