Skip to content

Commit

Permalink
Update pgrx to 0.12.0-alpha.0 (#1497)
Browse files Browse the repository at this point in the history
Hello and welcome to The Beginning of The End!

You may have seen some largely-inscrutable rambling about "object
lifetimes" and "memory contexts" from me in various comments, logs, and
issues. You may have also heard that this has effectively stalled all
forward feature work. You may have noticed this has been the case for
months now.

The long and short of it is that pgrx never actually fully built-in the
actual lifetimes of objects in Postgres into its various types. As more
and more interlocking parts grew, between things like the type unboxing
in `trait FromDatum`, or the bounded memory context of `Spi::connect`,
eventually many supposedly-safe interfaces arose which proved wildly
unsafe in reality due to this mesh of interactions. Internal portions of
pgrx relied on expeditious hacks to ignore the growing problems, until
this rotten foundation yielded an enormous crop of soundness issues over
the year of 2023. Even when not exploitable, they prevent
otherwise-trivial enhancements in terms of speed or memory usage.

Key elements of a new foundation have landed in pgrx, which allow
ascribing lifetimes to every datum and every memory context that a
Postgres extension will encounter. There is much more work to be done to
actually make it so all Rust code has to flow through these new
interfaces. This alpha release is an extremely "preview" release to
allow assessing some of the damage from the first set of breaking
changes, so that some initial feedback and triage can occur. There will,
unfortunately, be more breaking changes on the horizon.

## Many Macros Expand Subtly Differently

If your extension now breaks in some inscrutable way that you cannot
otherwise discern, the problem is probably hidden in macro expansion.
This cannot really be diagnosed except using `cargo expand` diffed
against previous expansions. A most likely issue is that something that
previously hid a lifetime during expansion or writes it as 'static now
propagates it by name or as the anonymous '_ lifetime.

## `Datum<'src>`

There are now lifetime-bound Datums. Expect to see them in more places.

## `UnboxDatum<As<'src> = Type<'src>>`

Expect to see this or a similar signature a lot: there are new
conversion traits which use a generic associated type or similar sneaky
tactics to allow "clamping down" the lifetime to a bound, unless the
produced type is always 'static by being a simple value like `i32`.

## `&'mcx MemCx<'_>`

You will see more and more references to this type, which is a memory
context that encodes an inner invariant lifetime, in signatures. If one
of these is currently in-scope, then please remember it is always
`unsafe` to manipulate the `static mut CurrentMemoryContext` in
Postgres, but it is doubly so then. In general, when designing your own
types using pgrx, you should prefer designing code that uses a signature
like that of `MemoryContextAlloc` instead of `palloc` if you are at all
uncertain.
  • Loading branch information
workingjubilee authored Jan 25, 2024
1 parent ea78a5b commit 9429f99
Show file tree
Hide file tree
Showing 21 changed files with 2,682 additions and 546 deletions.
281 changes: 131 additions & 150 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cargo-pgrx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[package]
name = "cargo-pgrx"
version = "0.11.2"
version = "0.12.0-alpha.0"
authors = ["PgCentral Foundation, Inc. <[email protected]>"]
license = "MIT"
description = "Cargo subcommand for 'pgrx' to make Postgres extension development easy"
Expand All @@ -31,8 +31,8 @@ clap-cargo = { version = "0.11.0", features = [ "cargo_metadata" ] }
semver = "1.0.20"
owo-colors = { version = "3.5" }
env_proxy = "0.4.1"
pgrx-pg-config = { path = "../pgrx-pg-config", version = "=0.11.2" }
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph", version = "=0.11.2" }
pgrx-pg-config = { path = "../pgrx-pg-config", version = "=0.12.0-alpha.0" }
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph", version = "=0.12.0-alpha.0" }
prettyplease = "0.2.15"
proc-macro2 = { version = "1.0.69", features = [ "span-locations" ] }
quote = "1.0.33"
Expand Down
4 changes: 2 additions & 2 deletions cargo-pgrx/src/templates/cargo_toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
pgrx = "=0.11.2"
pgrx = "=0.12.0-alpha.0"

[dev-dependencies]
pgrx-tests = "=0.11.2"
pgrx-tests = "=0.12.0-alpha.0"

[profile.dev]
panic = "unwind"
Expand Down
4 changes: 2 additions & 2 deletions nix/templates/default/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
pgrx = "=0.11.2"
pgrx = "=0.12.0-alpha.0"

[dev-dependencies]
pgrx-tests = "=0.11.2"
pgrx-tests = "=0.12.0-alpha.0"
tempfile = "3.2.0"
once_cell = "1.7.2"

Expand Down
4 changes: 2 additions & 2 deletions pgrx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[package]
name = "pgrx-macros"
version = "0.11.2"
version = "0.12.0-alpha.0"
authors = ["PgCentral Foundation, Inc. <[email protected]>"]
license = "MIT"
description = "Proc Macros for 'pgrx'"
Expand All @@ -31,7 +31,7 @@ rustc-args = ["--cfg", "docsrs"]
no-schema-generation = ["pgrx-sql-entity-graph/no-schema-generation"]

[dependencies]
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph", version = "=0.11.2" }
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph", version = "=0.12.0-alpha.0" }
proc-macro2 = "1.0.69"
quote = "1.0.33"
syn = { version = "1.0.109", features = [ "extra-traits", "full", "fold", "parsing" ] }
Expand Down
2 changes: 1 addition & 1 deletion pgrx-pg-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[package]
name = "pgrx-pg-config"
version = "0.11.2"
version = "0.12.0-alpha.0"
authors = ["PgCentral Foundation, Inc. <[email protected]>"]
license = "MIT"
description = "A Postgres pg_config wrapper for 'pgrx'"
Expand Down
8 changes: 4 additions & 4 deletions pgrx-pg-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[package]
name = "pgrx-pg-sys"
version = "0.11.2"
version = "0.12.0-alpha.0"
authors = ["PgCentral Foundation, Inc. <[email protected]>"]
license = "MIT"
description = "Generated Rust bindings for Postgres internals, for use with 'pgrx'"
Expand Down Expand Up @@ -39,8 +39,8 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
memoffset = "0.9.0"
pgrx-macros = { path = "../pgrx-macros/", version = "=0.11.2" }
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph/", version = "=0.11.2" }
pgrx-macros = { path = "../pgrx-macros/", version = "=0.12.0-alpha.0" }
pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph/", version = "=0.12.0-alpha.0" }
serde = { version = "1.0", features = [ "derive" ] } # impls on pub types
# polyfill until #![feature(strict_provenance)] stabilizes
sptr = "0.3"
Expand All @@ -49,7 +49,7 @@ libc = "0.2"
[build-dependencies]
bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
clang-sys = { version = "1", features = ["clang_6_0", "runtime"] }
pgrx-pg-config= { path = "../pgrx-pg-config/", version = "=0.11.2" }
pgrx-pg-config= { path = "../pgrx-pg-config/", version = "=0.12.0-alpha.0" }
proc-macro2 = "1.0.69"
quote = "1.0.33"
syn = { version = "1.0.109", features = [ "extra-traits", "full", "fold", "parsing" ] }
Expand Down
Loading

0 comments on commit 9429f99

Please sign in to comment.