feat: Reduce binary size with more compact exhaustiveness error reporting (#1112)

This commit is contained in:
jacereda 2021-01-05 07:22:43 +01:00 committed by GitHub
parent eb1e060f54
commit 0c6eae63c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -34,6 +34,12 @@ typedef char CChar;
} while (0)
#endif
#define UNHANDLED(file, line) \
do { \
printf("Unhandled case in 'match' expression at %s:%d\n", file, line); \
abort(); \
} while (0)
// Array
typedef struct {
size_t len;

View File

@ -20,6 +20,7 @@ import Info
import qualified Map
import qualified Meta
import Obj
import Path (takeFileName)
import Project
import Scoring
import qualified Set
@ -445,16 +446,8 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
let Just t = ty
in appendToSrc (addIndent indent ++ tyToCLambdaFix t ++ " " ++ retVar ++ ";\n")
zipWithM_ (emitCase exprVar) (True : repeat False) (pairwise rest)
appendToSrc (addIndent indent ++ "else {\n")
appendToSrc (addIndent indent ++ " // This will not be needed with static exhaustiveness checking in 'match' expressions:\n")
appendToSrc (addIndent indent ++ " fprintf(stderr, \"Unhandled case in 'match' expression at " ++ quoteBackslashes (prettyInfo info) ++ "\\n\");\n")
appendToSrc (addIndent indent ++ " exit(1);\n")
appendToSrc (addIndent indent ++ "}\n")
appendToSrc (addIndent indent ++ "else UNHANDLED(\"" ++ takeFileName (infoFile info) ++ "\", " ++ show (infoLine info) ++ ");\n")
pure retVar
where
quoteBackslashes [] = []
quoteBackslashes ('\\' : r) = "\\\\" ++ quoteBackslashes r
quoteBackslashes (x : r) = x : quoteBackslashes r
XObj (Match _) _ _ : _ ->
error "Fell through match."
-- While