Skip to content

Commit d08424f

Browse files
committed
Remove useless uid parameter and stop printing uids all the time
1 parent 30f48b2 commit d08424f

File tree

22 files changed

+128
-132
lines changed

22 files changed

+128
-132
lines changed

hkmc2/shared/src/main/scala/hkmc2/bbml/bbML.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ end BbCtx
6767

6868

6969
class BBTyper(using elState: Elaborator.State, tl: TL):
70-
import elState.nextUid
7170
import tl.{trace, log}
7271

7372
private val infVarState = new InfVarUid.State()

hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Lowering(using TL, Raise, Elaborator.State):
7171
case sem.Fld(sem.FldFlags(false, false, false, true), value, N) => value
7272
case sem.Fld(flags, value, asc) =>
7373
TODO("Other argument forms")
74-
val l = new TempSymbol(summon[Elaborator.State].nextUid, S(t))
74+
val l = new TempSymbol(S(t))
7575
subTerm(f): fr =>
7676
def rec(as: Ls[st], asr: Ls[Path]): Block = as match
7777
case Nil => k(Call(fr, asr.reverse))
@@ -182,7 +182,7 @@ class Lowering(using TL, Raise, Elaborator.State):
182182
term(els)(k)
183183
)
184184
case _ =>
185-
val l = new TempSymbol(summon[Elaborator.State].nextUid, S(t))
185+
val l = new TempSymbol(S(t))
186186
subTerm(scrut): sr =>
187187
Match(sr, Case.Lit(tru) -> subTerm(thn)(r => Assign(l, r, End())) :: Nil,
188188
elseBranch.map(els => subTerm(els)(r => Assign(l, r, End()))),
@@ -202,10 +202,10 @@ class Lowering(using TL, Raise, Elaborator.State):
202202
var usesResTmp = false
203203
lazy val l =
204204
usesResTmp = true
205-
new TempSymbol(summon[Elaborator.State].nextUid, S(t))
205+
new TempSymbol(S(t))
206206

207207
lazy val lbl =
208-
new TempSymbol(summon[Elaborator.State].nextUid, S(t))
208+
new TempSymbol(S(t))
209209

210210
def go(split: Split, topLevel: Bool)(using Subst): Block = split match
211211
case Split.Let(sym, trm, tl) =>
@@ -234,7 +234,7 @@ class Lowering(using TL, Raise, Elaborator.State):
234234
// mkMatch(Case.Cls(cls, st) -> go(tail, topLevel = false))
235235
Case.Cls(cls, st) -> go(tail, topLevel = false)
236236
case (param, arg) :: args =>
237-
// summon[Subst].+(arg -> Value.Ref(new TempSymbol(summon[Elaborator.State].nextUid, N)))
237+
// summon[Subst].+(arg -> Value.Ref(new TempSymbol(N)))
238238
// Assign(arg, Select(sr, Tree.Ident("head")), mkArgs(args))
239239

240240
val (cse, blk) = mkArgs(args)
@@ -288,7 +288,7 @@ class Lowering(using TL, Raise, Elaborator.State):
288288
rec(as, Nil)
289289

290290
case Try(sub, finallyDo) =>
291-
val l = new TempSymbol(summon[Elaborator.State].nextUid, S(sub))
291+
val l = new TempSymbol(S(sub))
292292
TryBlock(
293293
term(sub)(p => Assign(l, p, End())),
294294
term(finallyDo)(_ => End()),
@@ -305,7 +305,7 @@ class Lowering(using TL, Raise, Elaborator.State):
305305
case v: Value => k(v)
306306
case p: Path => k(p)
307307
case r =>
308-
val l = new TempSymbol(summon[Elaborator.State].nextUid, N)
308+
val l = new TempSymbol(N)
309309
Assign(l, r, k(l |> Value.Ref.apply))
310310

311311

hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class JSBuilder extends CodeBuilder:
188188
}; }"""
189189
} #} # }"
190190
if (clsDefn.kind is syntax.Mod) || (clsDefn.kind is syntax.Obj) then
191-
val clsTmp = summon[Scope].allocateName(new semantics.TempSymbol(0/*TODO rm this useless param*/, N, sym.nme+"$"+"class"))
191+
val clsTmp = summon[Scope].allocateName(new semantics.TempSymbol(N, sym.nme+"$"+"class"))
192192
clsDefn.owner match
193193
case S(owner) =>
194194
assert(clsDefn.paramsOpt.isEmpty)
@@ -427,7 +427,7 @@ end JSBuilder
427427

428428
trait JSBuilderSanityChecks(instrument: Bool) extends JSBuilder:
429429

430-
val functionParamVarargSymbol = semantics.TempSymbol(0, N, "args")
430+
val functionParamVarargSymbol = semantics.TempSymbol(N, "args")
431431

432432
override def setupFunction(name: Option[Str], params: List[semantics.Param], body: Block)(using Raise, Scope): (Document, Document) =
433433
if instrument then

hkmc2/shared/src/main/scala/hkmc2/semantics/Desugarer.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
3535
import Desugarer.*
3636
import Elaborator.Ctx
3737
import elaborator.term
38-
import state.nextUid
3938
import tl.*
4039

4140
// We're working on composing continuations in the UCS translation.
@@ -71,14 +70,14 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
7170
extension (symbol: BlockLocalSymbol)
7271
def getSubScrutinees(cls: ClassSymbol): List[BlockLocalSymbol] =
7372
subScrutineeMap.getOrElseUpdate(symbol, new ScrutineeData).classes.getOrElseUpdate(cls, {
74-
(0 until cls.arity).map(i => TempSymbol(nextUid, N, s"param$i")).toList
73+
(0 until cls.arity).map(i => TempSymbol(N, s"param$i")).toList
7574
})
7675
def getTupleLeadSubScrutinee(index: Int): BlockLocalSymbol =
7776
val data = subScrutineeMap.getOrElseUpdate(symbol, new ScrutineeData)
78-
data.tupleLead.getOrElseUpdate(index, TempSymbol(nextUid, N, s"first$index"))
77+
data.tupleLead.getOrElseUpdate(index, TempSymbol(N, s"first$index"))
7978
def getTupleLastSubScrutinee(index: Int): BlockLocalSymbol =
8079
val data = subScrutineeMap.getOrElseUpdate(symbol, new ScrutineeData)
81-
data.tupleLast.getOrElseUpdate(index, TempSymbol(nextUid, N, s"last$index"))
80+
data.tupleLast.getOrElseUpdate(index, TempSymbol(N, s"last$index"))
8281

8382

8483
def default: Split => Sequel = split => _ => split
@@ -164,7 +163,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
164163
pre = s"termSplit: let ${ident.name} = $termTree",
165164
post = (res: Split) => s"termSplit: let >>> $res"
166165
):
167-
val sym = VarSymbol(ident, nextUid)
166+
val sym = VarSymbol(ident)
168167
val fallbackCtx = ctx + (ident.name -> sym)
169168
Split.Let(sym, term(termTree)(using ctx), elabFallback(fallback)(fallbackCtx)).withLocOf(t)
170169
case Modified(Keyword.`else`, elsLoc, default) => fallback => ctx => trace(
@@ -222,7 +221,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
222221
val first = Fld(FldFlags.empty, lhsSymbol.ref(/* FIXME ident? */), N)
223222
val second = Fld(FldFlags.empty, rhsTerm, N)
224223
val arguments = Term.Tup(first :: second :: Nil)(rawTup)
225-
val joint = FlowSymbol("‹applied-result›", nextUid)
224+
val joint = FlowSymbol("‹applied-result›")
226225
Term.App(opRef, arguments)(tree, joint)
227226
termSplit(rhs, finishInner)(fallback)
228227
case tree @ App(lhs, blk @ OpBlock(opRhsApps)) => fallback => ctx =>
@@ -232,14 +231,14 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
232231
val second = Fld(FldFlags.empty, rhsTerm, N)
233232
val rawTup = Tup(lhs :: Nil): Tup // <-- loc might be wrong
234233
val arguments = Term.Tup(first :: second :: Nil)(rawTup)
235-
val joint = FlowSymbol("‹applied-result›", nextUid)
234+
val joint = FlowSymbol("‹applied-result›")
236235
Term.App(op, arguments)(tree, joint)
237236
opRhsApps.foldRight(Function.const(fallback): Sequel): (tt, elabFallback) =>
238237
tt match
239238
case (Tree.Empty(), LetLike(`let`, ident @ Ident(_), termTree, N)) => ctx =>
240239
termTree match
241240
case S(termTree) =>
242-
val sym = VarSymbol(ident, nextUid)
241+
val sym = VarSymbol(ident)
243242
val fallbackCtx = ctx + (ident.name -> sym)
244243
Split.Let(sym, term(termTree)(using ctx), elabFallback(fallbackCtx))
245244
case (Tree.Empty(), Modified(Keyword.`else`, elsLoc, default)) => ctx =>
@@ -268,7 +267,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
268267
cont(symbol)(innerCtx)
269268
case _ =>
270269
val name = "scrut"
271-
val symbol = TempSymbol(nextUid, N, name)
270+
val symbol = TempSymbol(N, name)
272271
val innerCtx = baseCtx + (name -> symbol)
273272
Split.Let(symbol, scrutinee, cont(symbol)(innerCtx))
274273

@@ -320,7 +319,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
320319
case LetLike(`let`, ident @ Ident(_), termTree, N) => backup => ctx =>
321320
termTree match
322321
case S(termTree) =>
323-
val sym = VarSymbol(ident, nextUid)
322+
val sym = VarSymbol(ident)
324323
val fallbackCtx = ctx + (ident.name -> sym)
325324
Split.Let(sym, term(termTree)(using ctx), elabFallback(backup)(fallbackCtx))
326325
case Modified(Keyword.`else`, elsLoc, body) => backup => ctx => trace(
@@ -381,13 +380,13 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
381380
case Ident("_") => _ => ctx => sequel(ctx)
382381
// Alias pattern
383382
case pat as (alias @ Ident(_)) => fallback =>
384-
val aliasSymbol = VarSymbol(alias, nextUid)
383+
val aliasSymbol = VarSymbol(alias)
385384
val inner = (ctx: Ctx) =>
386385
val ctxWithAlias = ctx + (alias.name -> aliasSymbol)
387386
Split.Let(aliasSymbol, ref, sequel(ctxWithAlias))
388387
expandMatch(scrutSymbol, pat, inner)(fallback)
389388
case id @ Ident(nme) if nme.headOption.forall(_.isLower) => fallback => ctx =>
390-
val aliasSymbol = VarSymbol(id, nextUid)
389+
val aliasSymbol = VarSymbol(id)
391390
val ctxWithAlias = ctx + (nme -> aliasSymbol)
392391
Split.Let(aliasSymbol, ref, sequel(ctxWithAlias) ++ fallback)
393392
case ctor @ (_: Ident | _: Sel) => fallback => ctx =>
@@ -418,7 +417,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
418417
def fld(t: Term) = Fld(FldFlags.empty, t, N)
419418
def tup(xs: Fld*) = Term.Tup(xs.toList)(Tup(Nil))
420419
def app(lhs: Term, rhs: Term, sym: FlowSymbol) = Term.App(lhs, rhs)(Tree.App(Tree.Empty(), Tree.Empty()), sym)
421-
def getLast(i: Int) = TempSymbol(nextUid, N, s"last$i")
420+
def getLast(i: Int) = TempSymbol(N, s"last$i")
422421
// `wrap`: add let bindings for tuple elements
423422
// `matches`: pairs of patterns and symbols to be elaborated
424423
val (wrapRest, restMatches) = rest match
@@ -434,7 +433,7 @@ class Desugarer(tl: TraceLogger, elaborator: Elaborator)
434433
rest match
435434
case N => (wrapLast, lastMatches)
436435
case S(pat) =>
437-
val sym = TempSymbol(nextUid, N, "rest")
436+
val sym = TempSymbol(N, "rest")
438437
val wrap = (split: Split) =>
439438
Split.Let(sym, app(tupleSlice, tup(fld(ref), fld(int(lead.length)), fld(int(last.length))), sym), wrapLast(split))
440439
(wrap, (sym, pat) :: lastMatches)

hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,16 @@ object Elaborator:
8484
))
8585
type Ctxl[A] = Ctx ?=> A
8686
def ctx: Ctxl[Ctx] = summon
87-
class State:
88-
private var curUi = 0
89-
def nextUid: Int = { curUi += 1; curUi }
87+
class State
9088
import Elaborator.*
9189

9290
class Elaborator(val tl: TraceLogger, val wd: os.Path)
9391
(using val raise: Raise, val state: State)
9492
extends Importer:
95-
import state.nextUid
9693
import tl.*
9794

9895
// * Ref allocation skolem UID, preserved
99-
private val allocSkolemUID = nextUid
100-
private val allocSkolemSym = VarSymbol(Ident("Alloc"), allocSkolemUID)
96+
private val allocSkolemSym = VarSymbol(Ident("Alloc"))
10197
private val allocSkolemDef = TyParam(FldFlags.empty, N, allocSkolemSym)
10298
allocSkolemSym.decl = S(allocSkolemDef)
10399

@@ -160,7 +156,7 @@ extends Importer:
160156
lhs match
161157
case id: Ident =>
162158
val lt = term(lhs)
163-
val sym = TempSymbol(nextUid, S(lt), "old")
159+
val sym = TempSymbol(S(lt), "old")
164160
Term.Blk(
165161
LetDecl(sym) :: DefineVar(sym, lt) :: Nil, Term.Try(Term.Blk(
166162
Term.Assgn(lt, term(rhs)) :: Nil,
@@ -211,7 +207,7 @@ extends Importer:
211207
case InfixApp(TyTup(tvs), Keyword.`->`, body) =>
212208
val boundVars = mutable.HashMap.empty[Str, VarSymbol]
213209
def genSym(id: Tree.Ident) =
214-
val sym = VarSymbol(id, nextUid)
210+
val sym = VarSymbol(id)
215211
sym.decl = S(TyParam(FldFlags.empty, N, sym)) // TODO vce
216212
boundVars += id.name -> sym
217213
sym
@@ -258,7 +254,7 @@ extends Importer:
258254
case App(Ident("~"), Tree.Tup(rhs :: Nil)) =>
259255
term(rhs)
260256
case tree @ App(lhs, rhs) =>
261-
val sym = FlowSymbol("‹app-res›", nextUid)
257+
val sym = FlowSymbol("‹app-res›")
262258
val lt = term(lhs)
263259
val rt = term(rhs)
264260

@@ -312,7 +308,7 @@ extends Importer:
312308
case Tree.Quoted(body) => Term.Quoted(term(body))
313309
case Tree.Unquoted(body) => Term.Unquoted(term(body))
314310
case Tree.Case(branches) =>
315-
val scrut = VarSymbol(Ident("caseScrut"), nextUid)
311+
val scrut = VarSymbol(Ident("caseScrut"))
316312
val desugarer = new Desugarer(tl, this)
317313
val des = desugarer.patternSplit(branches, scrut)(Split.End)(ctx)
318314
scoped("ucs:desugared"):
@@ -330,7 +326,7 @@ extends Importer:
330326
case TypeDef(Mod, head, N, N) =>
331327
term(head)
332328
case Tree.Region(id: Tree.Ident, body) =>
333-
val sym = VarSymbol(id, nextUid)
329+
val sym = VarSymbol(id)
334330
val nestCtx = ctx + (id.name -> sym)
335331
Term.Region(sym, term(body)(using nestCtx))
336332
case Tree.RegRef(reg, value) => Term.RegRef(term(reg), term(value))
@@ -357,13 +353,13 @@ extends Importer:
357353
// * TODO would be better to keep the fixity of applications part of the Tree repr.
358354
case (ap @ App(f: Ident, tup @ Tup(lhs :: args))) :: trees if !f.name.head.isLetter =>
359355
val res = go(acc, lhs :: Nil)
360-
val sym = FlowSymbol("‹app-res›", nextUid)
356+
val sym = FlowSymbol("‹app-res›")
361357
val fl = Fld(FldFlags.empty, res, N)
362358
val app = Term.App(term(f), Term.Tup(
363359
fl :: args.map(fld))(tup))(ap, sym)
364360
go(app, trees)
365361
case (ap @ App(f, tup @ Tup(args))) :: trees =>
366-
val sym = FlowSymbol("‹app-res›", nextUid)
362+
val sym = FlowSymbol("‹app-res›")
367363
go(Term.App(term(f),
368364
Term.Tup(Fld(FldFlags.empty, acc, N) :: args.map(fld))(tup)
369365
)(ap, sym), trees)
@@ -556,7 +552,7 @@ extends Importer:
556552
val st = td.annotatedResultType.orElse(newSignatureTrees.get(id.name))
557553
val s = st.map(term(_)(using newCtx))
558554
val b = rhs.map(term(_)(using newCtx))
559-
val r = FlowSymbol(s"‹result of ${sym}", nextUid)
555+
val r = FlowSymbol(s"‹result of ${sym}")
560556
val tdf = TermDefinition(owner, k, sym, pss, s, b, r,
561557
TermDefFlags.empty.copy(isModMember = isModMember))
562558
sym.defn = S(tdf)
@@ -612,7 +608,7 @@ extends Importer:
612608
(id, S(false))
613609
case Modified(Keyword.`out`, outLoc, id: Ident) =>
614610
(id, S(true))
615-
val vs = VarSymbol(id, nextUid)
611+
val vs = VarSymbol(id)
616612
val res = TyParam(FldFlags.empty, vce, vs)
617613
vs.decl = S(res)
618614
res :: Nil
@@ -697,7 +693,7 @@ extends Importer:
697693

698694
def fieldOrVarSym(k: TermDefKind, id: Ident)(using Ctx): LocalSymbol & NamedSymbol =
699695
if ctx.outer.isDefined then TermSymbol(k, ctx.outer, id)
700-
else VarSymbol(id, nextUid)
696+
else VarSymbol(id)
701697

702698
def param(t: Tree): Ctxl[Ls[Param]] = t match
703699
case TypeDef(Mod, inner, N, N) =>
@@ -721,7 +717,7 @@ extends Importer:
721717
case TyTup(ps) =>
722718
val vs = ps.map:
723719
case id: Ident =>
724-
val sym = VarSymbol(id, nextUid)
720+
val sym = VarSymbol(id)
725721
sym.decl = S(TyParam(FldFlags.empty, N, sym))
726722
Param(FldFlags.empty, sym, N)
727723
(vs, ctx ++ vs.map(p => p.sym.name -> p.sym))
@@ -731,7 +727,7 @@ extends Importer:
731727
val boundVars = mutable.HashMap.empty[Str, VarSymbol]
732728
def go(t: Tree): Pattern = t match
733729
case id @ Ident(name) =>
734-
val sym = boundVars.getOrElseUpdate(name, VarSymbol(id, nextUid))
730+
val sym = boundVars.getOrElseUpdate(name, VarSymbol(id))
735731
Pattern.Var(sym)
736732
// case Tup(fields) =>
737733
// val pats = fields.map(

hkmc2/shared/src/main/scala/hkmc2/semantics/Symbol.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,32 @@ abstract class Symbol extends Located:
5555
end Symbol
5656

5757

58-
class FlowSymbol(label: Str, uid: Int) extends Symbol:
58+
class FlowSymbol(label: Str) extends Symbol:
5959
def nme: Str = label
6060
def toLoc: Option[Loc] = N // TODO track source trees of flows
6161
import typing.*
6262
val outFlows: mutable.Buffer[FlowSymbol] = mutable.Buffer.empty
6363
val outFlows2: mutable.Buffer[Consumer] = mutable.Buffer.empty
6464
val inFlows: mutable.Buffer[ConcreteProd] = mutable.Buffer.empty
65-
override def toString: Str = s"$label@$uid"
65+
override def toString: Str =
66+
label
67+
// s"$label@$uid"
6668

6769

6870
sealed trait LocalSymbol extends Symbol
6971
sealed trait NamedSymbol extends Symbol:
7072
def name: Str
7173
def id: Ident
7274

73-
abstract class BlockLocalSymbol(name: Str, uid: Int) extends FlowSymbol(name, uid) with LocalSymbol:
75+
abstract class BlockLocalSymbol(name: Str) extends FlowSymbol(name) with LocalSymbol:
7476
var decl: Opt[Declaration] = N
7577

76-
class TempSymbol(uid: Int, val trm: Opt[Term], dbgNme: Str = "tmp") extends BlockLocalSymbol(dbgNme, uid):
78+
class TempSymbol(val trm: Opt[Term], dbgNme: Str = "tmp") extends BlockLocalSymbol(dbgNme):
7779
val nameHints: MutSet[Str] = MutSet.empty
7880
override def toLoc: Option[Loc] = trm.flatMap(_.toLoc)
7981
override def toString: Str = s"$$${super.toString}"
8082

81-
class VarSymbol(val id: Ident, uid: Int) extends BlockLocalSymbol(id.name, uid) with NamedSymbol:
83+
class VarSymbol(val id: Ident) extends BlockLocalSymbol(id.name) with NamedSymbol:
8284
val name: Str = id.name
8385
// override def toString: Str = s"$name@$uid"
8486

hkmc2/shared/src/main/scala/hkmc2/typing/TypeChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TypeChecker(using raise: Raise):
8787
P.Ctor(TupSymbol(S(fields.size)), fields.map(f => typeProd(f.value)))
8888
case Error =>
8989
P.Ctor(Extr(false), Nil)
90-
case _ => P.Flow(FlowSymbol("TODO", 666)) // TODO
90+
case _ => P.Flow(FlowSymbol("TODO")) // TODO
9191

9292
def typeParams(ps: Ls[Param]): Ls[(C, P)] =
9393
ps.map: p =>

0 commit comments

Comments
 (0)