Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Daffodil has a module called daffodil-runtime1. The suffix "1" was intentional to suggest that there would be other kinds of runtimes in the future.

...

Runtime 2 is, initially, a very minimalist system, which handles only a tiny subset of DFDL, but which generates Java source code for separate compilation and use. The subset of DFDL can increase in size over time, but initially it is intended to be the smallest possible subset that will illustrate how an alternative runtime can/should be constructed.

Daffodil Primary Data Structures

DSOM - Daffodil Schema Object Model

Daffodil contains a DFDL schema compiler, primarily implemented in the daffodil-core module, and a runtime (currently as of 2019-09-25, daffodil-runtime1).

...

Nothing computed on the DSOM tree should be in any way specific to any runtime system with the exception of the runtimeData methods (runtimeData, termRuntimeData, modelGroupRuntimeData, ElementRuntimeData, etc.). These methods return RuntimeData objects, which are defined in daffodil-runtime1.

Gram or Grammar Objects

The DFDL specification contains something called the "Data Syntax Grammar". The notion is that data describable by DFDL must be something the data syntax grammar can describe.

...

The leaves or terminals of the grammar are implementations of the Terminal class. These are generally called the grammar primitives, and those are where the back-end independent code meets the back-end specific code.

RuntimeGenerator Objects

Ultimately, the Gram objects construct a RuntimeGenerator object. The RuntimeGenerator object is specific to each separate runtime implementation strategy. For the daffodil-runtime1, the RuntimeGenerator object has parser() and unparser() methods which generate runtime1 parser and unparser objects, parameterizing them with information from the schema that controls behavior. The parser and unparser methods recursively construct these runtime1-specific Parser and Unparser class instances.


The RuntimeGenerator trait is new. The daffodil-runtime1 is actually implemented directly by the Gram objects. These can/should be refactored onto a runtime1 RuntimeGenerator class so as to provide a uniform API for developement of runtime2 and other runtimes. The creation of runtime2 is largely about refactoring members and methods on the Gram objects into:

  • general purpose shared members usable by multiple runtimes

  • runtime1-specific members (e.g., parser() and unparser())

DPath - DFDL Path Language

Expression - the DPath Abstract Syntax Tree

Daffodil’s schema compiler (in daffodil-core) also compiles DFDL’s expression language, which we call DPath (for DFDL Path), which is closely related to the standard XPath 2.0 language. We refer to the part of Daffodil’s schema compiler that compiles DPath expressions as the DPath compiler.

...

Ultimately, the DPath compiler produces a CompiledExpression object which is implemented either as a ConstantExpression (when constant folding worked), or a RuntimeExpressionDPath object which contains the CompiledDPath.


Introducing additional runtimes beyond runtime1 requires introducing a new class ExpressionRuntimeGenerator. The compile() method of DFDLPathExpressionParser currently returns a CompiledExpression which is a daffodil-runtime1 object. We need the compile() method to instead return an ExpressionRuntimeGenerator which subsequently can be called for the runtime1 case to produce a CompiledExpression object.

The RecipeOp classes currently have a run() method. This must be refactored so that the run() method becomes part of a Runtime 1 data structure, and alternate runtime scan have their own realizations. Effectively each RecipeOp becomes a generator of a "real" runtime1 RecipeOp, or of that of some other runtime.

It is TBD whether this is too late, i.e., whether the DPathExpressionParser’s compile method contains runtime1-specific assumptions.

Runtime 2 Simplifying Assumptions

DFDL allows conforming subsets of features. Runtime 2 will be, roughly, the smallest possible conforming subset. ;

Feature

Detection

Implemented In Runtime 2 ?

Validation

External switch

No

Named Formats

dfdl:defineFormat or dfdl:ref

Yes

Choices

xs:choice in xsd

Not initially. Will be added with restrictions.

  • choiceDispatchKey only,  no backtracking choices
  • Depends on Expressions

Arrays where size not known in advance

dfdl:occursCountKind 'implicit', 'parsed', 'stopValue'

Not initially. Will be added with restrictions.

  • occursCountKind='expression' only. No backtracking.
  • Depends on Expressions

