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

Pr fix 14179 nim dump slow #304

Draft
wants to merge 15 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

- Added high-level `asyncnet.sendTo` and `asyncnet.recvFrom`. UDP functionality.

- `paramCount` & `paramStr` are now defined in os.nim instead of nimscript.nim for nimscript/nimble.
- `dollars.$` now works for unsigned ints with `nim js`

- Improvements to the `bitops` module, including bitslices, non-mutating versions
Expand Down Expand Up @@ -111,6 +110,8 @@
- new module `std/jsonutils` with hookable `jsonTo,toJson,fromJson` for json serialization/deserialization of custom types.

- new proc `heapqueue.find[T](heap: HeapQueue[T], x: T): int` to get index of element ``x``.
- Add `rstgen.rstToLatex` convenience proc for `renderRstToOut` and `initRstGenerator` with `outLatex` output.


## Language changes
- In the newruntime it is now allowed to assign discriminator field without restrictions as long as case object doesn't have custom destructor. Discriminator value doesn't have to be a constant either. If you have custom destructor for case object and you do want to freely assign discriminator fields, it is recommended to refactor object into 2 objects like this:
Expand Down
10 changes: 5 additions & 5 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ type
# instantiation and prior to this it has the potential to
# be any type.

tyOpt
# Builtin optional type
tyOptDeprecated
# deadcode: was `tyOpt`, Builtin optional type

tyVoid
# now different from tyEmpty, hurray!
Expand Down Expand Up @@ -658,7 +658,7 @@ type
mNewString, mNewStringOfCap, mParseBiggestFloat,
mMove, mWasMoved, mDestroy,
mDefault, mUnown, mAccessEnv, mReset,
mArray, mOpenArray, mRange, mSet, mSeq, mOpt, mVarargs,
mArray, mOpenArray, mRange, mSet, mSeq, mVarargs,
mRef, mPtr, mVar, mDistinct, mVoid, mTuple,
mOrdinal,
mInt, mInt8, mInt16, mInt32, mInt64,
Expand Down Expand Up @@ -1492,7 +1492,7 @@ proc isGCedMem*(t: PType): bool {.inline.} =
t.kind == tyProc and t.callConv == ccClosure

proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) =
const HaveTheirOwnEmpty = {tySequence, tyOpt, tySet, tyPtr, tyRef, tyProc}
const HaveTheirOwnEmpty = {tySequence, tySet, tyPtr, tyRef, tyProc}
owner.flags = owner.flags + (elem.flags * {tfHasMeta, tfTriggersCompileTime})
if tfNotNil in elem.flags:
if owner.kind in {tyGenericInst, tyGenericBody, tyGenericInvocation}:
Expand All @@ -1505,7 +1505,7 @@ proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) =
if mask != {} and propagateHasAsgn:
let o2 = owner.skipTypes({tyGenericInst, tyAlias, tySink})
if o2.kind in {tyTuple, tyObject, tyArray,
tySequence, tyOpt, tySet, tyDistinct, tyOpenArray, tyVarargs}:
tySequence, tySet, tyDistinct, tyOpenArray, tyVarargs}:
o2.flags.incl mask
owner.flags.incl mask

Expand Down
2 changes: 1 addition & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope =
if result != nil: return
result = getTypePre(m, typ, sig)
if result != nil: return
let concrete = typ.skipTypes(abstractInst + {tyOpt})
let concrete = typ.skipTypes(abstractInst)
case concrete.kind
of tySequence, tyTuple, tyObject:
result = getTypeName(m, typ, sig)
Expand Down
2 changes: 1 addition & 1 deletion compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ proc writeVersionInfo(conf: ConfigRef; pass: TCmdLinePass) =
CPU[conf.target.hostCPU].name, CompileDate]),
{msgStdout})

const gitHash = gorge("git log -n 1 --format=%H").strip
const gitHash {.strdefine.} = gorge("git log -n 1 --format=%H").strip
when gitHash.len == 40:
msgWriteln(conf, "git hash: " & gitHash, {msgStdout})

