Error starting the swift repl on windows

Hi,
I've been eager to start working with Swift on Windows, and I have gone through the installation instructions. However, when starting the repl using swift repl -target x86_64-unknown-windows-msvc %SWIFTFLAGS% as instructed by the getting started page, I get the following error:

Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
TypeSystem for language swift doesn't existStack dump:
0.      Program arguments: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe --repl=-disable-objc-interop -sdk "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -color-diagnostics -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL

I get the same error just starting with swift.
I have tried the x64 Native Tools Command Prompt, Powershell, and cmd (all as admin).
I am able to compile and do things like swift --version, but I cannot import SwiftWin32 (probably unrelated) which leads me to believe that the problem lies somewhere with python. I have installed the vs version of python and added that to my path, and I also had other versions of python installed and in my path as well.

If anyone knows how to fix this or what is going on, I would be grateful.

1 Like

@PseudonymPatel, I think at least one part of the issue you're experiencing is that there is a known bug regarding the REPL that is preventing it from working on Windows (see SR-13591). From what I've heard, it sounds like this might be fixed in time for the 5.3.1 release.

The other part is probably installation/environment related. I had a few issues getting setup myself, but after following the installation instructions to the 'T', I finally got things working to where I could invoke swiftc directly. Below is info on my environment just in case it helps you.

Windows 10 build: 18362.1082
Build tools version: MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.27)
Windows SDK installed: 10.0.18362.0
Python version: 3.7.8

One thing I had trouble with was that I didn't copy the Support Files at the right time. You need to be sure to copy those after installing (or updating) the Swift toolchain or after any update to Visual Studio (also, be sure to do that as an administrator from the x64 Native Tools Command Prompt for VS). It's also worth trying to restart your machine after copying the Support Files if it still doesn't work.

For more context of my particular scenario, here's a link to an issue thread where I received some help working through some of the initial issues I was experiencing.

2 Likes

@PseudonymPatel, here’s another thread that may help. In it, there’s some discussion of the current issues with the REPL, as well as how to invoke swiftc directly.

This one helped me a little, too.

2 Likes

I just installed Swift 5.4.2 for Windows and the latest Visual Studio 2019 as per the guides on swift.org. Copied the four files to the VS image, etc.

I'm able to successfully run:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>swift --version
compnerd.org Swift version 5.4.2 (swift-5.4.2-RELEASE)
Target: x86_64-unknown-windows-msvc

However simply running swift at the command prompt fails to invoke the REPL environment. What am I doing wrong? Or is it still broken? Thanks.

Nevermind... I notice in the "REPL" section near the bottom it says you have to run this command to add a python-related path to use the REPL:

path %ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Python37_64;%PATH%

Might be good to include this step in the "On Windows" of the "Installing Swift" section on Swift.org, rather than having it buried down under "Using the REPL" since most of us who have used the REPL on Mac in the past, probably wouldn't read that section as it shouldn't contain any new information for us? Just a thought.

Sadly, adjusting just the path is insufficient :-(. There was some regressions in lldb that broke the REPL on Windows a while ago. There are too many other items that are higher priority for me so I've not yet gotten back to this. I'd love it if someone else would step up to help with getting the REPL experience improved on Windows.

1 Like