You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2020/09/11 18:16:54 UTC

[incubator-daffodil] branch master updated: Removed ExecutionMode.scala and all references

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new 10d5e2a  Removed ExecutionMode.scala and all references
10d5e2a is described below

commit 10d5e2a16660a0a5a4671513b2dbafe84989658d
Author: Steinberger <rs...@tresys.com>
AuthorDate: Fri Sep 11 10:57:41 2020 -0400

    Removed ExecutionMode.scala and all references
    
    This process has been documented as no longer being necessary.
    
    Daffodil-1814
---
 .../daffodil/dsom/AnnotatedSchemaComponent.scala   |  3 -
 .../apache/daffodil/dsom/DFDLEscapeScheme.scala    |  2 -
 .../scala/org/apache/daffodil/dsom/SchemaSet.scala |  3 -
 .../daffodil/runtime1/SchemaSetRuntime1Mixin.scala |  3 -
 .../scala/org/apache/daffodil/ExecutionMode.scala  | 98 ----------------------
 .../daffodil/debugger/InteractiveDebugger.scala    |  3 -
 .../main/scala/org/apache/daffodil/dsom/SDE.scala  |  3 -
 .../apache/daffodil/processors/DataProcessor.scala | 90 ++++++++++----------
 .../daffodil/processors/ProcessorStateBases.scala  |  4 -
 9 files changed, 43 insertions(+), 166 deletions(-)

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/AnnotatedSchemaComponent.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/AnnotatedSchemaComponent.scala
index 3551a05..7c39683 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/AnnotatedSchemaComponent.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/AnnotatedSchemaComponent.scala
@@ -19,7 +19,6 @@ package org.apache.daffodil.dsom
 
 import scala.xml.Node
 import org.apache.daffodil.exceptions.Assert
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.xml.XMLUtils
 import org.apache.daffodil.xml.NS
 import org.apache.daffodil.equality._
