Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added oids_of! macro #1879

Merged
merged 4 commits into from
Nov 25, 2024

Conversation

YohDeadfall
Copy link
Contributor

That's an improvement for SPI making it less cumbersome. Just to feel the difference look at the tests. Who would really want to write something like PgBuiltInOids::INT4OID.oid() instead of just telling a Rust type?

I will change the behavior of this macro a bit when you will be ready for shipping 0.13, so it won't produce any vector but a slice.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has the right semantics right now. It's not clear to me that oids_of!() should be an InvalidOid, instead of, say, a compile-time error. Or an empty array.

@workingjubilee
Copy link
Member

I think we should ship a non-plural oid_of! (I'd prefer an fn if we can swing it, tbh, but I'll settle) first and tinker with it a bit before jumping to generating arrays.

@YohDeadfall
Copy link
Contributor Author

If something isn't an IntoDatum then a compiler error will appear, so the value of each element purely depends on the implementation of each type used there. InvalidOid is just to make an empty version of oids_of! to be strongly typed and not to depend on the context.

Let's say, I don't want oids_of! to give you an empty array of integers like in the following case:

let _: &[i32] = oids_of![];

That's why there's [$crate::pg_sys::PgOid::Invalid; 0].

@YohDeadfall
Copy link
Contributor Author

I think we should ship a non-plural oid_of!

You have it already, IntoDatum::type_oid(), and it's a function. I thought about making a non-plural version of the macro, but I see no real use case for it.

@workingjubilee
Copy link
Member

tbh, that's kind of the problem.

A macro creates a false impression this will resolve statically.

That fn produces runtime lookups.

@YohDeadfall
Copy link
Contributor Author

It depends, actually. For built-in types, it's static, but for custom types it isn't.

@workingjubilee
Copy link
Member

I realize that for the existing inputs, it's somewhat incoherent to use. But the reason to make it a zero-sized array, effectively, is to make a macro-call to it... possibly itself from a macro-expansion... valid anywhere we ask for &[pg_sys::Oid], without having to reason about the exact input. For a given input, sure, they might need to do something like

let oids = oids_of![$($types,)];
oids.is_empty().then_some(&oids)

but this enables that.

Basically, we shouldn't overfit it to the existing use-cases.

@YohDeadfall
Copy link
Contributor Author

Sorry, not following. Could you reword it a bit so I can get what I should do?

@workingjubilee
Copy link
Member

I would still prefer zero arguments to evaluate to a zero-sized slice, or to compile_error

@YohDeadfall
Copy link
Contributor Author

Isn't [$crate::pg_sys::PgOid::Invalid; 0] a zero sized array?

@workingjubilee
Copy link
Member

...hm.

I somehow managed to misread this code repeatedly, I suppose.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I managed to not give this proper attention the past times I glanced at it. Some nits and a rebase should make this good.

pgrx/src/datum/mod.rs Outdated Show resolved Hide resolved
pgrx/src/datum/mod.rs Show resolved Hide resolved
pgrx/src/datum/mod.rs Show resolved Hide resolved
pgrx/src/datum/mod.rs Show resolved Hide resolved
@workingjubilee workingjubilee merged commit eda7549 into pgcentralfoundation:develop Nov 25, 2024
14 checks passed
@YohDeadfall YohDeadfall deleted the oids-of-macro branch November 26, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants