Skip to content

Parser API annotations: RealSrcLoc

Vladislav Zavialov requested to merge wip/ann-real-loc into master

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.

Edited by Vladislav Zavialov

Merge request reports