summary refs log tree commit diff stats
path: root/compiler/liftdestructors.nim
Commit message (Collapse)AuthorAgeFilesLines
* [backport] fixes #23690; SIGSEGV with object variants and RTTI (#23703)ringabout2024-06-111-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23690 ```nim dest.`:state` = src.`:state` var :tmp_553651276 = dest.e1.a `=wasMoved`(dest.e1.a) dest.e1.a.kind = src.e1.a.kind case dest.e1.a.kind of 0: dest.e1.a.a = src.e1.a.a of 1: `=copy`(dest.e1.a.c, src.e1.a.c) case :tmp_553651276.kind of 0: of 1: `=destroy`(:tmp_553651276.c) ``` `dest.e1.a.kind = src.e1.a.kind` changes the discrimant but it fails to clear the memory of `dest.e1.a`. Before using hooks for copying, we need to clear the dest, e.g. `=wasMoved(dest.e1.a.c)`. ```nim dest.`:state` = src.`:state` var :tmp_553651276 = dest.e1.a `=wasMoved`(dest.e1.a) dest.e1.a.kind = src.e1.a.kind case dest.e1.a.kind of 0: `=wasMoved`(dest.e1.a.a) dest.e1.a.a = src.e1.a.a `=wasMoved`(dest.e1.a.b) of 1: `=wasMoved`(dest.e1.a.c) `=copy`(dest.e1.a.c, src.e1.a.c) case :tmp_553651276.kind of 0: of 1: `=destroy`(:tmp_553651276.c) ```
* fixes lifting subtype calling parent's hooks (#23612)ringabout2024-05-151-1/+4
| | | | | ref https://forum.nim-lang.org/t/11587 Tested with `gcc version 14.0.1 20240412` locally
* fixes #23552; Invalid codegen when trying to mannualy delete distinct seq ↵ringabout2024-05-081-6/+8
| | | | | (#23558) fixes #23552
* fixes sink regression for ORC; ref #23354 (#23359)ringabout2024-03-031-1/+1
| | | | | | | | | ref #23354 The new move analyzer requires types that have the tfAsgn flag (otherwise `lastRead` will return true); tfAsgn is included when the destructor is not trival. But it should consider the assignement for objects in this case because objects might have a trival destructors but it's the assignement that matters when it is passed to sink parameters.
* fixes #22923; fixes `=dup` issues (#23182)ringabout2024-01-111-1/+9
| | | fixes #22923
* fixes #23129; fixes generated hooks raise unlisted Exception, which never ↵ringabout2024-01-111-1/+6
| | | | | raise (#23195) fixes #23129
* type refactor: part 4 (#23077)Andreas Rumpf2023-12-151-9/+9
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-16/+16
|
* fixes #22286; enforce Non-var T destructors by `nimPreviewNonVarDestructor` ↵ringabout2023-11-251-3/+5
| | | | | | | | | | | | | | | | | | (#22975) fixes #22286 ref https://forum.nim-lang.org/t/10642 For backwards compatibilities, we might need to keep the changes under a preview compiler flag. Let's see how many packags it break. **TODO** in the following PRs - [ ] Turn the `var T` destructors warning into an error with `nimPreviewNonVarDestructor` --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-2/+2
|
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-1/+2
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* fixes #22664; guard against potential seqs self assignments (#22671)ringabout2023-09-081-0/+11
| | | fixes #22664
* fixes #22619; don't lift cursor fields in the hook calls (#22638)ringabout2023-09-051-2/+1
| | | | | | | | | | | | | | | | | | | | | | | fixes https://github.com/nim-lang/Nim/issues/22619 It causes double free for closure iterators because cursor fields are destroyed in the lifted destructors of `Env`. Besides, according to the Nim manual > In fact, cursor more generally prevents object construction/destruction pairs and so can also be useful in other contexts. At least, destruction of cursor fields might cause troubles. todo - [x] tests - [x] revert a certain old PR --------- Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com>
* unpublic the sons field of PType; the precursor to PType refactorings (#22446)ringabout2023-08-111-1/+1
| | | | | | | | | | | * unpublic the sons field of PType * tiny fixes * fixes an omittance * fixes IC * fixes
* replaces `doAssert false` with `raiseAssert` for unreachable branches, which ↵ringabout2023-08-101-1/+1
| | | | | works better with strictdefs (#22436) replaces `doAssert false` with `raiseAssert`, which works better with strictdefs
* use strictdefs for compiler (#22365)ringabout2023-08-061-1/+13
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fixes #22268; fixes `move` codegen (#22288)ringabout2023-07-191-3/+3
|
* adds =destroy T support for strings and seqs (#22167)ringabout2023-06-271-2/+2
| | | | | | | * adds =destroy T support for strings and seqs * fixes system * fixes tests
* adds T destructor for refs (#22147)ringabout2023-06-261-1/+6
| | | | | | | | | * adds T destructor for refs * add `newRefdestructor` * adds ref overload for destructors * fixes config
* allow destructors to accept non var parameters; deprecate `proc =destroy(x: ↵ringabout2023-06-211-3/+7
| | | | | | | | | | var T)` (#22130) * make destructors accept non var parameters * define nimAllowNonVarDestructor * add a test case and a changelog * update documentation and error messages * deprecate destructors taking 'var T'
* make `move` use `=wasMoved` internally (#22032)ringabout2023-06-091-3/+3
| | | | | | | | | | | | | * make `move` use `=wasMoved` internally * fixes tests * fixes spawn finally * fixes views * rename to internalMove * add a test case
* fixes overriden typo (#22044)ringabout2023-06-081-12/+12
|
* fixes #21989; lift `=dup` from a custom `=copy` for objects to keep backward ↵ringabout2023-06-071-1/+10
| | | | | | | | | | | | | compatibilities (#22009) * fixes #21989; optimize `=dup` iff it is overridden * remove owned * fixes refs * lift destructors * lift dup
* lift the `=dup` hook (#21903)ringabout2023-06-021-29/+103
| | | | | | * fixes tests again * remove helper functions * fixes closures, owned refs * final cleanup
* improve `wasMoved` hooks; allow reset to use the overridden `wasMoved` hook ↵ringabout2023-05-121-14/+23
| | | | | | | (#21831) * improve `wasMoved` hooks * Because `wasMoved` is lifted
* adds documentation for `=wasMoved` and `=dup` hooks and small fixes (#21827)ringabout2023-05-111-1/+1
| | | | | | | | | | | * adds documentation for `=wasMoved` and `=dup` hooks and small fixes * Update doc/destructors.md * Update doc/destructors.md --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* bring #21802 back; fixes #21753 [backport] (#21815)ringabout2023-05-111-6/+6
| | | | | | | | | | | | | * bring #21802 back; fixes #21753 [backport] * adds tests and multiple fixes * add test cases * refactor and remove startId * fixes custom hooks and adds tests * handle tyUncheckedArray better
* adds an experimental `mm:atomicArc` switch (#21798)ringabout2023-05-081-5/+5
|
* implement `=dup` hook eliminating `wasMoved` and `=copy` pairs (#21586)ringabout2023-05-061-3/+23
| | | | | | | | | | | | | | | | | | | * import `=dup` hook eliminating `wasMoved` and `=copy` pairs * add dup * add a test for dup * fixes documentation * fixes signature * resolve comments * fixes tests * fixes tests * clean up
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-9/+9
| | | | | | | | | | | (#21667) * refactoring in preparation for better, simpler name mangling that works with IC flawlessly * use new disamb field * see if this makes tests green * make tests green again
* minor refactoring (#21499)Andreas Rumpf2023-03-101-7/+1
|
* fixes #20139; hash types based on its path relative to its package path ↵ringabout2023-03-021-2/+2
| | | | | | | | | | | | | | | (#21274) [backport:1.6] * fixes #20139; hash types based on its path relative its project * add a test case * fixes procs * better implementation and test case --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #19291; implements `wasMoved` hook (#21303)ringabout2023-03-021-5/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fixes #19291; implements `wasMoved` hook * basics * checkpoint * finish `wasMoved` * add a test for #19291 * add documentation and changelog * work `attachedWasMoved` with generics * fixes optimizer * register `=wasMoved` * handle wasMoved magcis * check another round * some patches * try `op == nil` * nicer * generate `wasMoved` before `destroy` * try again * fixes tests * default wasMoved * Update tests/destructor/tv2_cast.nim * Update tests/destructor/tv2_cast.nim * Update tests/arc/topt_refcursors.nim
* fixes comments about type bound operations (#21365)ringabout2023-02-141-1/+1
|
* fixes #21171; dynamic acyclic refs need to use dyn decRef (#21184)ringabout2022-12-281-0/+7
| | | | | | | * fixes #21171; dyn destructors for acyclic inherited refs * add a test * Update compiler/liftdestructors.nim
* Prevent use-after-free bugs in object variants. Fixes bug #20305 (#20300) ↵Antonis Geralis2022-09-051-0/+3
| | | | | | | | | | | [backport] prevent use-after-free bugs in cased objects the bug happens specifically when deleting an item in a seq. The item taking it's place might not have the same case fields. Then =sink(x[i], move x[xl]) might leave the deleted fields still in memory! If the new item switches branches again, you get a use-after-free bug.
* move assertions out of system (#19599)flywind2022-03-231-0/+3
|
* fixes an old ARC bug: the produced copy/sink operations don't copy the ↵Andreas Rumpf2021-12-091-0/+10
| | | | hidden type field for objects with enabled inheritance; fixes #19205 [backport:1.6] (#19232)
* fixes #17893 (#18485)Andreas Rumpf2021-07-131-6/+1
| | | * fixes #17893
* ORC: support for custom =trace procs (#18459)Andreas Rumpf2021-07-091-2/+14
| | | | | | | | | | | * ORC: support custom =trace procs (WIP) * Update tests/arc/tcustomtrace.nim Co-authored-by: Clyybber <darkmine956@gmail.com> * =trace is now documented and seems to work * make test green Co-authored-by: Clyybber <darkmine956@gmail.com>
* ORC: use =destroy instead of =dispose (#18440)Andreas Rumpf2021-07-071-40/+9
| | | | | | * ORC refactoring in preparation for further changes (=dispose must die) * ORC: embrace =destroy, avoid =dispose * ORC: no need for =dispose * closes #18421
* ORC: progress (#18000)Andreas Rumpf2021-05-121-6/+8
| | | | | | | | | * ORC: progress * ORC: bugfix; don't follow acyclic data even if only at runtime the subtype is marked as acyclic * progress * minor style changes
* ORC: improvements (#17993)Andreas Rumpf2021-05-121-2/+7
| | | | * ORC: improvements * ORC: fix .acyclic annotation for ref objects
* ORC: critical bugfix for mixing acyclic refs with cyclic refs [backport:1.4] ↵Andreas Rumpf2021-05-111-7/+10
| | | | (#17991)
* cString => cSourceString; tyCString => tyCstring so that error msgs show ↵Timothee Cour2021-04-171-1/+1
| | | | cstring, not cString (#17744)
* iterable[T] (#17196)Timothee Cour2021-04-111-1/+1
| | | | | | | | * fix failing test toSeq in manual which now works * changelog * reject proc fn(a: iterable) * add iterable to spec * remove MCS/UFCS limitation that now works
* Fix #17412 (#17560)Clyybber2021-03-291-1/+10
| | | | | * Fix #17412 * Address review
* IC: green tests (#17311)Andreas Rumpf2021-03-191-36/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * IC: renamed to_packed_ast module to ic module * IC: don't store the --forceBuild flag, makes it easier to test * IC: enable hello world test * Codegen: refactorings for IC; changed the name mangling algorithm * fixed the HCR regressions * life is too short for HCR * tconvexhull is now allowed to use deepCopy * IC exposed a stdlib bug, required a refactoring * codegen: code cleanups * IC: even if a module is outdated, its dependencies might come from disk * IC: progress * IC: better name mangling, module IDs are not stable * IC: another refactoring helping with --ic:on --gc:arc * disable arraymancer on Windows for the time being * disable arraymancer altogether * IC: make basic test work with 'nim cpp' * IC: progress on --ic:on --gc:arc * wip; name mangling for type info
* semLambda removed, semProcAux reworked (#17379)Saem Ghani2021-03-171-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * simplified proc-like name ident to symbol code * wip - reworking generic param sem * wip - closer to removing nkEmpty generic params * it's hacky but tests pass * slowly tweaking semProcAux to take on semLambda * fix pragma superset check proto vs current * Set the symbol owner earlier * partial progress reworking proto found bug where default values between forward and impl lead to overload resolution issues. * simplified pragma handling and callConv checks Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> * partially working * cgexprs issue * It works! * comment clean-up * clean-up asserts, comments, and other bits * add isGenericParams, inline isGeneric queries * seeing if this is sufficiently consistent * can use this approach or continue it in a further PR * commentary about nullary generics and clean-ups * fixed a mistake in PNode isGenericRoutine * Some small cleanups * Small cleanup * for func lambdas ensure we use lambda pragmas * add some basic compileTime func tests * [ci skip] remove comments Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> Co-authored-by: Clyybber <darkmine956@gmail.com>
* new-style concepts implementation, WIP (#15251)Andreas Rumpf2021-02-241-1/+1
| | | | | | | | | | | | | * fixes #15210 [backport:1.2] * make tests green * make ordinal work * makes Swapable test compile * make Indexable example work * concepts: 'self' is now 'Self' * concepts: make Dictionary example compile * document the new concept implementation * concepts: make typeDesc work properly * concepts: allow documentation comments (d'oh)