Expand Down
2 changes: 1 addition & 1 deletion compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasUserErrors")
defineSymbol("nimUncheckedArrayTyp")
defineSymbol("nimHasTypeof")
defineSymbol("nimErrorProcCanHaveBody")
defineSymbol("nimErrorProcCanHaveBody") # since #9665 but now unused
defineSymbol("nimHasInstantiationOfInMacro")
defineSymbol("nimHasHotCodeReloading")
defineSymbol("nimHasNilSeqs")
Expand Down
9 changes: 5 additions & 4 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ proc mapType(typ: PType): TJSTypeKind =
of tyBool: result = etyBool
of tyFloat..tyFloat128: result = etyFloat
of tySet: result = etyObject # map a set to a table
of tyString, tySequence, tyOpt: result = etySeq
of tyString, tySequence: result = etySeq
of tyObject, tyArray, tyTuple, tyOpenArray, tyVarargs, tyUncheckedArray:
result = etyObject
of tyNil: result = etyNull
Expand All @@ -210,6 +210,7 @@ proc mapType(typ: PType): TJSTypeKind =
else: result = etyNone
of tyProc: result = etyProc
of tyCString: result = etyString
of tyOptDeprecated: doAssert false

proc mapType(p: PProc; typ: PType): TJSTypeKind =
result = mapType(typ)
Expand Down Expand Up @@ -1041,7 +1042,7 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =

# we don't care if it's an etyBaseIndex (global) of a string, it's
# still a string that needs to be copied properly:
if x.typ.skipTypes(abstractInst).kind in {tySequence, tyOpt, tyString}:
if x.typ.skipTypes(abstractInst).kind in {tySequence, tyString}:
xtyp = etySeq
case xtyp
of etySeq:
Expand Down Expand Up @@ -1086,7 +1087,7 @@ proc genFastAsgn(p: PProc, n: PNode) =
# See bug #5933. So we try to be more compatible with the C backend semantics
# here for 'shallowCopy'. This is an educated guess and might require further
# changes later:
let noCopy = n[0].typ.skipTypes(abstractInst).kind in {tySequence, tyOpt, tyString}
let noCopy = n[0].typ.skipTypes(abstractInst).kind in {tySequence, tyString}
genAsgnAux(p, n[0], n[1], noCopyNeeded=noCopy)

proc genSwap(p: PProc, n: PNode) =
Expand Down Expand Up @@ -1697,7 +1698,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
result = putToSeq("null", indirect)
of tySequence, tyString:
result = putToSeq("[]", indirect)
of tyCString, tyOpt, tyProc:
of tyCString, tyProc:
result = putToSeq("null", indirect)
of tyStatic:
if t.n != nil:
Expand Down
3 changes: 2 additions & 1 deletion compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
case t.kind
of tyNone, tyEmpty, tyVoid: discard
of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString,
tyPtr, tyOpt, tyUncheckedArray, tyVar, tyLent:
tyPtr, tyUncheckedArray, tyVar, tyLent:
defaultOp(c, t, body, x, y)
of tyRef:
if c.g.config.selectedGC in {gcArc, gcOrc}:
Expand Down Expand Up @@ -785,6 +785,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
of tyOrdinal, tyRange, tyInferred,
tyGenericInst, tyAlias, tySink:
fillBody(c, lastSon(t), body, x, y)
of tyOptDeprecated: doAssert false

proc produceSymDistinctType(g: ModuleGraph; c: PContext; typ: PType;
kind: TTypeAttachedOp; info: TLineInfo): PSym =
Expand Down
6 changes: 3 additions & 3 deletions compiler/reorder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ proc hasAccQuoted(n: PNode): bool =
if hasAccQuoted(a):
return true

const extandedProcDefs = procDefs + {nkMacroDef, nkTemplateDef}
const extendedProcDefs = procDefs + {nkMacroDef, nkTemplateDef}

