-
Notifications
You must be signed in to change notification settings - Fork 317
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
Explicit self #3569
Explicit self #3569
Conversation
b8bf352
to
460a334
Compare
) => | ||
val global = fn.getMetadata(GlobalNames) | ||
global.map(_.target) match { | ||
case Some(BindingsMap.ResolvedMethod(module, method)) => |
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 change is a bit controversial in a sense that by making GlobalNames
code simple and conform to the overall approach (no self arguments) we have to compensate for that in IrToTruffle translation. It seemed like a good idea at the time but it complicated the logic slightly here.
On the upside, we don't do symbol resolution for local functions in runtime.
I can bring back the old approach by reverting the change in GlobalNames
and removing this special handling here. It would be a tiny change and I checked that it works. So happy to get feedback on this piece!
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.
Explained on priv, I have some doubts about why this change reaches so deep into function execution
24cf852
to
47e909b
Compare
@kustosz removed the controversial method dispatch changes. |
47e909b
to
429b86c
Compare
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Noise/Generator.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Prim_Text_Helper.enso
Show resolved
Hide resolved
distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Postgres.enso
Outdated
Show resolved
Hide resolved
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.
Have only reviewed the enso files - a few minor fixed but otherwise LGTM
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 went thru all the non-.enso
files and tried to make a sense of the changes. My comments are more questions. If the system holds together the change is probably good. Great work!
@@ -58,24 +58,24 @@ public abstract List<String> generate( | |||
protected String methodSigDef(String owner, List<MethodParameter> params, boolean isAbstract) { | |||
int paramsLen = params.size(); | |||
String paramsDef; | |||
boolean includeSelfParam = !(isStatic || isConstructor); |
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.
These DSL changes are interesting, but: @hubertp, didn't you have to update Ir
or parser? I am asking because I am supposed to implement default
keyword. I thought my task will be similar to your one. It seems to me that with explicit self
we are also introducing new keyword self
...
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 particular change affects generating builtin nodes.
For example (roughly) for
@Builtin.Method
public static void foo(Object x) {
// ...
}
it will generate Builtin node with execute
without Object self
i.e.
@BuiltinMethod(...)
public class FooNode {
public void execute(Object x) {
/// ...
}
}
rather than
@BuiltinMethod(...)
public class FooNode {
public void execute(Object self, Object x) {
/// ...
}
}
This is then accepted by the next processor which knows that it needs to add self
as ArgumentDefinition at 0.
While strictly speaking not necessary, because in this version everything still has self
( insert sad face ) but at least most of it is now hidden.
@@ -210,7 +210,7 @@ case object IgnoredBindings extends IRPass { | |||
): IR.DefinitionArgument = { | |||
arg match { | |||
case spec @ IR.DefinitionArgument.Specified( | |||
IR.Name.Self(_, _, _), | |||
IR.Name.Self(_, _, _, _), |
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.
Here is IR.Name.Self
! In the same manner I will have to make sure there is IR.Name.Default
once I try to implement default arguments, right?
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 change is only because I added a parameter to Self class definition and compiler would reject this pattern
* @param ir the annotated application | ||
* @param paramPosition the reason why the annotation cannot be obeyed | ||
*/ | ||
case class WrongSelfParameterPos( |
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.
Any reason why not make it an error instead of warning?
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.
The discussion in discord mentions that it should be a warning. Truth be told, it will almost always be an error....
case AstView.Binding(AST.App.Section.Right(opr, arg), body) => | ||
val translatedArgs = arg match { | ||
case AstView.FunctionParamList(items) => |
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.
Is this change related to self
? Or is it just adding a missing processing of FunctionParamList
triggered by some new failing tests?
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, this is related to self
.
Previously methods involving operands wouldn't have self
.
For example, without this change we will crash on something as simple as
== self that = ....
engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala
Show resolved
Hide resolved
engine/runtime/src/main/scala/org/enso/compiler/pass/desugar/FunctionBinding.scala
Outdated
Show resolved
Hide resolved
engine/runtime/src/test/scala/org/enso/compiler/test/pass/analyse/AliasAnalysisTest.scala
Show resolved
Hide resolved
4799b21
to
1cb2229
Compare
ffba928
to
809c6e5
Compare
On a scale of 1 to 10, the hack is probably 5. All the alternatives I considered, involved tweaking IR in a horrible way. And JS is a bit of a special case TBH. The solution adds an implicit self parameter with a default value resolving to the definining module. That way users don't have to provide an extra parameter and all arguments are magically applied
Added missing `self` in interop specs that were pending.
Minor nit: turns out methods are registered for modules under their lowercase name, rather than the original one. This is a bit surprising and might need to be removed, if it turns out to be unnecessary.
In the current approach the order of calling local functions matters which came up accidentally in a method with default arguments in Delimited_Reader. This is because methods are added to the scope in the order they are processed. Suprised this hasn't come up before. Will need to address this before releasing. Added a (pending) test-case to demonstrate the problem.
Handle local functions that are being used before being defined. Might want to revise that in GlobalNames
Discovered by accident.
This was requested to resolve the exceptional status of `this` in JS. It also introduces an inconsistency to the language as everything else uses `self`. Added some logic to detect situations when someone uses `self` in JS and issue warnings in such situation. The implementation implicitly replaces `this` with `self` in the parameter list so that we don't have to change the whole compiler to support this exception.
This approach might still go away, since we will explore adding implicit self always.
In order to limit the complexity of the change and its effect on method dispatch, this change brings back (implicit) self arguments for all methods. Couldn't force myself to bring all self parameters to builtins so instead adapted processor to add them.
98d4f7b
to
387904b
Compare
`main` method is now special because it is trully static i.e. no implicit `self` is being generated for it. But since REPL's `main` isn't called `main` its invocation was missing an argument. Follow up on #3569 Will work on adding a CI test for REPL to avoid problems with REPL in a follow up PR.
`main` method is now special because it is trully static i.e. no implicit `self` is being generated for it. But since REPL's `main` isn't called `main` its invocation was missing an argument. Follow up on #3569 Will work on adding a CI test for REPL to avoid problems with REPL in a follow up PR.
`main` method is now special because it is trully static i.e. no implicit `self` is being generated for it. But since REPL's `main` isn't called `main` its invocation was missing an argument. Follow up on #3569 Will work on adding a CI test for REPL to avoid problems with REPL in a follow up PR.
`main` method is now special because it is trully static i.e. no implicit `self` is being generated for it. But since REPL's `main` isn't called `main` its invocation was missing an argument. Follow up on #3569 # Important Notes Will work on adding a CI test for REPL to avoid problems with REPL in a follow up PR.
Pull Request Description
This change modifies the current language by requiring explicit
self
parameter declarationfor methods. Methods without
self
parameter in the first position should be treated as staticsalthough that is not yet part of this PR. We add an implicit self to all methods
This obviously required updating the whole stdlib and its components, tests etc but the change
is pretty straightforward in the diff.
Notice that this change does not change method dispatch, which was removed in the last changes.
This was done on purpose to simplify the implementation for now. We will likely still remove all
those implicit selfs to bring true statics.
Minor caveat - since
main
doesn't actually need self, already removed that which simplifieda lot of code.
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide dist
and./run ide watch
.