-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Return Values #272
base: master
Are you sure you want to change the base?
Conversation
Fixes the compilation errors introduced by cherry-picked aa8b5cb.
This makes optimizations easier and automatically whole-program.
@@ -567,7 +588,7 @@ object Named { | |||
} | |||
|
|||
extension [T <: Definitions](t: T & Definition) { | |||
def symbol(using C: Context): ResolvedDefinitions[T] = C.symbolOf(t).asInstanceOf | |||
def symbol(using C: Context): List[ResolvedDefinitions[T]] = C.symbolsOf(t).map(asInstanceOf) // TODO MRV 26: ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denhie Here this should be C.symbolsOf(t).asInstanceOf
without the map
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only reviewed Repl.scala and Server.scala but I think it would be valuable to discuss my questions, before I continue. @phischu
@@ -108,7 +108,7 @@ class Repl(driver: Driver) extends REPL[Tree, EffektConfig, EffektError] { | |||
runFrontend(StringSource(""), module.make(UnitLit()), config) { cu => | |||
module.definitions.foreach { | |||
case u: Def => | |||
outputCode(DeclPrinter(context.symbolOf(u)), config) | |||
outputCode(DeclPrinter(context.symbolsOf(u)), config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary? Can you please help me understand? Is the reason that a definition now introduces multiple symbols?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intuition tells me that there are invariants which are not represented here. This will lead to a lot of code changes that might not be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a definition now has multiple symbols.
} | ||
output.emitln(s"\nImported Functions\n==================") | ||
cu.terms.toList.sortBy { case (n, _) => n }.foreach { | ||
case (name, syms) => | ||
syms.collect { | ||
case sym if !sym.isSynthetic => | ||
outputCode(DeclPrinter(sym), config) | ||
outputCode(DeclPrinter(List(sym)), config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that DeclPrinter now takes a list... This feels wrong.
@@ -215,21 +215,22 @@ class Repl(driver: Driver) extends REPL[Tree, EffektConfig, EffektError] { | |||
case d: Def => | |||
val extendedDefs = module + d | |||
val decl = extendedDefs.make(UnitLit()) | |||
val output = config.output() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused
|
||
runFrontend(source, decl, config) { cu => | ||
module = extendedDefs | ||
|
||
// try to find the symbol for the def to print the type | ||
(context.symbolOption(d.id) match { | ||
d.ids.foreach(id => (context.symbolOption(id) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not the correct implementation. It should print
x:Int, y:String, z:Bool
not
x: Int
y: String
z: Bool
or what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the correct behavior in this case. It can still be refactored, though.
import effekt.source.{ FunDef, Hole, ModuleDecl, Tree } | ||
import effekt.util.{ PlainMessaging, getOrElseAborting } | ||
import effekt.source.{FunDef, Hole, ModuleDecl, Tree} | ||
import effekt.util.{PlainMessaging, getOrElseAborting} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to keep this changes out of the PR or change them upstream, so that the diff is smaller :)
@@ -231,10 +234,11 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with | |||
} | |||
} yield res | |||
|
|||
def needsUpdate(annotated: (ValueType, Effects), inferred: (ValueType, Effects))(using Context): Boolean = { | |||
def needsUpdate(annotated: (List[ValueType], Effects), inferred: (List[ValueType], Effects))(using Context): Boolean = { | |||
val (tpe1, effs1) = annotated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called tpes1
since they are now multiple.
val (tpe1, effs1) = annotated | ||
val (tpe2, effs2) = inferred | ||
tpe1 != tpe2 || effs1 != effs2 | ||
|
||
tpe1.size != tpe2.size || tpe1.zip(tpe2).forall { case (t1, t2) => t1 != t2 } || effs1 != effs2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't write huge boolean expressions like this.
tpe1.size != tpe2.size || tpe1.zip(tpe2).forall { case (t1, t2) => t1 != t2 } || effs1 != effs2 | |
val differentArity = tpes1.size != tpes2.size | |
val differentEffects = effs1 != effs2 | |
def differentTypes = (tpes1 zip tpes2).forall { case (tpe1, tpe2) => tpe1 != tpe2 } | |
differentArity || differentEffects || differentTypes |
…es-invariants Feature/multiple return values invariants
|
||
//</editor-fold> | ||
|
||
//<editor-fold desc="statements and definitions"> | ||
|
||
def checkStmt(stmt: Stmt, expected: Option[ValueType])(using Context, Captures): Result[ValueType] = | ||
def checkStmt(stmt: Stmt, expected: Option[List[ValueType]])(using Context, Captures): Result[List[ValueType]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a list of option since each individual component might be known or not.
ee9d209
to
58c8510
Compare
No description provided.