transpile: Fix translation failures exposed by SQLite - #2001
Open
thedataking wants to merge 5 commits into
Open
Conversation
thedataking
force-pushed
the
perl/sqlite-transpiler-fixes
branch
from
September 8, 2026 02:33
f409fa9 to
c6c1988
Compare
thedataking
marked this pull request as ready for review
September 8, 2026 03:24
Translation units without declarations have no AST nodes to register their main file. Exporting comments then introduces a file ID absent from the file table, causing include-path lookup to panic. Register the main file before serializing the table so comments always refer to an exported file.
…nters Exposed-provenance constructors require Sized pointees, but forward declarations become unsized extern types. Construct a byte pointer first, then cast to the opaque pointer type while preserving its constness. This allows integer sentinel values and runtime addresses to initialize opaque pointers in both supported Rust editions.
… va_arg An enclosing cast can prevent Rust from inferring the destination of the transmute used for nullable function pointers. Pass the converted C type explicitly so va_arg results can be assigned through function pointer typedefs and struct fields.
Rust atomic intrinsics reject Option<fn>, the representation of nullable C function pointers. Convert atomic operands to raw pointers and convert results back to their function pointer type. Apply this to loads, stores, exchanges, and compare-exchanges, including the expected value written back after a failed comparison. Null callbacks retain their null representation.
Default initialization does not handle CTypeKind::Atomic, so local _Atomic declarations fail to translate even when they have an explicit initializer. Delegate to the underlying value type to produce the initializer for the atomic storage.
thedataking
force-pushed
the
perl/sqlite-transpiler-fixes
branch
from
September 8, 2026 03:34
c6c1988 to
2ec4c4d
Compare
ahomescu
reviewed
Sep 8, 2026
| } | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn sentinel() -> *mut Opaque { | ||
| return ::core::ptr::with_exposed_provenance_mut::<u8>(8 as ::core::ffi::c_int as usize) |
Contributor
There was a problem hiding this comment.
If there isn't a matching call to expose_provenance, this is undefined behavior.
| .ast_context | ||
| .is_forward_declared_type(pointee_type_id.ctype); | ||
| let pointee_type_rs = if is_opaque { | ||
| mk().path_ty(vec!["u8"]) |
Contributor
There was a problem hiding this comment.
I'm not sure yet if this should be u8 or c_void.
Contributor
There was a problem hiding this comment.
We use c_void in other places, so yeah we should keep it consistent.
| transmute_expr(mk().infer_ty(), mk().infer_ty(), val) | ||
| VaArgCastKind::Transmute(ty) => { | ||
| // An enclosing cast or field access may prevent | ||
| // inference of the transmute's destination type. |
Contributor
There was a problem hiding this comment.
Could either this comment or the current commit message provide an example of the generated code?
ahomescu
reviewed
Sep 8, 2026
| .transpose()?; | ||
| let weak = weak_id.and_then(|x| self.convert_constant_bool(x)); | ||
|
|
||
| // Rust represents nullable C function pointers as Option<fn>, which |
Contributor
There was a problem hiding this comment.
This only covers the AST atomics, but not any of the __sync_* or __atomic_* builtins. You could refactor this to cover everything.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix five translation failures exposed by SQLite's individual source files:
va_arg. Enclosing casts can prevent Rust from inferring it.Option<fn>representation of nullable C callbacks._Atomicstorage through its underlying value type. Default initialization otherwise fails for local atomic declarations, including explicitly initialized ones.