-
Notifications
You must be signed in to change notification settings - Fork 396
Unify TreeHash and Versioned into a single Version #4772
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
Conversation
Only the last commit is part of this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I like it :)
val isHash = version.isHash | ||
buffer.writeBoolean(isHash) | ||
if (isHash) | ||
version.writeHash(buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens/should happen if the version is Combined
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not write it. The idea (and yes I'll document this properly) is that we'll only ever serialize hashed versions. All the other versions are not serialization safe (as in: we cannot guarantee collision freedom across linker instances).
private[linker] def fileTimeToVersion(time: FileTime): ir.Version = | ||
ir.Version.fromBytes(time.toString().getBytes(StandardCharsets.US_ASCII)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems unnecessarily inefficient. Consider something like:
val instant = time.toInstant()
ir.Version.fromLongs(instant.getEpochSecond(), instant.getNano())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have. But that isn't lossless according to this: https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/FileTime.html#toInstant--
toString
is the only lossless serialization of FileTime
I could find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, OK. Probably worth a comment, then.
} { linkedInit => | ||
mergeVersions(linkedClass.version, linkedInit.version).map("2-" + _) | ||
Version.combine(linkedClass.version, linkedInit.version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit funny. We can distinguish those two Version
s because Combine
of different lengths are always different. That's a bit of an implementation detail, though, isn't it? Also, what if we wanted the same distinguishing feature but coming from two different single Version
s?
Should we have a Version.tag(tag: Int, underlying: Version)
constructor for that purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have considered that. IMO that is subsumed by:
Version.combine(Version.fromInt(tag), underlying)
(arguably that is slighly less space efficient, but I'm not sure it matters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that makes sense.
b41a68b
to
88f6988
Compare
project/JavalibIRCleaner.scala
Outdated
@@ -204,7 +204,7 @@ final class JavalibIRCleaner(baseDirectoryURI: URI) { | |||
case m @ MethodDef(flags, name, originalName, args, resultType, body) => | |||
implicit val pos = m.pos | |||
MethodDef(flags, transformMethodIdent(name), originalName, transformParamDefs(args), | |||
transformType(resultType), body)(m.optimizerHints, m.hash) | |||
transformType(resultType), body)(m.optimizerHints, Version.NoVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: We're running the overall result through Hashers anyways (as we should). So this will just keep an old / wrong hash (in fact, it could lead to spurious diffs where there are non in the resulting tree).
Not ready for review yet. Needs test adjustment (and tests). |
e130295
to
ebe5066
Compare
Ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments only.
final class Version private (private val v: Array[Byte]) extends AnyVal { | ||
import Version.Type | ||
|
||
/** Whether this is a sentinel. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A sentinel is an implementation-detail concept. I wouldn't talk about it in the public API. Also this suggests that it returns true when it's the sentinel.
Consider instead "Whether this version is different than NoVersion." or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we weren't actually using this a public API, so I made it private and dropped the comment entirely.
|
||
testNe(v, fromHash(a)) | ||
testNe(v, fromBytes(a)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious new line.
exclude[DirectMissingMethodProblem]("org.scalajs.ir.Trees#JSPropertyDef.apply"), | ||
exclude[MissingClassProblem]("org.scalajs.ir.Trees$DoWhile"), | ||
exclude[MissingClassProblem]("org.scalajs.ir.Trees$DoWhile$"), | ||
exclude[Problem]("org.scalajs.ir.*"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
Have you considered calling |
Good point. |
No real preference between |
Updated. |
eb5773c
to
321e993
Compare
No description provided.