From 2a046e648756b6a36acf580c9c0289319cd697d7 Mon Sep 17 00:00:00 2001 From: Archar Gelod <60652075+Archargelod@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:35:40 +0800 Subject: [PATCH 1/5] better examples for std/inotify (#23415) Previous example wouldn't run unless `std/posix` was imported and it wasn't mentioned anywhere in the docs. Other changes in the example: - replaced magic number with constant `MaxWatches` . - changed seq buffer to array, because length is already constant + pointer is a bit nicer: `addr seq[0]` vs `addr arr` - added example for getting a `cstring` name value from `InotifyEvent` struct with explicit cast. - added a bit more description to `inotify_init1` (copied from `man inotify(7)`) --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> --- lib/posix/inotify.nim | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/posix/inotify.nim b/lib/posix/inotify.nim index 7bc1504e5c..db68dbecb0 100644 --- a/lib/posix/inotify.nim +++ b/lib/posix/inotify.nim @@ -67,7 +67,8 @@ proc inotify_init*(): FileHandle {.cdecl, importc: "inotify_init", proc inotify_init1*(flags: cint): FileHandle {.cdecl, importc: "inotify_init1", header: "".} - ## Create and initialize inotify instance. + ## Like `inotify_init<#inotify_init>`_ , + ## but has a flags argument that provides access to some extra functionality. proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint {.cdecl, importc: "inotify_add_watch", header: "".} @@ -79,11 +80,18 @@ proc inotify_rm_watch*(fd: cint; wd: cint): cint {.cdecl, iterator inotify_events*(evs: pointer, n: int): ptr InotifyEvent = ## Abstract the packed buffer interface to yield event object pointers. - ## ```Nim - ## var evs = newSeq[byte](8192) # Already did inotify_init+add_watch - ## while (let n = read(fd, evs[0].addr, 8192); n) > 0: # read forever - ## for e in inotify_events(evs[0].addr, n): echo e[].len # echo name lens - ## ``` + runnableExamples("-r:off"): + when defined(linux): + import std/posix # needed for FileHandle read procedure + const MaxWatches = 8192 + + let inotifyFd = inotify_init() # create new inotify instance and get it's FileHandle + let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE) # Add new watch + + var events: array[MaxWatches, byte] # event buffer + while (let n = read(inotifyFd, addr events, MaxWatches); n) > 0: # blocks until any events have been read + for e in inotify_events(addr events, n): + echo (e[].wd, e[].mask, cast[cstring](addr e[].name)) # echo watch id, mask, and name value of each event var ev: ptr InotifyEvent = cast[ptr InotifyEvent](evs) var n = n while n > 0: @@ -94,8 +102,10 @@ iterator inotify_events*(evs: pointer, n: int): ptr InotifyEvent = runnableExamples: when defined(linux): - let inoty: FileHandle = inotify_init() ## Create 1 Inotify. - doAssert inoty >= 0 ## Check for errors (FileHandle is alias to cint). - let watchdoge: cint = inotify_add_watch(inoty, ".", IN_ALL_EVENTS) ## Add directory to watchdog. - doAssert watchdoge >= 0 ## Check for errors. - doAssert inotify_rm_watch(inoty, watchdoge) >= 0 ## Remove directory from the watchdog + let inotifyFd = inotify_init() # create and get new inotify FileHandle + doAssert inotifyFd >= 0 # check for errors + + let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE) # Add new watch + doAssert wd >= 0 # check for errors + + discard inotifyFd.inotify_rm_watch(wd) # remove watch From 06b25bd2c40194f4b00d1d664492b6aed1dee91c Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:00:56 +0800 Subject: [PATCH 2/5] disable presto (#23958) --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 038f7edccf..533b6c7b7a 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -142,7 +142,7 @@ pkg "pixie" pkg "plotly", "nim c examples/all.nim" pkg "pnm" pkg "polypbren" -pkg "presto" +pkg "presto", allowFailure = true pkg "prologue", "nimble tcompile" pkg "protobuf", "nim c -o:protobuff -r src/protobuf.nim" pkg "rbtree" From 298ada3412c9cf5971abc2b3b891b9bb8612e170 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 15 Aug 2024 19:28:13 +0800 Subject: [PATCH 3/5] fixes #23954; uint8 > 8 bit at compile-time (#23955) fixes #23954 --- compiler/semfold.nim | 3 ++- tests/int/t1.nim | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 69aaf2e901..450ae70fbb 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -421,8 +421,9 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P of tyChar, tyUInt..tyUInt64, tyInt..tyInt64: var val = a.getOrdValue if dstTyp.kind in {tyUInt..tyUInt64}: - result = newIntNodeT(val, n, idgen, g) + result = newIntNodeT(maskBytes(val, getSize(g.config, dstTyp)), n, idgen, g) result.transitionIntKind(nkUIntLit) + result.typ = dstTyp else: if check: rangeCheck(n, val, g) result = newIntNodeT(val, n, idgen, g) diff --git a/tests/int/t1.nim b/tests/int/t1.nim index f1d6c9a183..b8d6f9c922 100644 --- a/tests/int/t1.nim +++ b/tests/int/t1.nim @@ -47,3 +47,8 @@ block: # bug #14522 doAssert 0xFF000000_00000000.uint64 == 18374686479671623680'u64 +block: # bug #23954 + let testRT_u8 : uint8 = 0x107.uint8 + doAssert testRT_u8 == 7 + const testCT_u8 : uint8 = 0x107.uint8 + doAssert testCT_u8 == 7 From d43a5954c5e179c5ef270bb7b48bcab7288ddba5 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 16 Aug 2024 07:33:43 +0300 Subject: [PATCH 4/5] remove nontoplevel type hack + consider symbol disamb in type hash (#23969) fixes #22571 Removes the hack added in #13589 which made non-top-level object type symbols `gensym` because they couldn't be mangled into different names for codegen vs. top-level types. Now we consider the new `disamb` field (added in #21667) of the type symbols in the type hash (which is used for the mangled name) to differentiate between the types. In other parts of the compiler, specifically the [proc mangling](https://github.com/nim-lang/Nim/blob/298ada3412c9cf5971abc2b3b891b9bb8612e170/compiler/mangleutils.nim#L59), `itemId.item` is used instead of the `disamb` field, but I didn't use it in case it's the outdated method. --- compiler/semstmts.nim | 4 ---- compiler/sighashes.nim | 4 ++++ tests/ccgbugs/tsamename3.nim | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 915f2dcb6d..5e7aabe017 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1785,10 +1785,6 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = checkForMetaFields(c, baseType.n, hasError) if not hasError: checkConstructedType(c.config, s.info, s.typ) - - # fix bug #5170, bug #17162, bug #15526: ensure locally scoped types get a unique name: - if s.typ.kind in {tyEnum, tyRef, tyObject} and not isTopLevel(c): - incl(s.flags, sfGenSym) #instAllTypeBoundOp(c, n.info) diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index f86f866794..d8dfe1828b 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -55,6 +55,8 @@ proc hashSym(c: var MD5Context, s: PSym) = c &= it.name.s c &= "." it = it.owner + c &= "#" + c &= s.disamb proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) = if sfAnon in s.flags or s.kind == skGenericParam: @@ -69,6 +71,8 @@ proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) = c &= it.name.s c &= "." it = it.owner + c &= "#" + c &= s.disamb proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]; conf: ConfigRef) = if n == nil: diff --git a/tests/ccgbugs/tsamename3.nim b/tests/ccgbugs/tsamename3.nim index a69391e5c7..ded18e9f8f 100644 --- a/tests/ccgbugs/tsamename3.nim +++ b/tests/ccgbugs/tsamename3.nim @@ -109,3 +109,12 @@ block: # make sure `hashType` doesn't recurse infinitely a, b: PFoo c: int var a: PFoo + +block: # issue #22571 + macro foo(x: typed) = + result = x + + block: # or `proc main =` + foo: + type Foo = object + doAssert $Foo() == "()" From 995081b56a098c431eb24fbb37afadb4cee2fb4b Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 16 Aug 2024 09:22:49 +0300 Subject: [PATCH 5/5] fix `is` with `type`/`typedesc` crashing the compiler (#23967) fixes #22850 The `is` operator checks the type of the left hand side, and if it's generic or if it's a `typedesc` type with no base type, it leaves it to be evaluated later. But `typedesc` types with no base type precisely describe the default typeclass `type`/`typeclass`, so this condition is removed. Maybe at some point this represented an unresolved generic type? --- compiler/semexprs.nim | 3 +-- tests/types/tisopr.nim | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index d49f115ea8..e2a4df3ffe 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -611,8 +611,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode = n[1] = makeTypeSymNode(c, lhsType, n[1].info) lhsType = n[1].typ else: - if lhsType.base.kind == tyNone or - (c.inGenericContext > 0 and lhsType.base.containsGenericType): + if c.inGenericContext > 0 and lhsType.base.containsGenericType: # BUGFIX: don't evaluate this too early: ``T is void`` return diff --git a/tests/types/tisopr.nim b/tests/types/tisopr.nim index 64b3d03c00..c95b63c90f 100644 --- a/tests/types/tisopr.nim +++ b/tests/types/tisopr.nim @@ -165,3 +165,7 @@ block: # previously tisop.nim doAssert f.y.typeof is float doAssert f.z.typeof is float p(A, f) + +block: # issue #22850 + doAssert not (type is int) + doAssert not (typedesc is int)