Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
New SIP: Implicit Source Locations
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  18 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Philipp Haller  
View profile  
 More options Mar 30 2012, 5:18 am
From: Philipp Haller <philipp.hal...@epfl.ch>
Date: Fri, 30 Mar 2012 09:18:36 +0000
Local: Fri, Mar 30 2012 5:18 am
Subject: [SIP 19] New SIP: Implicit Source Locations

Hi all,

Here is a new SIP which describes Implicit Source Locations [1], a feature that has been in Scala-Virtualized for a while (with extensions), and which has been used in frameworks and DSLs built on top of it, such as Delite and OptiML [2].

It is now a SIP so that it can be discussed and voted on formally for inclusion in Scala 2.10.

Cheers,
Philipp

[1] http://docs.scala-lang.org/sips/pending/source-locations.html
[2] http://stanford-ppl.github.com/Delite/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Mar 30 2012, 5:22 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Fri, 30 Mar 2012 11:22:57 +0200
Local: Fri, Mar 30 2012 5:22 am
Subject: Re: [SIP 19] New SIP: Implicit Source Locations

Why not expose a Position, which can also be a range position?

On 30 Mar 2012, at 11:18, Philipp Haller <philipp.hal...@epfl.ch> wrote:

 Hi all,

 Here is a new SIP which describes Implicit Source Locations [1], a feature
that has been in Scala-Virtualized for a while (with extensions), and which
has been used in frameworks and DSLs built on top of it, such as Delite and
OptiML [2].

 It is now a SIP so that it can be discussed and voted on formally for
inclusion in Scala 2.10.

 Cheers,
Philipp

 [1] http://docs.scala-lang.org/sips/pending/source-locations.html
[2] http://stanford-ppl.github.com/Delite/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Mar 30 2012, 5:43 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Fri, 30 Mar 2012 11:43:03 +0200
Local: Fri, Mar 30 2012 5:43 am
Subject: Re: [SIP 19] New SIP: Implicit Source Locations

Another suggestion would be writing an auxiliary macro, which gives you
access to the position and does not require changing the original method at
all.

Example:

def foo(implicit pos: SourcePosition) = {
  val bar = f(pos)
  baz

}

Would become:

def foo = macro impl

def impl(c: Context) = {
  reify { foo(c.pos.eval) }

}

def foo(pos: SourcePosition) = <original definition of foo>

Benefit of this approach is reducing magic and unifying metaprogramming
facilities under macros infrastructure.

Also, could you please elaborate on the differences between SourceContext
and SourceInfo, so that we can discuss them w.r.t macros.

On 30 March 2012 11:18, Philipp Haller <philipp.hal...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Mar 30 2012, 6:02 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Fri, 30 Mar 2012 12:02:40 +0200
Local: Fri, Mar 30 2012 6:02 am
Subject: Re: [SIP 19] New SIP: Implicit Source Locations

Okay, the boilerplate can be reduced to just one method:

@inline final def foo = withPosition(foo)

def foo(pos: Position) = <original definition of foo>

Where withPosition is a macro that goes from T to T and injects the
position into the invocation it wraps.

On 30 March 2012 11:43, Eugene Burmako <eugene.burm...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miles Sabin  
View profile  
 More options Mar 30 2012, 7:10 am
From: Miles Sabin <mi...@milessabin.com>
Date: Fri, 30 Mar 2012 12:10:47 +0100
Local: Fri, Mar 30 2012 7:10 am
Subject: Re: [SIP 19] New SIP: Implicit Source Locations

On Fri, Mar 30, 2012 at 11:02 AM, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
> Okay, the boilerplate can be reduced to just one method:

> @inline final def foo = withPosition(foo)

> def foo(pos: Position) = <original definition of foo>

> Where withPosition is a macro that goes from T to T and injects the position
> into the invocation it wraps.

Maybe I'm missing something, but isn't there only one invocation of
foo(pos: Position) being wrapped, namely the one in,

  @inline final def foo = withPosition(foo)
                                       ^^^

