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

std/json: remove macro type API usage #825

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/ast/ast_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ proc hasNilSon*(n: PNode): bool =
proc containsNode*(n: PNode, kinds: TNodeKinds): bool =
if n == nil: return
case n.kind
of nkEmpty..nkNilLit: result = n.kind in kinds
of nkEmpty..nkNilLit, nkError: result = n.kind in kinds
saem marked this conversation as resolved.
Show resolved Hide resolved
else:
for i in 0..<n.len:
if n.kind in kinds or containsNode(n[i], kinds): return true
Expand Down
1 change: 0 additions & 1 deletion compiler/front/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasStyleChecks")
defineSymbol("nimToOpenArrayCString")
defineSymbol("nimHasUsed")
defineSymbol("nimFixedForwardGeneric")
defineSymbol("nimnomagic64")
defineSymbol("nimNewShiftOps")
defineSymbol("nimHasCursor")
Expand Down
8 changes: 2 additions & 6 deletions compiler/sem/semfields.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ proc semForObjectFields(c: TFieldsCtx, typ, forLoop, father: PNode) =
if call.len > 2:
localReport(c.c.config, forLoop.info, reportAst(
rsemParallelFieldsDisallowsCase, call))

return
# iterate over the selector:
semForObjectFields(c, typ[0], forLoop, father)
Expand All @@ -102,7 +101,6 @@ proc semForObjectFields(c: TFieldsCtx, typ, forLoop, father: PNode) =
of nkRecList:
for t in items(typ):
semForObjectFields(c, t, forLoop, father)

else:
semReportIllformedAst(c.c.config, typ, {
nkRecList, nkRecCase, nkNilLit, nkSym})
Expand All @@ -114,7 +112,6 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
var trueSymbol = systemModuleSym(c.graph, getIdent(c.cache, "true"))
if trueSymbol == nil:
localReport(c.config, n.info, reportStr(rsemSystemNeeds, "true"))

trueSymbol = newSym(
skUnknown, getIdent(c.cache, "true"),
nextSymId c.idgen, getCurrOwner(c), n.info)
Expand All @@ -130,14 +127,12 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
rsemWrongNumberOfVariables,
expected = call.len - 1 + ord(m == mFieldPairs),
got = n.len - 2))

return result

const skippedTypesForFields = abstractVar - {tyTypeDesc} + tyUserTypeClasses
var tupleTypeA = skipTypes(call[1].typ, skippedTypesForFields)
if tupleTypeA.kind notin {tyTuple, tyObject}:
localReport(c.config, n.info, reportSem(rsemNoObjectOrTupleType))

return result
for i in 1..<call.len:
let calli = call[i]
Expand All @@ -146,7 +141,6 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
let r = typeMismatch(c.config, calli.info, tupleTypeA, tupleTypeB, calli)
if r.kind == nkError:
localReport(c.config, r)

inc(c.p.nestedLoopCounter)
if tupleTypeA.kind == tyTuple:
var loopBody = n[^1]
Expand Down Expand Up @@ -180,3 +174,5 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
stmts.add(b)
else:
result = stmts
if containsNode(stmts, {nkError}):
result = c.config.wrapError(result)
7 changes: 4 additions & 3 deletions compiler/sem/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1638,12 +1638,13 @@ proc semFor(c: PContext, n: PNode; flags: TExprFlags): PNode =
n[^2] = implicitIterator(c, "pairs", n[^2])
else:
localReport(c.config, n[^2], reportSem(rsemForExpectsIterator))

result = semForVars(c, n, flags)
else:
result = semForVars(c, n, flags)
# propagate any enforced VoidContext:
if n[^1].typ == c.enforceVoidContext:
if result.kind == nkError:
discard # do nothing
elif n[^1].typ == c.enforceVoidContext:
# propagate any enforced VoidContext:
result.typ = c.enforceVoidContext
elif efInTypeof in flags:
result.typ = result.lastSon.typ
Expand Down
4 changes: 1 addition & 3 deletions compiler/sem/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -959,15 +959,13 @@ proc addInheritedFieldsAux(c: PContext, check: var IntSet, pos: var int,
case n.kind
of nkRecCase:
c.config.internalAssert(n[0].kind == nkSym, n.info, "addInheritedFieldsAux")

addInheritedFieldsAux(c, check, pos, n[0])
for i in 1..<n.len:
case n[i].kind
of nkOfBranch, nkElse:
addInheritedFieldsAux(c, check, pos, lastSon(n[i]))
else:
internalError(c.config, n.info, "addInheritedFieldsAux(record case branch)")

of nkRecList, nkRecWhen, nkElifBranch, nkElse:
for i in int(n.kind == nkElifBranch)..<n.len:
addInheritedFieldsAux(c, check, pos, n[i])
Expand All @@ -986,7 +984,7 @@ proc skipGenericInvocation(t: PType): PType {.inline.} =

proc addInheritedFields(c: PContext, check: var IntSet, pos: var int,
obj: PType) =
assert obj.kind == tyObject
assert obj.kind == tyObject, $obj.kind
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert obj.kind == tyObject, $obj.kind
assert obj.kind == tyObject

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be easier to debug by leaving the kind in there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, although I personally think that assertions with $x are visually a bit noisy, hence my suggestion. It's nothing critical, however, and I'm fine with it staying as it is.

It's nothing for this PR, but since asserting that the discriminator of some object has a certain value is a common pattern in the compiler, I think that adding a new idiom assertKind (which automatically renders the value on failure) would make sense.

if (obj.len > 0) and (obj[0] != nil):
addInheritedFields(c, check, pos, obj[0].skipGenericInvocation)
addInheritedFieldsAux(c, check, pos, obj.n)
Expand Down
Loading
Loading