RangePosition vs TransparentPosition

86 views
Skip to first unread message

Mirco Dotta

unread,
Mar 29, 2012, 4:26:07 AM3/29/12
to scala-i...@googlegroups.com
Hi guys,

I wonder what's the difference between RangePosition and TransparentPosition. 
And, under what conditions a RangePosition is turned into a TransparentPosition? 


Cheers,
  Mirco

---------------
Mirco Dotta
Typesafe - The software stack for applications that scale
PSE-D, 1015 Lausanne, Switzerland
Twitter: @mircodotta








Mirko Stocker

unread,
Mar 29, 2012, 4:40:29 AM3/29/12
to scala-i...@googlegroups.com
Hi Mirco,

Let me try to answer that: As you know, trees that have a direct
correspondence in the source code have a RangePosition, and compiler-generated
trees have an OffsetPosition. By INV1 in Position.scala, "a tree with an offset
position never contains a child with a range position". The problem is that
there are ASTs that don't have a source-code correspondence but still have
children that are visible in the source. So that's where the
TransparentPositions come into play, for example:

"abc".charAt _

is represented as a Function tree, where the Function, the parameter ValDef
and the Apply all have a TransparentPosition, and the Select(Literal(""),
"charAt") has a RangePosition.

I hope this helps,

Mirko

--
Mirko Stocker | m...@misto.ch
Work: http://ifs.hsr.ch | http://infoq.com
Personal: http://misto.ch | http://twitter.com/m_st

Mirco Dotta

unread,
Mar 29, 2012, 4:45:37 AM3/29/12
to scala-i...@googlegroups.com
Nice, that helps a lot! Thanks!

-- Mirco

martin odersky

unread,
Mar 29, 2012, 5:20:46 AM3/29/12
to scala-i...@googlegroups.com
Mirko is correct. One more point: Trees with range positions may not
overlap. So If you want to create two Range position trees that do
have subtrees with interleaving range positions, one of them must be a
transparent position.

The doc comment to scala.tools.nsc.util.Position is really required
reading for anyone dealing with positions.

Cheers

- Martin

Mirco Dotta

unread,
Mar 29, 2012, 5:41:01 AM3/29/12
to scala-i...@googlegroups.com
Mirko is correct. One more point: Trees with range positions may not
overlap. So If you want to create two Range position trees that do
have subtrees with interleaving range positions, one of them must be a
transparent position.

I might be failing to understand your point, but it looks like a TransparentPosition 
is allowed to break the contract of a RangePosition.

If the above is true, then why TransparentPosition <: RangePosition?

The doc comment to scala.tools.nsc.util.Position is really required
reading for anyone dealing with positions.

but I can't find the explanation you gave about TransparentPositions.


Cheers

- Martin

martin odersky

unread,
Mar 29, 2012, 5:47:32 AM3/29/12
to scala-i...@googlegroups.com
On Thu, Mar 29, 2012 at 11:41 AM, Mirco Dotta <mirco...@typesafe.com> wrote:
> Mirko is correct. One more point: Trees with range positions may not
> overlap. So If you want to create two Range position trees that do
> have subtrees with interleaving range positions, one of them must be a
> transparent position.
>
>
> I might be failing to understand your point, but it looks like
> a TransparentPosition
> is allowed to break the contract of a RangePosition.
>
> If the above is true, then why TransparentPosition <: RangePosition?
>
> The doc comment to scala.tools.nsc.util.Position is really required
> reading for anyone dealing with positions.
>
>
> I read
> this http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/compiler/scala/tools/nsc/util/Position.html,
> but I can't find the explanation you gave about TransparentPositions.
>
>I

I meant opaque range positions may not overlap, where an opaque range
position is a range position that is not also a transparent range
position. See INV 3 in the doc comment.

Cheers

- Martin

> Cheers
>
> - Martin
>
>
>
> ---------------
> Mirco Dotta
> Typesafe - The software stack for applications that scale
> PSE-D, 1015 Lausanne, Switzerland
> Work: +41 (0)21 691 49 65
> Twitter: @mircodotta
>
>
>
>
>
>
>
>

--
Martin Odersky
Prof., EPFL and Chairman, Typesafe
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967

Amanj Sherwany

unread,
Feb 6, 2017, 11:57:55 PM2/6/17
to scala-internals, mirco...@typesafe.com
Sorry for bringing this OLD thread to live again. But I want to make
sure that I understood correctly. Is it safe to assume:

1- Opaque positions are guaranteed to point to trees that are actually in the source code
2- Transparent positions are guaranteed to be compiler generated?

-- Amanj
Reply all
Reply to author
Forward
0 new messages