Skip to content

Commit 44d860a

Browse files
committed
Changes from meeting
1 parent 48d1f31 commit 44d860a

File tree

7 files changed

+136
-40
lines changed

7 files changed

+136
-40
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
200200
WarningReport(msg"Pure expression in statement position" -> t.toLoc :: Nil, S(t))
201201

202202
val withImplicitApp = t match
203-
case t: sem.ImplicitApp => t.instantiate
203+
case t: sem.PossiblyImplicitApp => t.instantiate
204204
case t => t
205205

206206
// Funny Scala: the non-exhaustive match is actually the second match
207207
t match
208-
case t: sem.ImplicitApp => t.instantiate
208+
case t: sem.PossiblyImplicitApp => t.instantiate
209209
case t => t
210210
match
211211
case st.UnitVal() => k(unit)

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,20 @@ class Resolver(tl: TraceLogger)
124124
case NonModule(reason: Opt[Message])
125125
case Any
126126

127-
extension (e: Expect)
128-
def message: Ls[Message -> Opt[Loc]] = e match
127+
def message: Ls[Message -> Opt[Loc]] = this match
129128
case Expect.Module(msg) => msg.toList.map(_ -> N)
130129
case Expect.NonModule(msg) => msg.toList.map(_ -> N)
131130
case Expect.Any => Nil
132131

133-
def module = e match
132+
def module = this match
134133
case Expect.Module(_) => true
135134
case _ => false
136135

137-
def nonModule = e match
136+
def nonModule = this match
138137
case Expect.NonModule(_) => true
139138
case _ => false
140-
139+
140+
end Expect
141141
import Expect.*
142142