@@ -79,7 +78,6 @@ trait ResolvesLocalProperties
    * Does lookup of only local properties
    */
   protected override def lookupProperty(pname: String): PropertyLookupResult = {
-    ExecutionMode.requireCompilerMode
     Assert.usage(
       ResolvesProperties.localOnlyProperties.contains(pname),
       "Property '%s' is not a valid local-only property.".format(pname))
@@ -163,7 +161,6 @@ trait ResolvesScopedProperties
    *  properties, then default property locations.
    */
   protected override def lookupProperty(pname: String): PropertyLookupResult = {
-    ExecutionMode.requireCompilerMode
     // first try in regular properties
     val regularResult = findNonDefaultProperty(pname)
     regularResult match {
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/DFDLEscapeScheme.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/DFDLEscapeScheme.scala
index 7eadc36..84eef74 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/DFDLEscapeScheme.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/DFDLEscapeScheme.scala
@@ -19,7 +19,6 @@ package org.apache.daffodil.dsom
 
 import scala.xml.Node
 import scala.xml.Utility
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.schema.annotation.props.gen.EscapeScheme_AnnotationMixin
 import org.apache.daffodil.dpath._
 import org.apache.daffodil.schema.annotation.props.gen.EscapeKind
@@ -44,7 +43,6 @@ final class DFDLEscapeScheme(node: Node, decl: AnnotatedSchemaComponent, defES:
   final lazy val referringComponent: Option[SchemaComponent] = Some(defES)
 
   protected final override def lookupProperty(pname: String): PropertyLookupResult = {
-    ExecutionMode.requireCompilerMode // never get properties at runtime, only compile time.
     val propNodeSeq = xml.attribute(pname)
     propNodeSeq match {
       case None => NotFound(Seq(this), Nil, pname) // attribute was not found
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
index 7ef8752..a3345fb 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
@@ -29,7 +29,6 @@ import org.apache.daffodil.exceptions.ThrowsSDE
 import org.apache.daffodil.dpath.NodeInfo
 import java.io.File
 
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.xml.DFDLCatalogResolver
 import org.apache.daffodil.api.DaffodilSchemaSource
 import org.apache.daffodil.api.UnitTestSchemaSource
@@ -472,7 +471,6 @@ final class SchemaSet(
   }.value
 
   override def isError = {
-    ExecutionMode.usingCompilerMode {
       OOLAG.keepGoing(true) {
         val valid = isValid
         if (valid) {
@@ -490,7 +488,6 @@ final class SchemaSet(
           hasErrors
         } else true
       }
-    }
   }
 }
 
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/SchemaSetRuntime1Mixin.scala b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/SchemaSetRuntime1Mixin.scala
index e43fb8b..ea46146 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/SchemaSetRuntime1Mixin.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/SchemaSetRuntime1Mixin.scala
@@ -17,7 +17,6 @@
 
 package org.apache.daffodil.runtime1
 
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.api.DFDL
 import org.apache.daffodil.api.ValidationMode
 import org.apache.daffodil.dsom.SchemaSet
@@ -73,7 +72,6 @@ trait SchemaSetRuntime1Mixin { self : SchemaSet =>
   }.value
 
   def onPath(xpath: String): DFDL.DataProcessor = {
-    ExecutionMode.usingCompilerMode {
       Assert.usage(!isError)
       if (xpath != "/") root.notYetImplemented("""Path must be "/". Other path support is not yet implemented.""")
       val rootERD = root.elementRuntimeData
@@ -104,7 +102,6 @@ trait SchemaSetRuntime1Mixin { self : SchemaSet =>
         log(LogLevel.Compile, "Compilation (DataProcesor) completed with no errors.")
       }
       dataProc
-    }
   }
 
 }
diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/ExecutionMode.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/ExecutionMode.scala
deleted file mode 100644
index 25f1e14..0000000
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/ExecutionMode.scala
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.daffodil
-
-import scala.util.DynamicVariable
-import org.apache.daffodil.exceptions.Assert
-
-/**
- * This uses a scala DynamicVariable to create a dynamically scoped binding of
- * the Execution mode information (are we compiling, or are we at runtime).
- *
- * This works as a thread-local variable. So different threads can have independent dynamic
- * bindings.
- *
- * Supposedly this inherits so if one thread creates another, then it will inherit
- * the current value of the dynamic variable. (So, if we use parallelism using say, futures,
- * which is a natural idiom for functional programming, then threads they create would
- * work right.)
- *
- */
-object ExecutionMode {
-
-  private sealed class ExecutionModeBase
-
-  // The point of unknown mode is that it allows us to catch
-  // situations where we neglected to wrap usingCompilerMode or 
-  // usingRuntimeMode around something.
-
-  private case object UnknownMode extends ExecutionModeBase
-  private object CompileMode extends ExecutionModeBase
-  private object RuntimeMode extends ExecutionModeBase
-  private object UnrestrictedMode extends ExecutionModeBase
-
-  private val executionMode = new DynamicVariable[ExecutionModeBase](UnknownMode)
-
-  /**
-   * Use this by doing:
-   * <pre>
-   *     usingCompilerMode {
-   *     ... everything in this dynamic scope can call
-   *     requireCompilerMode, and it will not do anything
-   *     but requireRuntimeMode will abort.
-   *     ...
-   *     }
-   * </pre>
-   * Symmetrically for runtime mode.
-   */
-
-  final def usingCompilerMode[S] = executionMode.withValue[S](CompileMode) _
-  final def usingRuntimeMode[S] = executionMode.withValue[S](RuntimeMode) _
-  final def usingUnrestrictedMode[S] = executionMode.withValue[S](UnrestrictedMode) _
-
-  // private final def isCompilerMode = executionMode.value == CompileMode
-  private final def isRuntimeMode = executionMode.value == RuntimeMode
-  private final def isUnknownMode = executionMode.value == UnknownMode
-  private final def isUnrestrictedMode = executionMode.value == UnrestrictedMode
-
-  private def notUnknown = {
-    !isUnknownMode
-  }
-
-  final def requireCompilerMode = {
-    //
-    // Removed this as it was causing errors when the infoset code wanted
-    // to issue an SDE. That code doesn't have a PState around to issue 
-    // a runtime SDE, and it isn't clear whether it wants to issue a 
-    // regular SDE or a runtime one, because expression evaluation occurs
-    // both at compile time and runtime. The ERD object available as a Throws
-    // SDE object in the infoset throws regular SDE regardless of when
-    //
-    // TODO: consider removing this entire mechanism as no longer necessary.
-    // 
-    //    if (notUnknown && !isUnrestrictedMode)
-    //      Assert.invariant(isCompilerMode)
-    // if (!isCompilerMode) System.err.println("Doing a compile time thing at runtime!")
-  }
-
-  final def requireRuntimeMode = {
-    if (notUnknown && !isUnrestrictedMode)
-      Assert.invariant(isRuntimeMode)
-  }
-
-}
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/debugger/InteractiveDebugger.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/debugger/InteractiveDebugger.scala
index 594c5a4..36789e9 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/debugger/InteractiveDebugger.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/debugger/InteractiveDebugger.scala
@@ -25,7 +25,6 @@ import org.apache.daffodil.processors.parsers._
 import org.apache.daffodil.xml.XMLUtils
 import org.apache.daffodil.xml.GlobalQName
 import org.apache.daffodil.xml.QName
-import org.apache.daffodil.ExecutionMode
 import java.io.File
 import jline.console.completer.Completer
 import jline.console.completer.StringsCompleter
@@ -155,7 +154,6 @@ class InteractiveDebugger(runner: InteractiveDebuggerRunner, eCompilers: Express
   }
 
   def debugStep(before: StateForDebugger, after: ParseOrUnparseState, processor: Processor, ignoreBreakpoints: Boolean): Unit = {
-    ExecutionMode.usingUnrestrictedMode {
       debugState = debugState match {
         case _ if ((after.processorStatus ne Success) && DebuggerConfig.breakOnFailure) => DebugState.Pause
         case DebugState.Continue | DebugState.Trace if !ignoreBreakpoints => {
@@ -195,7 +193,6 @@ class InteractiveDebugger(runner: InteractiveDebuggerRunner, eCompilers: Express
         val args = readCmd
         debugState = runCommand(args, before, after, processor)
       }
-    }
   }
 
   private def isInteresting(parser: Parser): Boolean = {
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/dsom/SDE.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/dsom/SDE.scala
index a65a915..1a6965a 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/dsom/SDE.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/dsom/SDE.scala
@@ -18,7 +18,6 @@
 package org.apache.daffodil.dsom
 
 import org.apache.daffodil.exceptions._
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.api.Diagnostic
 import org.apache.daffodil.processors.ParseOrUnparseState
 import org.apache.daffodil.processors.CompileState
@@ -191,7 +190,6 @@ trait ImplementsThrowsOrSavesSDE
   def warn(th: Diagnostic): Unit
 
   def SDEButContinue(id: String, args: Any*): Unit = {
-    ExecutionMode.requireCompilerMode
     val sde = new SchemaDefinitionError(Some(schemaFileLocation), NoAnnotationContext, id, args: _*)
     error(sde) // calls the error routine which records the error, but doesn't throw/toss it.
   }
@@ -201,7 +199,6 @@ trait ImplementsThrowsOrSavesSDE
    */
   def SDW(warnID: WarnID, fmt: String, args: Any*): Unit = {
     if (tunable.notSuppressedWarning(warnID)) {
-      ExecutionMode.requireCompilerMode
       val sdw = new SchemaDefinitionWarning(Some(schemaFileLocation), NoAnnotationContext, fmt, args: _*)
       warn(sdw)
     }
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
index a469a4f..316aaf8 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
@@ -32,7 +32,6 @@ import org.xml.sax.ErrorHandler
 import org.xml.sax.SAXException
 import org.xml.sax.SAXParseException
 
-import org.apache.daffodil.ExecutionMode
 import org.apache.daffodil.api.DFDL
 import org.apache.daffodil.api.DaffodilTunables
 import org.apache.daffodil.api.ValidationMode
@@ -403,60 +402,57 @@ class DataProcessor private (
     // then validating at the end of the parse. See DAFFODIL-2386
     //
     val (outputter, maybeValidationBytes) =
-      if (validationMode == ValidationMode.Full) {
-        val bos = new java.io.ByteArrayOutputStream()
-        val xmlOutputter = new XMLTextInfosetOutputter(bos, false)
-        val teeOutputter = new TeeInfosetOutputter(output, xmlOutputter)
-        (teeOutputter, One(bos))
-      } else {
-        (output, Nope)
-      }
+    if (validationMode == ValidationMode.Full) {
+      val bos = new java.io.ByteArrayOutputStream()
+      val xmlOutputter = new XMLTextInfosetOutputter(bos, false)
+      val teeOutputter = new TeeInfosetOutputter(output, xmlOutputter)
+      (teeOutputter, One(bos))
+    } else {
+      (output, Nope)
+    }
 
     val rootERD = ssrd.elementRuntimeData
     val state = PState.createInitialPState(rootERD, input, outputter, this, areDebugging)
 
-    ExecutionMode.usingRuntimeMode {
-
-      if (areDebugging) {
-        Assert.invariant(optDebugger.isDefined)
-        addEventHandler(debugger)
-        state.notifyDebugging(true)
+    if (areDebugging) {
+      Assert.invariant(optDebugger.isDefined)
+      addEventHandler(debugger)
+      state.notifyDebugging(true)
+    }
+    state.dataProc.get.init(ssrd.parser)
+    doParse(ssrd.parser, state)
+    val pr = new ParseResult(this, state)
+    if (!pr.isProcessingError) {
+
+      // By the time we get here, all infoset nodes have been setFinal, all
+      // walker blocks released, and all elements walked. The one exception
+      // is that the root node has not been set final because setFinal is
+      // handled by the sequence parser and there is no sequence around the
+      // root node. So mark it as final and do one last walk to end the
+      // document.
+      state.infoset.contents(0).setFinal()
+      state.walker.walk()
+      Assert.invariant(state.walker.isFinished)
+
+      if (maybeValidationBytes.isDefined) {
+        pr.validateResult(maybeValidationBytes.get.toByteArray)
       }
-      state.dataProc.get.init(ssrd.parser)
-      doParse(ssrd.parser, state)
-      val pr = new ParseResult(this, state)
-      if (!pr.isProcessingError) {
-
-        // By the time we get here, all infoset nodes have been setFinal, all
-        // walker blocks released, and all elements walked. The one exception
-        // is that the root node has not been set final because setFinal is
-        // handled by the sequence parser and there is no sequence around the
-        // root node. So mark it as final and do one last walk to end the
-        // document.
-        state.infoset.contents(0).setFinal()
-        state.walker.walk()
-        Assert.invariant(state.walker.isFinished)
-    
-        if (maybeValidationBytes.isDefined) {
-          pr.validateResult(maybeValidationBytes.get.toByteArray)
-        }
 
-        state.output.setBlobPaths(state.blobPaths)
-      } else {
-        // failed, so delete all blobs that were created
-        state.blobPaths.foreach { path =>
-          Files.delete(path)
-        }
-        // ensure the blob paths are empty in case of outputter reuse
-        state.output.setBlobPaths(Seq.empty)
+      state.output.setBlobPaths(state.blobPaths)
+    } else {
+      // failed, so delete all blobs that were created
+      state.blobPaths.foreach { path =>
+        Files.delete(path)
       }
-      val s = state
-      val dp = s.dataProc
-      val ssrdParser = ssrd.parser
-      if (dp.isDefined) dp.value.fini(ssrdParser)
-
-      pr
+      // ensure the blob paths are empty in case of outputter reuse
+      state.output.setBlobPaths(Seq.empty)
     }
+    val s = state
+    val dp = s.dataProc
+    val ssrdParser = ssrd.parser
+    if (dp.isDefined) dp.value.fini(ssrdParser)
+
+    pr
   }
 
   private def doParse(p: Parser, state: PState): Unit = {
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/ProcessorStateBases.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/ProcessorStateBases.scala
index 9177381..525abf7 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/ProcessorStateBases.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/ProcessorStateBases.scala
@@ -497,28 +497,24 @@ abstract class ParseOrUnparseState protected (
   def notifyDebugging(flag: Boolean): Unit
 
   final def SDE(str: String, args: Any*) = {
-    // ExecutionMode.requireRuntimeMode // not any more. More code is shared between compile and runtime now, so these requirements gotta go
     val ctxt = getContext()
     val rsde = new RuntimeSchemaDefinitionError(ctxt.schemaFileLocation, this, str, args: _*)
     ctxt.toss(rsde)
   }
 
   final def SDEButContinue(str: String, args: Any*) = {
-    // ExecutionMode.requireRuntimeMode
     val ctxt = getContext()
     val rsde = new RuntimeSchemaDefinitionError(ctxt.schemaFileLocation, this, str, args: _*)
     diagnostics = rsde :: diagnostics
   }
 
   final def SDW(str: String, args: Any*) = {
-    // ExecutionMode.requireRuntimeMode
     val ctxt = getContext()
     val rsdw = new RuntimeSchemaDefinitionWarning(ctxt.schemaFileLocation, this, str, args: _*)
     diagnostics = rsdw :: diagnostics
   }
 
   final def SDW(warnID: WarnID, str: String, args: Any*) = {
-    // ExecutionMode.requireRuntimeMode
     if (tunable.notSuppressedWarning(warnID)) {
       val ctxt = getContext()
       val rsdw = new RuntimeSchemaDefinitionWarning(ctxt.schemaFileLocation, this, str, args: _*)