summary refs log tree commit diff stats
path: root/compiler/semtempl.nim
Commit message (Collapse)AuthorAgeFilesLines
* make routine implicitly gensym when other gensym symbol exists again (#23842)metagn2024-07-161-5/+7
| | | | | | | | | | | | | fixes #23813, partially reverts #23392 Before #23392, if a `gensym` symbol was defined before a proc with the same name in a template even with an `inject` annotation, the proc would be `gensym`. After #23392 the proc was instead changed to be `inject` as long as no `gensym` annotation was given. Now, to keep compatibility with the old behavior, the behavior is changed back to infer the proc as `gensym` when no `inject` annotation is given, however an explicit `inject` annotation will still inject the proc. This is also documented in the manual as the old behavior was undocumented and the new behavior is slightly different.
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-1/+1
|
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23326 In a routine declaration node in a template, if the routine is marked as `gensym`, the compiler adds it as a new symbol to a preliminary scope of the template. If it's not marked as gensym, then it searches the preliminary scope of the template for the name of the routine, then when it matches a template parameter or a gensym identifier, the compiler replaces the name node with a symbol node of the found symbol. This makes sense for the template parameter since it has to be replaced later, but not really for the gensym identifier, as it doesn't allow us to inject a routine with the same name as an identifier previously declared as gensym (the problem in #23326 is when this is in another `when` branch). However this is the only channel to reuse a gensym symbol in a declaration, so maybe removing it has side effects. For example if we have: ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) {.gensym.} = discard ``` it will not behave the same as ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) = discard ``` behaved previously, which maybe allowed overloading over the gensym'd symbols. A note to the "undeclared identifier" error message has also been added for a potential error code that implicitly depended on the old behavior might give, namely ``undeclared identifier: 'abc`gensym123'``, which happens when in a template an identifier is first declared gensym in code that doesn't compile, then as a routine which injects by default, then the identifier is used.
* don't transform typed bracket exprs to `[]` calls in templates (#23175)metagn2024-01-071-14/+25
| | | | | | | | | | | | | | fixes #22775 It's pre-existing that [`prepareOperand` doesn't typecheck expressions which have types](https://github.com/nim-lang/Nim/blob/a4f3bf374238df96f0982b7106e3702da6b485b1/compiler/sigmatch.nim#L2444). Templates can take typed subscript expressions, transform them into calls to `[]`, and then have this `[]` not be resolved later if the expression is nested inside of a call argument, which leaks an untyped expression past semantic analysis. To prevent this, don't transform any typed subscript expressions into calls to `[]` in templates. Ditto for curly subscripts (with `{}`) and assignments to subscripts and curly subscripts (with `[]=` and `{}=`).
* fixes yet another strictdefs bug (#23069)ringabout2023-12-151-12/+14
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-2/+2
|
* refactor semtempl ident declarations, some special word use (#22693)metagn2023-09-141-62/+42
| | | | | | | | | `semtempl` is refactored to combine the uses of `getIdentNode`, `onlyReplaceParams`, `isTemplParam` and most of `replaceIdentBySym` into a single `getIdentReplaceParams` proc. This might fix possible problems with injections of `nkAccQuoted`. Some special word comparison in `ast` and `semtempl` are also made more efficient.
* correct logic for qualified symbol in templates (#22577)metagn2023-08-281-1/+4
| | | | | | | * correct logic for qualified symbol in templates fixes #19865 * add test
* Fix #21532: Check if template return is untyped (#22517)SirOlaf2023-08-231-0/+3
| | | | | | | | | * Don't ignore return in semTemplateDef * Add test --------- Co-authored-by: SirOlaf <>
* use strictdefs for compiler (#22365)ringabout2023-08-061-0/+1
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* consider object types as declarative in templates (#22106)metagn2023-06-161-13/+36
| | | | | | | | | * consider object types as declarative in templates fixes #16005 * correct logic for nkRecList children, inject fields * don't actually inject fields
* fix dot calls with resolved symbols in templates (#22076)metagn2023-06-121-0/+8
| | | | | | | | | | | | | * fix dot calls with resolved symbols in templates * make old code work * fix custom number literals test * remove leftover debug marker * enable "bug 9" test too * fix renderer, add test for #7085
* retain forced open undeclared ident information (#22019)metagn2023-06-071-4/+3
|
* underscore as special word (#21766)metagn2023-05-021-2/+2
| | | | | * underscore as special word * fix really hard to notice error
* fix #21727 (#21729)metagn2023-04-261-7/+9
|
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-1/+1
| | | | | | | | | | | (#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
* alias syntax fixes, improvements and tests (#21671)metagn2023-04-221-0/+8
| | | | | | | | | | | | | * alias syntax fixes, improvements and tests * even better, cannot use alias syntax with generics * more type tests, improve comment * fix again * consistent error message + make t5167_5 work * more comments, remove {.noalias.}
* underscores for routine parameters (#21192)metagn2023-01-081-2/+3
| | | | | | | | | * underscores for routine parameters fixes #13443, fixes #13804, refs #21121 * add changelog + more tests * support generics and ensure inferred lambdas work
* deprecate `do:` meaning `do ():` + misc cleanup (#20927)metagn2022-12-061-1/+1
| | | | | | | | | | | | | | | | | * test disable do: block lambda lifting * fix last test [skip ci] * deprecate `do:` meaning `do ():` + misc cleanup closes https://github.com/nim-lang/RFCs/issues/486 * oops * fix * no idea what could be causing nimsuggest failure other than this * ensure ci works
* alternate fix + test for #12094, refs #13804 (#20686)metagn2022-10-291-1/+1
|
* fixes #1027; disallow templates to use ambiguous identifiers (#20631)ringabout2022-10-241-0/+2
| | | | | | | | | | | | | | | | | | | | * test qualifiedLookUp in templates * check later * add testcase * add 4errormsg * Update tests/template/m1027a.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * Update tests/template/m1027b.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* fixes #20572 (#20585)Andreas Rumpf2022-10-171-1/+1
| | | | | * fixes #20572 * added a test case
* pragma for sfCallsite instead of name check + better semantics, test (#20464)metagn2022-10-031-6/+0
| | | | | | | | | | | * pragma for sfCallsite instead of name check at every template definition Not documented because it seems to be for internal use? Should also make it possible to make comparisons and setops imports, but this doesn't have to be done. I can reuse a name like `cursor` for the pragma as well, added a new name just to be safe. * make sfCallsite recursive, add tests
* fix #13515 [backport] (#20315)metagn2022-09-111-1/+7
| | | | | | | | | | | * fix #13515 * only compile test * no idea why this PR is unlocking this * don't rope in symchoices * even more restrictive
* overloadable enums no longer experimental (#20298)metagn2022-09-051-7/+3
| | | depends on #20126
* new .redefine pragma for templates, warn on redefinition without it (#20211)metagn2022-08-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * test CI for template redefinitions * adapt asyncmacro * fix quote * fix again * try something else * revert * fix ioselectors_select, disable packages CI * adapt more tests & simplify * more * more * more * rename to redefine, warn on implicit redefinition * basic documentation [skip ci] * Update compiler/lineinfos.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
* fix #20002 (#20004)metagn2022-07-151-1/+1
| | | | | | While this fix seems innocent, this unlocks the hidden behavior of method calls not being able to call gensym'ed routines inside templates.
* Change `styleCheck` to ignore foreign packages (#19822)quantimnot2022-07-141-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Change `styleCheck` to ignore foreign packages * Symbols from foreign packages are now ignored. * Fixed `styleCheck` violations in `compiler` package. * Added symbol ownership to custom annotation pragmas. * Minor refactors to cleanup style check callsites. * Minor internal documentation of reasons why a symbol isn't checked. Style violations were fixed in the compiler after thet were exposed by the changes. The compiler wouldn't compile otherwise. Symbol ownership for custom pragma annotations is needed for checking the annotation's style. A NPE was raised otherwise. Fixes #10201 See also nim-lang/RFCs#456 * Fix a misunderstanding about excluding field style checks I had refactored the callsites of `styleCheckUse` to apply the DRY principle, but I misunderstood the field access handling in a template as a general case. This corrects it. * Fix some `styleCheck` violations in `compiler/evalffi` The violations were exposed in CI when the compiler was built with libffi. * Removed some uneeded transitionary code * Add changelog entry Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* New/better macro pragmas, mark some as experimental (#19406)metagn2022-01-201-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * New/better macro pragmas, make some experimental fix #15920, close #18212, close #14781, close #6696, close https://github.com/nim-lang/RFCs/issues/220 Variable macro pragmas have been changed to only take a unary section node. They can now also be applied in sections with multiple variables, as well as `const` sections. They also accept arguments. Templates now support macro pragmas, mirroring other routine types. Type and variable macro pragmas have been made experimental. Symbols without parentheses instatiating nullary macros or templates has also been documented in the experimental manual. A check for a redefinition error based on the left hand side of variable definitions when using variable macro pragmas was disabled. This nerfs `byaddr` specifically, however this has been documented as a consequence of the experimental features `byaddr` uses. Given how simple these changes are I'm worried if I'm missing something. * accomodate compiler boot * allow weird pragmas * add test for #10994 * remove some control flow, try remove some logic
* fix stylecheck error with asyncdispatch (#19350)flywind2022-01-101-1/+2
| | | | | | | | | | | | | | | | | | | | | * stylecheck usages part two: stdlib cleanup typeinfo.nim: importCompilerProc => importcompilerproc nre.nim: newLineFlags => newlineFlags system.nim: JSRoot => JsRoot ref #19319 * prefer importCompilerProc * fix stylecheck error with asyncdispatch it is a partial regression since #12842 * add tests * don't use echo in tests
* fixes a regression caused by overloadable enums even though they're opt-in ↵Andreas Rumpf2021-10-071-3/+7
| | | | (#18970)
* fixes a 'mixin' statement handling regression [backport:1.2] (#18968)Andreas Rumpf2021-10-071-1/+6
|
* fixes #18863 [backport] (#18871)Andreas Rumpf2021-09-201-3/+4
|
* fix: `var a{.foo.} = expr` inside templates (refs #15920) (except when `foo` ↵Timothee Cour2021-08-111-3/+12
| | | | | | | | | | | is overloaded) (#13869) * fix: `var a{.foo.} = expr` inside templates * add test * improve tdecls test * improve tests * add failing test * PRTEMP * fixup
* Fixed template const tuple unpacking (#18562)Jason Beetham2021-07-231-22/+18
|
* refactoring: removed empty withBracketExpr template (#18152)Andreas Rumpf2021-06-021-10/+4
|
* fix #18113 (#18124)Saem Ghani2021-05-311-2/+6
|
* semTemplateDef and t17433 clean-ups (#17448)Saem Ghani2021-03-221-19/+19
| | | | | - use `doAssert` in t17433 - use setGenericParamsMisc in semTemplateDef akin to semProcAux - pragma handling in semTemplateDef inline with semProcAux
* Fixes #17433; gensym callDef return in templ body (#17445)Saem Ghani2021-03-221-1/+1
|
* semLambda removed, semProcAux reworked (#17379)Saem Ghani2021-03-171-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* fixes #11225; generic sandwich problems; [backport:1.2] (#17255)Andreas Rumpf2021-03-091-3/+7
| | | | | * fixes #11225; generic sandwich problems; [backport:1.2] * progress * delegating these symbols must be done via 'bind'
* Fix #12595 (#16874)konsumlamm2021-01-311-0/+4
|
* IC: next steps (#16550)Andreas Rumpf2021-01-071-1/+1
| | | | | | | | | | | | | | | | | | * cleanups * ast.nim: cleanups * IC: no more sym.tab field, stored externally in the module graph * nimble compiles again * rodfiles: store bitwidth of integers and the endianness in the cookie because we serialize 'int' directly * rodfiles: added compilerproc and export sections * rodfiles: added all the missing sections * rodfiles: track the missing information * IC: architecture for lazy loading of proc bodies * make tests green again * completed the lazy loading of proc bodies * symbol lookup integration, part 1 * symbol lookup integration, part 2 * symbol lookup integration, part 3 * make tcompilerapi work again * rodfiles: fixed config change handling
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-1/+1
| | | | | | | | | | | | | | | | | | | * reworked ID handling * the packed AST now has its own ID mechanism * basic serialization code works * extract rodfiles to its own module * rodfiles: store and compare configs * rodfiles: store dependencies * store config at the end * precise dependency tracking * dependency tracking for rodfiles * completed loading of PSym, PType, etc * removed dead code * bugfix: do not realloc seqs when taking addr into an element * make IC opt-in for now * makes tcompilerapi green again * final cleanups Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-3/+3
| | | | | | | | | | | | | | | | | * refactoring: idents don't need inheritance * refactoring: adding an IdGenerator (part 1) * refactoring: adding an IdGenerator (part 2) * refactoring: adding an IdGenerator (part 3) * refactoring: adding an IdGenerator (part 4) * refactoring: adding an IdGenerator (part 5) * refactoring: adding an IdGenerator (part 5) * IdGenerator must be a ref type; hello world works again * make bootstrapping work again * progress: add back the 'exactReplica' ideas * added back the missing exactReplica hacks * make tcompilerapi work again * make important packages green * attempt to fix the build for 32 bit machines (probably need a better solution here)
* views: yet another bugfix (#15447)Andreas Rumpf2020-10-011-5/+0
| | | | | | | * views: yet another bugfix * views: extended the spec * views: take into account potential hidden mutations via proc calls
* Fix forward declarations in shadow scope contexts (#15386)Clyybber2020-09-221-2/+2
| | | | | | | | | | | | | | | * Fix forward declarations in shadow scope contexts * Add testcase for #15385 * Less empty lines * Fix tests * Inline isShadowScope * Add original testcase (with reduced amount of iterations) * Add testcase without forward decl
* Big compiler Cleanup (#14777)Clyybber2020-08-281-1/+0
|
* Fix forward declaration issues in template/macro context (#15091)Clyybber2020-07-291-22/+5
| | | | | | | | | | | | | | | | | | | | | | | * Fix forward declaration issues in template/macro context * Correct forward declaration resolving for overloads * Remove old dead code * WIP consistent gensym ids * Minimize diff * Remove obsoleted hack * Add templInstCounter to give unique IDs to template instantiations * Remove obsoleted code * Eh, init in myOpen, not myProcess... * Remove optNimV019 * Add testcase for #13484
* fix codegen bug due to changing existing symbol declaration in template (#14666)jcosborn2020-06-151-1/+1
|