Commit Graph

97 Commits

Author SHA1 Message Date
Andreas Rumpf
6cb2dca41d updated compiler DFA docs (#23527) 2024-04-22 13:04:30 +02:00
Andreas Rumpf
91ad6a740b type refactor: part 4 (#23077) 2023-12-15 10:20:57 +01:00
ringabout
e17237ce9d prepare for the enforcement of std prefix (#22873)
follow up https://github.com/nim-lang/Nim/pull/22851
2023-10-29 14:48:11 +01:00
Andreas Rumpf
816589b667 NIR: Nim intermediate representation (#22777)
Theoretical Benefits / Plans: 

- Typed assembler-like language.
- Allows for a CPS transformation.
- Can replace the existing C backend by a new C backend.
- Can replace the VM.
- Can do more effective "not nil" checking and static array bounds
checking.
- Can be used instead of the DFA.
- Easily translatable to LLVM.
- Reasonably easy to produce native code from.
- Tiny memory consumption. No pointers, no cry.

**In very early stages of development.**

Todo:
- [x] Map Nim types to IR types.
- [ ] Map Nim AST to IR instructions:
  - [x] Map bitsets to bitops.
  - [ ] Implement string cases.
  - [ ] Implement range and index checks.
  - [x] Implement `default(T)` builtin.
  - [x] Implement multi string concat.
- [ ] Write some analysis passes.
- [ ] Write a backend.
- [x] Integrate into the compilation pipeline.
2023-10-11 17:44:14 +02:00
ringabout
7be2e2bef5 replaces doAssert false with raiseAssert for unreachable branches, which works better with strictdefs (#22436)
replaces `doAssert false` with `raiseAssert`, which works better with strictdefs
2023-08-10 14:26:40 +02:00
ringabout
93ced31353 use strictdefs for compiler (#22365)
* wip; use strictdefs for compiler

* checkpoint

* complete the chores

* more fixes

* first phase cleanup

* Update compiler/bitsets.nim

* cleanup
2023-08-06 14:26:21 +02:00
Andreas Rumpf
427ad17161 fixes #22001 (#22177)
* fixes #22001

* added test case
2023-06-27 22:42:48 +02:00
ringabout
4533e894ad adds an experimental mm:atomicArc switch (#21798) 2023-05-08 16:25:47 +02:00
Andreas Rumpf
81087c949f fixes #20572 (#20585)
* fixes #20572

* added a test case
2022-10-17 23:48:51 +02:00
Andreas Rumpf
0d23419e68 DAA and 'out' parameters (#20506)
* DAA and 'out' parameters

* progress

* documented strictDefs and out parameters

* docs, tests and a bugfix

* fixes silly regression
2022-10-06 17:08:41 +02:00
Andreas Rumpf
8d47bf1822 new move analyser2 (#20471)
* produce better code for closure environment creation
* new 'first write' analysis; 
* scope based move analyser
* code cleanup

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-10-01 16:46:51 +02:00
metagn
a95b6391fd support cstring in case (#20130)
* implement case for cstring

for now just converts to string on C backend

* custom implementation for cstring

* remove leftover

* revert even more

* add nil + fix packages weird variant literal bug

* update docs
2022-09-01 18:10:00 +02:00
flywind
7f6e800caf move assertions out of system (#19599) 2022-03-23 20:34:53 +01:00
Clyybber
3e83d73f27 compiler: Handle nkCheckedFieldExpr better in dfa (#19616)
Simply recurse into their first child, which is always
a nkDotExpr instead of treating them seperately.
This fixes the rhs sym of a nkCheckedFieldExpr being
checked twice in aliases. This double checking didn't
cause any issues, but was unintentional and redundant.
2022-03-18 16:41:45 +01:00
Clyybber
f7d642f2f3 [backport] arc: improve compile time of (nested) loops (#18890) 2021-09-24 14:59:48 +02:00
Andreas Rumpf
bc14b77359 fixes #18665 DFA generator bug (#18676) 2021-08-11 17:19:23 +02:00
Timothee Cour
0b7361e938 followup #18362: make UnusedImport work robustly (#18366)
* warnDuplicateModuleImport => hintDuplicateModuleImport
* improve DuplicateModuleImport msg, add test
2021-06-27 20:39:16 +02:00
Andreas Rumpf
3bc625aff1 ORC: progress (#18000)
* ORC: progress

* ORC: bugfix; don't follow acyclic data even if only at runtime the subtype is marked as acyclic

* progress

* minor style changes
2021-05-12 22:00:37 +02:00
Clyybber
b03d6c9b2f Fix #17712 (#17873) 2021-04-27 13:03:26 +02:00
Saem Ghani
ab780f66ef fixes #17198, DFA failure on large case stmts (#17210)
This alters the DFA control flow graph generation for case statments.
Gotos are now generated as a chained link, this ensures that evaluation
of variant branches collapses as early as possible, without hitting the
2k call limit.
2021-03-02 10:32:43 +01:00
Timothee Cour
31bb67a309 add -d:nimStrictMode in CI to keep code from regressing; fixes ConvFromXtoItselfNotNeeded, UnusedImport notes (#16764) 2021-02-17 19:30:09 +01:00
Clyybber
aa3af9e053 ARC Analysis in one pass v3 (#17068)
* Analyse last reads all at once

* Integrate firstWrite analysis

* Small cleanup

* Use sets instead of seqs

* Remove instrTargets

* Reap the benefits

* Implement error diagnostics

* Operate on DFA index for lastRead analysis

* Use mgetOrPut

* Cache alias results

This improves performance by a lot, since many
CFG locations map to a single PNode

* Improve performance

* Improve performance

* Cleanup

* Fix #17025

* Grammar

* Expand testcase
2021-02-17 14:17:35 +01:00
Clyybber
70b9e9962f Revert "ARC: Analysis in one pass v2 (#17000)" (#17046)
This reverts commit 216be4060a.
2021-02-15 18:31:15 +01:00
Clyybber
216be4060a ARC: Analysis in one pass v2 (#17000)
* Analyse last reads all at once

* Integrate firstWrite analysis

* Small cleanup

* Use sets instead of seqs

* Remove instrTargets

* Reap the benefits

* Implement error diagnostics

* Operate on DFA index for lastRead analysis

* Use mgetOrPut

* Cache alias results

This improves performance by a lot, since many
CFG locations map to a single PNode

* Improve performance

* Improve performance

* Cleanup
2021-02-10 15:03:57 +01:00
Clyybber
9edf719e1e Revert "ARC Analysis in one pass (#16849)" (#16984)
This reverts commit ab740cb5b9.
2021-02-09 15:50:52 +01:00
Clyybber
ab740cb5b9 ARC Analysis in one pass (#16849)
* Analyse last reads all at once

* Integrate firstWrite analysis

* Small cleanup

* Use sets instead of seqs

* Remove instrTargets

* Reap the benefits

* Implement error diagnostics

* Operate on DFA index for lastRead analysis

* Use mgetOrPut
2021-02-09 14:20:58 +01:00
Clyybber
301e5838ec Finer analysis for array access (#16787)
* Refine the analysis for array access
* Cleanup
* Add comments
2021-01-24 21:01:41 +01:00
flywind
95f599ca2d move asciitables to std/private/ (#16498)
* move asciitables

* minor
2020-12-29 16:20:47 +01:00
Andreas Rumpf
8e3f51f06c fixes #15130 (#15141)
* fixes #15130

* you really have to copy from cursors
2020-08-01 18:04:04 +02:00
Andreas Rumpf
4ab6887a67 fixes #15111 (#15136) 2020-08-01 07:39:00 +02:00
Clyybber
2b0e336c97 injectdestructors fixes and refactor (#14964)
* injectdestructors fixes and refactor

* Tiny cleanup

* Refactor and expand testcase

* Closes #14902 by adding testcase

* Better naming

* Fix test failures

* Misc cleanup

* Add testcase for #14968

* Better approach; expand testcases

* Optimizations and fixes

* Add testcase

* typo

* Tiny cleanup
2020-07-14 14:15:39 +02:00
Clyybber
62394616e8 DFA and injectdestructors cleanup (#14824)
* DFA and injectdestructors cleanup

* More precise write analysis

* Cleanup obsoleted path

* Unify defInstrTargets and useInstrTargets

* Misc cleanups

* Nicer CFG printing

* Misc cleanups 2
2020-06-28 19:36:30 +02:00
Andreas Rumpf
da29222f86 init checks and 'out' parameters (#14521)
* I don't care about observable stores
* enforce explicit initializations
* cleaner code for the stdlib
* stdlib: use explicit initializations
* make tests green
* algorithm.nim: set result explicitly
* remove out parameters and bring the PR into a mergable state
* updated the changelog
2020-06-23 10:53:57 +02:00
Andreas Rumpf
e31ac81899 more checking for --gc:arc, no need for valgrind (#14467)
* sigmatch: removed dead code
2020-05-29 12:08:17 +02:00
Clyybber
9f78f116b2 New "ping-pong" DFA (#14322)
* New ping-pong analysis

* Add testcase for #13456

* Remove debugging leftover

* Unquote "unstructured controlflow"

* Fix typo

* Fix exponential complexity in edge cases

* Add sanity testcase

* Fix
2020-05-15 19:24:43 +01:00
Clyybber
8e93105606 Fix #14269 (#14286) 2020-05-09 18:22:25 +02:00
Clyybber
42db75c970 Fix the DFA for "unstructured controlflow" (#14263)
* Fix the DFA for "unstructured controlflow"

* Add testcase from #14233
2020-05-07 21:41:55 +02:00
Andreas Rumpf
b6fb609e0d destructors: don't produce stupid code for 'cast' (#14208) [backport:1.2]
* destructors: don't produce stupid code for 'cast'

* fixes #14207
2020-05-04 07:43:22 +02:00
Araq
87ac28d19a fixes #14159 [backport:1.2] 2020-05-02 22:31:19 +02:00
Juan Carlos
afd0afe0a3 Deprecate when declared(echo):echo (#13840) 2020-04-02 02:56:18 +02:00
Andreas Rumpf
a0eca75182 sink parameter inference for types that have destructors (#13544)
* ensure capitalize doesn't take an inferred sink parameter

* sink parameter inference: first version, for now disabled. Changed that sink parameters can be consumed multiple times in order to adhere to our spec.

* sink inference can now be disabled with .nosinks; sometimes for proc type interop this is required

* fixes yet another critical DFA bug

* better implementation that also understands if expressions etc

* document sink parameter inference and allow for global disabling
2020-03-04 14:28:53 +01:00
Andreas Rumpf
240174dd81 fixes #13314 (#13372) 2020-02-09 00:22:34 +01:00
Clyybber
e3acb2d12c Cleanup DFA (#13173) 2020-01-16 20:15:50 +01:00
Andreas Rumpf
a5e67071d2 ARC: misc bugfixes (#13156)
* fixes #13102
* closes #13149
* ARC: fixes a move optimizer bug (there are more left regarding array and tuple indexing)
* proper fix; fixes #12957
* fixes yet another case object '=' code generation problem
2020-01-15 22:13:31 +01:00
Andreas Rumpf
1917ebf082 minor refactorings 2019-12-27 08:29:40 +01:00
Araq
7e6e399d10 fixes #12669 2019-11-29 19:46:21 +01:00
Clyybber
7e747d11c6 Cosmetic compiler cleanup (#12718)
* Cleanup compiler code base

* Unify add calls

* Unify len invocations

* Unify range operators

* Fix oversight

* Remove {.procvar.} pragma

* initCandidate -> newCandidate where reasonable

* Unify safeLen calls
2019-11-28 17:13:04 +01:00
Federico Ceratto
39290cf88c Fix spellings (#12277) [backport] 2019-09-27 07:02:54 +02:00
Clyybber
029dcc6259 fix #12037 (#12089) 2019-08-30 06:41:26 +02:00
Araq
07d465ca42 [refactoring] remove unused imports in the compiler and in some stdlib modules 2019-07-18 00:36:03 +02:00