SOMns icon indicating copy to clipboard operation
SOMns copied to clipboard

While Primitives are not triggering, missing specialization logic?

Open smarr opened this issue 5 years ago • 0 comments

Some of following tests are failing with stack overflows. Inspection shows that the SOMns version of the while methods run, instead of the primitives:

diff --git a/core-lib/TestSuite/LanguageTests.ns b/core-lib/TestSuite/LanguageTests.ns
index 68baf641..f487c8a3 100644
--- a/core-lib/TestSuite/LanguageTests.ns
+++ b/core-lib/TestSuite/LanguageTests.ns
@@ -982,4 +982,143 @@ class LanguageTests usingPlatform: platform testFramework: minitest = Value (
       assert: #overridden2 equals: OtherScope new AnotherA new B new C new localTarget.
     )
   ) : ( TEST_CONTEXT = () )
+
+  public class WhileLoops = TestContext (
+  | private BOUND = 3000. |
+  )(
+
+    public testLiteralBlocksForTrue = (
+      | i |
+      i:: 1.
+      [ i < BOUND ] whileTrue: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralBlocksForFalse = (
+      | i |
+      i:: 1.
+      [ i >= BOUND ] whileFalse: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralReceiverAndVarArgForTrue = (
+      | i block |
+      block:: [ i:: i + 1 ].
+      i:: 1.
+      [ i < BOUND ] whileTrue: block.
+      assert: BOUND equals: i.
+    )
+
+    public testLiteralReceiverAndVarArgForFalse = (
+      | i block |
+      block:: [ i:: i + 1 ].
+      i:: 1.
+      [ i >= BOUND ] whileFalse: block.
+      assert: BOUND equals: i.
+    )
+
+    public testVarReceiverAndLiteralArgForTrue = (
+      | i block |
+      block:: [ i < BOUND ].
+      i:: 1.
+      block whileTrue: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testVarReceiverAndLiteralArgForFalse = (
+      | i block |
+      block:: [ i >= BOUND ].
+      i:: 1.
+      block whileFalse: [ i:: i + 1 ].
+      assert: BOUND equals: i.
+    )
+
+    public testVarBlocksForTrue = (
+      | i blockRcvr blockArg |
+      blockRcvr:: [ i < BOUND ].
+      blockArg:: [ i:: i + 1 ].
+      i:: 1.
+      blockRcvr whileTrue: blockArg.
+      assert: BOUND equals: i.
+    )
+
+    public testVarBlocksForFalse = (
+      | i blockRcvr blockArg |
+      blockRcvr:: [ i >= BOUND ].
+      blockArg:: [ i:: i + 1 ].
+      i:: 1.
+      blockRcvr whileFalse: blockArg.
+      assert: BOUND equals: i.
+    )
+
+    public testPolymorpicBlocksForTrue = (
+      | rcvrBlocks argBlocks j |
+      rcvrBlocks:: Array new: 10.
+      rcvrBlocks at:  1 put: [j < 3].
+      rcvrBlocks at:  2 put: [j < 3].
+      rcvrBlocks at:  3 put: [j < 3].
+      rcvrBlocks at:  4 put: [j < 3].
+      rcvrBlocks at:  5 put: [j < 3].
+      rcvrBlocks at:  6 put: [j < 3].
+      rcvrBlocks at:  7 put: [j < 3].
+      rcvrBlocks at:  8 put: [j < 3].
+      rcvrBlocks at:  9 put: [j < 3].
+      rcvrBlocks at: 10 put: [j < 3].
+
+      argBlocks:: Array new: 10.
+      argBlocks at:  1 put: [j:: j + 1].
+      argBlocks at:  2 put: [j:: j + 1].
+      argBlocks at:  3 put: [j:: j + 1].
+      argBlocks at:  4 put: [j:: j + 1].
+      argBlocks at:  5 put: [j:: j + 1].
+      argBlocks at:  6 put: [j:: j + 1].
+      argBlocks at:  7 put: [j:: j + 1].
+      argBlocks at:  8 put: [j:: j + 1].
+      argBlocks at:  9 put: [j:: j + 1].
+      argBlocks at: 10 put: [j:: j + 1].
+
+      1 to: 10 do: [:i |
+        j:: 1.
+        (rcvrBlocks at: i)
+          whileTrue:
+            (argBlocks at: i).
+        assert: 3 equals: j.
+      ].
+    )
+
+    public testPolymorpicBlocksForFalse = (
+      | rcvrBlocks argBlocks j |
+      rcvrBlocks:: Array new: 10.
+      rcvrBlocks at:  1 put: [j >= 3].
+      rcvrBlocks at:  2 put: [j >= 3].
+      rcvrBlocks at:  3 put: [j >= 3].
+      rcvrBlocks at:  4 put: [j >= 3].
+      rcvrBlocks at:  5 put: [j >= 3].
+      rcvrBlocks at:  6 put: [j >= 3].
+      rcvrBlocks at:  7 put: [j >= 3].
+      rcvrBlocks at:  8 put: [j >= 3].
+      rcvrBlocks at:  9 put: [j >= 3].
+      rcvrBlocks at: 10 put: [j >= 3].
+
+      argBlocks:: Array new: 10.
+      argBlocks at:  1 put: [j:: j + 1].
+      argBlocks at:  2 put: [j:: j + 1].
+      argBlocks at:  3 put: [j:: j + 1].
+      argBlocks at:  4 put: [j:: j + 1].
+      argBlocks at:  5 put: [j:: j + 1].
+      argBlocks at:  6 put: [j:: j + 1].
+      argBlocks at:  7 put: [j:: j + 1].
+      argBlocks at:  8 put: [j:: j + 1].
+      argBlocks at:  9 put: [j:: j + 1].
+      argBlocks at: 10 put: [j:: j + 1].
+
+      1 to: 10 do: [:i |
+        j:: 1.
+        (rcvrBlocks at: i)
+          whileFalse:
+            (argBlocks at: i).
+        assert: 3 equals: j.
+      ].
+    )
+  ) : ( TEST_CONTEXT = () )
 )

The solution for this would be to add the necessary logic into the while specializers. The specializers need to have the checks for this case, and the node creation needs to instantiate the WhileCache-nodes, I think.

smarr avatar Dec 18 '18 13:12 smarr