Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Dec 6, 2023
1 parent 0327727 commit 5f4f163
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2119,8 +2119,9 @@ nameEndsWith ppe suffix r = case PrettyPrintEnv.termName ppe (Referent.Ref r) of
-- Algorithm is the following:
-- 1. Form the set of all local variables used anywhere in the term
-- 2. When picking a name for a term, see if it is contained in this set.
-- If yes, use the qualified name for the term (which PPE conveniently provides)
-- If no, use the suffixed name for the term
-- If yes: use a minimally qualified name which is longer than the suffixed name,
-- but doesn't conflict with any local vars.
-- If no: use the suffixed name for the term
--
-- The algorithm does the same for type references in signatures.
--
Expand Down Expand Up @@ -2150,10 +2151,14 @@ avoidShadowing tm (PrettyPrintEnv terms types) =
minimallySuffixed :: HQ'.HashQualified Name
minimallySuffixed =
revFQNSegments
-- Get all suffixes (it's inits instead of tails because name segments are in reverse order)
& NEL.inits
-- Drop the empty 'init'
& NEL.tail
& mapMaybe (fmap Name.fromReverseSegments . NEL.nonEmpty)
& mapMaybe (fmap Name.fromReverseSegments . NEL.nonEmpty) -- Convert back into names
-- Drop the suffixes that we know are shorter than the suffixified name
& List.drop (Name.countSegments suffixedName)
-- Drop the suffixes that are equal to local variables
& filter ((\n -> n `Set.notMember` used))
& listToMaybe
& maybe fullName HQ'.NameOnly
Expand Down

0 comments on commit 5f4f163

Please sign in to comment.