Skip to content

Commit

Permalink
Merge branch 'master' of
Browse files Browse the repository at this point in the history
ssh://git@github.com/kaptoxic/scala-ide-insynth-integration.git

Conflicts:
	ch.epfl.insynth.build/README.rst
  • Loading branch information
ikuraj committed Jul 30, 2012
2 parents b257d3d + 45f46a8 commit f5afdb4
Show file tree
Hide file tree
Showing 21 changed files with 1,406 additions and 1,310 deletions.
2 changes: 1 addition & 1 deletion InSynth_CompilerPlugin/src/insynth/Config.scala
Expand Up @@ -5,7 +5,7 @@ import java.util.logging._
object Config {
// logging

val outputFilename = "/home/ivcha/git/scala-ide-insynth-integration/InSynth_CompilerPlugin/out/output.txt"
var outputFilename = "/home/ivcha/git/scala-ide-insynth-integration/InSynth_CompilerPlugin/out/output.txt"

// defines loggers
val logger = Logger.getLogger("insynth.plugin")
Expand Down
12 changes: 9 additions & 3 deletions InSynth_CompilerPlugin/src/insynth/InSynthPlugin.scala
Expand Up @@ -17,13 +17,19 @@ class InSynthPlugin(val global: Global) extends Plugin {
/** A short description of the plugin, read from the properties file */
val description = PluginProperties.pluginDescription

/** @todo A description of the plugin's options */
override val optionsHelp = Some(
" -P:"+ name +":option sets some option for this plugin")
" -appStatFile:"+ name +":option sets a filename for statistics to be written")

/** @todo Implement parsing of plugin options */
/** get file to write statistics */
override def processOptions(options: List[String], error: String => Unit) {
super.processOptions(options, error)
for (option <- options) {
if (option.startsWith("appStatFile:")) {
Config.outputFilename = option.substring("appStatFile:".length)
} else {
error("Option not recognized: " + option)
}
}
}

/** The compiler components that will be applied when running
Expand Down
2 changes: 1 addition & 1 deletion InSynth_CompilerPlugin/src/insynth/TraverseComponent.scala
Expand Up @@ -12,7 +12,7 @@ import scala.collection.mutable.MutableList
class TraverseComponent (val global: Global) extends PluginComponent {
import global._
import global.definitions._

lazy val logger = Config.logger

val runsAfter = List[String]("refchecks")
Expand Down
Expand Up @@ -73,10 +73,45 @@ class TraverseComponent(val global: Global) extends PluginComponent {
(t, level)
}
}


def getApplicationInfo(tpe: Type): Boolean = {

def isPolymorphic(tpe: Type): Boolean = tpe match {
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) if (!sym.isMonomorphicType && !args.isEmpty) =>
false
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) if (sym.isTypeParameter) =>
true
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) =>
(false /: args) { (res, arg) => res || isPolymorphic(arg) }
case _ => false
}

def getApplicationInfoMethodRec(methodType: Type): Boolean = methodType match {
case m:MethodType if (m.isHigherKinded) => true
case MethodType(params, resultType) => {
if ((false /: params) { (res, param) => res || isPolymorphic(param.tpe) } )
true
else
getApplicationInfoMethodRec(resultType)
}
case t => getApplicationInfoFunctionRec(t)
}

def getApplicationInfoFunctionRec(functionType: Type): Boolean = functionType match {
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) if(definitions.isFunctionType(functionType)) =>
if ((false /: args.init) { (res, param) => res || isPolymorphic(param) } )
true
else
getApplicationInfoFunctionRec(args.last)
case t => false
}

getApplicationInfoMethodRec(tpe)
}

def isPolymorphic(tpe: Type): Boolean = tpe match {
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) if (!sym.isMonomorphicType && !args.isEmpty) =>
true
false
case TypeRef(pre: Type, sym: Symbol, args: List[Type]) if (sym.isTypeParameter) =>
true
case _ => false
Expand Down Expand Up @@ -115,13 +150,16 @@ class TraverseComponent(val global: Global) extends PluginComponent {
// logger.fine("definitions.isFunctionType(fun.symbol.tpe) " + definitions.isFunctionType(fun.symbol.tpe))
logger.fine("App tree: " + fun + " tree position " + tree.pos)

val isPolymorphicRes = (false /: args) { (res, arg) => res || isPolymorphic(arg.tpe) }
val isPolymorphicRes = (fun.toString.contains("[") /: args) {
(res, arg) => res || arg.toString.contains("[")
}
//(false /: args) { (res, arg) => res || isPolymorphic(arg.tpe) }
logger.info("isPolymorphic =" + isPolymorphicRes)

val isCandidate = (false /: args) {
(result, arg) => result || checkIfFunctionType(arg.tpe)
}
if (isCandidate)
if (isCandidate && !isPolymorphicRes)
appendToFile(Config.outputFilename,
tree.symbol.name + "...=" + tree.pos.source.path + ":" + tree.pos.line)
}
Expand Down
2 changes: 1 addition & 1 deletion ch.epfl.insynth.build/README.rst
Expand Up @@ -26,4 +26,4 @@ InSynth user documentation

A short user documentation can be found at the project's `Wiki`_ pages.

.. _Wiki: https://github.com/kaptoxic/scala-ide-insynth-integration/wiki
.. _Wiki: https://github.com/kaptoxic/scala-ide-insynth-integration/wiki
Binary file modified ch.epfl.insynth.build/ch.epfl.insynth/.cache
Binary file not shown.
48 changes: 46 additions & 2 deletions ch.epfl.insynth.reconstruction/src/ch/epfl/insynth/Config.scala
@@ -1,14 +1,58 @@
package ch.epfl.insynth

import java.util.logging._

object Config {
final val getTimeOutSlot = 500

final val loadPredefs = true

final val numberOfSnippets = 15
final val numberOfSnippets = 1

val logCombinatorInputProofTreeLevel = 6

final val outputFileName = "/home/ivcha/development/workspace_gsoc/Insynth_core_svn/insynthOutput.txt"
final val errorFileName = "/home/ivcha/development/workspace_gsoc/Insynth_core_svn/insynthError.txt"

final val debugFileName = "/home/ivcha/development/workspace_gsoc/Insynth_core_svn/insynthDebug.txt"
final val debugFileName = "/home/ivcha/development/workspace_gsoc/Insynth_core_svn/insynthDebug.txt"

// logging for code generation phase

// defines loggers
val logger = Logger.getLogger("reconstruction.combination")
val logStructures = Logger.getLogger("reconstruction.combination.structures")
val logApply = Logger.getLogger("reconstruction.combination.apply")
val logPQAdding = Logger.getLogger("reconstruction.combination.apply.pqadding")

val logExtractor = Logger.getLogger("reconstruction.extractor")

val isLogging = true

// static code for loggers setup
{
val array = Array(logger, logStructures, logApply, logExtractor, logPQAdding)

// remove all handlers
for (logger <- array)
for (handler <- logger.getHandlers)
logger.removeHandler(handler)

Logger.getLogger("reconstruction.combination").setLevel(Level.FINE)
Logger.getLogger("reconstruction.combination.apply").setLevel(Level.FINE)
Logger.getLogger("reconstruction.combination.structures").setLevel(Level.INFO)
logPQAdding.setLevel(Level.FINEST)

logExtractor.setLevel(Level.FINEST)

val handler = new FileHandler("%h/combinator%u.log");
val handlerEx = new FileHandler("%h/extractor%u.log");
handler.setFormatter(new SimpleFormatter)
handlerEx.setFormatter(new SimpleFormatter)
// PUBLISH this level
handler.setLevel(Level.FINEST);
logger.addHandler(handler);
logExtractor.addHandler(handlerEx)
// Logger.getLogger("reconstruction.combination.apply").addHandler(handler);
// Logger.getLogger("reconstruction.combination.structures").addHandler(handler);
}
}
Expand Up @@ -7,6 +7,7 @@ import java.util.logging.Logger
import java.util.logging.ConsoleHandler
import ch.epfl.insynth.env.FormatNode
import java.util.logging.Level
import ch.epfl.insynth.Config

/**
* object which application transforms an InSynth representation input
Expand All @@ -16,6 +17,7 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {

val logger = Rules.logger
val logApply = Rules.logApply//(logger.getName + ".apply")
val logPQAdding = Config.logPQAdding

// // predefined default number of combinations
// val predefinedNeededCombinations = 15
Expand All @@ -30,7 +32,7 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
// logging
if (Rules.isLogging) {
logApply.entering(getClass.getName, "apply")
//logApply.finest("Entering combinator step (root: "+ FormatNode(root) + ", combinations: " + neededCombinations)
logApply.finest("Entering combinator step (root: "+ FormatNode(root, Config.logCombinatorInputProofTreeLevel) + ", combinations: " + neededCombinations)
}

// import transformer from InSynth to intermediate declaration
Expand Down Expand Up @@ -72,18 +74,18 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {

// if current declaration is pruned or already visited on this path, log
if (currentDeclaration.isPruned) {
logApply.fine("Declaration with " + FormatNode(currentDeclaration.getAssociatedNode, true) + " pruned")
logApply.fine("Declaration with " + FormatNode(currentDeclaration.getAssociatedNode, 0) + " pruned")
}
if (visited.contains(currentDeclaration.getAssociatedNode)) {
logApply.fine("Stumbled upon a cycle (discarding the node: " + FormatNode(currentDeclaration.getAssociatedNode, true) + ")")
logApply.fine("Stumbled upon a cycle (discarding the node: " + FormatNode(currentDeclaration.getAssociatedNode, 0) + ")")
}

// additional pruning conditions
if (currentDeclaration.getAssociatedTree.isPruned) {
logApply.fine("!Declaration with " + FormatNode(currentDeclaration.getAssociatedNode, true) + " pruned")
logApply.fine("!Declaration " + currentDeclaration + " pruned")
}
if (Rules.doPruning && currentDeclaration.getAssociatedTree.checkIfPruned(currentDeclaration.getTraversalWeight)) {
logApply.fine("!!Declaration with " + FormatNode(currentDeclaration.getAssociatedNode, true) + " pruned")
logApply.fine("!!Declaration " + currentDeclaration + " pruned")
}

if (Rules.doPruning)
Expand Down Expand Up @@ -130,8 +132,14 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {
for (dec <- node.getDecls;
// optimization - only consider those nodes that have less weight than
// all trees up to the tree
if !(Rules.doPruning && paramTree.checkIfPruned(dec.getWeight.getValue
+ paramTree.getTraversalWeight))
val notConsider = Rules.doPruning && paramTree.checkIfPruned(dec.getWeight.getValue
+ paramTree.getTraversalWeight);
// logging
val dummy =
if (Config.isLogging && notConsider) {
logPQAdding.info("Decl " + dec.getSimpleName + " is not considered")
}
if !notConsider
) // for
{

Expand All @@ -144,19 +152,25 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {

// logging
if (Rules.isLogging)
logApply.finer("Adding simple " + dec.getSimpleName + " to the queue")
logPQAdding.finer("Adding " + newPair._1 + " to the queue")
// add new pair to the queue

pq += newPair
}
// if there are parameters insert composite nodes
} else {
// for each of its declarations
for (dec <- node.getDecls
for (dec <- node.getDecls;
// optimization - only consider those nodes that have less weight than
// all trees up to the tree
if !(Rules.doPruning && paramTree.checkIfPruned(dec.getWeight.getValue
+ paramTree.getTraversalWeight))
val notConsider = Rules.doPruning && paramTree.checkIfPruned(dec.getWeight.getValue
+ paramTree.getTraversalWeight);
// logging
val dummy =
if (Config.isLogging && notConsider) {
logPQAdding.info("Decl " + dec.getSimpleName + " is not considered")
}
if !(notConsider)
) // for
{
// new pair of simple expression and extended path
Expand All @@ -168,7 +182,7 @@ object Combinator extends ((InSynth.SimpleNode, Int) => Node) {

// logging
if (Rules.isLogging)
logApply.finer("Adding composite " + dec.getSimpleName + " to the queue")
logPQAdding.finer("Adding " + newPair._1 + " to the queue")

// add new pair to the queue
pq += newPair
Expand Down

0 comments on commit f5afdb4

Please sign in to comment.