Skip to content

[SE-0408] Enable Pack Iteration #67594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 8, 2023

Conversation

simanerush
Copy link
Member

@simanerush simanerush commented Jul 28, 2023

This is the implementation of this SE-0408.

What's working

  • Generate and apply constraints
  • Verify AST
  • Emit valid SIL
  • Interpret

Supported

Design

  • Use TaggedUnion for representing ForEachStmtInfo, where it can either be SequenceIterationInfo or the new PackIterationInfo.
  • Add new logic in CSGen/CSApply for handling the pack iteration case.
  • The bulk of the logic is in SILGenStmt: it handles constructing the loop from a pack expansion expression

@simanerush simanerush force-pushed the simanerush/pack-iteration-impl branch 2 times, most recently from 4b1b8c5 to 1fcb8da Compare August 10, 2023 06:54
@simanerush simanerush marked this pull request as ready for review August 10, 2023 06:54
@simanerush simanerush changed the title [Variadic Generics][WIP] Enable Pack Iteration [Variadic Generics] Enable Pack Iteration pt.1 Aug 10, 2023
@simanerush simanerush force-pushed the simanerush/pack-iteration-impl branch from 1fcb8da to 42a4340 Compare August 10, 2023 18:36
@simanerush simanerush requested a review from tshortli as a code owner August 10, 2023 18:36
@simanerush simanerush changed the title [Variadic Generics] Enable Pack Iteration pt.1 [Variadic Generics] Enable Pack Iteration Aug 16, 2023
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, I left a few comments line.

@simanerush simanerush requested a review from xedin December 3, 2023 21:27
@simanerush simanerush force-pushed the simanerush/pack-iteration-impl branch from bf57556 to 48cb330 Compare December 4, 2023 05:51
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AST/Sema changes look great to me, thank you!

@simanerush
Copy link
Member Author

@swift-ci Please smoke test

@simanerush
Copy link
Member Author

@swift-ci please test source compatibility

@AnthonyLatsis
Copy link
Collaborator

Are we fine with merging that last joint commit with this PR? Why did we need it here in the first place?

@hborla
Copy link
Member

hborla commented Dec 7, 2023

Yes please do! It's a latent bug that manifested in one of Sima's test cases IIRC. The bug fix isn't really relevant to the PR I originally included it in (the same-element requirement PR) other than I also hit the issue in one of the test cases there.

Comment on lines +1258 to +1261
JumpDest loopDest = createJumpDest(S->getBody());

// Set the destinations for 'break' and 'continue'.
JumpDest endDest = createJumpDest(S->getBody());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think loopDest and endDest would be far clearer as continueDest and breakDest for anyone yet to read this. Just an opinion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw this. I think this makes a lot of sense, thank you!

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in fantastic shape, thank you for your work on this feature! The review discussion above is very focused in on details, targeted bug fixes (e.g. adding a diagnosis for where clauses during constraint generation), improvements to documentation, etc, and this patch is already quite large, so I suggest landing this as is and addressing further feedback in subsequent PRs. This will help make more incremental progress, and it'll make the subsequent changes easier to review.

@simanerush simanerush merged commit b6d0afb into swiftlang:main Dec 8, 2023
@simanerush simanerush deleted the simanerush/pack-iteration-impl branch December 8, 2023 01:10
@finagolfin
Copy link
Member

This pull broke the community Android CI, maybe because a host Swift compiler isn't available there and so SWIFT_BUILD_SWIFT_SYNTAX is not enabled?

