-
Notifications
You must be signed in to change notification settings - Fork 205
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
LF: clean daml-lf/language module #11152
Conversation
- enable NonUnitStatements, and find a useless statement. - add missing `final`s, - replace `{ ... }` by `( ... )` for one statement anonymous function - drop useless `new` for case class. - replace `sealed class X { ... object Y extend X` by `class X private[Z] { ... val Y = new X` to avoid unecessary class alocation. - move invariant check inside the body of some case class instead of the companion object. - other cosmetic changes. CHANGELOG_BEGIN CHANGELOG_END
object TemplateKey extends GenTemplateKeyCompanion[Expr] | ||
val TemplateKey = new GenTemplateKeyCompanion[Expr] | ||
|
||
type TemplateKeySignature = GenTemplateKey[Unit] | ||
object TemplateKeySignature extends GenTemplateKeyCompanion[Unit] | ||
val TemplateKeySignature = new GenTemplateKeyCompanion[Unit] |
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.
By using new
instead of extends we avoid allocation of two extra java classes.
@@ -686,9 +681,9 @@ object Ast { | |||
observers: E, // Observers of the contract. | |||
key: Option[GenTemplateKey[E]], | |||
implements: Map[TypeConName, GenTemplateImplements[E]], | |||
) extends NoCopy |
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.
There is no special invariant for this case class, so no reason to have a private constructor and prevent copy method.
) { | ||
templates.keysIterator.foreach(name => | ||
if (exceptions.keySet.contains(name)) | ||
throw PackageError(s"Collision between exception and template name ${name.toString}") | ||
) | ||
} |
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.
Once putting the invariant check inside GenModule
, we do not need the constructor to be private
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. Question: should there be more collision checks here? E.g. between templates and interfaces, exceptions and interfaces.
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.
Oh actually, they can't collide anyway because Interface has a DataInterface as underlying, not a DataRecord.
@@ -9,7 +9,7 @@ object StablePackages { | |||
// Based on compiler/damlc/tests/src/stable-packages.sh | |||
// TODO: Use this map to generate the mapping used in the test, | |||
// or generate both from a single source. | |||
private val nameToIdMap = Map[PackageName, PackageId]( | |||
private[this] def nameToIdMap: Map[PackageName, PackageId] = Map( |
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 used only once to create Ids
, no need to keep it in memory.
daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/Ast.scala
Show resolved
Hide resolved
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, thank you!
) { | ||
templates.keysIterator.foreach(name => | ||
if (exceptions.keySet.contains(name)) | ||
throw PackageError(s"Collision between exception and template name ${name.toString}") | ||
) | ||
} |
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. Question: should there be more collision checks here? E.g. between templates and interfaces, exceptions and interfaces.
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.
Thanks!
@@ -586,18 +584,18 @@ object Ast { | |||
isTest: Boolean, | |||
) extends GenDefinition[E] | |||
|
|||
class GenDValueCompanion[E] { | |||
final class GenDValueCompanion[E] private[Ast] { |
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 does private[Ast]
mean/do 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.
you cannot allocate a new GenDValueCompanion outside Ast object.
final
s,{ ... }
by( ... )
for one statement anonymous functionnew
for case class.sealed class X { ... object Y extend X
byclass X private[Z] { ... val Y = new X
to avoid unecessary classalocation.
the companion object.
CHANGELOG_BEGIN
CHANGELOG_END
Pull Request Checklist
CHANGELOG_BEGIN
andCHANGELOG_END
tagsNOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with
/AzurePipelines run
totrigger the build.