[Cbor] CDDL modules: sockets and features

Carsten Bormann <cabo@tzi.org> Fri, 10 July 2020 16:27 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 87D143A0C57 for <cbor@ietfa.amsl.com>; Fri, 10 Jul 2020 09:27:05 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.897
X-Spam-Level:
X-Spam-Status: No, score=-1.897 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nslB7ExDhPil for <cbor@ietfa.amsl.com>; Fri, 10 Jul 2020 09:27:03 -0700 (PDT)
Received: from gabriel-vm-2.zfn.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A559F3A0EEF for <cbor@ietf.org>; Fri, 10 Jul 2020 09:27:01 -0700 (PDT)
Received: from [172.16.42.100] (p5089ae91.dip0.t-ipconnect.de [80.137.174.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gabriel-vm-2.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4B3JN42kk1zycY; Fri, 10 Jul 2020 18:27:00 +0200 (CEST)
From: Carsten Bormann <cabo@tzi.org>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Mao-Original-Outgoing-Id: 616091219.5651881-0a528c076f55465db1d837a2efad645c
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
Date: Fri, 10 Jul 2020 18:26:59 +0200
Message-Id: <413FE7A3-F98C-4593-8513-E5E1C7A0FA74@tzi.org>
To: cbor@ietf.org
X-Mailer: Apple Mail (2.3608.80.23.2.2)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/aHxANFr16iPo4NFqta7e_aT6ADE>
Subject: [Cbor] CDDL modules: sockets and features
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 10 Jul 2020 16:27:06 -0000

CDDL provides a convention to indicate extension points by "sockets", Section 3.9 of RFC 8610 [1].  That section provides a few examples how sockets can be used for indicating extensibility for both type choices and group choices.

In practice, a specification will tend to provide the "plugs" (alternatives filled in for a socket) that exist at the time the specification, but of course cannot provide those that will be defined only in the future.

A common idiom to provide unlimited extensibility is to provide the general type of the alternatives expected in the socket as a last item in the choice:

foo = $foo / text
$foo /= "ant"
$foo /= "bat"
$foo /= "cat"

This can be combined with .within to restrict what can go into the socket:

foo = $foo .within text / text
...

(which is a bit non-DRY [2], but usually tolerably so).

The problem with this idiom is that anything validates now; there is no longer any help in identifying typos.  The .feature control operator comes to the rescue:

foo = $foo .within text / text .feature "foo-ext"
...

When the CDDL tool is asked to generate ten examples for this:

/foo/ "cat"
/foo/ "isolationist"
/foo/ "treater"
/foo/ "bat"
/foo/ "ant"
/foo/ "bat"
/foo/ "epigenist"
/foo/ "transpersonal"
/foo/ "recast"
/foo/ "uncompounding"

it tells us:

** Features potentially used: foo-ext: ["isolationist"]
** Features potentially used: foo-ext: ["treater"]
** Features potentially used: foo-ext: ["epigenist"]
** Features potentially used: foo-ext: ["transpersonal"]
** Features potentially used: foo-ext: ["recast"]
** Features potentially used: foo-ext: ["uncompounding"]

So we get warned (the warning is not a validation failure!) that there are six new words in the foo-ext extension point (some of which might be typos) besides the already sanctioned usage of ant, bat, and cat.

<aside>

foo = $foo .within text / text .feature "foo-ext"

is a rather verbose construct with only two actual pieces of information:

-- foo, the name of the choice, which generates $foo and "foo-ext", and
-- text, the type to be satidfied by all the alternatives.

Unfortunately, CDDL's generics are not powerful enough to construct other rule names ($foo) or text strings ("foo-ext") from an argument (foo); C language connoiseurs may remember the hacks that were used initially and then replaced by stringification (# operator) and concatenation/token pasting (## operator) [3] -- CDDL doesn't have those (and is clean enough not to support the earlier hacks).
Also, generics in CDDL defines types or groups, not entire rules.
So we cannot abbreviate

foo = $foo .within text / text .feature "foo-ext"
as
Make-Extension-Point<foo, text>

</aside>

Sockets have been defined already to allow composition, there is relatively little support needed to do that composition beyond single modules (some form of namespacing, I'd think).

A related question is how CDDL specifications might incorporate alternatives that are registered in an IANA registry; this could be modeled as a module import to a module that is generated from the current state of that registry.

Grüße, Carsten

[1]: https://tools.ietf.org/html/rfc8610#section-3.9
[2]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
[3]: https://en.wikipedia.org/wiki/C_preprocessor#Token_stringification