143143
/**
@@ -172,16 +172,16 @@ class Resolver(tl: TraceLogger)
172172
case t: Term.IfLike =>
173173
t.subTerms.foreach(resolve(_, expect = Any))
174174

175-
case t: ImplicitApp =>
175+
case t: PossiblyImplicitApp =>
176176
resolveImplicitApp(t)
177177

178178
case _ =>
179179
t.subTerms.foreach(resolve(_, expect = NonModule(N)))
180180

181181
def resolveSymbol(t: Term.Sel | Term.SynthSel)(using ictx: ICtx): Unit =
182182
val (lhs, id) = t match
183-
case Term.Sel(lhs: ImplicitApp, id) => (lhs, id)
184-
case Term.SynthSel(lhs: ImplicitApp, id) => (lhs, id)
183+
case Term.Sel(lhs: PossiblyImplicitApp, id) => (lhs, id)
184+
case Term.SynthSel(lhs: PossiblyImplicitApp, id) => (lhs, id)
185185
case _ => return
186186
lhs.termDefn match
187187
case S(lhsDefn) =>
@@ -212,15 +212,15 @@ class Resolver(tl: TraceLogger)
212212
lastWords(s"term ${lhs} returns module but has no type signature")
213213
case N =>
214214

215-
def resolveImplicitApp(t: Term & ImplicitApp, inPrefix: Bool = false)(using ICtx): (Opt[TermDefinition], ICtx) =
215+
def resolveImplicitApp(t: Term & PossiblyImplicitApp, inPrefix: Bool = false)(using ICtx): (Opt[TermDefinition], ICtx) =
216216
trace[(Opt[TermDefinition], ICtx)](s"Resolving implicit application: ${t}, (inPrefix = ${inPrefix})", _ => s"~> ${t}"):
217217
val (defn, newICtx1) = t match
218-
case Term.App(lhs: ImplicitApp, _) =>
218+
case Term.App(lhs: PossiblyImplicitApp, _) =>
219219
resolveImplicitApp(lhs)
220220
case Term.App(lhs: Term, args) =>
221221
resolve(lhs, expect = Any)
222222
(t.termDefn, ictx)
223-
case Term.TyApp(lhs: ImplicitApp, targs) =>
223+
case Term.TyApp(lhs: PossiblyImplicitApp, targs) =>
224224
resolveImplicitApp(lhs, inPrefix = true)
225225
(t.termDefn, ictx)
226226
case Term.TyApp(lhs: Term, targs) =>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum Annot extends AutoLocated:
2828
case Trm(trm) => trm :: Nil
2929
case _: Modifier | Untyped => Nil
3030

31-
sealed trait ImplicitApp:
31+
sealed trait PossiblyImplicitApp:
3232
t: Term =>
3333

3434
var argsLs: Ls[Term.Tup] = Nil
@@ -68,11 +68,11 @@ enum Term extends Statement:
6868
case Missing // Placeholder terms that were not elaborated due to the "lightweight" elaboration mode `Mode.Light`
6969
case Lit(lit: Literal)
7070
case Builtin(id: Tree.Ident, nme: Str)
71-
case Ref(sym: Symbol)(val tree: Tree.Ident, val refNum: Int) extends Term with ImplicitApp
72-
case App(lhs: Term, rhs: Term)(val tree: Tree.App, val resSym: FlowSymbol) extends Term with ImplicitApp
73-
case TyApp(lhs: Term, targs: Ls[Term]) extends Term with ImplicitApp
74-
case Sel(prefix: Term, nme: Tree.Ident)(var sym: Opt[FieldSymbol]) extends Term with ImplicitApp
75-
case SynthSel(prefix: Term, nme: Tree.Ident)(var sym: Opt[FieldSymbol]) extends Term with ImplicitApp
71+
case Ref(sym: Symbol)(val tree: Tree.Ident, val refNum: Int) extends Term with PossiblyImplicitApp
72+
case App(lhs: Term, rhs: Term)(val tree: Tree.App, val resSym: FlowSymbol) extends Term with PossiblyImplicitApp
73+
case TyApp(lhs: Term, targs: Ls[Term]) extends Term with PossiblyImplicitApp
74+
case Sel(prefix: Term, nme: Tree.Ident)(var sym: Opt[FieldSymbol]) extends Term with PossiblyImplicitApp
75+
case SynthSel(prefix: Term, nme: Tree.Ident)(var sym: Opt[FieldSymbol]) extends Term with PossiblyImplicitApp
7676
case DynSel(prefix: Term, fld: Term, arrayIdx: Bool)
7777
case Tup(fields: Ls[Elem])(val tree: Tree.Tup)
7878
case IfLike(kw: Keyword.`if`.type | Keyword.`while`.type, desugared: Split)(val normalized: Split)

hkmc2/shared/src/main/scala/hkmc2/utils/utils.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import hkmc2.semantics.FldFlags
2525
import hkmc2.semantics.ParamListFlags
2626
import scala.collection.mutable.Buffer
2727
import mlscript.utils.StringOps
28-
import hkmc2.semantics.ImplicitApp
28+
import hkmc2.semantics.PossiblyImplicitApp
2929

3030
trait ProductWithTail extends Product
3131

@@ -81,9 +81,9 @@ extension (t: Product)
8181
case a =>
8282
var args = t.productIterator.zipWithIndex.map:
8383
case (v, i) => t.productElementName(i) + " = " + aux(v, t.isInstanceOf[ProductWithTail] && i === a - 1)
84-
if t.isInstanceOf[ImplicitApp] then
84+
if t.isInstanceOf[PossiblyImplicitApp] then
8585
args = args ++ Iterator:
86-
"ImplicitArgs = " + aux(t.asInstanceOf[ImplicitApp].argsLs)
86+
"ImplicitArgs = " + aux(t.asInstanceOf[PossiblyImplicitApp].argsLs)
8787
prefix + locally:
8888
if inTailPos then ": \\\n" + args.mkString("\n")
8989
else ":\n" + args.mkString("\n").indent(" ")

hkmc2/shared/src/test/mlscript/basics/ModuleMethods.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ val v: module M = M
157157

158158

159159

160-
// "Module" Methods
160+
// *Module* Methods
161161

162162
module N with
163163
fun foo(): module M = M

hkmc2/shared/src/test/mlscript/ctx/CascadingTypeClasses.mls

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ fun foo[A](using Foo[A], A)
1111
use Foo[Baz] = new Foo
1212

1313

14-
:todo
14+
// FIXME: error message refers to `A`
15+
:e
16+
:fixme // Internal Error should never reach users
1517
foo[Baz]
1618
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
17-
//│ ║ l.15: foo[Baz]
19+
//│ ║ l.17: foo[Baz]
1820
//│ ║ ^^^^^^^
1921
//│ ╟── Required by contextual parameter declaration:
2022
//│ ║ l.9: fun foo[A](using Foo[A], A)
2123
//│ ║ ^
2224
//│ ╙── Expected: A; Available: (Foo[Baz])
2325
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
2426

25-
:todo
27+
:e
28+
:fixme // Internal Error should never reach users
2629
foo
2730
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
28-
//│ ║ l.26: foo
31+
//│ ║ l.29: foo
2932
//│ ║ ^^^
3033
//│ ╟── Required by contextual parameter declaration:
3134
//│ ║ l.9: fun foo[A](using Foo[A], A)
@@ -34,17 +37,31 @@ foo
3437
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
3538

3639

40+
use Baz = new Baz
41+
42+
:todo
43+
foo
44+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
45+
//│ ║ l.43: foo
46+
//│ ║ ^^^
47+
//│ ╟── Required by contextual parameter declaration:
48+
//│ ║ l.9: fun foo[A](using Foo[A], A)
49+
//│ ║ ^
50+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
51+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
52+
53+
3754
fun foo[A](using Foo[A])(using A)
3855

3956
:todo
4057
foo
4158
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
42-
//│ ║ l.40: foo
59+
//│ ║ l.57: foo
4360
//│ ║ ^^^
4461
//│ ╟── Required by contextual parameter declaration:
45-
//│ ║ l.37: fun foo[A](using Foo[A])(using A)
62+
//│ ║ l.54: fun foo[A](using Foo[A])(using A)
4663
//│ ║ ^
47-
//│ ╙── Expected: A; Available: (Foo[Baz])
64+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
4865
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
4966

5067

@@ -53,12 +70,12 @@ fun foo[A](using A)(using Foo[A])
5370
:todo
5471
foo
5572
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
56-
//│ ║ l.54: foo
73+
//│ ║ l.71: foo
5774
//│ ║ ^^^
5875
//│ ╟── Required by contextual parameter declaration:
59-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
76+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
6077
//│ ║ ^
61-
//│ ╙── Expected: A; Available: (Foo[Baz])
78+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
6279
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
6380

6481

@@ -68,25 +85,51 @@ use Foo[Bar[Baz]] = new Foo
6885
:e
6986
foo
7087
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
71-
//│ ║ l.69: foo
88+
//│ ║ l.86: foo
7289
//│ ║ ^^^
7390
//│ ╟── Required by contextual parameter declaration:
74-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
91+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
7592
//│ ║ ^
76-
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz])
93+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz)
7794
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
7895

7996
use Bar[Baz] = new Bar
8097

81-
:todo
98+
:fixme
8299
foo
83100
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
84-
//│ ║ l.82: foo
101+
//│ ║ l.99: foo
85102
//│ ║ ^^^
86103
//│ ╟── Required by contextual parameter declaration:
87-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
104+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
105+
//│ ║ ^
106+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Baz])
107+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
108+
109+
use Bar[Int] = new Bar
110+
111+
:fixme
112+
foo
113+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
114+
//│ ║ l.112: foo
115+
//│ ║ ^^^
116+
//│ ╟── Required by contextual parameter declaration:
117+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
118+
//│ ║ ^
119+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Int], Bar[Baz])
120+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
121+
122+
use Bar[Baz] = new Bar
123+
124+
:todo
125+
foo
126+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
127+
//│ ║ l.125: foo
128+
//│ ║ ^^^
129+
//│ ╟── Required by contextual parameter declaration:
130+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
88131
//│ ║ ^
89-
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Bar[Baz])
132+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Baz], Bar[Int], Bar[Baz])
90133
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
91134

92135

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
:js
2+
:todo
3+
4+
5+
class Foo()(using Int)
6+
//│ ╔══[ERROR] Multiple parameter lists are not supported for this definition.
7+
//│ ║ l.5: class Foo()(using Int)
8+
//│ ╙── ^^^^^^^^^^^^^^^^
9+
10+
class Foo(using val n: Int)
11+
//│ ╔══[ERROR] Illegal definition in term position.
12+
//│ ║ l.10: class Foo(using val n: Int)
13+
//│ ╙── ^^^^^^
14+
15+
16+
fun summon[A](using a: A) = a
17+
18+
class Foo(using Int) with
19+
fun foo() = summon[Int]
20+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
21+
//│ ║ l.19: fun foo() = summon[Int]
22+
//│ ║ ^^^^^^^^^^
23+
//│ ╟── Required by contextual parameter declaration:
24+
//│ ║ l.16: fun summon[A](using a: A) = a
25+
//│ ║ ^^^^
26+
//│ ╙── Expected: A; Available: ()
27+
28+
29+
fun summon(using a: Int) = a
30+
31+
class Foo(using Int) with
32+
fun foo() = summon
33+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `Int` in this call
34+
//│ ║ l.32: fun foo() = summon
35+
//│ ║ ^^^^^^
36+
//│ ╟── Required by contextual parameter declaration:
37+
//│ ║ l.29: fun summon(using a: Int) = a
38+
//│ ║ ^^^^^^
39+
//│ ╙── Expected: Int; Available: ()
40+
41+
Foo()
42+
//│ = Foo()
43+
44+
45+
fun foo(using Int) = 1
46+
47+
use Int = 1
48+
49+
:re
50+
foo()
51+
//│ ═══[RUNTIME ERROR] TypeError: tmp is not a function
52+
53+

0 commit comments

Comments
 (0)