Expressions

Use of a DFDL expression in any property value

Not initially. Will be added with restrictions.
  • No runtime-valued properties except for dfdl:length and dfdl:occursCount

  • Note that if length and occursCount work, then implementing other runtime-valued properties may not be hard.

End of parent

dfdl:lengthKind "endOfParent"

No

Simple type restrictions

xs:simpleType in xsd

Yes. (Requires no work for a runtime backend, so why not.)

Text representation for types other than String

dfdl:representation "text" for Number, Calendar or Boolean types

No.

Delimiters

dfdl:separator <> "" or dfdl:initiator <> "" or dfdl:terminator <> "" or dfdl:lengthKind "delimited"

No.

  • TBD: might have to soften this and allow terminators on simple type string only. Restricting the delimiter to 1 character only may be ok. This allows implementing e.g., null-terminated strings.

Nils

XSDL nillable 'true' in xsd

No.

Defaults

XSDL default or fixed in xsd

No.

Bi-Directional text.

dfdl:textBiDi 'yes'

No. (Note: This is being dropped from DFDL v1.0 because there are no implementations as yet. )

Lengths in Bits

dfdl:alignmentUnits 'bits' or dfdl:lengthUnits 'bits'

No. Lengths may be expressed in bits, but must be multiples of 8. So really it is bytes.

Delimited lengths and representation binary element

dfdl:representation 'binary' (or implied binary) and dfdl:lengthKind 'delimited'

No

Regular expressions

dfdl:lengthKind 'pattern',

dfdl:assert with dfdl:testkind 'pattern' ,

dfdl:discriminator with dfdl:testkind 'pattern'

No

Zoned numbers

dfdl:textNumberRep 'zoned'

No

IBM 390 packed numbers

dfdl:binaryNumberRep 'packed' 

No

IBM 390 packed calendars

dfdl:binaryCalendarRep 'packed'

No

IBM 390 floats

dfdl:binaryFloatRep 'ibm390Hex'

No

Unordered sequences

dfdl:sequenceKind 'unordered'

No

Floating elements

dfdl:floating 'yes'

No

dfdl functions in expression language

dfdl:functions in expression

Not initially.

  • Will be added with expression language.
  • The set of available functions may be limited, increasing over time.

Hidden groups

dfdl:hiddenGroupRef <> ''

Yes. (No work required in runtime backend.)

Calculated values

dfdl:inputValueCalc <> '' or dfdl:outputValueCalc <> ''

Not initially. Eventually should be added.

Escape schemes

dfd:defineEscapeScheme in xsd

No

Extended encodings

Any dfdl:encoding value beyond the core list

No

Asserts

dfdl:assert in xsd

No

Discriminators

dfdl:discriminator in xsd

No

Prefixed lengths

dfdl:lengthKind 'prefixed'

No

Variables


dfdl:defineVariable,

dfdl:newVariableInstances,

dfdl:setVariable

Variables in DFDL expression language

Note that variables as a feature is dependent on the Expressions feature.

No

BCD calendars

dfdl:binaryCalendarRep "bcd"  

No

BCD numbers

dfdl:binaryNumberRep "bcd"

No

Multiple schemas

xs:include or xs:import in xsd

Yes. (Requires no work in a runtime backend.)

IBM 4690 packed numbers

dfdl:binaryNumberRep "ibm4690Packed"

No

IBM 4690 packed calendars

dfdl:binaryCalendarRep "ibm4690Packed"

No

DFDL Byte Value Entities

Use of %#r syntax in a DFDL String Literal other than the dfdl:fillByte property

No

DFDL Standard Character Set Encodings

dfdl:encoding name begins with "X-DFDL-".

No

Bit Order - Least Significant Bit First

dfdl:bitOrder with value 'leastSignificantBitFirst'

No

Daffodil extensions to DFDL - layering, blob objects, the dfdlx:emptyElementParsePolicy property, additional character sets (hex, octal, bits, and specialty sets), etc. all will not be supported.

