Skip to content
Tcl Source Code History Of Ticket 47ac84309bab4719
Login

History Of Ticket 47ac84309bab4719

Artifacts Associated With Ticket 47ac84309bab4719

  1. Ticket change [9ccf91e72c] (rid 142158) by aspect on 2015-06-22 03:24:10:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      in chasing [44fd4b9a4e], another edge case with compiled lreplace:
      
      <pre>% lreplace {a b c} end 0
      !! {a b c} != {a b b c}
      % lreplace {a b c} end 0 A
      !! {a b A c} != {a b A b c}</pre>
      
      
      In each case the LHS is the interpreted & incorrect answer, RHS compiled & correct.
      
      Test script:
      
      <pre>proc check {cmd} {
          puts "% $cmd"
          proc t {} $cmd
          set rc [t]
          set ri [uplevel 1 $cmd]
          if {$ri ne $rc} {
              puts "!! [list $ri != $rc]"
          } else {
              puts "ok [list $rc]"
          }
      }
      
      foreach {a} {
          0 1 2 3 end-3 end-2 end-1 end
      } {
          check [list lreplace {a b c} end $a]
          check [list lreplace {a b c} end $a a]
      }</pre>
      
    5. foundin initialized to: "trunk"
    6. is_private initialized to: "0"
    7. login: "aspect"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "aspect"
    13. subsystem initialized to: "14. List Object"
    14. title initialized to: "more (compiled) lreplace madness"
    15. type initialized to: "Bug"
  2. Ticket change [9ba87fc8cd] (rid 142162) by aspect on 2015-06-22 07:41:25:

    1. icomment:
      <p>It looks to me like compiled lreplace as currently implemented <i>cannot</i> correctly deal with indexes of differing sign (ie, one is an end-based index).
      
      <p><a href="http://core.tcl.tk/tcl/artifact/987b59004f8ac6da?ln=1592-1598">here</a> is the code responsible for the "dropRange" case.  It compiles as the equivalent of:
      
      <pre>concat [lrange $l 0 $idx1-1] [lrange $l $idx2+1 end]</pre>
      
      <p>which is fine in ordinary cases, but fails when one of the indices is <tt>end</tt>-based and <tt>$idx2 < $idx1</tt>.
      
      <p>To fix this, compiled <tt>lreplace</tt> needs to be sensitive to the length of the list it is examining.  Simplest is probably to emit bytecode for <tt>end</tt>-based indexes that does the arithmetic to make them positive.
      
      <p>Since that has to be computed on the stack, and <tt>INST_LIST_RANGE_IMM</tt> seems to need its arguments as immediates, I need advice on what bytecode instructions should be used in this case.
      
    2. login: "aspect"
    3. mimetype: "text/html"
  3. Ticket change [e6522a134c] (rid 142163) by aspect on 2015-06-22 07:43:30:

    1. icomment:
      <p>For clarity, the manual's words on <tt>$idx2 < $idx1</tt>:
      
      <p><i>If last is less than first, then any specified elements will be inserted
      into the list at the point specified by first with no elements being deleted.</i></p>
      
      <p>Clearly in the case of exactly one <tt>end</tt>-based index, this requires some computation with the length of the list.
      
    2. login: "aspect"
    3. mimetype: "text/html"
  4. Ticket change [eafccc8183] (rid 142165) by oehhar on 2015-06-22 15:39:32:

    1. comment changed to:
      in chasing [44fd4b9a4e], another edge case with compiled lreplace:
      
      <pre>% lreplace {a b c} end 0
      !! {a b c} != {a b b c}
      % lreplace {a b c} end 0 A
      !! {a b A c} != {a b A b c}</pre>
      
      
      In each case the LHS is the interpreted & correct answer, RHS compiled & incorrect.
      
      Test script:
      
      <pre>proc check {cmd} {
          puts "% $cmd"
          proc t {} $cmd
          set rc [t]
          set ri [uplevel 1 $cmd]
          if {$ri ne $rc} {
              puts "!! [list $ri != $rc]"
          } else {
              puts "ok [list $rc]"
          }
      }
      
      foreach {a} {
          0 1 2 3 end-3 end-2 end-1 end
      } {
          check [list lreplace {a b c} end $a]
          check [list lreplace {a b c} end $a a]
      }</pre>
      
    2. icomment:
      Exchanged "correct" and "incorrect" in the description.
      I hope this is correct.
      
      Harald
      
    3. login: "oehhar"
    4. mimetype: "text/x-fossil-wiki"
    5. username: "oehhar"
  5. Ticket change [7bf85accf0] (rid 142167) by msofer on 2015-06-22 17:49:07:

    1. icomment:
      Do we have a good case for compiling lreplace at all?
      
    2. login: "msofer"
    3. mimetype: "text/plain"
  6. Ticket change [0b9b03a557] (rid 142207) by aspect on 2015-06-24 13:19:00:

    1. icomment:
      I think it's safe to preserve the compilation of lreplace in simple cases:
      both index arguments known and of the same "sign".  Ferrieux has also
      advised "drastically reducing the ambition of the optimiser" in [44fd4b9a4e].
      I'm very much in agreement that falling back to the interpreted version when it
      gets difficult is the path to sanity.
      
      That, and clearly articulating the various cases.  Which is where it gets
      interesting (see also [44fd4b9a4e]):
      
      
      Compiled lreplace has supported end+1 indexing to append since at least
      8.6.3:
      
      % lreplace a 1 1 b
      a b
      % lreplace a end+1 end+1 b
      a b
      
      This isn't documented or supported by interpreted lreplace, but it seems to
      be useful.  I would like to add this to supported behaviour of [lreplace],
      complete with a decent set of tests and an example in the man page.
      
      
      As an aside, I find the below surprising .. it's documented and consistently
      implemented behaviour, but I cannot understand the motivation.
      
      % lreplace {} 2 2
      
      % lreplace 1 2 2
      list doesn't contain element 2
      
      Perhaps if anyone can come up with a good motivation for the error being
      suppressed for an empty list, I can add that to the manual too.
      
    2. login: "aspect"
    3. mimetype: "text/plain"
  7. Ticket change [819806cb5e] (rid 142228) by aku on 2015-06-24 16:35:07:

    1. icomment:
      > % lreplace {} 2 2
      >
      > % lreplace 1 2 2
      > list doesn't contain element 2
      
      > Perhaps if anyone can come up with a good motivation
      > for the error being suppressed for an empty list, I
      > can add that to the manual too.
      
      I wonder if that might be due to TIP 323 "Do nothing gracefully", i.e.
      http://tip.tcl.tk/323
      
    2. login: "aku"
    3. mimetype: "text/plain"
  8. Ticket change [d88b5988fc] (rid 142229) by dgp on 2015-06-24 17:20:41:

    1. icomment:
      
      No. that disparity was in place long before TIP 323:
      
      % info patch
      8.0.3
      % lreplace {} 2 2
      % lreplace 1 2 2
      list doesn't contain element 2
      
      
      But curiously not in Tcl 7:
      
      % info patch
      7.6p2
      % lreplace {} 2 2
      list doesn't contain element 2
      % lreplace 1 2 2
      list doesn't contain element 2
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  9. Ticket change [513887c0c6] (rid 142230) by aku on 2015-06-24 18:04:16:

    1. icomment:
      So, then likely a bug introduced with the bytecode compiler.
      
    2. login: "aku"
    3. mimetype: "text/plain"
  10. Ticket change [448963a718] (rid 142231) by dgp on 2015-06-24 18:44:01:

    1. icomment:
      
      No, [lreplace] was did not become a bytecode compiled
      command until Tcl 8.6.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  11. Ticket change [c3a62e2c31] (rid 142232) by aspect on 2015-06-25 03:16:29:

    1. icomment:
      Empty-list behaviour was first documented in [ae7e3132d3602091], which references "bug #1705" from 2000.  I can't find bug #1705, but the behaviour has existed since the beginning of available history [http://core.tcl.tk/tcl/artifact/7969e2e65bb3ab96?ln=2239]?  I guess that's not changing!
      
      While spelunking for that I discovered another argument for end+1 indexing.  [linsert] has also usefully supported it for a long time:
      
      % linsert 1 2 d
      1 d
      
    2. login: "aspect"
    3. mimetype: "text/x-fossil-wiki"
  12. Ticket change [8f6ce6e692] (rid 142280) by dgp on 2015-06-25 14:25:39:

    1. icomment:
      
      "bug #1705" is now
      
      http://core.tcl.tk/tcl/tktview/218675
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  13. Ticket change [16153c39eb] (rid 142294) by aspect on 2015-06-29 12:31:43:

    1. icomment:
      Finally had a chance to be confident enough with my results to commit and push:
      see branch "aspect-lreplace-cleanup" in
      http://chiselapp.com/user/aspect/repository/tcl/timeline
      
      It's not very tidy I'm afraid as donuts are interfering, but a quick précis:
      
      [0c4a83c31e] fixes the bug raised in this ticket (without introducing a test - oops)
      
      [b820489dec] is a new empty-list bug fixed with a test case introduced in 355706aa97
      
      [0f2c6bc9a8] modifies both compiled and interpreted lreplace to allow appending.
      This might still be controversial :-).
      
      [0586ceac09] introduces a "test battery" enumerating over a set of small list
      cases ensuring compiled and interpreted both agree with a reference
      implementation, for a total of about 1200 "mostly free" tests.  It's not at
      all integrated with tcltest, so failures aren't reported usefully for
      downstreams to submit, but was tremendously helpful in this exercise.
      
      
      I hope all but [0f2c6bc9a8] (lreplace can append) and the associated test change 
      should be easy to accept, or at least beat into shape.  I'm a little less sure
      this one is a good idea recalling now that {[string replace foo 3 3 bar] == "foo"}.
      
    2. login: "aspect"
    3. mimetype: "text/plain"
  14. Ticket change [2b52b40ac9] (rid 142941) by dkf on 2015-08-30 20:25:06:

    1. assignee changed to: "dkf"
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. priority changed to: "8"
    5. severity changed to: "Important"
  15. Ticket change [ac56e37c69] (rid 143907) by aspect on 2015-11-17 08:28:04:

    1. icomment:
      See also [578c2fd960].
      
      Ping?  I could use some feedback on how the
      aspect-lreplace-cleanup branch can be brought into
      a state suitable for merging.
      
    2. login: "aspect"
    3. mimetype: "text/plain"
  16. Ticket change [9d147fec96] (rid 146003) by dkf on 2016-03-27 15:38:42:

    1. icomment:
      Hmm, I can't read that repository right now; chiselapp is having one of its periodic conniptions.
      
    2. login: "dkf"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "dkf"
  17. Ticket change [bbe226066b] (rid 146013) by dkf on 2016-03-27 16:39:06:

    1. icomment:
      Disabled compilation in these cases. Fixing it while keeping everything compiled will require a totally different strategy, probably with new bytecodes.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  18. Ticket change [28c127b5fb] (rid 146014) by dkf on 2016-03-27 16:39:34:

    1. login: "dkf"
    2. mimetype: "text/plain"
    3. priority changed to: "4"
    4. severity changed to: "Minor"
  19. Add attachment "aspect-lreplace-cleanup.bundle" [c97c5b3286] (rid 146023) by anonymous on 2016-03-28 00:26:05.

  20. Ticket change [d561a93539] (rid 146064) by dkf on 2016-03-30 08:52:39:

    1. icomment:
      I've now imported the changes from the <a href="http://chiselapp.com/user/aspect/repository/tcl/timeline?n=100&r=aspect-lreplace-cleanup">branch on aspect's chiselapp repository</a> into the main Tcl repository, where they are more visible (same name of branch; changes just the total ones <i>except</i> that the bulk testing is done a little bit differently).<p>They change some existing behaviour so they need a bit wider review than just me, though I'm minded to go with them.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  21. Ticket change [0f11a6b0c2] (rid 146180) by dkf on 2016-04-04 21:43:02:

    1. closedate changed to: "2457483.40489382"
    2. closer changed to: "dkf"
    3. icomment:
      OK, everything should be fixed. I might wish to revisit and reconsider how we compile <code>lreplace</code>, but that'll be entirely new work centred around doing the whole job, and it might only get done in Tcl 9.<p>Thanks to Alexandre Ferrieux for his assistance with reviewing.
      
    4. login: "dkf"
    5. mimetype: "text/html"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dkf"