Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexDefect on --verbosity:3 when compiling nimbus #24021

Closed
arnetheduck opened this issue Aug 28, 2024 · 3 comments · Fixed by #24290
Closed

IndexDefect on --verbosity:3 when compiling nimbus #24021

arnetheduck opened this issue Aug 28, 2024 · 3 comments · Fixed by #24290

Comments

@arnetheduck
Copy link
Contributor

Description

/compiler/sem.nim(836) semStmtAndGenerateGenerics
/compiler/semstmts.nim(2689) semStmt
/compiler/semexprs.nim(1182) semExprNoType
/compiler/semexprs.nim(3323) semExpr
/compiler/semstmts.nim(2636) semStmtList
/compiler/semexprs.nim(3356) semExpr
/compiler/importer.nim(360) evalImport
/compiler/importer.nim(328) impMod
/compiler/importer.nim(293) myImportModule
/compiler/passes.nim(201) importModule
/compiler/passes.nim(172) compileModule
/compiler/passes.nim(149) processModule
/compiler/passes.nim(82) processTopLevelStmt
/compiler/passes.nim(252) mySemProcess
/compiler/sem.nim(867) semWithPContext
/compiler/sem.nim(836) semStmtAndGenerateGenerics
/compiler/semstmts.nim(2689) semStmt
/compiler/semexprs.nim(1182) semExprNoType
/compiler/semexprs.nim(3323) semExpr
/compiler/semstmts.nim(2636) semStmtList
/compiler/semexprs.nim(3342) semExpr
/compiler/semstmts.nim(2458) semFunc
/compiler/semstmts.nim(2380) semProcAux
/compiler/sempass2.nim(1489) trackProc
/compiler/sempass2.nim(1091) track
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1205) track
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1146) track
/compiler/sempass2.nim(701) trackCase
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1147) track
/compiler/sempass2.nim(725) trackIf
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1146) track
/compiler/sempass2.nim(701) trackCase
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1091) track
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1215) track
/compiler/sempass2.nim(1328) track
/compiler/sempass2.nim(1087) track
/compiler/guards.nim(1063) checkFieldAccess
/compiler/guards.nim(731) doesImply
/compiler/guards.nim(723) factImplies
/compiler/guards.nim(555) impliesIn
/compiler/guards.nim(541) compareSets
/compiler/nimsets.nim(129) equalSets
/compiler/nimsets.nim(75) toBitSet
/compiler/bitsets.nim(34) bitSetIncl
/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]
git clone https://github.com/status-im/nimbus-eth1.git
make
./env.sh nim c nimbus/nimbus --verbosity:3

Nim Version

2.0.8

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@arnetheduck
Copy link
Contributor Author

also on --verbosity:2

@metagn
Copy link
Collaborator

metagn commented Oct 12, 2024

Minimal options would be --warning[ProveField]:on or --experimental:strictCaseObjects

Happens here:

https://github.com/status-im/nimbus-eth1/blob/6e114dc95054ab9ccd85da596f57c682685399bc/nimbus/db/aristo/aristo_part/part_helpers.nim#L169

For some reason the compiler is producing a set {0, 1, 2, 3, 4, 5, 6, 7, 8, ...} but set[PrfType] has size 1 and can't contain 8. I can't come up with a minimal reproduction for this. see below

metagn added a commit to metagn/Nim that referenced this issue Oct 12, 2024
@metagn
Copy link
Collaborator

metagn commented Oct 12, 2024

Minimized:

type
  FooKind = enum
    a
    b
  BiggerEnum = enum b1, b2, b3, b4, b5, b6, b7, b8, b9, b10
  Foo = object
    case kind: FooKind
    of a: discard
    else:
      z: BiggerEnum

proc p(foo: Foo, val: int) =
  case foo.kind
  of a:
    discard
  else:
    discard foo.z

The type for the field check on FooKind is conflated with BiggerEnum somehow. There's a patch that works around this (using n[1].typ.elementType instead of n[2].typ here) but I don't know the root cause yet.

Found the root cause #24290

Araq pushed a commit that referenced this issue Oct 12, 2024
…[backport] (#24290)

fixes #24021

The field checking for case object branches at some point generates a
negated set `contains` check for the object discriminator. For enum
types, this tries to generate a complement set and convert to a
`contains` check in that instead. It obtains this type from the type of
the element node in the `contains` check.

`buildProperFieldCheck` creates the element node by changing a field
access expression like `foo.z` into `foo.kind`. In order to do this, it
copies the node `foo.z` and sets the field name in the node to the
symbol `kind`. But when copying the node, the type of the original
`foo.z` is retained. This means that the complement is performed on the
type of the accessed field rather than the type of the discriminator,
which causes problems when the accessed field is also an enum.

To fix this, we properly set the type of the copied node to the type of
the kind field. An alternative is just to make a new node instead.

A lot of text for a single line change, I know, but this part of the
codebase could use more explanation.
narimiran pushed a commit that referenced this issue Oct 23, 2024
…[backport] (#24290)

fixes #24021

The field checking for case object branches at some point generates a
negated set `contains` check for the object discriminator. For enum
types, this tries to generate a complement set and convert to a
`contains` check in that instead. It obtains this type from the type of
the element node in the `contains` check.

`buildProperFieldCheck` creates the element node by changing a field
access expression like `foo.z` into `foo.kind`. In order to do this, it
copies the node `foo.z` and sets the field name in the node to the
symbol `kind`. But when copying the node, the type of the original
`foo.z` is retained. This means that the complement is performed on the
type of the accessed field rather than the type of the discriminator,
which causes problems when the accessed field is also an enum.

To fix this, we properly set the type of the copied node to the type of
the kind field. An alternative is just to make a new node instead.

A lot of text for a single line change, I know, but this part of the
codebase could use more explanation.

(cherry picked from commit 1bebc23)
narimiran pushed a commit that referenced this issue Oct 23, 2024
…[backport] (#24290)

fixes #24021

The field checking for case object branches at some point generates a
negated set `contains` check for the object discriminator. For enum
types, this tries to generate a complement set and convert to a
`contains` check in that instead. It obtains this type from the type of
the element node in the `contains` check.

`buildProperFieldCheck` creates the element node by changing a field
access expression like `foo.z` into `foo.kind`. In order to do this, it
copies the node `foo.z` and sets the field name in the node to the
symbol `kind`. But when copying the node, the type of the original
`foo.z` is retained. This means that the complement is performed on the
type of the accessed field rather than the type of the discriminator,
which causes problems when the accessed field is also an enum.

To fix this, we properly set the type of the copied node to the type of
the kind field. An alternative is just to make a new node instead.

A lot of text for a single line change, I know, but this part of the
codebase could use more explanation.

(cherry picked from commit 1bebc23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants