summaryrefslogtreecommitdiff
path: root/test/files/run/toolbox_typecheck_macrosdisabled.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-09-10 20:00:22 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-09-14 13:29:47 +0200
commit00d7cd2d5300524aeb885d8d51b2123aa0b44f6e (patch)
tree10e384ad9a6665abc606f2a1c0e1024fa11e5709 /test/files/run/toolbox_typecheck_macrosdisabled.scala
parent6d5a92b3f1c5bfb32230e5902d6dd494c9cd3a0a (diff)
downloadscala-00d7cd2d5300524aeb885d8d51b2123aa0b44f6e.tar.gz
scala-00d7cd2d5300524aeb885d8d51b2123aa0b44f6e.tar.bz2
scala-00d7cd2d5300524aeb885d8d51b2123aa0b44f6e.zip
improvements for reification of free symbols
1) Free symbols no longer carry signatures in their constructors. Previously to reify a free symbol (i.e. to generate a ValDef that creates it) one had to reify sym.info first. However reification of sym.info might lead to unexpected side effects, including stack overflows, if reification of sym.info recursively required reifying sym itself. Now it's not a problem. First we reify a "header" of a free symbol by emitting something like: val free$Foo1 = build.newFreeTerm("Foo", Foo.this, NoFlags)` Afterwards, when doing code generation for the reification symbol table, we populate free symbols by inserting calls to `build.setTypeSignature($sym.info)` This techniques transforms recursion into memoized iteration, because even if reifying sym.info indirectly requires reification of sym itself, we remember that we already reified sym and simply return things like Ident(free$Foo1). 2) Unfortunately I haven't been able to get rid of recursion completely. Since some symbols (e.g. local classes) aren't pickled, we need to recreate them during reification (this is necessary e.g. to reify RefinedTypes). Reifier uses a special function, named `reifySymDef`, for that purpose. Here's an example of how it works: val symdef$_1 = build.newNestedSymbol(free$U1, newTypeName("_"), NoPosition, DEFERRED | PARAM, false); `reifySymDef` expands into a call to `newNestedSymbol`, which requires an owner This essentially turns `reifySymDef` into a recursion of `reifySymDef` calls, so that the entire owner chain get reified. This is an implementation strategy that was employed in the first revision of the reifier written by Martin, and personally I have no clue whether it's really necessary to reify the parents. I leave this as a future work. 3) When working with free symbols, it's necessary to attach free symbols to their reification. This is required in obscure nested reification scenarios, when a symbol that was free for an inner reifee is no longer free for an outer reifee. In that case we need to remove that free symbol from the symbol table of the inner reification. Back then we didn't have tree attachments, so I had to introduce a phantom "value" parameter for `newFreeType` to keep track of the original symbols for free types. Now when we have attachments, this is no longer necessary and allowed me to clean up the code.
Diffstat (limited to 'test/files/run/toolbox_typecheck_macrosdisabled.scala')
-rw-r--r--test/files/run/toolbox_typecheck_macrosdisabled.scala3
1 files changed, 2 insertions, 1 deletions
diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.scala b/test/files/run/toolbox_typecheck_macrosdisabled.scala
index 01a418d42e..51eb63f294 100644
--- a/test/files/run/toolbox_typecheck_macrosdisabled.scala
+++ b/test/files/run/toolbox_typecheck_macrosdisabled.scala
@@ -12,7 +12,8 @@ object Test extends App {
val rupkg = cm.staticModule("scala.reflect.runtime.package")
val rusym = build.selectTerm(rupkg, "universe")
val NullaryMethodType(rutpe) = rusym.typeSignature
- val ru = build.newFreeTerm("ru", rutpe, scala.reflect.runtime.universe)
+ val ru = build.newFreeTerm("ru", scala.reflect.runtime.universe)
+ build.setTypeSignature(ru, rutpe)
val tree1 = Apply(Select(Ident(ru), newTermName("reify")), List(Literal(Constant(2))))
val ttree1 = toolbox.typeCheck(tree1, withMacrosDisabled = false)