8787 StructField * = object
8888 # # Struct/union field description.
8989 ident: LitId
90- offset: IntVal
9190 align* : int16
9291 extra: uint16
9392 typ* : TypeId
@@ -542,24 +541,24 @@ proc open(b: var StructBuilder, kind: TypeKind): StructBuilder =
542541 swap (result .fields, b.fields) # temporarily take over the buffer
543542 result .header = TypeHeader (kind: kind)
544543
545- proc addField (b: var StructBuilder , env: var TypeEnv , offset: IntVal ,
544+ proc addField (b: var StructBuilder , env: var TypeEnv ,
546545 typ: TypeId ; name = " " ; mangle = true ) =
547546 # # Adds a field declaration. `typ` is the type, `name` the name, and `mangle`
548547 # # indicates whether the name should be mangled.
549548 inc b.header.b
550549 if name.len > 0 :
551- b.fields.add StructField (typ: typ, offset: offset,
552- ident: env.idents.getOrIncl (name),
553- extra: (if mangle: MangleFlag else : 0 ))
550+ b.fields.add StructField (typ: typ,
551+ ident: env.idents.getOrIncl (name),
552+ extra: (if mangle: MangleFlag else : 0 ))
554553 else :
555- b.fields.add StructField (typ: typ, offset: offset )
554+ b.fields.add StructField (typ: typ)
556555
557- proc addField (b: var StructBuilder , offset: IntVal , typ: TypeId ) =
556+ proc addField (b: var StructBuilder , typ: TypeId ) =
558557 inc b.header.b
559- b.fields.add StructField (typ: typ, offset: offset )
558+ b.fields.add StructField (typ: typ)
560559
561560proc addField (b: var StructBuilder , env: var TypeEnv , s: PSym , typ: TypeId ) =
562- var field = StructField (typ: typ, offset: env. toIntVal (s.offset),
561+ var field = StructField (typ: typ,
563562 align: s.alignment.int16 )
564563 if {sfImportc, sfExportc} * s.flags == {}:
565564 field.ident = env.idents.getOrIncl (s.name.s)
@@ -670,10 +669,10 @@ proc recordToMir(env: var TypeEnv, str: var StructBuilder, n: PNode,
670669 recurse (sub, child)
671670 let x = tu.close (env, sub)
672671 # add as field to the tagged union:
673- tu.addField (IntVal ( 0 ), env.newType (x))
672+ tu.addField (env.newType (x))
674673
675674 let x = str.close (env, tu)
676- str.addField (env.toIntVal (n[ 0 ].sym.offset), env. newType (x))
675+ str.addField (env.newType (x))
677676 else :
678677 unreachable (n.kind)
679678
@@ -759,19 +758,10 @@ proc typeToMir(env: var TypeEnv, t: PType; canon = false, unique=true): HeaderId
759758 of tyTuple:
760759 var tup = openStruct (env.toIntVal (t.size), t.align)
761760 if t.len == 0 :
762- tup.addField (IntVal 0 , CharType )
763- elif t.size < 0 :
764- # the size contains some incomplete imported types; no offsets can be
765- # computed
766- for i in 0 ..< t.len:
767- tup.addField (env, IntVal 0 , typeref t[i])
761+ tup.addField (CharType )
768762 else :
769- var offset: BiggestInt = 0
770763 for i in 0 ..< t.len:
771- let mask = t[i].align - 1
772- offset = (offset + mask) and not (mask) # align the offset
773- tup.addField (env, env.toIntVal (offset), typeref t[i])
774- offset += t[i].size
764+ tup.addField (env, typeref t[i])
775765
776766 tup.close (env)
777767 of tyObject:
@@ -797,7 +787,7 @@ proc typeToMir(env: var TypeEnv, t: PType; canon = false, unique=true): HeaderId
797787 let ptrTyp = env.newType (single (tkPtr, rtti.typ))
798788 # the type field is at position -1
799789 rec = openStruct (size, t.align, - 1 )
800- rec.addField (env, IntVal 0 , ptrTyp, " m_type" )
790+ rec.addField (env, ptrTyp, " m_type" )
801791 else :
802792 # legacy support for backends not yet using RTTI fields
803793 rec = openStruct (size, t.align)
@@ -809,7 +799,7 @@ proc typeToMir(env: var TypeEnv, t: PType; canon = false, unique=true): HeaderId
809799
810800 if isEmpty:
811801 # struct-like types must always have at least *one* field
812- rec.addField (IntVal 0 , CharType )
802+ rec.addField (CharType )
813803
814804 # object/union types are not de-duplicated
815805 rec.close (env, unique)
@@ -979,30 +969,29 @@ proc lowerType(env: var TypeEnv, graph: ModuleGraph, id: HeaderId): HeaderId =
979969 bu.addParam (flags, typ)
980970
981971 env.buildStruct (h.size, h.align, bu):
982- bu.addField (env, IntVal 0 , prc, " ClP_0" , mangle= false )
972+ bu.addField (env, prc, " ClP_0" , mangle= false )
983973 # XXX: the type of the environment pointer should be a ``RootRef``
984- bu.addField (env, IntVal graph.config.target.ptrSize,
985- PointerType , " ClE_0" , mangle= false )
974+ bu.addField (env, PointerType , " ClE_0" , mangle= false )
986975 of tkOpenArray:
987976 # -> (ptr UncheckedArray[T], int)
988977 let ptrTyp = env.newPtrTy (env.newUncheckedArrayTy (h.elem))
989978
990979 env.buildStruct (h.size, h.align, bu):
991- bu.addField (env, IntVal 0 , ptrTyp)
992- bu.addField (env, IntVal graph.config.target.ptrSize, env.sizeType)
980+ bu.addField (env, ptrTyp)
981+ bu.addField (env, env.sizeType)
993982 of tkSeq:
994983 # -> (cap: int, data: ptr (int, UncheckedArray[T]))
995984 let
996985 dataType = env.newUncheckedArrayTy (h.elem)
997986 # the payload type's name is inferred from the body
998987 payload = env.buildStruct (h.size, h.align, bu):
999- bu.addField (env, IntVal 0 , env.sizeType, " cap" )
1000- bu.addField (env, IntVal graph.config.target.intSize, dataType, " data" )
988+ bu.addField (env, env.sizeType, " cap" )
989+ bu.addField (env, dataType, " data" )
1001990 ppTyp = env.newPtrTy (env.newType (payload))
1002991
1003992 env.buildStruct (h.size, h.align, bu):
1004- bu.addField (env, IntVal 0 , env.sizeType, " len" )
1005- bu.addField (env, IntVal graph.config.target.intSize, ppTyp, " p" )
993+ bu.addField (env, env.sizeType, " len" )
994+ bu.addField (env, ppTyp, " p" )
1006995 else :
1007996 id
1008997
0 commit comments