tree match memoization, promote library checks to main build