Skip to content

Better integration of "foreign types"? #36770

Closed
@fingolfin

Description

@fingolfin

Two years ago, our PR was accepted which among other things added jl_new_foreign_type to the Julia kernel. We've been relying on that work since then in GAP.jl.

However, it has one annoying limitation: these foreign types are not visible to precompilation. We worked around this by adding an abstract supertype GapObj. Instead of the actual foreign type, we then use GapObj throughout our Julia code. That was fine until we started to write higher level Julia types which contain GapObj members: As we discovered, by having x::GapObj instead of x::ActualConcreteType, various optimization are disabled. I am now looking into working around this by parametrizing all our structs (not sure whether that will work out). But I've also wondered if it might be possible to enhance precompilation to deal with our foreign type. Thinking extremely naively, perhaps one could add a syntax extension foreign type MyForeignType end or some other means (say, some special macro/function call/whatever) to inform the precompiler about the foreign type? It could then parse code referencing this, and would trust that the __init__ section of the package in which it occurs will actually provide such an external type. However, I don't even know whether that is enough information about the type for the precompiler, perhaps it needs much more; perhaps some of it could be added, perhaps others make the whole idea impossible. I clearly don't know enough about how precompilation works. Before I try to dig deeper and find out, I thought I could ask the experts whether this sounds even remotely realistic to achieve? Or perhaps I am overlooking a much simpler solution?

UPDATE 17. June 2022: Just to say, things have evolved quite a bit since I opened this issue. In particular, the foreign type is now initialized in GAP_jll, and this seems enough to enable precompilation in GAP.jl, which uses GAP_jll. So all is good from that point of view. It would still be nice to be able to implement more, e.g. having some kind of interface to enable handling (de)serialization of instances of this type. I realize it'll be up to us to provide one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsffiforeign function interfaces, ccall, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions