Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move structural type reconstruction down from inferTypes into expandTables where a full tree transformation has to be done anyway. - Remove the assignTypes phase. Types are now preserved everywhere. - Some simplifications.
- Loading branch information
Showing
16 changed files
with
134 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package slick.compiler | ||
|
||
import slick.ast._ | ||
import Util._ | ||
|
||
/** Expand paths of record types to reference all fields individually and | ||
* recreate the record structure at the call site. */ | ||
class ExpandRecords extends Phase { | ||
val name = "expandRecords" | ||
|
||
def apply(state: CompilerState) = | ||
state.map(_.replace({ case n @ Path(_) => expandPath(n) }, keepType = true)) | ||
|
||
def expandPath(n: Node): Node = n.nodeType.structural match { | ||
case StructType(ch) => | ||
StructNode(ch.map { case (s, t) => | ||
(s, expandPath(n.select(s).nodeTypedOrCopy(t))) | ||
}(collection.breakOut)).nodeTyped(n.nodeType) | ||
case p: ProductType => | ||
ProductNode(p.numberedElements.map { case (s, t) => | ||
expandPath(n.select(s).nodeTypedOrCopy(t)) | ||
}.toVector).nodeTyped(n.nodeType) | ||
case t => n | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package slick.compiler | ||
|
||
import slick.ast._ | ||
import Util._ | ||
import TypeUtil._ | ||
|
||
/** Expand table-valued expressions in the result type to their star projection and compute the | ||
* missing structural expansions of table types. */ | ||
class ExpandTables extends Phase { | ||
val name = "expandTables" | ||
|
||
def apply(state: CompilerState) = state.map { n => ClientSideOp.mapServerSide(n) { tree => | ||
// Find table fields | ||
val structs = tree.collect[(TypeSymbol, (Symbol, Type))] { | ||
case s @ Select(_ :@ (n: NominalType), sym) => n.sourceNominalType.sym -> (sym -> s.nodeType) | ||
}.groupBy(_._1).mapValues(v => StructType(v.map(_._2).toMap.toIndexedSeq)) | ||
logger.debug("Found Selects for NominalTypes: "+structs.keySet.mkString(", ")) | ||
|
||
// Check for table types | ||
val tsyms: Set[TableIdentitySymbol] = | ||
tree.nodeType.collect { case NominalType(sym: TableIdentitySymbol, _) => sym }.toSet | ||
logger.debug("Tables for expansion in result type: " + tsyms.mkString(", ")) | ||
|
||
val tree2 = tree.replace({ | ||
case TableExpansion(_, t, _) => t | ||
case n => n :@ n.nodeType.replace { case NominalType(tsym, UnassignedType) => NominalType(tsym, structs(tsym)) } | ||
}, keepType = true, bottomUp = true) | ||
|
||
if(tsyms.isEmpty) tree2 else { | ||
// Find the corresponding TableExpansions | ||
val tables: Map[TableIdentitySymbol, (Symbol, Node)] = tree.collect { | ||
case TableExpansion(s, TableNode(_, _, ts, _, _), ex) if tsyms contains ts => ts -> (s, ex) | ||
}.toMap | ||
logger.debug("Table expansions: " + tables.mkString(", ")) | ||
// Create a mapping that expands the tables | ||
val sym = new AnonSymbol | ||
val mapping = createResult(tables, Ref(sym), tree2.nodeType.asCollectionType.elementType) | ||
.nodeWithComputedType(SymbolScope.empty + (sym -> tree2.nodeType.asCollectionType.elementType), typeChildren = true) | ||
Bind(sym, tree2, Pure(mapping)).nodeWithComputedType() | ||
} | ||
}} | ||
|
||
/** Create an expression that copies a structured value, expanding tables in it. */ | ||
def createResult(expansions: Map[TableIdentitySymbol, (Symbol, Node)], path: Node, tpe: Type): Node = tpe match { | ||
case p: ProductType => | ||
ProductNode(p.numberedElements.map { case (s, t) => createResult(expansions, Select(path, s), t) }.toVector) | ||
case NominalType(tsym: TableIdentitySymbol, _) if expansions contains tsym => | ||
val (sym, exp) = expansions(tsym) | ||
exp.replace { case Ref(s) if s == sym => path } | ||
case tpe: NominalType => createResult(expansions, path, tpe.structuralView) | ||
case m: MappedScalaType => | ||
TypeMapping(createResult(expansions, path, m.baseType), m.mapper, m.classTag) | ||
case OptionType(el) => | ||
val gen = new AnonSymbol | ||
OptionFold(path, LiteralNode.nullOption, OptionApply(createResult(expansions, Ref(gen), el)), gen) | ||
case _ => path | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
slick/src/main/scala/slick/compiler/FixRowNumberOrdering.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package slick.compiler | ||
|
||
import slick.ast._ | ||
import Util._ | ||
|
||
/** Inject the proper orderings into the RowNumber nodes produced earlier by | ||
* the resolveFixJoins phase. */ | ||
class FixRowNumberOrdering extends Phase { | ||
val name = "fixRowNumberOrdering" | ||
|
||
def apply(state: CompilerState) = | ||
if(state.get(Phase.resolveZipJoins).get) state.map(n => fix(n)) else state | ||
|
||
/** Push ORDER BY into RowNumbers in ordered Comprehensions. */ | ||
def fix(n: Node, parent: Option[Comprehension] = None): Node = (n, parent) match { | ||
case (r @ RowNumber(_), Some(c)) if !c.orderBy.isEmpty => | ||
RowNumber(c.orderBy).nodeTyped(r.nodeType) | ||
case (c: Comprehension, _) => c.nodeMapScopedChildren { | ||
case (Some(gen), ch) => fix(ch, None) | ||
case (None, ch) => fix(ch, Some(c)) | ||
}.nodeWithComputedType() | ||
case (n, _) => n.nodeMapChildren(ch => fix(ch, parent), keepType = true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.