[swift-dev] "For" loop iterator and "enum"

Sam Ding samding at ca.ibm.com
Tue Oct 24 10:32:51 CDT 2017


It is found that "for" loop iterate and "enum" does not work on s390x.
Here is a sample code:

      enum IntKey : Int {
          case a = 3
          case b = 4 // Implicitly 4
          case c = 1
      for ( a1, a2) in [(IntKey.a, 1)] {
         print ("+++++  test \n")

The for loop  inifinitly iterates on s390x. Note that it works fine if
replacing the enum with normal tuple in the above code.
When debugging this code, after one iteration, the logic gets a "nil" in "
IndexingIterator.next()" as follows:

       frame #0: 0x000003fffd5b4088 libswiftCore.so`IndexingIterator.next
   (self=0x000003fffffff460) at Collection.swift:411
      408    @inline(__always)
      409    public mutating func next() -> Elements.Element? {
      410      if _position == _elements.endIndex {
   -> 411          return nil
      412      }
      413      let element = _elements[_position]
Then comes "Enum.cpp:211" (swift::swift_storeEnumTagSinglePayload) and no
difference  on both s390x and x86_64.
However, It continues goes into the loop body on s390x, and  terminates  on
x86_64, respectively.

Have anyones know well this implementation and give us a hint for the


Sam Ding,
Linux on z Systems  Open Source Ecosystem
IBM Toronto Lab,
email: samding at ca.ibm.com
phone: (905)413-2947
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171024/7ea04d89/attachment.html>

More information about the swift-dev mailing list