chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH 0/5][5] Generalize port directionality and add


From: Evan Hanson
Subject: [Chicken-hackers] [PATCH 0/5][5] Generalize port directionality and add basic refinement types
Date: Thu, 30 Jun 2016 20:09:44 +1200

Hi hackers,

Here is a quite large patchset that, at its heart, adds support for
multidirectional ports by converting the simple boolean flag indicating
whether a port is for input or output to a bitmap. It also adds
`input-port-open?` and `output-port-open?` procedures for testing
whether a port is open in a specific direction (incidentally, these are
from R7RS), as well as a `make-bidirectional-port` procedure for merging
two points into one. This allows for things like:

  (import (chicken tcp) (chicken ports))
  (define tcp-listener (tcp-listen 8080))
  (define tcp-port
    (call-with-values (cut tcp-accept tcp-listener) make-bidirectional-port))
  (write (read tcp-port) tcp-port)

That's the strictly port-related part. However, in order for ports to
allow input and output simultaneously, the type system also needed to be
extended so that the respective types aren't mutually exclusive.
Previously, "input-port" and "output-port" were totally distinct, and
"port" was an alias for the union thereof. Now, the scrutinizer must
instead allow ports to be open for input, output, or both, with
procedures like `input-port?` still providing type information but not
precluding that `output-port?` might also be true.

To support this, a basic type refinement mechanism has been added.
Specifically, there is now a "(refine (ATTRIBUTE ...) TYPE)" type form
that tags a type with some extra information. For example, the type of
an input port is now "(refine (input) port)" (although the "input-port"
name has been left as an alias), and a bidirectional port is expressed
as "(refine (input output) port)". Refinements are "additive", that is
to say, when a variable's type is narrowed by a predicate or enforcing
procedure, refinements in the old and new types are merged. These types
are currently only used for ports and not meant for use in user-defined
types, but they'll have other applications in the future, for example to
mark strings with certain semantic information.

This is a pretty big change, so I've also added a hefty suite of unit
tests for the scrutinizer. It's not exhaustive, but it's a good start,
and it'll hopefully help to illustrate some of the work in this
changeset.

By the way, the dates on those first two patches are actually correct.
The port direction changes were finished way back in 2014, and I
actually showed the WIP to Felix at the ICC. It then sat for over a year
until I had time to hack the scrutinizer into shape. Oh well.

Cheers,

Evan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]