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

Add an initial version of DAML script #3428

Merged
merged 1 commit into from
Nov 12, 2019
Merged

Add an initial version of DAML script #3428

merged 1 commit into from
Nov 12, 2019

Conversation

cocreature
Copy link
Contributor

The code still needs a fair amount of cleanup but it seems to work and
there is a test so I’d like to do the cleanup in-tree after merging
the current state

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
  • Add a line to the release notes, if appropriate
  • 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.

@cocreature cocreature requested review from a user and aherrmann-da November 12, 2019 10:27
The code still needs a fair amount of cleanup but it seems to work and
there is a test so I’d like to do the cleanup in-tree after merging
the current state
Copy link
Contributor

@leo-da leo-da left a comment

Choose a reason for hiding this comment

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

You should use match instead of asInstanceOf.

dar.all
.find {
case (pkgId, pkg) =>
pkg.modules.contains(DottedName.assertFromString("DA.Internal.LF"))
Copy link
Contributor

Choose a reason for hiding this comment

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

DottedName.assertFromString("DA.Internal.LF") can be a constant.

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not put loback.xml in the src/main/resources. It would get packaged in a jar and gets deployed to maven. This is going to pollute end-user's classpath with unnecessary logback.xml. I would rather force everyone who deploys you app start thinking about logback configuration ASAP :)
java -Dlogback.configurationFile=/path/to/config.xml is the way to go. However we have not been following this practice. So feel free to disregard this comment :)

Copy link
Contributor

Choose a reason for hiding this comment

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

src/test/resources is fine, it does not pollute production classpath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don’t plan to publish anything else than the executable and even for the executable you can still override the bundled logback file with -Dlogback.configurationFile.

}
}
}
val tuple = machine.toSValue.asInstanceOf[STuple]
Copy link
Contributor

@leo-da leo-da Nov 12, 2019

Choose a reason for hiding this comment

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

you should use match here, something like this:

machine.toSValue match {
  case STuple(_, (a0: SVariant) :: (a1: SVariant) :: _) => (a0, a1)
  case => sys.error("something unexpected")
}

or if you know that it is a tuple 2

machine.toSValue match {
  case STuple(_, (a0: SVariant) :: (a1: SVariant) :: Nil) => (a0, a1)
  case => sys.error("something unexpected")
}

in any case using match is more idiomatic Scala, you should never use asInstanceOf.

Copy link
Contributor

Choose a reason for hiding this comment

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

oops it is java.util.ArrayList you cannot match it like this, so you might want to convert it to Scala first. But in any case using asInstanceOf is discouraged unless you are hardcore Java programmer :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I’ll kill all the asInstanceOf stuff in a follow-up PR. That was just for prototyping.

Copy link
Contributor

@leo-da leo-da left a comment

Choose a reason for hiding this comment

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

had a chat with @cocreature. He wants to merge it ASAP to avoid any further conflicts. He is planning to address the instanceOf in a follow-up PR.

@cocreature cocreature merged commit b3ae656 into master Nov 12, 2019
@cocreature cocreature deleted the daml-script branch November 12, 2019 17:02
Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

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

Super nice. Thank you so much!

Free x >>= f = Free ((>>= f) <$> x)

-- | A free applicative, since we don’t have existentials we have to use the weird RankNTypes encoding, this is isomorphic to
-- forall b. Ap f b (Ap f (b -> a))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- forall b. Ap f b (Ap f (b -> a))
-- forall b. Ap (f b) (Ap f (b -> a))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks! fixed in #3438

SEMakeClo(Array(), 1, SEVar(1)))
val compiledPackages = PureCompiledPackages(darMap, definitionMap).right.get

def toLedgerRecord(v: SValue) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could some of this be shared between triggers and daml-script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could probably share a bit, e.g., the logic for converting AnyTemplate but most of the conversion are specific to the types used in the trigger/script library so the shared code isn’t as large as one might hope. I’ll first cleanup the conversion logic here and then see what we can factor out.

bame-da pushed a commit that referenced this pull request Nov 19, 2019
The code still needs a fair amount of cleanup but it seems to work and
there is a test so I’d like to do the cleanup in-tree after merging
the current state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants