Skip to content

trimming: no way to ccall into a dynamically-computed library name #57707

@topolarity

Description

@topolarity

Once #57706 is fixed, there will be no way to compute a library string dynamically for a ccall because

  1. ccall forbids referring to local variables:
julia> foo() = (b = bar(); ccall((:test, b), Cvoid, ()))
ERROR: syntax: ccall function name and library expression cannot reference local variables
  1. inference / optimizer never inlines / resolves the library function for a ccall:
julia> bar() = string(rand(Int))
julia> foo() = ccall((:test, bar()), Cvoid, ())
julia> code_typed(foo, ())
1-element Vector{Any}:
 CodeInfo(
1$(Expr(:foreigncall, :(Core.tuple(:test, Main.bar())), Nothing, svec(), 0, :(:ccall)))::Nothing
└──     return nothing
) => Nothing

Notice that the call to Main.bar() is embedded as a sub-expression in Expr(:foreigncall) and is never explored by inference / optimizer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requeststrimmingIssues with trimming functionality or PR's relevant to its performance/functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions