Skip to content

Commit

Permalink
clean up system/arc (#20792)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Nov 9, 2022
1 parent cdb136f commit d8d0832
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions lib/system/arc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ In this new runtime we simplify the object layouts a bit: The runtime type
information is only accessed for the objects that have it and it's always
at offset 0 then. The ``ref`` object header is independent from the
runtime type and only contains a reference count.
Object subtyping is checked via the generated 'name'. This should have
comparable overhead to the old pointer chasing approach but has the benefit
that it works across DLL boundaries.
The generated name is a concatenation of the object names in the hierarchy
so that a subtype check becomes a substring check. For example::
type
ObjectA = object of RootObj
ObjectB = object of ObjectA
ObjectA's ``name`` is "|ObjectA|RootObj|".
ObjectB's ``name`` is "|ObjectB|ObjectA|RootObj|".
Now to check for ``x of ObjectB`` we need to check
for ``x.typ.name.endsWith("|ObjectB|ObjectA|RootObj|")``.
In the actual implementation, however, we could also use a
hash of ``package & "." & module & "." & name`` to save space.
]#

when defined(gcOrc):
Expand Down Expand Up @@ -227,22 +207,5 @@ template tearDownForeignThreadGc* =
## With `--gc:arc` a nop.
discard

proc memcmp(str1, str2: cstring, n: csize_t): cint {.importc, header: "<string.h>".}

func endsWith(s, suffix: cstring): bool {.inline.} =
let
sLen = s.len
suffixLen = suffix.len

if suffixLen <= sLen:
result = memcmp(cstring(addr s[sLen - suffixLen]), suffix, csize_t(suffixLen)) == 0

proc isObj(obj: PNimTypeV2, subclass: cstring): bool {.compilerRtl, inl.} =
result = endsWith(obj.name, subclass)

proc isObjDisplayCheck(source: PNimTypeV2, targetDepth: int16, token: uint32): bool {.compilerRtl, inline.} =
result = targetDepth <= source.depth and source.display[targetDepth] == token

proc chckObj(obj: PNimTypeV2, subclass: cstring) {.compilerRtl.} =
# checks if obj is of type subclass:
if not isObj(obj, subclass): sysFatal(ObjectConversionDefect, "invalid object conversion")

0 comments on commit d8d0832

Please sign in to comment.