Skip to content

[FR] user-facing type inference API #54207

Open
@nsajko

Description

Many packages, such as Dictionaries.jl or StaticArrays.jl, seemingly need access to Julia's type inference functionality to be able to offer their users convenient construction of their custom data structures from generators. This is how comprehensions that create Arrays work, after all, so it only seems fair to enable user packages to use type inference, too.

Exposing type inference to users is, however, dangerous; because the type inference works on a best-effort basis, it's not reliably exact, so users must not rely on the exactness of the type inference for correctness of their code and APIs. A peculiar fact is that type inference may give different results for the same queries at different points during the run of Julia. These issues are subtle, and users are overconfident.

Functionality like Core.Compiler.return_type, Base.return_types or Base.@default_eltype is widely used in the ecosystem, even though these are Julia-internal implementation details not subject to any compatibility guarantee.

Could we have a user-facing type inference API, provided it came with enough documentation and warnings to enable it to be used correctly?

Realistically, the type inference functionality is already widely (mis)used, so IMO it's clear that such documentation is necessary. And, once the docs exist, I guess that providing an interface that's actually permitted for use would be a no-brainer?

Metadata

Assignees

No one assigned

    Labels

    compiler:inferenceType inferencedesignDesign of APIs or of the language itselffeatureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions