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

u32 has bad diagnostics with #[pg_extern] #1577

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Feb 22, 2024

Check in a test that demonstrates this so that we are aware of improvements, and to prevent any regressions, as they used to be significantly worse.

This is a step towards resolving these issues:

@workingjubilee
Copy link
Member Author

@nyurik This is a bit indirect still, isn't it? The spans are all fucked up.

@nyurik
Copy link
Contributor

nyurik commented Feb 22, 2024

Thx for working on it! But yeah, trait not satisfied error is a bit of a rabbit hole... Perhaps it might be better to handle it explicitly? I am sure there will be plenty of surprises for such a common use case of an incorrect data type - so juts look at the input/return params in the PgExtern::new or nearby, and raise an error?

@workingjubilee
Copy link
Member Author

workingjubilee commented Feb 22, 2024

nondet diagnostic output, adding cshim alters the hash I think

@workingjubilee
Copy link
Member Author

workingjubilee commented Feb 22, 2024

Thx for working on it! But yeah, trait not satisfied error is a bit of a rabbit hole... Perhaps it might be better to handle it explicitly? I am sure there will be plenty of surprises for such a common use case of an incorrect data type - so juts look at the input/return params in the PgExtern::new or nearby, and raise an error?

Well, I'd rather not special-case the strings of any types (at least, any further than our code already does...), because given the sheer amount of FFI pgrx involves, people are very likely to do something like:

#[pg_extern]
fn pg_fn(arg: ffi::c_uint) -> ffi::c_ulong {

@workingjubilee
Copy link
Member Author

This is not to say I'm against adding more diagnostic code here, I'd just rather do so in a more underhanded / generic way, like e.g. emitting structs with the name of the error I would want to emit and embedding the argument and return types in the struct.

@workingjubilee
Copy link
Member Author

Nope, last one didn't fix it. Guess I'm waiting for better test infra or finding a way to emit a better diagnostic or rustc being less random about ordering here.

@nyurik
Copy link
Contributor

nyurik commented Feb 22, 2024

How about just handle the well known simple types, e.g. u16, u32, ...?

@workingjubilee workingjubilee marked this pull request as draft February 22, 2024 02:15
@workingjubilee
Copy link
Member Author

How about just handle the well known simple types, e.g. u16, u32, ...?

It feels like it lacks a satisfactory boundary.

@nyurik
Copy link
Contributor

nyurik commented Feb 22, 2024

Well, it is not perfect, i agree, but if it will make the most common usecase more helpful... at least maybe give a warning?

@workingjubilee
Copy link
Member Author

Well, it is not perfect, i agree,

It isn't about perfection. The problem in this case is that there are three type systems involved (Rust's, C's, and Postgres's), and people are going to have different opinions about what is "obvious" and "common". Without usage statistics (and cargo pgrx doesn't include telemetry), I can't rule anything out.

Check in a test that demonstrates this so that we are aware of improvements,
and to prevent any regressions, as they used to be significantly worse.
@workingjubilee
Copy link
Member Author

I'm going to do some things that will significantly affect the diagnostics and might make them significantly worse or better, so this PR needs to serve its original purpose.

@workingjubilee workingjubilee marked this pull request as ready for review May 8, 2024 05:27
@nyurik
Copy link
Contributor

nyurik commented May 8, 2024

Would the recently released diagnostics support help in this case? https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes

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.

None yet

2 participants