Swift Scripts sometimes fail in KM 10.x with Xcode 14 beta installed

Just a heads-up, with Xcode 14.0 beta 1 (and its Swift toolchain enabled with xcode-select) is causing a lot of Swift scripts to fail in Keyboard Maestro 10.1.1.

This is on macOS 12.4 / M1 Max.

Attempting to run a Swift Script action with certain Swift scripts results in this error output:

2022-06-10 20:37:31 Execute a Swift Script failed with script error: JIT session error: Symbols not found: [ _$s10Foundation22_convertNSErrorToErrorys0E0_pSo0C0CSgF, _$sSa10FoundationE36_unconditionallyBridgeFromObjectiveCySayxGSo7NSArrayCSgFZ, _$sSS10FoundationE19_bridgeToObjectiveCSo8NSStringCyF, _$sSS10FoundationE36_unconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ]
Failed to materialize symbols: { (main, { _got.$ss10SetAlgebraPSQTb, _$sSoMXM, _$sSaySo20NSTextCheckingResultCGSayxGSlsWl, _$sSo17NSMatchingOptionsVMf, _$sSo17NSMatchingOptionsV8rawValueABSu_tcfC, _associated conformance So17NSMatchingOptionsVs9OptionSetSCSY, _$sSAySo7NSErrorCSgGSAyxGs8_PointersWL, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACPxycfCTW, _$sSo17NSMatchingOptionsVML, _$sSo17NSMatchingOptionsVMn, _$sSo17NSMatchingOptionsVABSYSCWl, _$sSo26NSRegularExpressionOptionsV8rawValueSuvg, _$sSo17NSMatchingOptionsV8rawValueSuvg, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACPxycfCTW, _got.$s7Elements10SetAlgebraPTl, _$sSo26NSRegularExpressionOptionsVABSQSCWl, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP10isSuperset2ofSbx_tFTW, _$sSo26NSRegularExpressionOptionsVABs10SetAlgebraSCWl, _$sSo17NSMatchingOptionsVABSQSCWl, _$sSo17NSMatchingOptionsVABs25ExpressibleByArrayLiteralSCWl, ___swift_instantiateConcreteTypeFromMangledNameAbstract, _got.$ss10SetAlgebraMp, _$sSo26NSRegularExpressionOptionsVABSYSCWl, _$s10FoundationMXM, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP8containsySb7ElementQzFTW, _$sSo17NSMatchingOptionsVSQSCSQ2eeoiySbx_xtFZTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP12intersectionyxxFTW, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP8subtractyyxFTW, _$sSo26NSRegularExpressionOptionsVs25ExpressibleByArrayLiteralSCMA, _$sSaySo20NSTextCheckingResultCGMD, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP6update4with7ElementQzSgAHn_tFTW, _$sSaySo20NSTextCheckingResultCGSayxGSlsWL, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACPyxqd__ncSTRd__7ElementQyd__AERtzlufCTW, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACPyxqd__ncSTRd__7ElementQyd__AERtzlufCTW, _$sSo26NSRegularExpressionOptionsVABSQSCWL, _got.$ss25ExpressibleByArrayLiteralP05arrayD0x0cD7ElementQzd_tcfCTq, _$sSo17NSMatchingOptionsVSYSCMA, _$sSo26NSRegularExpressionOptionsVs25ExpressibleByArrayLiteralSCMc, _$sSo17NSMatchingOptionsVSYSCMc, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP23formSymmetricDifferenceyyxnFTW, _symbolic $ss10SetAlgebraP, _symbolic _____ So26NSRegularExpressionOptionsV, _$sSo17NSMatchingOptionsVABs9OptionSetSCWl, _got.$sSY8rawValue03RawB0QzvgTq, _$sSo20NSTextCheckingResultCML, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP6removey7ElementQzSgAGFTW, _$sSAySo7NSErrorCSgGSAyxGs8_PointersWl, _associated conformance So26NSRegularExpressionOptionsVs9OptionSetSCSY, _associated conformance So26NSRegularExpressionOptionsVs9OptionSetSCs0E7Algebra, _$sSo17NSMatchingOptionsVABs10SetAlgebraSCWL, _$sSo19NSRegularExpressionCMa, _$sSo17NSMatchingOptionsVMa, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP7isEmptySbvgTW, _symbolic SaySo20NSTextCheckingResultCG, _$sSo26NSRegularExpressionOptionsVABs10SetAlgebraSCWL, _got.$ss10SetAlgebraP9formUnionyyxnFTq, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCMA, _got.$s8RawValueSYTl, _got.$ss10SetAlgebraP16formIntersectionyyxFTq, _$sSo19NSRegularExpressionCML, _got.$ss10SetAlgebraP11subtractingyxxFTq, _$sSo17NSMatchingOptionsVSYSCSY8rawValue03RawD0QzvgTW, _$sSo26NSRegularExpressionOptionsVSYSCSY8rawValuexSg03RawE0Qz_tcfCTW, _got.$ss10SetAlgebraP8isSubset2ofSbx_tFTq, _$sSo26NSRegularExpressionOptionsVABs9OptionSetSCWl, _$sSo17NSMatchingOptionsVSYSCSY8rawValuexSg03RawD0Qz_tcfCTW, _associated conformance So26NSRegularExpressionOptionsVs10SetAlgebraSCSQ, _got.$ss10SetAlgebraP8containsySb7ElementQzFTq, _$sSo17NSMatchingOptionsVs9OptionSetSCsACP8rawValuex03RawF0Qz_tcfCTW, _got.$ss10SetAlgebraP5unionyxxnFTq, _$sSo26NSRegularExpressionOptionsVABs25ExpressibleByArrayLiteralSCWL, _$sS2us17FixedWidthIntegersWl, _got.$ss10SetAlgebraP12intersectionyxxFTq, _$sSo26NSRegularExpressionOptionsV8rawValueABSu_tcfC, _got.$ss10SetAlgebraP6insertySb8inserted_7ElementQz17memberAfterInserttAFnFTq, _got.$ss10SetAlgebraP6removey7ElementQzSgAEFTq, _$sSo17NSMatchingOptionsVSQSCMc, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP16formIntersectionyyxFTW, _$sSo17NSMatchingOptionsVABSQSCWL, _$sSo26NSRegularExpressionOptionsVSQSCSQ2eeoiySbx_xtFZTW, _symbolic _____ So17NSMatchingOptionsV, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP7isEmptySbvgTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP23formSymmetricDifferenceyyxnFTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCMA, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP8isSubset2ofSbx_tFTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP8subtractyyxFTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP19symmetricDifferenceyxxnFTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCMc, _got.$ss9OptionSetPSYTb, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP10isDisjoint4withSbx_tFTW, _got.$ss10SetAlgebraP10isDisjoint4withSbx_tFTq, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP9formUnionyyxnFTW, _got.$ss10SetAlgebraP10isSuperset2ofSbx_tFTq, _got.$ss9OptionSetMp, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP10isSuperset2ofSbx_tFTW, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP5unionyxxnFTW, _got.$ss10SetAlgebraP7isEmptySbvgTq, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP11subtractingyxxFTW, _$sSo26NSRegularExpressionOptionsVs9OptionSetSCsACP8rawValuex03RawG0Qz_tcfCTW, _got.$ss10SetAlgebraP8subtractyyxFTq, _got.$ss9OptionSetP8rawValuex03RawD0Qz_tcfCTq, _$sSo17NSMatchingOptionsVs25ExpressibleByArrayLiteralSCsACP05arrayF0x0eF7ElementQzd_tcfCTW, _got.$ss9OptionSetPs0B7AlgebraTb, _$sSo17NSMatchingOptionsVs25ExpressibleByArrayLiteralSCMA, _$sSo17NSMatchingOptionsVs9OptionSetSCMA, _$sSo26NSRegularExpressionOptionsVSYSCSY8rawValue03RawE0QzvgTW, _$sSo26NSRegularExpressionOptionsVs9OptionSetSCMc, _$sSo17NSMatchingOptionsVABSYSCWL, _symbolic $ss9OptionSetP, _$sSo26NSRegularExpressionOptionsVs9OptionSetSCMA, _symbolic $ss25ExpressibleByArrayLiteralP, _got.$s19ArrayLiteralElements013ExpressibleByaB0PTl, _$sSo26NSRegularExpressionOptionsVSQSCMc, _$sSo26NSRegularExpressionOptionsVABSYSCWL, _$sSo17NSMatchingOptionsVABs25ExpressibleByArrayLiteralSCWL, _got.$ss25ExpressibleByArrayLiteralMp, _associated conformance So17NSMatchingOptionsVs10SetAlgebraSCSQ, _got.$sSQ2eeoiySbx_xtFZTq, __swift_FORCE_LOAD_$_swiftDarwin_$_main, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCMc, _got.$ss10SetAlgebraPyxqd__ncSTRd__7ElementQyd__ACRtzlufCTq, __swift_FORCE_LOAD_$_swiftObjectiveC_$_main, _associated conformance So17NSMatchingOptionsVs9OptionSetSCs0D7Algebra, __swift_FORCE_LOAD_$_swiftDispatch_$_main, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_main, _$sSo20NSTextCheckingResultCMa, _got.$ss10SetAlgebraP23formSymmetricDifferenceyyxnFTq, _$sSo26NSRegularExpressionOptionsVSYSCMA, _got.$ss10SetAlgebraP6update4with7ElementQzSgAFn_tFTq, _$sSo20NSTextCheckingResultCSSs5Error_pIggozo_ABSSsAC_pIegnrzo_TR, _$sSo17NSMatchingOptionsVs10SetAlgebraSCsACP6insertySb8inserted_7ElementQz17memberAfterInserttAHnFTW, _$sSo17NSMatchingOptionsVs9OptionSetSCMc, _got.$ss10SetAlgebraP19symmetricDifferenceyxxnFTq, _got.$ss10SetAlgebraPs25ExpressibleByArrayLiteralTb, _$sSo26NSRegularExpressionOptionsVSYSCMc, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP6insertySb8inserted_7ElementQz17memberAfterInserttAHnFTW, _$sSo19NSRegularExpressionC7pattern7optionsABSS_So0aB7OptionsVtKcfC, _got.$sSY8rawValuexSg03RawB0Qz_tcfCTq, _$sSo26NSRegularExpressionOptionsVMB, _associated conformance So26NSRegularExpressionOptionsVs10SetAlgebraSCs25ExpressibleByArrayLiteral, _$sSo26NSRegularExpressionOptionsVML, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP8containsySb7ElementQzFTW, $.main.__inits.0, _$sSo17NSMatchingOptionsVABs9OptionSetSCWL, _$sSo26NSRegularExpressionOptionsVABs25ExpressibleByArrayLiteralSCWl, _$sSo19NSRegularExpressionC7pattern7optionsABSS_So0aB7OptionsVtKcfcTO, _$sSo26NSRegularExpressionOptionsVMF, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP6update4with7ElementQzSgAHn_tFTW, __swift_FORCE_LOAD_$_swiftIOKit_$_main, _$sSAySo7NSErrorCSgGMD, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP12intersectionyxxFTW, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP6removey7ElementQzSgAGFTW, _symbolic SAySo7NSErrorCSgG, __swift_FORCE_LOAD_$_swiftXPC_$_main, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP5unionyxxnFTW, _$sSo26NSRegularExpressionOptionsVMf, _$sSo26NSRegularExpressionOptionsVMn, _$sS2us17FixedWidthIntegersWL, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP16formIntersectionyyxFTW, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP19symmetricDifferenceyxxnFTW, _$sSS4mainE13rregexMatches7patternSaySSGSS_tF, _$sSo26NSRegularExpressionOptionsVs25ExpressibleByArrayLiteralSCsACP05arrayG0x0fG7ElementQzd_tcfCTW, _main, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP9formUnionyyxnFTW, _$sSo17NSMatchingOptionsVMF, _$sSo17NSMatchingOptionsVMB, _symbolic Su, _got.$sSQMp, _$sSo26NSRegularExpressionOptionsVABs9OptionSetSCWL, _associated conformance So17NSMatchingOptionsVs10SetAlgebraSCs25ExpressibleByArrayLiteral, _got.$sSYMp, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP10isDisjoint4withSbx_tFTW, _symbolic $sSY, _got.$ss10SetAlgebraPxycfCTq, ___swift_instantiateConcreteTypeFromMangledName, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP11subtractingyxxFTW, _$sSo17NSMatchingOptionsVABs10SetAlgebraSCWl, _$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACP8isSubset2ofSbx_tFTW, _$sSo17NSMatchingOptionsVs25ExpressibleByArrayLiteralSCMc, _$sSo26NSRegularExpressionOptionsVMa }) }. Macro “Trying” cancelled (while executing Execute Swift Script).

This is happening with a variety of Swift scripts, but not all of them. Here is one example repro. Not a complete script, but enough to cause the error because compile fails.

import Foundation

public func regexMatches(in str: String, pattern: String) -> [String] {
	guard let regex = try? NSRegularExpression(pattern: pattern)
	else { return [] }
	let nsString = str as NSString
	let results = regex.matches(in: str, range: NSMakeRange(0, nsString.length))
	return results.map { nsString.substring(with: $0.range) }
}

This compiles fine in both an Xcode 14 project and in Xcode's Swift playground without issue, and works fine if the previous Xcode 13.4 toolchain is enabled. Which leads me to believe it's a bug with swift's command-line interpreter in the Xcode 14 beta toolchain.

This may resolve itself by the time Xcode 14 hits GM (if it's actually a swift toolchain bug) unless it's a clear issue that can/should be fixed within Keyboard Maestro.