So wouldn't we only ever see that one source position?

That said, I'm very much in favour or trying to unify these mechanisms
if it's at all possible.

Cheers,

Miles

--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://underscoreconsulting.com
http://www.chuusai.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Mar 30 2012, 7:40 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Fri, 30 Mar 2012 13:40:14 +0200
Local: Fri, Mar 30 2012 7:40 am
Subject: Re: [SIP 19] New SIP: Implicit Source Locations

Yeah, true, my bad.

However, we've come up with an implicit macro idea that seems to be
working. We'll post the update when we're sure.

On 30 March 2012 13:10, Miles Sabin <mi...@milessabin.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Apr 1 2012, 1:14 pm
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Sun, 1 Apr 2012 10:14:47 -0700 (PDT)
Local: Sun, Apr 1 2012 1:14 pm
Subject: Re: New SIP: Implicit Source Locations
Okay, here we go:
[1] Location-generating macro:
https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...
[2] Location-aware function:
https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...

Good news:
+ It's totally possible to implement SIP-19 without any changes to the
compiler.

Bad news:
- Chaining of source locations becomes ugly (see [2] for the example),
because implicit parameter of type SourceLocation and implicit macro
of type => SourceLocation conflict. Any ideas how to fix that?

On Mar 30, 1:10 pm, Miles Sabin <mi...@milessabin.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Zaugg  
View profile  
 More options Apr 1 2012, 2:29 pm
From: Jason Zaugg <jza...@gmail.com>
Date: Sun, 1 Apr 2012 20:29:36 +0200
Local: Sun, Apr 1 2012 2:29 pm
Subject: Re: New SIP: Implicit Source Locations

On Sun, Apr 1, 2012 at 7:14 PM, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
> Okay, here we go:
> [1] Location-generating macro:
> https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...
> [2] Location-aware function:
> https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...

> Good news:
> + It's totally possible to implement SIP-19 without any changes to the
> compiler.

> Bad news:
> - Chaining of source locations becomes ugly (see [2] for the example),
> because implicit parameter of type SourceLocation and implicit macro
> of type => SourceLocation conflict. Any ideas how to fix that?

I would love a means to issue a casting vote in case of implicit
ambiguity. Scalaz has a ton of boilerplate (example [1]) that would
melt away with something more refined than LowPriorityImplicits.

This would work for me, although I understand that using annotations
to influence type checking isn't to everyone's taste.

  @weight(+1) implicit def sourceLocation = ...

-jason

[1] https://github.com/scalaz/scalaz/blob/scalaz-seven/core/src/main/scal...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Apr 1 2012, 5:09 pm
From: martin odersky <martin.oder...@epfl.ch>
Date: Sun, 1 Apr 2012 23:09:48 +0200
Local: Sun, Apr 1 2012 5:09 pm
Subject: Re: New SIP: Implicit Source Locations

On Sun, Apr 1, 2012 at 7:14 PM, Eugene Burmako <eugene.burm...@epfl.ch>wrote:

Cheers

 - Martin

--
Martin Odersky
Prof., EPFL <http://www.epfl.ch> and Chairman, Typesafe<http://www.typesafe.com>
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Apr 1 2012, 5:47 pm
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Sun, 1 Apr 2012 23:47:05 +0200
Local: Sun, Apr 1 2012 5:47 pm
Subject: Re: New SIP: Implicit Source Locations

Good question.

Here's what the SIP says: "First, if there is already an implicit argument
of type SourceLocation, this argument is selected. Otherwise, an instance
of SourceLocation is generated by invoking the apply method of the object
scala.reflect.SourceLocation, passing the components of the source location
as arguments".

If you follow the specification to the letter, it says that fresh
SourceLocations must be generated every time when the implicit argument is
not provided explicitly. That is, even if there's a compatible implicit in
scope. Let's ask Philipp (/cc'd) for clarifications.

On 1 April 2012 23:09, martin odersky <martin.oder...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Philipp Haller  
View profile  
 More options Apr 1 2012, 9:36 pm
