Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove shallowCopy for ARC/ORC #20070

Merged
merged 14 commits into from
Jul 26, 2022
10 changes: 8 additions & 2 deletions compiler/btrees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ proc copyHalf[Key, Val](h, result: Node[Key, Val]) =
result.links[j] = h.links[Mhalf + j]
else:
for j in 0..<Mhalf:
shallowCopy(result.vals[j], h.vals[Mhalf + j])
when defined(gcArc) or defined(gcOrc):
result.vals[j] = h.vals[Mhalf + j]
ringabout marked this conversation as resolved.
Show resolved Hide resolved
else:
shallowCopy(result.vals[j], h.vals[Mhalf + j])

proc split[Key, Val](h: Node[Key, Val]): Node[Key, Val] =
## split node in half
Expand All @@ -88,7 +91,10 @@ proc insert[Key, Val](h: Node[Key, Val], key: Key, val: Val): Node[Key, Val] =
if less(key, h.keys[j]): break
inc j
for i in countdown(h.entries, j+1):
shallowCopy(h.vals[i], h.vals[i-1])
when defined(gcArc) or defined(gcOrc):
h.vals[i] = move h.vals[i-1]
else:
shallowCopy(h.vals[i], h.vals[i-1])
h.vals[j] = val
else:
var newLink: Node[Key, Val] = nil
Expand Down
11 changes: 9 additions & 2 deletions compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,18 @@ proc setDirtyFile*(conf: ConfigRef; fileIdx: FileIndex; filename: AbsoluteFile)

proc setHash*(conf: ConfigRef; fileIdx: FileIndex; hash: string) =
assert fileIdx.int32 >= 0
shallowCopy(conf.m.fileInfos[fileIdx.int32].hash, hash)
when defined(gcArc) or defined(gcOrc):
conf.m.fileInfos[fileIdx.int32].hash = hash
else:
shallowCopy(conf.m.fileInfos[fileIdx.int32].hash, hash)


proc getHash*(conf: ConfigRef; fileIdx: FileIndex): string =
assert fileIdx.int32 >= 0
shallowCopy(result, conf.m.fileInfos[fileIdx.int32].hash)
when defined(gcArc) or defined(gcOrc):
result = conf.m.fileInfos[fileIdx.int32].hash
else:
shallowCopy(result, conf.m.fileInfos[fileIdx.int32].hash)

proc toFullPathConsiderDirty*(conf: ConfigRef; fileIdx: FileIndex): AbsoluteFile =
if fileIdx.int32 < 0:
Expand Down
10 changes: 8 additions & 2 deletions compiler/nimfix/prettybase.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent
let last = first+identLen(line, first)-1
if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
when defined(gcArc) or defined(gcOrc):
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
else:
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
conf.m.fileInfos[info.fileIndex.int32].dirty = true
#if newSym.s == "File": writeStackTrace()

Expand All @@ -35,5 +38,8 @@ proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
if line[first] != '#': inc first

var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
when defined(gcArc) or defined(gcOrc):
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
else:
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
conf.m.fileInfos[info.fileIndex.int32].dirty = true
5 changes: 4 additions & 1 deletion compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ proc processCompile(c: PContext, n: PNode) =
n[i] = c.semConstExpr(c, n[i])
case n[i].kind
of nkStrLit, nkRStrLit, nkTripleStrLit:
shallowCopy(result, n[i].strVal)
when defined(gcArc) or defined(gcOrc):
result = n[i].strVal
else:
shallowCopy(result, n[i].strVal)
else:
localError(c.config, n.info, errStringLiteralExpected)
result = ""
Expand Down
8 changes: 6 additions & 2 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ template decodeBx(k: untyped) {.dirty.} =
let rbx = instr.regBx - wordExcess
ensureKind(k)

template move(a, b: untyped) {.dirty.} = system.shallowCopy(a, b)
# XXX fix minor 'shallowCopy' overloading bug in compiler
template move(a, b: untyped) {.dirty.} =
when defined(gcArc) or defined(gcOrc):
a = move b
else:
system.shallowCopy(a, b)
# XXX fix minor 'shallowCopy' overloading bug in compiler

proc derefPtrToReg(address: BiggestInt, typ: PType, r: var TFullReg, isAssign: bool): bool =
# nim bug: `isAssign: static bool` doesn't work, giving odd compiler error
Expand Down
5 changes: 4 additions & 1 deletion lib/pure/asynchttpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ proc processRequest(
# \n
request.headers.clear()
request.body = ""
request.hostname.shallowCopy(address)
when defined(gcArc) or defined(gcOrc):
request.hostname = address
ringabout marked this conversation as resolved.
Show resolved Hide resolved
else:
request.hostname.shallowCopy(address)
assert client != nil
request.client = client

Expand Down
10 changes: 8 additions & 2 deletions lib/pure/marshal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ proc store*[T](s: Stream, data: T) =

var stored = initIntSet()
var d: T
shallowCopy(d, data)
when defined(gcArc) or defined(gcOrc):
d = data
ringabout marked this conversation as resolved.
Show resolved Hide resolved
else:
shallowCopy(d, data)
storeAny(s, toAny(d), stored)

proc loadVM[T](typ: typedesc[T], x: T): string =
Expand All @@ -321,7 +324,10 @@ proc `$$`*[T](x: T): string =
else:
var stored = initIntSet()
var d: T
shallowCopy(d, x)
when defined(gcArc) or defined(gcOrc):
d = x
ringabout marked this conversation as resolved.
Show resolved Hide resolved
else:
shallowCopy(d, x)
var s = newStringStream()
storeAny(s, toAny(d), stored)
result = s.data
Expand Down
31 changes: 18 additions & 13 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,16 @@ proc low*(x: string): int {.magic: "Low", noSideEffect.}
## var str = "Hello world!"
## low(str) # => 0

proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
## Use this instead of `=` for a `shallow copy`:idx:.
##
## The shallow copy only changes the semantics for sequences and strings
## (and types which contain those).
##
## Be careful with the changed semantics though!
## There is a reason why the default assignment does a deep copy of sequences
## and strings.
##
## .. warning:: `shallowCopy` does a deep copy with ARC/ORC.
when not defined(gcArc) and not defined(gcOrc):
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
## Use this instead of `=` for a `shallow copy`:idx:.
##
## The shallow copy only changes the semantics for sequences and strings
## (and types which contain those).
##
## Be careful with the changed semantics though!
## There is a reason why the default assignment does a deep copy of sequences
## and strings.

# :array|openArray|string|seq|cstring|tuple
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
Expand All @@ -494,7 +493,10 @@ proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} =
discard
proc `=sink`*[T](x: var T; y: T) {.inline, magic: "Asgn".} =
## Generic `sink`:idx: implementation that can be overridden.
shallowCopy(x, y)
when defined(gcArc) or defined(gcOrc):
x = move y
ringabout marked this conversation as resolved.
Show resolved Hide resolved
else:
shallowCopy(x, y)

when defined(nimHasTrace):
proc `=trace`*[T](x: var T; env: pointer) {.inline, magic: "Trace".} =
Expand Down Expand Up @@ -2852,7 +2854,10 @@ when hasAlloc or defined(nimscript):
setLen(x, xl+item.len)
var j = xl-1
while j >= i:
shallowCopy(x[j+item.len], x[j])
when defined(gcArc) or defined(gcOrc):
x[j+item.len] = move x[j]
else:
shallowCopy(x[j+item.len], x[j])
dec(j)
j = 0
while j < item.len:
Expand Down