@@ -17,12 +17,12 @@ import
17
17
intsets, strtabs, ast, astalgo, msgs, renderer, magicsys, types, idents,
18
18
strutils, options, lowerings, tables, modulegraphs,
19
19
lineinfos, parampatterns, sighashes, liftdestructors, optimizer,
20
- varpartitions, aliasanalysis, dfa
20
+ varpartitions, aliasanalysis, dfa, wordrecg
21
21
22
22
when defined (nimPreviewSlimSystem):
23
23
import std/ assertions
24
24
25
- from trees import exprStructuralEquivalent, getRoot
25
+ from trees import exprStructuralEquivalent, getRoot, whichPragma
26
26
27
27
type
28
28
Con = object
35
35
idgen: IdGenerator
36
36
body: PNode
37
37
otherUsage: TLineInfo
38
+ inUncheckedAssignSection: int
38
39
39
40
Scope = object # we do scope-based memory management.
40
41
# a scope is comparable to an nkStmtListExpr like
@@ -342,15 +343,16 @@ It is best to factor out piece of object that needs custom destructor into separ
342
343
return
343
344
344
345
# generate: if le != tmp: `=destroy`(le)
345
- let branchDestructor = produceDestructorForDiscriminator (c.graph, objType, leDotExpr[1 ].sym, n.info, c.idgen)
346
- let cond = newNodeIT (nkInfix, n.info, getSysType (c.graph, unknownLineInfo, tyBool))
347
- cond.add newSymNode (getMagicEqSymForType (c.graph, le.typ, n.info))
348
- cond.add le
349
- cond.add tmp
350
- let notExpr = newNodeIT (nkPrefix, n.info, getSysType (c.graph, unknownLineInfo, tyBool))
351
- notExpr.add newSymNode (createMagic (c.graph, c.idgen, " not" , mNot))
352
- notExpr.add cond
353
- result .add newTree (nkIfStmt, newTree (nkElifBranch, notExpr, c.genOp (branchDestructor, le)))
346
+ if c.inUncheckedAssignSection != 0 :
347
+ let branchDestructor = produceDestructorForDiscriminator (c.graph, objType, leDotExpr[1 ].sym, n.info, c.idgen)
348
+ let cond = newNodeIT (nkInfix, n.info, getSysType (c.graph, unknownLineInfo, tyBool))
349
+ cond.add newSymNode (getMagicEqSymForType (c.graph, le.typ, n.info))
350
+ cond.add le
351
+ cond.add tmp
352
+ let notExpr = newNodeIT (nkPrefix, n.info, getSysType (c.graph, unknownLineInfo, tyBool))
353
+ notExpr.add newSymNode (createMagic (c.graph, c.idgen, " not" , mNot))
354
+ notExpr.add cond
355
+ result .add newTree (nkIfStmt, newTree (nkElifBranch, notExpr, c.genOp (branchDestructor, le)))
354
356
result .add newTree (nkFastAsgn, le, tmp)
355
357
356
358
proc genWasMoved (c: var Con , n: PNode ): PNode =
@@ -877,14 +879,33 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode; tmpFlags = {sfSing
877
879
nkTypeOfExpr, nkMixinStmt, nkBindStmt:
878
880
result = n
879
881
880
- of nkStringToCString, nkCStringToString, nkChckRangeF, nkChckRange64, nkChckRange, nkPragmaBlock :
882
+ of nkStringToCString, nkCStringToString, nkChckRangeF, nkChckRange64, nkChckRange:
881
883
result = shallowCopy (n)
882
884
for i in 0 ..< n.len:
883
885
result [i] = p (n[i], c, s, normal)
884
886
if n.typ != nil and hasDestructor (c, n.typ):
885
887
if mode == normal:
886
888
result = ensureDestruction (result , n, c, s)
887
889
890
+ of nkPragmaBlock:
891
+ var inUncheckedAssignSection = 0
892
+ let pragmaList = n[0 ]
893
+ for pi in pragmaList:
894
+ if whichPragma (pi) == wCast:
895
+ case whichPragma (pi[1 ])
896
+ of wUncheckedAssign:
897
+ inUncheckedAssignSection = 1
898
+ else :
899
+ discard
900
+ result = shallowCopy (n)
901
+ inc c.inUncheckedAssignSection, inUncheckedAssignSection
902
+ for i in 0 ..< n.len:
903
+ result [i] = p (n[i], c, s, normal)
904
+ dec c.inUncheckedAssignSection, inUncheckedAssignSection
905
+ if n.typ != nil and hasDestructor (c, n.typ):
906
+ if mode == normal:
907
+ result = ensureDestruction (result , n, c, s)
908
+
888
909
of nkHiddenSubConv, nkHiddenStdConv, nkConv:
889
910
# we have an "ownership invariance" for all constructors C(x).
890
911
# See the comment for nkBracket construction. If the caller wants
0 commit comments