Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14807] [Windows] Runtime crash in swift_getAssociatedTypeWitness #57155

Closed
BradLarson opened this issue Jun 21, 2021 · 3 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself Windows Platform: Windows

Comments

@BradLarson
Copy link
Collaborator

Previous ID SR-14807
Radar None
Original Reporter @BradLarson
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Windows
Assignee @compnerd
Priority Medium

md5: 6bc255090c6cd3804f7011ce5d486a3f

is duplicated by:

  • SR-15222 Access Violation when running unit test on Windows

Issue Description:

The following differentiable Swift code builds and runs correctly on macOS and Linux, but on Windows when built and run it triggers a runtime crash in swift_getAssociatedTypeWitness:

import _Differentiation

protocol NumericDifferentiable : Numeric, Differentiable {
  @differentiable(reverse) static func *(lhs: Self, rhs: Self) -> Self
}

extension Float: NumericDifferentiable {}

struct Model2<T: NumericDifferentiable>: Differentiable {
  var first: T
  var second: T
}

@differentiable(reverse)
func loss2(model: Model2<Float>, multiplier: Float) -> Float {
  return model.first
}

var model = Model2<Float>(first: 1, second: 3)
let grad = gradient(at: model, 5.0, of: loss2)

print("Gradient: \(grad)")

This occurs on Windows with the Swift 5.4.1 release, Swift 5.5 development branch, and the latest nightly Swift toolchains. To reproduce, place the above in main.swift, build, and run the resulting executable via lldb to catch the runtime crash.

You should see a stop reason of "Exception 0xc0000005 encountered at address 0x7ff8a327ba4c: Access violation reading location 0x00000018" in swiftCore.dll at swift_getAssociatedTypeWitness.

Again, this same code builds and runs correctly on macOS and Linux, the crash only seems to appear on Windows.

@typesanitizer
Copy link

cc @rxwei @compnerd

@compnerd
Copy link
Collaborator

I have a local patch that I want to try to refine a bit and need to do some housekeeping on first.

S:\tmp>S:\b\1\bin\swiftc -sdk %SDKROOT% -emit-executable -o reduced.exe reduced.swift
   Creating library reduced.lib and object reduced.exp

S:\tmp>.\reduced.exe
Gradient: (reduced.Model2<Swift.Float>.TangentVector(first: 1.0, second: 0.0), 0.0) 

S:\tmp>S:\b\1\bin\swiftc -sdk %SDKROOT% -emit-executable -o reduced.exe reduced.swift -O
   Creating library reduced.lib and object reduced.exp

S:\tmp>.\reduced.exe
Gradient: (reduced.Model2<Swift.Float>.TangentVector(first: 1.0, second: 0.0), 0.0)

I've also tested it with luiz (JIRA User)'s Geometria package and @jpsim's Yams package (with a change to re-enable all tests on Windows). All three of the cases are happy with the change. I believe that this fix is pretty complete. I would consider it for a 5.5.x backport as this is the only known feature gap outside of some corner cases for async and is quite self-contained.

@compnerd
Copy link
Collaborator

compnerd commented Nov 5, 2021

#40067

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself Windows Platform: Windows
Projects
None yet
Development

No branches or pull requests

3 participants