From: Philipp Haller <philipp.hal...@epfl.ch>
Date: Mon, 2 Apr 2012 01:36:29 +0000
Local: Sun, Apr 1 2012 9:36 pm
Subject: Re: New SIP: Implicit Source Locations

On Apr 1, 2012, at 11:09 PM, martin odersky wrote:

On Sun, Apr 1, 2012 at 7:14 PM, Eugene Burmako <eugene.burm...@epfl.ch<mailto:eugene.burm...@epfl.ch>> wrote:
Okay, here we go:
[1] Location-generating macro:
https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...
[2] Location-aware function:
https://github.com/scalamacros/kepler/blob/0cabc96861c4d7b0e9dcdb8ea1...

Good news:
+ It's totally possible to implement SIP-19 without any changes to the
compiler.

Bad news:
- Chaining of source locations becomes ugly (see [2] for the example),
because implicit parameter of type SourceLocation and implicit macro
of type => SourceLocation conflict. Any ideas how to fix that?

But as far as I can see SIP 19 does not specify chaining?

That's true, it doesn't specify chaining. So far, chaining is only implemented in Virtualized Scala.

I think what Eugene wanted to point out is that it's a bit cumbersome to get access to the implicit SourceLocation parameter of a method, and at the same time create a new SourceLocation for the next callee (preventing the existing implicit value to simply be passed as an argument also to the callee).

To do that we need to save the implicit parameter, and subsequently shadow it, so that the implicit macro is invoked again. If we do that then we could implement chaining explicitly, which is of course not as nice as in Virtualized Scala. So, I think we still need to clarify whether SIP 19 should specify chaining.

Cheers,
Philipp

On Mar 30, 1:10 pm, Miles Sabin <mi...@milessabin.com<mailto:mi...@milessabin.com>> wrote:

--
Martin Odersky
Prof., EPFL<http://www.epfl.ch/> and Chairman, Typesafe<http://www.typesafe.com/>
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Apr 2 2012, 4:20 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Mon, 2 Apr 2012 01:20:58 -0700 (PDT)
Local: Mon, Apr 2 2012 4:20 am
Subject: Re: New SIP: Implicit Source Locations
Allrighty, with a help of a little hack (not on the compiler side!)
implicit location macro now has bigger priority than implicit location
values in scope. I'm not very into implicit prioritization rules, so
maybe there exists a more elegant way to solve the ambiguity problem.

This not only gets rid of all the ugliness, but also enables
transparent chaining as shown in [1]. Updated macro is here: [2].

[1] https://github.com/scalamacros/kepler/blob/e388ddc559549573e3b3357f61...
[2]
https://github.com/scalamacros/kepler/blob/e388ddc559549573e3b3357f61...

On Apr 2, 3:36 am, Philipp Haller <philipp.hal...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Heather Miller  
View profile  
 More options Apr 2 2012, 10:28 am
From: Heather Miller <heather.mil...@epfl.ch>
Date: Mon, 2 Apr 2012 16:28:28 +0200
Local: Mon, Apr 2 2012 10:28 am
Subject: Re: New SIP: Implicit Source Locations

So, while I understand the motivation at the moment to demonstrate that as many compiler-changes as possible can be expressed with macros, I'm not so sure it makes sense to replace the current implementation of SourceLocations outright with macros.

This is mostly due to the pragmas proposed in SIP-18…

Assuming (a) the proposed language imports would come to be, and (b) these implicit macro defs designed to implement SIP-19 also come to be, then wouldn't that mean that DSL authors would have to import macros in order to use SourceLocations?

Bottom-line: it's probably best if DSL authors, didn't have to know that macros even exist.  

--  
Heather Miller
Doctoral Assistant
EPFL, IC, LAMP
http://people.epfl.ch/heather.miller


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Apr 2 2012, 10:43 am
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Mon, 2 Apr 2012 16:43:57 +0200
Local: Mon, Apr 2 2012 10:43 am
Subject: Re: New SIP: Implicit Source Locations

