Skip to content

case class with more than 195 fields causes stackOverflowError in pickler #16500

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

Closed
philwalk opened this issue Dec 11, 2022 · 0 comments · Fixed by #16501
Closed

case class with more than 195 fields causes stackOverflowError in pickler #16500

philwalk opened this issue Dec 11, 2022 · 0 comments · Fixed by #16501

Comments

@philwalk
Copy link
Contributor

Compiler version

Scala code runner version 3.2.2-RC1 -- Copyright 2002-2022, LAMP/EPFL

Minimized code

#!/usr/bin/env scala3

def main(args: Array[String]): Unit =
  println("hello!")

type I = Int
case class BigClass(
  company_id:I,
  udef00:I, udef01:I, udef02:I, udef03:I, udef04:I, udef05:I, udef06:I, udef07:I, udef08:I, udef09:I,
  udef0a:I, udef0b:I, udef0c:I, udef0d:I, udef0e:I, udef0f:I, udef10:I, udef11:I, udef12:I, udef13:I,
  udef14:I, udef15:I, udef16:I, udef17:I, udef18:I, udef19:I, udef1a:I, udef1b:I, udef1c:I, udef1d:I,
  udef1e:I, udef1f:I, udef20:I, udef21:I, udef22:I, udef23:I, udef24:I, udef25:I, udef26:I, udef27:I,
  udef28:I, udef29:I, udef2a:I, udef2b:I, udef2c:I, udef2d:I, udef2e:I, udef2f:I, udef30:I, udef31:I,
  udef32:I, udef33:I, udef34:I, udef35:I, udef36:I, udef37:I, udef38:I, udef39:I, udef3a:I, udef3b:I,
  udef3c:I, udef3d:I, udef3e:I, udef3f:I, udef40:I, udef41:I, udef42:I, udef43:I, udef44:I, udef45:I,
  udef46:I, udef47:I, udef48:I, udef49:I, udef4a:I, udef4b:I, udef4c:I, udef4d:I, udef4e:I, udef4f:I,
  udef50:I, udef51:I, udef52:I, udef53:I, udef54:I, udef55:I, udef56:I, udef57:I, udef58:I, udef59:I,
  udef5a:I, udef5b:I, udef5c:I, udef5d:I, udef5e:I, udef5f:I, udef60:I, udef61:I, udef62:I, udef63:I,
  udef64:I, udef65:I, udef66:I, udef67:I, udef68:I, udef69:I, udef6a:I, udef6b:I, udef6c:I, udef6d:I,
  udef6e:I, udef6f:I, udef70:I, udef71:I, udef72:I, udef73:I, udef74:I, udef75:I, udef76:I, udef77:I,
  udef78:I, udef79:I, udef7a:I, udef7b:I, udef7c:I, udef7d:I, udef7e:I, udef7f:I, udef80:I, udef81:I,
  udef82:I, udef83:I, udef84:I, udef85:I, udef86:I, udef87:I, udef88:I, udef89:I, udef8a:I, udef8b:I,
  udef8c:I, udef8d:I, udef8e:I, udef8f:I, udef90:I, udef91:I, udef92:I, udef93:I, udef94:I, udef95:I,
  udef96:I, udef97:I, udef98:I, udef99:I, udef9a:I, udef9b:I, udef9c:I, udef9d:I, udef9e:I, udef9f:I,
  udefa0:I, udefa1:I, udefa2:I, udefa3:I, udefa4:I, udefa5:I, udefa6:I, udefa7:I, udefa8:I, udefa9:I,
  udefaa:I, udefab:I, udefac:I, udefad:I, udefae:I, udefaf:I, udefb0:I, udefb1:I, udefb2:I, udefb3:I,
  udefb4:I, udefb5:I, udefb6:I, udefb7:I, udefb8:I, udefb9:I, udefba:I, udefbb:I, udefbc:I, udefbd:I,
  udefbe:I, udefbf:I, udefc0:I,
  udefc1:I,
)

Output (click arrow to expand)

java.lang.StackOverflowError while running pickler on C:\opt\ue\bigCaseClass.sc
java.lang.StackOverflowError while compiling C:\opt\ue\bigCaseClass.sc
Exception in thread "main" java.lang.StackOverflowError
	at dotty.tools.dotc.core.Contexts$ContextBase.erasurePhase(Contexts.scala:828)
	at dotty.tools.dotc.core.Phases$.erasurePhase(Phases.scala:452)
	at dotty.tools.dotc.core.Types$NamedType.sigFromDenot(Types.scala:2256)
	at dotty.tools.dotc.core.Types$NamedType.computeSignature$1(Types.scala:2227)
	at dotty.tools.dotc.core.Types$NamedType.signature(Types.scala:2232)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:404)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$2(TreePickler.scala:420)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$adapted$2(TreePickler.scala:422)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:58)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:422)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$3(TreePickler.scala:432)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$adapted$3(TreePickler.scala:434)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:58)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:434)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$2(TreePickler.scala:420)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$adapted$2(TreePickler.scala:422)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:58)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:422)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$3(TreePickler.scala:432)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$adapted$3(TreePickler.scala:434)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
[1000 lines deleted]

An attempt to represent a database table with 254 columns as a case class.
More than 194 fields triggers a compile error.

If the last line is commented out, compilation succeeds.

Could the size of symRefs be a factor? compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

@philwalk philwalk added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 11, 2022
@odersky odersky self-assigned this Dec 11, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 11, 2022
Required to avoid linear composition of conditions in the `equals` method.

Fixes scala#16500
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 11, 2022
The original error case scala#16500 showed an example of deeply nested code
which blew up TreePickler with a StackOverflow. We now handle this situation
and provide better error diagnostics

 - point to the closes enclosing definition that caused the SO when pickled
 - suggest to increase the stack size with -Xss
@WojciechMazur WojciechMazur added area:pickling and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 12, 2022
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Required to avoid linear composition of conditions in the `equals` method.

Fixes scala#16500
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
The original error case scala#16500 showed an example of deeply nested code
which blew up TreePickler with a StackOverflow. We now handle this situation
and provide better error diagnostics

 - point to the closes enclosing definition that caused the SO when pickled
 - suggest to increase the stack size with -Xss
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
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.

4 participants