<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Some slight additions to Kais message:</p>
<div class="moz-cite-prefix">On 03/08/2025 17:25, Kai Prott wrote:<br>
</div>
<blockquote type="cite"
cite="mid:3020D236-1B6F-4B23-97CB-A6DC456B8D55@mail.uni-kiel.de">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">Hi,<br>
<br>
what I have used In the past (and that I am fairly confident
works) is exactly what you say: use `uniqFromTag` or
`mkSplitUniqSupply`.<br>
<br>
According to the documentation, "the payload part of the Uniques
allocated from this UniqSupply are guaranteed distinct wrt all
other supplies, regardless of their 'tag'."<br>
(Assuming the unique does not overflow it's number of bits)<br>
</div>
</blockquote>
If you read on the docs refer to an edge case in the next lines. GHC
contains a (limited) number of fixed/"built in" uniques. GHC itself
never creates uniques with the same tag as those fixed ones on the
fly so there is no risk of collision. However if you explicitly use
this tag it could happen and then compilation could go wrong.
Outside of this that is correct.
<blockquote type="cite"
cite="mid:3020D236-1B6F-4B23-97CB-A6DC456B8D55@mail.uni-kiel.de">
<div dir="auto"><br>
As far as I know, end users should not get to see a unique and
it should not influence compilation, so the Tag is only relevant
for plugin/GHC devs for debugging. <br>
</div>
</blockquote>
Uniques influence code generation slightly, as they are part of
internal symbol names. They should however not affect the behaviour
of the program. This doesn't matter often, but when it does it
really does.
<blockquote type="cite"
cite="mid:3020D236-1B6F-4B23-97CB-A6DC456B8D55@mail.uni-kiel.de">
<div dir="auto"><br>
Also just curious: why do you need to construct a unique? Before
the GHC renamer a plugin can get away with generating
essentially strings that are "unique" and use them in `mkUnqual`
or similar. <br>
Most of the time, I just generate a `RdrName` with a prefix that
would not be allowed in source code with an incrementing suffix
that I manage myself. <br>
I have not checked if a plugin-generated name has to be a valid
Haskell name nowadays. However, it worked in the past.<br>
<br>
And just for completeness if someone else stumbles across this:
After the GHC renamer in `CoreM`, `TcM` (and others) one can
just use `getUniqueM` or `getUniqueSupplyM`.<br>
<br>
Best wishes,<br>
Kai Prott </div>
<br>
<br>
<div class="gmail_quote">
<div dir="auto">On August 2, 2025 7:08:10 PM GMT+02:00, Wolfgang
Jeltsch <a class="moz-txt-link-rfc2396E" href="mailto:wolfgang@well-typed.com"><wolfgang@well-typed.com></a> wrote:</div>
<blockquote class="gmail_quote"
style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><div dir="auto">Hello, again!
After some more digging, I came to the conclusion that `uniqFromTag` is
likely what I should use. However, what exactly is the tag for?
The note „Uniques and tags“ only says the following:
</div><blockquote class="gmail_quote"
style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><div
dir="auto">The tag […] is typically used to make it easier to distinguish uniques
constructed by different parts of the compiler.
</div></blockquote><div dir="auto">
Who distinguishes uniques using tags: the compiler, compiler developers
when reading debugging output, or end users? Does the choice of tag
influence the behavior of the compiler other than with respect to
messages?
The documentation of `mkSplitUniqSupply` says that the tag “is mostly
cosmetic”. If it is only *mostly* cosmetic, what aspects of it are not
cosmetic?
In the end, how do I choose a tag for uniques generated by a plugin? Is
the choice essentially irrelevant? Do I have to prevent clashes with
tags used by GHC or other plugins?
Looking forward to insights. 🙂
All the best,
Wolfgang
Am Samstag, dem 02.08.2025 um 16:16 +0300 schrieb Wolfgang Jeltsch:
</div><blockquote class="gmail_quote"
style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><div
dir="auto">Hello!
I want to generate AST fragments in a source plugin, and for this I
need to generate fresh (local) names. My current approach is to use
`mkSystemName`, but it, like many of the other name-generating
operations, needs a value of type `Unique`. How can I generate such
values? It seems that the `Hsc` monad doesn’t carry a value of type
`UniqueSupply` with it.
All the best,
Wolfgang
</div></blockquote><div dir="auto"><hr>ghc-devs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs"
moz-do-not-send="true" class="moz-txt-link-freetext">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</div></pre>
</blockquote>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre wrap="" class="moz-quote-pre">_______________________________________________
ghc-devs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</pre>
</blockquote>
</body>
</html>