SIP-18 restricts macro definitions, not macro usages, so SourceLocation
macros will still work without a flag.

On 2 April 2012 16:28, Heather Miller <heather.mil...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Heather Miller  
View profile  
 More options Apr 2 2012, 11:38 am
From: Heather Miller <heather.mil...@epfl.ch>
Date: Mon, 2 Apr 2012 17:38:28 +0200
Local: Mon, Apr 2 2012 11:38 am
Subject: Re: New SIP: Implicit Source Locations

In my previous email, I was talking about the language import statements, I didn't mention compiler flags. The email was about how this new proposition looked to a user. It's not clear how one should use it, or where it should go. A clearer answer would've been that it could go in the SourceLocation object (whose source would of course import macros as proposed in SIP-18), which could be imported (normally) by the user. Is that what you intend to do with it?

====
The rest isn't written to Eugene, but to the SIP committee in general...

It's not really clear from the chain of emails where or really in depth *how* SourceLocations would be implemented (yes, there's a sketch linked to, but it's preliminary and it's not clear where it'd go in the library) and thus how they'd appear (and how they could misbehave) before users.  

Before settling on macros for this one, maybe it's a good idea to have it fully implemented and tested first? Or at least, an organized plan would be nice before this one's voted on…  

So, the one big thing going for the current approach is that SourceLocations have been in Delite/scala-virtualized for a while, they're understood, used, and tested, they're fully-implemented and sitting as a pull-request on scala/master: https://github.com/scala/scala/pull/343

The new macro-based approach would have to be better-baked, integrated, and more thoroughly tested pretty soon…

--  
Heather Miller
Doctoral Assistant
EPFL, IC, LAMP
http://people.epfl.ch/heather.miller


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugene Burmako  
View profile  
 More options Apr 2 2012, 12:04 pm
From: Eugene Burmako <eugene.burm...@epfl.ch>
Date: Mon, 2 Apr 2012 18:04:24 +0200
Local: Mon, Apr 2 2012 12:04 pm
Subject: Re: New SIP: Implicit Source Locations

Yes, this is right, proposed macros would need to be imported, or they
could go into the SourceLocation object to be located without imports.

Regarding the rest, please, let me know if you need me to elaborate on the
details of the provided sketch.

Also, I would like to note that in comparison with the original
implementation, macro-based implementation transparently supports chaining,
something that cannot be easily achieved without macros. I hope, this shows
flexibility of macro-based approaches to metaprogramming and will be an
argument towards giving macros a chance.

On 2 April 2012 17:38, Heather Miller <heather.mil...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Apr 2 2012, 4:52 pm
From: martin odersky <martin.oder...@epfl.ch>
Date: Mon, 2 Apr 2012 13:52:58 -0700
Local: Mon, Apr 2 2012 4:52 pm
Subject: Re: New SIP: Implicit Source Locations

On Mon, Apr 2, 2012 at 8:38 AM, Heather Miller <heather.mil...@epfl.ch>wrote:

macros. The motivation for macros was that they can simplify the language
and the compiler. If we do not use them for that, we have failed.

And, btw, I believe that the total effort to implement SIP 19 as a macro
should be not higher than to implement it as a language extension. In
particular, it should be simpler to write ScalaDoc for source locations
than to put them in the spec.

Cheers

 -- Martin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Phillips  
View profile  
 More options Apr 2 2012, 10:18 pm
From: Paul Phillips <pa...@improving.org>
Date: Mon, 2 Apr 2012 19:18:06 -0700
Local: Mon, Apr 2 2012 10:18 pm
Subject: Re: New SIP: Implicit Source Locations
I find SourceLocation less interesting than I'd hoped.  You can
implement it coarsely without any compiler support at all; I did so
long ago.  Dredged up old version appended.

With respect to chaining, why isn't it a linked list? As long as it's
getting special support it may as well support that much.

