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

Focus/minimization functionality #1285

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/col/vct/col/ast/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ final class Function[G](
val contract: ApplicableContract[G],
val inline: Boolean = false,
val threadLocal: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[ContractedFailure])(implicit val o: Origin)
extends GlobalDeclaration[G] with AbstractFunction[G] with FunctionImpl[G]
@scopes[LabelDecl]
Expand All @@ -709,6 +710,7 @@ final class Procedure[G](
val inline: Boolean = false,
val pure: Boolean = false,
val vesuv_entry: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[CallableFailure])(implicit val o: Origin)
extends GlobalDeclaration[G] with AbstractMethod[G] with ProcedureImpl[G]
@scopes[LabelDecl]
Expand All @@ -723,6 +725,7 @@ final class Predicate[G](
val body: Option[Expr[G]],
val threadLocal: Boolean = false,
val inline: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(implicit val o: Origin)
extends GlobalDeclaration[G] with AbstractPredicate[G] with PredicateImpl[G]
final class Enum[G](val constants: Seq[EnumConstant[G]])(implicit val o: Origin)
Expand Down Expand Up @@ -760,6 +763,7 @@ final class InstanceFunction[G](
val contract: ApplicableContract[G],
val inline: Boolean,
val threadLocal: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[ContractedFailure])(implicit val o: Origin)
extends ClassDeclaration[G]
with AbstractFunction[G]
Expand All @@ -773,6 +777,7 @@ final class Constructor[G](
val body: Option[Statement[G]],
val contract: ApplicableContract[G],
val inline: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[CallableFailure])(implicit val o: Origin)
extends ClassDeclaration[G] with AbstractMethod[G] with ConstructorImpl[G]
@scopes[LabelDecl]
Expand All @@ -785,6 +790,7 @@ final class InstanceMethod[G](
val contract: ApplicableContract[G],
val inline: Boolean = false,
val pure: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[CallableFailure])(implicit val o: Origin)
extends ClassDeclaration[G]
with AbstractMethod[G]
Expand All @@ -796,6 +802,7 @@ final class InstancePredicate[G](
val body: Option[Expr[G]],
val threadLocal: Boolean = false,
val inline: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(implicit val o: Origin)
extends ClassDeclaration[G]
with AbstractPredicate[G]
Expand All @@ -817,6 +824,7 @@ final class InstanceOperatorFunction[G](
val contract: ApplicableContract[G],
val inline: Boolean,
val threadLocal: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[ContractedFailure])(implicit val o: Origin)
extends ClassDeclaration[G]
with AbstractFunction[G]
Expand All @@ -829,6 +837,7 @@ final class InstanceOperatorMethod[G](
val contract: ApplicableContract[G],
val inline: Boolean = false,
val pure: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[CallableFailure])(implicit val o: Origin)
extends ClassDeclaration[G]
with AbstractMethod[G]
Expand Down Expand Up @@ -898,8 +907,10 @@ final class ParInvariantDecl[G]()(implicit val o: Origin)
extends Declaration[G] with ParInvariantDeclImpl[G]

sealed trait Applicable[G] extends ApplicableImpl[G] with Declaration[G]
sealed trait FilterApplicable[G]
extends Applicable[G] with FilterApplicableImpl[G]
sealed trait InlineableApplicable[G]
extends Applicable[G] with InlineableApplicableImpl[G]
extends FilterApplicable[G] with InlineableApplicableImpl[G]
sealed trait AbstractPredicate[G]
extends InlineableApplicable[G] with AbstractPredicateImpl[G]
sealed trait ContractApplicable[G]
Expand All @@ -910,6 +921,16 @@ sealed trait AbstractMethod[G]
extends ContractApplicable[G] with AbstractMethodImpl[G]
sealed trait Field[G] extends FieldImpl[G]

@family
sealed trait FilterMode[G] extends NodeFamily[G] with FilterModeImpl[G]
case class Include[G]()(implicit val o: Origin = DiagnosticOrigin)
extends FilterMode[G] with IncludeImpl[G]
case class Exclude[G]()(implicit val o: Origin = DiagnosticOrigin)
extends FilterMode[G] with ExcludeImpl[G]
// Slightly longer name here to avoid claiming the keyword "Neutral", just Option[FilterMode] can be avoided.
case class NeutralFilterMode[G]()(implicit val o: Origin = DiagnosticOrigin)
extends FilterMode[G] with NeutralFilterModeImpl[G]

@family @scopes[Variable]
@scopes[LocalHeapVariable]
final case class SignalsClause[G](binding: Variable[G], assn: Expr[G])(
Expand Down Expand Up @@ -3534,6 +3555,7 @@ final class LLVMSpecFunction[G](
val contract: ApplicableContract[G],
val inline: Boolean = false,
val threadLocal: Boolean = false,
val filter: FilterMode[G] = NeutralFilterMode[G](),
)(val blame: Blame[ContractedFailure])(implicit val o: Origin)
extends LLVMCallable[G]
with AbstractFunction[G]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package vct.col.ast.declaration.category

import vct.col.ast.{AbstractPredicate, TResource, Type}
import vct.col.ast.{AbstractPredicate, Expr, TResource, Type}

trait AbstractPredicateImpl[G] extends InlineableApplicableImpl[G] {
this: AbstractPredicate[G] =>
def body: Option[Expr[G]]
def threadLocal: Boolean
override def returnType: Type[G] = TResource()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package vct.col.ast.declaration.category

import vct.col.ast.{FilterApplicable, FilterMode}

trait FilterApplicableImpl[G] extends ApplicableImpl[G] {
this: FilterApplicable[G] =>
def filter: FilterMode[G]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package vct.col.ast.declaration.category

import vct.col.ast.InlineableApplicable

trait InlineableApplicableImpl[G] extends ApplicableImpl[G] {
trait InlineableApplicableImpl[G] extends FilterApplicableImpl[G] {
this: InlineableApplicable[G] =>
def inline: Boolean
}
5 changes: 4 additions & 1 deletion src/col/vct/col/ast/unsorted/AmbiguousFoldTargetImpl.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package vct.col.ast.unsorted

import vct.col.ast.AmbiguousFoldTarget
import vct.col.ast.{AmbiguousFoldTarget, ApplyAnyPredicate}
import vct.col.ast.ops.AmbiguousFoldTargetOps
import vct.col.print._

trait AmbiguousFoldTargetImpl[G] extends AmbiguousFoldTargetOps[G] {
this: AmbiguousFoldTarget[G] =>
override def layout(implicit ctx: Ctx): Doc = target.show

// Not supported, until someone implements it
def apply: ApplyAnyPredicate[G] = ???
}
10 changes: 10 additions & 0 deletions src/col/vct/col/ast/unsorted/ExcludeImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package vct.col.ast.unsorted

import vct.col.ast.{Exclude, FilterMode, Include}
import vct.col.ast.ops.ExcludeOps
import vct.col.print._

trait ExcludeImpl[G] extends ExcludeOps[G] {
this: Exclude[G] =>
// override def layout(implicit ctx: Ctx): Doc = ???
}
10 changes: 10 additions & 0 deletions src/col/vct/col/ast/unsorted/FilterModeImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package vct.col.ast.unsorted

import vct.col.ast.FilterMode
import vct.col.ast.ops.FilterModeFamilyOps
import vct.col.print._

trait FilterModeImpl[G] extends FilterModeFamilyOps[G] {
this: FilterMode[G] =>
// override def layout(implicit ctx: Ctx): Doc = ???
}
3 changes: 2 additions & 1 deletion src/col/vct/col/ast/unsorted/FoldTargetImpl.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package vct.col.ast.unsorted

import vct.col.ast.FoldTarget
import vct.col.ast.{AbstractPredicate, ApplyAnyPredicate, FoldTarget}
import vct.col.ast.node.NodeFamilyImpl
import vct.col.ast.ops.FoldTargetFamilyOps
import vct.col.print._

trait FoldTargetImpl[G] extends NodeFamilyImpl[G] with FoldTargetFamilyOps[G] {
this: FoldTarget[G] =>

def apply: ApplyAnyPredicate[G]
}
10 changes: 10 additions & 0 deletions src/col/vct/col/ast/unsorted/IncludeImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package vct.col.ast.unsorted

import vct.col.ast.{Exclude, FilterMode, Include}
import vct.col.ast.ops.IncludeOps
import vct.col.print._

trait IncludeImpl[G] extends IncludeOps[G] {
this: Include[G] =>
// override def layout(implicit ctx: Ctx): Doc = ???
}
10 changes: 10 additions & 0 deletions src/col/vct/col/ast/unsorted/NeutralFilterModeImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package vct.col.ast.unsorted

import vct.col.ast.NeutralFilterMode
import vct.col.ast.ops.NeutralFilterModeOps
import vct.col.print._

trait NeutralFilterModeImpl[G] extends NeutralFilterModeOps[G] {
this: NeutralFilterMode[G] =>
// override def layout(implicit ctx: Ctx): Doc = ???
}
2 changes: 2 additions & 0 deletions src/col/vct/col/typerules/CoercingRewriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ abstract class CoercingRewriter[Pre <: Generation]()
case node: ApplyAnyPredicate[Pre] => coerce(node)
case node: FoldTarget[Pre] => coerce(node)
case node: LLVMFloatType[Pre] => node
case node: FilterMode[Pre] => coerce(node)
}

def preCoerce(decl: Declaration[Pre]): Declaration[Pre] = decl
Expand Down Expand Up @@ -2973,4 +2974,5 @@ abstract class CoercingRewriter[Pre <: Generation]()
def coerce(node: PVLEndpointName[Pre]): PVLEndpointName[Pre] = node
def coerce(node: EndpointName[Pre]): EndpointName[Pre] = node

def coerce(node: FilterMode[Pre]): FilterMode[Pre] = node
}
4 changes: 4 additions & 0 deletions src/col/vct/col/util/AstBuildHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,23 @@ object AstBuildHelpers {
def rewrite(
args: => Seq[Variable[Post]] = rewriter.variables
.dispatch(predicate.args),
body: => Option[Expr[Post]] = predicate.body
.map((e: Expr[Pre]) => rewriter.dispatch(e)),
inline: => Boolean = predicate.inline,
threadLocal: => Boolean = predicate.threadLocal,
): AbstractPredicate[Post] =
predicate match {
case predicate: Predicate[Pre] =>
predicate.rewrite(
args = args,
body = body,
inline = Some(inline),
threadLocal = Some(threadLocal),
)
case predicate: InstancePredicate[Pre] =>
predicate.rewrite(
args = args,
body = body,
inline = Some(inline),
threadLocal = Some(threadLocal),
)
Expand Down
Loading
Loading