Skip to content

Enable mem2reg of enum types #65085

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 2 commits into from
Apr 14, 2023
Merged

Conversation

meg-gupta
Copy link
Contributor

Previously it was disabled because we have incomplete address lifetimes for such types,
and transforming to value form in mem2reg would expose verification errors due to incompleteness.

Enable this case here and fixup the lifetimes using the new lifetime completion utility.

if (asi->getType().isOrHasEnum()) {
for (auto it : initializationPoints) {
auto *si = it.second;
auto src = si->getOperand(0);
Copy link
Contributor

@nate-chandler nate-chandler Apr 11, 2023

Choose a reason for hiding this comment

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

Should [a function extracted from--no need to find the block, only to find the appropriate value to use] StackAllocationPromoter::getLiveOutValues(_, it.first) be used here to find the lexical borrows or moves that may have been introduced?

Copy link
Contributor Author

@meg-gupta meg-gupta Apr 12, 2023

Choose a reason for hiding this comment

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

Lifetime completion will work on the inner borrows. But looks like it doesn't for inner moves (or any other forwarding consumes). Also lifetime completion of lexical values (move_value [lexical]) is only possible at the unreachable blocks, what we really need is lifetime completion at the boundary in this case in mem2reg. Looks like some additional work is needed here..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to wait for @atrick's comment here about the lifetime completion utility's use in this case.

@nate-chandler Until then, I have disabled this for lexical stack locs.

Copy link
Contributor

Choose a reason for hiding this comment

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

@meg-gupta @nate-chandler For the record...
Lifetime completion only handles inner scopes that might affect the lifetime of the outer scope. It doesn't make sense for lifetime completion to look past any consumes.
This will, however, change when we fully support a mark_dependence where an owned value depends on a borrow scope. To handle that, we'll need to look through all potentially forwarding consumes. The final destroy will need to be within the borrow scope. That change only affects cases where such a mark_dependence exists

@meg-gupta meg-gupta force-pushed the mem2regenableoptional branch from f7b443f to 70069f9 Compare April 12, 2023 19:24
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

Needs #65074 to be merged

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci please benchmark

@meg-gupta
Copy link
Contributor Author

@swift-ci Please Apple Silicon benchmark

Previously it was disabled because we have incomplete address lifetimes for such types,
and transforming to value form in mem2reg would expose verification errors due to incompleteness.

Enable this case here and fixup the lifetimes using the new lifetime completion utility.
@meg-gupta meg-gupta force-pushed the mem2regenableoptional branch from 70069f9 to 96a6d44 Compare April 13, 2023 22:51
@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 2c084d8 into swiftlang:main Apr 14, 2023
@compnerd
Copy link
Member

compnerd commented Apr 14, 2023

I think that this might be causing problems on the Windows builds:

cmd.exe /C "cd . && D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -target x86_64-unknown-windows-msvc -j 2 -num-threads 2 -emit-library -o bin\Workspace.dll -module-name Workspace -module-link-name Workspace -emit-module -emit-module-path swift\Workspace.swiftmodule -emit-dependencies -DWorkspace_EXPORTS -sdk D:\a\swift-build\swift-build/BuildRoot/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -O -swift-version 5 -libc MD -Xcc -D_CRT_SECURE_NO_WARNINGS -output-file-map Sources\Workspace\CMakeFiles\Workspace.dir\Release\output-file-map.json -I D:\a\swift-build\swift-build\BinaryCache\swift-package-manager\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-tools-support-core\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-system\swift -I D:\a\swift-build\swift-build\SourceCache\swift-system\Sources\CSystem\include -I D:\a\swift-build\swift-build\BinaryCache\swift-collections\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-crypto\swift -I D:\a\swift-build\swift-build\SourceCache\swift-crypto\Sources\CCryptoBoringSSL\include -I D:\a\swift-build\swift-build\BinaryCache\swift-certificates\swift -I D:\a\swift-build\swift-build\BinaryCache\swift-asn1\swift @CMakeFiles\Workspace.rsp    -Xlinker -implib:lib\Workspace.lib  && cd ."
Assertion failed: pai && pai->isOnStack(), file C:\a\swift-build\swift-build\SourceCache\swift\include\swift/SIL/OwnershipUseVisitor.h, line 295
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: D:\\a\\swift-build\\swift-build\\BuildRoot\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe -frontend -c D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\CheckoutState.swift -primary-file D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\DefaultPluginScriptRunner.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\Diagnostics.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\FileSystemPackageContainer.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\InitPackage.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\ManagedArtifact.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\ManagedDependency.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\RegistryPackageContainer.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\ResolvedFileWatcher.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\ResolverPrecomputationProvider.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\SourceControlPackageContainer.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\ToolsVersionSpecificationRewriter.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\Workspace.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\Workspace+BinaryArtifacts.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\Workspace+Configuration.swift D:\\a\\swift-build\\swift-build\\SourceCache\\swift-package-manager\\Sources\\Workspace\\Workspace+State.swift -emit-module-path Sources\\Workspace\\CMakeFiles\\Workspace.dir\\DefaultPluginScriptRunner.swift.swiftmodule -emit-module-doc-path Sources\\Workspace\\CMakeFiles\\Workspace.dir\\DefaultPluginScriptRunner.swift.swiftdoc -emit-module-source-info-path Sources\\Workspace\\CMakeFiles\\Workspace.dir\\DefaultPluginScriptRunner.swift.swiftsourceinfo -emit-dependencies-path Sources\\Workspace\\CMakeFiles\\Workspace.dir\\DefaultPluginScriptRunner.swift.obj.d -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk D:\\a\\swift-build\\swift-build/BuildRoot/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-package-manager\\swift -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-tools-support-core\\swift -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-system\\swift -I D:\\a\\swift-build\\swift-build\\SourceCache\\swift-system\\Sources\\CSystem\\include -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-collections\\swift -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-crypto\\swift -I D:\\a\\swift-build\\swift-build\\SourceCache\\swift-crypto\\Sources\\CCryptoBoringSSL\\include -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-certificates\\swift -I D:\\a\\swift-build\\swift-build\\BinaryCache\\swift-asn1\\swift -module-link-name Workspace -swift-version 5 -O -D Workspace_EXPORTS -plugin-path D:\\a\\swift-build\\swift-build\\BuildRoot\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\host\\plugins -plugin-path D:\\a\\swift-build\\swift-build\\BuildRoot\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\local\\lib\\swift\\host\\plugins -Xcc -D_CRT_SECURE_NO_WARNINGS -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -parse-as-library -module-name Workspace -num-threads 2 -o Sources\\Workspace\\CMakeFiles\\Workspace.dir\\DefaultPluginScriptRunner.swift.obj
1.	compnerd.org Swift version 5.9-dev (LLVM 0b945a41db5d9af, Swift 4e71efce1f56373)
2.	Compiling with the current language version
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for Workspace)
4.	While running pass #67608 SILFunctionTransform "Mem2Reg" on SILFunction "@$s9Workspace25DefaultPluginScriptRunnerV07compilecD011sourceFiles10pluginName12toolsVersion18observabilityScope13callbackQueue8delegate10completionySay8TSCBasic12AbsolutePathVG_SS12PackageModel05ToolsL0V6Basics013ObservabilityN0C8Dispatch08DispatchP0C12SPMBuildCore0cD16CompilerDelegate_pys6ResultOyAY0C17CompilationResultVs5Error_pGctFyA0_yAL13ProcessResultVsA3__pGcfU3_".
 for expression at [D:\a\swift-build\swift-build\SourceCache\swift-package-manager\Sources\Workspace\DefaultPluginScriptRunner.swift:347:104 - line:387:9] RangeText="{
            // We are now on our caller's requested callback queue, so we just call the completion handler directly.
            dispatchPrecondition(condition: .onQueue(callbackQueue))
            completion($0.tryMap { process in
                // Emit the compiler output as observable info.
                let compilerOutput = ((try? process.utf8Output()) ?? "") + ((try? process.utf8stderrOutput()) ?? "")
                if !compilerOutput.isEmpty {
                    observabilityScope.emit(info: compilerOutput)
                }

                // Save the persisted compilation state for possible reuse next time.
                let compilationState = PersistedCompilationState(
                    commandLine: commandLine,
                    environment: toolchain.swiftCompilerEnvironment,
                    inputHash: compilerInputHash,
                    output: compilerOutput,
                    result: .init(process.exitStatus))
                do {
                    try JSONEncoder.makeWithDefaults().encode(path: stateFilePath, fileSystem: self.fileSystem, compilationState)
                }
                catch {
                    // We couldn't write out the `.state` file. We warn about it but proceed.
                    observabilityScope.emit(debug: "Couldn't save plugin compilation state (\(error))")
                }

                // Construct a PluginCompilationResult for both the successful and unsuccessful cases (to convey diagnostics, etc).
                let result = PluginCompilationResult(
                    succeeded: compilationState.succeeded,
                    commandLine: commandLine,
                    executableFile: execFilePath,
                    diagnosticsFile: diagFilePath,
                    compilerOutput: compilerOutput,
                    cached: false)

                // Tell the delegate that we're done compiling the plugin, passing it the result.
                delegate.didCompilePlugin(result: result)

                // Also return the result to the caller.
                return result
            })
        "
Exception Code: 0x80000003
 #0 0x00007ff65fa52675 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x55c2675)
 #1 0x00007ffa17d9bab4 (C:\Windows\System32\ucrtbase.dll+0x7bab4)
 #2 0x00007ffa17d9ca81 (C:\Windows\System32\ucrtbase.dll+0x7ca81)
 #3 0x00007ffa17d9e451 (C:\Windows\System32\ucrtbase.dll+0x7e451)
 #4 0x00007ffa17d9e691 (C:\Windows\System32\ucrtbase.dll+0x7e691)
 #5 0x00007ff65b57d04e (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10ed04e)
 #6 0x00007ff65b4b0c73 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x1020c73)
 #7 0x00007ff65b4b0d1a (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x1020d1a)
 #8 0x00007ff65b4b0d1a (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x1020d1a)
 #9 0x00007ff65b4af512 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x101f512)
#10 0x00007ff65b5584b7 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10c84b7)
#11 0x00007ff65b57ce6c (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10ece6c)
#12 0x00007ff65b57d40e (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10ed40e)
#13 0x00007ff65b57c643 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10ec643)
#14 0x00007ff65b57a859 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x10ea859)
#15 0x00007ff65af4386d (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xab386d)
#16 0x00007ff65af3fdbb (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xaafdbb)
#17 0x00007ff65af42f77 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xab2f77)
#18 0x00007ff65af43397 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xab3397)
#19 0x00007ff65acb6053 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x826053)
#20 0x00007ff65acb5331 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x825331)
#21 0x00007ff65acb38fc (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x8238fc)
#22 0x00007ff65acb3bb4 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x823bb4)
#23 0x00007ff65acb3607 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x807)
#24 0x00007ff65ac813ad (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x7f13ad)
#25 0x00007ff65acb01fb (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x8201fb)
#26 0x00007ff65acb3c54 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x823c54)
#27 0x00007ff65ac811c5 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x7f11c5)
#28 0x00007ff65a745c45 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x2b5c45)
#29 0x00007ff65a55a78d (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xca78d)
#30 0x00007ff65a55b6a2 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xcb6a2)
#31 0x00007ff65a559ff5 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc9ff5)
#32 0x00007ff65a55a45b (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xca45b)
#33 0x00007ff65a55ca44 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xcca44)
#34 0x00007ff65a518bf6 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x88bf6)
#35 0x00007ff65a518729 (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x88729)
#36 0x00007ff65fade16c (D:\a\swift-build\swift-build\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x564e16c)
#37 0x00007ffa19e24de0 (C:\Windows\System32\KERNEL32.DLL+0x14de0)
#38 0x00007ffa1a7de3db (C:\Windows\SYSTEM32\ntdll.dll+0x7e3db)

<unknown>:0: error: compile command failed due to signal -2147483645 (use -v to see invocation)

@compnerd
Copy link
Member

CC: @MaxDesiatov

@compnerd
Copy link
Member

@swift-ci please build toolchain Windows platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants