Compiler crashing with unhelpful error

Hey guys.

I started getting a compiler error from a project and I'm not sure how to track it down to report it. It happens on windows and does not happen on macOS, or Ubuntu.

The package is here GitHub - STREGAsGate/Gravity: Gravity for Swift.

This is the error:

error: compile command failed due to exception 3 (use -v to see invocation)error: failed parsing the Swift compiler output: unexpected JSON message: : dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "invalid kind", underlyingError: nil))

The --verbose output just shows the last compiled file but it's not that same each time.

Verbose Output Snippet

C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Errors.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Foundation.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Testing.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity.swift -primary-file C:\GitHub\Gravity-1\Sources\Gravity\GravityClass.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClosure.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityInstance.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityValue.swift C:\GitHub\Gravity-1\Sources\Gravity\Protocols.swift -emit-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClass.d -emit-reference-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClass.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -color-diagnostics -enable-testing -g -module-cache-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\GravityC.build\module.modulemap -Xcc -I -Xcc C:\GitHub\Gravity-1\Sources\GravityC\include -module-name Gravity -parse-as-library -o C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClass.swift.o -index-store-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Errors.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Foundation.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Testing.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClass.swift -primary-file C:\GitHub\Gravity-1\Sources\Gravity\GravityClosure.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityInstance.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityValue.swift C:\GitHub\Gravity-1\Sources\Gravity\Protocols.swift -emit-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClosure.d -emit-reference-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClosure.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk
-I C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -color-diagnostics -enable-testing -g -module-cache-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\GravityC.build\module.modulemap -Xcc -I -Xcc C:\GitHub\Gravity-1\Sources\GravityC\include -module-name Gravity -parse-as-library -o C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityClosure.swift.o -index-store-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Errors.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Foundation.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Testing.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClass.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClosure.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityInstance.swift -primary-file C:\GitHub\Gravity-1\Sources\Gravity\GravityValue.swift C:\GitHub\Gravity-1\Sources\Gravity\Protocols.swift -emit-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityValue.d -emit-reference-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityValue.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -color-diagnostics -enable-testing -g -module-cache-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\GravityC.build\module.modulemap -Xcc -I -Xcc C:\GitHub\Gravity-1\Sources\GravityC\include -module-name Gravity -parse-as-library -o C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityValue.swift.o -index-store-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Errors.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Foundation.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Testing.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClass.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClosure.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityInstance.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityValue.swift -primary-file C:\GitHub\Gravity-1\Sources\Gravity\Protocols.swift -emit-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\Protocols.d -emit-reference-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\Protocols.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -color-diagnostics -enable-testing -g -module-cache-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\GravityC.build\module.modulemap -Xcc -I -Xcc C:\GitHub\Gravity-1\Sources\GravityC\include -module-name Gravity -parse-as-library -o C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\Protocols.swift.o -index-store-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Errors.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Foundation.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity+Testing.swift C:\GitHub\Gravity-1\Sources\Gravity\Gravity.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClass.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityClosure.swift -primary-file C:\GitHub\Gravity-1\Sources\Gravity\GravityInstance.swift C:\GitHub\Gravity-1\Sources\Gravity\GravityValue.swift C:\GitHub\Gravity-1\Sources\Gravity\Protocols.swift -emit-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityInstance.d -emit-reference-dependencies-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityInstance.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -color-diagnostics -enable-testing -g -module-cache-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\GravityC.build\module.modulemap -Xcc -I -Xcc C:\GitHub\Gravity-1\Sources\GravityC\include -module-name Gravity -parse-as-library -o C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\Gravity.build\GravityInstance.swift.o -index-store-path C:\GitHub\Gravity-1.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
error: emit-module command failed due to exception 3 (use -v to see invocation)error: failed parsing the Swift compiler output: unexpected JSON message: : dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "invalid kind", underlyingError: nil))
PS C:\GitHub\Gravity-1>

Anyone have some suggestions on how I could track this down?

On macOS we would simply find the crash report and file a bug. If the crash reports says it's a compilation issue, to work around you'd want to look at the last X files, where X is your build width (usually logical cores), and start commenting out parts of those files, if you can. That, or bisect recent successful builds.

So far this doesn't seem to be related to Windows specifically. The invalid output sounds like an issue with the driver, but it doesn't really help narrow it down. It seems like there is a syntax error somewhere and that is flowing through the system.

I tried this and ended up removing all of the Swift code, so it's definitely not Swift source code.

Hmmm, I don't know enough about the lower level components of the build process but I can confirm macOS or Ubuntu are working.