trait SourceLocation extends Serializable {
  def fileName: String = ""
  def line: Int
  def charOffset: Int = 0
  // the missing piece
  def previous: SourceLocation = NoSourceLocation

}

// From extempore's giant collection of abandoned git branches

package scala.tools
package reflect

import scala.tools.nsc.util.{ JavaStackFrame, FrameContext, StackSlice }
import scala.collection.{ mutable, immutable, SeqLike }
import mutable.{ WrappedArray, ArrayBuilder }
import Caller._

class CallerOps(override val repr: Caller) extends
SeqLike[StackTraceElement, Caller] {
  override protected[this] def thisCollection:
WrappedArray[StackTraceElement] = repr.stack
  override protected[this] def toCollection(repr: Caller):
WrappedArray[StackTraceElement] = repr.stack
  override protected[this] def newBuilder = new
ArrayBuilder.ofRef[StackTraceElement] mapResult { xs => Caller(xs, 0)

}

  def apply(idx: Int) = repr.stack(idx)
  def length          = repr.stack.length
  def iterator        = repr.stack.iterator
  def seq             = repr.stack.seq

}

/** A class for recording from whence a certain call originated.
 *  This trick is accomplished by having an implicit value of type Caller
 *  available, and when said implicit is invoked, a stack trace is recorded
 *  and trimmed to start with the original caller.
 */
class Caller private (val complete: StackSlice, val index: Int) {
  def stack     = complete drop index
  def top       = JavaStackFrame(stack(index))
  def context() = stack map (x => FrameContext(x))
  def frames()  = stack map (x => JavaStackFrame(x))

  def dropConstructors = dropWhile(_.isConstructor)
  def dropWhile(pred: StackTraceElement => Boolean): Caller =
dropUntil(x => !pred(x))
  def dropUntil(pred: StackTraceElement => Boolean): Caller = {
    stack indexWhere pred match {
      case -1   => Caller.Empty
      case idx  => drop(idx)
    }
  }
  def drop(numFrames: Int): Caller = Caller(complete, index + numFrames)

  def intersect(other: Caller): Caller = {
    if (stack.length == 0 || other.stack.length == 0)
      Caller.Empty
    else {
      val idx1 = stack indexWhere (_ == other.stack.head)
      lazy val idx2 = other.stack indexWhere (_ == stack.head)

      if (idx1 > 0)
        this drop idx1
      else if (idx2 > 0)
        other drop idx2
      else
        (this drop 1) intersect (other drop 1)
    }
  }
  def combine(implicit other: Caller) = intersect(other)

  def show()         { show(complete.length) }
  def show(num: Int) { context() take num foreach println }

  private def methodString = dropConstructors match {
    case Empty    => ""
    case frame    => " (" + frame.top.tag + ")"
  }
  override def toString =
    if (top.isConstructor) "constructor for class " + top.className +
methodString
    else if (top.isStaticConstructor) "static initializer for " + top.className
    else top.tag

}

trait LowPriorityCaller {
  self: Caller.type =>

  private val ThreadName = classOf[Thread].getName
  private val CallerName = classOf[Caller].getName
  private val CallerFile = nonThreadFrames.head.getFileName

  private def nonThreadFrames = Thread.currentThread.getStackTrace
dropWhile (_.getClassName == ThreadName)
  private def skipFrame(ste: StackTraceElement) = ste.getFileName == CallerFile

  def trace() = apply(nonThreadFrames, 0) dropWhile skipFrame
  implicit def reifyCallerStack: Caller = apply(nonThreadFrames, 0)
dropWhile skipFrame

}

object Caller extends LowPriorityCaller {
  object Empty extends Caller(Array(), -1) {
    override def top = null
    override def intersect(other: Caller) = this
    override def toString = "NoCaller"
  }

  def apply(complete: StackSlice, index: Int): Caller = {
    if (index < 0 || index >= complete.length) Caller.Empty
    else new Caller(complete, index)
  }
  def caller[T](implicit c: Caller) = c


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »