mbeckerle commented on a change in pull request #324: WIP: DAFFODIL-1444 Schema 
Compiler Space/Speed
URL: https://github.com/apache/incubator-daffodil/pull/324#discussion_r379858230
 
 

 ##########
 File path: daffodil-core/src/main/scala/org/apache/daffodil/dsom/Term.scala
 ##########
 @@ -107,11 +135,82 @@ trait Term
   requiredEvaluations(nonDefaultPropertySources)
   requiredEvaluations(defaultPropertySources)
   requiredEvaluations(termChecks)
+  requiredEvaluations(shared)
 
   private lazy val termChecks = {
     statements.foreach { _.checkTerm(this) }
   }
 
+  /**
+   * If two terms have the same propEnv, they have identical properties
+   * in scope.
+   */
+  lazy val propEnv: PropEnv = {
+    val localPropsSets = this.nonDefaultFormatChain.propertyPairsSets
+    val defaultPropObj = this.defaultFormatChain.propertyPairsSets
+    val next = refersToForPropertyCombining
+    PropEnvFactory(localPropsSets, defaultPropObj, next.map { _.xml })
+  }
+
+  /**
+   * The thing that provides the actual definition. If this is a local
+   * element decl or local sequence/choice, then this is the thing,
+   * if this is some sort of a ref, then the referenced definition is the 
thing.
+   */
+  private lazy val optionDef: AnnotatedSchemaComponent = {
+    this match {
+      case gr: GroupRef => gr.groupDef
+      case aer: AbstractElementRef => aer.referencedElement
+      case eb: ElementBase => eb
+      case grl: GroupDefLike => grl
+    }
+  }
+
+  type SharedTerm = Term.SharedTerm // for now these are the same object
+
+  /**
+   * The "shared term" is just a term which will be used as the
+   * "prototypical term" for this definition and propEnv.
+   *
+   * We must be careful not to utilize anything from the shared term
+   * that depends on the uniqueness, like about position within
+   * enclosing model group def, or characteristics of sibling terms
+   * preceding in a sequence.
+   *
+   * On the other hand, if we are careful to generate runtime
+   * information off of the shared object, then that will only happen once.
+   * So if we do everything we can off of the shared object, that
+   * will fix most duplication/copying and redundant effort in the
+   * schema compiler.
+   *
+   * This has some quite obvious architectural flaws.
+   * For example that nothing stops you from doing this all utterly
+   * wrong by doing it on the term, not the term.shared.
+   *
+   * This is a temporary fix to try to incrementally improve the
+   * schema compiler's memory allocation and speed.
+   *
+   * Eventually, it would be better to have explicit UniqueTerm and SharedTerm
+   * classes and derivatives and split things that way.
+   *
+   * Such time as that is done, this member becomes non-final and without
+   * an implementation. All concrete subclasses of Term will have to implement
+   * this to create the proper shared object.
+   */
+
+  final protected def makeSharedTerm(unique: Term): SharedTerm = {
+    unique
+  }
+
+  lazy val shared: SharedTerm =
+    Term.sharedTermFactory(optionDef.xml, propEnv, makeSharedTerm(this))
+
+  /**
+   * True if this term is sharing a shared term. That is, this term
+   * is not the proto-term for this term + propenv combination.
+   */
+  lazy val isSharingATerm = this ne shared
 
 Review comment:
   Eliminated problematic isSharingATerm by eliminating term sharing. We now 
share exactly the things needed, and nothing else.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to