Compile-time recognition of parametric types e.g. K{T} for any K

Answering my own question:

abstract type AbstractGeneric end
struct MyType <: AbstractGeneric
  x
end
struct MySecondType <: AbstractGeneric
  x
  y
end

function myMethod(x::MyType)
  return 2*x.x
end

function fun(x::AbstractGeneric, z::AbstractArray)
  return sum((myMethod(x) .- z).^2)
end

@code_warntype fun(MyType(3), rand(5))

Gives

@code_warntype fun(MyType(3), rand(5))
Variables
  #self#::Core.Compiler.Const(fun, false)
  x::MyType
  z::Array{Float64,1}

Body::Any
1 ─ %1 = Main.myMethod(x)::Any
│   %2 = Base.broadcasted(Main.:-, %1, z)::Any
│   %3 = Core.apply_type(Base.Val, 2)::Core.Compiler.Const(Val{2}, false)
│   %4 = (%3)()::Core.Compiler.Const(Val{2}(), false)
│   %5 = Base.broadcasted(Base.literal_pow, Main.:^, %2, %4)::Any
│   %6 = Base.materialize(%5)::Any
│   %7 = Main.sum(%6)::Any
└──      return %7

The compiler substitutes for Any.