Move SSD import count checks to typed Kotlin

ober

ac326364a70be2584a0e3672a976b9560f6b7f83

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index b8671fc..0ac81a2 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1579,7 +1579,8 @@
                 destinationNewFileDelta
                 storageStatsExceedsQuota storageCapacityWithinQuota
                 byteCountWithinLimit storageEntryBytesAllowed
-                positiveCount learnedExamplesShouldRebuild
+                positiveCount learnedExamplesFull
+                learnedExamplesShouldRebuild treeDepthExceeded
                 zipEntryCountExceeded zipExpandedBytesExceeded
                 zipCompressionRatioExceeded zipExportQuotaExceeded
                 treeExportQuotaExceeded
@@ -1683,9 +1684,13 @@
           (byteCountWithinLimit bytes maxBytes))
         (def (positiveCount (count : Int32)) : Bool
           (> count (int32 0)))
+        (def (learnedExamplesFull (count : Int32) (maxExamples : Int32)) : Bool
+          (>= count maxExamples))
         (def (learnedExamplesShouldRebuild (imported : Int32)
                                            (learnedFile : File)) : Bool
           (or (positiveCount imported) (not (fileExists learnedFile))))
+        (def (treeDepthExceeded (depth : Int32) (maxDepth : Int32)) : Bool
+          (> depth maxDepth))
         (def (zipEntryCountExceeded (entries : Int32) (maxEntries : Int32)) : Bool
           (> entries maxEntries))
         (def (zipExpandedBytesExceeded (entryBytes : Int)
@@ -8338,7 +8343,7 @@
        "                return remoteTruthPayloadCount(payload)"
        "            }"
        "            val entries = remoteTruthPayloadTruths(payload)"
-       "            if (remoteTruthEntriesCount(entries) > MAX_ZIP_ENTRIES) throw IllegalStateException(\"Too many remote truth entries\")"
+       "            if (zipEntryCountExceeded(remoteTruthEntriesCount(entries), MAX_ZIP_ENTRIES)) throw IllegalStateException(\"Too many remote truth entries\")"
        "            var imported = 0"
        "            for (i in 0 until remoteTruthEntriesCount(entries)) {"
        "                val entry = remoteTruthEntryAt(entries, i)"
@@ -8610,7 +8615,7 @@
        "                continue"
        "            }"
        "            appendLearnedExamplesFromTruth(examples, MAX_LEARNED_EXAMPLES, file.name, truth)"
-       "            if (learnedExamplesCount(examples) >= MAX_LEARNED_EXAMPLES) break@fileLoop"
+       "            if (learnedExamplesFull(learnedExamplesCount(examples), MAX_LEARNED_EXAMPLES)) break@fileLoop"
        "        }"
        "        val learned = learnedExamplesDocument(examples, MAX_LEARNED_EXAMPLES)"
        "        atomicWriteText(containedLeaf(learnedDir, learnedExamplesFileName()), learned.toString(2))"
@@ -8663,7 +8668,7 @@
        "        depth: Int,"
        "        budget: ImportBudget"
        "    ): Int {"
-       "        if (depth > MAX_ZIP_DEPTH) throw IllegalStateException(\"Import tree exceeds depth limit\")"
+       "        if (treeDepthExceeded(depth, MAX_ZIP_DEPTH)) throw IllegalStateException(\"Import tree exceeds depth limit\")"
        "        localDir.mkdirs()"
        "        var count = 0"
        "        sourceDir.listFiles().forEach { child ->"