proc hasAccQuotedDef(n: PNode): bool =
# Checks if the node is a function, macro, template ...
# with a quoted name or if it contains one
case n.kind
of extandedProcDefs:
of extendedProcDefs:
result = n[0].hasAccQuoted
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
for a in n:
Expand All @@ -316,7 +316,7 @@ proc hasBody(n: PNode): bool =
case n.kind
of nkCommand, nkCall:
result = true
of extandedProcDefs:
of extendedProcDefs:
result = n[^1].kind == nkStmtList
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
for a in n:
Expand Down
10 changes: 4 additions & 6 deletions compiler/scriptconfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;
setResult(a, options.existsConfigVar(conf, a.getString 0))
cbconf nimcacheDir:
setResult(a, options.getNimcacheDir(conf).string)
result.registerCallback "stdlib.os." & astToStr(paramStr),
proc (a: VmArgs) =
setResult(a, os.paramStr(int a.getInt 0))
result.registerCallback "stdlib.os." & astToStr(paramCount),
proc (a: VmArgs) =
setResult(a, os.paramCount())
cbconf paramStr:
setResult(a, os.paramStr(int a.getInt 0))
cbconf paramCount:
setResult(a, os.paramCount())
cbconf cmpIgnoreStyle:
setResult(a, strutils.cmpIgnoreStyle(a.getString 0, a.getString 1))
cbconf cmpIgnoreCase:
Expand Down
1 change: 0 additions & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,6 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = semContainer(c, n, tySequence, "seq", prev)
if optSeqDestructors in c.config.globalOptions:
incl result.flags, tfHasAsgn
of mOpt: result = semContainer(c, n, tyOpt, "opt", prev)
of mVarargs: result = semVarargs(c, n, prev)
of mTypeDesc, mType, mTypeOf:
result = makeTypeDesc(c, semTypeNode(c, n[1], nil))
Expand Down
10 changes: 4 additions & 6 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,6 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
result = "seq"
if t.len > 0:
result &= "[" & typeToString(t[0]) & ']'
of tyOpt:
result = "opt"
if t.len > 0:
result &= "opt[" & typeToString(t[0]) & ']'
of tyOrdinal:
result = "ordinal"
if t.len > 0:
Expand Down Expand Up @@ -1150,7 +1146,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
of tyGenericInvocation, tyGenericBody, tySequence, tyOpenArray, tySet, tyRef,
tyPtr, tyVar, tyLent, tySink, tyUncheckedArray, tyArray, tyProc, tyVarargs,
tyOrdinal, tyCompositeTypeClass, tyUserTypeClass, tyUserTypeClassInst,
tyAnd, tyOr, tyNot, tyAnything, tyOpt, tyOwned:
tyAnd, tyOr, tyNot, tyAnything, tyOwned:
cycleCheck()
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
result = sameChildrenAux(a, b, c)
Expand All @@ -1173,6 +1169,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
cycleCheck()
result = sameTypeAux(a.lastSon, b.lastSon, c)
of tyNone: result = false
of tyOptDeprecated: doAssert false

proc sameBackendType*(x, y: PType): bool =
var c = initSameTypeClosure()
Expand Down Expand Up @@ -1365,7 +1362,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = t
else:
result = typeAllowedAux(marker, lastSon(t), kind, flags-{taHeap})
of tySequence, tyOpt:
of tySequence:
if t[0].kind != tyEmpty:
result = typeAllowedAux(marker, t[0], kind, flags+{taHeap})
elif kind in {skVar, skLet}:
Expand Down Expand Up @@ -1408,6 +1405,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = typeAllowedAux(marker, t.lastSon, kind, flags+{taHeap})
else:
result = t
of tyOptDeprecated: doAssert false

proc typeAllowed*(t: PType, kind: TSymKind; flags: TTypeAllowedFlags = {}): PType =
# returns 'nil' on success and otherwise the part of the type that is
Expand Down
2 changes: 1 addition & 1 deletion compiler/vmdeps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
of tyLent: result = mapTypeToBracket("lent", mBuiltinType, t, info)
of tySink: result = mapTypeToBracket("sink", mBuiltinType, t, info)
of tySequence: result = mapTypeToBracket("seq", mSeq, t, info)
of tyOpt: result = mapTypeToBracket("opt", mOpt, t, info)
of tyProc:
if inst:
result = newNodeX(nkProcTy)
Expand Down Expand Up @@ -298,6 +297,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
if t.n != nil:
result.add t.n.copyTree
of tyOwned: result = mapTypeToBracket("owned", mBuiltinType, t, info)
of tyOptDeprecated: doAssert false

proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
result = mapTypeToAstX(cache, t, info, inst=false, allowRecursionX=true)
Expand Down
2 changes: 0 additions & 2 deletions compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,6 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
result.add getNullValue(t[i], info, conf)
of tySet:
result = newNodeIT(nkCurly, info, t)
of tyOpt:
result = newNodeIT(nkNilLit, info, t)
of tySequence:
result = newNodeIT(nkBracket, info, t)
else:
Expand Down
2 changes: 1 addition & 1 deletion doc/advopt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Advanced options:
--skipUserCfg:on|off do not read the user's configuration file
--skipParentCfg:on|off do not read the parent dirs' configuration files
--skipProjCfg:on|off do not read the project's configuration file
--gc:refc|markAndSweep|boehm|go|none|regions
--gc:refc|arc|orc|markAndSweep|boehm|go|none|regions
select the GC to use; default is 'refc'
--exceptions:setjmp|cpp|goto|quirky
select the exception handling implementation
Expand Down
2 changes: 1 addition & 1 deletion doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4354,7 +4354,7 @@ caught by reference. Example:
fn()

**Note:** `getCurrentException()` and `getCurrentExceptionMsg()` are not available
for imported exceptions. One needs to use the `except ImportedException as x:` syntax
for imported exceptions from C++. One needs to use the `except ImportedException as x:` syntax
and rely on functionality of the `x` object to get exception details.


