Comments (10)
!nim c
from nim.
!nim c
import std/sequtils
type
SomeObj* = object of RootObj
Item* = object
case kind*: 0..1
of 0:
a*: int
b*: SomeObj
of 1:
c*: string
ItemExt* = object
a*: Item
b*: string
proc do1(x: int): seq[(string, Item)] =
result = @[("zero", Item(kind: 1, c: "first"))]
proc do2(x: int, e: ItemExt): seq[(string, ItemExt)] =
do1(x).map(proc(v: (string, Item)): auto = (v[0], ItemExt(a: v[1], b: e.b)))
echo do2(0, ItemExt(a: Item(kind: 1, c: "second"), b: "third"))
from nim.
@alex65536 wow, your insights are really helpful. I think it's mostly likely that copy
needs to zero memery the union before assignement. I'm working on it. Thank you very much!
from nim.
how destructors of old values behave when they encounter zeroed memory
Destructors are supposed to be written in such a way that 0'd memory indicates "this was moved"
from nim.
🐧 Linux bisect by @alex65536 (contributor)
devel 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:24
- Finished
2024-06-07T03:45:24
- Duration
AST
stable 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:25
- Finished
2024-06-07T03:45:25
- Duration
now
AST
2.0.4 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:25
- Finished
2024-06-07T03:45:25
- Duration
now
AST
2.0.0 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:28
- Finished
2024-06-07T03:45:28
- Duration
now
AST
1.6.20 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:31
- Finished
2024-06-07T03:45:31
- Duration
now
AST
1.4.8 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:33
- Finished
2024-06-07T03:45:33
- Duration
now
AST
1.2.18 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:35
- Finished
2024-06-07T03:45:35
- Duration
AST
1.0.10 👎 FAIL
Output
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-06-07T03:45:37
- Finished
2024-06-07T03:45:37
- Duration
now
AST
Stats
- GCC
11.4.0
- Clang
14.0.0
- NodeJS
20.3
- Created
2024-06-07T03:44:52Z
- Comments
1
- Commands
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
🤖 Bug found in 16 minutes
bisecting 8
commits at 0
commits per second
from nim.
It crashed with 1.6.16 with --mm:orc -d:useMalloc
from nim.
Digging further into the compiler code, I noticed the following:
- Here is the algorithm for copy-assignment of object variants. The main take here is that we move the old object into the new location and call
wasMoved
for the old object. wasMoved
is basically implemented here. Among other things, it callsresetLoc()
, which in our case (code) generatesnimZeroMem
+ default-initialization.- Zeroing memory is OK, but re-intialization with the default value for this moved-out object is actually the source of this bug.
I am not proficient in the compiler internals at all, so everything below this text in this comment is just a wild guess from a person who has seen the compiler code today for the first time:
- I am unsure whether zeroing memory is OK, because the next part of the code calls copy assign for each sub-variant, and I don't know how destructors of old values behave when they encounter zeroed memory (maybe everything is OK, but again, I don't know the compiler internals well).
- Another solution would probably be resetting the location before doing recursive assignment inside the case statement (not outside). It could be slower, but seems more reliable for me.
from nim.
Destructors are supposed to be written in such a way that 0'd memory indicates "this was moved"
OK, thank you, then zeroing is a nice idea indeed :)
And what happens if a =copy()
implementation hooked by user receives zeroed memory as a destination? Or is there anything that prevents such thing from happening?
from nim.
You call =destroy
then copy the data over, there is no special logic for data that is 0'd =wasMoved
should disarm =destroy
.
from nim.
Destructors are supposed to be written in such a way that 0'd memory indicates "this was moved"
Note that we're moving away from 0'd memory to the more abstract "=wasMoved
/default state".
from nim.
Related Issues (20)
- `joinPath` sometimes has extra `.` in the beginning of the path HOT 3
- `hasCustomPragma` does not work on generic types HOT 1
- Rasing an exception leaks memeory in `orc` HOT 1
- Seq IndexDefect leaks memeory in `arc` and `orc`
- https://learnxinyminutes.com/docs/nim/ error in the learning documentation code HOT 3
- `noinit` can cause arc to crash with ref objects HOT 2
- hello world Mummy web server crashes on devel HOT 2
- Sigsegv on std/tasks destructor HOT 1
- `=destroy` for non-var failed to compile when `nim doc` HOT 4
- regression from 2.0.4 to 2.0.6 cannot instantiate: 'SomeInteger' in return type HOT 1
- Deadloop in Windows, `os.sleep(-1)` HOT 5
- Deadloop in Windows, `os.sleep(-1)` HOT 1
- Inefficient codegen for field return HOT 1
- `setLen(0)` allocates memory causing performance regression HOT 3
- Generic sequence of proc type mismatch HOT 3
- `int64/int64` not compile for JS, but for C. HOT 4
- Local variables can be prematurely moved to closure, causing use-after-move HOT 2
- Regression: ambiguous identifier
- Regression from 1.6 to 2.0 using static parameter in return type with function taking typeclass HOT 2
- Can't create empty openArray with int8 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nim.