[1467/1974][ 74%][1115.143s] Building swift module SIL
FAILED: bootstrapping1/SwiftCompilerSources/SIL.o /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/SIL.o
cd /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources && /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/bin/swiftc -c -o /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/SIL.o -I /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/bin/../lib -I /usr/lib -target x86_64-unknown-linux-gnu -module-name SIL -emit-module -emit-module-path /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/SIL.swiftmodule -parse-as-library /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/ApplySite.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Argument.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/BasicBlock.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Builder.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Effects.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/ForwardingInstruction.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Function.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/GlobalVariable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Instruction.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Location.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Operand.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Registration.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/SILStage.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/SubstitutionMap.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Type.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Value.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/VTable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/WitnessTable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/SequenceUtilities.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/SmallProjectionPath.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/WalkUtils.swift -wmo -color-diagnostics -Xfrontend -validate-tbd-against-ir=none -Xfrontend -enable-experimental-cxx-interop -Xfrontend -disable-target-os-checking -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT -Xcc -DSWIFT_TARGET -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -Xfrontend -disable-implicit-string-processing-module-import -O -cross-module-optimization -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/llvm-project/llvm/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/llvm-linux-x86_64/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/llvm-project/clang/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/llvm-linux-x86_64/tools/clang/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/SwiftCompilerSources/../include -I /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources
<unknown>:0: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
<unknown>:0: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported
<unknown>:0: warning: unable to perform implicit import of "_Concurrency" module: no such module found
swift-frontend: /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/lib/AST/GenericEnvironment.cpp:410: static swift::Type swift::GenericEnvironment::mapTypeIntoContext(swift::GenericEnvironment *, swift::Type): Assertion `(env || !type->hasTypeParameter()) && "no generic environment provided for type with type parameters"' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/bin/swift-frontend -frontend -c /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/ApplySite.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Argument.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/BasicBlock.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Builder.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Effects.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/ForwardingInstruction.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Function.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/GlobalVariable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Instruction.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Location.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Operand.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Registration.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/SILStage.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/SubstitutionMap.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Type.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Value.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/VTable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/WitnessTable.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/SequenceUtilities.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/SmallProjectionPath.swift /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/SwiftCompilerSources/Sources/SIL/Utilities/WalkUtils.swift -supplementary-output-file-map /tmp/supplementaryOutputs-aa0ce4 -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/bin/../lib -I /usr/lib -I /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources -color-diagnostics -O -validate-tbd-against-ir=none -enable-experimental-cxx-interop -disable-target-os-checking -disable-implicit-string-processing-module-import -plugin-path /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/lib/swift/host/plugins -plugin-path /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping0/local/lib/swift/host/plugins -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT -Xcc -DSWIFT_TARGET -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/llvm-project/llvm/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/llvm-linux-x86_64/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/llvm-project/clang/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/llvm-linux-x86_64/tools/clang/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/include -Xcc -I -Xcc /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/SwiftCompilerSources/../include -parse-as-library -module-name SIL -cross-module-optimization -o /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/SIL.o
1.      Swift version 5.11-dev (LLVM 91cd37b9110872c, Swift b6d0afba1f0e044)
2.      Compiling with the current language version
3.      While walking into body of '__operatorSubscript(_:)' (in module '__ObjC')
4.      While verifying VarDecl 'index' (in module '__ObjC')

@hborla
Copy link
Member

hborla commented Dec 8, 2023

Thanks @finagolfin, I reproduced the issue locally and I'm investigating it. Here's the symbolicated stack trace:

1.	Swift version 5.11-dev (LLVM a2fd6a345facc7e, Swift d36173aa3c2da7d)
2.	Compiling with the current language version
3.	While walking into body of '__operatorSubscriptConst(_:)' (in module '__ObjC')
4.	While verifying VarDecl 'index' (in module '__ObjC')
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001058a98e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001058a7f48 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001058a9f38 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018382a584 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001837f9c28 pthread_kill + 288
5  libsystem_c.dylib        0x0000000183705a20 abort + 180
6  libsystem_c.dylib        0x0000000183704d10 err + 0
7  swift-frontend           0x0000000105f5c290 swift::GenericEnvironment::mapTypeIntoContext(swift::GenericEnvironment*, swift::Type) (.cold.4) + 0
8  swift-frontend           0x0000000101975a00 swift::GenericEnvironment::mapTypeIntoContext(swift::Type) const + 0
9  swift-frontend           0x00000001017b12b8 (anonymous namespace)::Verifier::verifyChecked(swift::VarDecl*) + 176
10 swift-frontend           0x00000001017a1654 (anonymous namespace)::Verifier::walkToDeclPost(swift::Decl*) + 3256
11 swift-frontend           0x00000001017b2fa8 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 316
12 swift-frontend           0x00000001017b6654 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 376
13 swift-frontend           0x00000001017b5560 (anonymous namespace)::Traversal::visit(swift::Decl*) + 140
14 swift-frontend           0x00000001017b2f90 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 292
15 swift-frontend           0x00000001017b2e60 swift::Decl::walk(swift::ASTWalker&) + 32
16 swift-frontend           0x000000010179e8e0 swift::verify(swift::Decl*) + 208
17 swift-frontend           0x00000001014e065c swift::ClangImporter::verifyAllModules() + 456
18 swift-frontend           0x00000001016ec910 swift::ASTContext::verifyAllLoadedModules() const + 84

SwiftCompilerSources currently use bootstrapping on macOS CI, so I'm not sure what the difference is, but I don't think it's related to SWIFT_BUILD_SWIFT_SYNTAX.

@bnbarham
Copy link
Contributor

bnbarham commented Dec 8, 2023

SwiftCompilerSources currently use bootstrapping on macOS CI

Just to clarify, macOS CI uses bootstrap-with-hostlibs vs Android which is using full bootstrap, so there could possibly be a difference there.

@hborla
Copy link
Member

hborla commented Dec 8, 2023

I filed #70328 to track this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for-in loops Feature: for-in loops parameter packs Feature → generics: Parameter packs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants