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

StackOverflowError during Measure Inference #1536

Open
drganam opened this issue Jun 6, 2024 · 0 comments
Open

StackOverflowError during Measure Inference #1536

drganam opened this issue Jun 6, 2024 · 0 comments

Comments

@drganam
Copy link
Collaborator

drganam commented Jun 6, 2024

When running the termination check for the following program, Stainless crashes with a stack overflow error:

import stainless.lang._

object C_formula_sol338 {
   
  sealed abstract class Formula {}
  case object True_ extends Formula {}
  case object False_ extends Formula {}
  case class Not(param0: Formula) extends Formula {}
  case class AndAlso(param0: Formula, param1: Formula) extends Formula {}
  case class OrElse(param0: Formula, param1: Formula) extends Formula {}
  case class Imply(param0: Formula, param1: Formula) extends Formula {}
  case class Equal(param0: Exp, param1: Exp) extends Formula {}

  sealed abstract class Exp {}
  case class Num(param0: Int) extends Exp {}
  case class Plus(param0: Exp, param1: Exp) extends Exp {}
  case class Minus(param0: Exp, param1: Exp) extends Exp {}

  
  def cal_exp(n: Exp): Int = {
    n match {
      case Num(a) => { a }
      case Plus(e1, e2) => { cal_exp(e1) + cal_exp(e2) }
      case Minus(e1, e2) => { cal_exp(e1) - cal_exp(e2) }
    }
  }
  
  def eval(f: Formula): Boolean = {
    f match {
      case True_ => { true }
      case False_ => { false }
      case Not(x) => {
        
        val v = eval(x)
        v match {
          case true => { eval(False_) }
          case false => { eval(True_) }
        }
        
      }
      case AndAlso(e1, e2) => {
        
        val v1 = eval(e1)
        
        val v2 = eval(e2)
        (v1, v2) match {
          case (true, true) => { eval(True_) }
          case (true, false) => { eval(False_) }
          case (false, true) => { eval(False_) }
          case (false, false) => { eval(False_) }
        }
        
        
      }
      case OrElse(e1, e2) => {
        
        val v1 = eval(e1)
        
        val v2 = eval(e2)
        (v1, v2) match {
          case (true, true) => { eval(True_) }
          case (true, false) => { eval(True_) }
          case (false, true) => { eval(True_) }
          case (false, false) => { eval(False_) }
        }
        
        
      }
      case Imply(e1, e2) => {
        
        val v1 = eval(e1)
        
        val v2 = eval(e2)
        (v1, v2) match {
          case (true, true) => { eval(True_) }
          case (true, false) => { eval(False_) }
          case (false, true) => { eval(True_) }
          case (false, false) => { eval(True_) }
        }
        
        
      }
      case Equal(e1, e2) => {
        
        val v1 = cal_exp(e1)
        
        val v2 = cal_exp(e2)
        (v1, v2) match {
          case (v1, v2) => { if (v1 == v2) eval(True_) else eval(False_) }
        }
        
        
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant