model,Psiandxmay not be constant
Minimal example reproducing OP’s problem:
julia> struct Model
x::Float64
end
julia> (m::Model)(y) = m.x * y
julia> model = Model(3.5) # model is a non-constant global
Model(3.5)
julia> @code_warntype model(2)
Variables
m::Model
y::Int64
Body::Float64
1 ─ %1 = Base.getproperty(m, :x)::Float64
│ %2 = (%1 * y)::Float64
└── return %2
julia> modelcall() = model(2) # using non-constant global "model" within a function definition
modelcall (generic function with 1 method)
julia> @code_warntype modelcall()
Variables
#self#::Core.Const(modelcall)
Body::Any
1 ─ %1 = Main.model(2)::Any
└── return %1