diff --git a/compiler/nir/types2ir.nim b/compiler/nir/types2ir.nim index 2cea140636..b6486f3702 100644 --- a/compiler/nir/types2ir.nim +++ b/compiler/nir/types2ir.nim @@ -7,19 +7,19 @@ # distribution, for details about the copyright. # -import std / [assertions, tables] -import ".." / [ast, types, options] +import std / [assertions, tables, sets] +import ".." / [ast, types, options, sighashes, modulegraphs] import nirtypes type Context = object processed: Table[ItemId, TypeId] + recursionCheck: HashSet[ItemId] g: TypeGraph conf: ConfigRef -proc mangle(t: PType): string = - # XXX Improve! - result = $t +proc mangle(c: var Context; t: PType): string = + result = $sighashes.hashType(t, c.conf) template cached(c: var Context; t: PType; body: untyped) = result = c.processed.getOrDefault(t.itemId) @@ -79,16 +79,19 @@ proc objectToIr(c: var Context; t: PType): TypeId = collectFieldTypes c, t.n, fieldTypes let obj = openType(c.g, ObjectDecl) # XXX Inheritance?! - c.g.addName mangle t + c.g.addName mangle(c, t) objectToIr c, t.n, fieldTypes, unionId result = sealType(c.g, obj) +proc objectHeaderToIr(c: var Context; t: PType): TypeId = + result = c.g.nominalType(ObjectTy, mangle(c, t)) + proc tupleToIr(c: var Context; t: PType): TypeId = var fieldTypes = newSeq[TypeId](t.len) for i in 0..