Clang.jl
Clang.jl copied to clipboard
`auto_mutability` doesn't take structs into account
There are a few structs which take a pointer to another struct as one of its fields. For example, in a certain generated code:
mutable struct A
x::Ptr{B}
y::C
end
struct B
x::Ptr{B}
y::D
end
In such cases, wouldn't it make more sense if B was mutable, and for auto_mutability to make B mutable as well?
Could you share the C example code?
typedef struct WGPUChainedStruct {
struct WGPUChainedStruct const * next;
WGPUSType sType;
} WGPUChainedStruct WGPU_STRUCTURE_ATTRIBUTE;
typedef struct WGPUBufferDescriptor {
WGPUChainedStruct const * nextInChain;
WGPU_NULLABLE char const * label;
WGPUBufferUsageFlags usage;
uint64_t size;
WGPUBool mappedAtCreation;
} WGPUBufferDescriptor WGPU_STRUCTURE_ATTRIBUTE;
from https://github.com/webgpu-native/webgpu-headers/blob/d02fec1b96af29695b9f5659a91067a241f40b04/webgpu.h#L746
@Gnimuc I believe we've to edit mutability.jl for StructForwardDecl, TypedefFunction and UnionForwardDecl? Does the current code allow this? (I saw it was just checking the nodes, so, can it work if we just edit https://github.com/JuliaInterop/Clang.jl/blob/master/src/generator/mutability.jl#L38 to include the above types to be checked?)
https://github.com/JuliaInterop/Clang.jl/blob/5a1cc29c154ed925f01e59dfd705cbf8042158e4/src/generator/passes.jl#L770-L791
This is the current rule which is used to workaround the following case:
https://github.com/JuliaInterop/Clang.jl/blob/5a1cc29c154ed925f01e59dfd705cbf8042158e4/gen/generator.toml#L118-L125
You can add more reasonable rules to should_tweak or directly in the pass function.
struct B x::Ptr{B} y::D end
wait. does it only happen to StructMutualRef?
https://github.com/JuliaInterop/Clang.jl/blob/5a1cc29c154ed925f01e59dfd705cbf8042158e4/src/generator/passes.jl#L819
~~What happens if you remove StructMutualRef in this line?~~
This actually do check those StructMutualRef types..
I think we need to add new rules for non-function-proto types.