Skip to content

Conversation

flaviut
Copy link
Contributor

@flaviut flaviut commented May 16, 2014

If an identifier starts with a number, this prepends N so that the C and javascript compilers can parse it. Includes test.

mangle is simplified with newer language features, as well as moved into ccgutils.nim to reduce code duplication between ccgtypes.nim and jsgen.nim, which has the side effect of changing current JS gen slightly such that it prepends HEX to weird characters instead of X

Varriount added a commit that referenced this pull request May 21, 2014
@Varriount Varriount merged commit 8581fb7 into nim-lang:devel May 21, 2014
@flaviut flaviut deleted the quotedidentescape branch May 31, 2014 19:01
Clyybber pushed a commit to Clyybber/Nim that referenced this pull request Feb 29, 2024
## Summary

Make turning copy and move assignments into `=copy` and `=sink` calls a
standalone MIR pass; semantics don't change, but higher quality MIR
code is produced. This is progress towards fully decoupling lifetime
hooks from the move analyzer / destructor injection.

## Details

### General architecture

* the `injectdestructors` pass/module only collapses `sink` assignments
  and updates the MIR tree accordingly
* turning copy assignments into `=copy` and sink assignments into
  `=sink` calls is done by the new `injecthooks` pass/module
* reporting errors and warnings regarding hooks is also made part of
  the `injecthooks` pass
* the `injecthooks` is run after the `injectdestructors` pass
* handling of `--expandArc` is moved to `backends.process`, so that it
  can happen after hook injection

### `injectdestructors` Pass

* assignments are not replaced with `=copy` or `=sink` calls
* `expandAsgn` is renamed to `specializeAsgn`
* `sink` assignments are turned into either `copy`, `move`, or
  destructive `move` assignments (same as before)
* assignments to locations that don't yet store a value are turned into
  *initializing* assignments (this is necessary for the later `=sink`
  injection to work)
* compared to before, *all* assignments are processed by
  `specializeAsgn`, not only those for locations with lifetime hooks
* `=destroy` hooks are still injected

### `injecthooks` Pass

* the pass looks for `move` and `copy` assignment modifiers
  * if the involved type has lifetime hooks, the assignment is
     replaced with a call to the appropriate hook
  * the same injection rules as used previously apply
* the error detection and reporting logic is moved over - without
  change - from `injectdestructors`
* an adapter procedure to the legacy pass managements is provided
  (needed by `backends`)

With less surrounding complexity, more effort is spent on using less
temporaries for the hook call injection:
* no temporary is used for the destination operand
* no temporary is used for the source operand when it's guaranteed to
  not alias the destination. This is the case for:
  * `move` assignments
  * define with `copy` (e.g., `def x = copy y`)
  * initial assignments with `copy` (e.g., `x := copy y`)

Less temporaries means less work for the pass eliminating unnecessary
temporaries.

### Technical Correctness

* `mirconstr.inline` is only usable with lvalue expressions and always
  creates a non-owning temporary (instead of an owning temporary)
* the remaining usage of `mirconstr.inline` in
  `injectdestructors.lowerBranchSwitch`, where an owning temporary is
  required, is replaced with using `wrapTemp`

---------

Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants