Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: rewrite
injectdestructors
as MIR passes
injectdestructors: fix steps being in the wrong order analyser: fix and improve `computeSpan` and `sibling` mirtrees: move `MirTree`-related parts to a separate module analyser: `injectHooks` progress analyser: correctly compute the nodes a scope spans The start and end node of the `mnkBranch`/`mnkBlock` sub-trees must not be included. analyser: fix issue in `prepass` analyser: run `prepass` first analyser: fix `exprRoot` - the traversal was implemented incorrectly - calls yielding views weren't considered analyser: progress on `isRootOf` - properly walk the expression nodes - compare symbol-storing atoms - fix and clean up `mnlCall` comparison - handle `mnkDeref` mirtraverse: implement abstract execution analyser: `canBorrow` progress - use `sliceIt` - general cleanup - fix initialization of locations other than the analysed one being considered - fix the `mnkArg` node being passed to `isLValue` and `handleUse` analyser: use the new `traverse` where applicable mirtraverse: use an instruction-based CFG This is simpler and faster than processing the `MirNode`s on-the-fly. tests: add the basics for testing `mirtraverse` Actual test cases are not yet present. tests: add two test cases mirtraverse: implement backwards execution of the CFG Make use the of the new algorithm in `injectHooks`. mirtraverse: fix abstract-evaluation-order issue The arguments to a call that can raise have to evaluated before the 'fork'. mirtraverse: don't use 'fork' for a catch-all branch analyser: consider complete assignments during ownership analysis In the following example, this enables the assignments to both `y` and `z` to be turned into moves: ```nim y = x x = ... z = x ``` analyser: a `while` also opens a scope analyser: use backwards analysis for `canBorrow` analyser: allow `unaryOperand` for `mnkDeref` analyser: make the `Changeset` API work analyser: progress on `=sink` injection analyser: only consider `sink` parameters with destructors analyser: register `useSink` actions move the `Changeset` implementation to a separate module In addition, add documentation for some of the procedures. split up application of 'borrow' and non-'borrow' actions This is a preparation for the upcoming refactoring of the analyser pipeline. general progress - split up alive- and ownership-analysis into two procedures - split borrow-inference into a fully separate pass - the analysis passes no longer produce actions. Instead, they now produce the data to infer the actions from - the `apply` procedures use said data to create changes directly - `prepass` is now unnecessary - make basic destructor injection work - make `=copy` and `=sink` hook injection work - respect `.cursor` ins some parts (not all yet) - improve documentation analyser: fix the wrong node being analysed The `mnkArg` node was passed to `isAnalysedLoc`, not it's operand. analyser: conside constructor expression inputs... ...during ownership analysis. mirtrees: remove the `fieldPos` field This lowers the size of a `MirNode` by 8-byte. Tuple access now uses `mnkPathArr`. mirgen: translate `skTemp` symbols to MIR temporaries Having two different types of temporaries is not a good idea and complicated things. [split off] sighashes: use `func` Due to the forward declaration, `hashType` was treated as having side-effects, preventing it from being used inside a `func`. injectdestructors: don't process inline iterators and... ... generated ops. analyser: remove non-working cursor/borrow inference Re-implementing cursor inference is out-of-scope for this PR. The existing implementation can be reused for now. general cleanup WIP: partial redesign of the MIR analyser: fix issues with `hasInput` - operations with no input were detected as having input when appearing as the first child-node of input sub-trees - `void` lead to ambiguities. It still does, but in the case of `hasInput`, it's now ignored analyser: split destructor injection into a separate procedure analyser: implement proper destructor injection Locations of which the value escapes are now correctly destroyed inside a `finally` clause. It's likely that the current implementation is not final. injectdestructors: implement `mnkSwitch` lowering injectdestructors: add self-assignment elimination magicsys: add `getMagicEqForType` The procedure is useful when one is only interested in the magic itself and doesn't require a `PSym`. analyser: add the `operands` procedure In addition, make the `operand` procedure exported. Both are not directly related to the analyser logic and are thus candidates for being moved elsewhere. analyser: consider sub-trees in `operand` and `operands` analyser: add `findParent` analyser: move general query procedures over to `mirtrees.nim` mirgen: work around non-owning temporaries getting destroyed analyser: add missing `mnkModify` node `wasMoved` works without it, but omitting it is still a semantic error. injectdestructors: ensure that constructed `ref` are consumed mirtraverse: improve `computeCfg` - clean up the procedure so that it relies less on templates - simplify the insertion of `join` instructions - `maybeJoin` is no longer used - the instructions can now be sorted by their corresponding node position post-merge fix-up finish the rewrite tests: add `ttest.nim` adjust imports of `mirtraverse` (now `mirexec`)
- Loading branch information