0

I was building a class for a sqlite library, and suddenly the compiler hang forever.

I finally get a test case for it, and found is related to a dictionary parsing. This is the minimal code:

import Foundation import GRDB

class DeudaCliente : Record {
    var id: Int64
    var codigo: String
    var nombre: String
    var cobro: String
    var direccion: String
    var telefono: String
    var orden: Int32
    var calificacion: String
    var fechaIngreso: NSDate
    var fecha: NSDate
    var capital: NSDecimalNumber
    var interes: NSDecimalNumber
    var cuota: NSDecimalNumber
    var valor: NSDecimalNumber
    var valorPagar: NSDecimalNumber
    var saldo: NSDecimalNumber
    var atrasados: Int32


    /// Initialize from a database row
    required init(_ row: Row) {
        id = row.value(named: "id")
        codigo = row.value(named: "codigo")
        nombre = row.value(named: "nombre")
        cobro = row.value(named: "cobro")
        direccion = row.value(named: "direccion")
        telefono = row.value(named: "telefono")
        orden = row.value(named: "orden")
        calificacion = row.value(named: "calificacion")
        fechaIngreso = row.value(named: "fechaIngreso")
        fecha = row.value(named: "fecha")
        interes = row.value(named: "interes")
        cuota = row.value(named: "cuota")
        valor = row.value(named: "valor")
        valorPagar = row.value(named: "valorPagar")
        saldo = row.value(named: "saldo")
        capital = row.value(named: "capital")
        atrasados = row.value(named: "atrasados")

        super.init(row)
    }

    /// The values persisted in the database
    override var persistentDictionary: [String: DatabaseValueConvertible?]
    {
        return  [
            "id": id,
            "nombre": nombre,
            "codigo": codigo,
            "cobro": cobro,
            "direccion": direccion,
            "telefono": telefono,
            "orden": orden,
            "calificacion": calificacion,
            "fechaIngreso": fechaIngreso,
            "fecha": fecha, //THE COMPILER SLOWDOWN HERE
            "interes": interes,
            "cuota": cuota, //THE COMPILER HANG HERE
            "valor": valor,
            "valorPagar": valorPagar,
            "saldo": saldo,
            "capital": capital,
            "atrasados": atrasados
        ]
    }
}

The weird thing is I change the values after the key "fecha" for scalars like 1, "a", etc the compiler work.

Also: The indexing take forever too after "cuota" and the service SourceKitService start to report +300% CPU, Increasing memory (I have count up to 6GB)

This on El capitan, xcode Version 7.2.1 (7C1002)

Gwendal Roué
  • 3,949
  • 15
  • 34
mamcx
  • 15,916
  • 26
  • 101
  • 189
  • Have you tried saying something like `fecha as DatabaseValueConvertible`? The compiler is probably going crazy over type inference for some reason. – zneak Feb 10 '16 at 21:04
  • So don't do that. What's the question? The Swift compiler's dislike of big literals is well known. Avoid them and move on. – matt Feb 10 '16 at 21:31
  • Build the dictionary in several steps. – matt Feb 10 '16 at 21:33

1 Answers1

0

I'm the author of GRDB. Read my answer on https://github.com/groue/GRDB.swift/issues/21

I guess the dictionary is too long for the Swift compiler. You can try to break it, or build it key after key as in:

var dic: [String: DatabaseValueConvertible?] = [:]
dic["id"] = id
dic["nombre"] = nombre
// etc.
return dic
mamcx
  • 15,916
  • 26
  • 101
  • 189
Gwendal Roué
  • 3,949
  • 15
  • 34