Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-06-12
16:20 • Closed ticket [9a2351225c]: 32-bit build broken (test lseq-bug-54329e39c7 fails)... artifact: 147bf1ddc2 user: jan.nijtmans
2025-06-06
13:35 • Ticket [9a2351225c]: 3 changes artifact: e7b562eab2 user: dkf
08:56 • Ticket [9a2351225c]: 3 changes artifact: f7a137b2ed user: jan.nijtmans
08:44 • Pending ticket [9a2351225c]. artifact: b3496dd1d5 user: dkf
08:39
[9a2351225c] Alternate, portable way of testing for [foreach] and [lseq] interacting badly check-in: ed591cc6bb user: dkf tags: trunk, main
2025-06-05
14:59 • Ticket [9a2351225c] 32-bit build broken (test lseq-bug-54329e39c7 fails) sta... artifact: 22ded25e65 user: dkf
13:47 • Ticket [9a2351225c]: 3 changes artifact: e6cbec9e3c user: apnadkarni
08:47 • Ticket [9a2351225c]: 3 changes artifact: 8d1f59f627 user: dkf
08:02 • Ticket [9a2351225c]: 3 changes artifact: c00ba77790 user: dkf
08:00 • Ticket [9a2351225c]: 3 changes artifact: 05e8d8987c user: dkf
07:56 • Ticket [9a2351225c]: 3 changes artifact: e978ab23d1 user: jan.nijtmans
07:55 • Ticket [9a2351225c]: 3 changes artifact: 5cc281bb89 user: jan.nijtmans
2025-06-04
15:39 • Ticket [9a2351225c]: 3 changes artifact: b713fb4153 user: apnadkarni
13:54 • Ticket [9a2351225c]: 4 changes artifact: eb44b46c13 user: dkf
13:52 • Ticket [9a2351225c]: 3 changes artifact: 5668c45590 user: dkf
11:01 • Ticket [9a2351225c]: 3 changes artifact: d9c2698fa1 user: dkf
10:05 • Ticket [9a2351225c]: 3 changes artifact: 6edb90e03e user: jan.nijtmans
10:02 • Ticket [9a2351225c]: 3 changes artifact: 33d620c981 user: dkf
10:00 • Ticket [9a2351225c]: 3 changes artifact: 382c9e8fb3 user: apnadkarni
09:56 • Ticket [9a2351225c]: 3 changes artifact: f1b3b7582c user: dkf
09:55 • Ticket [9a2351225c]: 3 changes artifact: 9d162b01a0 user: apnadkarni
09:15 • Ticket [9a2351225c]: 3 changes artifact: 63b95cef4f user: dkf
09:00 • Ticket [9a2351225c]: 3 changes artifact: 59fa2226b2 user: dkf
08:45 • Ticket [9a2351225c]: 3 changes artifact: 07702d216f user: jan.nijtmans
08:10 • Ticket [9a2351225c]: 3 changes artifact: 605a050961 user: dkf
08:07 • Ticket [9a2351225c]: 3 changes artifact: 8ba00c0166 user: dkf
06:21 • Ticket [9a2351225c]: 3 changes artifact: 51bb0390ad user: apnadkarni
05:57 • Ticket [9a2351225c]: 3 changes artifact: 09ddd7df33 user: apnadkarni
2025-06-03
17:27 • Ticket [9a2351225c]: 4 changes artifact: 4d6cd0a74c user: jan.nijtmans
16:48
Proposed fix for [9a2351225c]: 32-bit build broken No longer needed closed check-in: 2456cb07e8 user: jan.nijtmans tags: bug-9a2351225c
16:34 • New ticket [9a2351225c] 32-bit build broken. artifact: b117645985 user: jan.nijtmans

32-bit build broken (test lseq-bug-54329e39c7 fails)

Closed / Fixed9a2351225c77fb4a90cf23ade237414b4f199361Created 2 years agoUpdated 1 year ago
Descriptionwiki2025-06-03 16:34:05
See: https://github.com/tcltk/tcl/actions/runs/15411189741

Breakage appears to start with [this] commit: Upgrade \[lappend\] so it bytecode compiles directly with expansion of arguments

Referenced by2
  • ed591cc6bb[9a2351225c] Alternate, portable way of testing for [foreach] and [lseq] interacting badly check-in2025-06-06 08:39:54
  • 2456cb07e8Proposed fix for [9a2351225c]: 32-bit build broken No longer needed check-in2025-06-03 16:48:41
jan.nijtmanswiki2025-06-03 17:27:48

Proposed fix [here], simply by reverting the commit that caused it.

