Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism for Generating Name Mangles #3

Open
DavePearce opened this issue Oct 25, 2016 · 1 comment
Open

Mechanism for Generating Name Mangles #3

DavePearce opened this issue Oct 25, 2016 · 1 comment

Comments

@DavePearce
Copy link
Member

DavePearce commented Oct 25, 2016

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.

@DavePearce
Copy link
Member Author

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

DavePearce added a commit that referenced this issue Nov 3, 2016
This is a temporary fix for addressing the issue of name mangling.
Specifically, it implements name mangling by reusing the existing
BinaryTypeWriter.  That class is, however, scheduled to be replaced ...
so this is only deferring the final solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant