From 03f00fe232c35189682341e39fac487ed2a70a8c Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 28 Dec 2011 19:06:49 +0100 Subject: [vpm] __match determines match semantics; virtualization determine match strategy by typing `__match` factored out the interface to generate code in this monad, cleaned up codegen a bit no longer solving a context bound to determine the match strategy and the monad's type constructor it's too expensive don't consider implicits looking for __match implicit search causes HUGE slowdowns -- now the overhead is about 4% compared to just assuming there's no __match in scope to support virtualization&staging, we use the type of `__match.one` as the prototype for how to wrap "pure" types and types "in the monad" pure types T are wrapped as P[T], and T goes into the monad as M[T], if one is defined as: def one[T](x: P[T]): M[T] for staging, P will typically be the Rep type constructor, and type M[T] = Rep[Option[T]] furthermore, naive codegen no longer supplies type information -- type inference will have to work it out optimized codegen still does, of course, and that's enough since we only bootstrap that way TODO: improve the test (currently the condition is not represented) --- src/library/scala/MatchingStrategy.scala | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/library/scala/MatchingStrategy.scala (limited to 'src/library') diff --git a/src/library/scala/MatchingStrategy.scala b/src/library/scala/MatchingStrategy.scala deleted file mode 100644 index d11598bad6..0000000000 --- a/src/library/scala/MatchingStrategy.scala +++ /dev/null @@ -1,27 +0,0 @@ -package scala - -abstract class MatchingStrategy[M[+x]] { - // runs the matcher on the given input - def runOrElse[T, U](in: T)(matcher: T => M[U]): U - - def zero: M[Nothing] - def one[T](x: T): M[T] - def guard[T](cond: Boolean, then: => T): M[T] - def isSuccess[T, U](x: T)(f: T => M[U]): Boolean // used for isDefinedAt - - def caseResult[T](x: T): M[T] = one(x) // used as a marker to distinguish the RHS of a case (case pat => RHS) and intermediate successes - // when deriving a partial function from a pattern match, - // we need to distinguish the RHS of a case, which should not be evaluated when computing isDefinedAt, - // from an intermediate result (which must be computed) -} - -object MatchingStrategy { - implicit object OptionMatchingStrategy extends MatchingStrategy[Option] { - type M[+x] = Option[x] - @inline def runOrElse[T, U](x: T)(f: T => M[U]): U = f(x) getOrElse (throw new MatchError(x)) - @inline def zero: M[Nothing] = None - @inline def one[T](x: T): M[T] = Some(x) - @inline def guard[T](cond: Boolean, then: => T): M[T] = if(cond) Some(then) else None - @inline def isSuccess[T, U](x: T)(f: T => M[U]): Boolean = !f(x).isEmpty - } -} \ No newline at end of file -- cgit v1.2.3