Closed adokitkat closed 2 months ago
More meaningful code, change CellVal = int|float
to CellVal = int
and it works:
import std/[sequtils]
type
Reactor = ref object
cells: seq[Cell]
CellKind = enum
CellInput, CellCompute
CellVal = int|float
CellComputeFunction = proc(vals: seq[CellVal]): CellVal
CellComputeCallback = proc(x: CellVal)
Cell = ref object
reactor: Reactor
val: CellVal
case kind: CellKind
of CellInput: discard
of CellCompute:
input: seq[Cell]
function: CellComputeFunction
callbacks: seq[ref CellComputeCallback]
proc newReactor*(): Reactor = Reactor()
proc value*(cell: Cell): CellVal =
if cell.kind == CellInput:
result = cell.val
elif cell.kind == CellCompute:
result = cell.function(cell.input.map(value))
proc update(reactor: Reactor) =
for cell in reactor.cells:
if cell.val != cell.value:
for callback in cell.callbacks:
callback[](cell.value)
proc `value=`*(cell: Cell, value: CellVal) =
cell.val = value
cell.reactor.update()
proc createInput*(reactor: Reactor, value: CellVal): Cell =
result = Cell(kind: CellInput, reactor: reactor, val: value)
reactor.cells.add result
proc createCompute*(reactor: Reactor, input: seq[Cell], function: CellComputeFunction): Cell =
result = Cell(kind: CellCompute, reactor: reactor, input: input, function: function)
result.val = result.value
reactor.cells.add result
when isMainModule:
block test:
proc sum(values: seq[CellVal]): CellVal = values.foldl(a + b)
let
reactor = newReactor()
i1 = reactor.createInput(1)
i2 = reactor.createInput(2)
c1 = reactor.createCompute(@[i1, i2], sum)
assert c1.value == 3
!nim c
import std/sequtils
type
Reactor = ref object
cells: seq[Cell]
CellKind = enum
CellInput, CellCompute
CellVal = int|float
CellComputeFunction = proc(vals: seq[CellVal]): CellVal
CellComputeCallback = proc(val: CellVal)
Cell = ref object
reactor: Reactor
val: CellVal
case kind: CellKind
of CellInput: discard
of CellCompute:
input: seq[Cell]
function: CellComputeFunction
callbacks: seq[ref CellComputeCallback]
proc newReactor*(): Reactor = Reactor()
function: CellComputeFunction
callbacks: seq[ref CellComputeCallback]
This is invalid, in Nim int or float
is a generic constraint, so you have a generic procedure inside of your typedef, you need to do
type
CellComputeFunction[T: CellVal] = proc(vals: seq[T]): T
CellComputeCallback[T: CellVal] = proc(val: T)
Cell[T: CellVal] = ref object
reactor: Reactor
val: CellVal
case kind: CellKind
of CellInput: discard
of CellCompute:
input: seq[Cell]
function: CellComputeFunction[T]
callbacks: seq[ref CellComputeCallback[T]]
Or more likely use a object variant for your CellVal
@juancarlospaco (contributor)devel :-1: FAIL
Output
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
assertions.nim(34) raiseAssert
Error: unhandled exception: liftdestructors.nim(602, 5) `t.destructor != nil` [AssertionDefect]
2023-08-02T18:00:26Z
2023-08-02T18:01:03
2023-08-02T18:01:04
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-02T18:00:26Z
2023-08-02T18:01:04
2023-08-02T18:01:04
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-02T18:00:26Z
2023-08-02T18:01:07
2023-08-02T18:01:08
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-08-02T18:00:26Z
2023-08-02T18:01:10
2023-08-02T18:01:11
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-08-02T18:00:26Z
2023-08-02T18:01:26
2023-08-02T18:01:26
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-08-02T18:00:26Z
2023-08-02T18:01:39
2023-08-02T18:01:40
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-08-02T18:00:26Z
2023-08-02T18:01:53
2023-08-02T18:01:53
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
81.94 Kb
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(x, y)
#define nimln_(x, y)
static N_INLINE(void, initStackBottomWith)(void* locals);
N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static N_INLINE(void, initStackBottomWith)(void* locals) {
nimGC_setStackBottom(locals);
}
void PreMainInner(void) {
}
int cmdCount;
char** cmdLine;
char** gEnv;
void PreMain(void) {
void (*volatile inner)(void);
inner = PreMainInner;
systemDatInit000();
initStackBottomWith((void *)&inner);
systemInit000();
(*inner)();
}
N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
initStackBottomWith((void *)&inner);
(*inner)();
}
int main(int argc, char** args, char** env) {
cmdLine = args;
cmdCount = argc;
gEnv = env;
NimMain();
return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
}
}
```
2022-09-23 19:05:05 +0800
on commit #7739e2342 with message:
```
defaults to ORC (#19972)
* defaults to Orc
* bootstrap using refc
* use gc
* init orc defines
* unregister orc
* fix gc
* fix commands
* add prepareMutation for orc
* enable deepcopy for orc
* prepareMutation
* more fixes
* some cases
* bug #20081
* partial fixes
* partial fixes
* fixes command line
* more fixes
* build Nim with refc
* use gc
* more fixes
* rstore
* orc doesn't support threadpool
* more shallowCopy
* more fixes
* fixes unsafeNew
* workarounds
* small
* more fixes
* fixes some megatest
* tcodegenbugs1 refc
* fxies megatest
* build nimble with refc
* workaround tensordsl tests
* replace shallowCopy with move
* fixes action
* workaround
* add todo
* fixes important packages
* unpublic unregisterArcOrc
* fixes cpp
* enable windows
Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
```
The bug is in the files:
```
.github/workflows/ci_docs.yml
compiler/commands.nim
compiler/nim.nim
compiler/options.nim
koch.nim
lib/system/iterators.nim
nimsuggest/sexp.nim
testament/categories.nim
testament/important_packages.nim
tests/assign/moverload_asgn2.nim
tests/async/tasync_traceback.nim
tests/ccgbugs/t13062.nim
tests/ccgbugs/tassign_nil_strings.nim
tests/ccgbugs/tcodegenbug1.nim
tests/ccgbugs/tdeepcopy_addr_rval.nim
tests/ccgbugs/thtiobj.nim
tests/ccgbugs/tmissinginit.nim
tests/ccgbugs/tmissingvolatile.nim
tests/collections/tseq.nim
tests/concepts/t3330.nim
tests/concepts/tusertypeclasses.nim
tests/destructor/tatomicptrs.nim
tests/errmsgs/t10376.nim
tests/exception/tcpp_imported_exc.nim
tests/generics/tgeneric3.nim
tests/generics/tparam_binding.nim
tests/gensym/tgensymgeneric.nim
tests/ic/config.nims
tests/iter/tshallowcopy_closures.nim
tests/macros/tstaticparamsmacro.nim
tests/magics/t10307.nim
tests/magics/tmagics.nim
tests/manyloc/keineschweine/keineschweine.nim.cfg
tests/manyloc/keineschweine/lib/estreams.nim
tests/metatype/tmetatype_various.nim
tests/metatype/tstaticparammacro.nim
tests/metatype/tstaticvector.nim
tests/misc/taddr.nim
tests/misc/tnew.nim
tests/misc/trunner_special.nim
tests/misc/tunsignedconv.nim
tests/modules/tmodule_name_clashes.nim
tests/niminaction/Chapter3/various3.nim
tests/objects/t4318.nim
tests/objects/tobj_asgn_dont_slice.nim
tests/objects/tobjconstr.nim
tests/parallel/tconvexhull.nim
tests/parallel/tdeepcopy.nim
tests/parallel/tdeepcopy2.nim
tests/parallel/tdisjoint_slice1.nim
tests/parallel/tflowvar.nim
tests/parallel/tinvalid_array_bounds.nim
tests/parallel/tmissing_deepcopy.nim
tests/parallel/tnon_disjoint_slice1.nim
tests/parallel/tparfind.nim
tests/parallel/tpi.nim
tests/parallel/tsendtwice.nim
tests/parallel/tsysspawn.nim
tests/parallel/tuseafterdef.nim
tests/parallel/twaitany.nim
tests/parser/t12274.nim
tests/pragmas/t12640.nim
tests/pragmas/tnoreturn.nim
tests/stdlib/mgenast.nim
tests/stdlib/tgenast.nim
tests/stdlib/thttpclient_ssl.nim
tests/stdlib/tjson.nim
tests/stdlib/tmitems.nim
tests/stdlib/tstdlib_various.nim
tests/stdlib/tstring.nim
tests/stdlib/twchartoutf8.nim
tests/system/tdeepcopy.nim
tests/template/twrongmapit.nim
tests/threads/tjsthreads.nim
tests/threads/tonthreadcreation.nim
tests/typerel/t4799_1.nim
tests/typerel/t4799_2.nim
tests/typerel/t4799_3.nim
tests/typerel/ttypedesc_as_genericparam1.nim
tests/typerel/ttypedesc_as_genericparam1_orc.nim
tests/typerel/ttypedesc_as_genericparam2.nim
```
The bug can be in the commits:
(Diagnostics sometimes off-by-one).
10 minutes
bisecting 1626
commits at 156
commits per second. !nim c --gc:arc
import std/sequtils
type
Reactor = ref object
cells: seq[Cell]
CellKind = enum
CellInput, CellCompute
CellVal = int|float
CellComputeFunction = proc(vals: seq[CellVal]): CellVal
CellComputeCallback = proc(val: CellVal)
Cell = ref object
reactor: Reactor
val: CellVal
case kind: CellKind
of CellInput: discard
of CellCompute:
input: seq[Cell]
function: CellComputeFunction
callbacks: seq[ref CellComputeCallback]
proc newReactor*(): Reactor = Reactor()
@ringabout (member)devel :-1: FAIL
Output
Error: Command failed: nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
command line(1, 2) Warning: `gc:option` is deprecated; use `mm:option` instead [Deprecated]
assertions.nim(34) raiseAssert
Error: unhandled exception: liftdestructors.nim(602, 5) `t.destructor != nil` [AssertionDefect]
2023-08-03T04:35:00Z
2023-08-03T04:35:52
2023-08-03T04:35:52
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:35:53
2023-08-03T04:35:53
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:35:57
2023-08-03T04:35:57
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:36:01
2023-08-03T04:36:02
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:36:18
2023-08-03T04:36:19
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:36:33
2023-08-03T04:36:33
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
2023-08-03T04:35:00Z
2023-08-03T04:36:44
2023-08-03T04:36:44
now
nim c --gc:arc --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0 bytes
```cpp
```
56 minutes
bisecting 7
commits at 0
commits per second. Now, it errors with 'CellVal' is not a concrete type
Description
Hi,
if I understand things correctly, the code below crashes the compiler (?).
Works when compiled with
refc
instead oforc
. The culprit isCellVal = int|float
. If it's set just toCellVal = int
orCellVal = float
, the code works correctly.The code without
proc newReactor*(): Reactor = Reactor()
also compiles fine. I will post a a longer (and more useful) code in a comment below, this is just the minimal code example I get the error with.Nim Version
Nim Compiler Version 2.0.0 [Linux: amd64] Compiled at 2023-08-01 Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a488067a4130f029000be4550a0fb1b39e0e9e7c active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
I also get different error, now with a nicer error message, when I change
CellComputeCallback = proc(val: CodeVal)
just toCellComputeCallback = proc(val: int)
orCellComputeCallback = proc(val: float)
with everything else usingCodeVal = int|float
.However I don't know if this one is a bug or is "OK".