From 54b59f500d4b45a3879b2a7bfc489fb53ba2b3c3 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 7 Mar 2021 08:44:49 +0100 Subject: spec: compile-shape: Prefer primitive type checkers for members. * language/aws/spec.scm (compile-shape): Only check for the AWS shape type if the member value is a complex type and not merely a wrapper around a primitive type. --- language/aws/spec.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/language/aws/spec.scm b/language/aws/spec.scm index a4c56ee..c40367b 100644 --- a/language/aws/spec.scm +++ b/language/aws/spec.scm @@ -148,10 +148,19 @@ if this is not a primitive data type." ;; Type checks ,@(map (match-lambda ((name . spec) - (let ((key-name (string->symbol name))) + (let* ((key-name (string->symbol name)) + (target-shape (string->symbol (assoc-ref spec "shape"))) + (target-spec (assoc-ref %shape-specs target-shape))) `(unless (eq? ,key-name '__unspecified__) - (ensure ,key-name - ',(string->symbol (assoc-ref spec "shape"))))))) + ,(if (and=> target-spec primitive?) + ;; Apply the primitive type + ;; check directly. This allows + ;; us to avoid unnecessary + ;; wrapping. + `(,(primitive-type-checker target-spec) ,key-name) + ;; Otherwise make sure the value has the correct type + `(ensure ,key-name + ',(string->symbol (assoc-ref spec "shape")))))))) members) (aws-structure ',scm-name -- cgit v1.2.3