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

Share new base transforms between WDL 1.0 and 1.1 #3852

Merged
merged 2 commits into from
Jul 16, 2018

Conversation

cjllanwarne
Copy link
Contributor

@cjllanwarne cjllanwarne commented Jul 3, 2018

Allows reading of WDL 1.0 and 1.1 Asts through a shared set of CheckedAtoB functions, with the flexibility to inject different transform behavior into each usage of the instantiations of the transforms.

Note: of the 9013 added lines, 7484 are the new 1.1 WDL parser and presumably about 810 are files which got moved out of draft-3/transforms and into base/transforms

@Horneth
Copy link
Contributor

Horneth commented Jul 3, 2018

@cjllanwarne Do you need a red review on this ? If so could you elaborate just a little on what

Allows reading of WDL 1.0 and 1.1 Asts through a shared set of CheckedAtoB functions, with the flexibility to inject different transform behavior into each usage of the instantiations of the transforms.

means for me poor mortal and / or point to relevant code that I should look at ? 😄

@cjllanwarne
Copy link
Contributor Author

The WDL map might help:

wdlmap

This PR splits the top two circles into two parallel paths: Draft3 file -> Draft3 ASTs and Biscayne file -> Biscayne ASTs (I'm using Biscayne as my codename for "whatever WDL version is next, probably 1.1", because national parks are cool). The ASTs can then go through a single transform function into a shared WDL Object Model.

The clever part is that the transform function can (but doesn't yet) be customised by replacing specific "AST to WDLOM" transformations with version specific functions (those are the CheckedAtoBs, and that's why the two lists of CheckedAtoBs each version uses are identical... for now)

@cjllanwarne cjllanwarne force-pushed the cjl_wdl_1.1_packages branch from c2899fd to 41cf6f0 Compare July 3, 2018 19:07
Copy link
Contributor

@Horneth Horneth left a comment

Choose a reason for hiding this comment

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

Just a few ToLs.
I know there's a tech talk next week for this, I don't know if we want to wait for that or not. I won't be there for it so depending on what you decide feel free to ignore my 👍

l.forall(_.isWhitespace) || l.dropWhile(_.isWhitespace).startsWith("#")
}
val start = trimStart.next.dropWhile(_.isWhitespace)
start.startsWith("version 1.1") || start.startsWith("version biscayne")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if there's any project the wdl factories share but if so, looks like this code could be in it since it's almost the same here and in draft 3

@@ -0,0 +1,57 @@
//package wdl.transforms.base.ast2wdlom
Copy link
Contributor

Choose a reason for hiding this comment

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

remove ?

(implicit astNodeToExpressionElement: CheckedAtoB[GenericAstNode, TypeElement]): Checked[TypeElement] = typeAst.getAttributeAs[String]("name") flatMap {
case "Array" => typeAst.getAttributeAsVector[TypeElement]("subtype") flatMap {
case one if one.size == 1 => ArrayTypeElement(one.head).validNelCheck
case other => s"Arrays must have exactly one type parameter, but got ${other.size}".invalidNelCheck
Copy link
Contributor

Choose a reason for hiding this comment

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

ToL: maybe also say what the provided types were in the error message ? (here and below if so)

)



Copy link
Contributor

Choose a reason for hiding this comment

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

Lots of room here 😄

@cjllanwarne cjllanwarne force-pushed the cjl_wdl_1.1_packages branch 3 times, most recently from cf6d2b2 to 1d61bf0 Compare July 11, 2018 15:29
@gemmalam gemmalam requested a review from aednichols July 12, 2018 12:57
Copy link
Collaborator

@aednichols aednichols left a comment

Choose a reason for hiding this comment

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

Still looking, some minor comments so far. I'd love to brainstorm a clever Scala-ey way to reduce code duplication.

@@ -205,7 +205,7 @@ object EngineFunctionEvaluators {
read <- readFile(fileToRead, ioFunctionSet, fileSizeLimitationConfig.readBoolLimit)
asBool <- Try(read.trim.toBoolean)
} yield WomBoolean(asBool)
tryResult.map(EvaluatedValue(_, Seq.empty)).toErrorOr.contextualizeErrors(s"""read_boolean("${fileToRead.value}")""")
tryResult.map(EvaluatedValue(_, Seq.empty)).toErrorOr.contextualizeErrors(s"""read_int("${fileToRead.value}")""")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Intentional change? Seems incorrect.

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... very good catch! I have no idea what caused this but it's definitely not right...

@@ -0,0 +1,34 @@
package wdl.transforms.biscayne.ast2wdlom
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use type parameters to reduce duplication between this file and Draft3GenericAstNode.scala? The only difference seems to be the type of the Ast (wdl.draft3.parser.WdlParser.Ast vs. wdl.biscayne.parser.WdlParser.Ast).

Incomplete but illustrates what I'm getting at:

case class BaseGenericAst[T <: GenericAstNode](ast: T) extends GenericAst {
  override def getAttribute(attr: String): GenericAstNode = Option(ast.getAttribute(attr)).map(T.apply).orNull
  override def getAttributes: Map[String, GenericAstNode] = ast.getAttributes.asScala.toMap collect {
    case (key, value) if value != null => key -> T(value)
  }
  override def getName: String = ast.getName
}

@@ -0,0 +1,62 @@
package wdl.transforms.biscayne
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency and ease of navigation, it probably makes sense to unify the file name between Biscayne and draft-3:

wdl/transforms/draft3/src/main/scala/wdl/draft3/transforms/ast2wdlom/package.scala
wdl/transforms/biscayne/src/main/scala/wdl/transforms/biscayne/ast2wdlom/ast2wdlom.scala

Copy link
Collaborator

@aednichols aednichols left a comment

Choose a reason for hiding this comment

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

Thumbing provisional on

  • fixing or clarifying the read_boolean() to read_int() change
  • addressing (or saying why not) the ast2wdlom.scala vs. package.scala comment

@cjllanwarne cjllanwarne force-pushed the cjl_wdl_1.1_packages branch from 1d61bf0 to 894824d Compare July 13, 2018 16:55
@cjllanwarne cjllanwarne merged commit cbaf799 into develop Jul 16, 2018
@cjllanwarne cjllanwarne deleted the cjl_wdl_1.1_packages branch May 10, 2019 15:22
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