swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

Constraint solver assertion failure with key paths and dynamic member subscript #69386

Open stephencelis opened 1 year ago

stephencelis commented 1 year ago

Description

I was setting up Windows CI for a project and encountered a crash in the constraint solver that seems to be around key paths and dynamic member lookup:

https://github.com/pointfreeco/swift-case-paths/actions/runs/6632315615/job/18017730580

2023-10-24T20:52:42.5386814Z error: compile command failed due to exception 3 (use -v to see invocation)
2023-10-24T20:52:42.5387982Z error: failed parsing the Swift compiler output: unexpected JSON message: {
2023-10-24T20:52:42.5388779Z   "exception" : 3,
2023-10-24T20:52:42.5389309Z   "kind" : "abnormal-exit",
2023-10-24T20:52:42.5389885Z   "name" : "compile",
2023-10-24T20:52:42.5516209Z   "output" : "Assertion failed: (path.size() == 1 && path[0].getKind() == ConstraintLocator::SubscriptMember) || (path.size() == 2 && path[1].getKind() == ConstraintLocator::KeyPathDynamicMember), file C:\\Users\\swift-ci\\jenkins\\workspace\\oss-swift-windows-toolchain\\swift\\lib\\Sema\\CSSimplify.cpp, line 15236\r\nPlease submit a bug report (https:\/\/swift.org\/contributing\/#reporting-bugs) and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: C:\/Library\/Developer\/Toolchains\/unknown-Asserts-development.xctoolchain\/usr\/bin\/swift-frontend.exe -frontend -c -primary-file D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\CasePathableTests.swift -primary-file D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\CasePathsTests.swift -primary-file D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\DeprecatedTests.swift -primary-file D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\DeprecatedXCTModifyTests.swift D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\ReflectionTests.swift D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\XCTModifyTests.swift D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\Tests\\\\CasePathsTests\\\\XCTUnwrapTests.swift -supplementary-output-file-map C:\\\\Users\\\\runneradmin\\\\AppData\\\\Local\\\\Temp\\\\TemporaryDirectory.6tvph0\\\\supplementaryOutputs-1 -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\\\\Library\\\\Developer\\\\Platforms\\\\Windows.platform\\\\Developer\\\\SDKs\\\\Windows.sdk -I D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug -I C:\\\\Library\\\\Developer\\\\Platforms\\\\Windows.platform\\\\Developer\\\\Library\\\\XCTest-development\\\\usr\\\\lib\\\\swift\\\\windows -I C:\\\\Library\\\\Developer\\\\Platforms\\\\Windows.platform\\\\Developer\\\\Library\\\\XCTest-development\\\\usr\\\\lib\\\\swift\\\\windows\\\\x86_64 -enable-testing -g -module-cache-path D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -load-plugin-executable D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\CasePathsMacros.exe#CasePathsMacros -empty-abi-descriptor -resource-dir C:\\\\Library\\\\Developer\\\\Toolchains\\\\unknown-Asserts-development.xctoolchain\\\\usr\\\\lib\\\\swift -enable-anonymous-context-mangled-names -Xcc -D_MT -Xcc -D_DLL -Xcc -Xclang -Xcc --dependent-lib=msvcrt -module-name CasePathsTests -package-name swift_case_paths -plugin-path C:\\\\Library\\\\Developer\\\\Toolchains\\\\unknown-Asserts-development.xctoolchain\\\\usr\\\\bin -plugin-path C:\\\\Library\\\\Developer\\\\Toolchains\\\\unknown-Asserts-development.xctoolchain\\\\usr\\\\local\\\\bin -parse-as-library -o D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\CasePathsTests.build\\\\CasePathableTests.swift.o -o D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\CasePathsTests.build\\\\CasePathsTests.swift.o -o D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\CasePathsTests.build\\\\DeprecatedTests.swift.o -o D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\CasePathsTests.build\\\\DeprecatedXCTModifyTests.swift.o -index-store-path D:\\\\a\\\\swift-case-paths\\\\swift-case-paths\\\\.build\\\\x86_64-unknown-windows-msvc\\\\debug\\\\index\\\\store -index-system-modules\r\n1.\tSwift version 5.9.1 (swift-5.9.1-RELEASE)\r\n2.\tCompiling with the current language version\r\n3.\tWhile evaluating request TypeCheckSourceFileRequest(source_file \"D:\\a\\swift-case-paths\\swift-case-paths\\Tests\\CasePathsTests\\CasePathsTests.swift\")\r\n4.\tWhile evaluating request TypeCheckFunctionBodyRequest(CasePathsTests.(file).CasePathsTests.testCaseKeyPaths()@D:\\a\\swift-case-paths\\swift-case-paths\\Tests\\CasePathsTests\\CasePathsTests.swift:49:10)\r\n5.\tWhile type-checking statement at [D:\\a\\swift-case-paths\\swift-case-paths\\Tests\\CasePathsTests\\CasePathsTests.swift:49:29 - line:83:5] RangeText=\"{\r\r\n      var foo: Foo = .bar(.int(1))\r\r\n\r\r\n      XCTAssertEqual(foo.bar, .int(1))\r\r\n      XCTAssertEqual(foo.bar?.int, 1)\r\r\n\r\r\n      XCTAssertEqual(foo[keyPath: \\.bar], .int(1))\r\r\n      XCTAssertEqual(foo[keyPath: \\.bar?.int], 1)\r\r\n\r\r\n      XCTAssertEqual(foo[case: \\.bar], .int(1))\r\r\n      XCTAssertEqual(foo[case: \\.bar.int], 1)\r\r\n\r\r\n      foo[case: \\.bar] = .int(42)\r\r\n\r\r\n      XCTAssertEqual(foo, .bar(.int(42)))\r\r\n\r\r\n      foo[case: \\.baz] = .string(\"Forty-two\")\r\r\n\r\r\n      XCTAssertEqual(foo, .bar(.int(42)))\r\r\n\r\r\n      foo[case: \\.bar.int] = 1792\r\r\n\r\r\n      XCTAssertEqual(foo, .bar(.int(1792)))\r\r\n\r\r\n      foo[case: \\.baz.string] = \"Seventeen hundred and ninety-two\"\r\r\n\r\r\n      XCTAssertEqual(foo, .bar(.int(1792)))\r\r\n\r\r\n      foo[case: \\.bar] = .int(42)\r\r\n\r\r\n      XCTAssertEqual((\\Foo.Cases.self)(.bar(.int(1))), .bar(.int(1)))\r\r\n      XCTAssertEqual((\\Foo.Cases.bar)(.int(1)), .bar(.int(1)))\r\r\n      XCTAssertEqual((\\Foo.Cases.bar.int)(1), .bar(.int(1)))\r\r\n      XCTAssertEqual((\\Foo.Cases.fizzBuzz)(), .fizzBuzz)\r\r\n    \"\r\n6.\tWhile type-checking expression at [D:\\a\\swift-case-paths\\swift-case-paths\\Tests\\CasePathsTests\\CasePathsTests.swift:55:7 - line:55:50] RangeText=\"XCTAssertEqual(foo[keyPath: \\.bar], .int(1)\"\r\n7.\tWhile type-checking-target starting at D:\\a\\swift-case-paths\\swift-case-paths\\Tests\\CasePathsTests\\CasePathsTests.swift:55:7\r\nException Code: 0x80000003\r\n #0 0x00007ff605a4a7a5 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x56da7a5)\r\n #1 0x00007ffdac6abab4 (C:\\Windows\\System32\\ucrtbase.dll+0x7bab4)\r\n #2 0x00007ffdac6aca81 (C:\\Windows\\System32\\ucrtbase.dll+0x7ca81)\r\n #3 0x00007ffdac6ae451 (C:\\Windows\\System32\\ucrtbase.dll+0x7e451)\r\n #4 0x00007ffdac6ae691 (C:\\Windows\\System32\\ucrtbase.dll+0x7e691)\r\n #5 0x00007ff6017bf4e0 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x144f4e0)\r\n #6 0x00007ff6017bf318 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x144f318)\r\n #7 0x00007ff60173b4f7 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13cb4f7)\r\n #8 0x00007ff6017e7249 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1477249)\r\n #9 0x00007ff60171b815 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13ab815)\r\n#10 0x00007ff6017eeda2 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x147eda2)\r\n#11 0x00007ff60171d380 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13ad380)\r\n#12 0x00007ff60173bd95 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13cbd95)\r\n#13 0x00007ff6017e7249 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1477249)\r\n#14 0x00007ff6017e90e5 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x14790e5)\r\n#15 0x00007ff601800abc (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1490abc)\r\n#16 0x00007ff6016a9134 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1339134)\r\n#17 0x00007ff60180b255 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x149b255)\r\n#18 0x00007ff60180a300 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x149a300)\r\n#19 0x00007ff60180ad77 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x149ad77)\r\n#20 0x00007ff601809d23 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1499d23)\r\n#21 0x00007ff6017627cc (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13f27cc)\r\n#22 0x00007ff601760d39 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13f0d39)\r\n#23 0x00007ff601760deb (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13f0deb)\r\n#24 0x00007ff601676b64 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1306b64)\r\n#25 0x00007ff601677eac (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1307eac)\r\n#26 0x00007ff60166d5f3 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x12fd5f3)\r\n#27 0x00007ff6016730c1 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x13030c1)\r\n#28 0x00007ff601c00fe6 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x1890fe6)\r\n#29 0x00007ff601beb720 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x187b720)\r\n#30 0x00007ff601bce5dc (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x185e5dc)\r\n#31 0x00007ff601c41a88 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x18d1a88)\r\n#32 0x00007ff60153d196 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11cd196)\r\n#33 0x00007ff60151ac1a (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11aac1a)\r\n#34 0x00007ff601537c84 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11c7c84)\r\n#35 0x00007ff6015361e4 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11c61e4)\r\n#36 0x00007ff601533b2f (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11c3b2f)\r\n#37 0x00007ff601540fba (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x11d0fba)\r\n#38 0x00007ff6006640bc (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x2f40bc)\r\n#39 0x00007ff60066afc9 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x2fafc9)\r\n#40 0x00007ff600670165 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x300165)\r\n#41 0x00007ff600476b2a (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x106b2a)\r\n#42 0x00007ff60047907f (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x10907f)\r\n#43 0x00007ff6004364fc (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0xc64fc)\r\n#44 0x00007ff600436169 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0xc6169)\r\n#45 0x00007ff605adc174 (C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe+0x576c174)\r\n#46 0x00007ffdadf44de0 (C:\\Windows\\System32\\KERNEL32.DLL+0x14de0)\r\n#47 0x00007ffdaefbed9b (C:\\Windows\\SYSTEM32\\ntdll.dll+0x7ed9b)\r\n",
2023-10-24T20:52:42.5606478Z   "pid" : -1000,
2023-10-24T20:52:42.5607045Z   "process" : {
2023-10-24T20:52:42.5607483Z     "real_pid" : 4156
2023-10-24T20:52:42.5607901Z   }
2023-10-24T20:52:42.5609139Z }: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "invalid kind", underlyingError: nil))
2023-10-24T20:52:43.8309622Z error: fatalError

Steps to reproduce

Check out swift-case-paths@f3c4825e3baad3003b29778cdc036eacc5f6ddd6.

Build the test targets with a toolchain with assertions enabled.

Expected behavior

I expect no assertion.

Environment

compnerd commented 1 year ago

Assertion failed: (path.size() == 1 && path[0].getKind() == ConstraintLocator::SubscriptMember) || (path.size() == 2 && path[1].getKind() == ConstraintLocator::KeyPathDynamicMember), file swift\lib\Sema\CSSimplify.cpp, line 15236

CC: @slavapestov @hborla

hborla commented 1 year ago

@xedin has been working in this area recently