Commit Graph

361 Commits

Author SHA1 Message Date
Andreas Rumpf
16355de5eb rename for code clarity 2019-03-15 17:51:52 +01:00
Andreas Rumpf
831626be85 newruntime: make dynamic destructors compatible with C++ 2019-03-15 17:51:52 +01:00
Andreas Rumpf
e263702688 --newruntime: progress 2019-03-14 19:53:27 +01:00
Andreas Rumpf
2ab6b2c657 --newruntime: work in progress 2019-03-14 07:59:44 +01:00
Andreas Rumpf
436ec57f83 seqs.nim: added a remark about C++ optimizers 2019-03-14 07:59:44 +01:00
Arne Döring
35aab357e2 Less warnings in macros (#10799) 2019-03-11 19:21:39 +01:00
Araq
e1d17ece5b alloc et al don't have any effect; fixes #9746 2019-03-01 14:50:51 +01:00
zah
e9d3c5de19 Fix corner-case uses of newLit (#10760) 2019-03-01 11:09:13 +01:00
Andreas Rumpf
728ff1004a gc:destructors: progress 2019-02-28 22:39:24 +01:00
Andreas Rumpf
9563be37d3 destructor based seqs: bugfix 2019-02-28 22:39:24 +01:00
zah
ca4b971bc8 Initial version of the hot-code reloading support for native targets (#10729)
* squashed work by Zahary

* squashing a ton of useful history... otherwise rebasing on top of upstream Nim after commit 82c009a2cb would be impossible.

* Code review changes; Working test suite (without code reloading enabled)

* - documentation
- implemented the HCR test - almost works...
- fix the issue on Unix where for executable targets the source file for the main module of a project in nimcache was being overwritten with the binary itself (and thus the actual source code was lost)
- fixing embedded paths to shared objects on unix (the "lib" prefix was being prepended to the entire path instead of just the filename)
- other fixes
- removing unnecessary includes since that file is already included in chcks.nim which is in turn included in system.nim (and previously was getting imported in chcks.nim but then system.nim improts something... and that breaks HCR (perhaps it could be fixed but it would be nice not to import anything in system))

* fix for clang & C++ - explicitly casting a function pointer to void*
more stable mangling of parameter names when HCR is on
the length of the static arrays in the DatInit functions is now part of the name of the variables, so when they get resized they get also recreated
more stable mangling for inline functions - no longer depends on the module which first used them
work on the new complicated HCR test - turned surprisingly complex - WIP
test now successfully passes even when re-running `koch test` (previously when the nimcache wasn't cold that lead to errors)
better documentation
calling setStackBottomWith for PreMain
passes over the HcrInit/DatInit/Init calls of all modules are now in the proper order (first all of one type, then all of the next). Also typeinfo globals are registered (created) in a single pass before the DatInit pass (because of the way generic instantiations are handled)
Fix the test suite execution on macOs
fix for being able to query the program arguments when using HCR on posix!
other fixes

* Bugfix: Fix a compilation error in C++ mode when a function pointer
is converted to a raw pointer

* basic documentation for the new hot code reloading semantics

* Add change log entry

* Don't re-execute the top-level statements while reloading JS code

* fix a number of tests broken in a recent bugfix

* Review changes

* Added {.executeOnReload.} pragma that indicates top-level statements
  that should be executed on each reload. To make this work, I've modified
  the way the `if (hcr_init_) {...}` guards are produced in the init code.
  This still needs more work as the new guards seem to be inserted within
  the previously generated guards.

  This change also removes the need for `lastRegistedGlobal` in nimhcr.

* Implemented the `signatureHash` magic and the `hasModuleChanged` API
  depending on it (the actual logic is not imlemented yet).

* Add the "hcr" prefix to all HCR-related symbols in the system module.
  Added a new `hotcodereloading` module exporting the high-level API to
  the user.

  Besides being more hygienic, this was also required in order to make
  it possible to use macros in the high-level API. Without the split,
  `system` would have to import `macros`, which was going to produce
  the well-known init problems.

* Attempted to solve the "GC markers problem".

  Crashes were expected with the previous code, because the GC markers
  were compiled as normal procs are registered in the GC. When their
  module is unloaded, dangling pointers will remain in the GC tables.
  To solve this issue, I don't register any GC markers when HCR is on,
  but I add them to the HCR globals metadata and I use a single marker
  registed in nimhcr during the initialization of the system module that
  will be responsible for marking all globals.

* fix a compilation error

* - implemented the hasModuleChanged functionality
- tuples can be returned and broken into different vars in global scope
- added comments for the closnig scopes of the if statements in the init proc
- the new executeOnReload pragma works now!
- other fixes

* finally! fixing this hack in a proper way - declaring the destructor out of line (out of the class body) - we no longer need to forward-declare popCurrentExceptionEx

* Force full module parsing

This is a temporary hack that breaks some tests. I'll investigate
later how these can be fixed.

* tuples are now properly handled when global!

* these comments mess up the codegen in debug mode when $n is not actually a new line (or something like that) - these labels are intended only for GOTO labels anyway...

* "solved" the issue with the .pdb locks on windows when a binary is being debugged and hot code reloading is used at the same time

* fixes after rebasing...

* small fixes for the test

* better handling of globals! no more compiler crashes for locals with the global pragma, also simplified code around loops in global scope which have local vars (actually globals)

* we can now use the global pragma even for ... globals!

* the right output

* lets try those boehm GC tests

* after the test is ran it will be at its starting state - no git modifications

* clarification in the docs

* removed unnecessary line directives for forward declarations of functions - they were causing trouble with hot code reloading when no semantic change propagates to the main module but a line directive got changed and thus the main module had to be recompiled since the .c code had changed

* fixed bug! was inserting duplicate keys into the table and later was removing only 1 copy of all the duplicates (after a few reloads)

* no longer breaking into DatInit code when not supposed to

* fixes after rebasing

* yet more fixes after rebasing

* Update jssys.nim

* Rework the HCR path-handling logic

After reviewing the code more carefully, I've noticed that the old logic
will be broken when the user overrides the '--out:f' compiler option.

Besides fixing this issues, I took the opportunity to implement the
missing '--outdir:d' option.

Other changes:

* ./koch test won't overwrite any HCR and RTL builds located in nim/lib
* HCR and RTL are compiled with --threads:on by default

* Clean up the globals registration logic

* Handle non-flattened top-level stmtlists in JS as well

* The HCR is not supported with the Boehm GC yet

Also fixes some typos and the expected output of the HCR integration test

* The GC marker procs are now properly used as trampolines

* Fix the HCR integration test in release builds

* Fix ./koch tools

* this forward declaration doesn't seem to be necessary, and in fact breaks HCR because a 2nd function pointer is emitted for this externed/rtl func

* the forward declaration I removed in the last commit was actually necessary

* Attempt to make all tests green

* Fix tgenscript

* BAT file for running the HCR integration test on Windows [skip ci]

* Fix the docgen tests

* A final fix for Travis (hopefully)
2019-02-26 15:48:55 +01:00
Andreas Rumpf
418cbbb450 macros.nim: spacing 2019-02-21 12:03:34 +01:00
LemonBoy
cf32d61fa5 Prevent crash on pragma templates w/ generics (#10685)
* Prevent crash on pragma templates w/ generics

* Remove incorrect call to pragma reconversion

`semOverloadedCall` may return a node with more elements than the
original nkCall node had (implicit and/or explicit generics).
2019-02-18 12:17:00 +01:00
narimiran
d3e35c3200 macros: add links in the docs [ci skip] 2019-02-11 09:11:04 +01:00
Timothee Cour
4910608394 revive #10228 (fix #9880) (#10610)
* Make index out of bounds more useful by including the 'bounds'.
* fixes #9880 index out of bounds (remaining cases); revives #10228
* change err msg to: `index 3 not in 0 .. 1`
2019-02-10 22:07:11 +01:00
Dean Thompson
d46a590f74 Expanded the typeinfo module's doc comment to warn that rtti will evolve and suggest alternative approaches. (#10596) 2019-02-10 08:56:28 +01:00
LemonBoy
1e88bf1def Misc macro things (#10612)
* Misc cleanup in macro code

Generate error messages using `error` instead of `assert`.

Fixes #10574

* Fix crash with hasCustomPragma on quoted fields

Use the `$` operator instead of reaching for the `strVal` field directly
2019-02-09 18:22:07 +01:00
Andreas Rumpf
6fc90ab1c2 macros.nim: minor comment change 2019-02-08 16:09:22 +01:00
LemonBoy
26255c72fd Fix getCustomPragmaVal on var fields 2019-02-06 11:34:55 +01:00
Andreas Rumpf
57b49cc509 allocators: add a name field for easier debugging 2019-02-04 21:06:23 +01:00
Andreas Rumpf
dee8e6e98a gc: destructors is beginning to work (#10483)
* kochdocs.nim: code cleanup
* docgen: nicer indentation
* parser.nim: code cleanup
* fixes #10458
* make tests green again
* make =destroy mixins
* gc:destructors: produced C code is almost working
* --gc:destructors simple program compiles (but leaks memory)
* gc:destructors make examples compile in C++ mode
* destructors: string implementation bugfixes
* strs.nim: minor code cleanup
* destructors: builtin seqs are beginning to work
* remove debugging helpers
2019-01-29 15:12:16 +01:00
Ico Doornekamp
f11f36e7d5 Fixed getCustomPragmaVal to allow multiple fields in custom annotations (#10289) 2019-01-18 09:04:12 +01:00
Ico Doornekamp
7e7603ed2b Documented error source argument of macros.error() (#10279) 2019-01-12 08:17:20 +01:00
Araq
647066e378 make the stdlib work with the changed docgen 2019-01-11 22:17:43 +01:00
jcosborn
044cef152f add custom pragma support for var and let symbols (#9582)
* add custom pragma support for var and let symbols
* updated changelog for custom pragmas on var and let symbols
* add oldast switch for backwards compatibility
2019-01-07 12:36:06 +01:00
Andreas Rumpf
3300c8a500 much simpler implementation of constant tuple declarations 2018-12-19 11:11:33 +01:00
Neelesh Chandola
8e90ed0618 Const tuple unpacking (#9964)
* tuple unpacking is now supported for consts

* Move nkConstTuple to the end of TNodeKind

* Add nnkConstTuple in macros.nim

* Fix Formatting
2018-12-19 10:52:41 +01:00
Andreas Rumpf
e3a668a33b --gc:destructors: baby steps 2018-12-15 13:54:41 +01:00
Araq
24106ade8f hotfix: discriminants can be of size 8 bytes [backport] 2018-12-05 09:43:59 +01:00
Andreas Rumpf
350396e1ca gc:destructors: more progress 2018-11-29 20:10:52 +01:00
Andreas Rumpf
7d82df20be gc:destructors further progress 2018-11-29 01:13:32 +01:00
Andreas Rumpf
8990764709 some progress on --gc:destructors 2018-11-27 00:36:29 +01:00
Andreas Rumpf
413580bc04 new minor language feature: .noSideEffect blocks like .gcsafe blocks 2018-11-27 00:36:29 +01:00
cooldome
086676782a Add isInstanceOf for generic procs to the macros module (#9730) 2018-11-21 21:30:03 +01:00
Araq
3f6168b337 removes deprecated T/P types 2018-11-16 13:27:56 +01:00
Araq
4bd9f32f33 --gc:destructors: hello world example compiles and runs 2018-11-16 00:13:49 +01:00
Lolo Iccl
37d88e5168 Add proc [](n: NimNode, s: HSlice[T, U]): seq[NimNode] to macros (#7735)
fixes #7670.
2018-11-10 14:10:50 +01:00
Arne Döring
573d02760e newLit works on enum (#9662)
* newLit works on enum

* remove debugging echo
2018-11-09 12:15:00 +01:00
Andreas Rumpf
24902394f7 VM: don't inject destructor calls, refs #7041 2018-11-06 19:36:39 +01:00
B3liever
fb75e3bb49 Fix names set and get procs in macros 2018-10-30 15:42:48 +02:00
Kaushal Modi
f8cef575b3 Improve dumpLisp macro (#9515)
* Improve dumpLisp macro

- Remove commas from the lisp representation of the AST.
- Make the dumpLisp output "pretty" and indented.
- Improve docs of `dumpTree` and `dumpLisp` macros.

With:

    dumpLisp:
      echo "Hello, World!"

Output before this commit:

    StmtList(Command(Ident("echo"), StrLit("Hello, World!")))

Output after this commit:

    (StmtList
     (Command
      (Ident "echo")
      (StrLit "Hello, World!")))

* Re-use the traverse proc inside treeRepr for lispRepr too

- Add module-local `treeTraverse` proc.
- Also fix treeRepr/dumpTree not printing nnkCommentStmt node contents.

* More doc string updates

* Allow unindented lispRepr output for tests

* Update a test affected by the lispRepr change

* Fix dumpTree

* Add note about lispRepr and dumpLisp to changelog [ci skip]
2018-10-27 14:10:05 +01:00
cooldome
eaca5be9d6 Change the order of compilation passes, transformation is made lazy at code gen (#8489)
* Ast no transformation
* Add getImplNoTransform to the macros module
* progress on delaying transf
* Fix methods tranformation
* Fix lazy lambdalifting
* fix create thread wrapper
* transform for lambda lifting
* improve getImplTransformed
* Fix destructor tests
* try to fix nimprof for linux
2018-10-18 20:21:25 +02:00
Arne Döring
f9bc4d014a changelog entry 2018-10-18 16:07:15 +02:00
Arne Döring
016e0b1aac fix typo 2018-10-18 15:42:14 +02:00
Arne Döring
358b5225df fixed comment 2018-10-18 15:39:22 +02:00
Arne Döring
48697dc5bb added test case for or operator 2018-10-18 15:39:22 +02:00
Arne Döring
abe8ac1962 or on NimNode 2018-10-18 15:39:22 +02:00
Vindaar
9cdd9be5a5 fixes #8916 by fixing typeinfo and marshal. (#9341)
* fixes #8916 by removing `tyString`, `tySeq`, mod. marshal, typeinfo

Need to check in `typeinfo` for nil of the underlying pointer.
In marshal don't have to check for nil of seq anymore.

* remove reference to string, sequence in `isNil` doc string
2018-10-13 08:47:58 +02:00
LemonBoy
0ead36dae6 Unchecked arrays now have their own type (#9267) 2018-10-10 21:03:18 +02:00
LemonBoy
32d5b80938 Fix macro expansion in expandMacros (#8998)
* Fix macro expansion in expandMacros

Running a semanticized node trough the semantic pass was a bad idea.

Fixes #7723

* Simpler smaller implementation
2018-10-09 23:24:54 +02:00