Uploaded image for project: 'Swift'
  1. Swift
  2. SR-920

Re-design builtin compiler protocols for literal convertible types

    XMLWordPrintable

    Details

      Description

      Swift aims to be an extensible language through the built-in compiler protocols, which allow user-defined types to adopt literal syntax.

      If we want to commit to that design as ABI, we need to improve the protocols so that they are actually useful outside of the standard library.

      1. There should be a type in the standard library that can represent the literal in a lossless way. For example, currently integer and floating point literals are truncated to the maximum precision supported by the library (Int64 and Float80) before they can be handled by user code.

      For example, the library could provide an IntegerLiteral type, which wraps a 2048-bit integer that user types adopting the literal protocols could use. Same for floating-point literals (but the number should be represented exactly to allow decimal foating point literals).

      2. Protocols related to string literals should have reasonable default implementations. Currently, to implement a string literal convertible type, you need to write many functions that just forward to each other to conform to the protocol.

      3. When we get special transport types, the initializer labels can become simpler (e.g. drop the ‘literal’ from the label, since that would repeat type information).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gribozavr Dmitri Gribenko
              • Votes:
                6 Vote for this issue
                Watchers:
                18 Start watching this issue

                Dates

                • Created:
                  Updated: