Parser API annotations: RealSrcLoc
During parsing, GHC collects lexical information about AST nodes and stores it in a map. It is needed to faithfully restore original source code, e.g. compare these expressions:
a = b
a = b
The position of the equality sign is not recorded in the AST, so it must be stored elsewhere.
This system is described in Note [Api annotations]
.
Before this patch, the mapping was represented by:
Map (SrcSpan, AnnKeywordId) SrcSpan
After this patch, the mapping is represented by:
Map (RealSrcSpan, AnnKeywordId) RealSrcSpan
The motivation behind this change is to avoid using the Ord SrcSpan
instance (required by Map
here), as it interferes with #17632 (closed) (see the
discussion there).
SrcSpan
is isomorphic to Either String RealSrcSpan
, but we shouldn't
use those strings as Map
keys. Those strings are intended as hints to
the user, e.g. "<interactive>"
or "<compiler-generated code>"
, so they
are not a valid way to identify nodes in the source code.