Can be re-applied after the problem is fixed.

apnadkarniplain2025-06-04 05:57:48
(moved from duplicate ticket)

Github CI shows the following test failure:

```
 ==== lseq-bug-54329e39c7 does not cause memory bloat FAILED
==== Contents of test case:

    set l [lseq 1000000]
    proc p l {foreach x $l {}}
    set premem [memusage]
    p $l
    set postmem [memusage]
    expr {[string match *purify* [tcl::build-info]] || ($postmem - $premem < 10) ? 1 : ($postmem - $premem)}

---- Result was:
36
---- Result should have been (exact matching):
1
==== lseq-bug-54329e39c7 FAILED
```

The configuration it fails on is Linux gcc `configure CFLAGS=-m32 CPPFLAGS=-m32 LDFLAGS=-m32 --disable-64bit`. Other Linux configurations are aborted when this run fails so it is not clear if they would also fail.

The failures started happening somewhere after [0ae5d5f12e847c50](https://core.tcl-lang.org/tcl/info/0ae5d5f12e847c50). Unfortunately since fossil->github CI updates are batched, and I cannot reproduce the failure on my system, I cannot tell when it started happening.

It is also possible that the test itself is flawed. It checks for increase in memory usage and it is possible the new byte code uses a little more than expected on this test. But that is pure speculation on my part.
apnadkarni Ticket [9a2351225c]: 3 changes [History diff]2025-06-04 06:21:21
dkfmarkdown2025-06-04 08:07:24

The problem is more likely in the INST_LAPPEND_LIST implementation, which that code causes to become more exercised.

dkfmarkdown2025-06-04 08:10:44

OTOH, why is a change to the lappend compiler causing a memory leak in code that doesn't (appear) to call that command?! That makes no sense...

jan.nijtmanswiki2025-06-04 08:45:33

@dkf, do you have (or can you work on) a better fix? trunk shouldn't be in the broken state for more than a few days.

dkfmarkdown2025-06-04 09:00:45

Have you confirmed that that commit fixes anything? I don't see that tag being run. (I also cannot run locally in that mode.)

dkfmarkdown2025-06-04 09:15:41

Hmm, the memusage command called by that test has a resource leak. The fd is never closed.

apnadkarniplain2025-06-04 09:55:41
dkf> OTOH, why is a change to the `lappend` compiler causing a memory leak in code that doesn't (appear) to call that command?! That makes no sense...

Yes, that is exactly what I wondered too. Also, it may not be a memory *leak* per se but rather more memory used (that gets freed eventually when the lseq goes out of scope). Iirc, it internally builds a Tcl_Obj array on a Tcl_ListObjGetElements call. That test was intended to ensure that does not happen on simple iteration. It's hard to see why lappend compilation changes would cause that to happen.

dkf> Have you confirmed that that commit fixes anything? I don't see that tag being run. 

I guess that tag was pushed too late for the current CI runs. The first CI run that failed included multiple fossil commits so difficult to tell immediately which one caused the failure. It is possible one of the other check-ins in that run caused the failure. I guess we will know after the next set of runs.
dkfmarkdown2025-06-04 09:56:01

Without knowing the page size, it's hard to say just how much is used extra. Or if that's a problem. (At a guess, it might be deciding to convert the arith-series to a base list, but I don't see why. Checking for that would be easy to add to the test.)

But I'm very concerned that you're blaming changes to lappend for alterations in memory usage of code that doesn't touch that command, especially without evidence that the backout of the change you're blaming resolves the problem (because those builds just aren't even being scheduled to run despite having what appears to be the right tag). I just don't see how that commit could possibly cause this; it makes no sense at all.

apnadkarniplain2025-06-04 10:00:43
The only other significant commit in prior to the breakage is the TIP 716 merge but it's even harder to imagine how that might have broken that test!
dkfmarkdown2025-06-04 10:02:36

Ah, I see what the problem is. We've hit the usage limits.

I'm going to have to disable most workflow jobs, especially on Windows, to free up resources for future testing. You have been told about this before. Only Linux may have large numbers of jobs, precisely because it is the cheapest option.

jan.nijtmanswiki2025-06-04 10:05:04

I prefer a 'real' solution over a simple backout. But if the trunk stays 'broken' for more than a few days, we have to do something.

It makes no sense to me either.

I don't know why the 'core-*' tags didn't build. That would have given proof which commit was to 'blame'

dkfmarkdown2025-06-04 11:01:20

I completely agree that this is serious. I'm just stuck on 64-bit Windows where I really cannot run that config myself. ;-)

Assuming I've not made a catastrophic blunder, I've turned down the size of the build matrices for the tags, which will start to recover resources. (Computed build matrices are a new departure for me.)


Evidence that I do have:

% eval {
    set l [lseq 1000000]
    proc p l {foreach x $l {}}
}
% repr $l
value is a arithseries with a refcount of 4, object pointer at 0x23b521a96b8, internal representation 0x23b521a97b8:0x0, no string representation
% memory info
total mallocs                 171310
total frees                   157962
current packets allocated      13348
current bytes allocated       873015
maximum packets allocated      13580
maximum bytes allocated       913761

% p $l
% repr $l
value is a arithseries with a refcount of 4, object pointer at 0x23b521a96b8, internal representation 0x23b521a97b8:0x0, no string representation
% memory info
total mallocs                3173083
total frees                  3159678
current packets allocated      13405
current bytes allocated       876104
maximum packets allocated      13580
maximum bytes allocated       913761

% proc p2 l {foreach x $l {set y [memory info]};return $y}
% p2 $l
total mallocs              148173686
total frees                148160185
current packets allocated      13501
current bytes allocated       880819
maximum packets allocated      13580
maximum bytes allocated       913761

% unset l
% memory info
total mallocs              148174291
total frees                148160792
current packets allocated      13499
current bytes allocated       881069
maximum packets allocated      13580
maximum bytes allocated       913761

This shows that we're not getting excess memory usage at least on this platform.

dkfmarkdown2025-06-04 13:52:58

Looking at what the failing test does, reworking to use memory info is probably the best option anyway. The test is looking to verify that foreach doesn't force an arithmetic series object to fully instantiate... which is good, but it's doing it by using a proxy measure that could be confounded by other effects, to which it thus becomes very sensitive. The fact that it's using [tcl::build-info purify] as a condition to make the test meaningless is a sign that things are not healthy.


The proof that there's nothing bad happening in the interaction between foreach and lseq is in this (with p1 and p2 pre-declared/executed to ensure the bytecode's already there):

% proc p1 l {foreach x $l {}}
% proc p2 l {foreach x [list 0 {*}$l] {}}
% p1 1
% p2 1
% memory info
total mallocs                 146292
total frees                   133476
current packets allocated      12816
current bytes allocated       818998
maximum packets allocated      13019
maximum bytes allocated       853114

% p1 [lseq 1 1000000]; memory info
total mallocs                3146737
total frees                  3133899
current packets allocated      12838
current bytes allocated       820140
maximum packets allocated      13019
maximum bytes allocated       853114

% p2 [lseq 1 1000000]; memory info
total mallocs                6147179
total frees                  6134325
current packets allocated      12854
current bytes allocated      9201511
maximum packets allocated    3012872
maximum bytes allocated    141202167

Notably, the expansion of the sequence to make a standard list (plus one element) results in a vastly higher peak memory usage, as expected.

And I'm concerned that there's so much memory still allocated in this case. There appears to be a leak!

dkf Ticket [9a2351225c]: 4 changes [History diff]2025-06-04 13:54:40
apnadkarniplain2025-06-04 15:39:49
@dkf - trying your p1/p2 with a valgrind build shows no memory leaks, and no difference between 9.0.1 and the trunk. So I don't think it is a leak in terms of lost memory. Nevertheless, that max memory allocated is strange because even if the lseq fully instantiated, it should not go THAT high even if the string form has to be generated along the way. As an aside, there are several places in the TEBCresume where abstract lists are instantiated via TclListObjElements where they need not be; it's on my todo list once things settle down.

The other mildly curious thing is that the 64-bit runs do not fail (well, they are aborted because the 32-build failed but logs show they ran successfully). Of course, memory management in 64-bit could be quite different.
jan.nijtmansplain2025-06-05 07:55:59
Building now gives:
<pre>
Invalid workflow file: .github/workflows/win-build.yml#L122
The workflow is not valid. .github/workflows/win-build.yml (Line: 122, Col: 17): Unrecognized named-value: 'need'. Located at position 10 within expression: fromJson(need.plan.outputs.gcc) .github/workflows/win-build.yml (Line: 122, Col: 17): Unexpected value '${{ fromJson(need.plan.outputs.gcc) }}'
</pre>
jan.nijtmanswiki2025-06-05 07:56:47

Building now gives:

Invalid workflow file: .github/workflows/win-build.yml#L122
The workflow is not valid. .github/workflows/win-build.yml (Line: 122, Col: 17): Unrecognized named-value: 'need'. Located at position 10 within expression: fromJson(need.plan.outputs.gcc) .github/workflows/win-build.yml (Line: 122, Col: 17): Unexpected value '${{ fromJson(need.plan.outputs.gcc) }}'

dkfmarkdown2025-06-05 08:00:06

@apnadkarni p2 is designed to force things to a list; by comparing it with p1, I can see that p1 isn't converting. The number of allocs is going to be large in both cases because there's all those temporary items for the members of the sequence, but they should all be released again and cause no problems.

I'm much more concerned by the "current bytes allocated" figure in the p2 case; the memory (either from the sequence or its copy) shouldn't be still being held. OTOH, it's strictly beyond the scope of the original test. New test case?

Out of scope of this issue.

I think we can rewrite the failing test to use memory info and get a more reliable result that works across all platforms and doesn't have that "interesting" purify exception. I suspect we'll need to run it in a subprocess for that to really work, as we're not just interested in leaks but also in peak allocations.

dkfplain2025-06-05 08:02:48
@jan.nijtmans Fixed.
dkfmarkdown2025-06-05 08:47:10

I've suggested an alternate test here: branch: lseq-no-bloat-test. It uses the peak memory usage data out of memory info in a fresh interpreter, so it should be pretty reliable (and not sensitive to the OS). If I alter the code to force a conversion of the sequence to a list (à la p2) then it shows up very visibly.

apnadkarniplain2025-06-05 13:47:32
I am ok with the alternate test if you think it is more suitable. My preference for statm was simply because it did not require a --enable-symbols=mem build. On the other hand, as you say it is platform specific so there's that.

I'm still mystified as to why it triggered though...
dkfmarkdown2025-06-05 14:59:54

I'm still mystified as to why it triggered though...

It's a puzzler to me too.

About the only possibility I can think of would be if things somehow triggered a new tranche of underlying memory blocks to be allocated for Tcl_Alloc and/or TclStackAlloc, but if that's what's being seen then it's small wonder that it isn't triggering for 64-bit (which probably uses different block sizes). I don't know if that fits the description of there being 36 more pages in use; I don't even know how much space 36 pages is on that system.

But if that's it, then it's not a bug and not indicative of the lseq failure the test is looking for, which shows up as needing space for a million new Tcl_Obj instances (minimum 24MB on 32-bit systems). I certainly don't believe that pages are as large as 650kB on any system deployed anywhere...

dkfmarkdown2025-06-06 08:44:45

I believe this is now resolved... by changing how we do that test to use the peak memory usage field from memory info; that's more stable, and runs on more platforms.

The fundamental problem was I couldn't correlate a 36 page increase in memory usage to anything in the changes between a passing and failing test. It was all too far into the realm of "I guess that's maybe not a bug". It sure wasn't due to allocating array of a million pointers to back a list...

jan.nijtmanswiki2025-06-06 08:56:41

Run case "$GITHUB_REF_NAME" in
  case "$GITHUB_REF_NAME" in
    "main" | "core-9-0-branch")
      cat >>$GITHUB_OUTPUT <<'EOF'
      gcc=<<'EOJ'
      {
        "config": [
          "",
          "CFLAGS=-DTCL_NO_DEPRECATED=1",
          "--disable-shared",
          "--disable-zipfs",
          "--enable-symbols",
          "--enable-symbols=mem",
          "--enable-symbols=all",
          "CFLAGS=-ftrapv",
          "CFLAGS=-m32 CPPFLAGS=-m32 LDFLAGS=-m32 --disable-64bit"
        ]
      }
      EOJ
      EOF
      ;;
    *)
      cat >>$GITHUB_OUTPUT <<'EOF'
      gcc=<<'EOJ'
      {
        "config": [
          "",
          "--enable-symbols=all",
          "CFLAGS=-m32 CPPFLAGS=-m32 LDFLAGS=-m32 --disable-64bit"
        ]
      }
      EOJ
      EOF
      ;;
  esac
  shell: /usr/bin/bash -e {0}
/home/runner/work/_temp/e2249492-f7ea-4ba7-9b51-9b9f2394f87a.sh: line 34: warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
/home/runner/work/_temp/e2249492-f7ea-4ba7-9b51-9b9f2394f87a.sh: line 35: syntax error: unexpected end of file
Error: Process completed with exit code 2.

dkfmarkdown2025-06-06 13:35:33

I was already fixing that. It's now sorted (and tested in a private repo, so I know it work).

jan.nijtmans Closed ticket [9a2351225c]. [History diff]2025-06-12 16:20:52
Log in (anonymous is fine) to add a comment.