After experimenting I've narrowed the crash down to linking GravityC (a c99 module).
If GravityC has an empty public header file everything compiles and products are emitted as expected.
So the crash seems to be related to bridging with C, but I'm not sure how to go deeper from here.

That doesn't seem too surprising. The clang importer is likely emitting a warning/error and that is trying to be surfaced through the driver and is triggering this. I would say try building the library using clang-cl and see if you can spot a build failure.

Thanks! This seems likely to be the issue.

I built the C code with clang on windows, found an issue, and added a work around.
The C code now compiles on windows with clang directly.

But I still get the error, so there's probably more to fix due to some difference in the environment I'm not accounting for.

Do the clang errors get logged somewhere or is there any way to see them on windows?

I am also just now running into this issue using swift build with 5.7.2 Release, but having done the digging yet to see if it's any of my C bridges or something else

Update: I forgot about using swift build --use-integrated-swift-driver which will give better diagnostic info.

This is the issue (and unfortunately I cannot provide the source code for this). I will try to make a minimal repro example.

Assertion failed: SGF.ExpectedExecutor || SGF.unsafelyInheritsExecutor(), file D:\a\1\s\swift\lib\SILGen\SILGenProlog.cpp, line 880
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.

This one must be a Windows-specific issue, right? It compiles just fine on macOS.

Followup - I needed to add @_unsafeInheritExecutor on an actor's member function that takes as a parameter a protocol that conforms to Actor. This seems like something I shouldn't need to do!

Yeah seems so. Based on our errors, which come from different tools and what compnerd, said the errors seems to be getting hung on something and not making there way up to standard output.

--use-integrated-swift-driver reveals my error is originating from clang as expected:

Assertion failed: Loc.isValid() && "Can't get file characteristic of invalid loc!", file D:\a\1\s\llvm-project\clang\lib\Basic\SourceManager.cpp, line 1473

But this trick didn't reveal any new leads for me. It could be duplicate symbols, or missing symbols, or literally anything. Thx for posting it though!

Could you please file an issue with a reproducer?

No, not necessarily. macOS releases are built without assertions, so this would silently pass. I would say that you should build a debug or release+asserts toolchain on macOS to verify.

But it does! It points us too https://github.com/apple/llvm-project/blob/stable/20220421/clang/lib/Basic/SourceManager.cpp#L1473. It seems to be an invalid SLoc, so either this is a scratch buffer or an include path gone awry.

I would try running single threaded, verbose, find the crashing command and then run that (unchanged) invocation explicitly through the CPP and try to isolate which inclusion is causing this. It could be a modules issue.

is there no magic incantation of swift build that will enable assertions?

Done. Passing actor as parameter to another actor causes compiler assertion failure · Issue #62731 · apple/swift · GitHub

1 Like

No, the assertions are compiled out of the codebase at build time.

Okay, after lots of trial and error I narrowed it down.

The error happens when #include <assert.h> is in a public header.

Not sure what the actual link error is though.
It's a lot of source modification that's going to make maintaining the package far more of hassle than I would have preferred, but I can just move the #includes to the .c files that use assert().

<assert.h> is special. That is a non-modular header (forced textual inclusion) as the macros impact the declarations. It sounds like you may have an issue with the environment. Was VsDevCmd sourced properly?

1 Like

I installed VS2019 using the installer tool from the ms dev portal and the toolchain from swift.org
I tried updating visual studio and reinstalling swift but that didn't work.

But I just tried it through a GitHub action and it builds and tests all pass.
So it does seem like it's my dev box. I'll try removing everything and installing fresh.
Thanks for help!

I had the same error message that @STREGAsGate initially had after I moved my Swift 5.6 projects to a new box with Swift 5.7 and VS2022 (5.7 was tested with VS2019 but I tried VS2022 anyway). All but one of my projects worked. The one that failed uses concurrency. It had a class annotated with @MainActor and an async main function instantiating that class. The --use-integrated-swift-driver option mentioned above directed me to the line of code in main() with instantiation. The 5.7 release notes say something about top-level asynchrony, and I just hit off the @MainActor annotation from the class and it worked: code compiles and still runs concurrently.

Maybe this helps.
Regards, Jürgen

Configuration
Code in question is on GitHub (swindows branch), class Rtow in Rtow.swift (changes in today's commit)
Windows 10, Build 19044
Visual Studio Community 2022
Swift on Windows 5.7.3, Traditional Installation
winget install Git.Git (because Git included in VS2022 didn't work in Swift 5.7)