Additional characteristics we expect Runtime 2 to have, which simplify the implementation:

  • each parse operation consumes data from an input stream, and produces a data structure. This data structure is not produced incrementally, but all at once.

    • Rationale: This eliminates the demands of streaming-parsing.

  • each unparse operation consumes one entire fully populated data structure, and produces data to an output stream.

    • Rationale: This massively simplifies unparsing by allowing expression evaluation to always assume the entire "infoset" object is already constructed. Expression evaluation never needs to support streaming, that is, be suspended waiting for additional infoset events to arrive.

  • I/O is byte-centric

    • data is byte-centric. That is no element spans a byte boundarycan be of size that is not a multiple of bytes long.

    • data can be big or little endian.bitOrder is mostSignificantBitFirst always

    • character sets are all byte-oriented. Their code units are 8 bit bytes minimum.

    • Rationale: This set of constraints insures ordinary Java I/O supplies most of the I/O layer natively.

Initial Simplifying Restrictions

These In general, use of unsupported features will cause a compile time SDE. These restrictions may be lifted over time.

...

No variables, no dfdl:setVariable dfdl:newVariableInstance

...

.

...

.

...

    • Note that if length and occursCount work, then implementing other runtime-valued properties may not be hard.

    Only lengthKind 'explicit' or 'implicit' for simple types, and only lengthKind 'implicit' for complex types.Limited set of expression functions

  • Only types long, int, short, byte, unsignedLong, unsignedInt, unsignedShort, unsignedByte, float, double,  string, and hexbinary are supported. (

    • Leaves out the decimal, integers greater than 64 bits long, boolean and date/time related types

    )
  • The dfdl:representation is always 'binary'. No text numbers are supported.

  • The dfdl:binaryNumberRep is always 'binary'.  Integers are fixed-length 2’s complement.

  • dfdl:binaryFloatRep="ieee".

  • The dfdl:alignment is always 1 byte.

  • No unordered sequences or floating elements

  • No validation

  • Only When added, note that occursCountKind="expression", and choices must use with only dfdl:choiceDispatchKey and dfdl:choiceBranchKey . No implies no backtracking/discrimination allowedis required.

    • Rationale: This and requiring only dfdl:occursCountKind='expression' means there are no ponts of uncertainty, so there is no backtracking.

...

Properties that end up needed, but shouldn't be - ex: anything about text numbers, anything about date/time - are bugs in Daffodil that should be reported. An include-file DFDL format definition should hide these from users so they are not distracting.

Goals

  • Use Julian Feiauer contributed code generation library so as to have the possibility of Java, C++, and Python backends from Runtime 2
  • Initial focus is a backend where the Infoset is Java POJO objects. The POJO definitions are part of the generated code, which is output as one or multiple text files.
  • DPath expressions compile into Java native language expressions that navigate Java POJOs Infoset objects the way handwritten code would.

  • Translating Runtime 2 into a similar C/C++ runtime should be conceptually quite easy. Nothing should be done in Runtime 2 that is particularly Java specific. (I/O streams that operate like Java BufferedInputStream and OutputStream are assumed.

    Dependencies on Java garbage collection should be minimized and documented.
  • The amount of runtime-library code should be minimum footprint.

    • Selective linking can be assumed (even for Java - search for GraalVM)

  • Satisfy the requirements that caused the PLC4X project to create their own MSpec data format language. (Or to serve as a Alternatively, Daffodil with Runtime 2 should be a good target for MSpec compilation.)

    • With one exception: DFDL is still going to be XML Schema based. Changing the syntax of the DFDL language is out of scope, as that's a front-end project. This is a runtime/back-end project.

Random Implementation Notes

  • ParseError and UnparseError must be supported. both are always fatal as there are no points-of-uncertainty/backtracking

  • RuntimeSDE ??

    • TBD: Can runtime SDEs occur? We may have eliminated all possibilities for them.

  • PState and UState (state of parser/unparser) and mutable data structures reachable from them are thread specific. All other data structures are shared /across threads and immutable or thread-safe.

  • JUnit-style tests should be easily created. This can use Scala so as to take advantage of XML syntax in the language so that schemas can be created in the test files.