-Yrangepos 除了在宏中提供源位置外还有什么作用

What's the effect of -Yrangepos other than giving me source locations in macros

所以我用谷歌搜索了一下,但除了稀疏之外没有其他信息:

-Yrangepos                     Use range positions for syntax trees.

好的。我知道如果我想在宏中捕获源代码片段,我需要使用它。

现在我的两个问题是:

出于性能原因,我只能猜测 scalac 默认情况下不使用范围位置。

在常规编译中,位置仅用于错误报告和将行号信息保存到类文件中。偏移位置足以做到这一点,因此没有必要完成操纵范围位置所需的所有工作。

除了简单的编译速度之外,我认为范围位置不会产生任何其他成本。

makro 拼写为 Burmak(r)o 的问题 introducing -Yrangepos 是由您的用例引起的。

-X 选项表示永久性,而 -Y 可能随时消失,这意味着它可能成为默认行为。

也许不是因为 bugs and crashes.

a team meeting written up by Moors

Range positions [martin]

Respecting range positions - decay in the ide which has to do with the fact that transformations in the typer or parser don’t respect range positions

  • every checked in change - automatically check range positions
  • range positions = not just a position point but start and end, contained in tree nodes (RangePosition is a subclass of Position)
  • there is map of RangePositions in CompilationUnit

invariants:

  • range positions of child nodes are contained in range pos of parent nodes
  • no overlap (except for transparent range positions)
  • rangepos cover whole program

problems:

  • templates
  • for

check files contain positions

rangeposition(start,point,end).focus == offsetposition(point) // escape from non-overlap invariant

2012年-Yrangepos的PR验证频繁失败;它已修复,但 turned into a nightly validation 以减少资源。

休伯特offered these notes:

A few things about rangepos:

  • if you try to run any code with 'scalac -Ybrowse:typer -Yrangepos FILE.scala' you will see that most of the trees have range positions.
  • some don't, yes, that's a bit unfortunate but we are trying to improve on that - actually whenever you find such in Yrangepos mode it is possible that it is a bug. The situation has improved dramatically from 2.9 to 2.10.0-snapshots.
  • syntactic trees are often assigned offset positions (this is something you might be experiencing but I would have to see an example)
  • for the compiler we only care if range positions are valid up to (and including) typer. after that, we don't care. You are running your tool after refchecks from what I can see, this can interfere with a couple of transformations that happen in refchecks which can manipulate/assign range- or offset- positions.

切换到范围位置似乎很容易,因为基础数学,但在合成或重构树时分配位置仍然存在错误like this one that demonstrate the extra labor involved

虽然演示编译器需要范围位置,但它们不在批编译的关键路径中。有了更多资源来提高稳健性,也许他们可以翻转开关。