-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ordered serialization stable across compilations (#1664)
* ordered serialization - fix `knownDirectSubclasses` indeterminism * remove special handling for hierarchies with <= 4 elements
- Loading branch information
Showing
3 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...rialization/macros/impl/ordered_serialization/providers/StableKnownDirectSubclasses.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.twitter.scalding.serialization.macros.impl.ordered_serialization.providers | ||
|
||
import scala.reflect.macros.whitebox.Context | ||
|
||
/** | ||
* The `knownDirectSubclasses` method doesn't provide stable ordering | ||
* since it returns an unordered `Set` and the `Type` AST nodes don't | ||
* override the `hashCode` method, relying on the default identity | ||
* `hashCode`. | ||
* | ||
* This function makes the ordering stable using a list ordered by the | ||
* full name of the types. | ||
*/ | ||
object StableKnownDirectSubclasses { | ||
|
||
def apply(c: Context)(tpe: c.Type): List[c.universe.TypeSymbol] = | ||
tpe.typeSymbol.asClass.knownDirectSubclasses.map(_.asType).toList.sortBy(_.fullName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters