JuliaVTK / WriteVTK.jl

Julia package for writing VTK XML files
Other
151 stars 32 forks source link

Type instability in `vtk_save`? #116

Closed jlchan closed 1 year ago

jlchan commented 1 year ago

Thanks for maintaining this package!

I ran into a type instability in vtk_save recently when working with an unstructured grid data type. Here is a MWE:

using WriteVTK
cells = [MeshCell(VTKCellTypes.VTK_LAGRANGE_TRIANGLE, [1, 2, 3])]
vtkfile = vtk_grid("test", [-1, -1, 1], [-1, 1, -1], cells)
@code_warntype vtk_save(vtkfile)

The output of @code_warntype is

Screen Shot 2023-02-14 at 3 23 05 PM

Any idea if this can be made type stable?

jipolanco commented 1 year ago

I'm not really sure why assertions sometimes are flagged as non-inferred by @code_warntype, but I believe this is completely harmless and doesn't impact performance. But I can provide a workaround for this if it helps.

In any case, I really think this is not what is causing the type instability that you're seeing in jlchan/StartUpDG.jl#87, since the return type of vtk_save (Vector{String}) is correctly inferred.