Expand Down
2 changes: 1 addition & 1 deletion lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type
ntyError,
ntyBuiltinTypeClass, ntyUserTypeClass, ntyUserTypeClassInst,
ntyCompositeTypeClass, ntyInferred, ntyAnd, ntyOr, ntyNot,
ntyAnything, ntyStatic, ntyFromExpr, ntyOpt, ntyVoid
ntyAnything, ntyStatic, ntyFromExpr, ntyOptDeprecated, ntyVoid

TNimTypeKinds* {.deprecated.} = set[NimTypeKind]
NimSymKind* = enum
Expand Down
11 changes: 11 additions & 0 deletions lib/packages/docutils/rstgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils,
algorithm, parseutils
import "$lib/../compiler/nimpaths"
import "$lib/../compiler/pathutils"
import ../../std/private/since

const
HtmlExt = "html"
Expand Down Expand Up @@ -1344,6 +1345,16 @@ proc rstToHtml*(s: string, options: RstParseOptions,
renderRstToOut(d, rst, result)


proc rstToLatex*(rstSource: string; options: RstParseOptions): string {.inline, since: (1, 3).} =
## Convenience proc for `renderRstToOut` and `initRstGenerator`.
runnableExamples: doAssert rstToLatex("*Hello* **world**", {}) == """\emph{Hello} \textbf{world}"""
if rstSource.len == 0: return
var option: bool
var rstGenera: RstGenerator
rstGenera.initRstGenerator(outLatex, defaultConfig(), "input", options)
rstGenera.renderRstToOut(rstParse(rstSource, "", 1, 1, option, options), result)


when isMainModule:
assert rstToHtml("*Hello* **world**!", {},
newStringTable(modeStyleInsensitive)) ==
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ proc sendFile(socket: Socket | AsyncSocket,
file.close()

proc redirection(status: string): bool =
const redirectionNRs = ["301", "302", "303", "307"]
const redirectionNRs = ["301", "302", "303", "307", "308"]
for i in items(redirectionNRs):
if status.startsWith(i):
return true
Expand Down
2 changes: 2 additions & 0 deletions lib/pure/httpcore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const
Http304* = HttpCode(304)
Http305* = HttpCode(305)
Http307* = HttpCode(307)
Http308* = HttpCode(308)
Http400* = HttpCode(400)
Http401* = HttpCode(401)
Http403* = HttpCode(403)
Expand Down Expand Up @@ -272,6 +273,7 @@ proc `$`*(code: HttpCode): string =
of 304: "304 Not Modified"
of 305: "305 Use Proxy"
of 307: "307 Temporary Redirect"
of 308: "308 Permanent Redirect"
of 400: "400 Bad Request"
of 401: "401 Unauthorized"
of 403: "403 Forbidden"
Expand Down
24 changes: 4 additions & 20 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ elif defined(posix):
else:
{.error: "OS module not ported to your operating system!".}

when weirdTarget and defined(nimErrorProcCanHaveBody):
{.pragma: noNimScript, error: "this proc is not available on the NimScript target".}
when weirdTarget:
template noNimScript(body): untyped = discard
else:
{.pragma: noNimScript.}

Expand Down Expand Up @@ -2708,23 +2708,7 @@ when defined(nimdoc):
## else:
## # Do something else!

elif defined(nimscript):
proc paramStr*(i: int): string =
## Retrieves the ``i``'th command line parameter.
discard

proc paramCount*(): int =
## Retrieves the number of command line parameters.
discard

elif defined(js):
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
raise newException(OSError, "paramStr is not implemented on JavaScript")

proc paramCount*(): int {.tags: [ReadIOEffect].} =
raise newException(OSError, "paramCount is not implemented on JavaScript")

elif defined(nintendoswitch):
elif defined(nintendoswitch) or weirdTarget:
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
raise newException(OSError, "paramStr is not implemented on Nintendo Switch")

Expand Down Expand Up @@ -3120,7 +3104,7 @@ template rawToFormalFileInfo(rawInfo, path, formalInfo): untyped =
assert(path != "") # symlinks can't occur for file handles
formalInfo.kind = getSymlinkFileKind(path)

when defined(js) or defined(nimscript):
when defined(js):
when not declared(FileHandle):
type FileHandle = distinct int32
when not declared(File):
Expand Down
2 changes: 1 addition & 1 deletion lib/system/hti.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type
tyAnythingHidden,
tyStaticHidden,
tyFromExprHidden,
tyOpt,
tyOptDeprecated,
tyVoidHidden

TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
Expand Down
Loading