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

LF: clean daml-lf/language module #11152

Merged
merged 1 commit into from
Oct 7, 2021
Merged

Conversation

remyhaemmerle-da
Copy link
Collaborator

  • enable NonUnitStatements, and find a useless statement.
  • add missing finals,
  • 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

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

- 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
@remyhaemmerle-da remyhaemmerle-da added the component/daml-engine DAML-LF Engine & Interpreter label Oct 6, 2021
object TemplateKey extends GenTemplateKeyCompanion[Expr]
val TemplateKey = new GenTemplateKeyCompanion[Expr]

type TemplateKeySignature = GenTemplateKey[Unit]
object TemplateKeySignature extends GenTemplateKeyCompanion[Unit]
val TemplateKeySignature = new GenTemplateKeyCompanion[Unit]
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

Comment on lines +930 to +935
) {
templates.keysIterator.foreach(name =>
if (exceptions.keySet.contains(name))
throw PackageError(s"Collision between exception and template name ${name.toString}")
)
}
Copy link
Collaborator Author

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

Copy link
Contributor

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.

Copy link
Contributor

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(
Copy link
Collaborator Author

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.

Copy link
Contributor

@sofiafaro-da sofiafaro-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

Comment on lines +930 to +935
) {
templates.keysIterator.foreach(name =>
if (exceptions.keySet.contains(name))
throw PackageError(s"Collision between exception and template name ${name.toString}")
)
}
Copy link
Contributor

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.

Copy link
Contributor

@nickchapman-da nickchapman-da left a 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] {
Copy link
Contributor

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?

Copy link
Collaborator Author

@remyhaemmerle-da remyhaemmerle-da Oct 7, 2021

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.

@remyhaemmerle-da remyhaemmerle-da merged commit dd233ef into main Oct 7, 2021
@remyhaemmerle-da remyhaemmerle-da deleted the remy-lf-language-cleanup branch October 7, 2021 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/daml-engine DAML-LF Engine & Interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants