move melt_ type-checking code to C for a speedup