mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-01 19:33:42 +00:00
IC: undo gratuitous rewrites the bulk migration made
Reading the previous commit's diff, as promised, turned up edits that were semantically neutral but said something false: a regex pass had rewritten `t.n == nil` (a TYPE's record tree) as `t.n.isNilNode`, done the same inside the grinder where both sides are `PNode`s, and relabelled `asgnComplexity` and `containsOpaqueImportcFieldAux` as `AnyNode` when both walk `PType.n` and can never see a cursor. It also edited a comment. None of it changed behaviour — `isNilNode` on a `PNode` is `== nil` — but it made unrelated code look like it participates in the seam, which is exactly the kind of noise that makes a later reader think the type-record walkers are migration candidates when the module doc says they are not. Reverted, and the two type-record procs now say why they stay. Verified: both builds compile; cursor-driven and `PNode`-driven output still identical (50/50). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XEF7FJvUkGKvG9LSGuEaNR
This commit is contained in:
@@ -68,7 +68,7 @@ proc preventNrvo(p: BProc; dest, le: PNode; ri: AnyNode): bool =
|
||||
return true
|
||||
|
||||
result = false
|
||||
if not le.isNilNode:
|
||||
if le != nil:
|
||||
for r in sonsFrom(ri, 1):
|
||||
# `isPartOf` compares field symbols by identity and so has not moved to
|
||||
# the seam; `origin` hands it the same nodes it always compared.
|
||||
@@ -79,7 +79,7 @@ proc preventNrvo(p: BProc; dest, le: PNode; ri: AnyNode): bool =
|
||||
locationEscapes(p, le, p.nestedTryStmts.len > 0):
|
||||
message(p.config, le.info, warnObservableStores, $le)
|
||||
# bug #19613 prevent dangerous aliasing too:
|
||||
if not dest.isNilNode and dest != le:
|
||||
if dest != nil and dest != le:
|
||||
for r in sonsFrom(ri, 1):
|
||||
if isPartOf(dest, origin(r), {pfStructural}) != arNo: return true
|
||||
|
||||
|
||||
@@ -186,8 +186,10 @@ proc genRefAssign(p: BProc, dest, src: TLoc) =
|
||||
let rs = rdLoc(src)
|
||||
p.s(cpsStmts).addCallStmt(fnName, cCast(ptrType(CPointer), rad), rs)
|
||||
|
||||
proc asgnComplexity(n: AnyNode): int =
|
||||
if not n.isNilNode:
|
||||
proc asgnComplexity(n: PNode): int =
|
||||
## Walks a TYPE's record tree (`PType.n`), never a body, so it is not a
|
||||
## migration candidate — see the type-record-tree blocker in `bnode`.
|
||||
if n != nil:
|
||||
case n.kind
|
||||
of nkSym: result = 1
|
||||
of nkRecCase:
|
||||
@@ -1867,7 +1869,7 @@ proc genFieldObjConstr[F: AnyNode; V: AnyNode](p: BProc; ty: PType; useTemp, isR
|
||||
let field = lookupFieldAgain(p, ty, nField.sym, tmp2.snippet)
|
||||
if field.loc.snippet == "": fillObjectFields(p.module, ty)
|
||||
if field.loc.snippet == "": internalError(p.config, info, "genFieldObjConstr")
|
||||
if not check.isNilNode and optFieldCheck in p.options:
|
||||
if check != nil and optFieldCheck in p.options:
|
||||
genFieldCheck(p, check, r, field, ty)
|
||||
tmp2.snippet = dotField(tmp2.snippet, field.loc.snippet)
|
||||
if useTemp:
|
||||
@@ -3872,14 +3874,15 @@ proc isOpaqueImportcType(t: PType): bool =
|
||||
if tfCompleteStruct notin t.flags:
|
||||
if tfIncompleteStruct in t.flags:
|
||||
return true
|
||||
if t.kind == tyObject and (t.n.isNilNode or not t.n.hasSons):
|
||||
if t.kind == tyObject and (t.n == nil or not t.n.hasSons):
|
||||
return true
|
||||
return false
|
||||
|
||||
proc containsOpaqueImportcField(typ: PType): bool
|
||||
|
||||
proc containsOpaqueImportcFieldAux(t: PType; n: AnyNode): bool =
|
||||
if n.isNilNode: return false
|
||||
proc containsOpaqueImportcFieldAux(t: PType; n: PNode): bool =
|
||||
## Also a type-record walk; `n` is `t.n`.
|
||||
if n == nil: return false
|
||||
case n.kind
|
||||
of nkRecList:
|
||||
for child in sons(n):
|
||||
|
||||
@@ -135,11 +135,11 @@ proc signatureHasMetaType*(t: PType; depth: int = 0): bool =
|
||||
# `HashList[T, N]`, …) is carried as a `tyStatic` node inside the otherwise
|
||||
# fully-concrete `tyGenericInst`, but it is NOT meta: the routine is a normal
|
||||
# runtime routine the owner must emit. Only an UNRESOLVED `static T` parameter
|
||||
# (no bound value, `t.n.isNilNode`) is meta. Without this, every routine whose
|
||||
# (no bound value, `t.n == nil`) is meta. Without this, every routine whose
|
||||
# signature touches a `static`-parameterized generic instance (the bulk of
|
||||
# the SSZ/`MDigest` API) is dropped from the owned-routine seeding and ends up
|
||||
# an undefined reference at link (mirrors the tyGenericBody case above).
|
||||
return t.n.isNilNode
|
||||
return t.n == nil
|
||||
if t.kind in {tyTyped, tyUntyped, tyTypeDesc, tyGenericParam,
|
||||
tyAnything, tyFromExpr, tyError}:
|
||||
return true
|
||||
@@ -1748,7 +1748,7 @@ when defined(newIcBackend):
|
||||
# `(ht . <sym>)` type difference. Only a subtree that clean is handed to
|
||||
# `grindPredicates` — see the descent below for why.
|
||||
result = true
|
||||
if a.isNilNode:
|
||||
if a == nil:
|
||||
if not c.isNilNode: bail("nil-ness", "not-nil", "nil")
|
||||
return
|
||||
if c.isNilNode: bail("nil-ness", "nil", "not-nil")
|
||||
@@ -1891,7 +1891,7 @@ when defined(newIcBackend):
|
||||
## disagreement with the original, so both directions are checked by the one
|
||||
## oracle rather than by a hand-written comparator that could agree with the
|
||||
## bug.
|
||||
if bnodeGrind == 0 or body.isNilNode: return
|
||||
if bnodeGrind == 0 or body == nil: return
|
||||
let htBefore = tolHtNil
|
||||
let fieldBefore = tolFieldSym
|
||||
|
||||
@@ -1908,7 +1908,7 @@ when defined(newIcBackend):
|
||||
# Asserted rather than assumed, with `==` on the reference: an equal copy
|
||||
# would not do.
|
||||
proc grindOrigins(enc: var BridgeBuf; c: BNode; a: PNode; path: string) =
|
||||
if a.isNilNode: return
|
||||
if a == nil: return
|
||||
# Through the AMBIENT accessor (`bnode.origin`, via `currentNav`), which
|
||||
# is the one a migrated generator proc will call from inside `initLoc` —
|
||||
# not the direct `originOf`, which would test a path nothing uses.
|
||||
@@ -1988,7 +1988,7 @@ when defined(newIcBackend):
|
||||
let ast = prc.ast
|
||||
if ast == nil or ast.safeLen <= bodyPos: return
|
||||
let body = son(ast, bodyPos)
|
||||
if body.isNilNode: return
|
||||
if body == nil: return
|
||||
var scope = default(BodyScope)
|
||||
var viaCursor = default(BNode)
|
||||
if not lazyBodyBNode(body, scope, viaCursor): return
|
||||
|
||||
Reference in New Issue
Block a user