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

sort mappings #163

Open
SpaceWalkerRS opened this issue Jul 29, 2024 · 2 comments
Open

sort mappings #163

SpaceWalkerRS opened this issue Jul 29, 2024 · 2 comments
Assignees
Labels
buildscript Issue related to the buildscript

Comments

@SpaceWalkerRS
Copy link
Member

the order in which mappings appear in mapping files is not well defined - mappings should be sorted in some way so that the order does not randomly change when working on mappings, blowing up commits

@SpaceWalkerRS SpaceWalkerRS added the buildscript Issue related to the buildscript label Jul 29, 2024
@SpaceWalkerRS SpaceWalkerRS self-assigned this Jul 29, 2024
@zeichenreihe
Copy link
Contributor

Creating a sorting for the mappings seems like a good idea.

My rust code sorts them like follows:

  • N is the number of namespaces. This is a constant and fixed for any mapping.
  • Option<T> gets sorted as follows: first come all the None variants, then all the Some(T) variants, sorted by T ofc.
  • Strings sort like the bytes of a UTF8 representation would sort. Since all Strings in mappings are just ASCII, I think relying on java's String sorting is fine for this (java actually sorts according to the chars inside the string, since we're not leaving the code point range of a char (where we'd have two chars encoding a surrogate pair), we're fine).
  • For classes, sort them lexicographically as if they were a list with length N of elements of type Option<ClassName>. The first element of the list is the name in the first namespace, the second one in the second namespace and so on. ClassName is a String.
    • Inside each class sort the fields first by their descriptor (again a String), then by their names (again a list of options like with classes)
    • The same goes for methods.
      • For parameters, sort by the index (as a number) and then by the names as a list of options like the classses.

Also relevant is the order in which the things are written out:

  • First comes the header, then inside each class
    • First the javadoc comment,
    • then the fields
      • with an javadoc comment,
    • then the methods,
      • with an javadoc comment,
      • and then the parameters,
        • with an javadoc comment.

It would be nice to get the same sorting order with java.

One note by me: For comparing my results with the results of the buildscript, I read, sorted and wrote the output once.

Also my code has forced sorting in the actual mappings writer.

@wagyourtail
Copy link

wagyourtail commented Jul 31, 2024

I don't like the idea of sorting fields by descriptor, sorting them by name (with how mojang has proguard configured) seems better, because that's their order withing the classfile

sorting by name, then descriptor for class members would be better imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buildscript Issue related to the buildscript
Projects
Status: No status
Development

No branches or pull requests

3 participants