-
Notifications
You must be signed in to change notification settings - Fork 326
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
Don't add module's builtins to the scope of a builtin type #3791
Don't add module's builtins to the scope of a builtin type #3791
Conversation
fde582a
to
01b2b08
Compare
07f1f90
to
436f7ce
Compare
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.
Looks good, just a few suggestions/questions.
...g/enso/interpreter/node/expression/builtin/immutable/FromPolyglotArrayBuiltinVectorNode.java
Outdated
Show resolved
Hide resolved
...untime/src/main/java/org/enso/interpreter/node/expression/builtin/special/RunThreadNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala
Show resolved
Hide resolved
engine/runtime/src/main/scala/org/enso/compiler/phase/ModuleBuiltins.scala
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/scala/org/enso/compiler/codegen/IrToTruffle.scala
Outdated
Show resolved
Hide resolved
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/MethodProcessor.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java
Outdated
Show resolved
Hide resolved
...-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala
Show resolved
Hide resolved
.../java/org/enso/interpreter/node/expression/builtin/immutable/FromArrayBuiltinVectorNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintErrNode.java
Outdated
Show resolved
Hide resolved
import org.enso.interpreter.runtime.callable.function.Function; | ||
|
||
/** BuiltinFunction encapsulates information about a builtin runtime function and its metadata. */ | ||
public class BuiltinFunction { |
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.
Wouldn't BuiltinFunction
rather be a record
than plain class
?
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, indeed. Except that frgaal appears to be causing problems when I make that change, as noted in the comment one line below.
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.
Yeap, still does it
[error] /home/hubert/tmp/enso/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinFunction.java:7:15: not found: type java
[error] public record BuiltinFunction(Function fun, boolean isStatic, Owner owner) {
[error] ^
[error] one error found
this is a weird one.
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 there a simple reproducer that wouldn't involve sbt
? Then we can report a bug.
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.
Seems that might be a known caveat - "record classes" section mentions some problems if the target is lower than 16.
983efc8
to
16157ae
Compare
c690ad3
to
b3c8eed
Compare
It appears that we were always adding builtin methods to the scope of the module and the builtin type that shared the same name. This resulted in some methods being accidentally available even though they shouldn't.
During Builtins initialization we only register non-static builtins. That way one does not have to import stdlib to have basic operations on Any or Number. Similarly during IRtoTruffle for only consider static builtins, thus avoiding a situation where we would try to register them twice. This required changing our annotations processor so that it is aware if a builtin is a static or not, based on the lack or presence of self parameter, respectively. More importantly this approach allows us to avoid hacky solution in types which caused adding module methods to types' scope. And we don't do that late in the interpreter.
Builtin statics are registered differently depending on whether their owner would be a module or a type. The latter can be registered early on because we already have type presents, while the former will be registered during codegen. This distinction allows us to treat all builtins the same. There is no need to make a stub definition of a builtin method - they will all be automatically registered, and the fact if they are static or not is now irrelevant.
Module builtin methods declarations had to be implicitly added at an early stage so that BindingAnalysis (and later passes) can make use of that information. This change adds implicit method definitions for all module builtins unless they have been provided explicitly. With this change one does not have to provide explicit builtin declarations ever, irrespective of whether the owner is a module or a type. Removed some stub definitions to illustrate the usage.
Co-authored-by: Radosław Waśko <[email protected]>
Builtins defined on modules are no longer auto-registered by default. This was suggested to be a more intuitive solution that avoids magic and potential name conflicts for modules using the same name.
b3c8eed
to
3c9c0b0
Compare
Pull Request Description
It appears that we were always adding builtin methods to the scope of the module and the builtin type that shared the same name.
This resulted in some methods being accidentally available even though they shouldn't.
This change treats differently builtins of types and modules and introduces auto-registration feature for builtins.
By default all builtin methods are registered with a type, unless explicitly defined in the annotation property.
Builtin methods that are auto-registered do not have to be explicitly defined and are registered with the underlying type.
Registration correctly infers the right type, depending whether we deal with static or instance methods.
Builtin methods that are not auto-registered have to be explicitly defined always. Modules' builtin methods are the prime example.
Important Notes
Builtins now carry information whether they are static or not (inferred from the lack of
self
parameter).They also carry a
autoRegister
property to determine if a builtin method should be automatically registered with the type.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.