Is this REPL issue a bug or specific to my environment?

I've been encountering an issue with the Swift REPL for a while now, and chalked it up to being some kind of issue with my local environment. That is, until I got a new computer and the issue was happening there too. This has been happening consistently with Swift 5.2.4/Xcode 11 and Swift 5.3/Xcode 12. Stranger still, it used to not happen with Swift 5.2.4 - but then just started seemingly out of nowhere.

The Swift REPL consistently complains when I try to import SwiftPM modules, saying that it can't lookup the symbols. This is strange, but the code has no problem running in tests — just the REPL.

Here's a quick example of how to maybe reproduce this. For me, it happens with any SwiftPM library, so the specific one doesn't matter.

$ mkdir Example
$ cd Example
$ swift package init --type library

Edit Sources/Example/Example.swift to look like so:

public struct Example {
    var text = "Hello, world!"
    public init() {}
}

Next, launch the REPL.

$ swift run --repl
...
1> #if canImport(Example)
2. print("Proceed")
3. #endif
Proceed
4> import Example
5> let example = Example()
example: Example.Example = {
  text = {
    _guts = {
      _object = {
        _countAndFlagsBits = <extracting data from value failed>

        _object = <extracting data from value failed>

      }
    }
  }
}
error: Couldn't lookup symbols:
  Example.Example.init() -> Example.Example
  Example.Example.init() -> Example.Example

It's really strange, isn't it?

If it's helpful I can include a log of what LLDB logs, but it's a lot. Let me know if anyone else is having this issue or what I can do to fix it! Thanks.

It doesn't reproduce on my system (in case that is interesting to know):

...
$ swift run --repl
[3/3] Linking libExample__REPL.dylib
Launching Swift REPL with arguments: -I/Users/jens/swifttest/Example/.build/x86_64-apple-macosx/debug -L/Users/jens/swifttest/Example/.build/x86_64-apple-macosx/debug -lExample__REPL
Welcome to Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1).
Type :help for assistance.
  1> #if canImport(Example) 
  2. print("Proceed") 
  3. #endif
Proceed
  4> import Example
  5> let example = Example()
example: Example.Example = {
  text = "Hello, World!"
}
  6>  

Bummer! Thanks for letting me know. I suspected it was something local rather than a proper bug. I wonder what could be going wrong on both of the computers that I'm trying it on... It's especially odd because the second computer is brand new. Hmm...

So in case someone stumbles by this in the future with the same issue -- I'm not 100% sure what caused it but I believe it was a privacy/security issue. I think I had tried to do some debugging in Xcode and got asked "Developer tools needs to take over another process for debugging" (or something of that sort). After giving that permission I noticed later that the REPL was working again for me. I believe this is what fixed the issue though, given that the REPL is built on LLDB.

1 Like