Skip to content

Commit

Permalink
Fixed InSynth core for dealing with HOFs, restructured reconstruction…
Browse files Browse the repository at this point in the history
… code and corresponding tests
  • Loading branch information
ikuraj committed Oct 1, 2013
1 parent a0ce39f commit 8edf7cf
Show file tree
Hide file tree
Showing 20 changed files with 7,825 additions and 384 deletions.
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ object ReconstructorTest {
// parameter[4]
// NOTE only one solution is expected (recursion in proof tree is terminated right away)
// f(intVal) returned rather than intVal ??
Array(buildTreeCycles, List[(Object, Object)](
//"intVal"
//,
"f(intVal)"
))
,
// Array(buildTreeCycles, List[(Object, Object)](
// //"intVal"
// //,
// "f(intVal)"
// ))
// ,
// parameter[5]
Array(buildTreeOverlapParameterTypeWithReturnType, List[(Object, Object)](
! "\\((\\S+), (\\S+)\\) => A\\.m1\\(\\)\\(\\1, \\2\\)",
Expand Down Expand Up @@ -234,6 +234,8 @@ object ReconstructorTest {
)

trees
// (List(trees(7)))
// (trees.take(7))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import ch.epfl.insynth.core.completion.InsynthCompletionProposalComputer
import ch.epfl.insynth.core.completion.InnerFinder
import ch.epfl.insynth.core.Activator
import ch.epfl.insynth.core.preferences.InSynthConstants
import ch.epfl.insynth.Config

object FeaturesTests extends TestProjectSetup("features", bundleName = "ch.epfl.insynth.tests") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import ch.epfl.insynth.core.completion.InsynthCompletionProposalComputer
import ch.epfl.insynth.core.completion.InnerFinder
import ch.epfl.insynth.core.Activator
import ch.epfl.insynth.core.preferences.InSynthConstants
import ch.epfl.insynth.Config

object IssuesTests extends TestProjectSetup("issues", bundleName = "ch.epfl.insynth.tests") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import ch.epfl.insynth.core.completion.InsynthCompletionProposalComputer
import ch.epfl.insynth.core.completion.InnerFinder
import ch.epfl.insynth.core.Activator
import ch.epfl.insynth.core.preferences.InSynthConstants
import ch.epfl.insynth.Config

class OtherIssuesTests {
// create a Scala IDE project setup
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import _root_.scala.tools.nsc.interactive.Global
import _root_.scala.reflect.internal.util.SourceFile

import ch.epfl.insynth.scala._
import ch.epfl.insynth.core._
import ch.epfl.insynth.core.preferences._
import ch.epfl.insynth.scala.loader.{ ScalaDeclaration => Declaration, _ }
import ch.epfl.insynth.reconstruction.codegen.CodeGenerator
import ch.epfl.insynth.reconstruction._
Expand Down Expand Up @@ -35,17 +37,21 @@ class InSynth(val compiler: Global, codeGenerator: CodeGenerator)
fine("builder.getAllDeclarations.size: " + builder.getAllDeclarations.size)
finer("Declarations: \n" + builder.getAllDeclarations.sortWith( (d1, d2) => d1.getSimpleName.compareTo(d2.getSimpleName) < 0 ).map( decl => decl +
"[" + decl.getDomainType + " : " + decl.inSynthType + " : " + decl.getWeight + "]" ).mkString("\n"))


// get maximum duration of the combination step
val maximumTime = Activator.getDefault.getPreferenceStore.getInt(
InSynthConstants.MaximumTimePropertyString)

val queryBuilder = new QueryBuilder(desiredType)
val engine = new Engine(builder, queryBuilder.getQuery, new WeightScheduler(), TimeOut(Config.getTimeOutSlot))
val engine = new Engine(builder, queryBuilder.getQuery, new WeightScheduler(), TimeOut(maximumTime))

val time = System.currentTimeMillis

val solution = engine.run()

if (solution != null) {
info("Solution found in " + (System.currentTimeMillis - time) + " ms.")
info("Solution found: " + TreePrinter(solution, Config.proofTreeLevelToLog))
info("Solution found: " + TreePrinter(solution, proofTreeLevelToLog))
//TreePrinter.printAnswerAsXML(Config.proofTreeOutput, solution, Config.proofTreeLevelToLog)
} else
info("No solution found in " + (System.currentTimeMillis - time) + " ms")
Expand All @@ -70,4 +76,6 @@ class InSynth(val compiler: Global, codeGenerator: CodeGenerator)
val typed = response.get
typed.fold(identity, throw _)
}

val proofTreeLevelToLog = 6
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import org.eclipse.jface.text.contentassist.{ ICompletionProposal, IContextInfor

import scala.tools.eclipse.javaelements.ScalaCompilationUnit
import scala.tools.nsc.interactive.Global
import scala.tools.eclipse.logging.HasLogger

import insynth.engine.InitialEnvironmentBuilder
import insynth.load.Declaration
import insynth.util.logging.HasLogger

import ch.epfl.insynth.Config
import ch.epfl.insynth.core.preferences.InSynthConstants
import ch.epfl.insynth.InSynth
import ch.epfl.insynth.reconstruction._
Expand All @@ -43,8 +42,7 @@ object InnerFinder extends ((ScalaCompilationUnit, Int) => Option[List[Output]])
scu.withSourceFile {
(sourceFile, compiler) =>

Config.inSynthLogger.info("InSynth working on source file: " + sourceFile.path)
logger.info("InSynth working on source file: " + sourceFile.path)
info("InSynth working on source file: " + sourceFile.path)

val codegen = getSourceCodeGenerator

Expand Down Expand Up @@ -79,7 +77,7 @@ object InnerFinder extends ((ScalaCompilationUnit, Int) => Option[List[Output]])
}
} catch {
case ex: Throwable =>
logger.error("InSynth synthesis failed.", ex)
error("InSynth synthesis failed." + ex)
None
} finally {
predefBuildLoader.start()
Expand Down Expand Up @@ -175,11 +173,11 @@ class InsynthCompletionProposalComputer extends IJavaCompletionProposalComputer

object InSynthWrapper {

var insynth:InSynth = null;
var compiler:Global = null;
var insynth:InSynth = null
var compiler:Global = null

var builder:InitialEnvironmentBuilder = null;
var predefDecls:List[Declaration] = null;
var builder:InitialEnvironmentBuilder = null
var predefDecls:List[Declaration] = Nil

final val loadPredefs = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package ch.epfl.insynth.core.preferences

// InSynth
import ch.epfl.insynth.core.Activator
import ch.epfl.insynth.Config

// java logging
import java.util.logging.Handler
import java.util.logging.FileHandler
import java.util.logging.Level
import java.util.logging.SimpleFormatter
import java.util.logging._

// eclipse
import org.eclipse.jface.util.PropertyChangeEvent

// Scala IDE
import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.util.SWTUtils
Expand Down Expand Up @@ -73,13 +72,13 @@ object LogManager extends HasLogger {
def setLogging(enable: Boolean) =
if (enable) {
// set logger handler
Config.setLoggerHandler(inSynthHandler);
// Config.setLoggerHandler(inSynthHandler);
// log to Scala IDE log
eclipseLog.info("InSynth library logger enabled.");
}
else {
// remove logger handler
Config.removeLoggerHandler(inSynthHandler);
// Config.removeLoggerHandler(inSynthHandler);
// log to Scala IDE log
eclipseLog.info("InSynth library logger disabled.");
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package ch.epfl.insynth.reconstruction

import insynth.reconstruction.stream._
import insynth.streams._
import insynth.streams.ordered._

import insynth.util.logging.HasLogger

class OrderedStreamFactory extends StreamFactory[Node] with HasLogger {

override def makeEmptyStreamable = Empty

override def makeSingleton[U <: Node](element: U) = Singleton(element)

override def makeSingletonList[U <: Node](element: List[U]) = Singleton(element)

// override def makeSingleStream[U <: T](stream: => Stream[U], isInfiniteFlag: Boolean) =
// SingleStream(stream, isInfiniteFlag)

override def makeUnaryStream[X, Y <: Node](streamable: Streamable[X], modify: X => Y, modifyVal: Option[Int => Int] = None) =
UnaryStream(streamable.asInstanceOf[OrderedStreamable[X]], modify, modifyVal)

override def makeUnaryStreamList[X, Y <: Node](streamable: Streamable[X], modify: X => List[Y]) =
UnaryStream(streamable.asInstanceOf[OrderedStreamable[X]], modify)

override def makeBinaryStream[X, Y, Z <: Node](s1: Streamable[X], s2: Streamable[Y])(combine: (X, Y) => List[Z]) =
BinaryStream(s1.asInstanceOf[OrderedStreamable[X]], s2.asInstanceOf[OrderedStreamable[Y]])(combine)

override def makeRoundRobbin[U <: Node](streams: Seq[Streamable[U]]) =
RoundRobbin(streams.asInstanceOf[Seq[OrderedStreamable[Node]]])

override def makeLazyRoundRobbin[U <: Node](initStreams: List[Streamable[U]]) =
LazyRoundRobbin[Node](initStreams.asInstanceOf[List[OrderedStreamable[Node]]])

def getFinalStream(streamable: Streamable[Node]) =
streamable match {
case os: OrderedStreamable[_] =>
fine("returning ordered streamable")
os.getStream zip os.getValues.map(_.toFloat)
case _: Streamable[_] =>
fine("returning unordered streamable")
streamable.getStream zip Stream.continually(0f)
}
}
//package ch.epfl.insynth.reconstruction
//
//import insynth.reconstruction.stream._
//import insynth.streams._
//import insynth.streams.ordered._
//
//import insynth.util.logging.HasLogger
//
//class OrderedStreamFactory extends StreamFactory[Node] with HasLogger {
//
// override def makeEmptyStreamable = Empty
//
// override def makeSingleton[U <: Node](element: U) = Singleton(element)
//
// override def makeSingletonList[U <: Node](element: List[U]) = Singleton(element)
//
//// override def makeSingleStream[U <: T](stream: => Stream[U], isInfiniteFlag: Boolean) =
//// SingleStream(stream, isInfiniteFlag)
//
// override def makeUnaryStream[X, Y <: Node](streamable: Streamable[X], modify: X => Y, modifyVal: Option[Int => Int] = None) =
// UnaryStream(streamable.asInstanceOf[OrderedStreamable[X]], modify, modifyVal)
//
// override def makeUnaryStreamList[X, Y <: Node](streamable: Streamable[X], modify: X => List[Y]) =
// UnaryStream(streamable.asInstanceOf[OrderedStreamable[X]], modify)
//
// override def makeBinaryStream[X, Y, Z <: Node](s1: Streamable[X], s2: Streamable[Y])(combine: (X, Y) => List[Z]) =
// BinaryStream(s1.asInstanceOf[OrderedStreamable[X]], s2.asInstanceOf[OrderedStreamable[Y]])(combine)
//
// override def makeRoundRobbin[U <: Node](streams: Seq[Streamable[U]]) =
// RoundRobbin(streams.asInstanceOf[Seq[OrderedStreamable[Node]]])
//
// override def makeLazyRoundRobbin[U <: Node](initStreams: List[Streamable[U]]) =
// LazyRoundRobbin[Node](initStreams.asInstanceOf[List[OrderedStreamable[Node]]])
//
// def getFinalStream(streamable: Streamable[Node]) =
// streamable match {
// case os: OrderedStreamable[_] =>
// fine("returning ordered streamable")
// os.getStream zip os.getValues.map(_.toFloat)
// case _: Streamable[_] =>
// fine("returning unordered streamable")
// streamable.getStream zip Stream.continually(0f)
// }
//}
Loading

0 comments on commit 8edf7cf

Please sign in to comment.