Internal compiler error with `fseek` FFI
I was trying to define an `fseek` FFI function when I ran into an internal compiler error. Here is the most minimal reproducer I could generate:
```
@ffi("fseek")
public fun fseek(_ stream: MemoryAddress, _ offset: Int64, _ whence: Int) -> Int;
trait SeekWhence {
property concrete: Int { let }
}
public fun seek(address: MemoryAddress, offset: Int64, whence: SeekWhence) {
let _ = fseek(address, offset, whence.concrete)
}
public fun main() {
}
```
Compiling this generated the following error:
```
💣 Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value
Platform: x86_64 Linux (Ubuntu 24.04.3 LTS)
Thread 0 "hc" crashed:
0 Module.defineGenericValueArguments(_:in:) + 1870 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:283:42
281│ ) -> OrderedDictionary<GenericParameterDecl.ID, InstructionID> {
282│ let insertionSite = SourceRange.empty(at: self[monomorphized].site.start)
283│ let entry = self[monomorphized].entry!
│ ▲
284│
285│ var genericValues = OrderedDictionary<GenericParameterDecl.ID, InstructionID>()
1 Program.monomorphize(_:for:usedIn:) + 2926 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:133:50
131│ }
132│
133│ let rewrittenGenericValue = modules[target]!.defineGenericValueArguments(z, in: result)
│ ▲
134│ var monomorphizer = Monomorphizer(
135│ specialization: z, scopeOfUse: scopeOfUse,
2 Program.depolymorphize(project:from:definedIn:) + 1270 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:81:13
79│
80│ let z = base.canonical(s.specialization, in: modules[m]![f].scope(containing: i))
81│ let g = monomorphize(s.callee, for: z, usedIn: modules[m]![f].scope(containing: i))
│ ▲
82│ let new = modules[m]!.makeProject(
83│ s.projection, applying: g, specializedBy: .empty, to: s.operands, at: s.site)
3 Program.depolymorphize(_:definedIn:) + 1561 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:43:9
41│ depolymorphize(call: i, from: f, definedIn: m)
42│ case is Project:
43│ depolymorphize(project: i, from: f, definedIn: m)
│ ▲
44│ default:
45│ continue
4 Program.depolymorphize(_:) + 644 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:24:9
22│ // All non-generic functions are deploymorphized.
23│ if !f.isGeneric {
24│ depolymorphize(k, definedIn: m)
│ ▲
25│ continue
26│ }
5 Program.depolymorphize() + 133 in hc at /workspaces/hylo/Sources/IR/Analysis/Module+Depolymorphize.swift:10:7
8│ public mutating func depolymorphize() {
9│ for m in modules.keys {
10│ depolymorphize(m)
│ ▲
11│ }
12│ }
6 Driver.executeCommand(extending:reportingDiagnosticsTo:) + 5212 in hc at /workspaces/hylo/Sources/Driver/Driver.swift:321:8
319│
320│ logVerbose("begin depolymorphization pass.\n")
321│ ir.depolymorphize()
│ ▲
322│
323│ logVerbose("create LLVM target machine.\n")
7 closure #1 in Driver.run() + 91 in hc at /workspaces/hylo/Sources/Driver/Driver.swift:224:13
222│ do {
223│ _ = try log.capturingErrors { (ds) in
224│ try executeCommand(reportingDiagnosticsTo: &ds)
│ ▲
225│ }
226│ status = log.containsError ? ExitCode.failure : ExitCode.success
8 DiagnosticSet.capturingErrors<A>(thrownBy:) + 34 in hc at /workspaces/hylo/Sources/FrontEnd/DiagnosticSet.swift:52:18
50│ ) rethrows -> T? {
51│ do {
52│ return try action(&self)
│ ▲
53│ } catch let d as DiagnosticSet {
54│ assert(d.containsError, "non-error diagnostics were thrown")
9 Driver.run() + 90 in hc at /workspaces/hylo/Sources/Driver/Driver.swift:223:19
221│
222│ do {
223│ _ = try log.capturingErrors { (ds) in
│ ▲
224│ try executeCommand(reportingDiagnosticsTo: &ds)
225│ }
10 hc_main + 89 in hc at /workspaces/hylo/Sources/hc/main.swift:3:8
1│ import Driver
2│
3│ Driver.main()
│ ▲
4│
11 0x00007c7e1a9c41ca <unknown> in libc.so.6
12 0x00007c7e1a9c428b <unknown> in libc.so.6
...
Backtrace took 1.77s
Illegal instruction (core dumped)
```
3 条评论