aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #115 from retronym/backport/74v0.9.4_2.10Jason Zaugg2015-07-071-1/+11
|\ | | | | Avoid compiler warning when awaiting Future[Unit]
| * Avoid compiler warning when awaiting Future[Unit]Jason Zaugg2015-07-071-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During the ANF transform, we were generating a tree of the shape: { val temp: Unit = await(futureOfUnit) temp () } I tried to simplifiy this to avoid creating the temporary value, but this proved difficult as it would have required changes to the subsequent state machine transformation. Even replacing `temp` with `()` made the state machine transform harder. So for now, I've just inserted `temp.asInstanceOf[Unit]` to hide from the compiler warning. Fixes #74 (cherry picked from commit f3f058991b207a07041672a7e119422d9054788d)
* | [backport] Avoid masking real errors with NotImplemented awaiting ↵Jason Zaugg2015-07-061-1/+1
| | | | | | | | | | | | | | | | | | | | Future[Nothing] This commit disabled live variable analysis for intermediate values of type Nothing. Fixes #104 (cherry picked from commit 6353443a0adec384172c38efac3bc96b9d2cbad2)
* | Fix compiler crash with value class in result positionJason Zaugg2015-07-061-2/+3
|/ | | | | | | | | We were leaking untyped trees out of the macro, which crashed in refchecks. This commit proactively typechecks the tree returned by `mkZero`. (cherry picked from commit f4275e22e000541eb619808723b70bd64b9b4873)
* Make `f(await(completedFuture))` execute `f` synchronouslyJason Zaugg2014-12-162-34/+57
| | | | | | A worthy optimization, suggested by @danarmak. Closes #73
* Remove extraneous method in generated code.Jason Zaugg2014-12-151-7/+2
|
* Avoid unbounded stack consumption for synchronous control flowJason Zaugg2014-12-154-52/+50
| | | | | | | | | | | | | | | | | | Previously, as sequence of state transitions that did not pass through an asynchrous boundary incurred stack frames. The trivial loop in the enclosed test case would then overflow the stack. This commit merges the `resume` and `apply(tr: Try[Any])` methods into a `apply`. It changes the body of this method to be an infinite loop with returns at the terminal points in the state machine (or at a terminal failure.) To allow merging of these previously separate matches, states that contain an await are now allocated two state ids: one for the setup code that calls `onComplete`, and one for the code in the continuation that records the result and advances the state machine. Fixes #93
* Avoid assigning null to vars of derived value typeJason Zaugg2014-09-293-7/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `TreeGen#mkZero` returns `q"null"` for derived value classes. ``` scala> class V(val a: String) extends AnyVal defined class V scala> showRaw(gen.mkZero(typeOf[V])) res0: String = Literal(Constant(null)) ``` We use this API in async to generate the initial value for ANF-lifted temporary variables. However, this leads to NPEs, as after posterasure, we call the unbox method on a null reference: ``` % cat sandbox/Macro.scala; scalac-hash v2.10.4 sandbox/Macro.scala; scala-hash v2.10.4 -e 'val x = Macros.myMacro' import scala.reflect.macros.Context import scala.language.experimental.macros object Macros { def macroImpl(c: Context): c.Expr[C] = { import c.universe._ val e1 = c.Expr[C](Literal(Constant(null)).setType(typeOf[C])) reify(e1.splice.asInstanceOf[C @annotation.unchecked.uncheckedVariance]) } def myMacro: C = macro macroImpl } class C(val a: String) extends AnyVal java.lang.NullPointerException at Main$$anon$1.<init>(scalacmd4059893593754060829.scala:1) at Main$.main(scalacmd4059893593754060829.scala:1) at Main.main(scalacmd4059893593754060829.scala) ``` This commit installs a custom version of `mkZero` that instead returns `q"new C[$..targs](${mkZero(wrappedType)})`. Thanks to @ewiner for pinpointing the problem.
* Merge pull request #80 from retronym/ticket/79Jason Zaugg2014-07-212-4/+7
|\ | | | | Fix regression around type skolems and if exprs.
| * Fix regression around type skolems and if exprs.Jason Zaugg2014-07-182-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we start with: async({ val res = await[S[_$1 with String]](s); if (true) await[Int](0) res }) Typechecking the application (before macro expansion) yields (where the trees are printed in the form `expr{tpe}`): async[S[_$1#5738 with String#137]]({ val res: S[_$1#5490 with String] forSome { type _$1#5490 } = await[S[_$1#5487 with String]]( s{S[_$1#5487 with String]} ){S[_$1#5487 with String]}; if (true) await(0) else () res{S[_$1#5738 with String]} }{S[_$1#5738 with String]}){S[_$1#5738 with String]} Note that the type of the second last line contains a skolemized symbol `_$1#5738` of the existential `_$1#5490`. This is created by this case in `Typer#adapt`: case et @ ExistentialType(_, _) if ((mode & (EXPRmode | LHSmode)) == EXPRmode) => adapt(tree setType et.skolemizeExistential(context.owner, tree), mode, pt, original) Our ANF rewrites part of this code to: <synthetic> val await$1: S[_$1#5487 with String] = await[S[_$1#5487 with String]](awaitable$1); val res: S[_$1#5490 with String] forSome { type _$1 } = await$1; And later, the state machine transformation splits the last line into a blank field and an assignment. Typechecking the `Assign` node led to the an type error. This commit manually attributes the types to the `Assign` node so as to avoid these problem. It also reigns in an overeager rewriting of `If` nodes in the ANF transform, which was due to a bug in the label detection logic introduced in 4fc5463538. Thanks to @gnovark for yet another devilish test case and analysis of the problem with label detection. I worked on a more principled fix on: https://github.com/retronym/async/compare/ticket/79-2?expand=1 in which I try to use `repackExistential` to convert skolemized types to existentials for use as the types of synthetic vals introduced by the ANF transform. This ran into a deeper problem with existential subtyping in the compiler itself though.
* | Merge pull request #82 from retronym/topic/live-variable-speedupPhilipp Haller2014-07-181-28/+43
|\ \ | | | | | | Fix asymptotic performance issues in live variables analysis.
| * | Fix asymptotic performance issues in live variables analysis.Gene Novark2014-07-151-28/+43
| |/ | | | | | | | | | | | | | | | | Fix possibly-exponential runtime for DFS graph searches. Improve DFA fixpoint algorithm to correctly compute worklist of only changed nodes for each iteration. Added test that takes > 2 minutes to compile without these improvements.
* / Avoid NotImplementedError awaiting a Future[Nothing]Jason Zaugg2014-06-141-2/+1
|/ | | | | | | `gen.mkZero(NothingTpe)` gives the tree `Predef.???`. Instead, we should leave the `await` field uninitialized with `ValDef(..., rhs = EmptyTree)`. Fixes #66
* Incorporate pull request feedbackJason Zaugg2014-03-272-2/+2
| | | | | | | | | - remove unneeded `setType(NoType)`, which was leftover from my first attempts to find this bug. - fix typo in error message - optimize imports (cherry picked from commit 5c6ea29966fa80faae13892da50fc68ed1bf9ae7)
* [backport] Allow lazy vals without await in the initializerJason Zaugg2014-03-272-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | We were incorrectly typechecking the `ClassDef` of the state machine in the macro in a way that discarded the resulting trees, and only kept around the symbol. The led to the the macro engine retypechecking that node, which somehow led to duplicated lazy val initiaializer `DefDef`-s in the template, which manifest as a `VerifyError`. This commit: - rescues the typechecked `ClassDef` node from the eager typechecking by the macro - loosens the restriction on lazy vals in async blocks. They are still prohibited if they contain an await on the RHS - Adds a test that shows evalution is indeed lazy. (cherry picked from commit cc4587b1985519f7049d0feb0783d8e22c10f792) Conflicts: src/main/scala/scala/async/internal/AsyncAnalysis.scala src/main/scala/scala/async/internal/AsyncTransform.scala
* Unhardcode use of scala.util.TryJason Zaugg2014-01-282-5/+2
| | | | In favour of the type defined by the active FutureSystem.
* Merge pull request #56 from retronym/topic/still-todoJason Zaugg2014-01-141-1/+1
|\ | | | | Update TODO comment about pres. compiler friendliness.
| * Update TODO comment about pres. compiler friendliness.Jason Zaugg2014-01-141-1/+1
| |
* | Update copyright years.Jason Zaugg2014-01-1410-10/+10
|/ | | | 2013 must have been unlucky.
* Minor fixes in Async`s scaladoc.akomar2014-01-121-2/+2
|
* Merge pull request #47 from retronym/topic/pres2Jason Zaugg2013-11-221-6/+5
|\ | | | | Another take at the 2.10/2.11 spanning suppressMacroAttachment
| * Another take at the 2.10/2.11 spanning suppressMacroAttachmentJason Zaugg2013-11-201-6/+5
| | | | | | | | It was only working on the former.
* | Fix crashers in do/while and while(await(..))Jason Zaugg2013-11-223-3/+27
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | The new tree shapes handled for do/while look like: // type checked async({ val b = false; doWhile$1(){ await(()); if (b) doWhile$1() else () }; () }) We had to change ExprBuilder to create states for the if/else that concludes the doWhile body, and also loosen the assertion that the label jump must be the last thing we see. We also have to look for more than just `containsAwait` when deciding whether an `If` needs to be transformed into states; it might also contain a jump to the enclosing label that is on the other side of an `await`, and hence needs to be a state transition instead.
* Merge pull request #42 from retronym/topic/hooksJason Zaugg2013-11-204-12/+58
|\ | | | | Hooks for custom async implementations
| * Abstract over use of scala.util.TryJason Zaugg2013-11-134-11/+52
| | | | | | | | | | Custom implementation of the async macro may choose to use a different data type to represent `Throwable | A`.
| * Add a hook for post-ANF transformationJason Zaugg2013-11-132-1/+6
| | | | | | | | For use by custom implementations of the async macro.
* | Less hacky check for presentation compiler.Jason Zaugg2013-11-201-1/+1
| | | | | | | | "There's a method for that!"
* | Return original macro application under presentation compiler.Jason Zaugg2013-11-202-7/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, the body of an async block suffers from diminished IDE support: most notably hyperlinking doesn't work [1]. During the course of the blackbox/whitebox macro discussion, we've often talked about how the former give us the latitude to simply disable macro expansion in the IDE so we could get these features working again, at the cost of losing domain specific errors, such as "await must not be used under a nested function". But why not have our cake and eat too? This commit detects if we are running the presentation compiler and, after running our regular macro, returns the original macro application. We need to annotate that tree to prevent the typechecker from stubbornly calling our macro again. EXPERIMENTAL NOTE: This logic shouldn't live in macros: this is just a short term measure. If these experiments in async prove successful, we'll roll something similar into the macro expansion engine itself. TODO: as a performance optimization, we could just run the "unsupported await" checks, and avoid doing the more expensive state machine transformation. [1] https://www.assembla.com/spaces/scala-ide/tickets/1001449-code-navigation-fails-when-macros-are-used#/activity/ticket:
* | Fix a NPE in the presentation compilerJason Zaugg2013-11-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We were using a TypingTransformer and we called `atOwner` before we had called `transform`. This meant that `currTree` was null, which was observed when that was passed to `Context#make`. IDE ticket: https://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1001971#/activity/ticket: Stack trace: exception during macro expansion: java.lang.NullPointerException at scala.tools.nsc.interactive.ContextTrees$class.addContext(ContextTrees.scala:78) at scala.tools.nsc.interactive.Global.addContext(Global.scala:28) at scala.tools.nsc.interactive.Global.registerContext(Global.scala:268) at scala.tools.nsc.typechecker.Contexts$Context.make(Contexts.scala:295) at scala.tools.nsc.typechecker.Contexts$Context.make0(Contexts.scala:320) at scala.tools.nsc.typechecker.Contexts$Context.make(Contexts.scala:327) at scala.tools.nsc.typechecker.Typers$Typer.atOwner(Typers.scala:5662) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:33) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.async.internal.AsyncTransform$class.fixup$1(AsyncTransform.scala:191)
* | Clean-ups found during review of PR #43Philipp Haller2013-11-141-10/+2
| |
* | Fix crasher in icode due to symbol mismatches in lifted methodsJason Zaugg2013-11-141-37/+44
|/ | | | | | | | | These stem from the handling of the internal/external view or method type parameters by `thisMethodType` in `Namers`. I've now preseversed the orginal ValDefs favoured the latter when constructing the new DefDef, and made construction of all liftables consistent in this regard.
* Don't aggressively null out captured varsJason Zaugg2013-11-123-11/+54
| | | | | Once they escape, we leave the references in the state machines fields untouched.
* Remove left-overs of CPS fallback logicPhilipp Haller2013-11-072-5/+3
| | | | Completes removal performed in #37.
* Remove scala.async.StateMachineJason Zaugg2013-11-072-19/+8
| | | | | | The generated code can simply extends Function1 and Function0. This class was a hacky means to get the macro working a long time ago.
* Minimize the public APIJason Zaugg2013-11-0714-233/+73
| | | | | | | | | | - Remove the CPS fallback version of async. That was not intended to be part of 1.0. - Lookup the await method beside the macro, rather than requiring all calls to go to AsyncBase.await. - Create a minimal version of Async that just contains await/async and delegates to the macro implementation in internal._ - Add scaladoc.
* Scala 2.11 compatibilityJason Zaugg2013-11-071-1/+15
| | | | We were relying on an internal API that no longer exists.
* Add more doc commentsPhilipp Haller2013-10-221-1/+8
|
* Avoid zero-ing out dead fields of primitive value class typePhilipp Haller2013-10-222-4/+4
| | | | | - Zero out fields of type Any - Zero out fields of value class type
* Enables testing the resetting of lifted local variablesPhilipp Haller2013-10-225-8/+41
| | | | | | | - Adds a hook that lets a derived macro insert additional code when zero-ing out a lifted field. - Adds a variant of the `AsyncId` macro that logs zeroed-out fields. - Adds a test using this mechanism
* Fix looping issue when computing last usages of fieldsPhilipp Haller2013-10-222-23/+20
| | | | | - A missing condition could cause an infinite loop - Various clean-ups
* Liveness analysis to avoid memory retention issuesPhilipp Haller2013-10-224-18/+248
| | | | | | | | - Iterative, backwards data-flow analysis - Make sure fields captured by nested defs are never zeroed out. This is done elegantly by declaring such fields a being live at the exit of the final state; thus, they will never be zeroed out.
* More complete doc commentsPhilipp Haller2013-10-181-19/+33
|
* Simplify a generated CaseDef tree in resume methodPhilipp Haller2013-10-181-3/+2
| | | | | | | | | | | | | | | | | | | OLD: case (throwable @ _) if NonFatal.apply(throwable) => { { stateMachine$1.this.result.complete(Failure.apply[Nothing](throwable)); () }; () } NEW: case (throwable @ _) if NonFatal.apply(throwable) => { stateMachine$1.this.result.complete(Failure.apply[Nothing](throwable)); () }
* Minor clean-upsPhilipp Haller2013-10-182-9/+11
|
* Handle while loops as expressions in ANF transform.Jason Zaugg2013-10-141-2/+6
| | | | | | | Append a `()`, as we do for `Unit` returning `if`-s and `try-s` We don't currently support `await` in try/catch, otherwise I'd write tests for that case, too.
* Merge pull request #30 from retronym/topic/unchecked-boundsJason Zaugg2013-08-235-12/+28
|\ | | | | Use @uncheckedBounds to avoid introducing refchecks errors …
| * Use @uncheckedBounds to avoid introducing refchecks errorsJason Zaugg2013-08-225-12/+28
| | | | | | | | | | | | | | | | | | ... in code that would otherwise have smuggled through these slack LUBs in the types of trees but never in a TypeTree. More details in SI-7694. Fixes #29
* | Collection of clean-upsPhilipp Haller2013-08-145-39/+30
|/ | | | | | - removed outdated comments in ANF transform - added a few comments - removed some unnecessary imports
* Don't set the body of If to the original type.Jason Zaugg2013-08-071-3/+3
| | | | Tweak the way we set tpe = Unit in matches.
* Remove unneeded special case in ANF transform.Jason Zaugg2013-08-071-2/+0
| | | | Obsolete now that we carry all the types around.