Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5844

Add the Object type to the Puppet Type system

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.5.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      2
    • Sprint:
      Language 2016-02-24, Language 2016-03-09, Language 2016-03-23, Language 2016-04-06, Language 2016-04-20
    • Release Notes:
      New Feature
    • Release Notes Summary:
      In preparation for future features in puppet, the abstract type {{Object}} has bee added to the type system.

      Description

      In the Puppet Core Type Model (PCore) that will be used to describe all serialization using the Puppet Type System it is essential to have an Object[T] type that matches instances of user defined type T. We also need the run time abstract Object from which the concrete instances of user defined data types are derived.

      This work is also required to enable the full user defined type definition using the syntax:

      type TypeName inherits SuperTypeName {
        # attribute definitions 
      }
      

      Which will be added in a separate ticket.

      Update


      We have decided (after many rounds of proposals) to use the following syntax for the Object type:

       type T = Object[{
       parent => < parent-type >,
        attributes => { <attributes-hash> }.
        functions => { <functions-hash> },
        equality => [ <equality-array> ],
        equality_includes_type => Boolean,
      }]
      

      Those are the basic features that the Object will have. Additional features can be expected later (separate tickets) to handle invariants.

      ATTRIBUTES

      The attributes feature is a map from name to Type for attributes that do not require a default value, or other special settings. For attributes where more than a type is required a hash is used.

      attributes => {
        name1 => Type,
        name2 => { 
         type     => Type,  # the type of the value
         kind     => Enum[given, derived, given_or_derived, constant],
         value => 'default value literal',
         final => Boolean,
         override => Boolean,
        }
      }
      

      The above example shows one short form, and one long form attribute. Expect there to be additional properties that can be set on an attribute.

      FUNCTIONS

      The function feature has fewer properties. Basically this is a name to type map.

      functions {
        name1 => Callable[ ... ],
        name2 => Callable[ ... ],
      }
      

      If a long form is needed it is defined the same way as for attributes.

      EQUALITY

      Equality can be specified by giving a list of attributes that must be equal for two instances of the object to be considered equal. If not given. Equality s base on all regular fields (i.e. excluding derived/computed and constant value attributes).

      equality => | 'a', 'b', 'c' ]
      

      IMPLEMENTATION

      Object type's not bound to an implementation can be used (a dynamic/generic implementation), but the operations are then not available. For operations to be available there must be a binding between an implementation type, and the Object type. Such a binding can be achieved in different ways.

      • via a special type alias that binds the object type to a Runtime type
      • via syntax to be added in a separate ticket that makes it possible to implement an object type in puppet.

      type T = Object[{ ... } ]  # defines the Object type (the interface)
      type T = Runtime['ruby'', SomeModule::Somewhere::MyImplOfT ]
      

      The example shows a definition of the object and a binding to a runtime implementation. This will follow in subsequent tickets.

      ACCEPTANCE CRITERIA


      There is not that much that can be directly used from Puppet when this ticket is finished. it will be useful when support for the 'new' function has been added, and that the type algebra is implemented (matching on type etc).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                qa qa
                Reporter:
                henrik.lindberg Henrik Lindberg
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support