Skip to content

Mechanism for Generating Name Mangles #3

Open

Description

@DavePearce

With recent changes to the compiler, we've lost the ability to create easy name mangles based on a byte representation of the Automata. Instead, we now face the somewhat easier task of generating name mangles from a type tree! As an example, consider these two cases:

type Point is {int x, int y}

function f(null|Point p):
    ...

function f(null|{int x, int y} p):
    ...

These functions are overloading each other and, hence, we need a mangling mechanism which distinguishes them. A simple strategy (based on the approach used for type signatures in JVM bytecode) might be:

  • Primitives. Let null, bool, byte, int, be represented by N, B, Y, I respectively.
  • Arrays. Let a type of the form T[] be represented as [f(T) (where f(T) is the representation of T)
  • Unions, Intersections and Negations. These should be represented directly using the obvious (infix) letters |, & and !.
  • Records. These should be represented simply enclosed in { and } with, for each field, the type first and then the name.
  • References. These should be represented by the infix operator *.
  • Nominals. These should be represented as L ... ; (I suppose this is homage to Java bytecode)

Following this alphabet, we would have the following signatures for the two methods given above:

  • null|Point is represented as n|LPoint;
  • null|{int x, int y} is represnted as n|{ILx;ILy;}

I guess an important question is: do we want to retain some level of human readability?

Another important issue is to ensure that types are in canonical form. More specifically, we need to generate the same mangles for the following two functions:

function f(int|null x):
    ...

function f(null|int x):
    ...

This ensures some (though not total) resistance against issues of binary compatibility.

Activity

  1. DavePearce commented on Nov 3, 2016

    @DavePearce
    MemberAuthor

    The current interim solution just reuses the BinaryTypeWriter. This is not ideal, but it works for now.

  2. added a commit that references this issue on Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions