Skip to content

Commit

Permalink
Possible implementation errors are now thrown using the Unreachable c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
Ellen Wittingen committed Oct 19, 2023
1 parent dba11b2 commit cdc36a5
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/rewrite/vct/rewrite/lang/LangCPPToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vct.col.rewrite.lang.LangSpecificToCol.NotAValue
import vct.col.rewrite.{Generation, ParBlockEncoder, Rewritten}
import vct.col.util.AstBuildHelpers._
import vct.col.util.{AstBuildHelpers, SuccessionMap}
import vct.result.VerificationError.UserError
import vct.result.VerificationError.{Unreachable, UserError}

import scala.collection.immutable.Seq
import scala.collection.mutable
Expand All @@ -40,11 +40,6 @@ case object LangCPPToCol {
override def text: String = ass.o.messageInContext(s"Reassigning variables holding a SYCL event is not supported.")
}

private case class SYCLEventWaitWrongType(inv: Expr[_]) extends UserError {
override def code: String = "unexpectedSYCLEventWaitWrongType"
override def text: String = inv.o.messageInContext("The declarator for the invocation to sycl::event::wait() is not a SYCL event.")
}

private case class ContractForCommandGroup(contract: ApplicableContract[_]) extends UserError {
override def code: String = "unsupportedContractForCommandGroup"
override def text: String = contract.o.messageInContext(s"Contracts are not supported for SYCL command groups.")
Expand Down Expand Up @@ -79,17 +74,6 @@ case object LangCPPToCol {
"only takes one (nd_)item argument, which should match the first (nd_)range parameter of the parallel_for method.")
}

private case class WrongKernelDimensionType(expr: Expr[_]) extends UserError {
override def code: String = "wrongKernelDimensionType"
override def text: String = expr.o.messageInContext("Wrong type for the dimensions parameter of the kernel. " +
"The dimensions parameter in a kernel declaration is supposed to be of type sycl::range<int> or sycl::nd_range<int>.")
}

private case class NotKernelDimensions(expr: Expr[_]) extends UserError {
override def code: String = "unexpectedNotKernelDimensions"
override def text: String = expr.o.messageInContext("The dimensions parameter of the kernel was not rewritten to a (nd_)range.")
}

private case class SYCLItemMethodInvocationBlame(inv: CPPInvocation[_]) extends Blame[InvocationFailure] {
override def blame(error: InvocationFailure): Unit = error match {
case PreconditionFailed(_, _, node) => inv.blame.blame(SYCLItemMethodPreconditionFailed(node))
Expand Down Expand Up @@ -136,7 +120,7 @@ case object LangCPPToCol {
private case class KernelForkBlame(kernel: CPPLambdaDefinition[_]) extends Blame[ForkFailure] {
override def blame(error: ForkFailure): Unit = error match {
case ForkNull(node) => throw KernelForkNull(node)
case RunnableNotIdle(_) => throw BlameUnreachable("This kernel submission has been forked already. This should not happen.", error) // EW TODO also turn into user error?
case RunnableNotIdle(_) => PanicBlame("This kernel submission has been forked already. This should not happen.").blame(error)
case e@RunnablePreconditionNotEstablished(_, _) => throw KernelPreconditionNotEstablished(e)
}
}
Expand Down Expand Up @@ -397,7 +381,7 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
cppNameSuccessor.get(classRef) match {
case Some(v) =>
Join(v.get)(KernelJoinBlame())
case _ => throw SYCLEventWaitWrongType(inv.applicable)
case _ => throw Unreachable("The declarator for the invocation to sycl::event::wait() is not a SYCL event.")
}
case "sycl::queue::submit" => rewriteSYCLQueueSubmit(inv)._1
case _ => rw.rewriteDefault(eval)
Expand Down Expand Up @@ -493,7 +477,8 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
val (kernelParBlock, contractRequires, contractEnsures) = rangeType match {
case SYCLTRange(_) => createBasicKernelBody(kernelDimensions, kernelDeclaration)
case SYCLTNDRange(_) => createNDRangeKernelBody(kernelDimensions, kernelDeclaration)
case _ => throw WrongKernelDimensionType(kernelDimensions)
case _ => throw Unreachable("Wrong type for the dimensions parameter of the kernel. " +
"The dimensions parameter in a kernel declaration is supposed to be of type sycl::range<int> or sycl::nd_range<int>.")
}

// Create the pre- and postconditions for the method that will hold the generated kernel code
Expand Down Expand Up @@ -550,7 +535,7 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
// Register the kernel dimensions
val range: Seq[Expr[Post]] = rw.dispatch(kernelDimensions) match {
case SYCLRange(dims) => dims
case _ => throw NotKernelDimensions(kernelDimensions)
case _ => throw Unreachable("The dimensions parameter of the kernel was not rewritten to a range.")
}

currentKernelType = Some(BasicKernel(range))
Expand Down Expand Up @@ -579,7 +564,7 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
// Register the kernel dimensions
val (globalRange, localRange): (Seq[Expr[Post]], Seq[Expr[Post]]) = rw.dispatch(kernelDimensions) match {
case SYCLNDRange(globalSize: SYCLRange[Post], localRange: SYCLRange[Post]) => (globalSize.dimensions, localRange.dimensions)
case _ => throw NotKernelDimensions(kernelDimensions)
case _ => throw Unreachable("The dimensions parameter of the kernel was not rewritten to an nd_range.")
}

currentKernelType = Some(NDRangeKernel(globalRange, localRange))
Expand Down

0 comments on commit cdc36a5

Please sign in to comment.